Mozzi  version v1.1.0
sound synthesis library for Arduino
AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE > Class Template Reference

Audio delay line with feedback for comb filter, flange, chorus and short echo effects. More...

#include <AudioDelayFeedback.h>

Public Member Functions

 AudioDelayFeedback ()
 Constructor.
 
 AudioDelayFeedback (uint16_t delaytime_cells)
 Constructor. More...
 
 AudioDelayFeedback (uint16_t delaytime_cells, int8_t feedback_level)
 Constructor. More...
 
int16_t next (int8_t input)
 Input a value to the delay and retrieve the signal in the delay line at the position delaytime_cells. More...
 
int16_t next (int8_t input, uint16_t delaytime_cells)
 Input a value to the delay, retrieve the signal in the delay line at the position delaytime_cells, and add feedback from the output to the input. More...
 
int16_t next (int8_t input, Q16n16 delaytime_cells)
 Input a value to the delay, retrieve the signal in the delay line at the interpolated fractional position delaytime_cells, and add feedback from the output to the input. More...
 
void write (int8_t input)
 Input a value to the delay but don't change the delay time or retrieve the output signal. More...
 
void writeFeedback (int8_t input)
 Input a value to the delay but don't advance the write position, change the delay time or retrieve the output signal. More...
 
void write (int8_t input, uint16_t offset)
 Input a value to the delay at an offset from the current write position. More...
 
int16_t read (Q16n16 delaytime_cells)
 Retrieve the signal in the delay line at the interpolated fractional position delaytime_cells. More...
 
int16_t read ()
 Retrieve the signal in the delay line at the current stored delaytime_cells. More...
 
void setDelayTimeCells (uint16_t delaytime_cells)
 Set delay time expressed in samples. More...
 
void setDelayTimeCells (Q16n16 delaytime_cells)
 Set delay time expressed in samples, fractional Q16n16 for an interpolating delay. More...
 
void setDelayTimeCells (float delaytime_cells)
 Set delay time expressed in samples, fractional float for an interpolating delay. More...
 
void setFeedbackLevel (int8_t feedback_level)
 Set the feedback gain. More...
 

Detailed Description

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
class AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >

Audio delay line with feedback for comb filter, flange, chorus and short echo effects.

Template Parameters
NUM_BUFFER_SAMPLESis the length of the delay buffer in samples, and should be a power of two. The maximum delay length which will fit in an atmega328 is half that of a plain AudioDelay object, in this case 256 cells, or about 15 milliseconds. AudioDelayFeedback uses int16_t sized cells to accomodate the higher amplitude of direct input to the delay as well as the feedback, without losing precision. Output is only the delay line signal. If you want to mix the delay with the input, do it in your sketch. AudioDelayFeedback uses more processing and memory than a plain AudioDelay, but allows for more dramatic effects with feedback.
INTERP_TYPEa choice of LINEAR (default) or ALLPASS interpolation. LINEAR is better for sweeping delay times, ALLPASS may be better for reverb-like effects.

Definition at line 40 of file AudioDelayFeedback.h.

Constructor & Destructor Documentation

◆ AudioDelayFeedback() [1/2]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::AudioDelayFeedback ( uint16_t  delaytime_cells)
inline

Constructor.

Parameters
delaytime_cellsdelay time expressed in cells. For example, 128 cells delay at AUDIO_RATE 16384 would produce a time delay of 128/16384 = 0.0078125 s = 7.8 ms Put another way, num_cells = delay_seconds * AUDIO_RATE.

Definition at line 55 of file AudioDelayFeedback.h.

◆ AudioDelayFeedback() [2/2]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::AudioDelayFeedback ( uint16_t  delaytime_cells,
int8_t  feedback_level 
)
inline

Constructor.

Parameters
delaytime_cellsdelay time expressed in cells. For example, 128 cells delay at AUDIO_RATE 16384 would produce a time delay of 128/16384 = 0.0078125 s = 7.8 ms Put another way, num_cells = delay_seconds * AUDIO_RATE.
feedback_levelis the feedback level from -128 to 127 (representing -1 to 1).

Definition at line 65 of file AudioDelayFeedback.h.

Member Function Documentation

◆ next() [1/3]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
int16_t AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::next ( int8_t  input)
inline

Input a value to the delay and retrieve the signal in the delay line at the position delaytime_cells.

Parameters
inputthe signal input.
Note
slower than next(int8_t input, uint16_t delaytime_cells)

Definition at line 75 of file AudioDelayFeedback.h.

◆ next() [2/3]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
int16_t AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::next ( int8_t  input,
uint16_t  delaytime_cells 
)
inline

Input a value to the delay, retrieve the signal in the delay line at the position delaytime_cells, and add feedback from the output to the input.

Parameters
inputthe signal input.
delaytime_cellsindicates the delay time in terms of cells in the delay buffer. It doesn't change the stored internal value of _delaytime_cells.
Note
Timing: 4us

Definition at line 92 of file AudioDelayFeedback.h.

◆ next() [3/3]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
int16_t AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::next ( int8_t  input,
Q16n16  delaytime_cells 
)
inline

Input a value to the delay, retrieve the signal in the delay line at the interpolated fractional position delaytime_cells, and add feedback from the output to the input.

Parameters
inputthe signal input.
delaytime_cellsis a fractional number to set the delay time in terms of cells or partial cells in the delay buffer. It doesn't change the stored internal value of _delaytime_cells.

Definition at line 117 of file AudioDelayFeedback.h.

◆ read() [1/2]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
int16_t AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::read ( Q16n16  delaytime_cells)
inline

Retrieve the signal in the delay line at the interpolated fractional position delaytime_cells.

It doesn't change the stored internal value of _delaytime_cells or feedback the output to the input.

Parameters
delaytime_cellsindicates the delay time in terms of cells in the delay buffer.

Definition at line 186 of file AudioDelayFeedback.h.

◆ read() [2/2]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
int16_t AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::read ( )
inline

Retrieve the signal in the delay line at the current stored delaytime_cells.

It doesn't change the stored internal value of _delaytime_cells or feedback the output to the input.

Definition at line 196 of file AudioDelayFeedback.h.

◆ setDelayTimeCells() [1/3]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
void AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::setDelayTimeCells ( uint16_t  delaytime_cells)
inline

Set delay time expressed in samples.

Parameters
delaytime_cellsdelay time expressed in cells, with each cell played per tick of AUDIO_RATE. For example, 128 cells delay at AUDIO_RATE would produce a time delay of 128/16384 = 0.0078125 s = 7.8 ms Put another way, num_cells = delay_seconds * AUDIO_RATE.

Definition at line 208 of file AudioDelayFeedback.h.

◆ setDelayTimeCells() [2/3]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
void AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::setDelayTimeCells ( Q16n16  delaytime_cells)
inline

Set delay time expressed in samples, fractional Q16n16 for an interpolating delay.

Parameters
delaytime_cellsdelay time expressed in cells, with each cell played per tick of AUDIO_RATE. For example, 128 cells delay at AUDIO_RATE would produce a time delay of 128/16384 = 0.0078125 s = 7.8 ms Put another way, num_cells = delay_seconds * AUDIO_RATE.

Definition at line 220 of file AudioDelayFeedback.h.

◆ setDelayTimeCells() [3/3]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
void AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::setDelayTimeCells ( float  delaytime_cells)
inline

Set delay time expressed in samples, fractional float for an interpolating delay.

Parameters
delaytime_cellsdelay time expressed in cells, with each cell played per tick of AUDIO_RATE. For example, 128 cells delay at AUDIO_RATE would produce a time delay of 128/16384 = 0.0078125 s = 7.8 ms Put another way, num_cells = delay_seconds * AUDIO_RATE.

Definition at line 232 of file AudioDelayFeedback.h.

◆ setFeedbackLevel()

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
void AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::setFeedbackLevel ( int8_t  feedback_level)
inline

Set the feedback gain.

Parameters
feedback_levelis the feedback level from -128 to 127 (representing -1 to 1).

Definition at line 242 of file AudioDelayFeedback.h.

◆ write() [1/2]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
void AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::write ( int8_t  input)
inline

Input a value to the delay but don't change the delay time or retrieve the output signal.

Parameters
inputthe signal input.

Definition at line 150 of file AudioDelayFeedback.h.

◆ write() [2/2]

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
void AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::write ( int8_t  input,
uint16_t  offset 
)
inline

Input a value to the delay at an offset from the current write position.

Don't advance the main write position or change the stored delay time or retrieve the output signal.

Parameters
inputthe signal input.
offsetthe number of cells behind the ordinary write position where the input will be written.

Definition at line 174 of file AudioDelayFeedback.h.

◆ writeFeedback()

template<uint16_t NUM_BUFFER_SAMPLES, int8_t INTERP_TYPE = LINEAR>
void AudioDelayFeedback< NUM_BUFFER_SAMPLES, INTERP_TYPE >::writeFeedback ( int8_t  input)
inline

Input a value to the delay but don't advance the write position, change the delay time or retrieve the output signal.

This can be useful for manually adding feedback to the delay line, "behind" the advancing write head.

Parameters
inputthe signal input.

Definition at line 162 of file AudioDelayFeedback.h.