Aviate Audio Multiverse Library
Public Member Functions | List of all members
Aviate::AudioDelay Class Reference

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...
 
SramMemSlotgetSlot () 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ AudioDelay() [1/3]

Aviate::AudioDelay::AudioDelay ( size_t  maxSamples)

Construct an audio buffer using INTERNAL memory by specifying the max number of audio samples you will want.

Parameters
maxSamplesequal or greater than your longest delay requirement

◆ AudioDelay() [2/3]

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.

Parameters
maxDelayTimeMsmax length of time you want in the buffer specified in milliseconds

◆ AudioDelay() [3/3]

Aviate::AudioDelay::AudioDelay ( SramMemSlot slot)

Construct an audio buffer using a slot configured with the baCore::ExternalSramManager.

Parameters
slota pointer to the slot representing the memory you wish to use for the buffer.

Member Function Documentation

◆ addBlock()

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.

Parameters
blockInpointer to the most recent block of audio
Returns
the buffer to be discarded, or nullptr if not filled (INTERNAL), or not applicable (EXTERNAL).

◆ getBlock()

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.

Parameters
indexthe specifies how many buffers older than the current to retrieve
Returns
a pointer to the requested audio_block_t

◆ getMaxDelaySamples()

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.

Returns
the maximum delay offset in units of samples.

◆ getRingBuffer()

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.

Returns
pointer to the underlying baCore::RingBuffer

◆ getSamples() [1/2]

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.

Parameters
destpointer to the target audio block to write the samples to.
offsetSamplesdata will start being transferred offset samples from the start of the audio buffer
numSamplesdefault value is AUDIO_SAMPLES_PER_BLOCK, so typically you don't have to specify this parameter.
Returns
true on success, false on error.

◆ getSamples() [2/2]

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.

Parameters
destpointer to the target sample array to write the samples to.
offsetSamplesdata will start being transferred offset samples from the start of the audio buffer
numSamplesnumber of samples to transfer
Returns
true on success, false on error.

◆ getSlot()

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.

Returns
pointer to the underlying baCore::ExtMemSlot.

◆ interpolateDelay()

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.

Parameters
extendedSourceBufferA source array that contains one more input sample than output samples needed.
destBufferpointer to the target sample array to write the samples to.
fractiona value between 0.0f and 1.0f that sets the interpolation point between the discrete samples.
numSamplesnumber of samples to transfer
Returns
true on success, false on error.

◆ setSpiDmaCopyBuffer()

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.

Returns
true if suceess, false if an error occurs

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