Namespace : DadDSP::cDelayLine Files : cDelayLine.h / cDelayLine.cpp Directory : DAD_FORGE/DSP Description : Implementation of a delay line (FIFO buffer) for digital signal processing, including audio effects and temporal modifications.
📋 Class Description
The cDelayLine class is a fundamental structure for Digital Signal Processing (DSP), designed as a circular buffer (FIFO - First In, First Out) allowing temporary storage of audio samples. It provides essential functionalities for temporal effects such as echo, reverberation, and flanging.
This class efficiently manages a circular buffer that allows:
Sequential storage of incoming audio samples
Retrieval of samples with different timed delays
Linear interpolation for non-integer (fractional) delays
Automatic buffer wrapping without data loss
🎯 Associated Enumerations and Structures
No associated enumerations or structures.
📚 Public Methods
cDelayLine
Element
Details
Method
cDelayLine()
Description
Default constructor for the cDelayLine class. Initializes data members to their default values (nullptr for the buffer, 0 for counters). Allows object instantiation without external memory allocation.
~cDelayLine
Element
Details
Method
~cDelayLine()
Description
Default destructor for the cDelayLine class. Releases resources associated with the object (note: the buffer itself is not dynamically allocated by this class, so no explicit release is necessary).
Initializes the delay line with an external memory buffer provided. Configures the circular buffer by defining a pointer to the memory address of the buffer and its size. Automatically calls Clear() to initialize the content to zero before use. Useful when the buffer is already allocated elsewhere in the system (e.g., dynamic allocation or global buffer).
Parameter(s)
Â
buffer
Pointer to an array of floating-point numbers (float*) containing the memory buffer where audio samples will be stored. The buffer must be pre-allocated with sufficient size.
bufferSize
Buffer size in number of samples (uint32_t). Determines the maximum storage capacity and the maximum possible delay of the delay line.
Return
No return value (void).
Clear
Element
Details
Method
void Clear()
Description
Completely empties the buffer by setting all values to zero. Uses memset for a fast and efficient operation. Useful for resetting the delay line between two audio processing segments or when it is necessary to eliminate any residual content from the buffer.
Parameter(s)
None.
Return
No return value (void).
Push
Element
Details
Method
void Push(float inputSample)
Description
Adds a new audio sample to the delay line. The sample is stored in the circular buffer at the current position, then the current index is incremented with automatic wrapping. This method represents the data entry (input stream) into the FIFO system.
Parameter(s)
Â
inputSample
Floating-point audio sample (float) to add to the buffer. Value is generally between -1.0 and 1.0 for normalized audio signals.
Return
No return value (void).
Pull
Element
Details
Method
float Pull(uint32_t delay)
Description
Retrieves an audio sample from the buffer with a fixed integer delay in number of samples. Uses circular wrapping to calculate the correct output index. Returns the sample directly without interpolation, ideal for precise and deterministic delays.
Parameter(s)
Â
delay
Delay in number of samples (uint32_t). Determines how many previous samples will be retrieved. Must be less than the buffer size for correct operation.
Return
Floating-point audio sample (float) representing the sample with the specified delay, or 0.0f if the buffer is not initialized.
Pull
Element
Details
Method
float Pull(float delay)
Description
Retrieves an audio sample with linear interpolation for fractional (non-integer) delays. Allows for precise and smooth temporal shifts, essential for effects like flanger or chorus. Calculates the interpolation between two adjacent buffer samples.
Parameter(s)
Â
delay
Delay in floating-point number of samples (float). Can contain a fractional part (e.g., 45.7) to achieve precise delays beyond single-sample resolution.
Return
Floating-point audio sample (float) linearly interpolated between the two adjacent samples, or 0.0f if the buffer is not initialized.
🔒 Protected / Private Methods
No protected or private methods.
📦 Data Members (Variables)
Public Variables
No public variables.
Protected / Private Variables
Member
Type
Description
m_Buffer
float*
Pointer to the allocated memory buffer (external or internal). Stores audio samples in a circular structure. Initialized to nullptr by default, must be initialized via Initialize().
m_NumElements
int32_t
Number of elements in the buffer. Represents the buffer size and serves as a limit for circular wrapping operations. Initialized to 0 by default.
m_CurrentIndex
int32_t
Current index (zero delay position). Points to the most recent write location in the circular buffer. Incremented upon each Push() call with automatic wrapping.
💡 Usage Example
#include"DadDSP/cDelayLine.h"intmain(){// Configuration: Buffer size = 4410 samples (~50ms at 44.1kHz)constuint32_tBUFFER_SIZE=4410;// Dynamic allocation of the audio bufferfloat*delayBuffer=newfloat[BUFFER_SIZE];// Initialization of the delay lineDadDSP::cDelayLinedelayLine;delayLine.Initialize(delayBuffer,BUFFER_SIZE);// Audio processing - sample loopfor(int32_tsample=0;sample<44100;sample++){// Input audio sample (e.g., from microphone or file)floatinputSample=GetAudioInput(sample);// Add the sample to the delay linedelayLine.Push(inputSample);// Retrieve the sample with a delay of 20 samples (~0.45ms)floatdelayedSample=delayLine.Pull(20u);// Mix direct signal and delayed signal (slapback effect)floatoutputSample=inputSample*0.7f+delayedSample*0.3f;// Additional processing...ProcessAudioOutput(outputSample,sample);}// Cleanup - interpolation for fractional delay (e.g., 25.5 samples)delayLine.Initialize(delayBuffer,BUFFER_SIZE);for(int32_tsample=0;sample<44100;sample++){delayLine.Push(inputSample);// Delay with interpolation for smoother effectfloatfractionalDelay=25.5f;floatinterpolatedOutput=delayLine.Pull(fractionalDelay);}// Resource releasedelete[]delayBuffer;return0;}
DAD_FORGE/DSP - Dad Design DSP Library Copyright (c) 2024-2026 Dad Design.