Aviate Audio Multiverse Library
|
Audio delays are a very common function in audio processing. More...
#include <LibBasicFunctions.h>
Public Member Functions | |
AudioDelay (size_t maxSamples) | |
Construct an audio buffer using INTERNAL memory by specifying the max number of audio samples you will want. More... | |
AudioDelay (float maxDelayTimeMs) | |
Construct an audio buffer using INTERNAL memory by specifying the max amount of time you will want available in the buffer. More... | |
AudioDelay (SramMemSlot *slot) | |
Construct an audio buffer using a slot configured with the baCore::ExternalSramManager. More... | |
virtual | ~AudioDelay () |
Destrutor. | |
audio_block_t * | addBlock (audio_block_t *blockIn) |
Add a new audio block into the buffer. When the buffer is filled, adding a new block will push out the oldest once which is returned. More... | |
audio_block_t * | getBlock (size_t index) |
When using INTERNAL memory, returns the pointer for the specified index into buffer. More... | |
size_t | getMaxDelaySamples () |
Returns the max possible delay samples. For INTERNAL memory, the delay can be equal to the full maxValue specified. For EXTERNAL memory, the max delay is actually one audio block less then the full size to prevent wrapping. More... | |
bool | getSamples (audio_block_t *dest, size_t offsetSamples, size_t numSamples=AUDIO_SAMPLES_PER_BLOCK) |
Retrieve an audio block (or samples) from the buffer into a destination block. More... | |
bool | getSamples (int16_t *dest, size_t offsetSamples, size_t numSamples) |
Retrieve an audio block (or samples) from the buffer into a destination sample array. More... | |
bool | interpolateDelay (int16_t *extendedSourceBuffer, int16_t *destBuffer, float fraction, size_t numSamples=AUDIO_SAMPLES_PER_BLOCK) |
Provides linearly interpolated samples between discrete samples in the sample buffer. The SOURCE buffer MUST BE OVERSIZED to numSamples+1. This is because the last output sample is interpolated from between NUM_SAMPLES and NUM_SAMPLES+1. More... | |
SramMemSlot * | getSlot () const |
When using EXTERNAL memory, this function can return a pointer to the underlying baCore::ExtMemSlot object associated with the buffer. More... | |
bool | setSpiDmaCopyBuffer (void) |
Calling this function will force the underlying SPI DMA to use an extra copy buffer. This is needed if the user audio buffers are not guarenteed to be cache aligned. More... | |
RingBuffer< audio_block_t * > * | getRingBuffer () const |
When using INTERNAL memory, this function can return a pointer to the underlying baCore::RingBuffer that contains audio_block_t * pointers. More... | |
Audio delays are a very common function in audio processing.
In addition to being used for simply create a delay effect, it can also be used for buffering a sliding window in time of audio samples. This is useful when combining several audio_block_t data buffers together to form one large buffer for FFTs, etc.
The buffer works like a queue. You add new audio_block_t when available, and the class will return an old buffer when it is to be discarded from the queue.
Note that using INTERNAL memory means the class will only store a queue of pointers to audio_block_t buffers, since the Teensy Audio uses a shared memory approach. When using EXTERNAL memory, data is actually copyied to/from an external SRAM device.
Aviate::AudioDelay::AudioDelay | ( | size_t | maxSamples | ) |
Construct an audio buffer using INTERNAL memory by specifying the max number of audio samples you will want.
maxSamples | equal or greater than your longest delay requirement |
Aviate::AudioDelay::AudioDelay | ( | float | maxDelayTimeMs | ) |
Construct an audio buffer using INTERNAL memory by specifying the max amount of time you will want available in the buffer.
maxDelayTimeMs | max length of time you want in the buffer specified in milliseconds |
Aviate::AudioDelay::AudioDelay | ( | SramMemSlot * | slot | ) |
Construct an audio buffer using a slot configured with the baCore::ExternalSramManager.
slot | a pointer to the slot representing the memory you wish to use for the buffer. |
audio_block_t* Aviate::AudioDelay::addBlock | ( | audio_block_t * | blockIn | ) |
Add a new audio block into the buffer. When the buffer is filled, adding a new block will push out the oldest once which is returned.
blockIn | pointer to the most recent block of audio |
audio_block_t* Aviate::AudioDelay::getBlock | ( | size_t | index | ) |
When using INTERNAL memory, returns the pointer for the specified index into buffer.
, the most recent block is 0, 2nd most recent is 1, ..., etc.
index | the specifies how many buffers older than the current to retrieve |
size_t Aviate::AudioDelay::getMaxDelaySamples | ( | ) |
Returns the max possible delay samples. For INTERNAL memory, the delay can be equal to the full maxValue specified. For EXTERNAL memory, the max delay is actually one audio block less then the full size to prevent wrapping.
RingBuffer<audio_block_t*>* Aviate::AudioDelay::getRingBuffer | ( | ) | const |
When using INTERNAL memory, this function can return a pointer to the underlying baCore::RingBuffer that contains audio_block_t * pointers.
bool Aviate::AudioDelay::getSamples | ( | audio_block_t * | dest, |
size_t | offsetSamples, | ||
size_t | numSamples = AUDIO_SAMPLES_PER_BLOCK |
||
) |
Retrieve an audio block (or samples) from the buffer into a destination block.
when using INTERNAL memory, only supported size is AUDIO_SAMPLES_PER_BLOCK. When using EXTERNAL, a size smaller than AUDIO_SAMPLES_PER_BLOCK can be requested.
dest | pointer to the target audio block to write the samples to. |
offsetSamples | data will start being transferred offset samples from the start of the audio buffer |
numSamples | default value is AUDIO_SAMPLES_PER_BLOCK, so typically you don't have to specify this parameter. |
bool Aviate::AudioDelay::getSamples | ( | int16_t * | dest, |
size_t | offsetSamples, | ||
size_t | numSamples | ||
) |
Retrieve an audio block (or samples) from the buffer into a destination sample array.
when using INTERNAL memory, only supported size is AUDIO_SAMPLES_PER_BLOCK. When using EXTERNAL, a size smaller than AUDIO_SAMPLES_PER_BLOCK can be requested.
dest | pointer to the target sample array to write the samples to. |
offsetSamples | data will start being transferred offset samples from the start of the audio buffer |
numSamples | number of samples to transfer |
SramMemSlot* Aviate::AudioDelay::getSlot | ( | ) | const |
When using EXTERNAL memory, this function can return a pointer to the underlying baCore::ExtMemSlot object associated with the buffer.
bool Aviate::AudioDelay::interpolateDelay | ( | int16_t * | extendedSourceBuffer, |
int16_t * | destBuffer, | ||
float | fraction, | ||
size_t | numSamples = AUDIO_SAMPLES_PER_BLOCK |
||
) |
Provides linearly interpolated samples between discrete samples in the sample buffer. The SOURCE buffer MUST BE OVERSIZED to numSamples+1. This is because the last output sample is interpolated from between NUM_SAMPLES and NUM_SAMPLES+1.
this function is typically not used with audio blocks directly since you need AUDIO_SAMPLES_PER_BLOCK+1 as the source size even though output size is still only AUDIO_SAMPLES_PER_BLOCK. Manually create an oversized buffer and fill it with AUDIO_SAMPLES_PER_BLOCK+1. e.g. 129 instead of 128 samples. The destBuffer does not need to be oversized.
extendedSourceBuffer | A source array that contains one more input sample than output samples needed. |
destBuffer | pointer to the target sample array to write the samples to. |
fraction | a value between 0.0f and 1.0f that sets the interpolation point between the discrete samples. |
numSamples | number of samples to transfer |
bool Aviate::AudioDelay::setSpiDmaCopyBuffer | ( | void | ) |
Calling this function will force the underlying SPI DMA to use an extra copy buffer. This is needed if the user audio buffers are not guarenteed to be cache aligned.