71 for (
unsigned i = 0; i <
mSources.size(); i++) {
78 throw RunTimeError(
"Error removing mixer input: not found.");
83 for (
unsigned i = 0; i <
mSources.size(); i++) {
90 throw RunTimeError(
"Error removing mixer input: not found.");
103 for (
unsigned i = 0; i <
mSources.size(); i++) {
109 logMsg(
"Mixer scaleInput -- input not found");
115 for (
unsigned i = 0; i <
mSources.size(); i++) {
134 for (
unsigned i = 0; i <
mSources.size(); i++)
152 unsigned numIns = mSources.size();
153 unsigned numFrames = outputBuffer.mNumFrames;
158 mOpBuffer.copyHeaderFrom(outputBuffer);
159 outputBuffer.zeroBuffers();
161 for (
int i = 0; i < numIns; i++) {
167 float scal = mScaleValues[i];
168 mOpBuffer.mNumChannels = ich;
169 mOpBuffer.mSequence = outputBuffer.mSequence;
170 mOpBuffer.zeroBuffers();
174 if (ich == mNumChannels) {
175 for (j = 0; j < ich; j++) {
176 out1 = outputBuffer.buffer(j);
177 opp = mOpBuffer.buffer(j);
181 for (k = 0; k < numFrames; k++)
184 for (k = 0; k < numFrames; k++)
185 *out1++ += (*opp++ * scal);
189 else if ((ich == 1) && (mNumChannels == 2)) {
190 out1 = outputBuffer.buffer(0);
191 out2 = outputBuffer.buffer(1);
192 opp = mOpBuffer.buffer(0);
194 for (k = 0; k < numFrames; k++) {
199 for (k = 0; k < numFrames; k++) {
200 *out1++ += *opp * scal;
201 *out2++ += *opp++ * scal;
204 logMsg(
kLogError,
"Error in mix: in = %d ch, out = %d ch\n", ich, mNumChannels);
208 #ifdef DO_MIX_AS_SCALABLE // not defined at present
212 for (j = 0; j < mNumChannels; j++) {
213 out1 = outputBuffer.buffer(j];
214 for (k = 0; k < numFrames; k++) {
216 samp = (samp * scaleValue) + offsetValue;
220 scalePort->resetPtr();
221 offsetPort->resetPtr();
222 scaleValue = scalePort->nextValue();
223 offsetValue = offsetPort->nextValue();
226 mOpBuffer.mAreBuffersZero =
false;
233 fprintf(stderr,
"Mixer -- %d inputs: ", (
int)
mSources.size());
234 for (
unsigned i = 0; i <
mSources.size(); i++) {
236 fprintf(stderr,
"\n");
290 if (outputBuffer.mNumChannels != 2)
294 unsigned numFrames = outputBuffer.mNumFrames;
297 if (checkFanOut(outputBuffer))
return;
308 float posValue = posPort->
nextValue() * 0.5;
310 for (
unsigned i = 0; i < numFrames; i++) {
311 *out1++ = (*inpp) * (0.5 - posValue) * scaleValue;
312 *out2++ = (*inpp++) * (posValue + 0.5) * scaleValue;
316 handleFanOut(outputBuffer);
331 unsigned in_c,
unsigned out_c)
342 unsigned in_c,
unsigned out_c,
float spr)
353 unsigned in_c,
unsigned out_c,
float spr)
376 unsigned numFrames = outputBuffer.mNumFrames;
377 float a_scale, dist, l_samp, r_samp, o_samp;
382 float l_weights[mOutCh], r_weights[mOutCh];
397 l_pos.
set(posXValue, posYValue);
398 r_pos.
set(posXValue, posYValue);
401 for (
unsigned j = 0; j < mOutCh; j++) {
402 dist = mSpeakers[j]->distance(& l_pos);
403 if (dist < 1.0) dist = 1.0;
404 l_weights[j] = 1.0 / dist;
406 dist = mSpeakers[j]->distance(& r_pos);
407 if (dist < 1.0) dist = 1.0;
408 r_weights[j] = 1.0 / dist;
426 inR = mInputs[
CSL_INPUT]->mBuffer->buffer(1);
428 for (
unsigned i = 0; i < numFrames; i++) {
432 for (
unsigned j = 0; j < mOutCh; j++) {
433 o_samp = l_samp * a_scale * l_weights[j];
435 o_samp += r_samp * a_scale * r_weights[j];
436 outputBuffer.setBuffer(j, i, o_samp);
454 printf(
"ERROR: unknown # of channels in NtoM_Panner: %d\n",
mOutCh);
461 float coord = dist * 0.7071;
470 float coord = dist * 0.7071;
516 float panL = sqrt(2*(1.0 - mPan));
517 float panR = sqrt(2*(mPan));
519 float widthFactor = mWidth;
520 if ((fabs(1.0 - panL) < 0.0001) && (fabs(1.0 - panR) < 0.0001) && (fabs(widthFactor) < 0.0001) && (fabs(1.0 - gain) < 0.0001)) {
525 static int count = 0;
527 printf(
"Pan L/R %f/%f \tWidth Factor/Gain %f\n", panL, panR, widthFactor);
531 unsigned numFrames = outputBuffer.mNumFrames;
533 for (
unsigned i = 0; i < numFrames; i++) {
534 newL = *outL + (*outR * widthFactor);
535 newR = *outR + (*outL * widthFactor);
536 *outL++ = newL * panL * gain;
537 *outR++ = newR * panR * gain;
sample * SampleBuffer
1-channel buffer data type, vector of (sample)
#define UPDATE_SCALABLE_CONTROLS
void logMsg(const char *format,...)
These are the public logging messages.
void pullInput(Buffer &outputBuffer)
void init_quad(float dist)
void init_6ch(float x, float y)
virtual void nextBuffer(Buffer &outputBuffer)
I'm stereo!
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Effect – mix-in for classes that have unit generators as inputs (like filters).
UGenVector mSources
mixers with inputs are always active
Buffer mOpBuffer
buffer used for operations, if needed
Panner()
Constructors / destructor.
Illegal operation at run time.
void addOutput(UnitGenerator *ugen)
add to or return the UGen vector of outputs
virtual void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
void freeBuffers()
fcn to free them
void removeInput(UnitGenerator &inp)
void setSize(unsigned numChannels, unsigned numFrames)
void rotateBy(double angle)
float nextValue()
answer the next value (dynamic or constant)
Scalable – mix-in class with scale and offset control inputs (may be constants or generators)...
#define MAX_OUTPUTS
N-channel (max 2 at present) input to M-channel output azimuth panner.
void nextBuffer(Buffer &outputBuffer)
fill the buffer with the next buffer_length of values
static unsigned blockSize()
the default block size
virtual unsigned numChannels()
float sample
(could be changed to int, or double)
void dump()
print info about this instance
unsigned mNumChannels
my "expected" number of output channels
void setPosition(UnitGenerator &pan)
Operations.
FloatVector mScaleValues
scales of inputs
virtual bool isActive()
query whether I'm currently active (Envelopes can go inactive)
void nextBuffer(Buffer &inputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
void allocateOpBuffer(unsigned chans)
allocate the op buffer
virtual void nextBuffer(Buffer &outputBuffer)
I'm stereo!
void init_5point1(float dist)
void scaleInput(UnitGenerator &inp, float val)
set the scale of an input
#define LOAD_SCALABLE_CONTROLS
Load the scale/offset-related values at the start.
unsigned getNumInputs(void)
list of inputs, arbitrary # of channels
void init_stereo(float dist)
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
void allocateBuffers()
fcn to malloc storage buffers
Port – used to represent constant, control-rate or signal inputs and outputs in named maps; holds a ...
The CSL mono-to-stereo L/R panner class.
void addInput(CSL_MAP_KEY name, UnitGenerator &ugen)
Plug in a unit generator to the named input slot.
void addInput(UnitGenerator &inp)
void pullInput(Port *thePort, unsigned numFrames)
method to read the control values (in case they're dynamic). this sends nextBuffer() to the input...
Base class of CSL exceptions (written upper-case). Has a string message.
#define DECLARE_SCALABLE_CONTROLS
Macros for all the Scalable UnitGenerators (note that these don't end with ";")