Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
staffpad::audio::CircularSampleBuffer< SampleT > Class Template Reference

#include <CircularSampleBuffer.h>

Inheritance diagram for staffpad::audio::CircularSampleBuffer< SampleT >:
[legend]

Public Member Functions

 CircularSampleBuffer ()
 
 ~CircularSampleBuffer ()
 
void setSize (int n)
 
int getAllocatedSize () const
 
void reset ()
 
void write (int offset, const SampleT &sample)
 
void writeOffset0 (const SampleT &sample)
 
const SampleT & read (int offset) const
 
void advance (int n)
 change the 0 position by n More...
 
void writeBlock (int startOffset, int n, const SampleT *sourceBlock)
 
void readBlockWithGain (int startOffset, int n, SampleT *targetBlock, float gainFactor) const
 
void readAddBlockWithGain (int startOffset, int n, SampleT *targetBlock, float gainFactor) const
 
void writeAddBlockWithGain (int startOffset, int n, const SampleT *sourceBlock, float gainFactor)
 
void readBlock (int startOffset, int n, SampleT *targetBlock) const
 
void readAndClearBlock (int startOffset, int n, SampleT *targetBlock)
 
void clearBlock (int startOffset, int n)
 

Private Member Functions

template<typename fnc >
void _splitBlockOffsetFunction (int startOffset, int n, fnc f) const
 

Private Attributes

SampleT * _buffer = nullptr
 
int _position0 = 0
 
int _allocatedSize = 0
 
int _bufferSizeMask = 0
 

Detailed Description

template<typename SampleT>
class staffpad::audio::CircularSampleBuffer< SampleT >

Definition at line 16 of file CircularSampleBuffer.h.

Constructor & Destructor Documentation

◆ CircularSampleBuffer()

template<typename SampleT >
staffpad::audio::CircularSampleBuffer< SampleT >::CircularSampleBuffer ( )
inline

Definition at line 19 of file CircularSampleBuffer.h.

20 {
21 }

◆ ~CircularSampleBuffer()

template<typename SampleT >
staffpad::audio::CircularSampleBuffer< SampleT >::~CircularSampleBuffer ( )
inline

Definition at line 23 of file CircularSampleBuffer.h.

24 {
25 if (_buffer)
27 }
void free(void *ptr)
Definition: VectorOps.h:34

References staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, and staffpad::vo::free().

Here is the call graph for this function:

Member Function Documentation

◆ _splitBlockOffsetFunction()

template<typename SampleT >
template<typename fnc >
void staffpad::audio::CircularSampleBuffer< SampleT >::_splitBlockOffsetFunction ( int  startOffset,
int  n,
fnc  f 
) const
inlineprivate

Definition at line 88 of file CircularSampleBuffer.h.

89 {
90 assert(n <= _allocatedSize);
91 int firstIndex = (_position0 + startOffset) & _bufferSizeMask;
92 int n_to_end = _allocatedSize - firstIndex;
93 if (n_to_end > n)
94 {
95 f(firstIndex, 0, n);
96 }
97 else
98 {
99 f(firstIndex, 0, n_to_end);
100 f(0, n_to_end, n - n_to_end);
101 }
102 }

References staffpad::audio::CircularSampleBuffer< SampleT >::_allocatedSize, staffpad::audio::CircularSampleBuffer< SampleT >::_bufferSizeMask, and staffpad::audio::CircularSampleBuffer< SampleT >::_position0.

Referenced by staffpad::audio::CircularSampleBuffer< SampleT >::clearBlock(), staffpad::audio::CircularSampleBuffer< SampleT >::readAddBlockWithGain(), staffpad::audio::CircularSampleBuffer< SampleT >::readAndClearBlock(), staffpad::audio::CircularSampleBuffer< SampleT >::readBlock(), staffpad::audio::CircularSampleBuffer< SampleT >::readBlockWithGain(), staffpad::audio::CircularSampleBuffer< SampleT >::writeAddBlockWithGain(), and staffpad::audio::CircularSampleBuffer< SampleT >::writeBlock().

Here is the caller graph for this function:

◆ advance()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::advance ( int  n)
inline

◆ clearBlock()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::clearBlock ( int  startOffset,
int  n 
)
inline

Definition at line 148 of file CircularSampleBuffer.h.

149 {
150 _splitBlockOffsetFunction(startOffset, n,
151 [=](int bufferOff, int sampleOff, int n) { vo::setToZero(&_buffer[bufferOff], n); });
152 }
void _splitBlockOffsetFunction(int startOffset, int n, fnc f) const
void setToZero(T *dst, int32_t n)
Definition: VectorOps.h:81

References staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, staffpad::audio::CircularSampleBuffer< SampleT >::_splitBlockOffsetFunction(), and staffpad::vo::setToZero().

Here is the call graph for this function:

◆ getAllocatedSize()

template<typename SampleT >
int staffpad::audio::CircularSampleBuffer< SampleT >::getAllocatedSize ( ) const
inline

◆ read()

template<typename SampleT >
const SampleT & staffpad::audio::CircularSampleBuffer< SampleT >::read ( int  offset) const
inline

◆ readAddBlockWithGain()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::readAddBlockWithGain ( int  startOffset,
int  n,
SampleT *  targetBlock,
float  gainFactor 
) const
inline

Definition at line 119 of file CircularSampleBuffer.h.

120 {
121 _splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
122 vo::constantMultiplyAndAdd(&_buffer[bufferOff], gainFactor, &targetBlock[sampleOff], n);
123 });
124 }
void constantMultiplyAndAdd(const T *src, T constant, T *dst, int32_t n)
Definition: VectorOps.h:67

References staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, staffpad::audio::CircularSampleBuffer< SampleT >::_splitBlockOffsetFunction(), and staffpad::vo::constantMultiplyAndAdd().

Here is the call graph for this function:

◆ readAndClearBlock()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::readAndClearBlock ( int  startOffset,
int  n,
SampleT *  targetBlock 
)
inline

Definition at line 140 of file CircularSampleBuffer.h.

141 {
142 _splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
143 vo::copy(&_buffer[bufferOff], &targetBlock[sampleOff], n);
144 vo::setToZero(&_buffer[bufferOff], n);
145 });
146 }
void copy(const T *src, T *dst, int32_t n)
Definition: VectorOps.h:40

References staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, staffpad::audio::CircularSampleBuffer< SampleT >::_splitBlockOffsetFunction(), staffpad::vo::copy(), and staffpad::vo::setToZero().

Here is the call graph for this function:

◆ readBlock()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::readBlock ( int  startOffset,
int  n,
SampleT *  targetBlock 
) const
inline

Definition at line 133 of file CircularSampleBuffer.h.

134 {
135 _splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
136 vo::copy(&_buffer[bufferOff], &targetBlock[sampleOff], n);
137 });
138 }

References staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, staffpad::audio::CircularSampleBuffer< SampleT >::_splitBlockOffsetFunction(), and staffpad::vo::copy().

Here is the call graph for this function:

◆ readBlockWithGain()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::readBlockWithGain ( int  startOffset,
int  n,
SampleT *  targetBlock,
float  gainFactor 
) const
inline

Definition at line 112 of file CircularSampleBuffer.h.

113 {
114 _splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
115 vo::constantMultiply(&_buffer[bufferOff], gainFactor, &targetBlock[sampleOff], n);
116 });
117 }
void constantMultiply(const T *src, T constant, T *dst, int32_t n)
Definition: VectorOps.h:60

References staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, staffpad::audio::CircularSampleBuffer< SampleT >::_splitBlockOffsetFunction(), and staffpad::vo::constantMultiply().

Here is the call graph for this function:

◆ reset()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::reset ( )
inline

◆ setSize()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::setSize ( int  n)
inline

Definition at line 29 of file CircularSampleBuffer.h.

30 {
31 if (n > _allocatedSize)
32 {
33 auto oldSize = _allocatedSize;
34
35 auto findLargerPowerOfTwo = [](int32_t number) {
36 int32_t powerOf2 = 1;
37 while (powerOf2 < number)
38 powerOf2 *= 2;
39 return powerOf2;
40 };
41
42 _allocatedSize = findLargerPowerOfTwo(n);
44 _buffer = (SampleT*)std::realloc(_buffer, _allocatedSize * sizeof(SampleT));
45
46 // Reset the new memory region
47 assert(_buffer);
48 std::fill(_buffer + oldSize, _buffer + _allocatedSize, 0.f);
49 }
50 }

References staffpad::audio::CircularSampleBuffer< SampleT >::_allocatedSize, staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, and staffpad::audio::CircularSampleBuffer< SampleT >::_bufferSizeMask.

◆ write()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::write ( int  offset,
const SampleT &  sample 
)
inline

◆ writeAddBlockWithGain()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::writeAddBlockWithGain ( int  startOffset,
int  n,
const SampleT *  sourceBlock,
float  gainFactor 
)
inline

Definition at line 126 of file CircularSampleBuffer.h.

127 {
128 _splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
129 vo::constantMultiplyAndAdd(&sourceBlock[sampleOff], gainFactor, &_buffer[bufferOff], n);
130 });
131 }

References staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, staffpad::audio::CircularSampleBuffer< SampleT >::_splitBlockOffsetFunction(), and staffpad::vo::constantMultiplyAndAdd().

Here is the call graph for this function:

◆ writeBlock()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::writeBlock ( int  startOffset,
int  n,
const SampleT *  sourceBlock 
)
inline

Definition at line 105 of file CircularSampleBuffer.h.

106 {
107 _splitBlockOffsetFunction(startOffset, n, [=](int bufferOff, int sampleOff, int n) {
108 vo::copy(&sourceBlock[sampleOff], &_buffer[bufferOff], n);
109 });
110 }

References staffpad::audio::CircularSampleBuffer< SampleT >::_buffer, staffpad::audio::CircularSampleBuffer< SampleT >::_splitBlockOffsetFunction(), and staffpad::vo::copy().

Here is the call graph for this function:

◆ writeOffset0()

template<typename SampleT >
void staffpad::audio::CircularSampleBuffer< SampleT >::writeOffset0 ( const SampleT &  sample)
inline

Member Data Documentation

◆ _allocatedSize

template<typename SampleT >
int staffpad::audio::CircularSampleBuffer< SampleT >::_allocatedSize = 0
private

◆ _buffer

template<typename SampleT >
SampleT* staffpad::audio::CircularSampleBuffer< SampleT >::_buffer = nullptr
private

◆ _bufferSizeMask

template<typename SampleT >
int staffpad::audio::CircularSampleBuffer< SampleT >::_bufferSizeMask = 0
private

◆ _position0

template<typename SampleT >
int staffpad::audio::CircularSampleBuffer< SampleT >::_position0 = 0
private

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