19 logMsg(
"FrequencyAmount::add null inputs");
30 logMsg(
"FrequencyAmount::set scale input UG");
37 logMsg(
"FrequencyAmount::set scale input value");
48 logMsg(
"FrequencyAmount::set offset input UG");
55 logMsg(
"FrequencyAmount::set offset input value");
107 logMsg(
"Filter nextBuffer");
110 unsigned numFrames = outputBuffer.mNumFrames;
120 bool isDynamic =
false;
121 if ((freqPort && ( ! freqPort->isFixed())) || (bwPort && ( ! bwPort->isFixed())))
126 inputPtr = mInputPtr;
133 for (
unsigned i = 0; i < numFrames; i++) {
137 *prevIPtr = scaleValue * *inputPtr++ + offsetValue;
138 for (
unsigned j = mBNum - 1; j > 0; j--) {
139 *prevOPtr += mBCoeff[j] * prevIns[j];
140 prevIns[j] = prevIns[j-1];
142 *prevOPtr += mBCoeff[0] * prevIns[0];
143 for (
unsigned j = mANum - 1; j > 0; j--) {
144 *prevOPtr += -mACoeff[j] * prevOuts[j];
145 prevOuts[j] = prevOuts[j-1];
148 *out++ = (*prevOPtr * scaleValue) + offsetValue;
157 for (
unsigned i = 0; i < num_b; i++)
159 for (
unsigned i = 0; i < num_a; i++)
174 fprintf(stderr,
"A coefficients ");
175 for (
unsigned i=0;i<
mANum;i++) {
176 fprintf(stderr,
"%.2f, ",
mACoeff[i]);
178 fprintf(stderr,
"\n");
179 fprintf(stderr,
"B coefficients ");
180 for (
unsigned i=0;i<
mBNum;i++) {
181 fprintf(stderr,
"%.2f, ",
mBCoeff[i]);
183 fprintf(stderr,
"\n");
330 float w0 = 2.0f * (float) M_PI * (centreFreq / FS);
331 float cosW = cosf(w0);
332 float sinW = sinf(w0);
333 float A = pow(10.0f, (dB / 40.0f));
334 float alpha = sinW / (2.0f *
Q);
335 float beta = pow(A, 0.5f) /
Q;
341 mBCoeff[0] = (1.0f - cosW) / 2.0f;
343 mBCoeff[2] = (1.0f - cosW) / 2.0f;
349 mBCoeff[0] = (1.0f + cosW)/2.0f;
351 mBCoeff[2] = (1.0f + cosW)/2.0f;
373 mBCoeff[0] = A* ((A + 1.0f) - ((A -1.0f) * cosW) + beta * sinW);
374 mBCoeff[1] = 2.0f * A * ((A - 1.0f) - ((A + 1.0f) * cosW));
375 mBCoeff[2] = A * ((A + 1.0f) - (A - 1.0f) * cosW - beta * sinW);
376 mACoeff[0] = ((A + 1.0f) + (A - 1.0f) * cosW + beta * sinW);
377 mACoeff[1] = -2.0f * ((A - 1.0f) + (A + 1.0f) * cosW);
378 mACoeff[2] = ((A + 1.0f) + (A - 1.0f) * cosW - (beta * sinW));
381 mBCoeff[0] = A * ((A + 1.0f) + (A - 1.0f) * cosW + beta * sinW);
382 mBCoeff[1] = -2.0f * A * ((A - 1.0f) + (A + 1.0f) * cosW);
383 mBCoeff[2] = A * ((A + 1.0f) + (A - 1.0f) * cosW - beta * sinW);
384 mACoeff[0] = ((A + 1.0f) - (A - 1.0f) * cosW + beta * sinW);
385 mACoeff[1] = 2.0f * ((A - 1.0f) - (A + 1.0f) * cosW);
386 mACoeff[2] = ((A + 1.0f) - (A - 1.0f) * cosW - beta * sinW);
389 mBCoeff[0] = 1.0f + (alpha * A);
390 mBCoeff[1] = -2.0f * cosW;
391 mBCoeff[2] = 1.0f - (alpha * A);
392 mACoeff[0] = 1.0f + (alpha / A);
393 mACoeff[1] = -2.0f * cosW;
394 mACoeff[2] = 1.0f - (alpha / A);
404 float V = powf(10.0f, fabs(dB) / 20.0f);
405 float K = tanf((
float) M_PI *
Fc);
410 norm = 1.0f / (1.0f + K /
Q + K * K);
414 b1 = 2.0f * (K * K - 1.0f) * norm;
415 b2 = (1.0f - K /
Q + K * K) * norm;
418 norm = 1.0f / (1.0f + K /
Q + K * K);
422 b1 = 2.0f * (K * K - 1.0f) * norm;
423 b2 = (1.0f - K /
Q + K * K) * norm;
426 norm = 1.0f / (1.0f + K /
Q + K * K);
430 b1 = 2.0f * (K * K - 1.0f) * norm;
431 b2 = (1.0f - K /
Q + K * K) * norm;
434 norm = 1.0f / (1.0f + K /
Q + K * K);
435 a0 = (1.0f + K * K) * norm;
436 a1 = 2.0f * (K * K - 1.0f) * norm;
439 b2 = (1.0f - K /
Q + K * K) * norm;
443 norm = 1.0f / (1.0f + 1.0f /
Q * K + K * K);
444 a0 = (1.0f + V /
Q * K + K * K) * norm;
445 a1 = 2.0f * (K * K - 1.0f) * norm;
446 a2 = (1.0f - V /
Q * K + K * K) * norm;
448 b2 = (1.0f - 1.0f /
Q * K + K * K) * norm;
450 norm = 1.0f / (1.0f + V /
Q * K + K * K);
451 a0 = (1.0f + 1.0f /
Q * K + K * K) * norm;
452 a1 = 2.0f * (K * K - 1) * norm;
453 a2 = (1.0f - 1.0f /
Q * K + K * K) * norm;
455 b2 = (1.0f - V /
Q * K + K * K) * norm;
460 norm = 1.0f / (1.0f + sqrtf(2.0f) * K + K * K);
461 a0 = (1.0f + sqrtf(2.0f * V) * K + V * K * K) * norm;
462 a1 = 2.0f * (V * K * K - 1.0f) * norm;
463 a2 = (1.0f - sqrtf(2.0f * V) * K + V * K * K) * norm;
464 b1 = 2.0f * (K * K - 1.0f) * norm;
465 b2 = (1.0f - sqrtf(2.0f) * K + K * K) * norm;
467 norm = 1.0f / (1.0f + sqrtf(2.0f * V) * K + V * K * K);
468 a0 = (1.0f + sqrtf(2.0f) * K + K * K) * norm;
469 a1 = 2.0f * (K * K - 1.0f) * norm;
470 a2 = (1.0f - sqrtf(2.0f) * K + K * K) * norm;
471 b1 = 2.0f * (V * K * K - 1.0f) * norm;
472 b2 = (1.0f - sqrtf(2.0f * V) * K + V * K * K) * norm;
477 norm = 1.0f / (1.0f + sqrtf(2.0f) * K + K * K);
478 a0 = (V + sqrtf(2.0f * V) * K + K * K) * norm;
479 a1 = 2.0f * (K * K - V) * norm;
480 a2 = (V - sqrtf(2.0f * V) * K + K * K) * norm;
481 b1 = 2.0f * (K * K - 1.0f) * norm;
482 b2 = (1.0f - sqrtf(2.0f) * K + K * K) * norm;
484 norm = 1.0f / (V + sqrtf(2.0f * V) * K + K * K);
485 a0 = (1.0f + sqrtf(2.0f) * K + K * K) * norm;
486 a1 = 2.0f * (K * K - 1.0f) * norm;
487 a2 = (1.0f - sqrtf(2.0f) * K + K * K) * norm;
488 b1 = 2.0f * (K * K - V) * norm;
489 b2 = (V - sqrtf(2.0f * V) * K + K * K) * norm;
523 unsigned numFrames = outputBuffer.mNumFrames;
531 for (
unsigned i = 0; i < numFrames; i++) {
533 float samp = inV * a0 + z1;
534 z1 = inV * a1 + z2 - b1 * samp;
535 z2 = inV * a2 - b2 * samp;
572 mACoeff[2] = radius * radius;
574 mBCoeff[0] = 0.5 - 0.5 * mACoeff[2];
576 mBCoeff[2] = -mBCoeff[0];
604 mBCoeff[2] = radius * radius;
628 mACoeff[0] = mBCoeff[1] = 1.0;
629 mBCoeff[0] = mACoeff[1] = coefficient;
668 logMsg(
"Moog Filter nextBuffer");
670 sample* out = outputBuffer.buffer(outBufNum);
671 unsigned numFrames = outputBuffer.mNumFrames;
679 for (
unsigned i = 0; i < numFrames; i++) {
682 x = *inputPtr++ - r * y4;
684 y1 = x * p + oldx * p - k * y1;
685 y2 = y1 * p + oldy1 * p - k * y2;
686 y3 = y2 * p + oldy2 * p - k * y3;
687 y4 = y3 * p + oldy3 * p - k * y4;
689 y4 = y4 - (y4*y4*y4) / 6;
707 k = 3.6 * f - 1.6 * f * f - 1;
709 scale = exp((1 -
p ) * 1.386249 );
710 r = resonance * scale;
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.
Buffer * mPrevInputs
arrays of past input and output samples
void pullInput(Buffer &outputBuffer)
unsigned mBNum
number of coeffs in b
#define CSL_FILTER_FREQUENCY
virtual void setupCoeffs()
float mBCoeff[FILTER_MAX_COEFFICIENTS]
array of numerator coeffs
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Effect – mix-in for classes that have unit generators as inputs (like filters).
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
Notch(UnitGenerator &in, float center_freq, float radius)
constructors & destructor
unsigned mFrameRate
trigger ignored here
#define DECLARE_FILTER_CONTROLS
Declare the pointer to freq/bw buffers (if used) and current scale/offset values. ...
void setAmount(UnitGenerator &amount)
set the receiver's amount to a UGen or a float
Filter: the canonical-form n-pole/m-zero filter class.
static float frameRateF()
default frame rate as a float
float Q
ctr frq (Hz), peak (dB), Q(uality) factor
void zeroBuffers()
fill all data with 0
virtual void dump()
pretty-print the receiver
~FrequencyAmount()
Destructor.
void dump()
log information about myself
Scalable – mix-in class with scale and offset control inputs (may be constants or generators)...
#define LOAD_FILTER_CONTROLS
Load the freq/bw-related values at the start.
int mFilterType
flag as to what kind of filter I am
float sample
(could be changed to int, or double)
static unsigned frameRate()
default frame rate
FrequencyAmount()
Constructors.
unsigned mANum
number of coeffs in a
#define CSL_FILTER_AMOUNT
Filter()
Generic Filter class with scalable order and generic next_buffer method that implememnts the canonica...
void setFrequency(UnitGenerator &frequency)
set the receiver's frequency to a UGen or a float
#define LOAD_SCALABLE_CONTROLS
Load the scale/offset-related values at the start.
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
~Filter()
Filter destructor frees temp memory.
Port * getPort(CSL_MAP_KEY name)
void allocateBuffers()
fcn to malloc storage buffers
void addInput(CSL_MAP_KEY name, UnitGenerator &ugen)
Plug in a unit generator to the named input slot.
PortMap mInputs
the map of my inputs or controls (used by the mix-in classes)
Allpass(UnitGenerator &in, float coeff)
float mACoeff[FILTER_MAX_COEFFICIENTS]
array of denominator coeffs
virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
void clear(void)
clears the input/output buffers
void init(unsigned a, unsigned b)
shared initialization function
virtual void dump()
pretty-print the receiver's input/controls map
Butter()
Butterworth IIR (2nd order recursive) filter. This operates upon a buffer of frames of amplitude samp...
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 ";")