56 #ifndef CSL_CORE_H // This is in case you try to include this twice
126 void setSize(
unsigned numChannels,
unsigned numFrames);
128 void setSizeOnly(
unsigned numChannels,
unsigned numFrames);
162 float normalize(
float maxVal,
float from,
float to);
167 float rms(
unsigned chan,
unsigned from,
unsigned to);
168 float avg(
unsigned chan,
unsigned from,
unsigned to);
169 float max(
unsigned chan,
unsigned from,
unsigned to);
170 float min(
unsigned chan,
unsigned from,
unsigned to);
172 #ifdef CSL_DSP_BUFFER
173 unsigned int zeroX(
unsigned chan);
174 unsigned int indexOfPeak(
unsigned chan);
175 unsigned int indexOfPeak(
unsigned chan,
unsigned low,
unsigned hi);
176 unsigned int indexOfMin(
unsigned chan);
177 unsigned int indexOfMin(
unsigned chan,
unsigned low,
unsigned hi);
178 void autocorrelation(
unsigned chan,
SampleBuffer result);
194 BufferCMap(
unsigned numChannels,
unsigned numFrames);
195 BufferCMap(
unsigned numChannels,
unsigned realNumChannels,
unsigned numFrames);
334 bool isFixed() {
return (mPtrIncrement == 0); };
407 Scalable(
float scale,
float offset);
429 #define DECLARE_SCALABLE_CONTROLS \
430 Port * scalePort = mInputs[CSL_SCALE]; \
431 Port * offsetPort = mInputs[CSL_OFFSET]; \
432 float scaleValue, offsetValue
436 #define LOAD_SCALABLE_CONTROLS \
437 Controllable::pullInput(scalePort, numFrames); \
438 scaleValue = scalePort->nextValue(); \
439 Controllable::pullInput(offsetPort, numFrames); \
440 offsetValue = offsetPort->nextValue()
444 #define UPDATE_SCALABLE_CONTROLS \
445 scaleValue = scalePort->nextValue(); \
446 offsetValue = offsetPort->nextValue()
448 #define CHECK_UPDATE_SCALABLE_CONTROLS \
450 scaleValue = scalePort->nextValue(); \
452 offsetValue = offsetPort->nextValue()
454 #define IS_UNSCALED \
455 (scalePort->isFixed()) && (offsetPort->isFixed()) && \
456 (scaleValue == 1.0) && (offsetValue == 0.0)
500 Phased(
float frequency,
float phase = 0);
520 #define DECLARE_PHASED_CONTROLS \
521 Port * freqPort = mInputs[CSL_FREQUENCY]; \
528 #define LOAD_PHASED_CONTROLS \
529 Controllable::pullInput(freqPort, numFrames); \
530 freqValue = freqPort->nextValue()
534 #define UPDATE_PHASED_CONTROLS \
535 freqValue = freqPort->nextValue()
537 #define CHECK_UPDATE_PHASED_CONTROLS \
539 freqValue = freqPort->nextValue()
566 #define kPositionStart 0
567 #define kPositionCurrent 1
568 #define kPositionEnd 2
586 virtual unsigned seekTo(
int position, SeekPosition whence)
throw(
CException) = 0;
696 #ifndef CSL_WINDOWS // on "normal" platforms
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))
704 #else // If on Windows
706 #ifdef DO_TIMING // Here are the macros and globals for the timing code
707 #include <Winsock2.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))
755 int in_device = -1,
int out_device = -1,
756 unsigned in_chans = 2,
unsigned out_chans = 2);
773 virtual
Buffer &
getInput(
unsigned numFrames,
unsigned numChannels) throw(CException);
795 #ifdef DO_TIMING // This is for the performance timing code
801 long * ttimeSum,
long * ttimeVals);
805 virtual void initialize(
unsigned sr,
unsigned bs,
int is,
int os,
unsigned ic,
unsigned oc) { };
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);
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
bool mAreBuffersZero
have the buffers been zeroed out?
SeekPosition
Enumeration for seek flags.
void pullInput(Buffer &outputBuffer)
virtual Buffer & getInput()
Get the current input from the sound card.
std::map< CSL_MAP_KEY, Port * > PortMap
long mTimeSum
for printing run-time statistics
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").
BufferContentType
Sample buffer contents type (optional) One could argue that we should use subclasses for this...
unsigned mNumFrames
num frames used in each buffer
virtual SampleBuffer samplePtrFor(unsigned channel, unsigned offset)
answer a samp ptr with offset
SampleBuffer mInputPtr
A pointer to my input's data. method to read the input value.
virtual void setBuffer(unsigned bufNum, SampleBuffer sPtr)
virtual void setValue(sample theValue)
set/get the value (not allowed in the abstract, useful for static values)
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...
unsigned mSequence
the highest-seen buffer seq number
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
SampleBuffer buffer(unsigned bufNum)
Pointer accessor uses channel map.
char mName[CSL_NAME_LEN]
public members
unsigned mFrameRate
trigger ignored here
Phased – a mix-in for objects with phase accumulators (local float) and frequency controls (an input...
bool mIsDefaultOut
am i the default out?
virtual ~Buffer()
Destructor de-allocated.
BufferCMap is a Sample buffer with channel map and count.
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
bool mInterleaved
flag if IO is interleaved
virtual bool isActive()
am I active?
std::vector< int > mChannelMap
the map between virtual and real channels
unsigned long Timestamp
Timestamp type: we assume that we can get the host's best guess at the IO word clock (normally passed...
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)
Timestamp mTimestamp
the buffer's most recent timestamp
void addOutput(UnitGenerator *ugen)
add to or return the UGen vector of outputs
void copyOnlySamplesFrom(Buffer &src)
import data from the given buffer
LPC reflection coefficients.
Buffer * mOutputCache
my past output ring buffer (only used in case of fan-out)
void copyFrom(Buffer &src)
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
virtual void dump()
pretty-print the receiver
void nextFrame(SampleBuffer where)
write the val to a buffer
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
float nextValue()
answer the next value (dynamic or constant)
unsigned mMonoBufferByteSize
size of each buffer in bytes
void setPhase(float phase)
UGenVector mOutputs
the vector of my output UGens
Scalable – mix-in class with scale and offset control inputs (may be constants or generators)...
UnitGenerator * mGraph
the root of my client DSP graph, often a mixer or panner
virtual void setBuffers(SampleBuffer *sPtr)
Set the buffer pointer (rare; used in joiners)
unsigned mNumOutputs
the number of outputs
#define CSL_NAME_LEN
default string length
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()
Unknown or other data type.
unsigned mNumChannels
num channels in buffer (num mono buffers)
FIR Impulse Response frames.
Cacheable – a mix-in for caching streams.
unsigned mCurrentFrame
where I currently am in the buffer
void zeroBuffer(Buffer &outputBuffer, unsigned outBufNum)
utility method to zero out an outputBuffer
float sample
(could be changed to int, or double)
BufferCopyPolicy copyPolicy()
unsigned mNumChannels
my "expected" number of output channels
float mFrameRate
current SR
virtual void nextBuffer(Buffer &outputBuffer)
nextBuffer processes joiner channels
IO – the abstract I/O scheduling class; subclasses interface to specific I/O APIs.
BufferContentType mType
Data type flag set the internal size variables (no buffer allocation takes place) ...
unsigned mSequence
sequential serial number
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
BufferCopyPolicy
UnitGenerator buffer copy policy flags (for multi-channel expansion)
static unsigned frameRate()
default frame rate
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)
bool mUseCache
whether I'm to cache (vs. compute)
void copySamplesFrom(Buffer &src)
import data from the given buffer
Writeable – a mix-in for buffers and streams that one can write to.
unsigned mValueIndex
my index (into the UGen's buffer)
virtual void trigger()
trigger passed on here
virtual void trigger()
trigger passed on here get the input port
virtual void setBuffer(unsigned bufNum, unsigned offset, sample samp)
void copySamplesFromTo(Buffer &src, unsigned offset)
same with write offset
virtual ~IO()
default is stereo input & output
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
std::vector< UnitGenerator * > UGenVector
void fillWith(sample value)
fill data with the given value
unsigned mNumFramesPlayed
counter of frames I've played
Splitter class – a de-multiplexer for multi-channel signals.
void setInput(UnitGenerator &inp)
set the receiver's input generator
virtual void trigger()
trigger passed on here
Joiner()
< loop through my vector of inputs
virtual void initialize(unsigned sr, unsigned bs, int is, int os, unsigned ic, unsigned oc)
initialize overridden in subclasses
vector< float > mFrameRates
the vector of frame rates I support
unsigned * mChannelMap
the output channel remapping array
double mActualFrame
where I actually am in the buffer
unsigned mOffset
used for capture offset
unsigned mNumOutChannels
outputs
virtual unsigned duration()
virtual void nextBuffer(Buffer &outputBuffer)
I'm mono nextBuffer processes splitter channels.
Status
CSL status flags (for return values)
unsigned mCurrent
the current output
void setFrameRate(unsigned rate)
get/set the receiver's frame rate
virtual void capture_off()
end output capture
unsigned mRealNumChannels
the actual number of channels used
void checkBuffers()
allocate if not already there
void addInput(UnitGenerator &in)
add the argument to vector of inputs
virtual bool isFixed()
query whether I'm fixed (StaticVariable overrides this)
compute 1 channel and copy
void setCopyPolicy(BufferCopyPolicy ch)
get/set the receiver's buffer copy policy
virtual unsigned numOutputs()
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)
IO_Status mStatus
status flag
unsigned mNumRealOutChannels
physical outputs
float duration()
answer the buffer's duration in seconds
bool isReady()
answer whether I'm ready to be read
unsigned mMaxOutputChannels
HW outs
virtual void close()
open/close start/stop methods
FFT complex spectral frames.
void setFrequency(UnitGenerator &frequency)
Setter accessors.
bool mDidIAllocateBuffers
who allocated my data buffers?
Buffer mBuffer
my temp buffer
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)
Buffer mOutputBuffer
the output buffer I use (passed to nextBuffer calls)
virtual ~Port()
Destructor.
ignore extra buffer channels
unsigned mNumRealInChannels
physical inputs
Buffer mInputBuffer
the most recent input buffer (if it's turned on)
unsigned mNumInChannels
inputs
float normalize(float maxVal)
normalize the buffer(s) to the given max; answer the prior max
Joiner class – a multiplexer for multi-channel signals.
Port * getPort(CSL_MAP_KEY name)
struct timeval mThen mNow
used for getting the real time
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
SampleBuffer * SampleBufferVector
Multi-channel buffer data type, vector of (SampleBuffer)
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)
SampleBuffer mInputPointer
the buffer for holding the sound card input (if open)
Buffer(unsigned numChannels=1, unsigned numFrames=CSL_mBlockSize)
Constructor: default is mono and default-size.
Spatial geometry buffers.
bool isInline
whether to use input or buffer as source
IO Device class – a holder for a sound interface with name, id, # IO channels, etc.
BufferCopyPolicy mCopyPolicy
the policy I use if asked for more or fewer channels
virtual void trigger()
am I fixed or dynamic
unsigned getAndIncrementSequence()
increment and answer my seq #
void setScale(UnitGenerator &scale)
set the receiver's scale member to a UGen or a float
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 setNumChannels(unsigned ch)
get/set the receiver's number of outputs
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.
virtual SampleBuffer * buffers()
#define CSL_mBlockSize
normal hosts
Seekable – a mix-in for positionable streams.
virtual void dump()
pretty-print the receiver's input/controls map
virtual Buffer * get_capture()
answer the capture buffer
bool mIsPopulated
does the buffer have data?
Base class of CSL exceptions (written upper-case). Has a string message.
void setInline()
set the Effect to be inline
virtual ~Controllable()
Constructor takes no arguments.
void isScaled()
answer whether scale = 1 & offset = 0