|
arduino-audio-tools
|
Variable speed ring buffer with 180-degree phase shifting. More...
#include <PitchShift.h>
Public Member Functions | |
| VariableSpeedRingBuffer180 (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 operation not supported in this buffer implementation. | |
| bool | read (T &result) |
| Read the next pitch-shifted sample. | |
| 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 and recalculate overlap region. | |
| void | setIncrement (float increment) |
| Set the pitch shift factor. | |
| 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 Member Functions | |
| virtual T | pitchRead () |
| Core pitch shifting algorithm with 180° phase offset blending. | |
Protected Attributes | |
| Vector< T > | buffer {0} |
| int | buffer_size = 0 |
| float | cross_fade = 1.0 |
| int | overlap = 0 |
| float | pitch_shift = 0 |
| float | read_pos_float = 0.0 |
| int | write_pointer = 0 |
| int | write_pos = 0 |
Variable speed ring buffer with 180-degree phase shifting.
Advanced buffer implementation that reads with 0° and 180° phase offsets and blends the results to prevent overrun artifacts. This technique reduces audio artifacts when read and write pointers collide by cross-fading between two read positions that are 180° apart (half buffer apart).
Based on the algorithm described at: https://github.com/YetAnotherElectronicsChannel/STM32_DSP_PitchShift
| T | The sample data type (typically int16_t or float) |
|
inline |
Constructor.
| size | Initial buffer size (0 means no allocation yet) |
| increment | Pitch shift factor (1.0 = no change, >1.0 = higher pitch) |
returns the address of the start of the physical read buffer
Implements BaseBuffer< T >.
provides the number of entries that are available to read
Implements BaseBuffer< T >.
provides the number of entries that are available to write
Implements BaseBuffer< T >.
Removes the next len entries.
Reimplemented in SingleBuffer< T >, SingleBuffer< float >, SingleBuffer< int16_t >, SingleBuffer< int32_t >, SingleBuffer< stsz_sample_size_t >, SingleBuffer< T >, SingleBuffer< uint32_t >, and SingleBuffer< uint8_t >.
checks if the buffer is full
Reimplemented from BaseBuffer< T >.
Returns the level of the buffer in %.
Peek operation not supported in this buffer implementation.
| result | Unused parameter |
Implements BaseBuffer< T >.
Core pitch shifting algorithm with 180° phase offset blending.
This method implements the heart of the pitch shifting algorithm:
The 180° offset ensures that when one read pointer collides with the write pointer, the other is safely away, allowing smooth transition.
Read the next pitch-shifted sample.
| result | Reference to store the processed sample |
Implements BaseBuffer< T >.
reads multiple values
Reimplemented in RingBufferFile< File, T >, BufferRTOS< T >, SynchronizedBuffer< T >, RedisBuffer< T >, BufferRP2040T< T >, NBufferFile< File, T >, and DynamicMultiBuffer< T, BufferType >.
Reset pointer positions and clear buffer.
Implements BaseBuffer< T >.
Resize the internal buffer and recalculate overlap region.
| size | New buffer size in samples |
Reimplemented from BaseBuffer< T >.
Set the pitch shift factor.
| increment | Pitch shift multiplier (1.0 = no change, >1.0 = higher pitch, <1.0 = lower pitch) |
Implements BaseBuffer< T >.
Write a sample to the buffer.
| sample | The sample value to write |
Implements BaseBuffer< T >.
Fills the buffer data.
Reimplemented in BufferRTOS< T >, SynchronizedBuffer< T >, RedisBuffer< T >, BufferRP2040T< T >, SingleBuffer< T >, SingleBuffer< T >, RingBufferFile< File, T >, NBufferFile< File, T >, and DynamicMultiBuffer< T, BufferType >.
Fills the buffer data and overwrites the oldest data if the buffer is full.