CSL  6.0
csl::Buffer Class Reference

Buffer – the multi-channel sample buffer class (passed around between generators and IO guys). More...

#include <CSL_Core.h>

+ Inheritance diagram for csl::Buffer:

Public Member Functions

 Buffer (unsigned numChannels=1, unsigned numFrames=CSL_mBlockSize)
 Constructor: default is mono and default-size. More...
 
virtual ~Buffer ()
 Destructor de-allocated. More...
 
float duration ()
 answer the buffer's duration in seconds More...
 
void setSize (unsigned numChannels, unsigned numFrames)
 
void setSizeOnly (unsigned numChannels, unsigned numFrames)
 this version doesn't even allocate the pointers More...
 
void checkBuffers () throw (MemoryError)
 allocate if not already there More...
 
void allocateBuffers () throw (MemoryError)
 fcn to malloc storage buffers More...
 
void freeBuffers ()
 fcn to free them More...
 
bool canStore (unsigned numFrames)
 answer whether the recevei can store numFrames more frames More...
 
void zeroBuffers ()
 fill all data with 0 More...
 
void fillWith (sample value)
 fill data with the given value More...
 
void scaleBy (sample value)
 scale the samples by the given value More...
 
void copyFrom (Buffer &src) throw (RunTimeError)
 
void copyHeaderFrom (Buffer &source) throw (RunTimeError)
 copy the "header" fields of a buffer More...
 
void copySamplesFrom (Buffer &src) throw (RunTimeError)
 import data from the given buffer More...
 
void copySamplesFromTo (Buffer &src, unsigned offset) throw (RunTimeError)
 same with write offset More...
 
void copyOnlySamplesFrom (Buffer &src) throw (RunTimeError)
 import data from the given buffer More...
 
bool readFromFile (char *fname)
 read a buffer from a snd file; answer success More...
 
csl::Status convertRate (int fromRate, int toRate)
 convert the sample rate using libSampleRate More...
 
virtual SampleBuffer samplePtrFor (unsigned channel, unsigned offset)
 answer a samp ptr with offset More...
 
virtual SampleBuffer samplePtrFor (unsigned channel, unsigned offset, unsigned maxFrame)
 answer a samp ptr tested for extent (offset + maxFrame) More...
 
virtual SampleBuffer buffer (unsigned bufNum)
 convenience accessors for sample buffers More...
 
virtual SampleBufferbuffers ()
 
virtual void setBuffers (SampleBuffer *sPtr)
 Set the buffer pointer (rare; used in joiners) More...
 
virtual void setBuffer (unsigned bufNum, SampleBuffer sPtr)
 
virtual void setBuffer (unsigned bufNum, unsigned offset, sample samp)
 
float normalize (float maxVal)
 normalize the buffer(s) to the given max; answer the prior max More...
 
float normalize (float maxVal, float from, float to)
 normalize the given region only More...
 
float rms (unsigned chan, unsigned from, unsigned to)
 Buffer Sample Processing (optional). One could also easily add Buffer operators, such as (Buffer + Buffer) or (Buffer * Buffer) More...
 
float avg (unsigned chan, unsigned from, unsigned to)
 get the average of the samples More...
 
float max (unsigned chan, unsigned from, unsigned to)
 get the max of the absolute val of the samples More...
 
float min (unsigned chan, unsigned from, unsigned to)
 get the min of the samples More...
 

Public Attributes

unsigned mNumChannels
 num channels in buffer (num mono buffers) More...
 
unsigned mNumFrames
 num frames used in each buffer More...
 
unsigned mNumAlloc
 num frames in each buffer More...
 
unsigned mMonoBufferByteSize
 size of each buffer in bytes More...
 
unsigned mSequence
 sequential serial number More...
 
Timestamp mTimestamp
 the buffer's most recent timestamp More...
 
bool mAreBuffersAllocated
 are the buffers allocated? More...
 
bool mDidIAllocateBuffers
 who allocated my data buffers? More...
 
bool mIsPopulated
 does the buffer have data? More...
 
bool mAreBuffersZero
 have the buffers been zeroed out? More...
 
BufferContentType mType
 Data type flag set the internal size variables (no buffer allocation takes place) More...
 

Protected Attributes

SampleBufferVector mBuffers
 the storage vector – pointers to (SampleBuffer) buffers More...
 

Detailed Description

Buffer – the multi-channel sample buffer class (passed around between generators and IO guys).

Buffers have an opaque pointer () to their data () and know their # channels and frames. They have Boolean aspects about their buffer allocation, and can allocate, free, zero, and check their data.

Note that this is a "record" class in that its members are all public and it has no accessor functions or complicated methods. It does handle sample buffer allocation and has Boolean members to determine what its pointer state is.

Note also that Buffers are not thread-safe; they hand out pointers (sample*) that are assumed to be volatile.

Definition at line 106 of file CSL_Core.h.

Constructor & Destructor Documentation

Buffer::Buffer ( unsigned  numChannels = 1,
unsigned  numFrames = CSL_mBlockSize 
)

Constructor: default is mono and default-size.

Definition at line 42 of file CSL_Core.cpp.

References setSize().

Buffer::~Buffer ( )
virtual

Destructor de-allocated.

Definition at line 59 of file CSL_Core.cpp.

References freeBuffers(), and mDidIAllocateBuffers.

Member Function Documentation

float Buffer::duration ( )

answer the buffer's duration in seconds

Definition at line 114 of file CSL_Core.cpp.

References csl::CGestalt::frameRateF(), and mNumFrames.

void Buffer::setSizeOnly ( unsigned  numChannels,
unsigned  numFrames 
)

this version doesn't even allocate the pointers

Definition at line 99 of file CSL_Core.cpp.

References mMonoBufferByteSize, mNumChannels, and mNumFrames.

void Buffer::checkBuffers ( )
throw (MemoryError
)

allocate if not already there

Definition at line 107 of file CSL_Core.cpp.

References allocateBuffers(), and mAreBuffersAllocated.

Referenced by csl::VSTIO::processReplacing().

bool Buffer::canStore ( unsigned  numFrames)

answer whether the recevei can store numFrames more frames

Definition at line 197 of file CSL_Core.cpp.

References mNumAlloc, and mNumFrames.

void Buffer::fillWith ( sample  value)

fill data with the given value

Definition at line 203 of file CSL_Core.cpp.

References mAreBuffersZero, mBuffers, mNumChannels, and mNumFrames.

void Buffer::scaleBy ( sample  value)

scale the samples by the given value

Definition at line 219 of file CSL_Core.cpp.

References mAreBuffersZero, mBuffers, mNumChannels, and mNumFrames.

void Buffer::copyFrom ( Buffer src)
throw (RunTimeError
)

Definition at line 250 of file CSL_Core.cpp.

Referenced by csl::Abst_SoundFile::mergeToMono(), and readFromFile().

void Buffer::copyHeaderFrom ( Buffer source)
throw (RunTimeError
)

copy the "header" fields of a buffer

Definition at line 235 of file CSL_Core.cpp.

References csl::logMsg().

void Buffer::copySamplesFrom ( Buffer src)
throw (RunTimeError
)

import data from the given buffer

Definition at line 270 of file CSL_Core.cpp.

References csl_min, csl::kLogError, and csl::logMsg().

void Buffer::copySamplesFromTo ( Buffer src,
unsigned  offset 
)
throw (RunTimeError
)

same with write offset

Definition at line 300 of file CSL_Core.cpp.

References csl_min, csl::kLogError, and csl::logMsg().

void Buffer::copyOnlySamplesFrom ( Buffer src)
throw (RunTimeError
)

import data from the given buffer

same with write offset

Definition at line 286 of file CSL_Core.cpp.

References csl_min, csl::kLogError, and csl::logMsg().

Referenced by csl::FanOut::nextBuffer().

bool Buffer::readFromFile ( char *  fname)

read a buffer from a snd file; answer success

Definition at line 315 of file CSL_Core.cpp.

References copyFrom(), csl::kLogError, csl::logMsg(), mDidIAllocateBuffers, and mNumFrames.

csl::Status csl::Buffer::convertRate ( int  fromRate,
int  toRate 
)

convert the sample rate using libSampleRate

Referenced by csl::Abst_SoundFile::convertRate().

sample * Buffer::samplePtrFor ( unsigned  channel,
unsigned  offset 
)
virtual

answer a samp ptr with offset

answer a samp ptr tested for extent (offset + maxFrame)

Definition at line 183 of file CSL_Core.cpp.

References mBuffers.

sample * Buffer::samplePtrFor ( unsigned  channel,
unsigned  offset,
unsigned  maxFrame 
)
virtual

answer a samp ptr tested for extent (offset + maxFrame)

answer whether the receiver can store numFrames more frames

Definition at line 189 of file CSL_Core.cpp.

References mBuffers, and mNumAlloc.

virtual SampleBuffer* csl::Buffer::buffers ( )
inlinevirtual

Definition at line 155 of file CSL_Core.h.

References mBuffers.

Referenced by csl::JSoundFile::readBufferFromFile(), and csl::WavetableOscillator::setWaveform().

virtual void csl::Buffer::setBuffers ( SampleBuffer sPtr)
inlinevirtual

Set the buffer pointer (rare; used in joiners)

Definition at line 157 of file CSL_Core.h.

References mBuffers.

Referenced by csl::WavetableOscillator::setWaveform().

virtual void csl::Buffer::setBuffer ( unsigned  bufNum,
unsigned  offset,
sample  samp 
)
inlinevirtual

Definition at line 159 of file CSL_Core.h.

References mBuffers.

float Buffer::normalize ( float  maxVal)

normalize the buffer(s) to the given max; answer the prior max

Definition at line 348 of file CSL_Core.cpp.

References mBuffers, mNumChannels, and mNumFrames.

float Buffer::normalize ( float  maxVal,
float  from,
float  to 
)

normalize the given region only

Definition at line 377 of file CSL_Core.cpp.

References csl::CGestalt::frameRateF(), mBuffers, mNumChannels, and mNumFrames.

sample Buffer::rms ( unsigned  chan,
unsigned  from,
unsigned  to 
)

Buffer Sample Processing (optional). One could also easily add Buffer operators, such as (Buffer + Buffer) or (Buffer * Buffer)

< get the root-mean-square of the samples

get the root-mean-square of the samples

get the average of the samples

Definition at line 465 of file CSL_Core.cpp.

References buffer(), mBuffers, mNumChannels, and mNumFrames.

Referenced by test_convolution_file().

sample Buffer::avg ( unsigned  chan,
unsigned  from,
unsigned  to 
)

get the average of the samples

get the max of the samples

Definition at line 483 of file CSL_Core.cpp.

References buffer(), mBuffers, mNumChannels, and mNumFrames.

sample Buffer::max ( unsigned  chan,
unsigned  from,
unsigned  to 
)

get the max of the absolute val of the samples

get the min of the samples

Definition at line 495 of file CSL_Core.cpp.

References buffer(), mBuffers, mNumChannels, and mNumFrames.

sample Buffer::min ( unsigned  chan,
unsigned  from,
unsigned  to 
)

get the min of the samples

Definition at line 509 of file CSL_Core.cpp.

References buffer(), mBuffers, mNumChannels, and mNumFrames.

Member Data Documentation

unsigned csl::Buffer::mNumAlloc
unsigned csl::Buffer::mMonoBufferByteSize

size of each buffer in bytes

Definition at line 115 of file CSL_Core.h.

Referenced by freeBuffers(), setSize(), setSizeOnly(), csl::WavetableOscillator::setWaveform(), csl::UnitGenerator::zeroBuffer(), and zeroBuffers().

unsigned csl::Buffer::mSequence

sequential serial number

Definition at line 116 of file CSL_Core.h.

Timestamp csl::Buffer::mTimestamp

the buffer's most recent timestamp

Definition at line 117 of file CSL_Core.h.

bool csl::Buffer::mAreBuffersZero

have the buffers been zeroed out?

Definition at line 123 of file CSL_Core.h.

Referenced by fillWith(), scaleBy(), csl::WavetableOscillator::setWaveform(), and zeroBuffers().

BufferContentType csl::Buffer::mType

Data type flag set the internal size variables (no buffer allocation takes place)

Definition at line 124 of file CSL_Core.h.

Referenced by csl::BinauralPanner::BinauralPanner(), csl::AmbisonicRotator::nextBuffer(), csl::AmbisonicEncoder::nextBuffer(), csl::AmbisonicDecoder::nextBuffer(), and csl::Controllable::pullInput().


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