arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
VariableSpeedRingBufferSimple< T > Class Template Reference

Very Simple Buffer implementation for Pitch Shift. More...

#include <PitchShift.h>

Inheritance diagram for VariableSpeedRingBufferSimple< T >:
BaseBuffer< T >

Public Member Functions

 VariableSpeedRingBufferSimple (int size=0, float increment=1.0)
 Constructor.
 
virtual T * address ()
 returns the address of the start of the physical read buffer
 
virtual int available ()
 provides the number of entries that are available to read
 
virtual int availableForWrite ()
 provides the number of entries that are available to write
 
void clear ()
 same as reset
 
virtual int clearArray (int len)
 Removes the next len entries.
 
bool isEmpty ()
 
virtual bool isFull ()
 checks if the buffer is full
 
virtual float levelPercent ()
 Returns the level of the buffer in %.
 
bool peek (T &result)
 Peek at the current sample without advancing the read pointer.
 
bool read (T &result)
 Read the next sample and advance the read pointer.
 
virtual int readArray (T data[], int len)
 reads multiple values
 
void reset ()
 Reset pointer positions and clear buffer.
 
bool resize (int size)
 Resize the internal buffer.
 
void setIncrement (float increment)
 Set the reading speed increment.
 
size_t size ()
 
bool write (T sample)
 Write a sample to the buffer.
 
virtual int writeArray (const T data[], int len)
 Fills the buffer data.
 
virtual int writeArrayOverwrite (const T data[], int len)
 Fills the buffer data and overwrites the oldest data if the buffer is full.
 

Protected Attributes

Vector< T > buffer {0}
 
int buffer_size = 0
 
float read_increment = 1.0
 
float read_pos_float = 0.0
 
int write_pos = 0
 

Detailed Description

template<typename T>
class audio_tools::VariableSpeedRingBufferSimple< T >

Very Simple Buffer implementation for Pitch Shift.

This buffer writes samples at constant speed but allows reading at variable speed to achieve pitch shifting. The reading speed is controlled by the increment parameter. When read and write pointers overlap, some audio artifacts (noise) may be audible.

Warning
This is a basic implementation that may produce audible artifacts during pointer overruns. For better quality, consider using VariableSpeedRingBuffer180 or VariableSpeedRingBuffer.
Template Parameters
TThe sample data type (typically int16_t or float)

Constructor & Destructor Documentation

◆ VariableSpeedRingBufferSimple()

template<typename T >
VariableSpeedRingBufferSimple ( int  size = 0,
float  increment = 1.0 
)
inline

Constructor.

Parameters
sizeInitial buffer size (0 means no allocation yet)
incrementReading speed multiplier (1.0 = normal speed, >1.0 = faster reading for higher pitch)

Member Function Documentation

◆ address()

template<typename T >
virtual T * address ( )
inlinevirtual

returns the address of the start of the physical read buffer

Implements BaseBuffer< T >.

◆ available()

template<typename T >
virtual int available ( )
inlinevirtual

provides the number of entries that are available to read

Implements BaseBuffer< T >.

◆ availableForWrite()

template<typename T >
virtual int availableForWrite ( )
inlinevirtual

provides the number of entries that are available to write

Implements BaseBuffer< T >.

◆ clearArray()

template<typename T >
virtual int clearArray ( int  len)
inlinevirtualinherited

◆ isFull()

template<typename T >
virtual bool isFull ( )
inlinevirtual

checks if the buffer is full

Reimplemented from BaseBuffer< T >.

◆ peek()

template<typename T >
bool peek ( T &  result)
inlinevirtual

Peek at the current sample without advancing the read pointer.

Parameters
resultReference to store the sample value
Returns
true if successful

Implements BaseBuffer< T >.

◆ read()

template<typename T >
bool read ( T &  result)
inlinevirtual

Read the next sample and advance the read pointer.

Parameters
resultReference to store the read sample value
Returns
true if successful

Read the next sample and advance the read pointer

Parameters
resultReference to store the read sample value
Returns
true if successful

Implements BaseBuffer< T >.

◆ readArray()

template<typename T >
virtual int readArray ( data[],
int  len 
)
inlinevirtualinherited

◆ reset()

template<typename T >
void reset ( )
inlinevirtual

Reset pointer positions and clear buffer.

Implements BaseBuffer< T >.

◆ resize()

template<typename T >
bool resize ( int  size)
inlinevirtual

Resize the internal buffer.

Parameters
sizeNew buffer size in samples
Returns
true if successful, false on memory allocation failure

Reimplemented from BaseBuffer< T >.

◆ setIncrement()

template<typename T >
void setIncrement ( float  increment)
inline

Set the reading speed increment.

Parameters
incrementReading speed multiplier (1.0 = normal, >1.0 = faster for higher pitch)

◆ size()

template<typename T >
size_t size ( )
inlinevirtual

Implements BaseBuffer< T >.

◆ write()

template<typename T >
bool write ( sample)
inlinevirtual

Write a sample to the buffer.

Parameters
sampleThe sample value to write
Returns
true if successful, false if buffer is not allocated

Implements BaseBuffer< T >.

◆ writeArray()

template<typename T >
virtual int writeArray ( const T  data[],
int  len 
)
inlinevirtualinherited

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