CSL  6.0
CSL_Core.h
Go to the documentation of this file.
1 ///
2 /// CSL_Core.h -- the specification file for the core classes of CSL version 6
3 ///
4 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
5 ///
6 /// What's here:
7 ///
8 /// Core Classes
9 ///
10 /// Buffer -- the multi-channel sample buffer class (passed around between generators and IO guys)
11 ///
12 /// BufferCMap -- a sample buffer with channel map and count (used for many-channel processing)
13 ///
14 /// Port -- used to represent signal and control inputs and outputs in named maps;
15 /// holds a UnitGenerator and its buffer
16 ///
17 /// UnitGenerator -- an object that can fill a buffer with samples, the central abstraction of CSL DSP
18 ///
19 /// Mix-in classes (added to UnitGenerator)
20 ///
21 /// Controllable -- superclass of the mix-ins that add control or signal inputs (held in maps)
22 ///
23 /// Effect -- A (controllable) UnitGenerator subclass that process an input port (e.g., filters, panners).
24 /// All effects inherit from me.
25 ///
26 /// Scalable -- A (controllable) mix-in that adds scale (multiplicative) and offset (additive)
27 /// inputs (used by most common UGens)
28 ///
29 /// Phased -- a (controllable) mix-in for generators with frequency inputs and persistent phase accumulators
30 /// All of these mix-in classes add macros for handling their special named control ports, as in
31 /// DECLARE_PHASED_CONTROLS, LOAD_PHASED_CONTROLS, and UPDATE_PHASED_CONTROLS
32 ///
33 /// Writeable -- a mix-in for generators that one can write into a buffer on
34 ///
35 /// Seekable -- a mix-in for generators that one can position (seek) as a stream
36 ///
37 /// Cacheable -- a mix-in for generators that can cache their past output values (of any size)
38 ///
39 /// Channel/Buffer processing
40 ///
41 /// FanOut -- 1-in n-out fan-out object (now built in to UnitGenerator)
42 ///
43 /// Splitter -- splits a stream into multiple 1-channel outputs
44 ///
45 /// Joiner -- joins multiple 1-channel inputs into a single stream
46 ///
47 /// Interleaver -- general inderleaver/de-interleaver
48 ///
49 /// I/O
50 ///
51 /// IO -- the input/output stream/driver, its utility functions and virtual constructors
52 ///
53 /// IODevice -- a holder for a sound interface with name, id, # IO channels, etc.
54 ///
55 
56 #ifndef CSL_CORE_H // This is in case you try to include this twice
57 #define CSL_CORE_H
58 
59 #include "CSL_Types.h" // CSL type definitions and central macros, Observer classes
60 #include "CSL_Exceptions.h" // CSL exception hierarchy
61 #include "CGestalt.h" // System constants class
62 
63 namespace csl { // All this happens in the CSL namespace
64 
65 ///
66 /// Sample buffer contents type (optional)
67 /// One could argue that we should use subclasses for this, but they're not behaviorally different at present.
68 ///
69 
70 #ifdef CSL_ENUMS
71 typedef enum {
72  kSamples, ///< Regular audio samples
73  kSpectra, ///< FFT complex spectral frames
74  kLPCCoeff, ///< LPC reflection coefficients
75  kIRData, ///< FIR Impulse Response frames
76  kWavelet, ///< Wavelet coefficients
77  kGeometry, ///< Spatial geometry buffers
78  kUnknown ///< Unknown or other data type
80 #else
81  #define kSamples 0
82  #define kSpectra 1
83  #define kLPCCoeff 2
84  #define kIRData 3
85  #define kWavelet 4
86  #define kGeometry 5
87  #define kUnknown 6
88  typedef int BufferContentType;
89 #endif
90 
91 //-------------------------------------------------------------------------------------------------//
92 ///
93 /// Buffer -- the multi-channel sample buffer class (passed around between generators and IO guys).
94 ///
95 /// Buffers have an opaque pointer () to their data () and know their # channels and frames.
96 /// They have Boolean aspects about their buffer allocation, and can allocate, free, zero, and check their data.
97 ///
98 /// Note that this is a "record" class in that its members are all public and it has no accessor
99 /// functions or complicated methods. It does handle sample buffer allocation and has
100 /// Boolean members to determine what its pointer state is.
101 ///
102 /// Note also that Buffers are *not* thread-safe; they hand out pointers (sample*)
103 /// that are assumed to be volatile.
104 ///
105 
106 class Buffer {
107 public: /// Constructor: default is mono and default-size
108  Buffer(unsigned numChannels = 1, unsigned numFrames = CSL_mBlockSize);
109  virtual ~Buffer(); ///< Destructor de-allocated
110 
111  // public data members
112  unsigned mNumChannels; ///< num channels in buffer (num mono buffers)
113  unsigned mNumFrames; ///< num frames used in each buffer
114  unsigned mNumAlloc; ///< num frames in each buffer
115  unsigned mMonoBufferByteSize; ///< size of each buffer in bytes
116  unsigned mSequence; ///< sequential serial number
117  Timestamp mTimestamp; ///< the buffer's most recent timestamp
118  float duration(); ///< answer the buffer's duration in seconds
119 
120  bool mAreBuffersAllocated; ///< are the buffers allocated?
121  bool mDidIAllocateBuffers; ///< who allocated my data buffers?
122  bool mIsPopulated; ///< does the buffer have data?
123  bool mAreBuffersZero; ///< have the buffers been zeroed out?
124  BufferContentType mType; ///< Data type flag
125  /// set the internal size variables (no buffer allocation takes place)
126  void setSize(unsigned numChannels, unsigned numFrames);
127  /// this version doesn't even allocate the pointers
128  void setSizeOnly(unsigned numChannels, unsigned numFrames);
129 
130  void checkBuffers() throw (MemoryError); ///< allocate if not already there
131  void allocateBuffers() throw (MemoryError); ///< fcn to malloc storage buffers
132  void freeBuffers(); ///< fcn to free them
133  bool canStore(unsigned numFrames); ///< answer whether the recevei can store numFrames more frames
134 
135  void zeroBuffers(); ///< fill all data with 0
136  void fillWith(sample value); ///< fill data with the given value
137  void scaleBy(sample value); ///< scale the samples by the given value
138  // import data from the given buffer
139  void copyFrom(Buffer & src) throw (RunTimeError);
140  void copyHeaderFrom(Buffer & source) throw (RunTimeError); ///< copy the "header" fields of a buffer
141  void copySamplesFrom(Buffer & src) throw (RunTimeError); ///< import data from the given buffer
142  void copySamplesFromTo(Buffer & src, unsigned offset) throw (RunTimeError); ///< same with write offset
143  void copyOnlySamplesFrom(Buffer & src) throw (RunTimeError);///< import data from the given buffer
144  bool readFromFile(char * fname); ///< read a buffer from a snd file; answer success
145 
146  csl::Status convertRate(int fromRate, int toRate); ///< convert the sample rate using libSampleRate
147 
148  /// answer a samp ptr with offset
149  virtual SampleBuffer samplePtrFor(unsigned channel, unsigned offset);
150  /// answer a samp ptr tested for extent (offset + maxFrame)
151  virtual SampleBuffer samplePtrFor(unsigned channel, unsigned offset, unsigned maxFrame);
152 
153  /// convenience accessors for sample buffers
154  virtual SampleBuffer buffer(unsigned bufNum);
155  virtual SampleBuffer * buffers() { return mBuffers; }
156  /// Set the buffer pointer (rare; used in joiners)
157  virtual void setBuffers(SampleBuffer * sPtr) { mBuffers = sPtr; };
158  virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr) { mBuffers[bufNum] = sPtr; };
159  virtual void setBuffer(unsigned bufNum, unsigned offset, sample samp) { *((mBuffers[bufNum]) + offset) = samp; };
160 
161  float normalize(float maxVal); ///< normalize the buffer(s) to the given max; answer the prior max
162  float normalize(float maxVal, float from, float to); ///< normalize the given region only
163 
164 /// Buffer Sample Processing (optional).
165 /// One could also easily add Buffer operators, such as (Buffer + Buffer) or (Buffer * Buffer)
166 
167  float rms(unsigned chan, unsigned from, unsigned to); ///< get the root-mean-square of the samples
168  float avg(unsigned chan, unsigned from, unsigned to); ///< get the average of the samples
169  float max(unsigned chan, unsigned from, unsigned to); ///< get the max of the absolute val of the samples
170  float min(unsigned chan, unsigned from, unsigned to); ///< get the min of the samples
171 
172 #ifdef CSL_DSP_BUFFER
173  unsigned int zeroX(unsigned chan); ///< count the zero-crossings in the samples
174  unsigned int indexOfPeak(unsigned chan); ///< answer the index of the peak value
175  unsigned int indexOfPeak(unsigned chan, unsigned low, unsigned hi); ///< answer the index of the peak value
176  unsigned int indexOfMin(unsigned chan); ///< answer the index of the peak value
177  unsigned int indexOfMin(unsigned chan, unsigned low, unsigned hi); ///< answer the index of the peak value
178  void autocorrelation(unsigned chan, SampleBuffer result); ///< autocorrelation into the given array
179 #endif
180 
181 protected:
182  SampleBufferVector mBuffers; ///< the storage vector -- pointers to (SampleBuffer) buffers
183 };
184 
185 ///
186 /// BufferCMap is a Sample buffer with channel map and count.
187 ///
188 /// The map is so that one can have (e.g.,) a buffer that stands for 3 channels within an 8-channel space
189 ///
190 
191 class BufferCMap : public Buffer {
192 public:
193  BufferCMap(); ///< Constructors: default is useless
194  BufferCMap(unsigned numChannels, unsigned numFrames); ///< ask for a given number of "virtual" channels
195  BufferCMap(unsigned numChannels, unsigned realNumChannels, unsigned numFrames);
196  ~BufferCMap(); ///< Destructor
197 
198  unsigned mRealNumChannels; ///< the actual number of channels used
199  std::vector<int> mChannelMap; ///< the map between virtual and real channels
200 
201  /// Pointer accessor uses channel map
202  SampleBuffer buffer(unsigned bufNum) { return mBuffers[mChannelMap[bufNum]]; }
203 };
204 
205 ///
206 /// UnitGenerator buffer copy policy flags (for multi-channel expansion)
207 ///
208 
209 #ifdef CSL_ENUMS
210 typedef enum {
211  kCopy, ///< compute 1 channel and copy
212  kExpand, ///< call monoNextBuffer multiple times
213  kIgnore ///< ignore extra buffer channels
215 #else
216  #define kCopy 0
217  #define kExpand 1
218  #define kIgnore 2
219  typedef int BufferCopyPolicy;
220 #endif
221 
222 class RingBuffer; ///< forward declaration
223 
224 //-------------------------------------------------------------------------------------------------//
225 ///
226 /// UnitGenerator -- the core of CSL; all unit generators inherit from this class.
227 ///
228 /// These have members for their sample rate and number of channels, and know their outputs.
229 /// The main operation is the nextBuffer() method, which is overridden in many of the subclasses.
230 ///
231 /// If more than 1 output is used, these can handle fan-out automatically, either synchronous
232 /// (as in loops in a graph) or async (as in separate call-back threads).
233 /// The mOutputCache RingBuffer may hold some large number of past samples, and can use nextBuffer()
234 /// to do n-way fan-out either synchronously or with differing buffer sizes or callback rates.
235 ///
236 /// UnitGenerator inherits from Model, meaning that it has to send this->changed((void *) dataBuffer)
237 /// from within its nextBuffer method so that dependent objects (like signal views) can get notification
238 /// when it computes samples. This mechanism could also be used for signal flow.
239 ///
240 
241 class UnitGenerator : public Model {
242 public:
243  /// Constructors (UGens are mono by default)
244  /// defaults to mono and maxBlockSize if not specified.
245  UnitGenerator(unsigned rate = CGestalt::frameRate(), unsigned chans = 1);
246  virtual ~UnitGenerator(); ///< Destructor
247 
248  // accessing methods
249  unsigned frameRate() { return mFrameRate; }; ///< get/set the receiver's frame rate
250  void setFrameRate(unsigned rate) { mFrameRate = rate; }
251 
252  virtual unsigned numChannels() { return mNumChannels; }; ///< get/set the receiver's number of outputs
253  void setNumChannels(unsigned ch) { mNumChannels = ch; }
254 
255  BufferCopyPolicy copyPolicy() { return mCopyPolicy; }; ///< get/set the receiver's buffer copy policy
256  void setCopyPolicy(BufferCopyPolicy ch) { mCopyPolicy = ch; }
257 
258 // string name() { return mName; }; ///< get/set the receiver's name string
259 // void setName(char * ch) { mName = string(ch); }
260 // void setName(string ch) { mName = ch; }
261 
262  /// get a buffer of Frames -- this is the core CSL "pull" function;
263  /// the given buffer can be written into, and a changed() message is sent.
264  virtual void nextBuffer(Buffer & outputBuffer) throw (CException);
265 
266  /// really compute the next buffer given an offset base channel;
267  /// this is called by nextBuffer, possibly multiple times
268  virtual void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
269 
270  /// query whether I'm fixed (StaticVariable overrides this)
271  virtual bool isFixed() { return false; };
272  /// query whether I'm currently active (Envelopes can go inactive)
273  virtual bool isActive() { return true; };
274  /// add to or return the UGen vector of outputs
275  void addOutput(UnitGenerator * ugen);
276  void removeOutput(UnitGenerator * ugen);
277  UGenVector outputs() { return mOutputs; };
278  virtual unsigned numOutputs() { return mNumOutputs; };
279  /// check for fan-out and copy previous buffer; return true if fanning out
280  bool checkFanOut(Buffer & outputBuffer) throw (CException);
281  void handleFanOut(Buffer & outputBuffer) throw (CException);
282 
283  /// set/get the value (not allowed in the abstract, useful for static values)
284  virtual void setValue(sample theValue) { throw LogicError("can't set value of a generator"); };
285  virtual sample value() { throw LogicError("can't get value of a generator"); };
286 
287  virtual void dump(); ///< pretty-print the receiver
288  virtual void trigger() { }; ///< trigger ignored here
289 
290 protected: // My data members
291  unsigned mFrameRate; ///< the frame rate -- initialized to be the default by the constructor
292  unsigned mNumChannels; ///< my "expected" number of output channels
293  BufferCopyPolicy mCopyPolicy; ///< the policy I use if asked for more or fewer channels
294  UGenVector mOutputs; ///< the vector of my output UGens
295  unsigned mNumOutputs; ///< the number of outputs
296  Buffer * mOutputCache; ///< my past output ring buffer (only used in case of fan-out)
297  unsigned mSequence; ///< the highest-seen buffer seq number
298 // string mName; ///< my name (used for editors)
299  /// utility method to zero out an outputBuffer
300  void zeroBuffer(Buffer & outputBuffer, unsigned outBufNum);
301 };
302 
303 //-------------------------------------------------------------------------------------------------//
304 ///
305 /// Port -- used to represent constant, control-rate or signal inputs and outputs in named maps;
306 /// holds a UnitGenerator and its buffer, OR a single floating-point value (in which case the
307 /// UGen pointer is set to NULL and mPtrIncrement = 0).
308 ///
309 /// The nextValue() message is used to get the dynamic or static value.
310 ///
311 
312 class Port {
313 public:
314  Port(); ///< Constructors: default is a float = 0
315  Port(UnitGenerator * ug); ///< Given a UGen, use it as the input
316  Port(float value); ///< given a float, hold it as the static value
317  virtual ~Port(); ///< Destructor
318 
319  // public data members
320  UnitGenerator * mUGen; ///< my unit generator (pointer or NULL)
321  Buffer * mBuffer; ///< the buffer used to hold my output
322  float mValue; ///< my value (in case I'm fixed [mUGen == NULL])
323  float *mValuePtr; ///< my value's address (const or buffer pointer)
324  unsigned mPtrIncrement; ///< the inter-sample ptr increment (0 for const, 1 for dynamic)
325  unsigned mValueIndex; ///< my index (into the UGen's buffer)
326 
327  void checkBuffer() throw (LogicError); ///< check the port's buffer and allocate it if needed
328  inline float nextValue(); ///< answer the next value (dynamic or constant)
329  inline void nextFrame(SampleBuffer where); ///< write the val to a buffer
330  inline bool isReady(); ///< answer whether I'm ready to be read
331  void resetPtr(); ///< reset the buffer pointer without re-pulling the input
332  virtual bool isActive(); ///< answer whether I'm active
333  void dump(); ///< pretty-print the receiver
334  bool isFixed() { return (mPtrIncrement == 0); }; ///< am I fixed or dynamic
335  virtual void trigger() { if (mUGen) mUGen->trigger(); }; ///< trigger passed on here
336 
337 };
338 
339 // Answer the next value (dynamic or constant) as a fast inline function
340 
342  mValuePtr += mPtrIncrement; // increment the pointer (mPtrIncrement may be 0)
343  return *mValuePtr; // return the value
344 }
345 
346 // Write the next n-dimensional sample frame
347 
348 inline void Port::nextFrame(SampleBuffer where) {
349  for (unsigned i = 0; i < mBuffer->mNumChannels; i++)
350  *where++ = mBuffer->buffer(i)[mValueIndex];
351  mValueIndex++; // increment the counter (an unsigned, initially 0)
352 }
353 
354 // Answer whether the give port is ready (i.e., has its UGen or scalar value set up and primed)
355 
356 inline bool Port::isReady() {
357  return (mValuePtr != 0);
358 }
359 
360 //-------------------------------------------------------------------------------------------------//
361 ///
362 /// Controllable -- superclass of the mix-ins that add control or signal inputs.
363 /// This holds onto a map of port objects that represent the inputs,
364 /// and manages the naming and processing flow for dynamic inputs.
365 ///
366 /// A typical complex UGen will have several ports, e.g., for frequency, scale, and
367 /// offset in the case of an oscillator that supports AM and FM.
368 /// The pullInput() message is used to call the nextBuffer() method of a given port.
369 ///
370 
372 public:
373  Controllable() : mInputs() { }; ///< Constructor takes no arguments
374  virtual ~Controllable(); ///< Destructor (remove the output links of the ports)
375 
376  Port * getPort(CSL_MAP_KEY name);
377 protected:
378  PortMap mInputs; ///< the map of my inputs or controls (used by the mix-in classes)
379 
380  /// Plug in a unit generator to the named input slot
381  void addInput(CSL_MAP_KEY name, UnitGenerator & ugen);
382  /// Plug in a float to the named input slot
383  void addInput(CSL_MAP_KEY name, float value);
384  /// method to read the control values (in case they're dynamic).
385  /// this sends nextBuffer() to the input.
386  void pullInput(Port * thePort, unsigned numFrames) throw (CException);
387  void pullInput(Port * thePort, Buffer & theBuffer) throw (CException);
388 
389  virtual void dump(); ///< pretty-print the receiver's input/controls map
390 };
391 
392 //-------------------------------------------------------------------------------------------------//
393 ///
394 /// Scalable -- mix-in class with scale and offset control inputs (may be constants or generators).
395 ///
396 /// This uses the mInput map keys CSL_SCALE and CSL_OFFSET.
397 ///
398 /// Most actual unit generators inherit this as well as UnitGenerator.
399 ///
400 /// We use Controllable as a virtual superclass so that we can mix it in twice (in classes that are also Phased)
401 ///
402 
403 class Scalable : public virtual Controllable {
404 public:
405  Scalable(); ///< Constructors
406  Scalable(float scale); ///< use the given static scale
407  Scalable(float scale, float offset); ///< use the given static scale & offset
408  Scalable(UnitGenerator & scale, float offset); ///< use the given dynamic scale & static offset
409  Scalable(UnitGenerator & scale, UnitGenerator & offset); ///< use the given dynamic scale & offset
410  ~Scalable(); ///< Destructor
411 
412  // accessors
413  void setScale(UnitGenerator & scale); ///< set the receiver's scale member to a UGen or a float
414  void setScale(float scale);
415 
416  void setOffset(UnitGenerator & offset); ///< set the receiver's offset member to a UGen or a float
417  void setOffset(float offset);
418  virtual void trigger(); ///< trigger passed on here
419  void isScaled(); ///< answer whether scale = 1 & offset = 0
420 
421 };
422 
423 /// Macros for all the Scalable UnitGenerators (note that these don't end with ";")
424 ///
425 /// Note that these make some assumptions about variable names declared in the method;
426 
427 /// Declare the pointer to scale/offset buffers (if used) and current scale/offset values
428 
429 #define DECLARE_SCALABLE_CONTROLS \
430  Port * scalePort = mInputs[CSL_SCALE]; \
431  Port * offsetPort = mInputs[CSL_OFFSET]; \
432  float scaleValue, offsetValue
433 
434 /// Load the scale/offset-related values at the start
435 
436 #define LOAD_SCALABLE_CONTROLS \
437  Controllable::pullInput(scalePort, numFrames); \
438  scaleValue = scalePort->nextValue(); \
439  Controllable::pullInput(offsetPort, numFrames); \
440  offsetValue = offsetPort->nextValue()
441 
442 // Update the scale/offset-related values in the loop
443 
444 #define UPDATE_SCALABLE_CONTROLS \
445  scaleValue = scalePort->nextValue(); \
446  offsetValue = offsetPort->nextValue()
447 
448 #define CHECK_UPDATE_SCALABLE_CONTROLS \
449  if (scalePort) \
450  scaleValue = scalePort->nextValue(); \
451  if (offsetPort) \
452  offsetValue = offsetPort->nextValue()
453 
454 #define IS_UNSCALED \
455  (scalePort->isFixed()) && (offsetPort->isFixed()) && \
456  (scaleValue == 1.0) && (offsetValue == 0.0)
457 
458 
459 //-------------------------------------------------------------------------------------------------//
460 ///
461 /// Effect -- mix-in for classes that have unit generators as inputs (like filters).
462 ///
463 /// Note that this always uses a separate buffer for the input.
464 ///
465 
466 class Effect : public UnitGenerator, public virtual Controllable {
467 public:
468  Effect(); ///< Constructors
469  Effect(UnitGenerator & input); ///< use the given input
470 
471  virtual bool isActive(); ///< am I active?
472 
473  void setInput(UnitGenerator & inp); ///< set the receiver's input generator
474 // UnitGenerator *input() { return mInputs[CSL_INPUT]->mUGen; } // no getter for now
475  bool isInline; ///< whether to use input or buffer as source
476  void setInline() { isInline = true; } ///< set the Effect to be inline
477 
478 protected:
479  SampleBuffer mInputPtr; ///< A pointer to my input's data.
480  /// method to read the input value
481  void pullInput(Buffer & outputBuffer) throw (CException);
482  void pullInput(unsigned numFrames) throw (CException);
483  virtual void trigger(); ///< trigger passed on here
484  /// get the input port
485  inline Port * inPort() { return mInputs[CSL_INPUT]; };
486 };
487 
488 //-------------------------------------------------------------------------------------------------//
489 ///
490 /// Phased -- a mix-in for objects with phase accumulators (local float) and frequency controls (an input port).
491 ///
492 /// This puts an item named CSL_FREQUENCY in the Controllable parent mInputs map.
493 ///
494 /// We use Controllable as a virtual superclass so that we can mix it in twice (in classes that are also Scalable)
495 ///
496 
497 class Phased : public virtual Controllable {
498 public:
499  Phased(); ///< Constructors; this one is rearely used
500  Phased(float frequency, float phase = 0); ///< use the given dynamic frequency & phase
501  Phased(UnitGenerator & freq, float phase = 0); ///< use the given dynamic or static frequency
502  ~Phased(); ///< Destructor
503 
504  /// Setter accessors
505  void setFrequency(UnitGenerator & frequency); ///< set frequency
506  void setFrequency(float frequency); ///< set frequency
507  void setPhase(float phase) { mPhase = phase; }; ///< set phase
508 
509 protected:
510  sample mPhase; ///< the actual phase accumulator
511 };
512 
513 /// Macros for all the Phased UnitGenerators (note that these don't end with ";")
514 /// These make some assumptions about variable names declared in the method;
515 /// i.e., the number of frames to compute must be named "numFrames."
516 /// Use this: unsigned numFrames = outputBuffer.mNumFrames;
517 
518 /// Declare the frequency port (accessing the mInputs map) and current value.
519 
520 #define DECLARE_PHASED_CONTROLS \
521  Port * freqPort = mInputs[CSL_FREQUENCY]; \
522  float freqValue
523 
524 /// Load the freq-related values at the start of the callback; if the frequency is a dynamic UGen input,
525 /// then pull its value, get the pointer to its buffer, and set the first value,
526 /// otherwise store the constant value
527 
528 #define LOAD_PHASED_CONTROLS \
529  Controllable::pullInput(freqPort, numFrames); \
530  freqValue = freqPort->nextValue()
531 
532 /// Update the freq-related value in the loop
533 
534 #define UPDATE_PHASED_CONTROLS \
535  freqValue = freqPort->nextValue()
536 
537 #define CHECK_UPDATE_PHASED_CONTROLS \
538  if (freqPort) \
539  freqValue = freqPort->nextValue()
540 
541 //-------------------------------------------------------------------------------------------------//
542 ///
543 /// Writeable -- a mix-in for buffers and streams that one can write to
544 ///
545 
546 class Writeable {
547 public: /// write to the receiver
548  virtual void writeBuffer(Buffer& inputBuffer) throw(CException);
549  virtual ~Writeable() { /* ?? */ };
550 
551 protected: /// write to the receiver
552  virtual void writeBuffer(Buffer & inputBuffer, unsigned bufNum) throw(CException);
553 };
554 
555 ///
556 /// Enumeration for seek flags
557 ///
558 
559 #ifdef CSL_ENUMS
560 typedef enum {
564 } SeekPosition;
565 #else
566  #define kPositionStart 0
567  #define kPositionCurrent 1
568  #define kPositionEnd 2
569  typedef int SeekPosition;
570 #endif
571 
572 //-------------------------------------------------------------------------------------------------//
573 ///
574 /// Seekable -- a mix-in for positionable streams
575 ///
576 
577 class Seekable {
578 public:
579  Seekable() : mCurrentFrame(0), mActualFrame(0.0) { } ///< Constructor
580  virtual ~Seekable() { /* ?? */ };
581 
582  unsigned mCurrentFrame; ///< where I currently am in the buffer
583  double mActualFrame; ///< where I actually am in the buffer
584 
585  /// general-purpose seek on a stream
586  virtual unsigned seekTo(int position, SeekPosition whence) throw(CException) = 0;
587  virtual void reset() throw(CException); ///< reset-to-zero
588  virtual unsigned duration() { return 0; }; ///< number of frames in the Seekable
589 };
590 
591 ///
592 /// Cacheable -- a mix-in for caching streams
593 ///
594 
595 class Cacheable {
596 public:
597  Cacheable() : mUseCache(false) { } ; ///< Constructors
598  Cacheable(bool uC) : mUseCache(uC) { };
599 
600  bool mUseCache; ///< whether I'm to cache (vs. compute)
601 };
602 
603 /////////////// Utility UnitGenerator Classes ///////////////////////
604 
605 ///
606 /// A fan-out generator for DSP graphs with loops.
607 ///
608 /// This takes a single input, and provides mNumFanOuts outputs;
609 /// it only calls its input every mNumFanOuts frames.
610 ///
611 /// This behavior is now standard on UnitGenerators, using their mOutputs UGenVector
612 /// (see UnitGenerators::nextBuffer).
613 ///
614 
615 class FanOut : public Effect {
616 public:
617  FanOut(UnitGenerator & in, unsigned taps); ///< Constructors
618  ~FanOut() { };
619 
620  virtual void nextBuffer(Buffer & outputBuffer) throw(CException);
621  virtual void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw(CException);
622 
623 protected:
624  Buffer mBuffer; ///< my temp buffer
625  unsigned mNumFanOuts; ///< the number of outputs
626  unsigned mCurrent; ///< the current output
627 };
628 
629 ///
630 /// Splitter class -- a de-multiplexer for multi-channel signals
631 ///
632 
633 class Splitter : public FanOut {
634 public:
635  Splitter(UnitGenerator & in); ///< Constructor
636  ~Splitter() { };
637 
638  unsigned numChannels() { return 1; }; ///< I'm mono
639  /// nextBuffer processes splitter channels
640  virtual void nextBuffer(Buffer & outputBuffer) throw(CException);
641  virtual void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw(CException);
642 };
643 
644 ///
645 /// Joiner class -- a multiplexer for multi-channel signals
646 ///
647 
648 class Joiner : public Effect {
649 public: ///< loop through my vector of inputs
650  Joiner() : Effect() { mNumChannels = 0; }; ///< Constructors
651  Joiner(UnitGenerator & in1, UnitGenerator & in2);
652  ~Joiner() { };
653  /// nextBuffer processes joiner channels
654  virtual void nextBuffer(Buffer & outputBuffer) throw(CException);
655  virtual void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw(CException);
656  void addInput(UnitGenerator & in); ///< add the argument to vector of inputs
657  bool isActive();
658  virtual void trigger(); ///< trigger passed on here
659 // unsigned numChannels() { return mNumChannels; };
660 // inline Port * inPort() { return mInputs[CSL_INPUT]; };
661 // virtual unsigned numOutputs() { return mNumOutputs; };
662 
663 protected:
664 // UGenVector mInputs; ///< my vector of inputs
665 };
666 
667 ///
668 /// Interleaver handles copying interleaved sample buffers (like sound files and inter-process sockets)
669 /// to/from non-interleaved CSL-style Buffer objects.
670 ///
671 
672 class Interleaver {
673 
674 public:
675  /// Interleave = copy from CSL-style Buffer object to an interleaved sample vector
676  void interleave(Buffer & output, SampleBuffer samples, unsigned numFrames,
677  unsigned numChannels) throw (CException);
678  void interleave(Buffer & output, short * samples, unsigned numFrames,
679  unsigned numChannels) throw (CException);
680 
681  /// Interleave = copy from CSL-style Buffer object to an interleaved sample vector
682  /// Remap = re-assign channels from the source buffer to the target while interleaving
683  void interleaveAndRemap(Buffer & output, SampleBuffer samples, unsigned numFrames, unsigned numChannels,
684  unsigned *channelMap) throw (CException);
685 
686  /// De-interleave = copy from interleaved SampleBuffer to CSL Buffer object
687  void deinterleave(Buffer & output, SampleBuffer samples, unsigned numFrames,
688  unsigned numChannels) throw (CException);
689  void deinterleave(Buffer & output, short * samples, unsigned numFrames,
690  unsigned numChannels) throw (CException);
691 };
692 
693 //-------------------------------------------------------------------------------------------------//
694 ///// Support for the IO classes
695 
696 #ifndef CSL_WINDOWS // on "normal" platforms
697 
698 #ifdef DO_TIMING // Here are the macros and globals for the timing code
699 #include <sys/time.h>
700 #define GET_TIME(val) if (gettimeofday(val, 0) != 0) logMsg(kLogError, "Output: Error reading current time");
701 #define SUB_TIMES(t1, t2) (((t1->tv_sec - t2->tv_sec) * 1000000) + (t1->tv_usec - t2->tv_usec))
702 #endif
703 
704 #else // If on Windows
705 
706 #ifdef DO_TIMING // Here are the macros and globals for the timing code
707 #include <Winsock2.h>
708 #include <winsock.h>
709 #include <time.h>
710 int getSysTime(timeval *val, void * e);
711 #define GET_TIME(val) if (getSysTime(val, 0) != 0) logMsg(kLogError, "Output: Error reading current time");
712 #define SUB_TIMES(t1, t2) (((t1->tv_sec - t2->tv_sec) * 1000000) + (t1->tv_usec - t2->tv_usec))
713 #endif
714 
715 #endif // Windows
716 
717 /// IO Status flag
718 
719 #ifdef CSL_ENUMS
720 typedef enum {
727 } IO_Status;
728 #else
729  #define kIONew 0
730  #define kIOInit 1
731  #define kIOOpen 2
732  #define kIORunning 3
733  #define kIOClosed 4
734  #define kIOExit 5
735  typedef int IO_Status;
736 #endif
737 
738 //-------------------------------------------------------------------------------------------------//
739 ///
740 /// IO -- the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
741 ///
742 /// An IO object has a graph (a ptr to a UGen), and it registers itself with some call-back API
743 /// (like PortAudio, CoreAudio, Jack, VST, JUCE), setting up a callback function that in turn
744 /// calls the nextBuffer() method of its graph root.
745 ///
746 /// One creates an IO with the desired rate, block size (optional) I/O device keys, and the number of
747 /// in and out channels; you then set its root to be your DSP graph and send it start/stop messages.
748 ///
749 /// All this is public because it's used by static call-back functions.
750 ///
751 
752 class IO : public Model { /// superclass = Model
753 public:
754  IO(unsigned s_rate = 44100, unsigned b_size = CSL_mBlockSize,
755  int in_device = -1, int out_device = -1,
756  unsigned in_chans = 2, unsigned out_chans = 2); /// default is stereo input & output
757  virtual ~IO() { };
758  // Control methods
759  virtual void open() throw(CException) { mStatus = kIOOpen; }; ///< open/close start/stop methods
760  virtual void close() throw(CException) { mStatus = kIOClosed; };
761  virtual void start() throw(CException) { mStatus = kIORunning; };
762  virtual void stop() throw(CException) { mStatus = kIOOpen; };
763  virtual void test() throw(CException) { }; ///< test the IO's graph
764  virtual void capture_on(float dur); ///< begin output capture
765  virtual void capture_off(); ///< end output capture
766  virtual Buffer * get_capture(); ///< answer the capture buffer
767  void setRoot(UnitGenerator & root); ///< set/clear my graph root generator
768  void clearRoot();
769  /// get a buffer from the CSL graph
770  void pullInput(Buffer & outBuffer, SampleBuffer out = 0) throw(CException);
771 
772  virtual Buffer & getInput() throw(CException); ///< Get the current input from the sound card
773  virtual Buffer & getInput(unsigned numFrames, unsigned numChannels) throw(CException);
774  unsigned getAndIncrementSequence(); ///< increment and answer my seq #
775 
776  // Data members
777  UnitGenerator * mGraph; ///< the root of my client DSP graph, often a mixer or panner
778  Buffer mInputBuffer; ///< the most recent input buffer (if it's turned on)
779  Buffer mOutputBuffer; ///< the output buffer I use (passed to nextBuffer calls)
780  Buffer mCaptureBuffer; ///< the output buffer I use for capturing output (for testing)
781  SampleBuffer mInputPointer; ///< the buffer for holding the sound card input (if open)
782  unsigned * mChannelMap; ///< the output channel remapping array
783 
784  unsigned mNumFramesPlayed; ///< counter of frames I've played
785  unsigned mSequence; ///< sequence counter
786  unsigned mLoggingPeriod; ///< logging period in seconds
787  unsigned mNumInChannels; ///< # inputs
788  unsigned mNumOutChannels; ///< # outputs
789  unsigned mNumRealInChannels; ///< # physical inputs
790  unsigned mNumRealOutChannels; ///< # physical outputs
791  IO_Status mStatus; ///< status flag
792  bool mInterleaved; ///< flag if IO is interleaved
793  unsigned mOffset; ///< used for capture offset
794 
795 #ifdef DO_TIMING // This is for the performance timing code
796  struct timeval mThen, mNow; ///< used for getting the real time
797  long mTimeVals, mThisSec, mTimeSum; ///< for printing run-time statistics
798  float mUsage; ///< cpu usage %
799  /// print the CPU usage message
800  void printTimeStatistics(struct timeval * tthen, struct timeval * tnow, long * tsecond,
801  long * ttimeSum, long * ttimeVals);
802 #endif
803 
804 protected: /// initialize overridden in subclasses
805  virtual void initialize(unsigned sr, unsigned bs, int is, int os, unsigned ic, unsigned oc) { };
806  float maxSampEver;
807 
808 };
809 
810 //-------------------------------------------------------------------------------------------------//
811 ///
812 /// IO Device class -- a holder for a sound interface with name, id, # IO channels, etc.
813 ///
814 
815 class IODevice {
816 public:
817  IODevice() { } ; /// Constructor takes all variables, calls initialize()
818  IODevice(char * name, unsigned index, unsigned maxIn, unsigned maxOut, bool isIn, bool isOut);
819  IODevice(string name, unsigned index, unsigned maxIn, unsigned maxOut, bool isIn, bool isOut);
820  /// public members
821  char mName[CSL_NAME_LEN]; ///< my device name
822  unsigned mIndex; ///< index (API-specific)
823  unsigned mMaxInputChannels; ///< # HW ins
824  unsigned mMaxOutputChannels; ///<# HW outs
825  float mFrameRate; ///< current SR
826  vector<float> mFrameRates; ///< the vector of frame rates I support
827  bool mIsDefaultIn; ///< am i the default in?
828  bool mIsDefaultOut; ///< am i the default out?
829  void dump(); ///< pretty-print the receiver' device
830 };
831 
832 } // end of namespace
833 
834 #endif // CSL_CORE_H
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
Definition: CSL_Types.h:194
bool mAreBuffersZero
have the buffers been zeroed out?
Definition: CSL_Core.h:123
SeekPosition
Enumeration for seek flags.
Definition: CSL_Core.h:560
void pullInput(Buffer &outputBuffer)
Definition: CSL_Core.cpp:1122
virtual Buffer & getInput()
Get the current input from the sound card.
Definition: CSL_Core.cpp:1517
virtual ~Seekable()
Definition: CSL_Core.h:580
std::map< CSL_MAP_KEY, Port * > PortMap
Definition: CSL_Types.h:238
long mTimeSum
for printing run-time statistics
Definition: CSL_Core.h:797
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").
Definition: CGestalt.h:258
BufferContentType
Sample buffer contents type (optional) One could argue that we should use subclasses for this...
Definition: CSL_Core.h:71
unsigned mNumFrames
num frames used in each buffer
Definition: CSL_Core.h:113
virtual SampleBuffer samplePtrFor(unsigned channel, unsigned offset)
answer a samp ptr with offset
Definition: CSL_Core.cpp:183
SampleBuffer mInputPtr
A pointer to my input's data. method to read the input value.
Definition: CSL_Core.h:479
virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr)
Definition: CSL_Core.h:158
unsigned frameRate()
Definition: CSL_Core.h:249
virtual void setValue(sample theValue)
set/get the value (not allowed in the abstract, useful for static values)
Definition: CSL_Core.h:284
csl::Status convertRate(int fromRate, int toRate)
convert the sample rate using libSampleRate
bool mAreBuffersAllocated
are the buffers allocated?
Definition: CSL_Core.h:120
call monoNextBuffer multiple times
Definition: CSL_Core.h:212
bool mIsDefaultIn
am i the default in?
Definition: CSL_Core.h:827
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
void handleFanOut(Buffer &outputBuffer)
Definition: CSL_Core.cpp:713
IO_Status
IO Status flag.
Definition: CSL_Core.h:720
Effect – mix-in for classes that have unit generators as inputs (like filters).
Definition: CSL_Core.h:466
void pullInput(Buffer &outBuffer, SampleBuffer out=0)
get a buffer from the CSL graph
Definition: CSL_Core.cpp:1425
Interleaver handles copying interleaved sample buffers (like sound files and inter-process sockets) t...
Definition: CSL_Core.h:672
unsigned mSequence
the highest-seen buffer seq number
Definition: CSL_Core.h:297
float maxSampEver
Definition: CSL_Core.h:805
Splitter(UnitGenerator &in)
Constructor.
Definition: CSL_Core.cpp:1184
void copyHeaderFrom(Buffer &source)
copy the "header" fields of a buffer
Definition: CSL_Core.cpp:235
unsigned mIndex
index (API-specific)
Definition: CSL_Core.h:822
virtual unsigned seekTo(int position, SeekPosition whence)=0
general-purpose seek on a stream
Port()
Constructors: default is a float = 0.
Definition: CSL_Core.cpp:766
bool canStore(unsigned numFrames)
answer whether the recevei can store numFrames more frames
Definition: CSL_Core.cpp:197
SampleBuffer buffer(unsigned bufNum)
Pointer accessor uses channel map.
Definition: CSL_Core.h:202
char mName[CSL_NAME_LEN]
public members
Definition: CSL_Core.h:821
virtual void test()
Definition: CSL_Core.h:763
unsigned mFrameRate
trigger ignored here
Definition: CSL_Core.h:288
Phased – a mix-in for objects with phase accumulators (local float) and frequency controls (an input...
Definition: CSL_Core.h:497
bool mIsDefaultOut
am i the default out?
Definition: CSL_Core.h:828
virtual ~Buffer()
Destructor de-allocated.
Definition: CSL_Core.cpp:59
BufferCMap is a Sample buffer with channel map and count.
Definition: CSL_Core.h:191
void resetPtr()
reset the buffer pointer without re-pulling the input
Definition: CSL_Core.cpp:811
unsigned mSequence
sequence counter
Definition: CSL_Core.h:785
Illegal operation at run time.
virtual SampleBuffer buffer(unsigned bufNum)
convenience accessors for sample buffers
Definition: CSL_Core.cpp:66
bool mInterleaved
flag if IO is interleaved
Definition: CSL_Core.h:792
virtual bool isActive()
am I active?
Definition: CSL_Core.cpp:1105
std::vector< int > mChannelMap
the map between virtual and real channels
Definition: CSL_Core.h:199
unsigned long Timestamp
Timestamp type: we assume that we can get the host's best guess at the IO word clock (normally passed...
Definition: CSL_Types.h:261
void dump()
pretty-print the receiver
Definition: CSL_Core.cpp:827
virtual void open()
Definition: CSL_Core.h:759
unsigned mLoggingPeriod
logging period in seconds
Definition: CSL_Core.h:786
Phased()
Constructors; this one is rearely used.
Definition: CSL_Core.cpp:956
sample mPhase
set phase
Definition: CSL_Core.h:507
float mValue
my value (in case I'm fixed [mUGen == NULL])
Definition: CSL_Core.h:322
unsigned mPtrIncrement
the inter-sample ptr increment (0 for const, 1 for dynamic)
Definition: CSL_Core.h:324
Timestamp mTimestamp
the buffer's most recent timestamp
Definition: CSL_Core.h:117
void addOutput(UnitGenerator *ugen)
add to or return the UGen vector of outputs
Definition: CSL_Core.cpp:670
void copyOnlySamplesFrom(Buffer &src)
import data from the given buffer
Definition: CSL_Core.cpp:286
LPC reflection coefficients.
Definition: CSL_Core.h:74
Buffer * mOutputCache
my past output ring buffer (only used in case of fan-out)
Definition: CSL_Core.h:296
Effect()
Constructors.
Definition: CSL_Core.cpp:1088
UGenVector outputs()
Definition: CSL_Core.h:277
void copyFrom(Buffer &src)
Definition: CSL_Core.cpp:250
virtual void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
Definition: CSL_Core.cpp:726
FanOut(UnitGenerator &in, unsigned taps)
Constructors.
Definition: CSL_Core.cpp:1155
void freeBuffers()
fcn to free them
Definition: CSL_Core.cpp:141
virtual bool isActive()
answer whether I'm active
Definition: CSL_Core.cpp:818
void deinterleave(Buffer &output, SampleBuffer samples, unsigned numFrames, unsigned numChannels)
De-interleave = copy from interleaved SampleBuffer to CSL Buffer object.
Definition: CSL_Core.cpp:1337
virtual void reset()
reset-to-zero
Definition: CSL_Core.cpp:1277
void zeroBuffers()
fill all data with 0
Definition: CSL_Core.cpp:173
Impossible operation.
virtual void dump()
pretty-print the receiver
Definition: CSL_Core.cpp:693
~Scalable()
Destructor.
Definition: CSL_Core.cpp:1031
void nextFrame(SampleBuffer where)
write the val to a buffer
Definition: CSL_Core.h:348
void setSize(unsigned numChannels, unsigned numFrames)
Definition: CSL_Core.cpp:75
unsigned mNumFanOuts
the number of outputs
Definition: CSL_Core.h:625
SampleBufferVector mBuffers
the storage vector – pointers to (SampleBuffer) buffers
Definition: CSL_Core.h:182
unsigned CSL_MAP_KEY
Forward declaration.
Definition: CSL_Types.h:233
Controllable – superclass of the mix-ins that add control or signal inputs. This holds onto a map of...
Definition: CSL_Core.h:371
void setOffset(UnitGenerator &offset)
set the receiver's offset member to a UGen or a float
Definition: CSL_Core.cpp:1053
float nextValue()
answer the next value (dynamic or constant)
Definition: CSL_Core.h:341
unsigned mMonoBufferByteSize
size of each buffer in bytes
Definition: CSL_Core.h:115
void setPhase(float phase)
Definition: CSL_Core.h:507
UGenVector mOutputs
the vector of my output UGens
Definition: CSL_Core.h:294
Scalable – mix-in class with scale and offset control inputs (may be constants or generators)...
Definition: CSL_Core.h:403
UnitGenerator * mGraph
the root of my client DSP graph, often a mixer or panner
Definition: CSL_Core.h:777
virtual void setBuffers(SampleBuffer *sPtr)
Set the buffer pointer (rare; used in joiners)
Definition: CSL_Core.h:157
unsigned mNumOutputs
the number of outputs
Definition: CSL_Core.h:295
Malloc failure subclass.
#define CSL_NAME_LEN
default string length
Definition: CSL_Types.h:121
virtual void start()
Definition: CSL_Core.h:761
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...
Definition: CSL_Core.cpp:1319
void dump()
pretty-print the receiver' device
Definition: CSL_Core.cpp:1570
virtual unsigned numChannels()
Definition: CSL_Core.h:252
Unknown or other data type.
Definition: CSL_Core.h:78
unsigned mNumChannels
num channels in buffer (num mono buffers)
Definition: CSL_Core.h:112
FIR Impulse Response frames.
Definition: CSL_Core.h:75
Cacheable – a mix-in for caching streams.
Definition: CSL_Core.h:595
unsigned mCurrentFrame
where I currently am in the buffer
Definition: CSL_Core.h:580
void zeroBuffer(Buffer &outputBuffer, unsigned outBufNum)
utility method to zero out an outputBuffer
Definition: CSL_Core.cpp:663
float sample
(could be changed to int, or double)
Definition: CSL_Types.h:191
BufferCopyPolicy copyPolicy()
Definition: CSL_Core.h:255
unsigned mNumChannels
my "expected" number of output channels
Definition: CSL_Core.h:292
Seekable()
Constructor.
Definition: CSL_Core.h:579
float mFrameRate
current SR
Definition: CSL_Core.h:825
virtual void nextBuffer(Buffer &outputBuffer)
nextBuffer processes joiner channels
Definition: CSL_Core.cpp:1240
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
Definition: CSL_Core.h:752
Scalable()
Constructors.
Definition: CSL_Core.cpp:991
BufferContentType mType
Data type flag set the internal size variables (no buffer allocation takes place) ...
Definition: CSL_Core.h:124
unsigned mSequence
sequential serial number
Definition: CSL_Core.h:116
float rms(unsigned chan, unsigned from, unsigned to)
Buffer Sample Processing (optional). One could also easily add Buffer operators, such as (Buffer + Bu...
Definition: CSL_Core.cpp:465
void setSizeOnly(unsigned numChannels, unsigned numFrames)
this version doesn't even allocate the pointers
Definition: CSL_Core.cpp:99
Port * inPort()
Definition: CSL_Core.h:485
#define CSL_INPUT
Definition: CSL_Types.h:275
BufferCopyPolicy
UnitGenerator buffer copy policy flags (for multi-channel expansion)
Definition: CSL_Core.h:210
static unsigned frameRate()
default frame rate
Definition: CGestalt.cpp:51
Buffer mCaptureBuffer
the output buffer I use for capturing output (for testing)
Definition: CSL_Core.h:780
bool isActive()
am I active?
Definition: CSL_Core.cpp:1225
virtual void trigger()
Definition: CSL_Core.h:288
float max(unsigned chan, unsigned from, unsigned to)
get the max of the absolute val of the samples
Definition: CSL_Core.cpp:495
virtual void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
Definition: CSL_Core.cpp:1168
unsigned mNumAlloc
num frames in each buffer
Definition: CSL_Core.h:114
float min(unsigned chan, unsigned from, unsigned to)
get the min of the samples
Definition: CSL_Core.cpp:509
~Phased()
Destructor.
Definition: CSL_Core.cpp:977
long mThisSec
Definition: CSL_Core.h:797
virtual bool isActive()
query whether I'm currently active (Envelopes can go inactive)
Definition: CSL_Core.h:273
bool mUseCache
whether I'm to cache (vs. compute)
Definition: CSL_Core.h:598
void copySamplesFrom(Buffer &src)
import data from the given buffer
Definition: CSL_Core.cpp:270
Writeable – a mix-in for buffers and streams that one can write to.
Definition: CSL_Core.h:546
unsigned mValueIndex
my index (into the UGen's buffer)
Definition: CSL_Core.h:325
virtual void trigger()
trigger passed on here
Definition: CSL_Core.cpp:1258
virtual void trigger()
trigger passed on here get the input port
Definition: CSL_Core.cpp:1148
virtual void setBuffer(unsigned bufNum, unsigned offset, sample samp)
Definition: CSL_Core.h:159
void copySamplesFromTo(Buffer &src, unsigned offset)
same with write offset
Definition: CSL_Core.cpp:300
virtual ~IO()
default is stereo input & output
Definition: CSL_Core.h:757
unsigned mMaxInputChannels
HW ins
Definition: CSL_Core.h:823
void scaleBy(sample value)
scale the samples by the given value
Definition: CSL_Core.cpp:219
void checkBuffer()
check the port's buffer and allocate it if needed
Definition: CSL_Core.cpp:796
std::vector< UnitGenerator * > UGenVector
Definition: CSL_Types.h:241
void fillWith(sample value)
fill data with the given value
Definition: CSL_Core.cpp:203
unsigned mNumFramesPlayed
counter of frames I've played
Definition: CSL_Core.h:784
Splitter class – a de-multiplexer for multi-channel signals.
Definition: CSL_Core.h:633
void setInput(UnitGenerator &inp)
set the receiver's input generator
Definition: CSL_Core.cpp:1112
virtual void trigger()
trigger passed on here
Definition: CSL_Core.cpp:1069
Joiner()
< loop through my vector of inputs
Definition: CSL_Core.h:650
virtual void initialize(unsigned sr, unsigned bs, int is, int os, unsigned ic, unsigned oc)
initialize overridden in subclasses
Definition: CSL_Core.h:805
vector< float > mFrameRates
the vector of frame rates I support
Definition: CSL_Core.h:826
unsigned * mChannelMap
the output channel remapping array
Definition: CSL_Core.h:782
double mActualFrame
where I actually am in the buffer
Definition: CSL_Core.h:583
unsigned mOffset
used for capture offset
Definition: CSL_Core.h:793
unsigned mNumOutChannels
outputs
Definition: CSL_Core.h:788
virtual unsigned duration()
Definition: CSL_Core.h:588
virtual void nextBuffer(Buffer &outputBuffer)
I'm mono nextBuffer processes splitter channels.
Definition: CSL_Core.cpp:1194
Status
CSL status flags (for return values)
unsigned mCurrent
the current output
Definition: CSL_Core.h:626
void setFrameRate(unsigned rate)
get/set the receiver's frame rate
Definition: CSL_Core.h:250
virtual void capture_off()
end output capture
Definition: CSL_Core.cpp:1544
unsigned mRealNumChannels
the actual number of channels used
Definition: CSL_Core.h:198
void checkBuffers()
allocate if not already there
Definition: CSL_Core.cpp:107
void addInput(UnitGenerator &in)
add the argument to vector of inputs
Definition: CSL_Core.cpp:1220
virtual ~Writeable()
Definition: CSL_Core.h:549
virtual bool isFixed()
query whether I'm fixed (StaticVariable overrides this)
Definition: CSL_Core.h:271
compute 1 channel and copy
Definition: CSL_Core.h:211
void setCopyPolicy(BufferCopyPolicy ch)
get/set the receiver's buffer copy policy
Definition: CSL_Core.h:256
virtual unsigned numOutputs()
Definition: CSL_Core.h:278
UnitGenerator * mUGen
my unit generator (pointer or NULL)
Definition: CSL_Core.h:320
virtual ~UnitGenerator()
Destructor.
Definition: CSL_Core.cpp:659
Buffer * mBuffer
the buffer used to hold my output
Definition: CSL_Core.h:321
void printTimeStatistics(struct timeval *tthen, struct timeval *tnow, long *tsecond, long *ttimeSum, long *ttimeVals)
Definition: CSL_Core.cpp:1486
IO_Status mStatus
status flag
Definition: CSL_Core.h:791
unsigned mNumRealOutChannels
physical outputs
Definition: CSL_Core.h:790
float duration()
answer the buffer's duration in seconds
Definition: CSL_Core.cpp:114
bool isReady()
answer whether I'm ready to be read
Definition: CSL_Core.h:356
unsigned mMaxOutputChannels
HW outs
Definition: CSL_Core.h:824
virtual void close()
open/close start/stop methods
Definition: CSL_Core.h:760
FFT complex spectral frames.
Definition: CSL_Core.h:73
void setFrequency(UnitGenerator &frequency)
Setter accessors.
Definition: CSL_Core.cpp:981
bool mDidIAllocateBuffers
who allocated my data buffers?
Definition: CSL_Core.h:121
Buffer mBuffer
my temp buffer
Definition: CSL_Core.h:624
void setRoot(UnitGenerator &root)
set/clear my graph root generator
Definition: CSL_Core.cpp:1405
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
Definition: CSL_Core.cpp:1393
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
float avg(unsigned chan, unsigned from, unsigned to)
get the average of the samples
Definition: CSL_Core.cpp:483
float * mValuePtr
my value's address (const or buffer pointer)
Definition: CSL_Core.h:323
virtual sample value()
Definition: CSL_Core.h:285
Buffer mOutputBuffer
the output buffer I use (passed to nextBuffer calls)
Definition: CSL_Core.h:779
virtual ~Port()
Destructor.
Definition: CSL_Core.cpp:789
void clearRoot()
Definition: CSL_Core.cpp:1410
ignore extra buffer channels
Definition: CSL_Core.h:213
unsigned mNumRealInChannels
physical inputs
Definition: CSL_Core.h:789
unsigned numChannels()
Definition: CSL_Core.h:638
Buffer mInputBuffer
the most recent input buffer (if it's turned on)
Definition: CSL_Core.h:778
unsigned mNumInChannels
inputs
Definition: CSL_Core.h:787
float normalize(float maxVal)
normalize the buffer(s) to the given max; answer the prior max
Definition: CSL_Core.cpp:348
Joiner class – a multiplexer for multi-channel signals.
Definition: CSL_Core.h:648
Port * getPort(CSL_MAP_KEY name)
Definition: CSL_Core.cpp:920
struct timeval mThen mNow
used for getting the real time
Definition: CSL_Core.h:796
void allocateBuffers()
fcn to malloc storage buffers
Definition: CSL_Core.cpp:122
bool checkFanOut(Buffer &outputBuffer)
check for fan-out and copy previous buffer; return true if fanning out
Definition: CSL_Core.cpp:699
float mUsage
cpu usage % print the CPU usage message
Definition: CSL_Core.h:798
SampleBuffer * SampleBufferVector
Multi-channel buffer data type, vector of (SampleBuffer)
Definition: CSL_Types.h:195
Port – used to represent constant, control-rate or signal inputs and outputs in named maps; holds a ...
Definition: CSL_Core.h:312
bool readFromFile(char *fname)
read a buffer from a snd file; answer success
Definition: CSL_Core.cpp:315
void addInput(CSL_MAP_KEY name, UnitGenerator &ugen)
Plug in a unit generator to the named input slot.
Definition: CSL_Core.cpp:894
void removeOutput(UnitGenerator *ugen)
Definition: CSL_Core.cpp:680
PortMap mInputs
the map of my inputs or controls (used by the mix-in classes)
Definition: CSL_Core.h:378
SampleBuffer mInputPointer
the buffer for holding the sound card input (if open)
Definition: CSL_Core.h:781
forward declaration
Definition: CSL_Core.h:241
Buffer(unsigned numChannels=1, unsigned numFrames=CSL_mBlockSize)
Constructor: default is mono and default-size.
Definition: CSL_Core.cpp:42
Spatial geometry buffers.
Definition: CSL_Core.h:77
bool isInline
whether to use input or buffer as source
Definition: CSL_Core.h:475
long mTimeVals
Definition: CSL_Core.h:797
~BufferCMap()
Destructor.
Definition: CSL_Core.cpp:635
IO Device class – a holder for a sound interface with name, id, # IO channels, etc.
Definition: CSL_Core.h:815
BufferCopyPolicy mCopyPolicy
the policy I use if asked for more or fewer channels
Definition: CSL_Core.h:293
virtual void trigger()
am I fixed or dynamic
Definition: CSL_Core.h:335
unsigned getAndIncrementSequence()
increment and answer my seq #
Definition: CSL_Core.cpp:1418
void setScale(UnitGenerator &scale)
set the receiver's scale member to a UGen or a float
Definition: CSL_Core.cpp:1039
UnitGenerator(unsigned rate=CGestalt::frameRate(), unsigned chans=1)
Constructors (UGens are mono by default) defaults to mono and maxBlockSize if not specified...
Definition: CSL_Core.cpp:647
virtual void capture_on(float dur)
test the IO's graph
Definition: CSL_Core.cpp:1536
A fan-out generator for DSP graphs with loops.
Definition: CSL_Core.h:615
BufferCMap()
Constructors: default is useless.
Definition: CSL_Core.cpp:625
Regular audio samples.
Definition: CSL_Core.h:72
virtual void writeBuffer(Buffer &inputBuffer)
write to the receiver
Definition: CSL_Core.cpp:1269
void setNumChannels(unsigned ch)
get/set the receiver's number of outputs
Definition: CSL_Core.h:253
void pullInput(Port *thePort, unsigned numFrames)
method to read the control values (in case they're dynamic). this sends nextBuffer() to the input...
Definition: CSL_Core.cpp:847
void interleave(Buffer &output, SampleBuffer samples, unsigned numFrames, unsigned numChannels)
Interleave = copy from CSL-style Buffer object to an interleaved sample vector.
Definition: CSL_Core.cpp:1285
virtual SampleBuffer * buffers()
Definition: CSL_Core.h:155
bool isFixed()
Definition: CSL_Core.h:334
#define CSL_mBlockSize
normal hosts
Definition: CSL_Types.h:99
virtual void stop()
Definition: CSL_Core.h:762
Seekable – a mix-in for positionable streams.
Definition: CSL_Core.h:577
virtual void dump()
pretty-print the receiver's input/controls map
Definition: CSL_Core.cpp:926
Wavelet coefficients.
Definition: CSL_Core.h:76
virtual Buffer * get_capture()
answer the capture buffer
Definition: CSL_Core.cpp:1550
bool mIsPopulated
does the buffer have data?
Definition: CSL_Core.h:122
Base class of CSL exceptions (written upper-case). Has a string message.
void setInline()
set the Effect to be inline
Definition: CSL_Core.h:476
virtual ~Controllable()
Constructor takes no arguments.
Definition: CSL_Core.cpp:841
void isScaled()
answer whether scale = 1 & offset = 0