minilogue xd SDK  v1.1-0
Public Member Functions | Public Attributes | List of all members
dsp::DelayLine Struct Reference

Basic delay line abstraction. More...

#include <delayline.hpp>

Public Member Functions

 DelayLine (void)
 Default constructor.
 
 DelayLine (float *ram, size_t line_size)
 Constructor with explicit memory area to use as backing buffer for delay line. More...
 
void clear (void)
 Zero clear the whole delay line.
 
void setMemory (float *ram, size_t line_size)
 Set the memory area to use as backing buffer for the delay line. More...
 
void write (const float s)
 Write a single sample to the head of the delay line. More...
 
float read (const uint32_t pos)
 Read a single sample from the delay line at given position from current write index. More...
 
float readFrac (const float pos)
 Read a sample from the delay line at a fractional position from current write index. More...
 
float readFracz (const uint32_t pos, const float frac)
 Read a sample from the delay line at a position from current write index with interpolation from last read. More...
 

Public Attributes

float * mLine
 
float mFracZ
 
size_t mSize
 
size_t mMask
 
uint32_t mWriteIdx
 

Detailed Description

Basic delay line abstraction.

Definition at line 56 of file delayline.hpp.

Constructor & Destructor Documentation

◆ DelayLine()

dsp::DelayLine::DelayLine ( float *  ram,
size_t  line_size 
)
inline

Constructor with explicit memory area to use as backing buffer for delay line.

Parameters
ramPointer to memory buffer
line_sizeSize in float of memory buffer

Definition at line 84 of file delayline.hpp.

84  :
85  mLine(ram),
86  mFracZ(0),
87  mSize(line_size),
88  mMask(line_size-1),
89  mWriteIdx(0)
90  { }

Member Function Documentation

◆ read()

float dsp::DelayLine::read ( const uint32_t  pos)
inline

Read a single sample from the delay line at given position from current write index.

Parameters
posOffset from write index
Returns
Sample at given position from write index

Definition at line 137 of file delayline.hpp.

137  {
138  return mLine[(mWriteIdx + pos) & mMask];
139  }

◆ readFrac()

float dsp::DelayLine::readFrac ( const float  pos)
inline

Read a sample from the delay line at a fractional position from current write index.

Parameters
posOffset from write index as floating point.
Returns
Interpolated sample at given fractional position from write index

Definition at line 148 of file delayline.hpp.

148  {
149  const uint32_t base = (uint32_t)pos;
150  const float frac = pos - base;
151  const float s0 = read(base);
152  const float s1 = read(base+1);
153  return linintf(frac, s0, s1);
154  }

◆ readFracz()

float dsp::DelayLine::readFracz ( const uint32_t  pos,
const float  frac 
)
inline

Read a sample from the delay line at a position from current write index with interpolation from last read.

Parameters
posOffset from write index
fracInterpolation from last read pair.
Returns
Interpolation of last read sample and sample at given position from write index.

Definition at line 164 of file delayline.hpp.

164  {
165  const float s0 = read(pos);
166  const float y = linintf(frac, s0, mFracZ);
167  mFracZ = s0;
168  return y;
169  }

◆ setMemory()

void dsp::DelayLine::setMemory ( float *  ram,
size_t  line_size 
)
inline

Set the memory area to use as backing buffer for the delay line.

Parameters
ramPointer to memory buffer
line_sizeSize in float of memory buffer
Note
Will round size to next power of two.

Definition at line 113 of file delayline.hpp.

113  {
114  mLine = ram;
115  mSize = nextpow2_u32(line_size); // must be power of 2
116  mMask = (mSize-1);
117  mWriteIdx = 0;
118  }

◆ write()

void dsp::DelayLine::write ( const float  s)
inline

Write a single sample to the head of the delay line.

Parameters
sSample to write

Definition at line 126 of file delayline.hpp.

126  {
127  mLine[(mWriteIdx--) & mMask] = s;
128  }

The documentation for this struct was generated from the following file:
nextpow2_u32
static uint32_t nextpow2_u32(uint32_t x)
Compute next power of 2 greater than x.
Definition: int_math.h:117
dsp::DelayLine::read
float read(const uint32_t pos)
Read a single sample from the delay line at given position from current write index.
Definition: delayline.hpp:137
linintf
static float linintf(const float fr, const float x0, const float x1)
Linear interpolation.
Definition: float_math.h:824