21 #include <samplerate.h>
30 #ifdef WIN32 // Windows doesn't have rintf
31 #define rint(x) ((int)(x + 0.5f))
46 mMonoBufferByteSize(0),
48 mAreBuffersAllocated(false),
49 mDidIAllocateBuffers(false),
51 mAreBuffersZero(true),
54 setSize(numChannels, numFrames);
123 #ifdef FVERBOSE_MALLOC
148 #ifdef FVERBOSE_MALLOC
158 }
catch (std::exception ex) {
204 float * bbuffer = NULL;
206 unsigned outBufNum, i;
209 for (outBufNum = 0; outBufNum < numChans; outBufNum++) {
211 for (i = 0; i < numFrames; i++)
220 float * bbuffer = NULL;
222 unsigned outBufNum, i;
225 for (outBufNum = 0; outBufNum < numChans; outBufNum++) {
227 for (i = 0; i < numFrames; i++)
236 if ((source.mNumChannels > mNumChannels) || (source.mNumFrames > mNumAlloc)) {
237 logMsg(
"Buffer::copyHeaderFrom(ch %d %d, fr %d %d)",
238 mNumChannels, source.mNumChannels, mNumAlloc, source.mNumFrames);
239 throw RunTimeError(
"Can't reallocate buffers at run-time");
241 mNumChannels = source.mNumChannels;
242 mNumFrames = source.mNumFrames;
243 mMonoBufferByteSize = mNumFrames *
sizeof(
sample);
244 mSequence = source.mSequence;
245 mType = source.mType;
253 mNumChannels = source.mNumChannels;
254 mNumFrames = source.mNumFrames;
255 mNumAlloc = source.mNumAlloc;
256 mMonoBufferByteSize = mNumFrames *
sizeof(
sample);
257 mSequence = source.mSequence;
260 for (
unsigned outBufNum = 0; outBufNum < mNumChannels; outBufNum++) {
261 mBuffers[outBufNum] = source.buffer(outBufNum);
263 mAreBuffersZero =
false;
264 mAreBuffersAllocated =
true;
265 mDidIAllocateBuffers =
false;
271 if ((source.mNumChannels > mNumChannels) || (source.mNumFrames > mNumAlloc)) {
273 mNumChannels, source.mNumChannels, mNumAlloc, source.mNumFrames);
274 throw RunTimeError(
"Can't reallocate buffers at run-time");
276 mNumChannels = source.mNumChannels;
277 mNumFrames = source.mNumFrames;
278 mMonoBufferByteSize = mNumFrames *
sizeof(
sample);
279 for (
unsigned outBufNum = 0; outBufNum < mNumChannels; outBufNum++) {
280 unsigned sBufNum =
csl_min(outBufNum, (source.mNumChannels - 1));
281 memcpy(mBuffers[outBufNum], source.buffer(sBufNum), mMonoBufferByteSize);
283 mAreBuffersZero =
false;
287 if ((source.mNumChannels > mNumChannels) || (source.mNumFrames > mNumAlloc)) {
289 mNumChannels, source.mNumChannels, mNumFrames, source.mNumFrames);
290 throw RunTimeError(
"Can't reallocate buffers at run-time");
292 for (
unsigned outBufNum = 0; outBufNum < mNumChannels; outBufNum++) {
293 unsigned sBufNum =
csl_min(outBufNum, (source.mNumChannels - 1));
294 memcpy(mBuffers[outBufNum], source.buffer(sBufNum), mMonoBufferByteSize);
301 if ((source.mNumChannels > mNumChannels) || ((offset + source.mNumFrames) > mNumAlloc)) {
303 mNumChannels, source.mNumChannels, mNumFrames, source.mNumFrames);
304 throw RunTimeError(
"Can't reallocate buffers at run-time");
306 for (
unsigned outBufNum = 0; outBufNum < mNumChannels; outBufNum++) {
307 unsigned sBufNum =
csl_min(outBufNum, (source.mNumChannels - 1));
308 memcpy(mBuffers[outBufNum] + offset, source.buffer(sBufNum),
309 (source.mNumFrames *
sizeof(
sample)));
316 if (strlen(finam) == 0) {
322 SoundFile * inFile = SoundFile::openSndfile(finam);
324 if ( ! inFile->isValid()) {
332 inFile->mWavetable.mDidIAllocateBuffers =
false;
349 float * bbuffer = NULL;
350 unsigned outBufNum, i;
353 float maxSamp = 0.0f;
354 for (outBufNum = 0; outBufNum < numChans; outBufNum++) {
356 for (i = 0; i < numFrames; i++) {
357 float samp = fabs(*bbuffer++);
364 float scaleV = maxVal / maxSamp;
365 for (outBufNum = 0; outBufNum < numChans; outBufNum++) {
367 for (i = 0; i < numFrames; i++) {
378 float * bbuffer = NULL;
379 unsigned outBufNum, i;
382 float maxSamp = 0.0f;
386 for (outBufNum = 0; outBufNum < numChans; outBufNum++) {
387 bbuffer =
mBuffers[outBufNum] + samp0;
388 for (i = samp0; i < sampN; i++) {
389 float samp = fabs(*bbuffer++);
396 if (maxSamp == maxVal)
398 float scaleV = maxVal / maxSamp;
399 for (outBufNum = 0; outBufNum < numChans; outBufNum++) {
400 bbuffer =
mBuffers[outBufNum] + samp0;
401 for (i = samp0; i < sampN; i++) {
409 #ifdef USE_SRC // sample-rate conversion methods
414 double src_ratio = (double) toRate / (
double) fromRate;
417 unsigned newLen = (unsigned) (rint(((
double)
mNumFrames) * src_ratio));
418 SRC_STATE * src_state;
426 src_ratio = (double) toRate / (
double) fromRate;
427 if (src_is_valid_ratio (src_ratio) == 0) {
432 if ((src_state = src_new (SRC_SINC_FASTEST , 1, &error)) == NULL) {
433 logMsg (
"Error : src_new() failed : %s.", src_strerror (error));
436 src_data.src_ratio = src_ratio;
438 src_data.output_frames = newLen;
439 src_data.end_of_input = 1;
443 src_data.data_out = newBuf->
buffer(i);
445 error = src_process(src_state, &src_data);
447 logMsg(
"SRC Error : %s", src_strerror(error));
451 src_state = src_delete (src_state);
471 for (
unsigned i = from; i < to; i++) {
473 if (isnan(val))
continue;
474 if (isinf(val))
continue;
488 for (
unsigned i = 0; i < numFrames; i++)
490 return sum / numFrames;
500 for (
unsigned i = 0; i < numFrames; i++) {
502 if (fabs(val) > tmax) tmax - fabs(val);
514 for (
unsigned i = 0; i < numFrames; i++) {
516 if (fabs(val) > tmax) tmax - fabs(val);
521 #ifdef CSL_DSP_BUFFER
527 unsigned int Buffer::zeroX(
unsigned chan) {
529 unsigned numFrames =
mNumFrames, count = 0, sign = 0;
532 for (
unsigned i = 0; i < numFrames; i++) {
534 if (((val > 0) && sign) || ((val < 0) && ! sign)) {
544 unsigned int Buffer::indexOfPeak(
unsigned chan) {
547 sample val, tmax = -1000000.0;
549 for (
unsigned i = 0; i < numFrames; i++) {
561 unsigned int Buffer::indexOfPeak(
unsigned chan,
unsigned lo,
unsigned hi) {
563 sample val, tmax = -100000.0;
565 for (
unsigned i = lo; i < hi; i++) {
577 unsigned int Buffer::indexOfMin(
unsigned chan) {
580 sample val, tmin = 1000000.0;
582 for (
unsigned i = 0; i < numFrames; i++) {
594 unsigned int Buffer::indexOfMin(
unsigned chan,
unsigned lo,
unsigned hi) {
596 sample val, tmin = 1000000.0;
598 for (
unsigned i = lo; i < hi; i++) {
610 void Buffer::autocorrelation(
unsigned chan,
SampleBuffer result) {
616 SPautoc (buffer, numFrames, result, numFrames);
619 #endif // CSL_DSP_BUFFER
628 Buffer(numChannels, numFrames),
629 mRealNumChannels(numChannels) { }
632 Buffer(numChannels, numFrames),
633 mRealNumChannels(realNumChannels) { }
643 #pragma mark UnitGenerator
664 float * buffer = outputBuffer.
buffer(outBufNum);
681 UGenVector::iterator pos;
700 if (mNumOutputs > 1) {
701 if (outputBuffer.mSequence <= mSequence) {
703 outputBuffer.copyOnlySamplesFrom(*mOutputCache);
715 mOutputCache->copySamplesFrom(outputBuffer);
716 mSequence =
csl_max(mSequence, outputBuffer.mSequence);
727 unsigned numOutputChannels = outputBuffer.mNumChannels;
728 unsigned bufferByteSize = outputBuffer.mMonoBufferByteSize;
731 logMsg(
"UnitGenerator::nextBuffer");
733 if (checkFanOut(outputBuffer))
return;
735 switch (mCopyPolicy) {
738 this->nextBuffer(outputBuffer, 0);
739 for (
unsigned i = 1; i < numOutputChannels; i += mNumChannels)
740 memcpy (outputBuffer.buffer(i), buffer0, bufferByteSize);
743 for (
unsigned i = 0; i < numOutputChannels; i += mNumChannels)
744 nextBuffer(outputBuffer, i);
747 this->nextBuffer(outputBuffer, 0);
750 handleFanOut(outputBuffer);
756 for (
unsigned i = 0; i < mNumChannels; i++)
757 zeroBuffer(outputBuffer, i);
801 throw LogicError(
"Checking an unassigned buffer");
830 fprintf(stderr,
"\t");
842 for (PortMap::iterator pos =
mInputs.begin(); pos !=
mInputs.end(); pos++)
843 delete (pos->second);
849 logMsg(
"Controllable::pullInput");
851 if (thePort == NULL) {
852 logMsg(
"Controllable::pullInput port == null!");
860 Buffer * theBuffer = thePort->mBuffer;
861 if (theBuffer == NULL) {
862 logMsg(
"Controllable::pullInput Buffer == null!");
865 thePort->checkBuffer();
873 thePort->mValuePtr = (thePort->mBuffer->buffer(0)) - 1;
874 thePort->mValueIndex = 0;
887 theBuffer.mIsPopulated =
true;
888 thePort->mValuePtr = (theBuffer.buffer(0)) - 1;
889 thePort->mValueIndex = 0;
896 logMsg(
"Controllable::set input \"%d\" UGen", key);
901 thePort =
new Port(&uGen);
908 logMsg(
"Controllable::set input \"%d\" to %g", key, value);
912 thePort =
new Port(value);
927 logMsg(
"a Controllable with the map:");
928 for (PortMap::iterator pos =
mInputs.begin(); pos !=
mInputs.end(); ++pos) {
929 switch (pos->first) {
931 logMsg(
" key: Frequency = UG: ");
934 logMsg(
" key: Scale = UG: ");
937 logMsg(
" key: Offset = UG: ");
942 logMsg(
" key: Input = UG: ");
945 logMsg(
" key: Other = UG: ");
959 logMsg(
"Phased::add freq input");
966 logMsg(
"Phased::add freq input");
973 logMsg(
"Phased::add freq input");
995 logMsg(
"Scalable::add null inputs");
1003 logMsg(
"Scalable::add scale input");
1011 logMsg(
"Scalable::add scale/offset input values");
1019 logMsg(
"Scalable::add scale/offset input values");
1027 logMsg(
"Scalable::add scale/offset input values");
1042 logMsg(
"Scalable::set scale input UG");
1049 logMsg(
"Scalable::set scale input value");
1056 logMsg(
"Scalable::set offset input UG");
1063 logMsg(
"Scalable::set offset input value");
1092 logMsg(
"Effect::add null input");
1101 logMsg(
"Effect::add input UG");
1116 logMsg(
"Effect::add input");
1124 logMsg(
"Effect::pullInput");
1127 mInputPtr = outputBuffer.buffer(0);
1133 mInputPtr = outputBuffer.buffer(0);
1139 logMsg(
"Effect::pullInput");
1156 :
Effect(in), mNumFanOuts(taps), mCurrent(taps) {
1163 throw LogicError(
"Asking for mono nextBuffer of a FanOut");
1169 if (outputBuffer.mNumChannels != mNumChannels)
1170 throw LogicError(
"Asking for wrong output ch # of a FanOut");
1171 if (mCurrent >= mNumFanOuts) {
1172 pullInput(outputBuffer.mNumFrames);
1185 :
FanOut(in, in.numChannels()) { }
1188 throw LogicError(
"Asking for mono nextBuffer of a Splitter");
1195 if (outputBuffer.mNumChannels != 1)
1196 throw LogicError(
"Asking for a stereo output of a channel splitter");
1198 if (mCurrent >= mNumFanOuts) {
1199 pullInput(outputBuffer.mNumFrames);
1204 throw LogicError(
"Missing buffer in channel splitter");
1205 unsigned bufferByteSize = outputBuffer.mMonoBufferByteSize;
1208 memcpy(dest, src, bufferByteSize);
1227 if (
mInputs[i]->mUGen->isActive())
1235 throw LogicError(
"Asking for mono nextBuffer of a Joiner");
1241 if (outputBuffer.mNumChannels != mNumChannels) {
1242 throw LogicError(
"Wrong number of channels in a joiner");
1245 Buffer tempBuffer(1, outputBuffer.mNumFrames);
1248 for (
unsigned i = 0; i < mNumChannels; i++) {
1250 tempBuffer.
setBuffer(0, outputBuffer.buffer(i));
1252 mInputs[i]->mUGen->nextBuffer(tempBuffer);
1270 unsigned numBufs = inputBuffer.mNumChannels;
1271 for (
unsigned i = 0; i < numBufs; i++)
1272 writeBuffer(inputBuffer, i);
1280 throw IOError(
"Error seeking");
1286 unsigned numFrames,
unsigned numChannels)
throw (
CException) {
1288 unsigned numOutputChannels = output.mNumChannels;
1289 unsigned numChannelsToInterleave =
csl_min(numOutputChannels, numChannels);
1290 unsigned numChannelsBeyond = numChannels - numChannelsToInterleave;
1292 for (
unsigned frame = 0; frame < numFrames; frame++) {
1293 for (
unsigned channel = 0; channel < numChannelsToInterleave; channel++)
1294 *samples++ = output.buffer(channel)[frame];
1295 for (
unsigned j = 0; j < numChannelsBeyond; j++)
1305 unsigned numOutputChannels = output.mNumChannels;
1306 unsigned numChannelsToInterleave =
csl_min(numOutputChannels, numChannels);
1307 unsigned numChannelsBeyond = numChannels - numChannelsToInterleave;
1309 for (
unsigned frame = 0; frame < numFrames; frame++) {
1310 for (
unsigned channel = 0; channel < numChannelsToInterleave; channel++)
1311 *samples++ = (
short) ((output.buffer(channel)[frame]) * 32767.0);
1312 for (
unsigned j = 0; j < numChannelsBeyond; j++)
1320 unsigned numChannels,
unsigned *channelMap)
throw (
CException) {
1322 unsigned numOutputChannels = output.mNumChannels;
1323 unsigned numChannelsToInterleave =
csl_min(numOutputChannels, numChannels);
1324 unsigned numChannelsBeyond = numChannels - numChannelsToInterleave;
1325 unsigned *map = channelMap;
1327 for (
unsigned frame = 0; frame < numFrames; frame++) {
1328 for (
unsigned channel = 0; channel < numChannelsToInterleave; channel++)
1329 *samples++ = output.buffer(map[channel])[frame];
1330 for (
unsigned j = 0; j < numChannelsBeyond; j++)
1340 unsigned numOutputChannels = output.mNumChannels;
1341 unsigned numChannelsToDeinterleave =
csl_min(numOutputChannels, numChannels);
1346 for (i = 0; i < numChannelsToDeinterleave; i++) {
1347 currentOutputBuffer = output.buffer(i);
1348 inputBuffer = samples + i;
1349 for (
unsigned j = 0; j < numFrames; j++, inputBuffer += numChannels) {
1350 *currentOutputBuffer++ = *inputBuffer;
1353 if (numOutputChannels > numChannelsToDeinterleave) {
1354 for (i = numChannelsToDeinterleave; i < numOutputChannels; i++)
1355 memset(output.buffer(i), 0, output.mMonoBufferByteSize);
1364 unsigned numOutputChannels = output.mNumChannels;
1365 unsigned numChannelsToDeinterleave =
csl_min(numOutputChannels, numChannels);
1367 short * inputBuffer;
1370 for (i = 0; i < numChannelsToDeinterleave; i++) {
1371 currentOutputBuffer = output.buffer(i);
1372 inputBuffer = samples + i;
1373 for (
unsigned j = 0; j < numFrames; j++, inputBuffer += numChannels) {
1374 *currentOutputBuffer++ = ((float )*inputBuffer) / 32767.0f;
1377 if (numOutputChannels > numChannelsToDeinterleave) {
1378 for (i = numChannelsToDeinterleave; i < numOutputChannels; i++)
1379 memset(output.buffer(i), 0, output.mMonoBufferByteSize);
1393 IO::IO(
unsigned s_rate,
unsigned b_size,
int in_device,
int out_device,
1394 unsigned in_chans,
unsigned out_chans)
1395 : mGraph(NULL), mInputBuffer(0, 0), mOutputBuffer(0, 0), mCaptureBuffer(0, 0),
1398 mNumRealInChannels(in_chans), mNumRealOutChannels(out_chans),
1399 mStatus(
kIONew), mInterleaved(false) {
1400 logMsg(
"Create IO: %d s @ %d Hz; %d i %d o", b_size, s_rate, in_chans, out_chans);
1428 static struct timeval * mte = & mThen;
1429 static struct timeval * mno = & mNow;
1438 outBuffer.mSequence = this->getAndIncrementSequence();
1440 mGraph->nextBuffer(outBuffer);
1441 if (mCaptureBuffer.mNumFrames > 0) {
1442 mCaptureBuffer.copySamplesFromTo(outBuffer, mOffset);
1443 mOffset += outBuffer.mNumFrames;
1447 logMsg(
kLogError,
"An error occured in the CSL nextBuffer method: %s\n",
1454 printTimeStatistics(mno, mte, & mThisSec, & mTimeSum, & mTimeVals);
1460 #ifdef DO_TIMING // DO_TIMING
1462 int (timeval *val,
void * e) {
1463 LARGE_INTEGER ticksPerSecond;
1466 QueryPerformanceFrequency(&ticksPerSecond);
1467 float ticksPerUSecond = ticksPerSecond.QuadPart / 1000000;
1469 QueryPerformanceCounter(&tick);
1470 val->tv_sec = tick.QuadPart/ticksPerSecond.QuadPart;
1471 val->tv_usec = tick.QuadPart/ticksPerUSecond;
1487 long * timeSum,
long * timeVals) {
1490 *thisSec = now->tv_sec;
1491 if (*timeSum != 0.0) {
1494 mUsage = (float) *timeSum / *timeVals * 100.0f / cycleTime;
1525 throw IOError(
"Can't get unopened input");
1528 interleaver.
deinterleave(mInputBuffer, mInputPointer, numFrames, numChannels);
1529 mInputBuffer.mIsPopulated =
true;
1531 return(mInputBuffer);
1557 : mIndex(index), mMaxInputChannels(maxIn), mMaxOutputChannels(maxOut),
1558 mIsDefaultIn(isIn), mIsDefaultOut(isOut) {
1559 strcpy(
mName, name);
1563 : mIndex(index), mMaxInputChannels(maxIn), mMaxOutputChannels(maxOut),
1564 mIsDefaultIn(isIn), mIsDefaultOut(isOut) {
1565 strcpy(
mName, name.c_str());
1571 logMsg(
" IO: %d = %s - %d i %d o %g Hz%s%s",
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
bool mAreBuffersZero
have the buffers been zeroed out?
void logMsg(const char *format,...)
These are the public logging messages.
void pullInput(Buffer &outputBuffer)
virtual Buffer & getInput()
Get the current input from the sound card.
The Model/Observable/Subject class; instances of its subclasses should send themselves, this->changed(some_data); on "relevant" state changes; the code they inherit (from Model) manages updating the list of observer/dependent objects in that they each receive update(some_data); and can access the model-passed data (the model might pass "this").
unsigned mNumFrames
num frames used in each buffer
virtual SampleBuffer samplePtrFor(unsigned channel, unsigned offset)
answer a samp ptr with offset
virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr)
static unsigned mFrameRate
default sample rate (tested up to 96000)
csl::Status convertRate(int fromRate, int toRate)
convert the sample rate using libSampleRate
bool mAreBuffersAllocated
are the buffers allocated?
call monoNextBuffer multiple times
bool mIsDefaultIn
am i the default in?
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
void handleFanOut(Buffer &outputBuffer)
Effect – mix-in for classes that have unit generators as inputs (like filters).
void pullInput(Buffer &outBuffer, SampleBuffer out=0)
get a buffer from the CSL graph
Interleaver handles copying interleaved sample buffers (like sound files and inter-process sockets) t...
Splitter(UnitGenerator &in)
Constructor.
void copyHeaderFrom(Buffer &source)
copy the "header" fields of a buffer
unsigned mIndex
index (API-specific)
virtual unsigned seekTo(int position, SeekPosition whence)=0
general-purpose seek on a stream
Port()
Constructors: default is a float = 0.
bool canStore(unsigned numFrames)
answer whether the recevei can store numFrames more frames
char mName[CSL_NAME_LEN]
public members
bool mIsDefaultOut
am i the default out?
virtual ~Buffer()
Destructor de-allocated.
void resetPtr()
reset the buffer pointer without re-pulling the input
unsigned mSequence
sequence counter
Illegal operation at run time.
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
virtual bool isActive()
am I active?
void dump()
pretty-print the receiver
unsigned mLoggingPeriod
logging period in seconds
Phased()
Constructors; this one is rearely used.
float mValue
my value (in case I'm fixed [mUGen == NULL])
unsigned mPtrIncrement
the inter-sample ptr increment (0 for const, 1 for dynamic)
void addOutput(UnitGenerator *ugen)
add to or return the UGen vector of outputs
void copyOnlySamplesFrom(Buffer &src)
import data from the given buffer
Buffer * mOutputCache
my past output ring buffer (only used in case of fan-out)
void copyFrom(Buffer &src)
static float frameRateF()
default frame rate as a float
virtual void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
FanOut(UnitGenerator &in, unsigned taps)
Constructors.
void freeBuffers()
fcn to free them
virtual bool isActive()
answer whether I'm active
void deinterleave(Buffer &output, SampleBuffer samples, unsigned numFrames, unsigned numChannels)
De-interleave = copy from interleaved SampleBuffer to CSL Buffer object.
virtual void reset()
reset-to-zero
void zeroBuffers()
fill all data with 0
The CSL system defaults class.
virtual void dump()
pretty-print the receiver
void setSize(unsigned numChannels, unsigned numFrames)
unsigned mNumFanOuts
the number of outputs
SampleBufferVector mBuffers
the storage vector – pointers to (SampleBuffer) buffers
unsigned CSL_MAP_KEY
Forward declaration.
Controllable – superclass of the mix-ins that add control or signal inputs. This holds onto a map of...
void setOffset(UnitGenerator &offset)
set the receiver's offset member to a UGen or a float
unsigned mMonoBufferByteSize
size of each buffer in bytes
UGenVector mOutputs
the vector of my output UGens
UnitGenerator * mGraph
the root of my client DSP graph, often a mixer or panner
unsigned mNumOutputs
the number of outputs
static unsigned blockSize()
the default block size
void interleaveAndRemap(Buffer &output, SampleBuffer samples, unsigned numFrames, unsigned numChannels, unsigned *channelMap)
Interleave = copy from CSL-style Buffer object to an interleaved sample vector Remap = re-assign chan...
void dump()
pretty-print the receiver' device
virtual unsigned numChannels()
unsigned mNumChannels
num channels in buffer (num mono buffers)
void zeroBuffer(Buffer &outputBuffer, unsigned outBufNum)
utility method to zero out an outputBuffer
float sample
(could be changed to int, or double)
unsigned mNumChannels
my "expected" number of output channels
float mFrameRate
current SR
virtual void nextBuffer(Buffer &outputBuffer)
nextBuffer processes joiner channels
BufferContentType mType
Data type flag set the internal size variables (no buffer allocation takes place) ...
float rms(unsigned chan, unsigned from, unsigned to)
Buffer Sample Processing (optional). One could also easily add Buffer operators, such as (Buffer + Bu...
void setSizeOnly(unsigned numChannels, unsigned numFrames)
this version doesn't even allocate the pointers
#define SUB_TIMES(t1, t2)
Buffer mCaptureBuffer
the output buffer I use for capturing output (for testing)
bool isActive()
am I active?
float max(unsigned chan, unsigned from, unsigned to)
get the max of the absolute val of the samples
virtual void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
unsigned mNumAlloc
num frames in each buffer
float min(unsigned chan, unsigned from, unsigned to)
get the min of the samples
virtual bool isActive()
query whether I'm currently active (Envelopes can go inactive)
void copySamplesFrom(Buffer &src)
import data from the given buffer
virtual void trigger()
trigger passed on here
virtual void trigger()
trigger passed on here get the input port
void copySamplesFromTo(Buffer &src, unsigned offset)
same with write offset
unsigned mMaxInputChannels
HW ins
void scaleBy(sample value)
scale the samples by the given value
void checkBuffer()
check the port's buffer and allocate it if needed
vector< IODevice * > gIODevices
void fillWith(sample value)
fill data with the given value
void setInput(UnitGenerator &inp)
set the receiver's input generator
virtual void trigger()
trigger passed on here
Joiner()
< loop through my vector of inputs
static unsigned mNumInChannels
The actual start-up values are defined in CSL_Types.h.
unsigned mOffset
used for capture offset
unsigned mNumOutChannels
outputs
virtual void nextBuffer(Buffer &outputBuffer)
I'm mono nextBuffer processes splitter channels.
Status
CSL status flags (for return values)
virtual void capture_off()
end output capture
void checkBuffers()
allocate if not already there
void addInput(UnitGenerator &in)
add the argument to vector of inputs
compute 1 channel and copy
UnitGenerator * mUGen
my unit generator (pointer or NULL)
virtual ~UnitGenerator()
Destructor.
Buffer * mBuffer
the buffer used to hold my output
void printTimeStatistics(struct timeval *tthen, struct timeval *tnow, long *tsecond, long *ttimeSum, long *ttimeVals)
float duration()
answer the buffer's duration in seconds
unsigned mMaxOutputChannels
HW outs
void setFrequency(UnitGenerator &frequency)
Setter accessors.
bool mDidIAllocateBuffers
who allocated my data buffers?
void setRoot(UnitGenerator &root)
set/clear my graph root generator
IO(unsigned s_rate=44100, unsigned b_size=CSL_mBlockSize, int in_device=-1, int out_device=-1, unsigned in_chans=2, unsigned out_chans=2)
superclass = Model
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
float avg(unsigned chan, unsigned from, unsigned to)
get the average of the samples
float * mValuePtr
my value's address (const or buffer pointer)
virtual ~Port()
Destructor.
ignore extra buffer channels
Buffer mInputBuffer
the most recent input buffer (if it's turned on)
float normalize(float maxVal)
normalize the buffer(s) to the given max; answer the prior max
Port * getPort(CSL_MAP_KEY name)
void allocateBuffers()
fcn to malloc storage buffers
bool checkFanOut(Buffer &outputBuffer)
check for fan-out and copy previous buffer; return true if fanning out
float mUsage
cpu usage % print the CPU usage message
Port – used to represent constant, control-rate or signal inputs and outputs in named maps; holds a ...
bool readFromFile(char *fname)
read a buffer from a snd file; answer success
void addInput(CSL_MAP_KEY name, UnitGenerator &ugen)
Plug in a unit generator to the named input slot.
void removeOutput(UnitGenerator *ugen)
PortMap mInputs
the map of my inputs or controls (used by the mix-in classes)
Buffer(unsigned numChannels=1, unsigned numFrames=CSL_mBlockSize)
Constructor: default is mono and default-size.
bool isInline
whether to use input or buffer as source
unsigned getAndIncrementSequence()
increment and answer my seq #
void error(int num, const char *m, const char *path)
void setScale(UnitGenerator &scale)
set the receiver's scale member to a UGen or a float
static unsigned mLoggingPeriod
log CPU every 15 sec
UnitGenerator(unsigned rate=CGestalt::frameRate(), unsigned chans=1)
Constructors (UGens are mono by default) defaults to mono and maxBlockSize if not specified...
virtual void capture_on(float dur)
test the IO's graph
A fan-out generator for DSP graphs with loops.
BufferCMap()
Constructors: default is useless.
virtual void writeBuffer(Buffer &inputBuffer)
write to the receiver
void pullInput(Port *thePort, unsigned numFrames)
method to read the control values (in case they're dynamic). this sends nextBuffer() to the input...
void interleave(Buffer &output, SampleBuffer samples, unsigned numFrames, unsigned numChannels)
Interleave = copy from CSL-style Buffer object to an interleaved sample vector.
static unsigned mNumOutChannels
stereo outputs
virtual void dump()
pretty-print the receiver's input/controls map
virtual Buffer * get_capture()
answer the capture buffer
#define SAFE_MALLOC(ptr, type, len)
Useful Macros.
bool mIsPopulated
does the buffer have data?
Base class of CSL exceptions (written upper-case). Has a string message.
virtual ~Controllable()
Constructor takes no arguments.