This class manages the buffers and other data needed in audio storage, playback, and processing. There are circular buffers for the input and output audio streams. Data that is reused from frame to frame (e.g. filter coefficients) is stored in this class and is accessible in ALFPackage.cpp for use with the DSP functions contained in DSPFunctions.c.
| AudioChannel.cpp | This class manages the buffers and other data needed in audio storage, playback, and processing. |
| Constructor | |
| AudioChannel | Creates an AudioChannel object with the default parameters. |
| initChannel() | This function is called with the allocation of every DATF (or ALF) object from ActionScript for a desired audio channel (left or right). |
| reInitChannel() | This funciton is called when a channel (L or R) has already been instantiated and initialized and a new song is loaded that requires changes to the buffer sizes. |
| initChannelVocoder | This function initializes a vocoder object for the AudioChanenl when needed for the vocoding function |
| Utilities | |
| checkRoom() | This function checks if the parameters entered are the same as the ones stored in the audio channel. |
| clearFFTFrame() | Clears the fftFrame buffer, which has the FFT data. |
| clearInAudioFrame() | Clears the inAudioFrame buffer that is one of the buffers that can be read and written to by C++ and Actionscript. |
| clearCorrFrame() | Clears the frames for performing a correlation. |
| resetChannel | Resets the buffers and flags in the channel. |
| Get Functions | |
| getCentroidVal() | Returns the centroid of the audio spectrum from the current frame of data |
| getChannelName() | Retrieves the name given to the AudioChannel object. |
| getFFTSize() | Returns the size of the FFT used on the current audio frame |
| getHopSize() | Returns the user-specificed hopSize object |
| getSampleRate() | Returns the sampling rate of the audio under analysis |
| getOutAudioFrameSamples() | Returns the current number of samples contained in outAudioFrame |
| Set Functions | |
| setCentroidVal() | Sets the value of the spectral centroid for the current frame |
| setChannelName() | Sets the name of the AudioChannel |
| setHopSize() | Sets the value of the hopSize |
| setSampleRate() | Sets the sampling rate of the audio under analysis |
| setAudioFrameSamples() | Sets the number of samples currently contained inthe inAudioFrame buffer |
| setOutAudioFrameSamples() | Sets the number of samples currently contained inthe OutAudioFrame buffer |
| setRoom() | Sets the parameters to the room impulse response function. |
| Flag Management | This is a set of functions to handle toggling various flags that are checked in ALFPackage.cpp in order to avoid duplicate computation. |
| clearFlags() | This function clears all of the flags that are used to specify whether a given value has been calculated on the current frame. |
| getCentroidFlag() | Returns the centroidFlag to determine if the centroid has been calculated. |
| getCircularBufferFlag() | Returns the status fo the circularBufferFlag to determine if audio output should be routed through the ouput circular buffer. |
| getFFTFlag() | Returns the status off the fftFlag to determine if the FFT has been computed on the current frame. |
| getMagFlag() | Returns the status off the magflag to determine if the magnitude has been calculated on the current frame |
| setCentroidFlag() | Sets the status of the centroid flag |
| setCircularBufferFlag() | Sets the status of the circularBuffer flag. |
| setFFTFlag() | Sets the status of the FFT flag |
| setMagFlag() | Sets the status of the magnitude flag |
| Public Members | The AudioChannel class contains many buffers required for storing various aspects of the current audio frame as well as the input/output buffer access so that flash can read/write directly from/to the C namespace. |
| Private Members | Includes variables and flags. |
AudioChannel::AudioChannel()
Creates an AudioChannel object with the default parameters.
void AudioChannel::initChannel( int _hopSize, int _fftSize, int _fs, int _lookAheadFrames )
This function is called with the allocation of every DATF (or ALF) object from ActionScript for a desired audio channel (left or right). This function initializes the circular buffers needed for input and output. It also initializes memory required for the feature analysis functions. Certain flags are initialized as well. See Sections Private Members, Public Members
| hopSize | The desired size of the analysis frame, as selected by the user from ALF or DATF. |
| fftSize | the size of the FFT to be computed on each frame when using spectral analysis fucntions. |
| fs | The audio sampling rate of the user-selected audio |
| lookAheadFrames | The number of frames to calculate features on before beginning playback. For example, entering a value of twenty will cause zeros to be returned as the audio output for the first 20 frames, while the feature values of the first twenty. |
void AudioChannel::reInitChannel( int _hopSize, int _fftSize, int _fs, int numCh, int _lookAheadFrames )
This funciton is called when a channel (L or R) has already been instantiated and initialized and a new song is loaded that requires changes to the buffer sizes.
| hopSize | The desired size of the analysis frame, as selected by the user from ALF or DATF. |
| fftSize | the size of the FFT to be computed on each frame when using spectral analysis fucntions. |
| fs | The audio sampling rate of the user-selected audio |
| lookAheadFrames | The number of frames to calculate features on before beginning playback. |
bool AudioChannel::checkRoom( float newRoomLength, float newRoomWidth, float newRoomHeight, float newSourceLength, float newSourceWidth, float newSourceHeight, float newMicLength, float newMicWidth, float newMicHeight, double newEchoStrength )
This function checks if the parameters entered are the same as the ones stored in the audio channel.
| newRoomLength | A float that is the new room length. |
| newRoomWidth | A float that is the new room width. |
| newRoomHeight | A float that is the new room height. |
| newSourceLength | A float that is the new source x location. |
| newSourceWidth | A float that is the new source y location. |
| newSourceHeight | A float that is the new source z location. |
| newMicLength | A float that is the new mic x location. |
| newMicWidth | A float that is the new mic y location. |
| newMicHeight | A float that is the new mic y location. |
| newEchoStrength | A double indicating the new echo strength. |
True if a new room impulse response must be calculated, false if the parameters entered are the same as those in the channel.
setRoom, <DATF.reverb>
void AudioChannel::clearFFTFrame()
Clears the fftFrame buffer, which has the FFT data. This must be done every frame. It is equivalent to zero padding to the next power of 2 greater than the frameSize. This also clears the buffers used in the filter function in ALFPackage.cpp.
void AudioChannel::clearInAudioFrame()
Clears the inAudioFrame buffer that is one of the buffers that can be read and written to by C++ and Actionscript. This function should be called when not writing a full frame as samples from the previous frame may remain and introduce error into calculations that are performed.
void AudioChannel::setRoom( float newRoomLength, float newRoomWidth, float newRoomHeight, float newSourceLength, float newSourceWidth, float newSourceHeight, float newMicLength, float newMicWidth, float newMicHeight, double newEchoStrength )
Sets the parameters to the room impulse response function. These are saved on each frame and compared to the last frame when reverb is in use. If the parameters are the same then no RIR will be calculated.
| newRoomLength | A float that is the new room length. |
| newRoomWidth | A float that is the new room width. |
| newRoomHeight | A float that is the new room height. |
| newSourceLength | A float that is the new source x location. |
| newSourceWidth | A float that is the new source y location. |
| newSourceHeight | A float that is the new source z location. |
| newMicLength | A float that is the new mic x location. |
| newMicWidth | A float that is the new mic y location. |
| newMicHeight | A float that is the new mic y location. |
| newEchoStrength | A double indicating the new echo strength. |
checkRoom, <DATF.reverb>
This is a set of functions to handle toggling various flags that are checked in ALFPackage.cpp in order to avoid duplicate computation. See Public Members, and Private Members for descriptions of each flag.
The AudioChannel class contains many buffers required for storing various aspects of the current audio frame as well as the input/output buffer access so that flash can read/write directly from/to the C namespace. The following description includes memory and flags.
| inAudioFrame | Before a frame can be processed, The DATF class writes samples directly to this buffer via a pointer. The buffer is then used to fill an input Circular Buffer for overlap processing. |
| inAudioFrameSamples | This is the number of samples written to the inAudioFrame. Each frame DATF->setFrame sets the number of samples written to the buffer. |
| outAudioFrame | When the ALF requests audioplayback, outAudioFrame is the buffer that provides the output audio samples. The ALF class reads directly from this buffer via a pointer. The sample are written directly to this array in ALFPackage.cpp->checkOutputBuffer. |
| outAudioFrameSamples | ALFPackage.cpp->checkOutputBuffer writes samples to the outAudioFrame even if there are not enough samples to play back in ActionScript. This number keeps track of how many samples are in the frame so that the proper number of samples are written on the next frame. |
| inBuffer | An instance of the CircularBuffer class. After inAudioFrame has been initialized by DATF. Methods in ALFPackage copy the data to inBuffer. This is required since features require overlap, so past samples are needed for future frames. |
| outBuffer | An instance of the CircularBuffer class. When the circularBufferFlag is set, a method the checkOutputBuffer method in ALF package loads outAudioFrame with samples from this buffer. This is necessary since filtering operations produce sequences that are larger than what can be stored in outAudioFrame (and played back at once by Flash). |
| inAudioFrameSamples | The number of smples currently contained in inAudioFrame buffer. This value is set in DATF->setFrame. |
| outAudioFrameSamples | The number of samples currently contained in outAudioFrame. This value is set in ALFPackage.cpp->checkOutputBuffer |
| hannCoefficients | An array containing the the Hann Window coefficients required for a tapered window. Theses values are multiplied by the samples when filling the fftFrame with the current frame’s samples. |
| fftFrame | After inAudioFrame is written to from DATF->setFrame, sample are written to fftFrame from the inBuffer. The number of samples written to fftFrame will be twice the hopSize. This occurs in ALFPackage.cpp->setInputBuffer. Use this as the input to <DSPFunctions.c->realFFT> |
| fftOut | This buffer is used as the output from <DSPFuncitons.c->realFFT>. |
| freqData | An array containing the center frequencies of the bins of the Discrete Fourier Transform. This is needed for certain spectral feature computation algorithms. These values are calculated in ALFPackage.cpp->initAudioChannel |
| magSpectrum | An array that contains the magnitude spectrum computed from the complex spectrum. This is required for certain feature computation algorithms. |
| spectrumPrev | An array containing the previous frame’s magnitude spectrum. This is required for the spectral flux algorithm. |
| filter | An array containing the filter coefficients for use with <ALFPackage.cpp->filter>. |
| filterLen | The number of coefficients in the filter array. |
| filterFFTSize | The size of the FFT needed to perform a frequency domain multiplication of the filter and audio. |
| filterArray | This array is used to compute the realFFT on the filter coefficients for frequency domain multiplication with dataArrayOut. |
| filterArrayOut | This is the output from the realFFT computed on filterArray. |
| dataArray | An array that is used as the input to the realFFT computed in <ALFPackage.cpp->filter>. This is necessary since it may be a different size than fftFrame. |
| dataArrayOut | An array that is used as the output of the realFFT computed in <ALFPackage.cpp->filter>. |
| firstFrame | A boolean indicating if the frame being processed is the first frame. This is necessary becuase we read in 2xhopSize samples on the first frame. This is used extensively in ALFPackage.cpp |
| stereo | A bool, true if the AudioChannel is one of of a stereo pair. |
| filterProcessing | This flag is true when filtering is in use. This is essential since we must know to play a frame with a few samples and padded by zeros on the last frame. Otherwise, Actionscript will not issue the AUDIO_COMPLETE event. |
| channelName | A string indicating the specified name of the AudioChannel. |
| corrData | An array used in calculating an autocorrelation in DSPFunctions.c->LPC and ALFPackage.cpp->getHarmonics |
| corrDataOut | An array that is the ouput of the realFFT in the computation of an autocorrelation. |
Includes variables and flags.
| fs | The sampling rate of the audio under analysis. |
| hopSize | The size of the current audio frame set by the user’s desired sampling rate. Note that spectral analysis is computed on twice the amount of data, that is a frame is twice the size of the hopSize. Only hopSize unique samples are read in on each frame, except the first where twice as many are read in. |
| fftSize | The size of the fft used for computation. In general, this is not the same as hopSize because it requires powers of 2. It is calculated as the next power of 2 greater or equal to 2*hopSize. |
| fftFlag | This flag is true when the spectrum has been calculated on the current frame. |
| centroidFlag | This flag is true when the centroid has been calculated on the current frame. |
| magFlag | This flag is true when the magnitude spectrum has been calculated on the current frame. |
| circularBufferFlag | This flag is true when the circular output buffer is being used (i.e. audio is being synthesized by reverb). |
| centroidVal | Holds the value of the spectral centroid for the current frame; |
| Reverb Parameters | roomLength, roomWidth, roomHeight, sourceLength, sourceWidth, sourceHeight, micLength, micWidth, micHeight, echoStrength. These parameters are used in computing the RIR (DSPFunctions.c->rir). The functions <checkRoom> and <setRoom> are used to tell if new room parameters are given and a new RIR should be calculated. |
Creates an AudioChannel object with the default parameters.
AudioChannel::AudioChannel()
This function is called with the allocation of every DATF (or ALF) object from ActionScript for a desired audio channel (left or right).
void AudioChannel::initChannel( int _hopSize, int _fftSize, int _fs, int _lookAheadFrames )
This funciton is called when a channel (L or R) has already been instantiated and initialized and a new song is loaded that requires changes to the buffer sizes.
void AudioChannel::reInitChannel( int _hopSize, int _fftSize, int _fs, int numCh, int _lookAheadFrames )
This function initializes a vocoder object for the AudioChanenl when needed for the vocoding function
void AudioChannel::initChannelVocoder( int frameOverlap )
This function checks if the parameters entered are the same as the ones stored in the audio channel.
bool AudioChannel::checkRoom( float newRoomLength, float newRoomWidth, float newRoomHeight, float newSourceLength, float newSourceWidth, float newSourceHeight, float newMicLength, float newMicWidth, float newMicHeight, double newEchoStrength )
Clears the fftFrame buffer, which has the FFT data.
void AudioChannel::clearFFTFrame()
Clears the inAudioFrame buffer that is one of the buffers that can be read and written to by C++ and Actionscript.
void AudioChannel::clearInAudioFrame()
Clears the frames for performing a correlation.
void AudioChannel::clearCorrFrame()
Resets the buffers and flags in the channel.
void AudioChannel::resetChannel()
Returns the centroid of the audio spectrum from the current frame of data
float AudioChannel::getCentroidVal()
Retrieves the name given to the AudioChannel object.
char *AudioChannel::getChannelName()
Returns the size of the FFT used on the current audio frame
int AudioChannel::getFFTSize()
Returns the user-specificed hopSize object
int AudioChannel::getHopSize()
Returns the sampling rate of the audio under analysis
int AudioChannel::getSampleRate()
Returns the current number of samples contained in outAudioFrame
int AudioChannel::getOutAudioFrameSamples()
Sets the value of the spectral centroid for the current frame
void AudioChannel::setCentroidVal( float val )
Sets the name of the AudioChannel
void AudioChannel::setChannelName( char name[] )
Sets the value of the hopSize
void AudioChannel::setHopSize( int hop )
Sets the sampling rate of the audio under analysis
int AudioChannel::setSampleRate( int _fs )
Sets the number of samples currently contained inthe inAudioFrame buffer
void AudioChannel::setAudioFrameSamples( int numSamples )
Sets the number of samples currently contained inthe OutAudioFrame buffer
void AudioChannel::setOutAudioFrameSamples( int numSamples )
Sets the parameters to the room impulse response function.
void AudioChannel::setRoom( float newRoomLength, float newRoomWidth, float newRoomHeight, float newSourceLength, float newSourceWidth, float newSourceHeight, float newMicLength, float newMicWidth, float newMicHeight, double newEchoStrength )
This function clears all of the flags that are used to specify whether a given value has been calculated on the current frame.
void AudioChannel::clearFlags()
Returns the centroidFlag to determine if the centroid has been calculated.
bool AudioChannel::getCentroidFlag()
Returns the status fo the circularBufferFlag to determine if audio output should be routed through the ouput circular buffer.
bool AudioChannel::getCircularBufferFlag()
Returns the status off the fftFlag to determine if the FFT has been computed on the current frame.
bool AudioChannel::getFFTFlag()
Returns the status off the magflag to determine if the magnitude has been calculated on the current frame
bool AudioChannel::getMagFlag()
Sets the status of the centroid flag
void AudioChannel::setCentroidFlag( bool flagVal )
Sets the status of the circularBuffer flag.
void AudioChannel::setCircularBufferFlag( bool flagVal )
Sets the status of the FFT flag
void AudioChannel::setFFTFlag( bool flagVal )
Sets the status of the magnitude flag
void AudioChannel::setMagFlag( bool flagVal )
This function should be called when a file is complete or after ALF.stopAudio has been called.
public function endOfFile():void
This function copies the data from a ByteArray into the shared Actionscript/C memory.
public function setFrame( audio:ByteArray, type:String ):int
This function is called prior to playback in ALF.as.
AS3_Val checkOutputBuffer( void * self, AS3_Val args )
This function copies the data from inAudioFrame in AudioChannel.cpp to to the inputBuffer in AudioChannel.cpp.
AS3_Val setInputBuffer( void * self, AS3_Val args )
This funciton initializes the AudioChannel (either left or right).
AS3_Val initAudioChannel( void * self, AS3_Val args )
Performs linear predictive analysis on an audio segment for a desired order.
int LPC( float * corrData, int audioLength, int order, float * lpCE )
This function finds harmonics present in a frame by using linear prediction.
AS3_Val getHarmonics( void * self, AS3_Val args )
Generates a room impulse response for the specified room dimensions, speaker and microphone positions.
float* rir( int fs, float refCo, float mic[], float room[], float src[], int rirLen[] )