MostlyHarmless 0.0.1
 
Loading...
Searching...
No Matches
marvin::containers::FixedCircularBuffer< T, N > Class Template Referencefinal

A simple fixed length circular buffer. More...

#include <marvin_FixedCircularBuffer.h>

Public Member Functions

 FixedCircularBuffer ()
 
void push (T toPush)
 
peek (size_t offset) const
 
void reset ()
 

Detailed Description

template<FloatType T, size_t N>
class marvin::containers::FixedCircularBuffer< T, N >

A simple fixed length circular buffer.

Very similar functionally to marvin::dsp::DelayLine, but with a fixed length, and no interpolation. Useful for a situation where you just need a KISS circular buffer. 99% of the time, for a delay effect, you're much better off using marvin::dsp::DelayLine instead.
Usage Example:

using namespace marvin::literals;
constexpr static auto size{ 1024 };
constexpr static auto delay{ 4 }; // 4 samples delay
std::vector<float> impulse(size, 0.0f);
impulse.front() = 1.0f; // [1, 0, 0, 0, 0 ......]
std::vector<float> delayBuffer{};
for(auto i = 0_sz; i < size; ++i) {
const auto delayed = circularBuffer.peek(delay);
circularBuffer.push(impulse[i]);
delayBuffer.emplace_back(delayed);
}
assert(delayBuffer[delay] == 1.0f); // [0, 0, 0, 0, 1, 0, 0 ......]
FixedCircularBuffer()
Definition marvin_FixedCircularBuffer.h:44

Constructor & Destructor Documentation

◆ FixedCircularBuffer()

template<FloatType T, size_t N>
marvin::containers::FixedCircularBuffer< T, N >::FixedCircularBuffer ( )
inline

Constructs a FixedCircularBuffer N points long, and zeroes the internal buffer.

Member Function Documentation

◆ peek()

template<FloatType T, size_t N>
T marvin::containers::FixedCircularBuffer< T, N >::peek ( size_t offset) const
inlinenodiscard

Retrieves an element at the specified offset from the write index into the buffer - this offset can be though of as the "delay time" in a delay-line context.

Parameters
offsetThe number of samples behind the write index to read from.
Returns
The element at the specified offset.

◆ push()

template<FloatType T, size_t N>
void marvin::containers::FixedCircularBuffer< T, N >::push ( T toPush)
inline

Emplaces a sample into the internal buffer, and increments the write index, wrapping around if necessary.

Parameters
toPushThe value to emplace into the circular buffer.

◆ reset()

template<FloatType T, size_t N>
void marvin::containers::FixedCircularBuffer< T, N >::reset ( )
inline

Zeroes the internal buffer, and resets the write index back to 0.


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