Vital
Loading...
Searching...
No Matches
vital::MemoryTemplate< kChannels > Class Template Reference

A template for a memory buffer that stores time-domain samples for one or more channels. More...

#include <memory.h>

Public Member Functions

 MemoryTemplate (int size)
 Constructs the memory with a given size (rounded up to a power of two).
 
 MemoryTemplate (const MemoryTemplate &other)
 Copy constructor.
 
virtual ~MemoryTemplate ()
 Destructor.
 
void push (poly_float sample)
 Pushes a poly_float of samples (one sample per channel) into the memory.
 
void clearMemory (int num, poly_mask clear_mask)
 Clears a specified number of samples in the memory for channels indicated by a mask.
 
void clearAll ()
 Clears all samples in the memory for all channels.
 
void readSamples (mono_float *output, int num_samples, int offset, int channel) const
 Reads samples from the memory into an output buffer.
 
unsigned int getOffset () const
 Gets the current offset (write position) in the buffer.
 
void setOffset (int offset)
 Sets the current offset (write position) in the buffer.
 
int getSize () const
 Gets the size of the memory buffer.
 
int getMaxPeriod () const
 Gets the maximum allowed period for reading samples.
 

Static Public Attributes

static constexpr mono_float kMinPeriod = 2.0f
 Minimum allowed period of time delay.
 
static constexpr int kExtraInterpolationValues = 3
 Extra values to support cubic interpolation.
 

Protected Attributes

std::unique_ptr< mono_float[]> memories_ [kChannels]
 Unique pointers to each channel's buffer.
 
mono_floatbuffers_ [kChannels]
 Raw pointers to each channel buffer.
 
unsigned int size_
 The size of the memory buffer.
 
unsigned int bitmask_
 Bitmask for efficient modulo operations.
 
unsigned int offset_
 Current write offset in the buffer.
 

Detailed Description

template<size_t kChannels>
class vital::MemoryTemplate< kChannels >

A template for a memory buffer that stores time-domain samples for one or more channels.

MemoryTemplate provides a ring buffer of samples. Samples can be pushed into the buffer and later retrieved based on a certain delay or offset. It supports clearing sections of the buffer and ensures that size is always a power-of-two for indexing efficiency.

Template Parameters
kChannelsThe number of channels stored in the memory.

Constructor & Destructor Documentation

◆ MemoryTemplate() [1/2]

template<size_t kChannels>
vital::MemoryTemplate< kChannels >::MemoryTemplate ( int size)
inline

Constructs the memory with a given size (rounded up to a power of two).

Parameters
sizeThe desired size of the memory buffer.

◆ MemoryTemplate() [2/2]

template<size_t kChannels>
vital::MemoryTemplate< kChannels >::MemoryTemplate ( const MemoryTemplate< kChannels > & other)
inline

Copy constructor.

Parameters
otherAnother MemoryTemplate to copy from.

◆ ~MemoryTemplate()

template<size_t kChannels>
virtual vital::MemoryTemplate< kChannels >::~MemoryTemplate ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ clearAll()

template<size_t kChannels>
void vital::MemoryTemplate< kChannels >::clearAll ( )
inline

Clears all samples in the memory for all channels.

◆ clearMemory()

template<size_t kChannels>
void vital::MemoryTemplate< kChannels >::clearMemory ( int num,
poly_mask clear_mask )
inline

Clears a specified number of samples in the memory for channels indicated by a mask.

Parameters
numThe number of samples to clear.
clear_maskA poly_mask indicating which channels to clear.

◆ getMaxPeriod()

template<size_t kChannels>
int vital::MemoryTemplate< kChannels >::getMaxPeriod ( ) const
inline

Gets the maximum allowed period for reading samples.

Returns
The maximum period that can be addressed.

◆ getOffset()

template<size_t kChannels>
unsigned int vital::MemoryTemplate< kChannels >::getOffset ( ) const
inline

Gets the current offset (write position) in the buffer.

Returns
The current write offset.

◆ getSize()

template<size_t kChannels>
int vital::MemoryTemplate< kChannels >::getSize ( ) const
inline

Gets the size of the memory buffer.

Returns
The size of the memory buffer.

◆ push()

template<size_t kChannels>
void vital::MemoryTemplate< kChannels >::push ( poly_float sample)
inline

Pushes a poly_float of samples (one sample per channel) into the memory.

Parameters
sampleThe sample to push for each channel (interleaved in poly_float).

◆ readSamples()

template<size_t kChannels>
void vital::MemoryTemplate< kChannels >::readSamples ( mono_float * output,
int num_samples,
int offset,
int channel ) const
inline

Reads samples from the memory into an output buffer.

Parameters
outputPointer to the output array to fill.
num_samplesNumber of samples to read.
offsetThe offset (delay) from the current write position.
channelThe channel to read from.

◆ setOffset()

template<size_t kChannels>
void vital::MemoryTemplate< kChannels >::setOffset ( int offset)
inline

Sets the current offset (write position) in the buffer.

Parameters
offsetThe new offset.

Member Data Documentation

◆ bitmask_

template<size_t kChannels>
unsigned int vital::MemoryTemplate< kChannels >::bitmask_
protected

Bitmask for efficient modulo operations.

◆ buffers_

template<size_t kChannels>
mono_float* vital::MemoryTemplate< kChannels >::buffers_[kChannels]
protected

Raw pointers to each channel buffer.

◆ kExtraInterpolationValues

template<size_t kChannels>
int vital::MemoryTemplate< kChannels >::kExtraInterpolationValues = 3
staticconstexpr

Extra values to support cubic interpolation.

◆ kMinPeriod

template<size_t kChannels>
mono_float vital::MemoryTemplate< kChannels >::kMinPeriod = 2.0f
staticconstexpr

Minimum allowed period of time delay.

◆ memories_

template<size_t kChannels>
std::unique_ptr<mono_float[]> vital::MemoryTemplate< kChannels >::memories_[kChannels]
protected

Unique pointers to each channel's buffer.

◆ offset_

template<size_t kChannels>
unsigned int vital::MemoryTemplate< kChannels >::offset_
protected

Current write offset in the buffer.

◆ size_

template<size_t kChannels>
unsigned int vital::MemoryTemplate< kChannels >::size_
protected

The size of the memory buffer.


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