CSL
6.0
|
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys). More...
#include <CSL_Core.h>
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 SampleBuffer * | buffers () |
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... | |
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.
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().
|
virtual |
Destructor de-allocated.
Definition at line 59 of file CSL_Core.cpp.
References freeBuffers(), and mDidIAllocateBuffers.
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::setSize | ( | unsigned | numChannels, |
unsigned | numFrames | ||
) |
Definition at line 75 of file CSL_Core.cpp.
References freeBuffers(), mAreBuffersAllocated, mBuffers, mDidIAllocateBuffers, mIsPopulated, mMonoBufferByteSize, mNumAlloc, mNumChannels, and mNumFrames.
Referenced by csl::Mixer::allocateOpBuffer(), CSLServerComponent::audioDeviceIOCallback(), CSLMIDIComponent::audioDeviceIOCallback(), CSLAbstComponent::audioDeviceIOCallback(), csl::BlockResizer::BlockResizer(), Buffer(), csl::IO::capture_off(), csl::IO::capture_on(), csl::Abst_SoundFile::checkBuffer(), csl::Port::checkBuffer(), csl::DelayLine::DelayLine(), csl::WavetableOscillator::fillSine(), csl::KarplusString::initDelayLine(), csl::PAIO::initialize(), csl::WaveShaper::initWaveTable(), csl::FileIO::open(), csl::VSTIO::processReplacing(), csl::Window::setSize(), csl::SpatialPanner::SpatialPanner(), and csl::WavetableOscillator::WavetableOscillator().
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().
void Buffer::allocateBuffers | ( | ) | ||
throw | ( | MemoryError | ||
) |
fcn to malloc storage buffers
Definition at line 122 of file CSL_Core.cpp.
References csl::logMsg(), mAreBuffersAllocated, mBuffers, mDidIAllocateBuffers, mNumAlloc, mNumChannels, mNumFrames, and SAFE_MALLOC.
Referenced by csl::UnitGenerator::addOutput(), csl::Mixer::allocateOpBuffer(), csl::BinauralPanner::BinauralPanner(), csl::BlockResizer::BlockResizer(), csl::IO::capture_on(), csl::Abst_SoundFile::checkBuffer(), csl::Port::checkBuffer(), checkBuffers(), csl::CompOrCacheOscillator::createCache(), csl::FFT::FFT(), csl::WavetableOscillator::fillSine(), csl::Filter::init(), csl::RemoteIO::init_io(), csl::KarplusString::initDelayLine(), csl::AmbisonicMixer::initialize(), csl::WaveShaper::initWaveTable(), csl::Abst_SoundFile::mergeToMono(), csl::FileIO::open(), csl::PAIO::open(), csl::Port::Port(), CSLServerComponent::recordOnOff(), CSLAbstComponent::recordOnOff(), CSLComponent::recordOnOff(), csl::RingBuffer::RingBuffer(), csl::Window::setSize(), csl::SpatialPanner::SpatialPanner(), and csl::PAIO::test().
void Buffer::freeBuffers | ( | ) |
fcn to free them
Definition at line 141 of file CSL_Core.cpp.
References csl::kLogError, csl::logMsg(), mAreBuffersAllocated, mBuffers, mDidIAllocateBuffers, mMonoBufferByteSize, mNumAlloc, mNumChannels, and mNumFrames.
Referenced by csl::Abst_SoundFile::checkBuffer(), csl::Port::checkBuffer(), csl::PAIO::close(), csl::FileIO::close(), csl::Abst_SoundFile::freeBuffer(), csl::FileIO::open(), csl::PAIO::open(), csl::Window::setSize(), setSize(), csl::WavetableOscillator::setWaveform(), csl::BlockResizer::~BlockResizer(), ~Buffer(), CSLAbstComponent::~CSLAbstComponent(), CSLComponent::~CSLComponent(), CSLServerComponent::~CSLServerComponent(), csl::Mixer::~Mixer(), csl::SpatialPanner::~SpatialPanner(), csl::WavetableOscillator::~WavetableOscillator(), and csl::Window::~Window().
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::zeroBuffers | ( | ) |
fill all data with 0
Definition at line 173 of file CSL_Core.cpp.
References mAreBuffersAllocated, mAreBuffersZero, mBuffers, mMonoBufferByteSize, and mNumChannels.
Referenced by csl::Filter::clear(), csl::AmbisonicEncoder::nextBuffer(), csl::Controllable::pullInput(), and csl::FileIO::writeNextBuffer().
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().
|
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.
|
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.
|
virtual |
convenience accessors for sample buffers
Reimplemented in csl::BufferCMap.
Definition at line 66 of file CSL_Core.cpp.
References mBuffers, and mNumChannels.
Referenced by CSLAbstComponent::audioDeviceIOCallback(), CSLComponent::audioDeviceIOCallback(), avg(), csl::Abst_SoundFile::buffer(), csl::CompOrCacheOscillator::createCache(), csl::WavetableOscillator::fillSine(), csl::Window::fillWindow(), csl::RectangularWindow::fillWindow(), csl::TriangularWindow::fillWindow(), csl::HammingWindow::fillWindow(), csl::HannWindow::fillWindow(), csl::BlackmanWindow::fillWindow(), csl::BlackmanHarrisWindow::fillWindow(), csl::WelchWindow::fillWindow(), csl::WaveShaper::initWaveTable(), max(), csl::Abst_SoundFile::mergeToMono(), min(), csl::InOut::nextBuffer(), csl::AmbisonicRotator::nextBuffer(), csl::AmbisonicEncoder::nextBuffer(), csl::AmbisonicDecoder::nextBuffer(), csl::Splitter::nextBuffer(), csl::Port::nextFrame(), csl::Port::Port(), csl::IntensityAttenuationCue::process(), csl::AirAbsorptionCue::process(), csl::VSTIO::processReplacing(), csl::Effect::pullInput(), csl::CASoundFile::readBufferFromFile(), csl::JSoundFile::readBufferFromFile(), csl::LSoundFile::readBufferFromFile(), RenderCallback(), csl::Port::resetPtr(), rms(), csl::WavetableOscillator::setWaveform(), csl::Window::window(), and csl::UnitGenerator::zeroBuffer().
|
inlinevirtual |
Definition at line 155 of file CSL_Core.h.
References mBuffers.
Referenced by csl::JSoundFile::readBufferFromFile(), and csl::WavetableOscillator::setWaveform().
|
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().
|
inlinevirtual |
Definition at line 158 of file CSL_Core.h.
References mBuffers.
Referenced by csl::JUCEIO::audioDeviceIOCallback(), CSLAbstComponent::audioDeviceIOCallback(), csl::WavetableOscillator::fillSine(), csl::HRTF::HRTF(), csl::Abst_SoundFile::mergeToMono(), csl::Joiner::nextBuffer(), csl::VSTIO::processReplacing(), csl::Convolver2::setIRData(), csl::WavetableOscillator::setWaveform(), testWaveTableFromFile(), and testWavetableInterpolation().
|
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.
unsigned csl::Buffer::mNumChannels |
num channels in buffer (num mono buffers)
Definition at line 112 of file CSL_Core.h.
Referenced by allocateBuffers(), avg(), buffer(), csl::Port::checkBuffer(), fillWith(), freeBuffers(), csl::AUIO::getInput(), csl::IO::getInput(), JackCallback(), max(), min(), csl::Port::nextFrame(), normalize(), RenderCallback(), rms(), scaleBy(), setSize(), setSizeOnly(), csl::WavetableOscillator::setWaveform(), and zeroBuffers().
unsigned csl::Buffer::mNumFrames |
num frames used in each buffer
Definition at line 113 of file CSL_Core.h.
Referenced by allocateBuffers(), csl::JUCEIO::audioDeviceIOCallback(), CSLServerComponent::audioDeviceIOCallback(), CSLAbstComponent::audioDeviceIOCallback(), CSLComponent::audioDeviceIOCallback(), avg(), canStore(), csl::Abst_SoundFile::checkBuffer(), csl::Port::checkBuffer(), csl::Abst_SoundFile::convertRate(), csl::CompOrCacheOscillator::createCache(), csl::RingBufferTap::duration(), duration(), fillWith(), freeBuffers(), csl::AUIO::getInput(), csl::IO::getInput(), csl::LSoundFile::isCached(), csl::Abst_SoundFile::isCached(), JackCallback(), max(), csl::Abst_SoundFile::mergeToMono(), min(), csl::AmbisonicRotator::nextBuffer(), csl::AmbisonicEncoder::nextBuffer(), csl::AmbisonicDecoder::nextBuffer(), normalize(), pa_callback(), csl::IntensityAttenuationCue::process(), csl::AirAbsorptionCue::process(), csl::Controllable::pullInput(), readFromFile(), CSLServerComponent::recordOnOff(), CSLAbstComponent::recordOnOff(), CSLComponent::recordOnOff(), RenderCallback(), rms(), scaleBy(), csl::RingBufferTap::setOffset(), setSize(), setSizeOnly(), csl::WavetableOscillator::setWaveform(), csl::WavetableOscillator::WavetableOscillator(), and csl::FileIO::writeNextBuffer().
unsigned csl::Buffer::mNumAlloc |
num frames in each buffer
Definition at line 114 of file CSL_Core.h.
Referenced by allocateBuffers(), csl::Abst_SoundFile::cacheSize(), canStore(), freeBuffers(), samplePtrFor(), setSize(), and csl::WavetableOscillator::setWaveform().
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::mAreBuffersAllocated |
are the buffers allocated?
Definition at line 120 of file CSL_Core.h.
Referenced by allocateBuffers(), csl::Abst_SoundFile::checkBuffer(), checkBuffers(), csl::PAIO::close(), csl::FileIO::close(), csl::WavetableOscillator::fillSine(), csl::Abst_SoundFile::freeBuffer(), freeBuffers(), csl::Abst_SoundFile::mergeToMono(), csl::FileIO::open(), csl::PAIO::open(), RenderCallback(), setSize(), csl::WavetableOscillator::setWaveform(), testWavetableInterpolation(), and zeroBuffers().
bool csl::Buffer::mDidIAllocateBuffers |
who allocated my data buffers?
Definition at line 121 of file CSL_Core.h.
Referenced by allocateBuffers(), csl::WavetableOscillator::fillSine(), freeBuffers(), load_filter_data(), csl::Abst_SoundFile::mergeToMono(), readFromFile(), RenderCallback(), setSize(), csl::WavetableOscillator::setWaveform(), and ~Buffer().
bool csl::Buffer::mIsPopulated |
does the buffer have data?
Definition at line 122 of file CSL_Core.h.
Referenced by csl::AmbisonicRotator::nextBuffer(), csl::AmbisonicEncoder::nextBuffer(), csl::AmbisonicDecoder::nextBuffer(), csl::Controllable::pullInput(), RenderCallback(), setSize(), and csl::WavetableOscillator::setWaveform().
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().
|
protected |
the storage vector – pointers to (SampleBuffer) buffers
Definition at line 182 of file CSL_Core.h.
Referenced by allocateBuffers(), CSLServerComponent::audioDeviceIOCallback(), CSLMIDIComponent::audioDeviceIOCallback(), avg(), buffer(), csl::BufferCMap::buffer(), buffers(), fillWith(), freeBuffers(), max(), min(), normalize(), RenderCallback(), rms(), samplePtrFor(), scaleBy(), setBuffer(), setBuffers(), setSize(), and zeroBuffers().