38 namespace cinder {
namespace audio {
75 std::memset(
mData.data(), 0,
mData.size() *
sizeof( T ) );
92 BufferT(
size_t numFrames = 0,
size_t numChannels = 1 )
113 void zero(
size_t startFrame,
size_t numFrames )
117 std::memset( &
getChannel( ch )[startFrame], 0, numFrames *
sizeof( T ) );
133 for(
size_t ch = 0; ch < numChannels; ch++ )
158 std::memmove( this->
getChannel( ch ) + frameOffset, other.
getChannel( ch ) + otherFrameOffset, numFrames *
sizeof( T ) );
170 template <
typename T>
177 void zero(
size_t startFrame,
size_t numFrames )
180 std::memset( &this->
mData[startFrame * this->
mNumChannels], 0, numFrames * this->mNumChannels *
sizeof( T ) );
188 template <
typename T>
206 template <
typename BufferTT>
210 BufferDynamicT(
size_t numFrames = 0,
size_t numChannels = 1 ) : BufferTT( numFrames, numChannels ),
211 mAllocatedSize( numFrames * numChannels )
215 void setSize(
size_t numFrames,
size_t numChannels )
217 this->mNumFrames = numFrames;
218 this->mNumChannels = numChannels;
225 this->mNumFrames = numFrames;
232 this->mNumChannels = numChannels;
239 mAllocatedSize = this->
getSize();
240 this->mData.resize( mAllocatedSize );
247 void resizeIfNecessary()
250 if( mAllocatedSize < size ) {
251 mAllocatedSize =
size;
252 this->mData.resize( mAllocatedSize );
256 size_t mAllocatedSize;
269 void *ptr = std::calloc( size,
sizeof( T ) );
276 return std::unique_ptr<T, FreeDeleter<T> >(
static_cast<T *
>( ptr ) );
const T * getData() const
Returns a const pointer to the first sample in the data buffer.
Definition: Buffer.h:58
BufferDynamicT< BufferInterleaved > BufferDynamicInterleaved
Definition: Buffer.h:290
std::shared_ptr< Buffer > BufferRef
Definition: Buffer.h:293
T * getChannel(size_t ch)
Returns a pointer offset to the first sample of channel ch.
Definition: Buffer.h:97
cinder::Vec2i getSize()
Definition: AppCocoaTouch.mm:978
T * getReal()
Returns a pointer to the first sample in the real component channel.
Definition: Buffer.h:195
const T * getReal() const
Returns a const pointer to the first sample in the real component channel.
Definition: Buffer.h:197
void zero(size_t startFrame, size_t numFrames)
Assigns zero to numFrames frames starting at startFrame.
Definition: Buffer.h:113
BufferInterleavedT(size_t numFrames=0, size_t numChannels=1)
Definition: Buffer.h:173
void copy(const BufferT< T > &other, size_t numFrames)
Definition: Buffer.h:139
void copy(const BufferT< T > &other)
Copies min( this, other ) channels and frames from other to internal storage.
Definition: Buffer.h:128
const T * getChannel(size_t ch) const
Returns a const pointer offset to the first sample of channel ch.
Definition: Buffer.h:104
void shrinkToFit()
Shrinks the allocated size to match the specified size, freeing any extra memory. ...
Definition: Buffer.h:237
std::shared_ptr< BufferDynamic > BufferDynamicRef
Definition: Buffer.h:296
BufferInterleavedT< float > BufferInterleaved
Definition: Buffer.h:286
void setSize(size_t numFrames, size_t numChannels)
Sets the new size of the buffer to numFrames number of frames and numChannels number of channels...
Definition: Buffer.h:215
void zeroChannel(size_t ch)
Assigns zero to all samples in channel channel.
Definition: Buffer.h:121
BufferT(size_t numFrames=0, size_t numChannels=1)
Constructs a BufferT object with numFrames number of frames (default = 0) and numChannels number of c...
Definition: Buffer.h:92
std::shared_ptr< BufferInterleaved > BufferInterleavedRef
Definition: Buffer.h:294
BufferDynamicT< Buffer > BufferDynamic
Definition: Buffer.h:289
std::unique_ptr< T, FreeDeleter< T > > makeAlignedArray(size_t size, size_t alignment=16)
Returns an array of size elements of type T, aligned by alignment.
Definition: Buffer.h:267
#define min(a, b)
Definition: AppImplMsw.cpp:36
size_t mNumChannels
Definition: Buffer.h:84
size_t getNumChannels() const
Returns the number of channels in the buffer.
Definition: Buffer.h:50
void zero(size_t startFrame, size_t numFrames)
Definition: Buffer.h:177
size_t getNumFrames() const
Returns the number of frames in the buffer.
Definition: Buffer.h:48
void setNumFrames(size_t numFrames)
Sets the new number of frames in the buffer to numFrames. Will only resize of the new size (frames * ...
Definition: Buffer.h:223
size_t getSize() const
Returns the total size of the buffer (frames * channels).
Definition: Buffer.h:52
BufferSpectralT< float > BufferSpectral
Definition: Buffer.h:287
GLenum GLint x
Definition: GLee.h:987
std::unique_ptr< float, FreeDeleter< float > > AlignedArrayPtr
Definition: Buffer.h:279
GLenum GLsizei n
Definition: GLee.h:5780
void setNumChannels(size_t numChannels)
Sets the new number of channels in the buffer to numChannels. Will only resize of the new size (frame...
Definition: Buffer.h:230
Audio buffer that stores its channels of type T contiguously (ie. the first sample of channel 1 is di...
Definition: Buffer.h:89
T SampleType
The compile-time defined type of samples contained in the buffer.
Definition: Buffer.h:45
BufferDynamicT(size_t numFrames=0, size_t numChannels=1)
Constructs a BufferDynamicT object with numFrames number of frames (default = 0) and numChannels numb...
Definition: Buffer.h:210
void copyChannel(size_t channel, const T *otherChannel)
Copies otherChannel to the internal channel channel. Assumes there is at least getNumFrames() samples...
Definition: Buffer.h:162
BufferDynamicT< BufferSpectral > BufferDynamicSpectral
Definition: Buffer.h:291
void operator()(T *x)
Definition: Buffer.h:262
const T * getImag() const
Returns a const pointer to the first sample in the imaginary component channel.
Definition: Buffer.h:202
std::vector< T > mData
Definition: Buffer.h:83
BufferSpectralT(size_t numFrames=0)
Constructs a BufferSpectralT object of frames numFrames. There is always two channels, where channel 0 is the real component and 1 is the imaginary component.
Definition: Buffer.h:192
int int channel
Definition: GLee.h:17150
void zero()
Sets all samples to the value zero.
Definition: Buffer.h:73
T * getData()
Returns a pointer to the first sample in the data buffer.
Definition: Buffer.h:56
A resizable BufferT. The internally allocated buffer will grow as needed, but it will not shrink unle...
Definition: Buffer.h:207
A buffer that contains frequency domain audio data.
Definition: Buffer.h:189
std::shared_ptr< BufferSpectral > BufferSpectralRef
Definition: Buffer.h:295
const T & operator[](size_t n) const
Definition: Buffer.h:66
size_t getAllocatedSize() const
Returns the number of samples allocated in this buffer (may be larger than getSize()).
Definition: Buffer.h:244
size_t mNumFrames
Definition: Buffer.h:84
void copyOffset(const BufferT< T > &other, size_t numFrames, size_t frameOffset, size_t otherFrameOffset)
Definition: Buffer.h:151
BufferT< float > Buffer
Definition: Buffer.h:285
T * getImag()
Returns a pointer to the first sample in the imaginary component channel.
Definition: Buffer.h:200
Audio buffer that stores its channels of type T in one interleaved array (ie. the first sample of cha...
Definition: Buffer.h:171
std::shared_ptr< BufferDynamicSpectral > BufferDynamicSpectralRef
Definition: Buffer.h:298
BufferBaseT(size_t numFrames, size_t numChannels)
Definition: Buffer.h:79
Base class for the various Buffer classes. The template parameter T defined the sample type (precisio...
Definition: Buffer.h:42
GLsizeiptr size
Definition: GLee.h:2089
std::unique_ptr< double, FreeDeleter< double > > AlignedArrayPtrd
Definition: Buffer.h:280
bool isEmpty() const
Returns true if number of frames is zero, false otherwise.
Definition: Buffer.h:54
#define CI_ASSERT_MSG(expr, msg)
Definition: CinderAssert.h:76
std::shared_ptr< BufferDynamicInterleaved > BufferDynamicInterleavedRef
Definition: Buffer.h:297
#define CI_ASSERT(expr)
Definition: CinderAssert.h:75
Simple functor wrapping free(), suitable for unique_ptr's that allocate memory with malloc...
Definition: Buffer.h:261
T & operator[](size_t n)
Definition: Buffer.h:60