chai3d::cAudioBuffer Class Reference

This class implements an audio buffer. More...

#include <CAudioBuffer.h>

Public Member Functions

 cAudioBuffer ()
 Constructor of cAudioBuffer. More...
 
virtual ~cAudioBuffer ()
 Destructor of cAudioBuffer. More...
 
bool setup (unsigned char *a_data, const unsigned int a_size, int a_frequency, bool a_stereo, unsigned short a_bitsPerSample)
 This method sets a buffer by passing a pointer to the audio data and defines the data specifications. More...
 
bool loadFromFile (const std::string &a_filename)
 This method loads an audio file by passing the filename as argument. More...
 
std::string getFilename () const
 This method returns the filename from which this audio data was most recently loaded. More...
 
unsigned int getBuffer ()
 This method returns the OpenAL buffer ID. More...
 
int getSize ()
 This method returns the size in bytes of the audio data. More...
 
int getNumSamples ()
 This method returns the number of samples that compose the audio data. More...
 
int getFrequency ()
 This method returns the sampling frequency of the audio data. More...
 
bool getStereo ()
 This method returns true if the audio data in in stereo format, otherwise false. More...
 
int getBitsPerSample ()
 This method returns the sample format of the audio data. More...
 
unsigned char * getData ()
 This method returns a pointer to the audio data. More...
 
short getSampleLeft (const double a_time, const bool a_loop)
 This method returns the current sample on the left channel. More...
 
short getSampleRight (const double a_time, const bool a_loop)
 This method returns the current sample on the right channel. More...
 
bool convertToMono ()
 This method converts a stereo stream to mono. More...
 

Protected Member Functions

bool checkError ()
 This methods checks for any OpenAL errors. More...
 
bool cleanup ()
 This method clears all memory. More...
 

Protected Attributes

std::string m_filename
 Audio filename. More...
 
unsigned char * m_data
 Audio data. More...
 
unsigned int m_buffer
 OpenAL buffer ID. More...
 
int m_size
 Audio buffer size in bytes. More...
 
int m_frequency
 Audio data frequency. More...
 
bool m_stereo
 Audio data format (stereo = true, mono = false). More...
 
unsigned short m_bitsPerSample
 Audio data resolution. Number of bits per sample (8 or 16). More...
 
bool m_flagDeleteData
 Audio data ownership flag. More...
 

Detailed Description

This class implements an audio buffer. An audio buffer contains audio data and information that describes the specifications of the sound signal such as frequency, length, and format.

Constructor & Destructor Documentation

chai3d::cAudioBuffer::cAudioBuffer ( )

Constructor of cAudioBuffer.

chai3d::cAudioBuffer::~cAudioBuffer ( )
virtual

Destructor of cAudioBuffer.

Member Function Documentation

bool chai3d::cAudioBuffer::setup ( unsigned char *  a_data,
const unsigned int  a_size,
int  a_frequency,
bool  a_stereo,
unsigned short  a_bitsPerSample 
)

This method sets a buffer by passing a pointer to the audio data and defines the data specifications which are passed by argument.

Parameters
a_dataPointer to the audio data.
a_sizeAudio data size in bytes.
a_frequencyAudio data frequency.
a_stereotrue for stereo, false for mono.
a_bitsPerSampleNumber of bits per sample (8 or 16).
Returns
true if the operation succeeds, false otherwise.
bool chai3d::cAudioBuffer::loadFromFile ( const std::string &  a_filename)

This method loads an audio file by passing the path and name as argument.

Parameters
a_filenameFilename.
Returns
true if the operation succeeds, false otherwise.
std::string chai3d::cAudioBuffer::getFilename ( ) const
inline
unsigned int chai3d::cAudioBuffer::getBuffer ( )
inline
int chai3d::cAudioBuffer::getSize ( )
inline
int chai3d::cAudioBuffer::getNumSamples ( )

This method returns the number of samples of the audio data. Please note that this value does not correspond to the number of bytes of the audio buffer.

Returns
Number of audio samples stored in this buffer.
int chai3d::cAudioBuffer::getFrequency ( )
inline
bool chai3d::cAudioBuffer::getStereo ( )
inline
int chai3d::cAudioBuffer::getBitsPerSample ( )
inline
unsigned char* chai3d::cAudioBuffer::getData ( )
inline
short chai3d::cAudioBuffer::getSampleLeft ( const double  a_time,
const bool  a_loop 
)

This method returns the left sample at a given time. If the a_loop argument is set to true then audiobuffer will return a sample value as it was playing in loop mode.

Parameters
a_timeSample time.
a_loopLoop mode.
Returns
Current playing position time in seconds.
short chai3d::cAudioBuffer::getSampleRight ( const double  a_time,
const bool  a_loop 
)

This method returns the right sample at a given time. If the a_loop argument is set to true then audiobuffer will return a sample value as it was playing in loop mode.

Parameters
a_timeSample time.
a_loopLoop mode.
Returns
Current playing position time in seconds.
bool chai3d::cAudioBuffer::convertToMono ( )

This method converts an audio signal from stereo to mono.

Returns
true if the operation succeeds, false otherwise.
bool chai3d::cAudioBuffer::checkError ( )
protected

This methods checks for any OpenAL errors.

Returns
true if no errors have occurred, false otherwise.
bool chai3d::cAudioBuffer::cleanup ( )
protected

This method clears audio data from memory.

Returns
true if operation succeeds, false otherwise.

Member Data Documentation

std::string chai3d::cAudioBuffer::m_filename
protected
unsigned char* chai3d::cAudioBuffer::m_data
protected
unsigned int chai3d::cAudioBuffer::m_buffer
protected
int chai3d::cAudioBuffer::m_size
protected
int chai3d::cAudioBuffer::m_frequency
protected
bool chai3d::cAudioBuffer::m_stereo
protected
unsigned short chai3d::cAudioBuffer::m_bitsPerSample
protected
bool chai3d::cAudioBuffer::m_flagDeleteData
protected

The documentation for this class was generated from the following files: