FFT: Prevent user from attempting hops smaller than SC's block size
[supercollider.git] / server / plugins / FilterUGens.cpp
blob46f9a8145465c62a813981b1ff679cec6dff5982
1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SC_PlugIn.h"
24 #define PI 3.1415926535898f
26 #define PUSH_LOOPVALS \
27 int tmp_floops = unit->mRate->mFilterLoops; \
28 int tmp_fremain = unit->mRate->mFilterRemain; \
29 unit->mRate->mFilterLoops = 0; \
30 unit->mRate->mFilterRemain = 1;
32 #define POP_LOOPVALS \
33 unit->mRate->mFilterLoops = tmp_floops; \
34 unit->mRate->mFilterRemain = tmp_fremain;
36 using namespace std; // for math functions
38 static InterfaceTable *ft;
40 struct Ramp : public Unit
42 double m_level, m_slope;
43 int m_counter;
46 struct Lag : public Unit
48 float m_lag, m_b1, m_y1;
51 struct Lag2 : public Unit
53 float m_lag, m_b1, m_y1a, m_y1b;
56 struct Lag3 : public Unit
58 float m_lag, m_b1, m_y1a, m_y1b, m_y1c;
61 struct LagUD : public Unit
63 float m_lagu, m_lagd, m_b1u, m_b1d, m_y1;
66 struct Lag2UD : public Unit
68 float m_lagu, m_lagd, m_b1u, m_b1d, m_y1a, m_y1b;
71 struct Lag3UD : public Unit
73 float m_lagu, m_lagd, m_b1u, m_b1d, m_y1a, m_y1b, m_y1c;
76 struct VarLag : public Unit
78 double m_level, m_slope;
79 int m_counter;
80 float m_in, m_lagTime;
83 struct OnePole : public Unit
85 float m_b1, m_y1;
88 struct OneZero : public Unit
90 float m_b1, m_x1;
93 struct Integrator : public Unit
95 float m_b1, m_y1;
98 struct Decay : public Unit
100 float m_decayTime, m_y1, m_b1;
103 struct Decay2 : public Unit
105 float m_attackTime, m_y1a, m_b1a;
106 float m_decayTime, m_y1b, m_b1b;
109 struct LeakDC : public Unit
111 double m_b1, m_x1, m_y1;
114 struct TwoPole : public Unit
116 float m_y1, m_y2, m_b1, m_b2, m_freq, m_reson;
119 struct APF : public Unit
121 float m_y1, m_y2, m_x1, m_x2, m_b1, m_b2, m_freq, m_reson;
124 struct TwoZero : public Unit
126 float m_x1, m_x2, m_b1, m_b2, m_freq, m_reson;
129 struct LPZ1 : public Unit
131 float m_x1;
134 struct HPZ1 : public Unit
136 float m_x1;
139 struct HPZ2 : public Unit
141 float m_x1, m_x2;
144 struct BPZ2 : public Unit
146 float m_x1, m_x2;
149 struct BRZ2 : public Unit
151 float m_x1, m_x2;
154 struct LPZ2 : public Unit
156 float m_x1, m_x2;
159 struct Flip : public Unit
163 struct Delay1 : public Unit
165 float m_x1;
168 struct Delay2 : public Unit
170 float m_x1, m_x2;
173 struct Slope : public Unit
175 float m_x1;
178 struct Slew : public Unit
180 float mLevel;
183 struct RLPF : public Unit
185 float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq, m_reson;
188 struct RHPF : public Unit
190 double m_y1, m_y2, m_a0, m_b1, m_b2;
191 float m_freq, m_reson;
194 struct LPF : public Unit
196 float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq;
199 struct HPF : public Unit
201 double m_y1, m_y2, m_a0, m_b1, m_b2;
202 float m_freq;
205 struct BPF : public Unit
207 float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq, m_bw;
210 struct BRF : public Unit
212 float m_y1, m_y2, m_a0, m_a1, m_b2, m_freq, m_bw;
215 struct MidEQ : public Unit
217 float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq, m_bw, m_db;
220 struct Resonz : public Unit
222 float m_y1, m_y2, m_a0, m_b1, m_b2, m_freq, m_rq;
225 struct Ringz : public Unit
227 float m_y1, m_y2, m_b1, m_b2, m_freq, m_decayTime;
230 struct FOS : public Unit
232 float m_y1, m_a0, m_a1, m_b1;
235 struct SOS : public Unit
237 float m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
240 struct Formlet : public Unit
242 float m_freq, m_decayTime, m_attackTime;
243 float m_y01, m_y02, m_b01, m_b02;
244 float m_y11, m_y12, m_b11, m_b12;
247 const int kMAXMEDIANSIZE = 32;
249 struct Median : public Unit
251 float m_medianValue[kMAXMEDIANSIZE];
252 long m_medianAge[kMAXMEDIANSIZE];
253 long m_medianSize, m_medianIndex;
256 struct Compander : public Unit
258 float m_prevmaxval, m_gain, m_clamp, m_clampcoef, m_relax, m_relaxcoef;
261 struct Normalizer : public Unit
263 float *m_table, *m_xinbuf, *m_xoutbuf, *m_xmidbuf;
264 long m_flips, m_pos, m_bufsize;
265 float m_slope, m_level, m_curmaxval, m_prevmaxval, m_slopefactor;
268 struct Limiter : public Unit
270 float *m_table, *m_xinbuf, *m_xoutbuf, *m_xmidbuf;
271 long m_flips, m_pos, m_bufsize;
272 float m_slope, m_level, m_curmaxval, m_prevmaxval, m_slopefactor;
276 struct Amplitude : public Unit
278 float m_previn, m_clampcoef, m_relaxcoef, m_clamp_in, m_relax_in;
281 struct DetectSilence : public Unit
283 float mThresh;
284 int32 mCounter, mEndCounter;
287 struct Hilbert : public Unit
289 float m_coefs[12];
290 float m_y1[12];
293 struct FreqShift : public Unit
295 float m_coefs[12];
296 float m_y1[12];
297 int32 m_phase;
298 int32 m_phaseoffset, m_lomask;
299 double m_cpstoinc, m_radtoinc, m_phasein;
303 struct MoogFF : public Unit
305 float m_freq, m_b0, m_a1; // Resonant freq and corresponding vals; stored because we need to compare against prev vals
306 double m_wcD;
308 float m_s1, m_s2, m_s3, m_s4; // 1st order filter states
311 //////////////////////////////////////////////////////////////////////////////////////////////////
314 extern "C"
317 void Ramp_next(Ramp *unit, int inNumSamples);
318 void Ramp_next_1(Ramp *unit, int inNumSamples);
319 void Ramp_Ctor(Ramp* unit);
321 void Lag_next(Lag *unit, int inNumSamples);
322 void Lag_Ctor(Lag* unit);
324 void Lag2_Ctor(Lag2* unit);
326 void Lag3_next(Lag3 *unit, int inNumSamples);
327 void Lag3_Ctor(Lag3* unit);
329 void LagUD_next(LagUD *unit, int inNumSamples);
330 void LagUD_Ctor(LagUD* unit);
332 void Lag2UD_next(Lag2UD *unit, int inNumSamples);
333 void Lag2UD_Ctor(Lag2UD* unit);
335 void Lag3UD_next(Lag3UD *unit, int inNumSamples);
336 void Lag3UD_Ctor(Lag3UD* unit);
338 void VarLag_next(VarLag *unit, int inNumSamples);
339 void VarLag_Ctor(VarLag* unit);
341 void OnePole_next_a(OnePole *unit, int inNumSamples);
342 void OnePole_next_k(OnePole *unit, int inNumSamples);
343 void OnePole_Ctor(OnePole* unit);
345 void OneZero_next(OneZero* unit, int inNumSamples);
346 void OneZero_Ctor(OneZero* unit);
348 void Integrator_next(Integrator *unit, int inNumSamples);
349 void Integrator_Ctor(Integrator* unit);
351 void Decay_next(Decay *unit, int inNumSamples);
352 void Decay_Ctor(Decay* unit);
354 void Decay2_next(Decay2 *unit, int inNumSamples);
355 void Decay2_Ctor(Decay2* unit);
357 void LeakDC_next(LeakDC *unit, int inNumSamples);
358 void LeakDC_next_1(LeakDC* unit, int inNumSamples);
359 void LeakDC_Ctor(LeakDC* unit);
361 void TwoPole_next(TwoPole *unit, int inNumSamples);
362 void TwoPole_Ctor(TwoPole* unit);
364 void TwoZero_next(TwoZero *unit, int inNumSamples);
365 void TwoZero_Ctor(TwoZero* unit);
367 void APF_next(APF *unit, int inNumSamples);
368 void APF_Ctor(APF* unit);
370 void LPZ1_next(LPZ1 *unit, int inNumSamples);
371 void LPZ1_Ctor(LPZ1* unit);
373 void HPZ1_next(HPZ1 *unit, int inNumSamples);
374 void HPZ1_Ctor(HPZ1* unit);
376 void Slope_next(Slope *unit, int inNumSamples);
377 void Slope_Ctor(Slope* unit);
379 void Delay1_next(Delay1 *unit, int inNumSamples);
380 void Delay1_Ctor(Delay1* unit);
382 void Flip_Ctor(Flip* unit);
383 void Flip_next_even(Flip *unit, int inNumSamples);
384 void Flip_next_odd(Flip *unit, int inNumSamples);
386 void Delay2_next(Delay2 *unit, int inNumSamples);
387 void Delay2_Ctor(Delay2* unit);
389 void LPZ2_next(LPZ2 *unit, int inNumSamples);
390 void LPZ2_Ctor(LPZ2* unit);
392 void HPZ2_next(HPZ2 *unit, int inNumSamples);
393 void HPZ2_Ctor(HPZ2* unit);
395 void BPZ2_next(BPZ2 *unit, int inNumSamples);
396 void BPZ2_Ctor(BPZ2* unit);
398 void BRZ2_next(BRZ2 *unit, int inNumSamples);
399 void BRZ2_Ctor(BRZ2* unit);
401 void Slew_next(Slew *unit, int inNumSamples);
402 void Slew_Ctor(Slew* unit);
404 void RLPF_next(RLPF *unit, int inNumSamples);
405 void RLPF_next_1(RLPF *unit, int inNumSamples);
406 void RLPF_Ctor(RLPF* unit);
408 void RHPF_next(RHPF *unit, int inNumSamples);
409 void RHPF_next_1(RHPF *unit, int inNumSamples);
410 void RHPF_Ctor(RHPF* unit);
412 void LPF_next(LPF *unit, int inNumSamples);
413 void LPF_next_1(LPF *unit, int inNumSamples);
414 void LPF_Ctor(LPF* unit);
416 void HPF_next(HPF *unit, int inNumSamples);
417 void HPF_next_1(HPF *unit, int inNumSamples);
418 void HPF_Ctor(HPF* unit);
420 void BPF_next(BPF *unit, int inNumSamples);
421 void BPF_next_1(BPF *unit, int inNumSamples);
422 void BPF_Ctor(BPF* unit);
424 void BRF_next(BRF *unit, int inNumSamples);
425 void BRF_next_1(BRF *unit, int inNumSamples);
426 void BRF_Ctor(BRF* unit);
428 void Median_next(Median *unit, int inNumSamples);
429 void Median_Ctor(Median* unit);
431 void MidEQ_next(MidEQ *unit, int inNumSamples);
432 void MidEQ_Ctor(MidEQ* unit);
434 void Resonz_next(Resonz *unit, int inNumSamples);
435 void Resonz_Ctor(Resonz* unit);
437 void Ringz_next(Ringz *unit, int inNumSamples);
438 void Ringz_Ctor(Ringz* unit);
440 void Formlet_next(Formlet *unit, int inNumSamples);
441 void Formlet_next_1(Formlet *unit, int inNumSamples);
442 void Formlet_Ctor(Formlet* unit);
444 void FOS_next_k(FOS *unit, int inNumSamples);
445 void FOS_next_a(FOS *unit, int inNumSamples);
446 void FOS_next_1(FOS *unit, int inNumSamples);
447 void FOS_Ctor(FOS* unit);
449 void SOS_next_k(SOS *unit, int inNumSamples);
450 void SOS_next_a(SOS *unit, int inNumSamples);
451 void SOS_next_1(SOS *unit, int inNumSamples);
452 void SOS_Ctor(SOS* unit);
454 void Normalizer_next(Normalizer *unit, int inNumSamples);
455 void Normalizer_Ctor(Normalizer* unit);
456 void Normalizer_Dtor(Normalizer* unit);
458 void Limiter_next(Limiter *unit, int inNumSamples);
459 void Limiter_Ctor(Limiter* unit);
460 void Limiter_Dtor(Limiter* unit);
462 void Compander_next(Compander *unit, int inNumSamples);
463 void Compander_Ctor(Compander* unit);
465 void Amplitude_next(Amplitude *unit, int inNumSamples);
466 void Amplitude_next_kk(Amplitude *unit, int inNumSamples);
467 void Amplitude_next_atok(Amplitude *unit, int inNumSamples);
468 void Amplitude_next_atok_kk(Amplitude *unit, int inNumSamples);
469 void Amplitude_Ctor(Amplitude* unit);
471 void DetectSilence_next(DetectSilence *unit, int inNumSamples);
472 void DetectSilence_done(DetectSilence *unit, int inNumSamples);
473 void DetectSilence_Ctor(DetectSilence* unit);
475 void Hilbert_Ctor(Hilbert* unit);
476 void Hilbert_next(Hilbert *unit, int inNumSamples);
478 void FreqShift_Ctor(FreqShift* unit);
479 void FreqShift_next_kk(FreqShift *unit, int inNumSamples);
480 void FreqShift_next_aa(FreqShift *unit, int inNumSamples);
481 void FreqShift_next_ak(FreqShift *unit, int inNumSamples);
482 void FreqShift_next_ka(FreqShift *unit, int inNumSamples);
484 void MoogFF_next(MoogFF *unit, int inNumSamples);
485 void MoogFF_Ctor(MoogFF* unit);
488 void Lag_next(Lag *unit, int inNumSamples);
489 void Lag_Ctor(Lag* unit);
491 void Lag_next(Lag *unit, int inNumSamples);
492 void Lag_Ctor(Lag* unit);
496 //////////////////////////////////////////////////////////////////////////////////////////////////
498 void Ramp_next(Ramp *unit, int inNumSamples)
500 float *out = ZOUT(0);
501 float *in = IN(0);
502 float period = ZIN0(1);
504 double slope = unit->m_slope;
505 double level = unit->m_level;
506 int counter = unit->m_counter;
507 int remain = inNumSamples;
508 while (remain) {
509 int nsmps = sc_min(remain, counter);
510 LOOP(nsmps,
511 ZXP(out) = level;
512 level += slope;
514 in += nsmps;
515 counter -= nsmps;
516 remain -= nsmps;
517 if (counter <= 0) {
518 counter = (int)(period * SAMPLERATE);
519 counter = sc_max(1, counter);
520 slope = (*in - level) / counter;
523 unit->m_level = level;
524 unit->m_slope = slope;
525 unit->m_counter = counter;
528 void Ramp_next_1(Ramp *unit, int inNumSamples)
530 float *out = OUT(0);
532 *out = unit->m_level;
533 unit->m_level += unit->m_slope;
534 if (--unit->m_counter <= 0) {
535 float in = ZIN0(0);
536 float period = ZIN0(1);
537 int counter = (int)(period * SAMPLERATE);
538 unit->m_counter = counter = sc_max(1, counter);
539 unit->m_slope = (in - unit->m_level) / counter;
543 void Ramp_Ctor(Ramp* unit)
545 if (BUFLENGTH == 1) {
546 SETCALC(Ramp_next_1);
547 } else {
548 SETCALC(Ramp_next);
551 unit->m_counter = 1;
552 unit->m_level = ZIN0(0);
553 unit->m_slope = 0.f;
554 ZOUT0(0) = unit->m_level;
557 //////////////////////////////////////////////////////////////////////////////////////////////////
559 void Lag_next(Lag *unit, int inNumSamples)
561 float *out = ZOUT(0);
562 float *in = ZIN(0);
563 float lag = ZIN0(1);
566 float y1 = unit->m_y1;
567 float b1 = unit->m_b1;
569 if (lag == unit->m_lag) {
570 LOOP1(inNumSamples,
571 float y0 = ZXP(in);
572 ZXP(out) = y1 = y0 + b1 * (y1 - y0);
574 } else {
575 unit->m_b1 = lag == 0.f ? 0.f : exp(log001 / (lag * unit->mRate->mSampleRate));
576 float b1_slope = CALCSLOPE(unit->m_b1, b1);
577 unit->m_lag = lag;
578 LOOP1(inNumSamples,
579 b1 += b1_slope;
580 float y0 = ZXP(in);
581 ZXP(out) = y1 = y0 + b1 * (y1 - y0);
584 unit->m_y1 = zapgremlins(y1);
587 void Lag_next_1(Lag *unit, int inNumSamples)
589 float *out = OUT(0);
590 float *in = IN(0);
591 float lag = IN0(1);
593 float y1 = unit->m_y1;
594 float b1 = unit->m_b1;
596 if (lag == unit->m_lag) {
597 float y0 = *in;
598 *out = y1 = y0 + b1 * (y1 - y0);
599 } else {
600 unit->m_b1 = b1 = lag == 0.f ? 0.f : exp(log001 / (lag * unit->mRate->mSampleRate));
601 unit->m_lag = lag;
602 float y0 = *in;
603 *out = y1 = y0 + b1 * (y1 - y0);
605 unit->m_y1 = zapgremlins(y1);
608 void Lag_Ctor(Lag* unit)
610 if (BUFLENGTH == 1)
611 SETCALC(Lag_next_1);
612 else
613 SETCALC(Lag_next);
615 unit->m_lag = 0.f;
616 unit->m_b1 = 0.f;
617 unit->m_y1 = ZIN0(0);
618 Lag_next(unit, 1);
621 //////////////////////////////////////////////////////////////////////////////////////////////////
622 void LagUD_next(LagUD *unit, int inNumSamples)
624 float *out = ZOUT(0);
625 float *in = ZIN(0);
626 float lagu = ZIN0(1);
627 float lagd = ZIN0(2);
629 float y1 = unit->m_y1;
630 float b1u = unit->m_b1u;
631 float b1d = unit->m_b1d;
633 if ( (lagu == unit->m_lagu) && (lagd == unit->m_lagd) ) {
634 LOOP1(inNumSamples,
635 float y0 = ZXP(in);
636 if ( y0 > y1 )
637 ZXP(out) = y1 = y0 + b1u * (y1 - y0);
638 else
639 ZXP(out) = y1 = y0 + b1d * (y1 - y0);
641 } else {
642 unit->m_b1u = lagu == 0.f ? 0.f : exp(log001 / (lagu * unit->mRate->mSampleRate));
643 float b1u_slope = CALCSLOPE(unit->m_b1u, b1u);
644 unit->m_lagu = lagu;
645 unit->m_b1d = lagd == 0.f ? 0.f : exp(log001 / (lagd * unit->mRate->mSampleRate));
646 float b1d_slope = CALCSLOPE(unit->m_b1d, b1d);
647 unit->m_lagd = lagd;
648 LOOP1(inNumSamples,
649 b1u += b1u_slope;
650 b1d += b1d_slope;
651 float y0 = ZXP(in);
652 if ( y0 > y1 )
653 ZXP(out) = y1 = y0 + b1u * (y1 - y0);
654 else
655 ZXP(out) = y1 = y0 + b1d * (y1 - y0);
658 unit->m_y1 = zapgremlins(y1);
661 void LagUD_Ctor(LagUD* unit)
663 SETCALC(LagUD_next);
665 unit->m_lagu = 0.f;
666 unit->m_lagd = 0.f;
667 unit->m_b1u = 0.f;
668 unit->m_b1d = 0.f;
669 unit->m_y1 = ZIN0(0);
670 LagUD_next(unit, 1);
673 //////////////////////////////////////////////////////////////////////////////////////////////////
675 static void Lag2_next_k(Lag2 *unit, int inNumSamples)
677 float *out = ZOUT(0);
678 float *in = ZIN(0);
679 float lag = ZIN0(1);
681 float y1a = unit->m_y1a;
682 float y1b = unit->m_y1b;
683 float b1 = unit->m_b1;
685 if (lag == unit->m_lag) {
686 LOOP1(inNumSamples,
687 float y0a = ZXP(in);
688 y1a = y0a + b1 * (y1a - y0a);
689 y1b = y1a + b1 * (y1b - y1a);
690 ZXP(out) = y1b;
692 } else {
693 unit->m_b1 = lag == 0.f ? 0.f : exp(log001 / (lag * unit->mRate->mSampleRate));
694 float b1_slope = CALCSLOPE(unit->m_b1, b1);
695 unit->m_lag = lag;
696 LOOP1(inNumSamples,
697 b1 += b1_slope;
698 float y0a = ZXP(in);
699 y1a = y0a + b1 * (y1a - y0a);
700 y1b = y1a + b1 * (y1b - y1a);
701 ZXP(out) = y1b;
704 unit->m_y1a = zapgremlins(y1a);
705 unit->m_y1b = zapgremlins(y1b);
708 static void Lag2_next_i(Lag2 *unit, int inNumSamples)
710 float *out = ZOUT(0);
711 float *in = ZIN(0);
713 float y1a = unit->m_y1a;
714 float y1b = unit->m_y1b;
715 float b1 = unit->m_b1;
717 LOOP1(inNumSamples,
718 float y0a = ZXP(in);
719 y1a = y0a + b1 * (y1a - y0a);
720 y1b = y1a + b1 * (y1b - y1a);
721 ZXP(out) = y1b;
723 unit->m_y1a = zapgremlins(y1a);
724 unit->m_y1b = zapgremlins(y1b);
727 static void Lag2_next_1_i(Lag2 *unit, int inNumSamples)
729 float y1a = unit->m_y1a;
730 float y1b = unit->m_y1b;
731 float b1 = unit->m_b1;
733 float y0a = ZIN0(0);
734 y1a = y0a + b1 * (y1a - y0a);
735 y1b = y1a + b1 * (y1b - y1a);
736 ZOUT0(0) = y1b;
738 unit->m_y1a = zapgremlins(y1a);
739 unit->m_y1b = zapgremlins(y1b);
742 void Lag2_Ctor(Lag2* unit)
744 switch (INRATE(1)) {
745 case calc_FullRate:
746 case calc_BufRate:
747 SETCALC(Lag2_next_k);
748 break;
750 default:
751 if (BUFLENGTH == 1)
752 SETCALC(Lag2_next_1_i);
753 else
754 SETCALC(Lag2_next_i);
755 break;
758 unit->m_lag = 0.f;
759 unit->m_b1 = 0.f;
760 unit->m_y1a = unit->m_y1b = ZIN0(0);
761 Lag2_next_k(unit, 1);
764 //////////////////////////////////////////////////////////////////////////////////////////////////
766 void Lag2UD_next(Lag2UD *unit, int inNumSamples)
768 float *out = ZOUT(0);
769 float *in = ZIN(0);
770 float lagu = ZIN0(1);
771 float lagd = ZIN0(2);
773 float y1a = unit->m_y1a;
774 float y1b = unit->m_y1b;
775 float b1u = unit->m_b1u;
776 float b1d = unit->m_b1d;
778 if ( (lagu == unit->m_lagu) && (lagd == unit->m_lagd) ) {
779 LOOP1(inNumSamples,
780 float y0a = ZXP(in);
781 if ( y0a > y1a ) {
782 y1a = y0a + b1u * (y1a - y0a);
783 } else {
784 y1a = y0a + b1d * (y1a - y0a);
786 if ( y1a > y1b )
787 y1b = y1a + b1u * (y1b - y1a);
788 else
789 y1b = y1a + b1d * (y1b - y1a);
790 ZXP(out) = y1b;
792 } else {
793 unit->m_b1u = lagu == 0.f ? 0.f : exp(log001 / (lagu * unit->mRate->mSampleRate));
794 float b1u_slope = CALCSLOPE(unit->m_b1u, b1u);
795 unit->m_lagu = lagu;
796 unit->m_b1d = lagd == 0.f ? 0.f : exp(log001 / (lagd * unit->mRate->mSampleRate));
797 float b1d_slope = CALCSLOPE(unit->m_b1d, b1d);
798 unit->m_lagd = lagd;
799 LOOP1(inNumSamples,
800 b1u += b1u_slope;
801 b1d += b1d_slope;
802 float y0a = ZXP(in);
803 if ( y0a > y1a ) {
804 y1a = y0a + b1u * (y1a - y0a);
805 } else {
806 y1a = y0a + b1d * (y1a - y0a);
808 if ( y1a > y1b )
809 y1b = y1a + b1u * (y1b - y1a);
810 else
811 y1b = y1a + b1d * (y1b - y1a);
812 ZXP(out) = y1b;
815 unit->m_y1a = zapgremlins(y1a);
816 unit->m_y1b = zapgremlins(y1b);
819 void Lag2UD_Ctor(Lag2UD* unit)
821 SETCALC(Lag2UD_next);
823 unit->m_lagu = 0.f;
824 unit->m_lagd = 0.f;
825 unit->m_b1u = 0.f;
826 unit->m_b1d = 0.f;
827 unit->m_y1a = unit->m_y1b = ZIN0(0);
828 Lag2UD_next(unit, 1);
831 //////////////////////////////////////////////////////////////////////////////////////////////////
833 void Lag3_next(Lag3 *unit, int inNumSamples)
835 float *out = ZOUT(0);
836 float *in = ZIN(0);
837 float lag = ZIN0(1);
839 float y1a = unit->m_y1a;
840 float y1b = unit->m_y1b;
841 float y1c = unit->m_y1c;
842 float b1 = unit->m_b1;
844 if (lag == unit->m_lag) {
845 LOOP1(inNumSamples,
846 float y0a = ZXP(in);
847 y1a = y0a + b1 * (y1a - y0a);
848 y1b = y1a + b1 * (y1b - y1a);
849 y1c = y1b + b1 * (y1c - y1b);
850 ZXP(out) = y1c;
852 } else {
853 unit->m_b1 = lag == 0.f ? 0.f : exp(log001 / (lag * unit->mRate->mSampleRate));
854 float b1_slope = CALCSLOPE(unit->m_b1, b1);
855 unit->m_lag = lag;
856 LOOP1(inNumSamples,
857 b1 += b1_slope;
858 float y0a = ZXP(in);
859 y1a = y0a + b1 * (y1a - y0a);
860 y1b = y1a + b1 * (y1b - y1a);
861 y1c = y1b + b1 * (y1c - y1b);
862 ZXP(out) = y1c;
865 unit->m_y1a = zapgremlins(y1a);
866 unit->m_y1b = zapgremlins(y1b);
867 unit->m_y1c = zapgremlins(y1c);
870 void Lag3_Ctor(Lag3* unit)
872 SETCALC(Lag3_next);
874 unit->m_lag = 0.f;
875 unit->m_b1 = 0.f;
876 unit->m_y1a = unit->m_y1b = unit->m_y1c = ZIN0(0);
877 Lag3_next(unit, 1);
880 //////////////////////////////////////////////////////////////////////////////////////////////////
882 void Lag3UD_next(Lag3UD *unit, int inNumSamples)
884 float *out = ZOUT(0);
885 float *in = ZIN(0);
886 float lagu = ZIN0(1);
887 float lagd = ZIN0(2);
889 float y1a = unit->m_y1a;
890 float y1b = unit->m_y1b;
891 float y1c = unit->m_y1c;
892 float b1u = unit->m_b1u;
893 float b1d = unit->m_b1d;
895 if ( (lagu == unit->m_lagu) && (lagd == unit->m_lagd) ) {
896 LOOP1(inNumSamples,
897 float y0a = ZXP(in);
898 if ( y0a > y1a ) {
899 y1a = y0a + b1u * (y1a - y0a);
900 } else {
901 y1a = y0a + b1d * (y1a - y0a);
903 if ( y1a > y1b ) {
904 y1b = y1a + b1u * (y1b - y1a);
905 } else {
906 y1b = y1a + b1d * (y1b - y1a);
908 if ( y1a > y1b ) {
909 y1c = y1b + b1u * (y1c - y1b);
910 } else {
911 y1c = y1b + b1d * (y1c - y1b);
913 ZXP(out) = y1c;
915 } else {
916 unit->m_b1u = lagu == 0.f ? 0.f : exp(log001 / (lagu * unit->mRate->mSampleRate));
917 float b1u_slope = CALCSLOPE(unit->m_b1u, b1u);
918 unit->m_lagu = lagu;
919 unit->m_b1d = lagd == 0.f ? 0.f : exp(log001 / (lagd * unit->mRate->mSampleRate));
920 float b1d_slope = CALCSLOPE(unit->m_b1d, b1d);
921 unit->m_lagd = lagd;
922 LOOP1(inNumSamples,
923 b1u += b1u_slope;
924 b1d += b1d_slope;
925 float y0a = ZXP(in);
926 if ( y0a > y1a ) {
927 y1a = y0a + b1u * (y1a - y0a);
928 } else {
929 y1a = y0a + b1d * (y1a - y0a);
931 if ( y1a > y1b ) {
932 y1b = y1a + b1u * (y1b - y1a);
933 } else {
934 y1b = y1a + b1d * (y1b - y1a);
936 if ( y1a > y1b ) {
937 y1c = y1b + b1u * (y1c - y1b);
938 } else {
939 y1c = y1b + b1d * (y1c - y1b);
941 ZXP(out) = y1c;
944 unit->m_y1a = zapgremlins(y1a);
945 unit->m_y1b = zapgremlins(y1b);
946 unit->m_y1c = zapgremlins(y1c);
949 void Lag3UD_Ctor(Lag3UD* unit)
951 SETCALC(Lag3UD_next);
953 unit->m_lagu = 0.f;
954 unit->m_lagd = 0.f;
955 unit->m_b1u = 0.f;
956 unit->m_b1d = 0.f;
958 unit->m_y1a = unit->m_y1b = unit->m_y1c = ZIN0(0);
959 Lag3UD_next(unit, 1);
962 //////////////////////////////////////////////////////////////////////////////////////////////////
964 void VarLag_next(VarLag *unit, int inNumSamples)
966 float *out = ZOUT(0);
967 float *in = IN(0);
968 float lagTime = ZIN0(1);
969 double slope = unit->m_slope;
970 double level = unit->m_level;
971 int counter = unit->m_counter;
972 int remain = inNumSamples;
974 if ( *in != unit->m_in) {
975 counter = (int)(lagTime * SAMPLERATE);
976 counter = unit->m_counter = sc_max(1, counter);
977 slope = unit->m_slope = ( *in - unit->m_level) / counter;
978 unit->m_in = *in;
979 unit->m_lagTime = lagTime;
980 } else {
981 if (lagTime != unit->m_lagTime) {
982 float scaleFactor = lagTime/unit->m_lagTime;
983 counter = (int) (unit->m_counter * scaleFactor);
984 counter = unit->m_counter = sc_max(1, counter);
985 slope = unit->m_slope / scaleFactor;
986 unit->m_lagTime = lagTime;
989 if(counter >0) {
990 LOOP(remain,
991 ZXP(out) = level;
992 if( counter > 0) {
993 level += slope; --counter;
994 } else {
995 level = unit->m_in;
998 } else {
999 LOOP(remain, ZXP(out) = level );
1002 unit->m_level = level;
1003 unit->m_slope = slope;
1004 unit->m_counter = counter;
1008 void VarLag_next_1(VarLag *unit, int inNumSamples)
1010 float *out = OUT(0);
1011 float in = *IN(0);
1012 float lagTime = ZIN0(1);
1013 int counter = unit->m_counter;
1014 if ( in != unit->m_in) {
1015 counter = (int)(lagTime * SAMPLERATE);
1016 unit->m_counter = counter = sc_max(1, counter);
1017 unit->m_slope = ( in - unit->m_level) / counter;
1018 unit->m_in = in;
1019 unit->m_lagTime = lagTime;
1021 if (lagTime != unit->m_lagTime) {
1022 if (counter != 0) {
1023 double scaleFactor = lagTime/unit->m_lagTime;
1024 counter = (int) (unit->m_counter * scaleFactor);
1025 unit->m_counter = counter = sc_max(1, counter);
1026 unit->m_slope = unit->m_slope / scaleFactor; }
1027 unit->m_lagTime = lagTime; }
1029 *out = unit->m_level;
1031 if (unit->m_counter > 0) {
1032 unit->m_level += unit->m_slope;
1033 --unit->m_counter;
1034 } else {
1035 unit->m_level = unit->m_in;
1040 void VarLag_Ctor(VarLag* unit)
1042 if (BUFLENGTH == 1) {
1043 SETCALC(VarLag_next_1);
1044 } else {
1045 SETCALC(VarLag_next);
1047 float in = *IN(0);
1048 float lagTime = ZIN0(1);
1049 unit->m_level = ZIN0(2);
1050 int counter = (int)(lagTime * SAMPLERATE);
1051 unit->m_counter = counter = sc_max(1, counter);
1052 unit->m_slope = ( in - unit->m_level) / counter;
1053 unit->m_in = in;
1054 unit->m_lagTime = lagTime;
1055 ZOUT0(0) = unit->m_level;
1059 //////////////////////////////////////////////////////////////////////////////////////////////////
1061 void OnePole_next_a(OnePole *unit, int inNumSamples)
1063 //printf("OnePole_next_a\n");
1065 float *out = ZOUT(0);
1066 float *in = ZIN(0);
1067 float *b1p = ZIN(1);
1069 float y1 = unit->m_y1;
1071 LOOP1(inNumSamples,
1072 float y0 = ZXP(in);
1073 float b1 = ZXP(b1p);
1074 ZXP(out) = y1 = y0 + b1 * (y1 - y0);
1076 unit->m_y1 = zapgremlins(y1);
1079 void OnePole_next_k(OnePole *unit, int inNumSamples)
1081 //printf("OnePole_next_a\n");
1083 float *out = ZOUT(0);
1084 float *in = ZIN(0);
1085 float b1 = unit->m_b1;
1086 unit->m_b1 = ZIN0(1);
1088 float y1 = unit->m_y1;
1090 if (b1 == unit->m_b1) {
1091 if (b1 >= 0.f) {
1092 LOOP1(inNumSamples,
1093 float y0 = ZXP(in);
1094 ZXP(out) = y1 = y0 + b1 * (y1 - y0);
1096 } else {
1097 LOOP1(inNumSamples,
1098 float y0 = ZXP(in);
1099 ZXP(out) = y1 = y0 + b1 * (y1 + y0);
1102 } else {
1103 float b1_slope = CALCSLOPE(unit->m_b1, b1);
1104 if (b1 >= 0.f && unit->m_b1 >= 0) {
1105 LOOP1(inNumSamples,
1106 float y0 = ZXP(in);
1107 ZXP(out) = y1 = y0 + b1 * (y1 - y0);
1108 b1 += b1_slope;
1110 } else if (b1 <= 0.f && unit->m_b1 <= 0) {
1111 LOOP1(inNumSamples,
1112 float y0 = ZXP(in);
1113 ZXP(out) = y1 = y0 + b1 * (y1 + y0);
1114 b1 += b1_slope;
1116 } else {
1117 LOOP1(inNumSamples,
1118 float y0 = ZXP(in);
1119 ZXP(out) = y1 = (1.f - std::abs(b1)) * y0 + b1 * y1;
1120 b1 += b1_slope;
1124 unit->m_y1 = zapgremlins(y1);
1127 void OnePole_Ctor(OnePole* unit)
1129 if (INRATE(1) == calc_FullRate) {
1130 SETCALC(OnePole_next_a);
1131 } else {
1132 SETCALC(OnePole_next_k);
1134 unit->m_b1 = 0.f;
1135 unit->m_y1 = 0.f;
1136 OnePole_next_a(unit, 1);
1139 //////////////////////////////////////////////////////////////////////////////////////////////////
1141 void OneZero_Ctor(OneZero* unit)
1143 SETCALC(OneZero_next);
1144 unit->m_b1 = 0.f;
1145 unit->m_x1 = ZIN0(0);
1146 OneZero_next(unit, 1);
1150 void OneZero_next(OneZero* unit, int inNumSamples)
1152 //printf("OneZero::next\n");
1154 float *out = ZOUT(0);
1155 float *in = ZIN(0);
1156 float b1 = unit->m_b1;
1157 unit->m_b1 = ZIN0(1);
1159 float x1 = unit->m_x1;
1160 if (b1 == unit->m_b1) {
1161 if (b1 >= 0.f) {
1162 LOOP1(inNumSamples,
1163 float x0 = ZXP(in);
1164 ZXP(out) = x0 + b1 * (x1 - x0);
1165 x1 = x0;
1167 } else {
1168 LOOP1(inNumSamples,
1169 float x0 = ZXP(in);
1170 ZXP(out) = x0 + b1 * (x1 + x0);
1171 x1 = x0;
1174 } else {
1175 float b1_slope = CALCSLOPE(unit->m_b1, b1);
1176 if (b1 >= 0.f && unit->m_b1 >= 0) {
1177 LOOP1(inNumSamples,
1178 float x0 = ZXP(in);
1179 ZXP(out) = x0 + b1 * (x1 - x0);
1180 x1 = x0;
1181 b1 += b1_slope;
1183 } else if (b1 <= 0.f && unit->m_b1 <= 0) {
1184 LOOP1(inNumSamples,
1185 float x0 = ZXP(in);
1186 ZXP(out) = x0 + b1 * (x1 + x0);
1187 x1 = x0;
1188 b1 += b1_slope;
1190 } else {
1191 LOOP1(inNumSamples,
1192 float x0 = ZXP(in);
1193 ZXP(out) = (1.f - std::abs(b1)) * x0 + b1 * x1;
1194 x1 = x0;
1195 b1 += b1_slope;
1199 unit->m_x1 = x1;
1202 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1204 void Integrator_Ctor(Integrator* unit)
1206 //printf("Integrator_Reset\n");
1207 SETCALC(Integrator_next);
1208 unit->m_b1 = 0.f;
1209 unit->m_y1 = 0.f;
1210 Integrator_next(unit, 1);
1213 void Integrator_next(Integrator* unit, int inNumSamples)
1215 //printf("Integrator_next_a\n");
1217 float *out = ZOUT(0);
1218 float *in = ZIN(0);
1219 float b1 = unit->m_b1;
1220 unit->m_b1 = ZIN0(1);
1222 float y1 = unit->m_y1;
1224 if (b1 == unit->m_b1) {
1225 if (b1 == 1.f) {
1226 LOOP1(inNumSamples,
1227 float y0 = ZXP(in);
1228 ZXP(out) = y1 = y0 + y1;
1230 } else if (b1 == 0.f) {
1231 LOOP1(inNumSamples,
1232 float y0 = ZXP(in);
1233 ZXP(out) = y1 = y0;
1235 } else {
1236 LOOP1(inNumSamples,
1237 float y0 = ZXP(in);
1238 ZXP(out) = y1 = y0 + b1 * y1;
1241 } else {
1242 float b1_slope = CALCSLOPE(unit->m_b1, b1);
1243 LOOP1(inNumSamples,
1244 float y0 = ZXP(in);
1245 ZXP(out) = y1 = y0 + b1 * y1;
1246 b1 += b1_slope;
1249 unit->m_y1 = zapgremlins(y1);
1252 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1254 void Decay_Ctor(Decay* unit)
1256 SETCALC(Decay_next);
1257 unit->m_decayTime = 0.f;
1258 unit->m_b1 = 0.f;
1259 unit->m_y1 = 0.f;
1260 Decay_next(unit, 1);
1263 void Decay_next(Decay* unit, int inNumSamples)
1265 //printf("Decay_next_a\n");
1267 float *out = ZOUT(0);
1268 float *in = ZIN(0);
1269 float decayTime = ZIN0(1);
1271 float y1 = unit->m_y1;
1272 float b1 = unit->m_b1;
1273 if (decayTime == unit->m_decayTime) {
1274 if (b1 == 0.f) {
1275 LOOP1(inNumSamples,
1276 float y0 = ZXP(in);
1277 ZXP(out) = y1 = y0;
1279 } else {
1280 LOOP1(inNumSamples,
1281 float y0 = ZXP(in);
1282 ZXP(out) = y1 = y0 + b1 * y1;
1285 } else {
1286 unit->m_b1 = decayTime == 0.f ? 0.f : exp(log001 / (decayTime * SAMPLERATE));
1287 unit->m_decayTime = decayTime;
1288 float b1_slope = CALCSLOPE(unit->m_b1, b1);
1289 //printf("decayTime %g %g %g\n", unit->m_decayTime, next_b1, b1);
1290 LOOP1(inNumSamples,
1291 float y0 = ZXP(in);
1292 ZXP(out) = y1 = y0 + b1 * y1;
1293 b1 += b1_slope;
1296 unit->m_y1 = zapgremlins(y1);
1299 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1302 void Decay2_Ctor(Decay2 *unit)
1304 SETCALC(Decay2_next);
1306 float attackTime = ZIN0(1);
1307 float decayTime = ZIN0(2);
1308 unit->m_b1a = decayTime == 0.f ? 0.f : exp(log001 / (decayTime * SAMPLERATE));
1309 unit->m_b1b = attackTime == 0.f ? 0.f : exp(log001 / (attackTime * SAMPLERATE));
1310 unit->m_decayTime = decayTime;
1311 unit->m_attackTime = attackTime;
1313 float y0 = ZIN0(0);
1314 unit->m_y1a = y0;
1315 unit->m_y1b = y0;
1316 ZOUT0(0) = 0.f;
1319 void Decay2_next(Decay2* unit, int inNumSamples)
1321 //printf("Decay2_next_a\n");
1323 float *out = ZOUT(0);
1324 float *in = ZIN(0);
1325 float attackTime = ZIN0(1);
1326 float decayTime = ZIN0(2);
1328 float y1a = unit->m_y1a;
1329 float y1b = unit->m_y1b;
1330 float b1a = unit->m_b1a;
1331 float b1b = unit->m_b1b;
1332 if (decayTime == unit->m_decayTime && attackTime == unit->m_attackTime) {
1333 LOOP1(inNumSamples,
1334 float y0 = ZXP(in);
1335 y1a = y0 + b1a * y1a;
1336 y1b = y0 + b1b * y1b;
1337 ZXP(out) = y1a - y1b;
1339 } else {
1340 unit->m_decayTime = decayTime;
1341 unit->m_attackTime = attackTime;
1342 float next_b1a = decayTime == 0.f ? 0.f : exp(log001 / (decayTime * SAMPLERATE));
1343 float next_b1b = attackTime == 0.f ? 0.f : exp(log001 / (attackTime * SAMPLERATE));
1344 unit->m_decayTime = decayTime;
1345 float b1a_slope = CALCSLOPE(next_b1a, b1a);
1346 float b1b_slope = CALCSLOPE(next_b1b, b1b);
1347 unit->m_b1a = next_b1a;
1348 unit->m_b1b = next_b1b;
1349 LOOP1(inNumSamples,
1350 float y0 = ZXP(in);
1351 y1a = y0 + b1a * y1a;
1352 y1b = y0 + b1b * y1b;
1353 ZXP(out) = y1a - y1b;
1354 b1a += b1a_slope;
1355 b1b += b1b_slope;
1358 unit->m_y1a = y1a;
1359 unit->m_y1b = y1b;
1360 unit->m_b1a = b1a;
1361 unit->m_b1b = b1b;
1364 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1366 void LeakDC_next_i_4(LeakDC* unit, int inNumSamples)
1368 float *out = ZOUT(0);
1369 float *in = ZIN(0);
1370 double b1 = unit->m_b1;
1371 double y1 = unit->m_y1;
1372 double x1 = unit->m_x1;
1374 LOOP1(inNumSamples/4,
1375 double x00 = ZXP(in);
1376 double x01 = ZXP(in);
1377 double x02 = ZXP(in);
1378 double x03 = ZXP(in);
1379 ZXP(out) = y1 = x00 - x1 + b1 * y1;
1380 ZXP(out) = y1 = x01 - x00 + b1 * y1;
1381 ZXP(out) = y1 = x02 - x01 + b1 * y1;
1382 ZXP(out) = y1 = x03 - x02 + b1 * y1;
1384 x1 = x03;
1386 unit->m_x1 = x1;
1387 unit->m_y1 = zapgremlins(y1);
1390 void LeakDC_next_i(LeakDC* unit, int inNumSamples)
1392 float *out = ZOUT(0);
1393 float *in = ZIN(0);
1394 double b1 = unit->m_b1;
1395 double y1 = unit->m_y1;
1396 double x1 = unit->m_x1;
1398 LOOP1(inNumSamples,
1399 double x0 = ZXP(in);
1400 ZXP(out) = y1 = x0 - x1 + b1 * y1;
1401 x1 = x0;
1403 unit->m_x1 = x1;
1404 unit->m_y1 = zapgremlins(y1);
1407 void LeakDC_next(LeakDC* unit, int inNumSamples)
1409 if (ZIN0(1) == unit->m_b1) {
1410 if ((inNumSamples & 3) == 0)
1411 LeakDC_next_i_4(unit, inNumSamples);
1412 else
1413 LeakDC_next_i(unit, inNumSamples);
1414 } else {
1415 float *out = ZOUT(0);
1416 float *in = ZIN(0);
1417 double b1 = unit->m_b1;
1418 unit->m_b1 = ZIN0(1);
1420 double y1 = unit->m_y1;
1421 double x1 = unit->m_x1;
1423 double b1_slope = CALCSLOPE(unit->m_b1, b1);
1424 LOOP1(inNumSamples,
1425 double x0 = ZXP(in);
1426 ZXP(out) = y1 = x0 - x1 + b1 * y1;
1427 x1 = x0;
1428 b1 += b1_slope;
1430 unit->m_x1 = x1;
1431 unit->m_y1 = zapgremlins(y1);
1436 void LeakDC_next_1(LeakDC* unit, int inNumSamples)
1438 double b1 = unit->m_b1 = ZIN0(1);
1440 double y1 = unit->m_y1;
1441 double x1 = unit->m_x1;
1443 double x0 = ZIN0(0);
1444 ZOUT0(0) = y1 = x0 - x1 + b1 * y1;
1445 x1 = x0;
1447 unit->m_x1 = x1;
1448 unit->m_y1 = zapgremlins(y1);
1451 void LeakDC_Ctor(LeakDC *unit)
1453 //printf("LeakDC_Ctor\n");
1454 if (BUFLENGTH == 1)
1455 SETCALC(LeakDC_next_1);
1456 else {
1457 if (INRATE(1) == calc_ScalarRate) {
1458 if ((BUFLENGTH & 3) == 0)
1459 SETCALC(LeakDC_next_i_4);
1460 else
1461 SETCALC(LeakDC_next_i);
1462 } else
1463 SETCALC(LeakDC_next);
1465 unit->m_b1 = 0.0;
1466 unit->m_x1 = ZIN0(0);
1467 unit->m_y1 = 0.0;
1468 LeakDC_next_1(unit, 1);
1472 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1474 void TwoPole_Ctor(TwoPole *unit)
1476 //printf("TwoPole_Reset\n");
1477 SETCALC(TwoPole_next);
1478 unit->m_b1 = 0.f;
1479 unit->m_b2 = 0.f;
1480 unit->m_y1 = 0.f;
1481 unit->m_y2 = 0.f;
1482 unit->m_freq = 0.f;
1483 unit->m_reson = 0.f;
1484 PUSH_LOOPVALS
1485 TwoPole_next(unit, 1);
1486 POP_LOOPVALS
1490 void TwoPole_next(TwoPole* unit, int inNumSamples)
1492 //printf("TwoPole_next_a\n");
1494 float *out = ZOUT(0);
1495 float *in = ZIN(0);
1496 float freq = ZIN0(1);
1497 float reson = ZIN0(2);
1499 float y0;
1500 float y1 = unit->m_y1;
1501 float y2 = unit->m_y2;
1503 if (freq != unit->m_freq || reson != unit->m_reson) {
1504 float b1 = unit->m_b1;
1505 float b2 = unit->m_b2;
1506 float b1_next = 2.f * reson * cos(freq * unit->mRate->mRadiansPerSample);
1507 float b2_next = -(reson * reson);
1508 float b1_slope = (b1_next - b1) * unit->mRate->mFilterSlope;
1509 float b2_slope = (b2_next - b2) * unit->mRate->mFilterSlope;
1510 LOOP(unit->mRate->mFilterLoops,
1511 ZXP(out) = y0 = ZXP(in) + b1 * y1 + b2 * y2;
1512 ZXP(out) = y2 = ZXP(in) + b1 * y0 + b2 * y1;
1513 ZXP(out) = y1 = ZXP(in) + b1 * y2 + b2 * y0;
1515 b1 += b1_slope;
1516 b2 += b2_slope;
1518 LOOP(unit->mRate->mFilterRemain,
1519 ZXP(out) = y0 = ZXP(in) + b1 * y1 + b2 * y2;
1520 y2 = y1;
1521 y1 = y0;
1524 unit->m_freq = freq;
1525 unit->m_reson = reson;
1526 unit->m_b1 = b1;
1527 unit->m_b2 = b2;
1528 } else {
1529 float b1 = unit->m_b1;
1530 float b2 = unit->m_b2;
1531 LOOP(unit->mRate->mFilterLoops,
1532 ZXP(out) = y0 = ZXP(in) + b1 * y1 + b2 * y2;
1533 ZXP(out) = y2 = ZXP(in) + b1 * y0 + b2 * y1;
1534 ZXP(out) = y1 = ZXP(in) + b1 * y2 + b2 * y0;
1536 LOOP(unit->mRate->mFilterRemain,
1537 ZXP(out) = y0 = ZXP(in) + b1 * y1 + b2 * y2;
1538 y2 = y1;
1539 y1 = y0;
1542 unit->m_y1 = zapgremlins(y1);
1543 unit->m_y2 = zapgremlins(y2);
1547 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1550 void TwoZero_Ctor(TwoZero* unit)
1552 //printf("TwoZero_Reset\n");
1553 SETCALC(TwoZero_next);
1554 unit->m_b1 = 0.f;
1555 unit->m_b2 = 0.f;
1556 unit->m_x1 = 0.f;
1557 unit->m_x2 = 0.f;
1558 unit->m_freq = 0.f;
1559 unit->m_reson = 0.f;
1560 PUSH_LOOPVALS
1561 TwoZero_next(unit, 1);
1562 POP_LOOPVALS
1565 void TwoZero_next(TwoZero* unit, int inNumSamples)
1567 //printf("TwoZero_next\n");
1569 float *out = ZOUT(0);
1570 float *in = ZIN(0);
1571 float freq = ZIN0(1);
1572 float reson = ZIN0(2);
1574 float x0;
1575 float x1 = unit->m_x1;
1576 float x2 = unit->m_x2;
1578 if (freq != unit->m_freq || reson != unit->m_reson) {
1579 float b1 = unit->m_b1;
1580 float b2 = unit->m_b2;
1581 float b1_next = -2.f * reson * cos(freq * unit->mRate->mRadiansPerSample);
1582 float b2_next = (reson * reson);
1583 float b1_slope = (b1_next - b1) * unit->mRate->mFilterSlope;
1584 float b2_slope = (b2_next - b2) * unit->mRate->mFilterSlope;
1585 LOOP(unit->mRate->mFilterLoops,
1586 x0 = ZXP(in);
1587 ZXP(out) = x0 + b1 * x1 + b2 * x2;
1588 x2 = ZXP(in);
1589 ZXP(out) = x2 + b1 * x0 + b2 * x1;
1590 x1 = ZXP(in);
1591 ZXP(out) = x1 + b1 * x2 + b2 * x0;
1593 b1 += b1_slope;
1594 b2 += b2_slope;
1596 LOOP(unit->mRate->mFilterRemain,
1597 x0 = ZXP(in);
1598 ZXP(out) = x0 + b1 * x1 + b2 * x2;
1599 x2 = x1;
1600 x1 = x0;
1603 unit->m_freq = freq;
1604 unit->m_reson = reson;
1605 unit->m_b1 = b1;
1606 unit->m_b2 = b2;
1607 } else {
1608 float b1 = unit->m_b1;
1609 float b2 = unit->m_b2;
1610 LOOP(unit->mRate->mFilterLoops,
1611 x0 = ZXP(in);
1612 ZXP(out) = x0 + b1 * x1 + b2 * x2;
1613 x2 = ZXP(in);
1614 ZXP(out) = x2 + b1 * x0 + b2 * x1;
1615 x1 = ZXP(in);
1616 ZXP(out) = x1 + b1 * x2 + b2 * x0;
1618 LOOP(unit->mRate->mFilterRemain,
1619 x0 = ZXP(in);
1620 ZXP(out) = x0 + b1 * x1 + b2 * x2;
1621 x2 = x1;
1622 x1 = x0;
1625 unit->m_x1 = x1;
1626 unit->m_x2 = x2;
1630 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1633 void APF_Ctor(APF* unit)
1635 //printf("APF_Reset\n");
1636 SETCALC(APF_next);
1637 unit->m_b1 = 0.f;
1638 unit->m_b2 = 0.f;
1639 unit->m_y1 = 0.f;
1640 unit->m_y2 = 0.f;
1641 unit->m_x1 = 0.f;
1642 unit->m_x2 = 0.f;
1643 unit->m_freq = 0.f;
1644 unit->m_reson = 0.f;
1645 PUSH_LOOPVALS
1646 APF_next(unit, 1);
1647 POP_LOOPVALS
1651 void APF_next(APF* unit, int inNumSamples)
1653 //printf("APF_next_a\n");
1655 float *out = ZOUT(0);
1656 float *in = ZIN(0);
1657 float freq = ZIN0(1);
1658 float reson = ZIN0(2);
1660 float x0, y0;
1661 float y1 = unit->m_y1;
1662 float y2 = unit->m_y2;
1663 float x1 = unit->m_x1;
1664 float x2 = unit->m_x2;
1666 if (freq != unit->m_freq || reson != unit->m_reson) {
1667 float b1 = unit->m_b1;
1668 float b2 = unit->m_b2;
1669 float b1_next = 2.f * reson * cos(freq * unit->mRate->mRadiansPerSample);
1670 float b2_next = -(reson * reson);
1671 float b1_slope = (b1_next - b1) * unit->mRate->mFilterSlope;
1672 float b2_slope = (b2_next - b2) * unit->mRate->mFilterSlope;
1673 LOOP(unit->mRate->mFilterLoops,
1674 x0 = ZXP(in);
1675 ZXP(out) = y0 = x0 + b1 * (y1 - x1) + b2 * (y2 - x2);
1676 x2 = ZXP(in);
1677 ZXP(out) = y2 = x2 + b1 * (y0 - x0) + b2 * (y2 - x1);
1678 x1 = ZXP(in);
1679 ZXP(out) = y1 = x1 + b1 * (y2 - x2) + b2 * (y2 - x0);
1681 b1 += b1_slope;
1682 b2 += b2_slope;
1684 LOOP(unit->mRate->mFilterRemain,
1685 x0 = ZXP(in);
1686 ZXP(out) = y0 = x0 + b1 * (y1 - x1) + b2 * (y2 - x2);
1687 y2 = y1;
1688 y1 = y0;
1689 x2 = x1;
1690 x1 = x0;
1693 unit->m_freq = freq;
1694 unit->m_reson = reson;
1695 unit->m_b1 = b1;
1696 unit->m_b2 = b2;
1697 } else {
1698 float b1 = unit->m_b1;
1699 float b2 = unit->m_b2;
1700 LOOP(unit->mRate->mFilterLoops,
1701 x0 = ZXP(in);
1702 ZXP(out) = y0 = x0 + b1 * (y1 - x1) + b2 * (y2 - x2);
1703 x2 = ZXP(in);
1704 ZXP(out) = y2 = x2 + b1 * (y0 - x0) + b2 * (y2 - x1);
1705 x1 = ZXP(in);
1706 ZXP(out) = y1 = x1 + b1 * (y2 - x2) + b2 * (y2 - x0);
1708 LOOP(unit->mRate->mFilterRemain,
1709 x0 = ZXP(in);
1710 ZXP(out) = y0 = x0 + b1 * (y1 - x1) + b2 * (y2 - x2);
1711 y2 = y1;
1712 y1 = y0;
1713 x2 = x1;
1714 x1 = x0;
1717 unit->m_y1 = zapgremlins(y1);
1718 unit->m_y2 = zapgremlins(y2);
1719 unit->m_x1 = x1;
1720 unit->m_x2 = x2;
1723 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1725 void LPZ1_Ctor(LPZ1* unit)
1727 //printf("LPZ1_Reset\n");
1728 SETCALC(LPZ1_next);
1729 unit->m_x1 = ZIN0(0);
1730 LPZ1_next(unit, 1);
1734 void LPZ1_next(LPZ1* unit, int inNumSamples)
1736 //printf("LPZ1_next_a\n");
1738 float *out = ZOUT(0);
1739 float *in = ZIN(0);
1741 float x0;
1742 float x1 = unit->m_x1;
1744 LOOP(inNumSamples >> 2,
1745 x0 = ZXP(in);
1746 ZXP(out) = 0.5f * (x0 + x1);
1747 x1 = ZXP(in);
1748 ZXP(out) = 0.5f * (x1 + x0);
1749 x0 = ZXP(in);
1750 ZXP(out) = 0.5f * (x0 + x1);
1751 x1 = ZXP(in);
1752 ZXP(out) = 0.5f * (x1 + x0);
1754 LOOP(inNumSamples & 3,
1755 x0 = ZXP(in);
1756 ZXP(out) = 0.5f * (x0 + x1);
1757 x1 = x0;
1760 unit->m_x1 = x1;
1763 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1766 void HPZ1_Ctor(HPZ1* unit)
1768 //printf("HPZ1_Reset\n");
1769 SETCALC(HPZ1_next);
1770 unit->m_x1 = ZIN0(0);
1771 HPZ1_next(unit, 1);
1775 void HPZ1_next(HPZ1* unit, int inNumSamples)
1777 //printf("HPZ1_next\n");
1779 float *out = ZOUT(0);
1780 float *in = ZIN(0);
1782 float x0;
1783 float x1 = unit->m_x1;
1785 LOOP(inNumSamples >> 2,
1786 x0 = ZXP(in);
1787 ZXP(out) = 0.5f * (x0 - x1);
1788 x1 = ZXP(in);
1789 ZXP(out) = 0.5f * (x1 - x0);
1790 x0 = ZXP(in);
1791 ZXP(out) = 0.5f * (x0 - x1);
1792 x1 = ZXP(in);
1793 ZXP(out) = 0.5f * (x1 - x0);
1795 LOOP(inNumSamples & 3,
1796 x0 = ZXP(in);
1797 //printf("%d %d %g %g\n", this, inNumSamples, x0, x1);
1798 ZXP(out) = 0.5f * (x0 - x1);
1799 x1 = x0;
1802 unit->m_x1 = x1;
1805 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1807 void Slope_Ctor(Slope* unit)
1809 //printf("Slope_Reset\n");
1810 SETCALC(Slope_next);
1811 unit->m_x1 = ZIN0(0);
1812 //printf("Slope_Reset %g\n", unit->m_x1);
1813 Slope_next(unit, 1);
1817 void Slope_next(Slope* unit, int inNumSamples)
1819 //printf("Slope_next_a %g\n", unit->m_x1);
1821 float *out = ZOUT(0);
1822 float *in = ZIN(0);
1824 float x1 = unit->m_x1;
1826 float sr = SAMPLERATE;
1827 LOOP1(inNumSamples,
1828 float x0 = ZXP(in);
1829 ZXP(out) = sr * (x0 - x1);
1830 x1 = x0;
1833 unit->m_x1 = x1;
1836 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1838 void Delay1_Ctor(Delay1* unit)
1840 //printf("Delay1_Reset\n");
1841 SETCALC(Delay1_next);
1842 unit->m_x1 = ZIN0(0);
1843 Delay1_next(unit, 1);
1847 void Delay1_next(Delay1* unit, int inNumSamples)
1849 //printf("Delay1_next_a\n");
1851 float *out = ZOUT(0);
1852 float *in = ZIN(0);
1854 float x0;
1855 float x1 = unit->m_x1;
1857 LOOP(inNumSamples >> 2,
1858 x0 = ZXP(in);
1859 ZXP(out) = x1;
1860 x1 = ZXP(in);
1861 ZXP(out) = x0;
1862 x0 = ZXP(in);
1863 ZXP(out) = x1;
1864 x1 = ZXP(in);
1865 ZXP(out) = x0;
1867 LOOP(inNumSamples & 3,
1868 x0 = ZXP(in);
1869 ZXP(out) = x1;
1870 x1 = x0;
1873 unit->m_x1 = x1;
1876 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1878 void Flip_Ctor(Flip* unit)
1880 if (unit->mBufLength & 1) {
1881 SETCALC(Flip_next_odd);
1882 Flip_next_odd(unit, 1);
1883 } else {
1884 SETCALC(Flip_next_even);
1885 ZOUT0(0) = ZIN0(0);
1890 void Flip_next_even(Flip* unit, int inNumSamples)
1892 float *out = ZOUT(0);
1893 float *in = ZIN(0);
1895 LOOP(inNumSamples >> 1,
1896 ZXP(out) = -ZXP(in);
1897 ZXP(out) = ZXP(in);
1901 void Flip_next_odd(Flip* unit, int inNumSamples)
1903 float *out = ZOUT(0);
1904 float *in = ZIN(0);
1906 if (unit->mWorld->mBufCounter & 1) {
1907 ZXP(out) = ZXP(in);
1908 LOOP(inNumSamples >> 1,
1909 ZXP(out) = -ZXP(in);
1910 ZXP(out) = ZXP(in);
1912 } else {
1913 LOOP(inNumSamples >> 1,
1914 ZXP(out) = -ZXP(in);
1915 ZXP(out) = ZXP(in);
1917 ZXP(out) = -ZXP(in);
1921 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1923 void Delay2_Ctor(Delay2* unit)
1925 SETCALC(Delay2_next);
1926 unit->m_x1 = ZIN0(0);
1927 ZOUT0(0) = 0.f;
1931 void Delay2_next(Delay2* unit, int inNumSamples)
1933 float *out = ZOUT(0);
1934 float *in = ZIN(0);
1936 float x0;
1937 float x1 = unit->m_x1;
1938 float x2 = unit->m_x2;
1940 LOOP(unit->mRate->mFilterLoops,
1941 x0 = ZXP(in);
1942 ZXP(out) = x2;
1943 x2 = ZXP(in);
1944 ZXP(out) = x1;
1945 x1 = ZXP(in);
1946 ZXP(out) = x0;
1948 LOOP(unit->mRate->mFilterRemain,
1949 x0 = ZXP(in);
1950 ZXP(out) = x2;
1951 x2 = x1;
1952 x1 = x0;
1955 unit->m_x1 = x1;
1956 unit->m_x2 = x2;
1959 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1962 void LPZ2_Ctor(LPZ2* unit)
1964 //printf("LPZ2_Reset\n");
1965 SETCALC(LPZ2_next);
1966 unit->m_x1 = unit->m_x2 = ZIN0(0);
1967 PUSH_LOOPVALS
1968 LPZ2_next(unit, 1);
1969 POP_LOOPVALS
1973 void LPZ2_next(LPZ2* unit, int inNumSamples)
1975 //printf("LPZ2_next_a\n");
1977 float *out = ZOUT(0);
1978 float *in = ZIN(0);
1980 float x0;
1981 float x1 = unit->m_x1;
1982 float x2 = unit->m_x2;
1984 LOOP(unit->mRate->mFilterLoops,
1985 x0 = ZXP(in);
1986 ZXP(out) = (x0 + 2.f * x1 + x2) * 0.25f;
1987 x2 = ZXP(in);
1988 ZXP(out) = (x2 + 2.f * x0 + x1) * 0.25f;
1989 x1 = ZXP(in);
1990 ZXP(out) = (x1 + 2.f * x2 + x0) * 0.25f;
1992 LOOP(unit->mRate->mFilterRemain,
1993 x0 = ZXP(in);
1994 ZXP(out) = (x0 + 2.f * x1 + x2) * 0.25f;
1995 x2 = x1;
1996 x1 = x0;
1999 unit->m_x1 = x1;
2000 unit->m_x2 = x2;
2003 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2005 void HPZ2_Ctor(HPZ2* unit)
2007 //printf("HPZ2_Reset\n");
2008 SETCALC(HPZ2_next);
2009 unit->m_x1 = unit->m_x2 = ZIN0(0);
2010 PUSH_LOOPVALS
2011 HPZ2_next(unit, 1);
2012 POP_LOOPVALS
2016 void HPZ2_next(HPZ2* unit, int inNumSamples)
2018 //printf("HPZ2_next_a\n");
2020 float *out = ZOUT(0);
2021 float *in = ZIN(0);
2023 float x0;
2024 float x1 = unit->m_x1;
2025 float x2 = unit->m_x2;
2027 LOOP(unit->mRate->mFilterLoops,
2028 x0 = ZXP(in);
2029 ZXP(out) = (x0 - 2.f * x1 + x2) * 0.25f;
2030 x2 = ZXP(in);
2031 ZXP(out) = (x2 - 2.f * x0 + x1) * 0.25f;
2032 x1 = ZXP(in);
2033 ZXP(out) = (x1 - 2.f * x2 + x0) * 0.25f;
2035 LOOP(unit->mRate->mFilterRemain,
2036 x0 = ZXP(in);
2037 ZXP(out) = (x0 - 2.f * x1 + x2) * 0.25f;
2038 x2 = x1;
2039 x1 = x0;
2042 unit->m_x1 = x1;
2043 unit->m_x2 = x2;
2046 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2048 void BPZ2_Ctor(BPZ2* unit)
2050 //printf("BPZ2_Reset\n");
2051 SETCALC(BPZ2_next);
2052 unit->m_x1 = unit->m_x2 = ZIN0(0);
2053 PUSH_LOOPVALS
2054 BPZ2_next(unit, 1);
2055 POP_LOOPVALS
2059 void BPZ2_next(BPZ2* unit, int inNumSamples)
2061 //printf("BPZ2_next_a\n");
2063 float *out = ZOUT(0);
2064 float *in = ZIN(0);
2066 float x0;
2067 float x1 = unit->m_x1;
2068 float x2 = unit->m_x2;
2070 LOOP(unit->mRate->mFilterLoops,
2071 x0 = ZXP(in);
2072 ZXP(out) = (x0 - x2) * 0.5f;
2073 x2 = ZXP(in);
2074 ZXP(out) = (x2 - x1) * 0.5f;
2075 x1 = ZXP(in);
2076 ZXP(out) = (x1 - x0) * 0.5f;
2078 LOOP(unit->mRate->mFilterRemain,
2079 x0 = ZXP(in);
2080 ZXP(out) = (x0 - x2) * 0.5f;
2081 x2 = x1;
2082 x1 = x0;
2085 unit->m_x1 = x1;
2086 unit->m_x2 = x2;
2089 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2091 void BRZ2_Ctor(BRZ2* unit)
2093 //printf("BRZ2_Reset\n");
2094 SETCALC(BRZ2_next);
2095 unit->m_x1 = unit->m_x2 = ZIN0(0);
2096 PUSH_LOOPVALS
2097 BRZ2_next(unit, 1);
2098 POP_LOOPVALS
2102 void BRZ2_next(BRZ2* unit, int inNumSamples)
2104 //printf("BRZ2_next_a\n");
2106 float *out = ZOUT(0);
2107 float *in = ZIN(0);
2109 float x0;
2110 float x1 = unit->m_x1;
2111 float x2 = unit->m_x2;
2113 LOOP(unit->mRate->mFilterLoops,
2114 x0 = ZXP(in);
2115 ZXP(out) = (x0 + x2) * 0.5f;
2116 x2 = ZXP(in);
2117 ZXP(out) = (x2 + x1) * 0.5f;
2118 x1 = ZXP(in);
2119 ZXP(out) = (x1 + x0) * 0.5f;
2121 LOOP(unit->mRate->mFilterRemain,
2122 x0 = ZXP(in);
2123 ZXP(out) = (x0 + x2) * 0.5f;
2124 x2 = x1;
2125 x1 = x0;
2128 unit->m_x1 = x1;
2129 unit->m_x2 = x2;
2132 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2134 void Slew_Ctor(Slew* unit)
2136 //printf("Slew_Reset\n");
2137 SETCALC(Slew_next);
2138 unit->mLevel = ZIN0(0);
2139 Slew_next(unit, 1);
2143 void Slew_next(Slew* unit, int inNumSamples)
2145 //printf("Slew_next_a\n");
2147 float sampleDur = unit->mRate->mSampleDur;
2148 float *out = ZOUT(0);
2149 float *in = ZIN(0);
2150 float upf = ZIN0(1) * sampleDur;
2151 float dnf = 0.f - ZIN0(2) * sampleDur;
2152 float level = unit->mLevel;
2153 LOOP1(inNumSamples,
2154 float slope = ZXP(in) - level;
2155 level += sc_clip(slope, dnf, upf);
2156 ZXP(out) = level;
2158 unit->mLevel = level;
2161 /*void Slew_next_1(Slew* unit, int inNumSamples)
2163 //printf("Slew_next_a\n");
2165 float *out = ZOUT(0);
2166 float in = ZIN0(0);
2167 float upf = ZIN0(1);
2168 float dnf = ZIN0(2);
2169 float level = unit->mLevel;
2170 float slope = ZXP(in) - level;
2171 if (slope > upf) slope = upf;
2172 else if (slope < dnf) slope = dnf;
2173 level += slope;
2174 ZXP(out) = level;
2175 unit->mLevel = level;
2179 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2181 void RLPF_Ctor(RLPF* unit)
2183 //printf("RLPF_Reset\n");
2184 if (unit->mBufLength == 1) {
2185 SETCALC(RLPF_next_1);
2186 } else {
2187 SETCALC(RLPF_next);
2190 unit->m_a0 = 0.f;
2191 unit->m_b1 = 0.f;
2192 unit->m_b2 = 0.f;
2193 unit->m_y1 = 0.f;
2194 unit->m_y2 = 0.f;
2195 unit->m_freq = 0.f;
2196 unit->m_reson = 0.f;
2197 RLPF_next_1(unit, 1);
2201 void RLPF_next(RLPF* unit, int inNumSamples)
2203 //printf("RLPF_next\n");
2205 float *out = ZOUT(0);
2206 float *in = ZIN(0);
2207 float freq = ZIN0(1);
2208 float reson = ZIN0(2);
2210 float y0;
2211 float y1 = unit->m_y1;
2212 float y2 = unit->m_y2;
2213 float a0 = unit->m_a0;
2214 float b1 = unit->m_b1;
2215 float b2 = unit->m_b2;
2217 if (freq != unit->m_freq || reson != unit->m_reson) {
2219 float qres = sc_max(0.001, reson);
2220 float pfreq = freq * unit->mRate->mRadiansPerSample;
2222 float D = tan(pfreq * qres * 0.5);
2223 float C = ((1.f-D)/(1.f+D));
2224 float cosf = cos(pfreq);
2226 float next_b1 = (1.f + C) * cosf;
2227 float next_b2 = -C;
2228 float next_a0 = (1.f + C - next_b1) * .25;
2229 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2231 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2232 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2233 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2234 LOOP(unit->mRate->mFilterLoops,
2235 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2236 ZXP(out) = y0 + 2.f * y1 + y2;
2238 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
2239 ZXP(out) = y2 + 2.f * y0 + y1;
2241 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
2242 ZXP(out) = y1 + 2.f * y2 + y0;
2244 a0 += a0_slope;
2245 b1 += b1_slope;
2246 b2 += b2_slope;
2248 LOOP(unit->mRate->mFilterRemain,
2249 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2250 ZXP(out) = y0 + 2.f * y1 + y2;
2251 y2 = y1;
2252 y1 = y0;
2255 unit->m_freq = freq;
2256 unit->m_reson = reson;
2257 unit->m_a0 = a0;
2258 unit->m_b1 = b1;
2259 unit->m_b2 = b2;
2260 } else {
2261 LOOP(unit->mRate->mFilterLoops,
2262 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2263 ZXP(out) = y0 + 2.f * y1 + y2;
2265 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
2266 ZXP(out) = y2 + 2.f * y0 + y1;
2268 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
2269 ZXP(out) = y1 + 2.f * y2 + y0;
2271 LOOP(unit->mRate->mFilterRemain,
2272 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2273 ZXP(out) = y0 + 2.f * y1 + y2;
2274 y2 = y1;
2275 y1 = y0;
2278 unit->m_y1 = zapgremlins(y1);
2279 unit->m_y2 = zapgremlins(y2);
2283 void RLPF_next_1(RLPF* unit, int inNumSamples)
2285 //printf("RLPF_next_1\n");
2287 float in = ZIN0(0);
2288 float freq = ZIN0(1);
2289 float reson = ZIN0(2);
2291 float y0;
2292 float y1 = unit->m_y1;
2293 float y2 = unit->m_y2;
2294 float a0 = unit->m_a0;
2295 float b1 = unit->m_b1;
2296 float b2 = unit->m_b2;
2298 if (freq != unit->m_freq || reson != unit->m_reson) {
2299 float qres = sc_max(0.001f, reson);
2300 float pfreq = freq * unit->mRate->mRadiansPerSample;
2302 float D = tan(pfreq * qres * 0.5f);
2303 float C = ((1.f-D)/(1.f+D));
2304 float cosf = cos(pfreq);
2306 b1 = (1.f + C) * cosf;
2307 b2 = -C;
2308 a0 = (1.f + C - b1) * .25f;
2310 y0 = a0 * in + b1 * y1 + b2 * y2;
2311 ZOUT0(0) = y0 + 2.f * y1 + y2;
2312 y2 = y1;
2313 y1 = y0;
2315 unit->m_freq = freq;
2316 unit->m_reson = reson;
2317 unit->m_a0 = a0;
2318 unit->m_b1 = b1;
2319 unit->m_b2 = b2;
2320 } else {
2321 y0 = a0 * in + b1 * y1 + b2 * y2;
2322 ZOUT0(0) = y0 + 2.f * y1 + y2;
2323 y2 = y1;
2324 y1 = y0;
2326 unit->m_y1 = zapgremlins(y1);
2327 unit->m_y2 = zapgremlins(y2);
2332 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2334 void RHPF_Ctor(RHPF* unit)
2336 if (unit->mBufLength == 1)
2337 SETCALC(RHPF_next_1);
2338 else
2339 SETCALC(RHPF_next);
2341 unit->m_a0 = 0.;
2342 unit->m_b1 = 0.;
2343 unit->m_b2 = 0.;
2344 unit->m_y1 = 0.;
2345 unit->m_y2 = 0.;
2346 unit->m_freq = 0.f;
2347 unit->m_reson = 0.f;
2348 RHPF_next_1(unit, 1);
2352 void RHPF_next(RHPF* unit, int inNumSamples)
2354 //printf("RHPFs_next\n");
2356 float *out = ZOUT(0);
2357 float *in = ZIN(0);
2358 float freq = ZIN0(1);
2359 float reson = ZIN0(2);
2361 double y1 = unit->m_y1;
2362 double y2 = unit->m_y2;
2363 double a0 = unit->m_a0;
2364 double b1 = unit->m_b1;
2365 double b2 = unit->m_b2;
2367 if (freq != unit->m_freq || reson != unit->m_reson) {
2368 float qres = sc_max(0.001f, reson);
2369 float pfreq = freq * unit->mRate->mRadiansPerSample;
2371 double D = tan(pfreq * qres * 0.5f);
2372 double C = ((1.-D)/(1.+D));
2373 double cosf = cos(pfreq);
2375 double next_b1 = (1. + C) * cosf;
2376 double next_b2 = -C;
2377 double next_a0 = (1. + C + next_b1) * .25;
2379 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2381 double a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2382 double b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2383 double b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2384 LOOP(unit->mRate->mFilterLoops,
2385 double y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2386 ZXP(out) = y0 - 2.f * y1 + y2;
2388 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
2389 ZXP(out) = y2 - 2.f * y0 + y1;
2391 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
2392 ZXP(out) = y1 - 2.f * y2 + y0;
2394 a0 += a0_slope;
2395 b1 += b1_slope;
2396 b2 += b2_slope;
2398 LOOP(unit->mRate->mFilterRemain,
2399 double y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2400 ZXP(out) = y0 - 2.f * y1 + y2;
2401 y2 = y1;
2402 y1 = y0;
2405 unit->m_freq = freq;
2406 unit->m_reson = reson;
2407 unit->m_a0 = a0;
2408 unit->m_b1 = b1;
2409 unit->m_b2 = b2;
2410 } else {
2411 LOOP(unit->mRate->mFilterLoops,
2412 double y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2413 ZXP(out) = y0 - 2.f * y1 + y2;
2415 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
2416 ZXP(out) = y2 - 2.f * y0 + y1;
2418 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
2419 ZXP(out) = y1 - 2.f * y2 + y0;
2421 LOOP(unit->mRate->mFilterRemain,
2422 double y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2423 ZXP(out) = y0 - 2.f * y1 + y2;
2424 y2 = y1;
2425 y1 = y0;
2428 unit->m_y1 = zapgremlins(y1);
2429 unit->m_y2 = zapgremlins(y2);
2432 void RHPF_next_1(RHPF* unit, int inNumSamples)
2434 //printf("RHPFs_next_1\n");
2436 float in = ZIN0(0);
2437 float freq = ZIN0(1);
2438 float reson = ZIN0(2);
2440 double y1 = unit->m_y1;
2441 double y2 = unit->m_y2;
2442 double a0 = unit->m_a0;
2443 double b1 = unit->m_b1;
2444 double b2 = unit->m_b2;
2446 if (freq != unit->m_freq || reson != unit->m_reson) {
2447 float qres = sc_max(0.001f, reson);
2448 float pfreq = freq * unit->mRate->mRadiansPerSample;
2450 double D = tan(pfreq * qres * 0.5f);
2451 double C = ((1.-D)/(1.+D));
2452 double cosf = cos(pfreq);
2454 b1 = (1. + C) * cosf;
2455 b2 = -C;
2456 a0 = (1. + C + b1) * .25;
2458 double y0 = a0 * in + b1 * y1 + b2 * y2;
2459 ZOUT0(0) = y0 - 2.f * y1 + y2;
2460 y2 = y1;
2461 y1 = y0;
2463 unit->m_freq = freq;
2464 unit->m_reson = reson;
2465 unit->m_a0 = a0;
2466 unit->m_b1 = b1;
2467 unit->m_b2 = b2;
2468 } else {
2469 double y0 = a0 * in + b1 * y1 + b2 * y2;
2470 ZOUT0(0) = y0 - 2.f * y1 + y2;
2471 y2 = y1;
2472 y1 = y0;
2474 unit->m_y1 = zapgremlins(y1);
2475 unit->m_y2 = zapgremlins(y2);
2479 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2481 void LPF_Ctor(LPF* unit)
2483 if (unit->mBufLength == 1)
2484 SETCALC(LPF_next_1);
2485 else
2486 SETCALC(LPF_next);
2488 unit->m_a0 = 0.f;
2489 unit->m_b1 = 0.f;
2490 unit->m_b2 = 0.f;
2491 unit->m_y1 = 0.f;
2492 unit->m_y2 = 0.f;
2493 unit->m_freq = 0.f;
2494 LPF_next_1(unit, 1);
2498 void LPF_next(LPF* unit, int inNumSamples)
2500 //printf("LPF_next\n");
2502 float *out = ZOUT(0);
2503 float *in = ZIN(0);
2504 float freq = ZIN0(1);
2506 float y0;
2507 float y1 = unit->m_y1;
2508 float y2 = unit->m_y2;
2509 float a0 = unit->m_a0;
2510 float b1 = unit->m_b1;
2511 float b2 = unit->m_b2;
2513 if (freq != unit->m_freq) {
2515 float pfreq = freq * unit->mRate->mRadiansPerSample * 0.5;
2517 float C = 1.f / tan(pfreq);
2518 float C2 = C * C;
2519 float sqrt2C = C * sqrt2_f;
2520 float next_a0 = 1.f / (1.f + sqrt2C + C2);
2521 float next_b1 = -2.f * (1.f - C2) * next_a0 ;
2522 float next_b2 = -(1.f - sqrt2C + C2) * next_a0;
2524 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2526 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2527 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2528 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2529 LOOP(unit->mRate->mFilterLoops,
2530 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2531 ZXP(out) = a0 * (y0 + 2.f * y1 + y2);
2533 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2534 ZXP(out) = a0 * (y2 + 2.f * y0 + y1);
2536 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2537 ZXP(out) = a0 * (y1 + 2.f * y2 + y0);
2539 a0 += a0_slope;
2540 b1 += b1_slope;
2541 b2 += b2_slope;
2543 LOOP(unit->mRate->mFilterRemain,
2544 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2545 ZXP(out) = a0 * (y0 + 2.f * y1 + y2);
2546 y2 = y1;
2547 y1 = y0;
2550 unit->m_freq = freq;
2551 unit->m_a0 = a0;
2552 unit->m_b1 = b1;
2553 unit->m_b2 = b2;
2554 } else {
2555 LOOP(unit->mRate->mFilterLoops,
2556 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2557 ZXP(out) = a0 * (y0 + 2.f * y1 + y2);
2559 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2560 ZXP(out) = a0 * (y2 + 2.f * y0 + y1);
2562 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2563 ZXP(out) = a0 * (y1 + 2.f * y2 + y0);
2565 LOOP(unit->mRate->mFilterRemain,
2566 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2567 ZXP(out) = a0 * (y0 + 2.f * y1 + y2);
2568 y2 = y1;
2569 y1 = y0;
2572 unit->m_y1 = zapgremlins(y1);
2573 unit->m_y2 = zapgremlins(y2);
2576 void LPF_next_1(LPF* unit, int inNumSamples)
2578 //printf("LPF_next\n");
2579 float in = ZIN0(0);
2580 float freq = ZIN0(1);
2582 float y0;
2583 float y1 = unit->m_y1;
2584 float y2 = unit->m_y2;
2585 float a0 = unit->m_a0;
2586 float b1 = unit->m_b1;
2587 float b2 = unit->m_b2;
2589 if (freq != unit->m_freq) {
2591 float pfreq = freq * unit->mRate->mRadiansPerSample * 0.5;
2593 float C = 1.f / tan(pfreq);
2594 float C2 = C * C;
2595 float sqrt2C = C * sqrt2_f;
2596 a0 = 1.f / (1.f + sqrt2C + C2);
2597 b1 = -2.f * (1.f - C2) * a0 ;
2598 b2 = -(1.f - sqrt2C + C2) * a0;
2600 y0 = in + b1 * y1 + b2 * y2;
2601 ZOUT0(0) = a0 * (y0 + 2.f * y1 + y2);
2602 y2 = y1;
2603 y1 = y0;
2605 unit->m_freq = freq;
2606 unit->m_a0 = a0;
2607 unit->m_b1 = b1;
2608 unit->m_b2 = b2;
2609 } else {
2611 y0 = in + b1 * y1 + b2 * y2;
2612 ZOUT0(0) = a0 * (y0 + 2.f * y1 + y2);
2613 y2 = y1;
2614 y1 = y0;
2617 unit->m_y1 = zapgremlins(y1);
2618 unit->m_y2 = zapgremlins(y2);
2622 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2624 void HPF_Ctor(HPF* unit)
2626 if (unit->mBufLength == 1)
2627 SETCALC(HPF_next_1);
2628 else
2629 SETCALC(HPF_next);
2630 unit->m_a0 = 0.;
2631 unit->m_b1 = 0.;
2632 unit->m_b2 = 0.;
2633 unit->m_y1 = 0.;
2634 unit->m_y2 = 0.;
2635 unit->m_freq = -1e6f;
2637 HPF_next_1(unit, 1);
2641 void HPF_next(HPF* unit, int inNumSamples)
2643 float *out = ZOUT(0);
2644 float *in = ZIN(0);
2645 float freq = ZIN0(1);
2647 double y1 = unit->m_y1;
2648 double y2 = unit->m_y2;
2649 double a0 = unit->m_a0;
2650 double b1 = unit->m_b1;
2651 double b2 = unit->m_b2;
2653 if (freq != unit->m_freq) {
2654 float pfreq = freq * unit->mRate->mRadiansPerSample * 0.5;
2656 double C = tan(pfreq);
2657 double C2 = C * C;
2658 double sqrt2C = C * sqrt2_f;
2659 double next_a0 = 1. / (1. + sqrt2C + C2);
2660 double next_b1 = 2. * (1. - C2) * next_a0 ;
2661 double next_b2 = -(1. - sqrt2C + C2) * next_a0;
2663 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2665 double a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2666 double b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2667 double b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2668 LOOP(unit->mRate->mFilterLoops,
2669 double y0 = ZXP(in) + b1 * y1 + b2 * y2;
2670 ZXP(out) = a0 * (y0 - 2. * y1 + y2);
2672 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2673 ZXP(out) = a0 * (y2 - 2. * y0 + y1);
2675 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2676 ZXP(out) = a0 * (y1 - 2. * y2 + y0);
2678 a0 += a0_slope;
2679 b1 += b1_slope;
2680 b2 += b2_slope;
2682 LOOP(unit->mRate->mFilterRemain,
2683 double y0 = ZXP(in) + b1 * y1 + b2 * y2;
2684 ZXP(out) = a0 * (y0 - 2. * y1 + y2);
2685 y2 = y1;
2686 y1 = y0;
2689 unit->m_freq = freq;
2690 unit->m_a0 = a0;
2691 unit->m_b1 = b1;
2692 unit->m_b2 = b2;
2693 } else {
2694 LOOP(unit->mRate->mFilterLoops,
2695 double y0 = ZXP(in) + b1 * y1 + b2 * y2;
2696 ZXP(out) = a0 * (y0 - 2. * y1 + y2);
2698 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2699 ZXP(out) = a0 * (y2 - 2. * y0 + y1);
2701 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2702 ZXP(out) = a0 * (y1 - 2. * y2 + y0);
2704 LOOP(unit->mRate->mFilterRemain,
2705 double y0 = ZXP(in) + b1 * y1 + b2 * y2;
2706 ZXP(out) = a0 * (y0 - 2. * y1 + y2);
2707 y2 = y1;
2708 y1 = y0;
2711 unit->m_y1 = zapgremlins(y1);
2712 unit->m_y2 = zapgremlins(y2);
2715 void HPF_next_1(HPF* unit, int inNumSamples)
2717 double in = ZIN0(0);
2718 double freq = ZIN0(1);
2720 double y1 = unit->m_y1;
2721 double y2 = unit->m_y2;
2722 double a0 = unit->m_a0;
2723 double b1 = unit->m_b1;
2724 double b2 = unit->m_b2;
2726 if (freq != unit->m_freq) {
2727 float pfreq = freq * unit->mRate->mRadiansPerSample * 0.5f;
2729 double C = tan(pfreq);
2730 double C2 = C * C;
2731 double sqrt2C = C * sqrt2_f;
2732 a0 = 1. / (1. + sqrt2C + C2);
2733 b1 = 2. * (1. - C2) * a0 ;
2734 b2 = -(1. - sqrt2C + C2) * a0;
2736 double y0 = in + b1 * y1 + b2 * y2;
2737 ZOUT0(0) = a0 * (y0 - 2. * y1 + y2);
2738 y2 = y1;
2739 y1 = y0;
2741 unit->m_freq = freq;
2742 unit->m_a0 = a0;
2743 unit->m_b1 = b1;
2744 unit->m_b2 = b2;
2745 } else {
2746 double y0 = in + b1 * y1 + b2 * y2;
2747 ZOUT0(0) = a0 * (y0 - 2. * y1 + y2);
2748 y2 = y1;
2749 y1 = y0;
2752 unit->m_y1 = zapgremlins(y1);
2753 unit->m_y2 = zapgremlins(y2);
2756 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2758 void BPF_Ctor(BPF* unit)
2760 //printf("BPF_Reset\n");
2761 if (unit->mBufLength == 1) {
2762 SETCALC(BPF_next_1);
2763 } else {
2764 SETCALC(BPF_next);
2766 unit->m_a0 = 0.f;
2767 unit->m_b1 = 0.f;
2768 unit->m_b2 = 0.f;
2769 unit->m_y1 = 0.f;
2770 unit->m_y2 = 0.f;
2771 unit->m_freq = 0.f;
2772 unit->m_bw = 0.f;
2774 BPF_next_1(unit, 1);
2777 void BPF_next(BPF* unit, int inNumSamples)
2779 //printf("BPF_next\n");
2781 float *out = ZOUT(0);
2782 float *in = ZIN(0);
2783 float freq = ZIN0(1);
2784 float bw = ZIN0(2);
2786 float y0;
2787 float y1 = unit->m_y1;
2788 float y2 = unit->m_y2;
2789 float a0 = unit->m_a0;
2790 float b1 = unit->m_b1;
2791 float b2 = unit->m_b2;
2793 if (freq != unit->m_freq || bw != unit->m_bw) {
2795 float pfreq = freq * unit->mRate->mRadiansPerSample;
2796 float pbw = bw * pfreq * 0.5f;
2798 float C = 1.f / tan(pbw);
2799 float D = 2.f * cos(pfreq);
2801 float next_a0 = 1.f / (1.f + C);
2802 float next_b1 = C * D * next_a0 ;
2803 float next_b2 = (1.f - C) * next_a0;
2805 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2806 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2807 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2808 LOOP(unit->mRate->mFilterLoops,
2809 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2810 ZXP(out) = a0 * (y0 - y2);
2812 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2813 ZXP(out) = a0 * (y2 - y1);
2815 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2816 ZXP(out) = a0 * (y1 - y0);
2818 a0 += a0_slope;
2819 b1 += b1_slope;
2820 b2 += b2_slope;
2822 LOOP(unit->mRate->mFilterRemain,
2823 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2824 ZXP(out) = a0 * (y0 - y2);
2825 y2 = y1;
2826 y1 = y0;
2829 unit->m_freq = freq;
2830 unit->m_bw = bw;
2831 unit->m_a0 = a0;
2832 unit->m_b1 = b1;
2833 unit->m_b2 = b2;
2834 } else {
2835 LOOP(unit->mRate->mFilterLoops,
2836 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2837 ZXP(out) = a0 * (y0 - y2);
2839 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2840 ZXP(out) = a0 * (y2 - y1);
2842 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2843 ZXP(out) = a0 * (y1 - y0);
2845 LOOP(unit->mRate->mFilterRemain,
2846 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2847 ZXP(out) = a0 * (y0 - y2);
2848 y2 = y1;
2849 y1 = y0;
2852 unit->m_y1 = zapgremlins(y1);
2853 unit->m_y2 = zapgremlins(y2);
2856 void BPF_next_1(BPF* unit, int inNumSamples)
2858 //printf("BPF_next_1\n");
2860 float in = ZIN0(0);
2861 float freq = ZIN0(1);
2862 float bw = ZIN0(2);
2864 float y0;
2865 float y1 = unit->m_y1;
2866 float y2 = unit->m_y2;
2867 float a0 = unit->m_a0;
2868 float b1 = unit->m_b1;
2869 float b2 = unit->m_b2;
2871 if (freq != unit->m_freq || bw != unit->m_bw) {
2873 float pfreq = freq * unit->mRate->mRadiansPerSample;
2874 float pbw = bw * pfreq * 0.5;
2876 float C = 1.f / tan(pbw);
2877 float D = 2.f * cos(pfreq);
2879 float a0 = 1.f / (1.f + C);
2880 float b1 = C * D * a0 ;
2881 float b2 = (1.f - C) * a0;
2883 y0 = in + b1 * y1 + b2 * y2;
2884 ZOUT0(0) = a0 * (y0 - y2);
2885 y2 = y1;
2886 y1 = y0;
2888 unit->m_freq = freq;
2889 unit->m_bw = bw;
2890 unit->m_a0 = a0;
2891 unit->m_b1 = b1;
2892 unit->m_b2 = b2;
2893 } else {
2894 y0 = in + b1 * y1 + b2 * y2;
2895 ZOUT0(0) = a0 * (y0 - y2);
2896 y2 = y1;
2897 y1 = y0;
2899 unit->m_y1 = zapgremlins(y1);
2900 unit->m_y2 = zapgremlins(y2);
2904 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2906 void BRF_Ctor(BRF* unit)
2908 //printf("BRF_Reset\n");
2909 if (unit->mBufLength == 1) {
2910 SETCALC(BRF_next_1);
2911 } else {
2912 SETCALC(BRF_next);
2914 unit->m_a0 = 0.f;
2915 unit->m_a1 = 0.f;
2916 unit->m_b2 = 0.f;
2917 unit->m_y1 = 0.f;
2918 unit->m_y2 = 0.f;
2919 unit->m_freq = 0.f;
2920 unit->m_bw = 0.f;
2921 BRF_next_1(unit, 1);
2925 void BRF_next(BRF* unit, int inNumSamples)
2927 //printf("BRF_next\n");
2929 float *out = ZOUT(0);
2930 float *in = ZIN(0);
2931 float freq = ZIN0(1);
2932 float bw = ZIN0(2);
2934 float ay;
2935 float y0;
2936 float y1 = unit->m_y1;
2937 float y2 = unit->m_y2;
2938 float a0 = unit->m_a0;
2939 float a1 = unit->m_a1;
2940 float b2 = unit->m_b2;
2942 if (freq != unit->m_freq || bw != unit->m_bw) {
2943 float pfreq = freq * unit->mRate->mRadiansPerSample;
2944 float pbw = bw * pfreq * 0.5f;
2946 float C = tan(pbw);
2947 float D = 2.f * cos(pfreq);
2949 float next_a0 = 1.f / (1.f + C);
2950 float next_a1 = -D * next_a0;
2951 float next_b2 = (1.f - C) * next_a0;
2953 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2954 float a1_slope = (next_a1 - a1) * unit->mRate->mFilterSlope;
2955 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2957 LOOP(unit->mRate->mFilterLoops,
2958 ay = a1 * y1;
2959 y0 = ZXP(in) - ay - b2 * y2;
2960 ZXP(out) = a0 * (y0 + y2) + ay;
2962 ay = a1 * y0;
2963 y2 = ZXP(in) - ay - b2 * y1;
2964 ZXP(out) = a0 * (y2 + y1) + ay;
2966 ay = a1 * y2;
2967 y1 = ZXP(in) - ay - b2 * y0;
2968 ZXP(out) = a0 * (y1 + y0) + ay;
2970 a0 += a0_slope;
2971 a1 += a1_slope;
2972 b2 += b2_slope;
2974 LOOP(unit->mRate->mFilterRemain,
2975 ay = a1 * y1;
2976 y0 = ZXP(in) - ay - b2 * y2;
2977 ZXP(out) = a0 * (y0 + y2) + ay;
2978 y2 = y1;
2979 y1 = y0;
2982 unit->m_freq = freq;
2983 unit->m_bw = bw;
2984 unit->m_a0 = a0;
2985 unit->m_a1 = a1;
2986 unit->m_b2 = b2;
2987 } else {
2988 LOOP(unit->mRate->mFilterLoops,
2989 ay = a1 * y1;
2990 y0 = ZXP(in) - ay - b2 * y2;
2991 ZXP(out) = a0 * (y0 + y2) + ay;
2993 ay = a1 * y0;
2994 y2 = ZXP(in) - ay - b2 * y1;
2995 ZXP(out) = a0 * (y2 + y1) + ay;
2997 ay = a1 * y2;
2998 y1 = ZXP(in) - ay - b2 * y0;
2999 ZXP(out) = a0 * (y1 + y0) + ay;
3001 LOOP(unit->mRate->mFilterRemain,
3002 ay = a1 * y1;
3003 y0 = ZXP(in) - ay - b2 * y2;
3004 ZXP(out) = a0 * (y0 + y2) + ay;
3005 y2 = y1;
3006 y1 = y0;
3009 unit->m_y1 = zapgremlins(y1);
3010 unit->m_y2 = zapgremlins(y2);
3015 void BRF_next_1(BRF* unit, int inNumSamples)
3017 //printf("BRF_next_1\n");
3019 float in = ZIN0(0);
3020 float freq = ZIN0(1);
3021 float bw = ZIN0(2);
3023 float ay;
3024 float y0;
3025 float y1 = unit->m_y1;
3026 float y2 = unit->m_y2;
3027 float a0 = unit->m_a0;
3028 float a1 = unit->m_a1;
3029 float b2 = unit->m_b2;
3031 if (freq != unit->m_freq || bw != unit->m_bw) {
3032 float pfreq = freq * unit->mRate->mRadiansPerSample;
3033 float pbw = bw * pfreq * 0.5f;
3035 float C = tan(pbw);
3036 float D = 2.f * cos(pfreq);
3038 float a0 = 1.f / (1.f + C);
3039 float a1 = -D * a0;
3040 float b2 = (1.f - C) * a0;
3042 ay = a1 * y1;
3043 y0 = in - ay - b2 * y2;
3044 ZOUT0(0) = a0 * (y0 + y2) + ay;
3045 y2 = y1;
3046 y1 = y0;
3048 unit->m_freq = freq;
3049 unit->m_bw = bw;
3050 unit->m_a0 = a0;
3051 unit->m_a1 = a1;
3052 unit->m_b2 = b2;
3053 } else {
3055 ay = a1 * y1;
3056 y0 = in - ay - b2 * y2;
3057 ZOUT0(0) = a0 * (y0 + y2) + ay;
3058 y2 = y1;
3059 y1 = y0;
3062 unit->m_y1 = zapgremlins(y1);
3063 unit->m_y2 = zapgremlins(y2);
3067 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3069 void MidEQ_Ctor(MidEQ* unit)
3071 //printf("MidEQ_Reset\n");
3072 SETCALC(MidEQ_next);
3073 unit->m_a0 = 0.f;
3074 unit->m_b1 = 0.f;
3075 unit->m_b2 = 0.f;
3076 unit->m_y1 = 0.f;
3077 unit->m_y2 = 0.f;
3078 unit->m_freq = 0.f;
3079 unit->m_bw = 0.f;
3080 unit->m_db = 0.f;
3081 PUSH_LOOPVALS
3082 MidEQ_next(unit, 1);
3083 POP_LOOPVALS
3087 void MidEQ_next(MidEQ* unit, int inNumSamples)
3089 //printf("MidEQ_next\n");
3091 float *out = ZOUT(0);
3092 float *in = ZIN(0);
3093 float freq = ZIN0(1);
3094 float bw = ZIN0(2);
3095 float db = ZIN0(3);
3097 float y0;
3098 float y1 = unit->m_y1;
3099 float y2 = unit->m_y2;
3100 float a0 = unit->m_a0;
3101 float b1 = unit->m_b1;
3102 float b2 = unit->m_b2;
3103 if (freq != unit->m_freq || bw != unit->m_bw || db != unit->m_db) {
3105 float amp = sc_dbamp(db) - 1.0f;
3106 float pfreq = freq * unit->mRate->mRadiansPerSample;
3107 float pbw = bw * pfreq * 0.5f;
3109 float C = 1.f / tan(pbw);
3110 float D = 2.f * cos(pfreq);
3112 float next_a0 = 1.f / (1.f + C);
3113 float next_b1 = C * D * next_a0 ;
3114 float next_b2 = (1.f - C) * next_a0;
3115 next_a0 *= amp;
3116 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
3117 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
3118 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
3119 float zin;
3120 LOOP(unit->mRate->mFilterLoops,
3121 zin = ZXP(in);
3122 y0 = zin + b1 * y1 + b2 * y2;
3123 ZXP(out) = zin + a0 * (y0 - y2);
3125 zin = ZXP(in);
3126 y2 = zin + b1 * y0 + b2 * y1;
3127 ZXP(out) = zin + a0 * (y2 - y1);
3129 zin = ZXP(in);
3130 y1 = zin + b1 * y2 + b2 * y0;
3131 ZXP(out) = zin + a0 * (y1 - y0);
3133 a0 += a0_slope;
3134 b1 += b1_slope;
3135 b2 += b2_slope;
3137 LOOP(unit->mRate->mFilterRemain,
3138 zin = ZXP(in);
3139 y0 = zin + b1 * y1 + b2 * y2;
3140 ZXP(out) = zin + a0 * (y0 - y2);
3141 y2 = y1;
3142 y1 = y0;
3145 unit->m_freq = freq;
3146 unit->m_bw = bw;
3147 unit->m_db = db;
3148 unit->m_a0 = a0;
3149 unit->m_b1 = b1;
3150 unit->m_b2 = b2;
3151 } else {
3152 float zin;
3153 LOOP(unit->mRate->mFilterLoops,
3154 zin = ZXP(in);
3155 y0 = zin + b1 * y1 + b2 * y2;
3156 ZXP(out) = zin + a0 * (y0 - y2);
3158 zin = ZXP(in);
3159 y2 = zin + b1 * y0 + b2 * y1;
3160 ZXP(out) = zin + a0 * (y2 - y1);
3162 zin = ZXP(in);
3163 y1 = zin + b1 * y2 + b2 * y0;
3164 ZXP(out) = zin + a0 * (y1 - y0);
3166 LOOP(unit->mRate->mFilterRemain,
3167 zin = ZXP(in);
3168 y0 = zin + b1 * y1 + b2 * y2;
3169 ZXP(out) = zin + a0 * (y0 - y2);
3170 y2 = y1;
3171 y1 = y0;
3174 unit->m_y1 = zapgremlins(y1);
3175 unit->m_y2 = zapgremlins(y2);
3178 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3180 static void Median_InitMedian(Median* unit, long size, float value);
3181 static float Median_InsertMedian(Median* unit, float value);
3183 void Median_Ctor(Median* unit)
3185 //printf("Median_Reset\n");
3186 SETCALC(Median_next);
3187 float in = ZIN0(1);
3188 unit->m_medianSize = sc_clip((int)ZIN0(0), 0, kMAXMEDIANSIZE);
3189 Median_InitMedian(unit, unit->m_medianSize, in);
3190 ZOUT0(0) = Median_InsertMedian(unit, in);
3194 float Median_InsertMedian(Median* unit, float value)
3196 long pos=-1;
3198 // keeps a sorted list of the previous n=size values
3199 // the oldest is removed and the newest is inserted.
3200 // values between the oldest and the newest are shifted over by one.
3202 // values and ages are both arrays that are 'size' long.
3203 // the median value is always values[size>>1]
3205 long last = unit->m_medianSize - 1;
3206 // find oldest bin and age the other bins.
3207 for (int i=0; i<unit->m_medianSize; ++i) {
3208 if (unit->m_medianAge[i] == last) { // is it the oldest bin ?
3209 pos = i;
3210 } else {
3211 unit->m_medianAge[i]++; // age the bin
3214 // move values to fill in place of the oldest and make a space for the newest
3215 // search lower if value is too small for the open space
3216 while (pos != 0 && value < unit->m_medianValue[pos-1]) {
3217 unit->m_medianValue[pos] = unit->m_medianValue[pos-1];
3218 unit->m_medianAge[pos] = unit->m_medianAge[pos-1];
3219 pos--;
3221 // search higher if value is too big for the open space
3222 while (pos != last && value > unit->m_medianValue[pos+1]) {
3223 unit->m_medianValue[pos] = unit->m_medianValue[pos+1];
3224 unit->m_medianAge[pos] = unit->m_medianAge[pos+1];
3225 pos++;
3227 unit->m_medianValue[pos] = value;
3228 unit->m_medianAge[pos] = 0; // this is the newest bin, age = 0
3229 return unit->m_medianValue[unit->m_medianSize>>1];
3232 void Median_InitMedian(Median* unit, long size, float value)
3234 // initialize the arrays with the first value
3235 unit->m_medianSize = size;
3236 for (int i=0; i<size; ++i) {
3237 unit->m_medianValue[i] = value;
3238 unit->m_medianAge[i] = i;
3242 void Median_next(Median* unit, int inNumSamples)
3244 //printf("Median_next_a\n");
3246 float *out = ZOUT(0);
3247 float *in = ZIN(1);
3249 LOOP1(inNumSamples,
3250 ZXP(out) = Median_InsertMedian(unit, ZXP(in));
3255 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3257 void Resonz_Ctor(Resonz* unit)
3259 //printf("Resonz_Reset\n");
3260 SETCALC(Resonz_next);
3261 unit->m_a0 = 0.f;
3262 unit->m_b1 = 0.f;
3263 unit->m_b2 = 0.f;
3264 unit->m_y1 = 0.f;
3265 unit->m_y2 = 0.f;
3266 unit->m_freq = 0.f;
3267 unit->m_rq = 0.f;
3268 PUSH_LOOPVALS
3269 Resonz_next(unit, 1);
3270 POP_LOOPVALS
3274 void Resonz_next(Resonz* unit, int inNumSamples)
3276 //printf("Resonz_next\n");
3278 float *out = ZOUT(0);
3279 float *in = ZIN(0);
3280 float freq = ZIN0(1);
3281 float rq = ZIN0(2);
3283 float y0;
3284 float y1 = unit->m_y1;
3285 float y2 = unit->m_y2;
3286 float a0 = unit->m_a0;
3287 float b1 = unit->m_b1;
3288 float b2 = unit->m_b2;
3290 if (freq != unit->m_freq || rq != unit->m_rq) {
3291 float ffreq = freq * unit->mRate->mRadiansPerSample;
3292 float B = ffreq * rq;
3293 float R = 1.f - B * 0.5f;
3294 float twoR = 2.f * R;
3295 float R2 = R * R;
3296 float cost = (twoR * cos(ffreq)) / (1.f + R2);
3297 float b1_next = twoR * cost;
3298 float b2_next = -R2;
3299 float a0_next = (1.f - R2) * 0.5f;
3300 float a0_slope = (a0_next - a0) * unit->mRate->mFilterSlope;
3301 float b1_slope = (b1_next - b1) * unit->mRate->mFilterSlope;
3302 float b2_slope = (b2_next - b2) * unit->mRate->mFilterSlope;
3303 LOOP(unit->mRate->mFilterLoops,
3304 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3305 ZXP(out) = a0 * (y0 - y2);
3307 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3308 ZXP(out) = a0 * (y2 - y1);
3310 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3311 ZXP(out) = a0 * (y1 - y0);
3313 a0 += a0_slope;
3314 b1 += b1_slope;
3315 b2 += b2_slope;
3317 LOOP(unit->mRate->mFilterRemain,
3318 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3319 ZXP(out) = a0 * (y0 - y2);
3320 y2 = y1;
3321 y1 = y0;
3324 unit->m_freq = freq;
3325 unit->m_rq = rq;
3326 unit->m_a0 = a0_next;
3327 unit->m_b1 = b1_next;
3328 unit->m_b2 = b2_next;
3329 } else {
3330 LOOP(unit->mRate->mFilterLoops,
3331 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3332 ZXP(out) = a0 * (y0 - y2);
3334 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3335 ZXP(out) = a0 * (y2 - y1);
3337 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3338 ZXP(out) = a0 * (y1 - y0);
3340 LOOP(unit->mRate->mFilterRemain,
3341 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3342 ZXP(out) = a0 * (y0 - y2);
3343 y2 = y1;
3344 y1 = y0;
3347 unit->m_y1 = zapgremlins(y1);
3348 unit->m_y2 = zapgremlins(y2);
3352 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3354 void Ringz_Ctor(Ringz* unit)
3356 //printf("Ringz_ctor\n");
3357 SETCALC(Ringz_next);
3358 unit->m_b1 = 0.f;
3359 unit->m_b2 = 0.f;
3360 unit->m_y1 = 0.f;
3361 unit->m_y2 = 0.f;
3362 unit->m_freq = 0.f;
3363 unit->m_decayTime = 0.f;
3364 PUSH_LOOPVALS
3365 Ringz_next(unit, 1);
3366 POP_LOOPVALS
3370 void Ringz_next(Ringz* unit, int inNumSamples)
3372 //printf("Ringz_next\n");
3374 float *out = ZOUT(0);
3375 float *in = ZIN(0);
3376 float freq = ZIN0(1);
3377 float decayTime = ZIN0(2);
3379 float y0;
3380 float y1 = unit->m_y1;
3381 float y2 = unit->m_y2;
3382 float a0 = 0.5f;
3383 float b1 = unit->m_b1;
3384 float b2 = unit->m_b2;
3386 if (freq != unit->m_freq || decayTime != unit->m_decayTime) {
3387 float ffreq = freq * unit->mRate->mRadiansPerSample;
3388 float R = decayTime == 0.f ? 0.f : exp(log001/(decayTime * SAMPLERATE));
3389 float twoR = 2.f * R;
3390 float R2 = R * R;
3391 float cost = (twoR * cos(ffreq)) / (1.f + R2);
3392 float b1_next = twoR * cost;
3393 float b2_next = -R2;
3394 float b1_slope = (b1_next - b1) * unit->mRate->mFilterSlope;
3395 float b2_slope = (b2_next - b2) * unit->mRate->mFilterSlope;
3396 LOOP(unit->mRate->mFilterLoops,
3397 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3398 ZXP(out) = a0 * (y0 - y2);
3400 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3401 ZXP(out) = a0 * (y2 - y1);
3403 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3404 ZXP(out) = a0 * (y1 - y0);
3406 b1 += b1_slope;
3407 b2 += b2_slope;
3409 LOOP(unit->mRate->mFilterRemain,
3410 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3411 ZXP(out) = a0 * (y0 - y2);
3412 y2 = y1;
3413 y1 = y0;
3416 unit->m_freq = freq;
3417 unit->m_decayTime = decayTime;
3418 unit->m_b1 = b1_next;
3419 unit->m_b2 = b2_next;
3420 } else {
3421 LOOP(unit->mRate->mFilterLoops,
3422 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3423 ZXP(out) = a0 * (y0 - y2);
3425 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3426 ZXP(out) = a0 * (y2 - y1);
3428 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3429 ZXP(out) = a0 * (y1 - y0);
3431 LOOP(unit->mRate->mFilterRemain,
3432 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3433 ZXP(out) = a0 * (y0 - y2);
3434 y2 = y1;
3435 y1 = y0;
3438 unit->m_y1 = zapgremlins(y1);
3439 unit->m_y2 = zapgremlins(y2);
3443 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3445 void Formlet_Ctor(Formlet* unit)
3447 //printf("Formlet_Reset\n");
3448 if (unit->mBufLength == 1) {
3449 SETCALC(Formlet_next_1);
3450 } else {
3451 SETCALC(Formlet_next);
3453 unit->m_b01 = 0.f;
3454 unit->m_b02 = 0.f;
3455 unit->m_y01 = 0.f;
3456 unit->m_y02 = 0.f;
3457 unit->m_b11 = 0.f;
3458 unit->m_b12 = 0.f;
3459 unit->m_y11 = 0.f;
3460 unit->m_y12 = 0.f;
3461 unit->m_freq = 0.f;
3462 unit->m_attackTime = 0.f;
3463 unit->m_decayTime = 0.f;
3464 Formlet_next_1(unit, 1);
3467 void Formlet_next(Formlet* unit, int inNumSamples)
3469 //printf("Formlet_next\n");
3471 float *out = ZOUT(0);
3472 float *in = ZIN(0);
3473 float freq = ZIN0(1);
3474 float attackTime = ZIN0(2);
3475 float decayTime = ZIN0(3);
3477 float y00;
3478 float y10;
3479 float y01 = unit->m_y01;
3480 float y11 = unit->m_y11;
3481 float y02 = unit->m_y02;
3482 float y12 = unit->m_y12;
3484 float b01 = unit->m_b01;
3485 float b11 = unit->m_b11;
3486 float b02 = unit->m_b02;
3487 float b12 = unit->m_b12;
3488 float ain;
3490 if (freq != unit->m_freq || decayTime != unit->m_decayTime || attackTime != unit->m_attackTime) {
3491 float ffreq = freq * unit->mRate->mRadiansPerSample;
3493 float R = decayTime == 0.f ? 0.f : exp(log001/(decayTime * SAMPLERATE));
3494 float twoR = 2.f * R;
3495 float R2 = R * R;
3496 float cost = (twoR * cos(ffreq)) / (1.f + R2);
3497 float b01_next = twoR * cost;
3498 float b02_next = -R2;
3499 float b01_slope = (b01_next - b01) * unit->mRate->mFilterSlope;
3500 float b02_slope = (b02_next - b02) * unit->mRate->mFilterSlope;
3502 R = attackTime == 0.f ? 0.f : exp(log001/(attackTime * SAMPLERATE));
3503 twoR = 2.f * R;
3504 R2 = R * R;
3505 cost = (twoR * cos(ffreq)) / (1.f + R2);
3506 float b11_next = twoR * cost;
3507 float b12_next = -R2;
3508 float b11_slope = (b11_next - b11) * unit->mRate->mFilterSlope;
3509 float b12_slope = (b12_next - b12) * unit->mRate->mFilterSlope;
3511 LOOP(unit->mRate->mFilterLoops,
3512 ain = ZXP(in);
3513 y00 = ain + b01 * y01 + b02 * y02;
3514 y10 = ain + b11 * y11 + b12 * y12;
3515 ZXP(out) = 0.25f * ((y00 - y02) - (y10 - y12));
3517 ain = ZXP(in);
3518 y02 = ain + b01 * y00 + b02 * y01;
3519 y12 = ain + b11 * y10 + b12 * y11;
3520 ZXP(out) = 0.25f * ((y02 - y01) - (y12 - y11));
3522 ain = ZXP(in);
3523 y01 = ain + b01 * y02 + b02 * y00;
3524 y11 = ain + b11 * y12 + b12 * y10;
3525 ZXP(out) = 0.25f * ((y01 - y00) - (y11 - y10));
3527 b01 += b01_slope;
3528 b02 += b02_slope;
3529 b11 += b11_slope;
3530 b12 += b12_slope;
3532 LOOP(unit->mRate->mFilterRemain,
3533 ain = ZXP(in);
3534 y00 = ain + b01 * y01 + b02 * y02;
3535 y10 = ain + b11 * y11 + b12 * y12;
3536 ZXP(out) = 0.25f * ((y00 - y02) - (y10 - y12));
3537 y02 = y01;
3538 y01 = y00;
3539 y12 = y11;
3540 y11 = y10;
3543 unit->m_freq = freq;
3544 unit->m_attackTime = attackTime;
3545 unit->m_decayTime = decayTime;
3546 unit->m_b01 = b01_next;
3547 unit->m_b02 = b02_next;
3548 unit->m_b11 = b11_next;
3549 unit->m_b12 = b12_next;
3550 } else {
3551 LOOP(unit->mRate->mFilterLoops,
3552 ain = ZXP(in);
3553 y00 = ain + b01 * y01 + b02 * y02;
3554 y10 = ain + b11 * y11 + b12 * y12;
3555 ZXP(out) = 0.25f * ((y00 - y02) - (y10 - y12));
3557 ain = ZXP(in);
3558 y02 = ain + b01 * y00 + b02 * y01;
3559 y12 = ain + b11 * y10 + b12 * y11;
3560 ZXP(out) = 0.25f * ((y02 - y01) - (y12 - y11));
3562 ain = ZXP(in);
3563 y01 = ain + b01 * y02 + b02 * y00;
3564 y11 = ain + b11 * y12 + b12 * y10;
3565 ZXP(out) = 0.25f * ((y01 - y00) - (y11 - y10));
3567 LOOP(unit->mRate->mFilterRemain,
3568 ain = ZXP(in);
3569 y00 = ain + b01 * y01 + b02 * y02;
3570 y10 = ain + b11 * y11 + b12 * y12;
3571 ZXP(out) = 0.25f * ((y00 - y02) - (y10 - y12));
3572 y02 = y01;
3573 y01 = y00;
3574 y12 = y11;
3575 y11 = y10;
3578 unit->m_y01 = y01;
3579 unit->m_y02 = y02;
3580 unit->m_y11 = y11;
3581 unit->m_y12 = y12;
3584 void Formlet_next_1(Formlet* unit, int inNumSamples)
3586 //printf("Formlet_next\n");
3588 float in = ZIN0(0);
3589 float freq = ZIN0(1);
3590 float attackTime = ZIN0(2);
3591 float decayTime = ZIN0(3);
3593 float y00;
3594 float y10;
3595 float y01 = unit->m_y01;
3596 float y11 = unit->m_y11;
3597 float y02 = unit->m_y02;
3598 float y12 = unit->m_y12;
3600 float b01 = unit->m_b01;
3601 float b11 = unit->m_b11;
3602 float b02 = unit->m_b02;
3603 float b12 = unit->m_b12;
3604 float ain;
3606 if (freq != unit->m_freq || decayTime != unit->m_decayTime || attackTime != unit->m_attackTime) {
3607 float ffreq = freq * unit->mRate->mRadiansPerSample;
3609 float R = decayTime == 0.f ? 0.f : exp(log001/(decayTime * SAMPLERATE));
3610 float twoR = 2.f * R;
3611 float R2 = R * R;
3612 float cost = (twoR * cos(ffreq)) / (1.f + R2);
3613 b01 = twoR * cost;
3614 b02 = -R2;
3616 R = attackTime == 0.f ? 0.f : exp(log001/(attackTime * SAMPLERATE));
3617 twoR = 2.f * R;
3618 R2 = R * R;
3619 cost = (twoR * cos(ffreq)) / (1.f + R2);
3620 b11 = twoR * cost;
3621 b12 = -R2;
3623 ain = in;
3624 y00 = ain + b01 * y01 + b02 * y02;
3625 y10 = ain + b11 * y11 + b12 * y12;
3626 ZOUT0(0) = 0.25f * ((y00 - y02) - (y10 - y12));
3628 y02 = y01;
3629 y01 = y00;
3630 y12 = y11;
3631 y11 = y10;
3633 unit->m_freq = freq;
3634 unit->m_attackTime = attackTime;
3635 unit->m_decayTime = decayTime;
3636 unit->m_b01 = b01;
3637 unit->m_b02 = b02;
3638 unit->m_b11 = b11;
3639 unit->m_b12 = b12;
3640 } else {
3641 ain = in;
3642 y00 = ain + b01 * y01 + b02 * y02;
3643 y10 = ain + b11 * y11 + b12 * y12;
3644 ZOUT0(0) = 0.25f * ((y00 - y02) - (y10 - y12));
3646 y02 = y01;
3647 y01 = y00;
3648 y12 = y11;
3649 y11 = y10;
3651 unit->m_y01 = y01;
3652 unit->m_y02 = y02;
3653 unit->m_y11 = y11;
3654 unit->m_y12 = y12;
3658 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3660 void FOS_Ctor(FOS* unit)
3662 //printf("FOS_Reset\n");
3663 if (unit->mBufLength == 1) {
3664 SETCALC(FOS_next_1);
3665 } else {
3666 if (INRATE(1) == calc_FullRate
3667 && INRATE(2) == calc_FullRate
3668 && INRATE(3) == calc_FullRate) {
3669 SETCALC(FOS_next_a);
3670 } else {
3671 SETCALC(FOS_next_k);
3674 unit->m_y1 = 0.f;
3675 unit->m_a0 = 0.f;
3676 unit->m_a1 = 0.f;
3677 unit->m_b1 = 0.f;
3678 FOS_next_1(unit, 1);
3681 void FOS_next_a(FOS* unit, int inNumSamples)
3683 float *out = ZOUT(0);
3684 float *in = ZIN(0);
3685 float *a0 = ZIN(1);
3686 float *a1 = ZIN(2);
3687 float *b1 = ZIN(3);
3689 float y1 = unit->m_y1;
3690 LOOP1(inNumSamples,
3691 float y0 = ZXP(in) + ZXP(b1) * y1;
3692 ZXP(out) = ZXP(a0) * y0 + ZXP(a1) * y1;
3693 y1 = y0;
3695 unit->m_y1 = zapgremlins(y1);
3698 void FOS_next_1(FOS* unit, int inNumSamples)
3700 float in = ZIN0(0);
3701 float a0 = ZIN0(1);
3702 float a1 = ZIN0(2);
3703 float b1 = ZIN0(3);
3705 float y1 = unit->m_y1;
3707 float y0 = in + b1 * y1;
3708 ZOUT0(0) = a0 * y0 + a1 * y1;
3709 y1 = y0;
3711 unit->m_y1 = zapgremlins(y1);
3715 void FOS_next_k(FOS* unit, int inNumSamples)
3717 float *out = ZOUT(0);
3718 float *in = ZIN(0);
3719 float next_a0 = ZIN0(1);
3720 float next_a1 = ZIN0(2);
3721 float next_b1 = ZIN0(3);
3723 float y1 = unit->m_y1;
3724 float a0 = unit->m_a0;
3725 float a1 = unit->m_a1;
3726 float b1 = unit->m_b1;
3727 float a0_slope = CALCSLOPE(next_a0, a0);
3728 float a1_slope = CALCSLOPE(next_a1, a1);
3729 float b1_slope = CALCSLOPE(next_b1, b1);
3730 LOOP1(inNumSamples,
3731 float y0 = ZXP(in) + b1 * y1;
3732 ZXP(out) = a0 * y0 + a1 * y1;
3733 y1 = y0;
3735 a0 += a0_slope;
3736 a1 += a1_slope;
3737 b1 += b1_slope;
3739 unit->m_y1 = zapgremlins(y1);
3740 unit->m_a0 = next_a0;
3741 unit->m_a1 = next_a1;
3742 unit->m_b1 = next_b1;
3745 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3747 void SOS_Ctor(SOS* unit)
3749 // printf("SOS_Reset\n");
3750 if (unit->mBufLength != 1) {
3751 if (INRATE(1) == calc_FullRate
3752 && INRATE(2) == calc_FullRate
3753 && INRATE(3) == calc_FullRate
3754 && INRATE(4) == calc_FullRate
3755 && INRATE(5) == calc_FullRate) {
3756 SETCALC(SOS_next_a);
3757 // printf("SOS_next_a\n");
3758 } else {
3759 SETCALC(SOS_next_k);
3760 // printf("SOS_next_k\n");
3762 } else {
3763 SETCALC(SOS_next_1);
3764 // printf("SOS_next_1\n");
3766 unit->m_y1 = 0.f;
3767 unit->m_y2 = 0.f;
3768 unit->m_a0 = 0.f;
3769 unit->m_a1 = 0.f;
3770 unit->m_a2 = 0.f;
3771 unit->m_b1 = 0.f;
3772 unit->m_b2 = 0.f;
3773 SOS_next_1(unit, 1);
3776 void SOS_next_a(SOS *unit, int inNumSamples)
3778 float *out = ZOUT(0);
3779 float *in = ZIN(0);
3780 float *a0 = ZIN(1);
3781 float *a1 = ZIN(2);
3782 float *a2 = ZIN(3);
3783 float *b1 = ZIN(4);
3784 float *b2 = ZIN(5);
3786 float y0;
3787 float y1 = unit->m_y1;
3788 float y2 = unit->m_y2;
3789 LOOP(unit->mRate->mFilterLoops,
3790 y0 = ZXP(in) + ZXP(b1) * y1 + ZXP(b2) * y2;
3791 ZXP(out) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2;
3793 y2 = ZXP(in) + ZXP(b1) * y0 + ZXP(b2) * y1;
3794 ZXP(out) = ZXP(a0) * y2 + ZXP(a1) * y0 + ZXP(a2) * y1;
3796 y1 = ZXP(in) + ZXP(b1) * y2 + ZXP(b2) * y0;
3797 ZXP(out) = ZXP(a0) * y1 + ZXP(a1) * y2 + ZXP(a2) * y0;
3799 LOOP(unit->mRate->mFilterRemain,
3800 y0 = ZXP(in) + ZXP(b1) * y1 + ZXP(b2) * y2;
3801 ZXP(out) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2;
3802 y2 = y1;
3803 y1 = y0;
3806 unit->m_y1 = zapgremlins(y1);
3807 unit->m_y2 = zapgremlins(y2);
3810 void SOS_next_k(SOS *unit, int inNumSamples)
3812 float *out = ZOUT(0);
3813 float *in = ZIN(0);
3814 float next_a0 = ZIN0(1);
3815 float next_a1 = ZIN0(2);
3816 float next_a2 = ZIN0(3);
3817 float next_b1 = ZIN0(4);
3818 float next_b2 = ZIN0(5);
3820 float y0;
3821 float y1 = unit->m_y1;
3822 float y2 = unit->m_y2;
3823 float a0 = unit->m_a0;
3824 float a1 = unit->m_a1;
3825 float a2 = unit->m_a2;
3826 float b1 = unit->m_b1;
3827 float b2 = unit->m_b2;
3828 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
3829 float a1_slope = (next_a1 - a1) * unit->mRate->mFilterSlope;
3830 float a2_slope = (next_a2 - a2) * unit->mRate->mFilterSlope;
3831 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
3832 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
3833 LOOP(unit->mRate->mFilterLoops,
3834 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3835 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
3837 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3838 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
3840 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3841 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
3843 a0 += a0_slope;
3844 a1 += a1_slope;
3845 a2 += a2_slope;
3846 b1 += b1_slope;
3847 b2 += b2_slope;
3849 LOOP(unit->mRate->mFilterRemain,
3850 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3851 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
3852 y2 = y1;
3853 y1 = y0;
3856 unit->m_a0 = a0;
3857 unit->m_a1 = a1;
3858 unit->m_a2 = a2;
3859 unit->m_b1 = b1;
3860 unit->m_b2 = b2;
3861 unit->m_y1 = zapgremlins(y1);
3862 unit->m_y2 = zapgremlins(y2);
3865 void SOS_next_1(SOS *unit, int inNumSamples) // optimized for SOS.kr
3867 float in = ZIN0(0);
3868 float a0 = ZIN0(1);
3869 float a1 = ZIN0(2);
3870 float a2 = ZIN0(3);
3871 float b1 = ZIN0(4);
3872 float b2 = ZIN0(5);
3874 float y0;
3875 float y1 = unit->m_y1;
3876 float y2 = unit->m_y2;
3878 y0 = in + b1 * y1 + b2 * y2;
3879 ZOUT0(0) = a0 * y0 + a1 * y1 + a2 * y2;
3880 y2 = y1;
3881 y1 = y0;
3883 unit->m_y1 = zapgremlins(y1);
3884 unit->m_y2 = zapgremlins(y2);
3887 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3889 void Compander_Ctor(Compander* unit)
3891 //printf("Compander_Reset\n");
3892 SETCALC(Compander_next);
3893 unit->m_clamp = 0.f;
3894 unit->m_clampcoef = 0.f;
3895 unit->m_relax = 0.f;
3896 unit->m_relaxcoef = 0.f;
3897 unit->m_prevmaxval = 0.f;
3898 unit->m_gain = 0.f;
3899 Compander_next(unit, 1);
3902 void Compander_next(Compander* unit, int inNumSamples)
3904 float *out = ZOUT(0);
3905 float *in = ZIN(0);
3906 float *control = ZIN(1);
3907 float thresh = ZIN0(2);
3908 float slope_below = ZIN0(3);
3909 float slope_above = ZIN0(4);
3910 float clamp = ZIN0(5);
3911 float relax = ZIN0(6);
3913 if (clamp != unit->m_clamp) {
3914 unit->m_clampcoef = clamp == 0.0 ? 0.0 : exp(log1/(clamp * SAMPLERATE));
3915 unit->m_clamp = clamp;
3917 if (relax != unit->m_relax) {
3918 unit->m_relaxcoef = relax == 0.0 ? 0.0 : exp(log1/(relax * SAMPLERATE));
3919 unit->m_relax = relax;
3922 float gain = unit->m_gain;
3924 float relaxcoef = unit->m_relaxcoef;
3925 float clampcoef = unit->m_clampcoef;
3927 float prevmaxval = unit->m_prevmaxval;
3929 float val;
3930 LOOP1(inNumSamples,
3931 val = std::abs(ZXP(control));
3932 if (val < prevmaxval) {
3933 val = val + (prevmaxval - val) * relaxcoef;
3934 } else {
3935 val = val + (prevmaxval - val) * clampcoef;
3937 prevmaxval = val;
3940 unit->m_prevmaxval = prevmaxval;
3942 float next_gain;//,absx;
3943 if (prevmaxval < thresh) {
3944 if (slope_below == 1.f) {
3945 next_gain = 1.f;
3946 } else {
3947 next_gain = pow(prevmaxval / thresh, slope_below - 1.f);
3948 //blows up here
3949 float32 absx = std::abs(next_gain);
3950 //zap gremlins, but returns 0. if gain is too small and 1. if gain is too big
3951 next_gain =
3952 (absx < (float32)1e-15) ? (float32)0. :
3953 (absx > (float32)1e15) ? (float32)1. : next_gain;
3955 } else {
3956 if (slope_above == 1.f) {
3957 next_gain = 1.f;
3958 } else {
3959 next_gain = pow(prevmaxval / thresh, slope_above - 1.f);
3963 float gain_slope = CALCSLOPE(next_gain, gain);
3964 LOOP1(inNumSamples, ZXP(out) = ZXP(in) * gain; gain += gain_slope;);
3965 unit->m_gain = gain;
3968 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3971 void Normalizer_Dtor(Normalizer* unit)
3973 RTFree(unit->mWorld, unit->m_table);
3976 void Normalizer_Ctor(Normalizer* unit)
3978 SETCALC(Normalizer_next);
3979 //printf("Normalizer_Reset\n");
3981 float dur = ZIN0(2);
3982 unit->m_bufsize = (long)(ceil(dur * SAMPLERATE));
3983 long allocsize = unit->m_bufsize * 3;
3984 //allocsize = NEXTPOWEROFTWO(allocsize);
3986 unit->m_table = (float*)RTAlloc(unit->mWorld, allocsize * sizeof(float));
3988 unit->m_pos = 0;
3989 unit->m_flips = 0;
3990 unit->m_level = 1.f;
3991 unit->m_slope = 0.f;
3992 unit->m_prevmaxval = 0.0;
3993 unit->m_curmaxval = 0.0;
3994 unit->m_slopefactor = 1.f / unit->m_bufsize;
3996 unit->m_xinbuf = unit->m_table - ZOFF;
3997 unit->m_xmidbuf = unit->m_xinbuf + unit->m_bufsize;
3998 unit->m_xoutbuf = unit->m_xmidbuf + unit->m_bufsize;
3999 Normalizer_next(unit, 1);
4003 void Normalizer_next(Normalizer* unit, int inNumSamples)
4005 float *out = ZOUT(0);
4006 float *in = ZIN(0);
4007 float amp = ZIN0(1);
4009 long pos = unit->m_pos;
4010 float slope = unit->m_slope;
4011 float level = unit->m_level;
4012 float curmaxval = unit->m_curmaxval;
4013 float val;
4015 long bufsize = unit->m_bufsize;
4016 long buf_remain = bufsize - pos;
4018 long remain = inNumSamples;
4019 while (remain > 0) {
4020 long nsmps = sc_min(remain, buf_remain);
4021 float* xinbuf = unit->m_xinbuf + pos;
4022 float* xoutbuf = unit->m_xoutbuf + pos;
4023 if (unit->m_flips >= 2) {
4024 LOOP(nsmps,
4025 ZXP(xinbuf) = val = ZXP(in);
4026 ZXP(out) = level * ZXP(xoutbuf);
4027 level += slope;
4028 val = std::abs(val);
4029 if (val > curmaxval) curmaxval = val;
4031 } else {
4032 LOOP(nsmps,
4033 ZXP(xinbuf) = val = ZXP(in);
4034 ZXP(out) = 0.f;
4035 level += slope;
4036 val = std::abs(val);
4037 if (val > curmaxval) curmaxval = val;
4040 pos += nsmps;
4041 if (pos >= bufsize) {
4042 pos = 0;
4043 buf_remain = bufsize;
4045 float maxval2 = sc_max(unit->m_prevmaxval, curmaxval);
4046 unit->m_prevmaxval = curmaxval;
4047 unit->m_curmaxval = curmaxval = 0.f;
4049 float next_level;
4050 if (maxval2 <= 0.00001f) next_level = 100000.f * amp;
4051 else next_level = amp / maxval2;
4053 slope = unit->m_slope = (next_level - level) * unit->m_slopefactor;
4055 float* temp = unit->m_xoutbuf;
4056 unit->m_xoutbuf = unit->m_xmidbuf;
4057 unit->m_xmidbuf = unit->m_xinbuf;
4058 unit->m_xinbuf = temp;
4060 unit->m_flips++;
4062 remain -= nsmps;
4065 unit->m_pos = pos;
4066 unit->m_level = level;
4067 unit->m_curmaxval = curmaxval;
4070 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4072 void Limiter_Dtor(Limiter* unit)
4074 RTFree(unit->mWorld, unit->m_table);
4077 void Limiter_Ctor(Limiter* unit)
4079 //printf("Limiter_Reset\n");
4080 SETCALC(Limiter_next);
4082 float dur = ZIN0(2);
4083 unit->m_bufsize = (long)(ceil(dur * SAMPLERATE));
4084 long allocsize = unit->m_bufsize * 3;
4085 allocsize = NEXTPOWEROFTWO(allocsize);
4087 unit->m_table = (float*)RTAlloc(unit->mWorld, allocsize * sizeof(float));
4089 unit->m_flips = 0;
4090 unit->m_pos = 0;
4091 unit->m_slope = 0.f;
4092 unit->m_level = 1.f;
4093 unit->m_prevmaxval = 0.0;
4094 unit->m_curmaxval = 0.0;
4095 unit->m_slopefactor = 1.f / unit->m_bufsize;
4097 unit->m_xinbuf = unit->m_table - ZOFF;
4098 unit->m_xmidbuf = unit->m_xinbuf + unit->m_bufsize;
4099 unit->m_xoutbuf = unit->m_xmidbuf + unit->m_bufsize;
4100 Limiter_next(unit, 1);
4104 void Limiter_next(Limiter* unit, int inNumSamples)
4106 float *out = ZOUT(0);
4107 float *in = ZIN(0);
4108 float amp = ZIN0(1);
4110 long pos = unit->m_pos;
4111 float slope = unit->m_slope;
4112 float level = unit->m_level;
4113 float curmaxval = unit->m_curmaxval;
4114 float val;
4116 long bufsize = unit->m_bufsize;
4117 long buf_remain = bufsize - pos;
4119 long remain = inNumSamples;
4120 while (remain > 0) {
4121 long nsmps = sc_min(remain, buf_remain);
4122 float* xinbuf = unit->m_xinbuf + pos;
4123 float* xoutbuf = unit->m_xoutbuf + pos;
4124 if (unit->m_flips >= 2) {
4125 LOOP(nsmps,
4126 ZXP(xinbuf) = val = ZXP(in);
4127 ZXP(out) = level * ZXP(xoutbuf);
4128 level += slope;
4129 val = std::abs(val);
4130 if (val > curmaxval) curmaxval = val;
4132 } else {
4133 LOOP(nsmps,
4134 ZXP(xinbuf) = val = ZXP(in);
4135 ZXP(out) = 0.f;
4136 level += slope;
4137 val = std::abs(val);
4138 if (val > curmaxval) curmaxval = val;
4141 pos += nsmps;
4142 if (pos >= bufsize) {
4143 pos = 0;
4144 buf_remain = bufsize;
4146 float maxval2 = sc_max(unit->m_prevmaxval, curmaxval);
4147 unit->m_prevmaxval = curmaxval;
4148 unit->m_curmaxval = curmaxval = 0.f;
4150 float next_level;
4151 if (maxval2 > amp) next_level = amp / maxval2;
4152 else next_level = 1.0;
4154 slope = unit->m_slope = (next_level - level) * unit->m_slopefactor;
4156 float* temp = unit->m_xoutbuf;
4157 unit->m_xoutbuf = unit->m_xmidbuf;
4158 unit->m_xmidbuf = unit->m_xinbuf;
4159 unit->m_xinbuf = temp;
4161 unit->m_flips++;
4163 remain -= nsmps;
4166 unit->m_pos = pos;
4167 unit->m_level = level;
4168 unit->m_curmaxval = curmaxval;
4171 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4173 void Amplitude_Ctor(Amplitude* unit)
4175 if(INRATE(1) != calc_ScalarRate || INRATE(2) != calc_ScalarRate) {
4176 if(INRATE(0) == calc_FullRate && unit->mCalcRate == calc_BufRate){
4177 SETCALC(Amplitude_next_atok_kk);
4178 } else {
4179 SETCALC(Amplitude_next_kk);
4182 } else {
4183 if(INRATE(0) == calc_FullRate && unit->mCalcRate == calc_BufRate){
4184 SETCALC(Amplitude_next_atok);
4185 } else {
4186 SETCALC(Amplitude_next);
4190 float clamp = ZIN0(1);
4191 unit->m_clampcoef = clamp == 0.0 ? 0.0 : exp(log1/(clamp * SAMPLERATE));
4193 float relax = ZIN0(2);
4194 unit->m_relaxcoef = relax == 0.0 ? 0.0 : exp(log1/(relax * SAMPLERATE));
4196 unit->m_previn = std::abs(ZIN0(0));
4197 Amplitude_next(unit, 1);
4200 void Amplitude_next(Amplitude* unit, int inNumSamples)
4202 float *out = ZOUT(0);
4203 float *in = ZIN(0);
4205 float relaxcoef = unit->m_relaxcoef;
4206 float clampcoef = unit->m_clampcoef;
4207 float previn = unit->m_previn;
4209 float val;
4210 LOOP1(inNumSamples,
4211 val = std::abs(ZXP(in));
4212 if (val < previn) {
4213 val = val + (previn - val) * relaxcoef;
4214 } else {
4215 val = val + (previn - val) * clampcoef;
4217 ZXP(out) = previn = val;
4220 unit->m_previn = previn;
4223 void Amplitude_next_atok(Amplitude* unit, int inNumSamples)
4225 float *in = ZIN(0);
4227 float relaxcoef = unit->m_relaxcoef;
4228 float clampcoef = unit->m_clampcoef;
4229 float previn = unit->m_previn;
4231 float val;
4232 LOOP1(FULLBUFLENGTH,
4233 val = std::abs(ZXP(in));
4234 if (val < previn) {
4235 val = val + (previn - val) * relaxcoef;
4236 } else {
4237 val = val + (previn - val) * clampcoef;
4239 previn = val;
4241 ZOUT0(0) = val;
4243 unit->m_previn = previn;
4246 void Amplitude_next_kk(Amplitude* unit, int inNumSamples)
4248 float *out = ZOUT(0);
4249 float *in = ZIN(0);
4250 float relaxcoef, clampcoef;
4252 if(ZIN0(1) != unit->m_clamp_in) {
4253 clampcoef = unit->m_clampcoef = exp(log1/(ZIN0(1) * SAMPLERATE));
4254 unit->m_clamp_in = ZIN0(1);
4255 } else {
4256 clampcoef = unit->m_clampcoef;
4259 if(ZIN0(2) != unit->m_relax_in) {
4260 relaxcoef = unit->m_relaxcoef = exp(log1/(ZIN0(2) * SAMPLERATE));
4261 unit->m_relax_in = ZIN0(2);
4262 } else {
4263 relaxcoef = unit->m_relaxcoef;
4266 float previn = unit->m_previn;
4268 float val;
4269 LOOP1(inNumSamples,
4270 val = std::abs(ZXP(in));
4271 if (val < previn) {
4272 val = val + (previn - val) * relaxcoef;
4273 } else {
4274 val = val + (previn - val) * clampcoef;
4276 ZXP(out) = previn = val;
4279 unit->m_previn = previn;
4282 void Amplitude_next_atok_kk(Amplitude* unit, int inNumSamples)
4284 float *in = ZIN(0);
4285 float relaxcoef, clampcoef;
4287 if(ZIN0(1) != unit->m_clamp_in) {
4288 clampcoef = unit->m_clampcoef = exp(log1/(ZIN0(1) * SAMPLERATE));
4289 unit->m_clamp_in = ZIN0(1);
4290 } else {
4291 clampcoef = unit->m_clampcoef;
4294 if(ZIN0(2) != unit->m_relax_in) {
4295 relaxcoef = unit->m_relaxcoef = exp(log1/(ZIN0(2) * SAMPLERATE));
4296 unit->m_relax_in = ZIN0(2);
4297 } else {
4298 relaxcoef = unit->m_relaxcoef;
4301 float previn = unit->m_previn;
4303 float val;
4304 LOOP1(FULLBUFLENGTH,
4305 val = std::abs(ZXP(in));
4306 if (val < previn) {
4307 val = val + (previn - val) * relaxcoef;
4308 } else {
4309 val = val + (previn - val) * clampcoef;
4311 previn = val;
4313 ZOUT0(0) = val;
4315 unit->m_previn = previn;
4318 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4320 void DetectSilence_Ctor(DetectSilence* unit)
4322 //printf("DetectSilence_Reset\n");
4323 SETCALC(DetectSilence_next);
4325 unit->mThresh = ZIN0(1);
4326 unit->mEndCounter = (int32)(SAMPLERATE * ZIN0(2));
4327 unit->mCounter = -1;
4331 void DetectSilence_next(DetectSilence* unit, int inNumSamples)
4333 float thresh = unit->mThresh;
4334 int counter = unit->mCounter;
4335 float val;
4337 // I thought of a better way to do this...
4339 for (int i=0; i<inNumSamples; ++i) {
4340 float val = std::abs(ZXP(in));
4341 if (val >= thresh) counter = 0;
4342 else if (counter >= 0) {
4343 if (++counter >= unit->mEndCounter && doneAction) {
4344 int doneAction = (int)ZIN0(3);
4345 DoneAction(doneAction, unit);
4346 SETCALC(DetectSilence_done);
4349 ZXP(out) = 0.f;
4352 float *in = IN(0);
4353 float *out = OUT(0);
4354 for (int i=0; i<inNumSamples; ++i) {
4355 val = std::abs(*in++);
4356 if (val > thresh) {
4357 counter = 0;
4358 *out++ = 0.f;
4359 } else if (counter >= 0) {
4360 if (++counter >= unit->mEndCounter) {
4361 int doneAction = (int)ZIN0(3);
4362 DoneAction(doneAction, unit);
4363 *out++ = 1.f;
4364 // SETCALC(DetectSilence_done);
4365 } else {
4366 *out++ = 0.f;
4369 else
4370 *out++ = 0.f;
4372 unit->mCounter = counter;
4375 void DetectSilence_done(DetectSilence* unit, int inNumSamples)
4378 ///////////////////////////////////////////////////////////////////////////////////////////////////////
4379 // Based on HilbertIIR from SC2
4380 // a 12 pole (6 per side) Hilbert IIR filter
4381 // based on Sean Costello and Bernie Hutchins
4382 // created by jl anderson - 7 jan 2001
4383 // UGen created by Josh Parmenter
4385 #define HILBERT_FILTER \
4386 y0_1 = thisin - (coefs[0]) * y1[0]; \
4387 ay1 = coefs[0] * y0_1 + 1 * y1[0]; \
4388 y1[0] = y0_1; \
4389 y0_2 = ay1 - (coefs[1]) * y1[1]; \
4390 ay2 = coefs[1] * y0_2 + 1 * y1[1]; \
4391 y1[1] = y0_2; \
4392 y0_3 = ay2 - (coefs[2]) * y1[2]; \
4393 ay3 = coefs[2] * y0_3 + 1 * y1[2]; \
4394 y1[2] = y0_3; \
4395 y0_4 = ay3 - (coefs[3]) * y1[3]; \
4396 ay4 =coefs[3] * y0_4 + 1 * y1[3]; \
4397 y1[3] = y0_4; \
4398 y0_5 = ay4 - (coefs[4]) * y1[4]; \
4399 ay5 = coefs[4] * y0_5 + 1 * y1[4]; \
4400 y1[4] = y0_5; \
4401 y0_6 = ay5 - (coefs[5]) * y1[5]; \
4402 ay6 = coefs[5] * y0_6 + 1 * y1[5]; \
4403 y1[5] = y0_6; \
4405 y0_7 = thisin - (coefs[6]) * y1[6]; \
4406 ay7 = coefs[6] * y0_7 + 1 * y1[6]; \
4407 y1[6] = y0_7; \
4408 y0_8 = ay7 - (coefs[7]) * y1[7]; \
4409 ay8 = coefs[7] * y0_8 + 1 * y1[7]; \
4410 y1[7] = y0_8; \
4411 y0_9 = ay8 - (coefs[8]) * y1[8]; \
4412 ay9 = coefs[8] * y0_9 + 1 * y1[8]; \
4413 y1[8] = y0_9; \
4414 y0_10 = ay9 - (coefs[9]) * y1[9]; \
4415 ay10 = coefs[9] * y0_10 + 1 * y1[9]; \
4416 y1[9] = y0_10; \
4417 y0_11 = ay10 - (coefs[10]) * y1[10]; \
4418 ay11 = coefs[10] * y0_11 + 1 * y1[10]; \
4419 y1[10] = y0_11; \
4420 y0_12 = ay11 - (coefs[11]) * y1[11]; \
4421 ay12 = coefs[11] * y0_12 + 1 * y1[11]; \
4422 y1[11] = y0_12; \
4425 void Hilbert_Ctor(Hilbert *unit)
4427 // calculate coefs based on SampleRate, store in the struct
4428 SETCALC(Hilbert_next);
4430 float gamconst = (15.0f * pi_f) / SAMPLERATE;
4431 float gamma01 = gamconst * 0.3609f;
4432 float gamma02 = gamconst * 2.7412f;
4433 float gamma03 = gamconst * 11.1573f;
4434 float gamma04 = gamconst * 44.7581f;
4435 float gamma05 = gamconst * 179.6242f;
4436 float gamma06 = gamconst * 798.4578f;
4437 float gamma07 = gamconst * 1.2524f;
4438 float gamma08 = gamconst * 5.5671f;
4439 float gamma09 = gamconst * 22.3423f;
4440 float gamma10 = gamconst * 89.6271f;
4441 float gamma11 = gamconst * 364.7914f;
4442 float gamma12 = gamconst * 2770.1114f;
4443 unit->m_coefs[0] = (gamma01 - 1.f) / (gamma01 + 1.f);
4444 unit->m_coefs[1] = (gamma02 - 1.f) / (gamma02 + 1.f);
4445 unit->m_coefs[2] = (gamma03 - 1.f) / (gamma03 + 1.f);
4446 unit->m_coefs[3] = (gamma04 - 1.f) / (gamma04 + 1.f);
4447 unit->m_coefs[4] = (gamma05 - 1.f) / (gamma05 + 1.f);
4448 unit->m_coefs[5] = (gamma06 - 1.f) / (gamma06 + 1.f);
4449 unit->m_coefs[6] = (gamma07 - 1.f) / (gamma07 + 1.f);
4450 unit->m_coefs[7] = (gamma08 - 1.f) / (gamma08 + 1.f);
4451 unit->m_coefs[8] = (gamma09 - 1.f) / (gamma09 + 1.f);
4452 unit->m_coefs[9] = (gamma10 - 1.f) / (gamma10 + 1.f);
4453 unit->m_coefs[10] = (gamma11 - 1.f) / (gamma11 + 1.f);
4454 unit->m_coefs[11] = (gamma12 - 1.f) / (gamma12 + 1.f);
4455 Clear(12, unit->m_y1);
4456 Hilbert_next(unit, 1);
4459 void Hilbert_next(Hilbert *unit, int inNumSamples)
4461 float *in = ZIN(0);
4462 float *outcos = ZOUT(0);
4463 float *outsin = ZOUT(1);
4464 float y1[12];
4465 float coefs[12];
4467 // each filter's last sample
4468 for(int i = 0; i < 12; ++i){
4469 y1[i] = unit->m_y1[i];
4470 coefs[i] = unit->m_coefs[i];
4473 float ay1, ay2, ay3, ay4, ay5, ay6;
4474 float ay7, ay8, ay9, ay10, ay11, ay12;
4476 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4477 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4479 LOOP1(inNumSamples,
4480 float thisin = ZXP(in);
4482 HILBERT_FILTER
4483 ZXP(outcos) = ay6;
4484 ZXP(outsin) = ay12;
4487 for(int i = 0; i < 12; ++i)
4488 unit->m_y1[i] = zapgremlins(y1[i]);
4492 /* Hilbert based SSB FreqShifter */
4494 void FreqShift_Ctor(FreqShift *unit)
4496 // calculate coefs based on SampleRate, store in the struct
4497 // SETCALC(FreqShift_next_kk);
4498 unit->m_phase = 0;
4499 if(INRATE(1) == calc_FullRate) {
4500 if(INRATE(2) == calc_FullRate)
4501 SETCALC(FreqShift_next_aa);
4502 else
4503 SETCALC(FreqShift_next_ak);
4504 } else {
4505 if(INRATE(2) == calc_FullRate)
4506 SETCALC(FreqShift_next_ka);
4507 else {
4508 SETCALC(FreqShift_next_kk);
4509 unit->m_phase = (int32)(unit->m_radtoinc * IN0(2));
4512 // set up for the oscil for the modualtion
4514 int tableSizeSin = ft->mSineSize;
4515 unit->m_lomask = (tableSizeSin - 1) << 3;
4516 unit->m_radtoinc = tableSizeSin * (rtwopi * 65536.);
4517 unit->m_cpstoinc = tableSizeSin * SAMPLEDUR * 65536.;
4518 unit->m_phasein = IN0(2);
4520 float gamconst = (15.0 * pi) / SAMPLERATE;
4521 float gamma01 = gamconst * 0.3609f;
4522 float gamma02 = gamconst * 2.7412f;
4523 float gamma03 = gamconst * 11.1573f;
4524 float gamma04 = gamconst * 44.7581f;
4525 float gamma05 = gamconst * 179.6242f;
4526 float gamma06 = gamconst * 798.4578f;
4527 float gamma07 = gamconst * 1.2524f;
4528 float gamma08 = gamconst * 5.5671f;
4529 float gamma09 = gamconst * 22.3423f;
4530 float gamma10 = gamconst * 89.6271f;
4531 float gamma11 = gamconst * 364.7914f;
4532 float gamma12 = gamconst * 2770.1114f;
4533 unit->m_coefs[0] = (gamma01 - 1.f) / (gamma01 + 1.f);
4534 unit->m_coefs[1] = (gamma02 - 1.f) / (gamma02 + 1.f);
4535 unit->m_coefs[2] = (gamma03 - 1.f) / (gamma03 + 1.f);
4536 unit->m_coefs[3] = (gamma04 - 1.f) / (gamma04 + 1.f);
4537 unit->m_coefs[4] = (gamma05 - 1.f) / (gamma05 + 1.f);
4538 unit->m_coefs[5] = (gamma06 - 1.f) / (gamma06 + 1.f);
4539 unit->m_coefs[6] = (gamma07 - 1.f) / (gamma07 + 1.f);
4540 unit->m_coefs[7] = (gamma08 - 1.f) / (gamma08 + 1.f);
4541 unit->m_coefs[8] = (gamma09 - 1.f) / (gamma09 + 1.f);
4542 unit->m_coefs[9] = (gamma10 - 1.f) / (gamma10 + 1.f);
4543 unit->m_coefs[10] = (gamma11 - 1.f) / (gamma11 + 1.f);
4544 unit->m_coefs[11] = (gamma12 - 1.f) / (gamma12 + 1.f);
4546 Clear(12, unit->m_y1);
4547 FreqShift_next_kk(unit, 1);
4550 void FreqShift_next_kk(FreqShift *unit, int inNumSamples)
4552 float *in = ZIN(0);
4553 float *out = ZOUT(0);
4554 float phasein = ZIN0(2);
4555 float freqin = ZIN0(1);
4556 float outcos, outsin; // the sample by sample output of the Hilbert
4557 float outsinosc, outsinoscHalfPi; // the samples from the oscil.
4558 int32 halfPi = (int32)(unit->m_radtoinc * (0.5 * pi));
4559 float y1[12];
4560 float coefs[12];
4562 float *table0 = ft->mSineWavetable;
4563 float *table1 = table0 + 1;
4564 int32 lomask = unit->m_lomask;
4565 int32 phase = unit->m_phase;
4567 int32 freq = (int32)(unit->m_cpstoinc * freqin);
4568 int32 phaseinc = freq + (int32)(CALCSLOPE(phasein, unit->m_phasein) * unit->m_radtoinc);
4569 unit->m_phasein = phasein;
4571 // each filter's last sample
4572 for(int i = 0; i < 12; ++i) {
4573 y1[i] = unit->m_y1[i];
4574 coefs[i] = unit->m_coefs[i];
4577 float ay1, ay2, ay3, ay4, ay5, ay6;
4578 float ay7, ay8, ay9, ay10, ay11, ay12;
4580 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4581 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4583 LOOP1(inNumSamples,
4584 float thisin = ZXP(in);
4586 HILBERT_FILTER
4588 outcos = ay6;
4589 outsin = ay12;
4591 outsinosc = lookupi1(table0, table1, phase, lomask);
4592 outsinoscHalfPi = lookupi1(table0, table1, phase + halfPi, lomask);
4594 ZXP(out) = (outcos * outsinoscHalfPi) + (outsinosc * outsin);
4596 phase += phaseinc;
4599 unit->m_phase = phase;
4601 for(int i = 0; i < 12; ++i)
4602 unit->m_y1[i] = zapgremlins(y1[i]);
4605 void FreqShift_next_aa(FreqShift *unit, int inNumSamples)
4607 float *in = ZIN(0);
4608 float *out = ZOUT(0);
4609 float *phasein = ZIN(2);
4610 float *freqin = ZIN(1);
4611 float outcos, outsin; // the sample by sample output of the Hilbert
4612 float outsinosc, outsinoscHalfPi; // the samples from the oscil.
4613 int32 halfPi = (int32)(unit->m_radtoinc * (0.5 * pi));
4614 float y1[12];
4615 float coefs[12];
4617 float *table0 = ft->mSineWavetable;
4618 float *table1 = table0 + 1;
4619 int32 lomask = unit->m_lomask;
4620 int32 phase = unit->m_phase;
4622 // each filter's last sample
4623 for(int i = 0; i < 12; ++i){
4624 y1[i] = unit->m_y1[i];
4625 coefs[i] = unit->m_coefs[i];
4628 float ay1, ay2, ay3, ay4, ay5, ay6;
4629 float ay7, ay8, ay9, ay10, ay11, ay12;
4631 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4632 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4634 LOOP1(inNumSamples,
4635 float thisin = ZXP(in);
4637 HILBERT_FILTER
4639 outcos = ay6;
4640 outsin = ay12;
4642 int32 phaseoffset = phase + (int32)(unit->m_radtoinc * ZXP(phasein));
4643 outsinosc = lookupi1(table0, table1, phaseoffset, lomask);
4644 outsinoscHalfPi = lookupi1(table0, table1, phaseoffset + halfPi, lomask);
4645 phase += (int32)(unit->m_cpstoinc * ZXP(freqin));
4647 ZXP(out) = (outcos * outsinoscHalfPi) + (outsinosc * outsin);
4650 unit->m_phase = phase;
4652 for(int i = 0; i < 12; ++i)
4653 unit->m_y1[i] = zapgremlins(y1[i]);
4656 void FreqShift_next_ak(FreqShift *unit, int inNumSamples)
4658 float *in = ZIN(0);
4659 float *out = ZOUT(0);
4660 float phasein = ZIN0(2);
4661 float *freqin = ZIN(1);
4662 float outcos, outsin; // the sample by sample output of the Hilbert
4663 float outsinosc, outsinoscHalfPi; // the samples from the oscil.
4664 int32 halfPi = (int32)(unit->m_radtoinc * (0.5 * pi));
4665 float y1[12];
4666 float coefs[12];
4668 float *table0 = ft->mSineWavetable;
4669 float *table1 = table0 + 1;
4670 int32 lomask = unit->m_lomask;
4671 int32 phase = unit->m_phase;
4672 float phasemod = unit->m_phasein;
4673 float phaseslope = CALCSLOPE(phasein, phasemod);
4675 // each filter's last sample
4676 for(int i = 0; i < 12; ++i) {
4677 y1[i] = unit->m_y1[i];
4678 coefs[i] = unit->m_coefs[i];
4681 float ay1, ay2, ay3, ay4, ay5, ay6;
4682 float ay7, ay8, ay9, ay10, ay11, ay12;
4684 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4685 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4687 LOOP1(inNumSamples,
4688 float thisin = ZXP(in);
4690 HILBERT_FILTER
4692 outcos = ay6;
4693 outsin = ay12;
4695 int32 pphase = phase + (int32)(unit->m_radtoinc * phasemod);
4696 phasemod += phaseslope;
4697 outsinosc = lookupi1(table0, table1, pphase, lomask);
4698 outsinoscHalfPi = lookupi1(table0, table1, pphase + halfPi, lomask);
4699 phase += (int32)(unit->m_cpstoinc * ZXP(freqin));
4701 ZXP(out) = (outcos * outsinoscHalfPi) + (outsinosc * outsin);
4704 unit->m_phase = phase;
4705 unit->m_phasein = phasein;
4707 for(int i = 0; i < 12; ++i)
4708 unit->m_y1[i] = zapgremlins(y1[i]);
4711 void FreqShift_next_ka(FreqShift *unit, int inNumSamples)
4713 float *in = ZIN(0);
4714 float *out = ZOUT(0);
4715 float *phasein = ZIN(2);
4716 float freqin = ZIN0(1);
4717 float outcos, outsin; // the sample by sample output of the Hilbert
4718 float outsinosc, outsinoscHalfPi; // the samples from the oscil.
4719 int32 halfPi = (int32)(unit->m_radtoinc * (0.5 * pi));
4720 float y1[12];
4721 float coefs[12];
4723 float *table0 = ft->mSineWavetable;
4724 float *table1 = table0 + 1;
4725 int32 lomask = unit->m_lomask;
4726 int32 phase = unit->m_phase;
4727 float phasemod = unit->m_phasein;
4729 int32 freq = (int32)(unit->m_cpstoinc * freqin);
4731 // each filter's last sample
4732 for(int i = 0; i < 12; ++i) {
4733 y1[i] = unit->m_y1[i];
4734 coefs[i] = unit->m_coefs[i];
4737 float ay1, ay2, ay3, ay4, ay5, ay6;
4738 float ay7, ay8, ay9, ay10, ay11, ay12;
4740 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4741 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4743 LOOP1(inNumSamples,
4744 float thisin = ZXP(in);
4746 HILBERT_FILTER
4748 outcos = ay6;
4749 outsin = ay12;
4751 int32 phaseoffset = phase + (int32)(unit->m_radtoinc * ZXP(phasein));
4752 outsinosc = lookupi1(table0, table1, phaseoffset, lomask);
4753 outsinoscHalfPi = lookupi1(table0, table1, phaseoffset + halfPi, lomask);
4754 phase += freq;
4756 ZXP(out) = (outcos * outsinoscHalfPi) + (outsinosc * outsin);
4759 unit->m_phase = phase;
4761 for(int i = 0; i < 12; ++i)
4762 unit->m_y1[i] = zapgremlins(y1[i]);
4767 "MoogFF" - Moog VCF digital implementation.
4768 As described in the paper entitled
4769 "Preserving the Digital Structure of the Moog VCF"
4770 by Federico Fontana
4771 appeared in the Proc. ICMC07, Copenhagen, 25-31 August 2007
4773 Original Java code Copyright F. Fontana - August 2007
4774 federico.fontana@univr.it
4776 Ported to C++ for SuperCollider by Dan Stowell - August 2007
4777 http://www.mcld.co.uk/
4779 This program is free software; you can redistribute it and/or modify
4780 it under the terms of the GNU General Public License as published by
4781 the Free Software Foundation; either version 2 of the License, or
4782 (at your option) any later version.
4784 This program is distributed in the hope that it will be useful,
4785 but WITHOUT ANY WARRANTY; without even the implied warranty of
4786 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4787 GNU General Public License for more details.
4789 You should have received a copy of the GNU General Public License
4790 along with this program; if not, write to the Free Software
4791 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4793 //////////////////////////////////////////////////////////////////
4795 void MoogFF_Ctor(MoogFF* unit)
4797 SETCALC(MoogFF_next);
4799 // initialize the unit generator state variables.
4800 unit->m_freq = -10000.3f; // Force the freq to update on first run
4801 unit->m_s1 = 0.f;
4802 unit->m_s2 = 0.f;
4803 unit->m_s3 = 0.f;
4804 unit->m_s4 = 0.f;
4806 // calculate one sample of output.
4807 MoogFF_next(unit, 1);
4810 void MoogFF_next(MoogFF *unit, int inNumSamples)
4812 float *out = ZOUT(0);
4814 float *in = ZIN(0);
4815 float k = IN0(2);
4816 k = k > 4.f? 4.f : (k<0.f ? 0.f : k);
4818 // Load state from the struct
4819 float s1 = unit->m_s1;
4820 float s2 = unit->m_s2;
4821 float s3 = unit->m_s3;
4822 float s4 = unit->m_s4;
4823 float freq = unit->m_freq;///
4825 // Reset filter state if requested
4826 if(IN0(3)>0)
4827 s1 = s2 = s3 = s4 = 0.f;
4829 float a1 = unit->m_a1, b0 = unit->m_b0; // Filter coefficient parameters
4830 float o, u; // System's null response, loop input
4832 // Update filter coefficients, but only if freq changes since it involves some expensive operations
4833 if(freq != IN0(1)) {
4834 freq = IN0(1);
4835 //Print("Updated freq to %g\n", freq);
4836 double wcD=unit->m_wcD;
4837 double T = SAMPLEDUR;
4838 wcD = 2.0 * tan ( T * PI * freq ) * SAMPLERATE;
4839 if(wcD<0)
4840 wcD = 0; // Protect against negative cutoff freq
4841 double TwcD = T*wcD;
4842 b0 = (float)(TwcD/(TwcD + 2.));
4843 a1 = (float)((TwcD - 2.)/(TwcD + 2.));
4844 unit->m_freq = freq;
4845 unit->m_b0 = b0;
4846 unit->m_a1 = a1;
4847 unit->m_wcD = wcD;
4850 LOOP1(inNumSamples,
4851 // compute loop values
4852 o = s4 + b0*(s3 + b0*(s2 + b0*s1));
4853 float ins = ZXP(in);
4854 float outs = (b0*b0*b0*b0*ins + o)/(1.f + b0*b0*b0*b0*k);
4855 ZXP(out) = outs;
4856 u = ins - k*outs;
4858 // update 1st order filter states
4859 float past = u;
4860 float future = b0*past + s1;
4861 s1 = b0*past - a1*future;
4863 past = future;
4864 future = b0*past + s2;
4865 s2 = b0*past - a1*future;
4867 past = future;
4868 future = b0*past + s3;
4869 s3 = b0*past - a1*future;
4871 s4 = b0*future - a1*outs;
4874 // Store state
4875 unit->m_s1 = s1;
4876 unit->m_s2 = s2;
4877 unit->m_s3 = s3;
4878 unit->m_s4 = s4;
4881 /* BEQSuite */
4884 struct BLowPass : public Unit
4886 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
4887 float m_freq, m_rq;
4890 extern "C"
4892 void BLowPass_next_kk(BLowPass *unit, int inNumSamples);
4893 void BLowPass_next_aa(BLowPass *unit, int inNumSamples);
4894 void BLowPass_Ctor(BLowPass* unit);
4898 void BLowPass_Ctor(BLowPass* unit)
4900 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
4901 SETCALC(BLowPass_next_aa);
4902 else
4903 SETCALC(BLowPass_next_kk);
4904 float rq = unit->m_rq = ZIN0(2);
4905 float freq = unit->m_freq = ZIN0(1);
4906 double w0 = twopi * (double)freq * SAMPLEDUR;
4907 double cosw0 = cos(w0);
4908 double i = 1. - cosw0;
4909 double alpha = sin(w0) * 0.5 * (double)rq;
4910 double b0rz = 1. / (1. + alpha);
4911 double a0 = unit->m_a0 = i * 0.5 * b0rz;
4912 unit->m_a1 = i * b0rz;
4913 unit->m_a2 = a0;
4914 unit->m_b1 = cosw0 * 2. * b0rz;
4915 unit->m_b2 = (1. - alpha) * -b0rz;
4916 unit->m_y1 = 0.;
4918 unit->m_y2 = 0.;
4919 PUSH_LOOPVALS
4920 BLowPass_next_kk(unit, 1);
4921 POP_LOOPVALS
4924 void BLowPass_next_aa(BLowPass *unit, int inNumSamples)
4926 float *out = ZOUT(0);
4927 float *in = ZIN(0);
4928 float *freq = ZIN(1);
4929 float *rq = ZIN(2);
4931 double a0, a1, a2, b1, b2, w0, cosw0, i, alpha, b0rz;
4932 double y0, y1, y2;
4933 float nextfreq, nextrq;
4935 y1 = unit->m_y1;
4936 y2 = unit->m_y2;
4938 a0 = unit->m_a0;
4939 a1 = unit->m_a1;
4940 a2 = unit->m_a2;
4941 b1 = unit->m_b1;
4942 b2 = unit->m_b2;
4944 LOOP(unit->mRate->mFilterLoops,
4945 nextfreq = ZXP(freq);
4946 nextrq = ZXP(rq);
4947 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)) {
4948 w0 = twopi * (double)nextfreq * SAMPLEDUR;
4949 cosw0 = cos(w0);
4950 i = 1. - cosw0;
4951 alpha = sin(w0) * 0.5 * (double)nextrq;
4952 b0rz = 1. / (1. + alpha);
4953 a0 = i * 0.5 * b0rz;
4954 a1 = i * b0rz;
4955 a2 = a0;
4956 b1 = cosw0 * 2. * b0rz;
4957 b2 = (1. - alpha) * -b0rz;
4958 unit->m_freq = nextfreq;
4959 unit->m_rq = nextrq;
4961 y0 = ZXP(in) + b1 * y1 + b2 * y2;
4962 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
4964 y2 = ZXP(in) + b1 * y0 + b2 * y1;
4965 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
4967 y1 = ZXP(in) + b1 * y2 + b2 * y0;
4968 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
4971 LOOP(unit->mRate->mFilterRemain,
4972 y0 = ZXP(in) + b1 * y1 + b2 * y2;
4973 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
4974 y2 = y1;
4975 y1 = y0;
4976 unit->m_freq = ZXP(freq);
4977 unit->m_rq = ZXP(rq);
4980 unit->m_a0 = a0;
4981 unit->m_a1 = a1;
4982 unit->m_a2 = a2;
4983 unit->m_b1 = b1;
4984 unit->m_b2 = b2;
4985 unit->m_y1 = zapgremlins(y1);
4986 unit->m_y2 = zapgremlins(y2);
4990 void BLowPass_next_kk(BLowPass *unit, int inNumSamples)
4992 float *out = ZOUT(0);
4993 float *in = ZIN(0);
4994 float nextfreq = ZIN0(1);
4995 float nextrq = ZIN0(2);
4997 double a0, a1, a2, b1, b2;
4998 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextcosw0, nexti, nextalpha, nextb0rz;
4999 double y0;
5000 double y1 = unit->m_y1;
5001 double y2 = unit->m_y2;
5002 double a0slope, a1slope, a2slope, b1slope, b2slope;
5004 a0 = unit->m_a0;
5005 a1 = unit->m_a1;
5006 a2 = unit->m_a2;
5007 b1 = unit->m_b1;
5008 b2 = unit->m_b2;
5010 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)){
5011 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5012 nextcosw0 = cos(nextw0);
5013 nexti = 1. - nextcosw0;
5014 nextalpha = sin(nextw0) * 0.5 * (double)nextrq;
5015 nextb0rz = 1. / (1. + nextalpha);
5016 nexta0 = nexti * 0.5 * nextb0rz;
5017 nexta1 = nexti * nextb0rz;
5018 nexta2 = nexta0;
5019 nextb1 = nextcosw0 * 2. * nextb0rz;
5020 nextb2 = ((1. - nextalpha) * -nextb0rz);
5021 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope;
5022 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope;
5023 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope;
5024 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope;
5025 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope;
5026 unit->m_freq = nextfreq;
5027 unit->m_rq = nextrq;
5028 LOOP(unit->mRate->mFilterLoops,
5029 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5030 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5032 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5033 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5035 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5036 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5037 a0 += a0slope;
5038 a1 += a1slope;
5039 a2 += a2slope;
5040 b1 += b1slope;
5041 b2 += b2slope;
5043 LOOP(unit->mRate->mFilterRemain,
5044 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5045 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5046 y2 = y1;
5047 y1 = y0;
5050 } else {
5051 LOOP(unit->mRate->mFilterLoops,
5052 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5053 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5055 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5056 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5058 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5059 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5061 LOOP(unit->mRate->mFilterRemain,
5062 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5063 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5064 y2 = y1;
5065 y1 = y0;
5068 unit->m_y1 = zapgremlins(y1);
5069 unit->m_y2 = zapgremlins(y2);
5070 unit->m_a0 = a0;
5071 unit->m_a1 = a1;
5072 unit->m_a2 = a2;
5073 unit->m_b1 = b1;
5074 unit->m_b2 = b2;
5077 struct BHiPass : public Unit
5079 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5080 float m_freq, m_rq;
5084 extern "C"
5086 void BHiPass_next_kk(BHiPass *unit, int inNumSamples);
5087 void BHiPass_next_aa(BHiPass *unit, int inNumSamples);
5088 void BHiPass_Ctor(BHiPass* unit);
5091 void BHiPass_Ctor(BHiPass* unit)
5093 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
5094 SETCALC(BHiPass_next_aa);
5095 else
5096 SETCALC(BHiPass_next_kk);
5097 float freq = unit->m_freq = ZIN0(1);
5098 float rq = unit->m_rq = ZIN0(2);
5099 double w0 = twopi * (double)freq * SAMPLEDUR;
5100 double cosw0 = cos(w0);
5101 double i = 1. + cosw0;
5102 double alpha = sin(w0) * 0.5 * (double)rq;
5103 double b0rz = 1. / (1. + alpha);
5104 double a0 = unit->m_a0 = i * 0.5 * b0rz;
5105 unit->m_a1 = -i * b0rz;
5106 unit->m_a2 = a0;
5107 unit->m_b1 = cosw0 * 2. * b0rz;
5108 unit->m_b2 = (1. - alpha) * -b0rz;
5109 unit->m_y1 = 0.;
5111 unit->m_y2 = 0.;
5112 PUSH_LOOPVALS
5113 BHiPass_next_kk(unit, 1);
5114 POP_LOOPVALS
5117 void BHiPass_next_aa(BHiPass *unit, int inNumSamples)
5119 float *out = ZOUT(0);
5120 float *in = ZIN(0);
5121 float *freq = ZIN(1);
5122 float *rq = ZIN(2);
5124 double a0, a1, a2, b1, b2, w0, cosw0, i, alpha, b0rz;
5125 double y0, y1, y2;
5126 float nextfreq, nextrq;
5128 y1 = unit->m_y1;
5129 y2 = unit->m_y2;
5131 a0 = unit->m_a0;
5132 a1 = unit->m_a1;
5133 a2 = unit->m_a2;
5134 b1 = unit->m_b1;
5135 b2 = unit->m_b2;
5137 LOOP(unit->mRate->mFilterLoops,
5138 nextfreq = ZXP(freq);
5139 nextrq = ZXP(rq);
5140 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)) {
5141 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5142 cosw0 = cos(w0);
5143 i = 1. + cosw0;
5144 alpha = sin(w0) * 0.5 * (double)nextrq;
5145 b0rz = 1. / (1. + alpha);
5146 a0 = i * 0.5 * b0rz;
5147 a1 = -i * b0rz;
5148 a2 = a0;
5149 b1 = cosw0 * 2. * b0rz;
5150 b2 = (1. - alpha) * -b0rz;
5151 unit->m_freq = nextfreq;
5152 unit->m_rq = nextrq;
5154 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5155 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5157 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5158 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5160 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5161 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5163 LOOP(unit->mRate->mFilterRemain,
5164 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5165 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5166 y2 = y1;
5167 y1 = y0;
5170 unit->m_a0 = a0;
5171 unit->m_a1 = a1;
5172 unit->m_a2 = a2;
5173 unit->m_b1 = b1;
5174 unit->m_b2 = b2;
5175 unit->m_y1 = zapgremlins(y1);
5176 unit->m_y2 = zapgremlins(y2);
5180 void BHiPass_next_kk(BHiPass *unit, int inNumSamples)
5182 float *out = ZOUT(0);
5183 float *in = ZIN(0);
5184 float nextfreq = ZIN0(1);
5185 float nextrq = ZIN0(2);
5187 double a0, a1, a2, b1, b2;
5188 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextcosw0, nexti, nextalpha, nextb0rz;
5189 double y0;
5190 double y1 = unit->m_y1;
5191 double y2 = unit->m_y2;
5192 double a0slope, a1slope, a2slope, b1slope, b2slope;
5194 a0 = unit->m_a0;
5195 a1 = unit->m_a1;
5196 a2 = unit->m_a2;
5197 b1 = unit->m_b1;
5198 b2 = unit->m_b2;
5200 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)){
5201 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5202 nextcosw0 = cos(nextw0);
5203 nexti = 1. + nextcosw0;
5204 nextalpha = sin(nextw0) * 0.5 * (double)nextrq;
5205 nextb0rz = 1. / (1. + nextalpha);
5206 nexta0 = nexti * 0.5 * nextb0rz;
5207 nexta1 = -nexti * nextb0rz;
5208 nexta2 = nexta0;
5209 nextb1 = nextcosw0 * 2. * nextb0rz;
5210 nextb2 = (1. - nextalpha) * -nextb0rz;
5211 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
5212 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
5213 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
5214 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
5215 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
5217 LOOP(unit->mRate->mFilterLoops,
5218 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5219 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5221 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5222 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5224 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5225 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5226 a0 += a0slope;
5227 a1 += a1slope;
5228 a2 += a2slope;
5229 b1 += b1slope;
5230 b2 += b2slope;
5232 LOOP(unit->mRate->mFilterRemain,
5233 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5234 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5235 y2 = y1;
5236 y1 = y0;
5238 unit->m_freq = nextfreq;
5239 unit->m_rq = nextrq;
5240 unit->m_a0 = a0;
5241 unit->m_a1 = a1;
5242 unit->m_a2 = a2;
5243 unit->m_b1 = b1;
5244 unit->m_b2 = b2;
5246 } else {
5248 LOOP(unit->mRate->mFilterLoops,
5249 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5250 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5252 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5253 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5255 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5256 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5258 LOOP(unit->mRate->mFilterRemain,
5259 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5260 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5261 y2 = y1;
5262 y1 = y0;
5266 unit->m_y1 = zapgremlins(y1);
5267 unit->m_y2 = zapgremlins(y2);
5270 /* BBandPass */
5272 struct BBandPass : public Unit
5274 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5275 float m_freq, m_bw;
5278 extern "C"
5280 void BBandPass_next_kk(BBandPass *unit, int inNumSamples);
5281 void BBandPass_next_aa(BBandPass *unit, int inNumSamples);
5282 void BBandPass_Ctor(BBandPass* unit);
5285 void BBandPass_Ctor(BBandPass* unit)
5287 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
5288 SETCALC(BBandPass_next_aa);
5289 else
5290 SETCALC(BBandPass_next_kk);
5291 float freq = unit->m_freq = ZIN0(1);
5292 float bw = unit->m_bw = ZIN0(2);
5294 double w0 = twopi * (double)freq * SAMPLEDUR;
5295 double sinw0 = sin(w0);
5296 double alpha = sinw0 * (sinh((0.34657359027997 * (double)bw * w0) / sinw0));
5297 double b0rz = 1. / (1. + alpha);
5298 double a0 = unit->m_a0 = alpha * b0rz;
5299 unit->m_a1 = 0.0f;
5300 unit->m_a2 = -a0;
5301 unit->m_b1 = cos(w0) * 2. * b0rz;
5302 unit->m_b2 = (1. - alpha) * -b0rz;
5304 unit->m_y1 = 0.;
5306 unit->m_y2 = 0.;
5307 PUSH_LOOPVALS
5308 BBandPass_next_kk(unit, 1);
5309 POP_LOOPVALS
5312 void BBandPass_next_aa(BBandPass *unit, int inNumSamples)
5314 float *out = ZOUT(0);
5315 float *in = ZIN(0);
5316 float *freq = ZIN(1);
5317 float *bw = ZIN(2);
5319 double a0, a1, a2, b1, b2, w0, sinw0, alpha, b0rz;
5320 double y0, y1, y2;
5321 float nextfreq, nextbw;
5323 y1 = unit->m_y1;
5324 y2 = unit->m_y2;
5326 a0 = unit->m_a0;
5327 a1 = unit->m_a1;
5328 a2 = unit->m_a2;
5329 b1 = unit->m_b1;
5330 b2 = unit->m_b2;
5332 LOOP(unit->mRate->mFilterLoops,
5333 nextfreq = ZXP(freq);
5334 nextbw = ZXP(bw);
5335 if ((unit->m_freq != nextfreq) || (unit->m_bw != nextbw)) {
5336 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5337 sinw0 = sin(w0);
5338 alpha = sinw0 * (sinh((0.34657359027997 * (double)nextbw * w0) / sinw0));
5339 b0rz = 1. / (1. + alpha);
5340 a0 = alpha * b0rz;
5341 a1 = 0.0f;
5342 a2 = -a0;
5343 b1 = cos(w0) * 2. * b0rz;
5344 b2 = (1. - alpha) * -b0rz;
5345 unit->m_freq = ZXP(freq);
5346 unit->m_bw = ZXP(bw);
5348 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5349 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5351 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5352 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5354 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5355 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5357 LOOP(unit->mRate->mFilterRemain,
5358 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5359 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5360 y2 = y1;
5361 y1 = y0;
5362 unit->m_freq = nextfreq;
5363 unit->m_bw = nextbw;
5366 unit->m_a0 = a0;
5367 unit->m_a1 = a1;
5368 unit->m_a2 = a2;
5369 unit->m_b1 = b1;
5370 unit->m_b2 = b2;
5371 unit->m_y1 = zapgremlins(y1);
5372 unit->m_y2 = zapgremlins(y2);
5376 void BBandPass_next_kk(BBandPass *unit, int inNumSamples)
5378 float *out = ZOUT(0);
5379 float *in = ZIN(0);
5380 float nextfreq = ZIN0(1);
5381 float nextbw = ZIN0(2);
5383 double a0, a1, a2, b1, b2;
5384 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextalpha, nextb0rz;
5385 double y0;
5386 double y1 = unit->m_y1;
5387 double y2 = unit->m_y2;
5388 double a0slope, a1slope, a2slope, b1slope, b2slope;
5390 a0 = unit->m_a0;
5391 a1 = unit->m_a1;
5392 a2 = unit->m_a2;
5393 b1 = unit->m_b1;
5394 b2 = unit->m_b2;
5395 if ((unit->m_freq != nextfreq) || (unit->m_bw != nextbw)){
5396 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5397 nextalpha = sin(nextw0) * (sinh((0.34657359027997 * (double)nextbw * nextw0) / sin(nextw0)));
5398 nextb0rz = 1. / (1. + nextalpha);
5399 nexta0 = nextalpha * nextb0rz;
5400 nexta1 = 0.;
5401 nexta2 = -nexta0;
5402 nextb1 = cos(nextw0) * 2. * nextb0rz;
5403 nextb2 = ((1. - nextalpha) * -nextb0rz);
5404 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
5405 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
5406 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
5407 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
5408 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
5409 unit->m_freq = nextfreq;
5410 unit->m_bw = nextbw;
5411 LOOP(unit->mRate->mFilterLoops,
5412 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5413 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5415 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5416 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5418 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5419 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5420 a0 += a0slope;
5421 a1 += a1slope;
5422 a2 += a2slope;
5423 b1 += b1slope;
5424 b2 += b2slope;
5426 LOOP(unit->mRate->mFilterRemain,
5427 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5428 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5429 y2 = y1;
5430 y1 = y0;
5432 } else {
5433 LOOP(unit->mRate->mFilterLoops,
5434 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5435 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5437 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5438 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5440 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5441 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5443 LOOP(unit->mRate->mFilterRemain,
5444 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5445 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5446 y2 = y1;
5447 y1 = y0;
5451 unit->m_a0 = a0;
5452 unit->m_a1 = a1;
5453 unit->m_a2 = a2;
5454 unit->m_b1 = b1;
5455 unit->m_b2 = b2;
5456 unit->m_y1 = zapgremlins(y1);
5457 unit->m_y2 = zapgremlins(y2);
5460 /* BBandStop */
5461 struct BBandStop : public Unit
5463 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5464 float m_freq, m_bw;
5467 extern "C"
5469 void BBandStop_next_kk(BBandStop *unit, int inNumSamples);
5470 void BBandStop_next_aa(BBandStop *unit, int inNumSamples);
5471 void BBandStop_Ctor(BBandStop* unit);
5474 void BBandStop_Ctor(BBandStop* unit)
5476 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
5477 SETCALC(BBandStop_next_aa);
5478 else
5479 SETCALC(BBandStop_next_kk);
5480 float freq = unit->m_freq = ZIN0(1);
5481 float bw = unit->m_bw = ZIN0(2);
5483 double w0 = twopi * (double)freq * SAMPLEDUR;
5484 double sinw0 = sin(w0);
5485 double alpha = sinw0 * (sinh((0.34657359027997 * (double)bw * w0) / sinw0));
5486 double b0rz = 1. / (1. + alpha);
5487 double b1 = unit->m_b1 = 2. * b0rz * cos(w0);
5488 unit->m_a0 = b0rz;
5489 unit->m_a1 = -b1;
5490 unit->m_a2 = b0rz;
5491 unit->m_b2 = (1. - alpha) * -b0rz;
5493 unit->m_y1 = 0.;
5495 unit->m_y2 = 0.;
5496 PUSH_LOOPVALS
5497 BBandStop_next_kk(unit, 1);
5498 POP_LOOPVALS
5501 void BBandStop_next_aa(BBandStop *unit, int inNumSamples)
5503 float *out = ZOUT(0);
5504 float *in = ZIN(0);
5505 float *freq = ZIN(1);
5506 float *bw = ZIN(2);
5508 double a0, a1, a2, b1, b2, w0, sinw0, alpha, b0rz;
5509 double y0, y1, y2;
5510 float nextfreq, nextbw;
5512 y1 = unit->m_y1;
5513 y2 = unit->m_y2;
5515 a0 = unit->m_a0;
5516 a1 = unit->m_a1;
5517 a2 = unit->m_a2;
5518 b1 = unit->m_b1;
5519 b2 = unit->m_b2;
5521 LOOP(unit->mRate->mFilterLoops,
5522 nextfreq = ZXP(freq);
5523 nextbw = ZXP(bw);
5524 if ((unit->m_freq != nextfreq) || (unit->m_bw != nextbw)) {
5525 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5526 sinw0 = sin(w0);
5527 alpha = sinw0 * (sinh((0.34657359027997 * (double)nextbw * w0) / sinw0));
5528 b0rz = 1. / (1. + alpha);
5529 b1 = 2. * b0rz * cos(w0);
5530 a0 = b0rz;
5531 a1 = -b1;
5532 a2 = b0rz;
5533 b2 = (1. - alpha) * -b0rz;
5534 unit->m_freq = ZXP(freq);
5535 unit->m_bw = ZXP(bw);
5537 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5538 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5540 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5541 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5543 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5544 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5546 LOOP(unit->mRate->mFilterRemain,
5547 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5548 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5549 y2 = y1;
5550 y1 = y0;
5551 unit->m_freq = nextfreq;
5552 unit->m_bw = nextbw;
5555 unit->m_a0 = a0;
5556 unit->m_a1 = a1;
5557 unit->m_a2 = a2;
5558 unit->m_b1 = b1;
5559 unit->m_b2 = b2;
5560 unit->m_y1 = zapgremlins(y1);
5561 unit->m_y2 = zapgremlins(y2);
5565 void BBandStop_next_kk(BBandStop *unit, int inNumSamples)
5567 float *out = ZOUT(0);
5568 float *in = ZIN(0);
5569 float nextfreq = ZIN0(1);
5570 float nextbw = ZIN0(2);
5572 double a0, a1, a2, b1, b2;
5573 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextalpha, nextb0rz;
5574 double y0;
5575 double y1 = unit->m_y1;
5576 double y2 = unit->m_y2;
5577 double a0slope, a1slope, a2slope, b1slope, b2slope;
5579 a0 = unit->m_a0;
5580 a1 = unit->m_a1;
5581 a2 = unit->m_a2;
5582 b1 = unit->m_b1;
5583 b2 = unit->m_b2;
5585 if ((unit->m_freq != nextfreq) || (unit->m_bw != nextbw)){
5586 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5587 nextalpha = sin(nextw0) * (sinh((0.34657359027997 * (double)nextbw * nextw0) / sin(nextw0)));
5588 nextb0rz = 1. / (1. + nextalpha);
5589 nextb1 = cos(nextw0) * 2. * nextb0rz;
5590 nexta0 = nextb0rz;
5591 nexta1 = -nextb1;
5592 nexta2 = nextb0rz;
5593 nextb2 = ((1. - nextalpha) * -nextb0rz);
5594 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
5595 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
5596 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
5597 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
5598 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
5599 unit->m_freq = nextfreq;
5600 unit->m_bw = nextbw;
5601 LOOP(unit->mRate->mFilterLoops,
5602 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5603 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5605 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5606 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5608 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5609 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5610 a0 += a0slope;
5611 a1 += a1slope;
5612 a2 += a2slope;
5613 b1 += b1slope;
5614 b2 += b2slope;
5616 LOOP(unit->mRate->mFilterRemain,
5617 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5618 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5619 y2 = y1;
5620 y1 = y0;
5623 } else {
5624 LOOP(unit->mRate->mFilterLoops,
5625 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5626 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5628 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5629 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5631 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5632 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5634 LOOP(unit->mRate->mFilterRemain,
5635 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5636 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5637 y2 = y1;
5638 y1 = y0;
5642 unit->m_a0 = a0;
5643 unit->m_a1 = a1;
5644 unit->m_a2 = a2;
5645 unit->m_b1 = b1;
5646 unit->m_b2 = b2;
5647 unit->m_y1 = zapgremlins(y1);
5648 unit->m_y2 = zapgremlins(y2);
5651 /* BPeakEQ */
5652 struct BPeakEQ : public Unit
5654 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5655 float m_freq, m_rq, m_db;
5658 extern "C"
5660 void BPeakEQ_next_kkk(BPeakEQ *unit, int inNumSamples);
5661 void BPeakEQ_next_aaa(BPeakEQ *unit, int inNumSamples);
5662 void BPeakEQ_Ctor(BPeakEQ* unit);
5665 void BPeakEQ_Ctor(BPeakEQ* unit)
5667 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate) && (INRATE(3) == calc_FullRate))
5668 SETCALC(BPeakEQ_next_aaa);
5669 else
5670 SETCALC(BPeakEQ_next_kkk);
5672 float freq = unit->m_freq = ZIN0(1);
5673 float rq = unit->m_rq = ZIN0(2);
5674 float db = unit->m_db = ZIN0(3);
5675 double a = pow(10., (double)db * 0.025);
5676 double w0 = twopi * (double)freq * SAMPLEDUR;
5677 double alpha = sin(w0) * 0.5 * (double)rq;
5678 double b0rz = 1. / (1. + (alpha / a));
5679 double b1 = unit->m_b1 = 2. * b0rz * cos(w0);
5680 unit->m_a0 = (1. + (alpha * a)) * b0rz;
5681 unit->m_a1 = -b1;
5682 unit->m_a2 = (1. - (alpha * a)) * b0rz;
5683 unit->m_b2 = (1. - (alpha / a)) * -b0rz;
5685 unit->m_y1 = 0.;
5686 unit->m_y2 = 0.;
5687 PUSH_LOOPVALS
5688 BPeakEQ_next_kkk(unit, 1);
5689 POP_LOOPVALS
5692 void BPeakEQ_next_aaa(BPeakEQ *unit, int inNumSamples)
5694 float *out = ZOUT(0);
5695 float *in = ZIN(0);
5696 float *freq = ZIN(1);
5697 float *rq = ZIN(2);
5698 float *db = ZIN(3);
5700 double a0, a1, a2, b1, b2, a, w0, alpha, b0rz;
5701 double y0, y1, y2;
5702 float nextfreq, nextrq, nextdb;
5704 y1 = unit->m_y1;
5705 y2 = unit->m_y2;
5707 a0 = unit->m_a0;
5708 a1 = unit->m_a1;
5709 a2 = unit->m_a2;
5710 b1 = unit->m_b1;
5711 b2 = unit->m_b2;
5714 LOOP(unit->mRate->mFilterLoops,
5715 nextfreq = ZXP(freq);
5716 nextrq = ZXP(rq);
5717 nextdb = ZXP(db);
5718 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq) || (unit->m_db != nextdb)) {
5719 a = pow(10., (double)nextdb * 0.025);
5720 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5721 alpha = sin(w0) * 0.5 * (double)nextrq;
5722 b0rz = 1. / (1. + (alpha / a));
5723 b1 = 2. * b0rz * cos(w0);
5724 a0 = (1. + (alpha * a)) * b0rz;
5725 a1 = -b1;
5726 a2 = (1. - (alpha * a)) * b0rz;
5727 b2 = (1. - (alpha / a)) * -b0rz;
5728 unit->m_freq = nextfreq;
5729 unit->m_rq = nextrq;
5730 unit->m_db = nextdb;
5732 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5733 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5735 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5736 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5738 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5739 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5741 LOOP(unit->mRate->mFilterRemain,
5742 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5743 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5744 y2 = y1;
5745 y1 = y0;
5746 unit->m_freq = ZXP(freq);
5747 unit->m_rq = ZXP(rq);
5748 unit->m_db = ZXP(db);
5751 unit->m_a0 = a0;
5752 unit->m_a1 = a1;
5753 unit->m_a2 = a2;
5754 unit->m_b1 = b1;
5755 unit->m_b2 = b2;
5756 unit->m_y1 = zapgremlins(y1);
5757 unit->m_y2 = zapgremlins(y2);
5761 void BPeakEQ_next_kkk(BPeakEQ *unit, int inNumSamples)
5763 float *out = ZOUT(0);
5764 float *in = ZIN(0);
5765 float nextfreq = ZIN0(1);
5766 float nextrq = ZIN0(2);
5767 float nextdb = ZIN0(3);
5769 double a0, a1, a2, b1, b2, a, w0, alpha, b0rz;
5770 double y0, y1, y2, a0slope, a1slope, a2slope, b1slope, b2slope, nexta0, nexta1, nexta2, nextb1, nextb2;
5772 y1 = unit->m_y1;
5773 y2 = unit->m_y2;
5775 a0 = unit->m_a0;
5776 a1 = unit->m_a1;
5777 a2 = unit->m_a2;
5778 b1 = unit->m_b1;
5779 b2 = unit->m_b2;
5781 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq) || (unit->m_db != nextdb)) {
5782 a = pow(10., (double)nextdb * 0.025);
5783 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5784 alpha = sin(w0) * 0.5 * (double)nextrq;
5785 b0rz = 1. / (1. + (alpha / a));
5786 nextb1 = 2. * b0rz * cos(w0);
5787 nexta0 = (1. + (alpha * a)) * b0rz;
5788 nexta1 = -nextb1;
5789 nexta2 = (1. - (alpha * a)) * b0rz;
5790 nextb2 = (1. - (alpha / a)) * -b0rz;
5791 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
5792 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
5793 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
5794 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
5795 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
5796 unit->m_freq = nextfreq;
5797 unit->m_db = nextdb;
5798 unit->m_rq = nextrq;
5799 LOOP(unit->mRate->mFilterLoops,
5800 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5801 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5803 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5804 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5806 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5807 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5809 a0 += a0slope;
5810 a1 += a1slope;
5811 a2 += a2slope;
5812 b1 += b1slope;
5813 b2 += b2slope;
5816 LOOP(unit->mRate->mFilterRemain,
5817 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5818 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5819 y2 = y1;
5820 y1 = y0;
5823 } else {
5824 LOOP(unit->mRate->mFilterLoops,
5825 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5826 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5828 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5829 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5831 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5832 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5835 LOOP(unit->mRate->mFilterRemain,
5836 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5837 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5838 y2 = y1;
5839 y1 = y0;
5843 unit->m_a0 = a0;
5844 unit->m_a1 = a1;
5845 unit->m_a2 = a2;
5846 unit->m_b1 = b1;
5847 unit->m_b2 = b2;
5848 unit->m_y1 = zapgremlins(y1);
5849 unit->m_y2 = zapgremlins(y2);
5852 /* BAllPass */
5853 struct BAllPass : public Unit
5855 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5856 float m_freq, m_rq;
5859 extern "C"
5861 void BAllPass_next_kk(BAllPass *unit, int inNumSamples);
5862 void BAllPass_next_aa(BAllPass *unit, int inNumSamples);
5863 void BAllPass_Ctor(BAllPass* unit);
5866 void BAllPass_Ctor(BAllPass* unit)
5868 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
5869 SETCALC(BAllPass_next_aa);
5870 else
5871 SETCALC(BAllPass_next_kk);
5873 float freq = unit->m_freq = ZIN0(1);
5874 float rq = unit->m_rq = ZIN0(2);
5876 double w0 = twopi * (double)freq * SAMPLEDUR;
5877 double alpha = sin(w0) * 0.5 * (double)rq;
5878 double b0rz = 1. / (1. + alpha);
5879 double a0 = unit->m_a0 = (1. - alpha) * b0rz;
5880 double b1 = unit->m_b1 = 2. * b0rz * cos(w0);
5881 unit->m_a1 = -b1;
5882 unit->m_a2 = 1.;
5883 unit->m_b2 = -a0;
5885 unit->m_y1 = 0.;
5887 unit->m_y2 = 0.;
5888 PUSH_LOOPVALS
5889 BAllPass_next_kk(unit, 1);
5890 POP_LOOPVALS
5893 void BAllPass_next_aa(BAllPass *unit, int inNumSamples)
5895 float *out = ZOUT(0);
5896 float *in = ZIN(0);
5897 float *freq = ZIN(1);
5898 float *rq = ZIN(2);
5900 double a0, a1, a2, b1, b2, w0, alpha, b0rz;
5901 double y0, y1, y2;
5902 float nextfreq, nextrq;
5904 y1 = unit->m_y1;
5905 y2 = unit->m_y2;
5907 a0 = unit->m_a0;
5908 a1 = unit->m_a1;
5909 a2 = unit->m_a2;
5910 b1 = unit->m_b1;
5911 b2 = unit->m_b2;
5913 LOOP(unit->mRate->mFilterLoops,
5914 nextfreq = ZXP(freq);
5915 nextrq = ZXP(rq);
5916 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)) {
5917 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5918 alpha = sin(w0) * (double)nextrq * 0.5;
5919 b0rz = 1. / (1. + alpha);
5920 b1 = 2. * b0rz * cos(w0);
5921 a0 = (1. - alpha) * b0rz;
5922 a1 = -b1;
5923 a2 = 1.;
5924 b2 = -a0;
5925 unit->m_freq = nextfreq;
5926 unit->m_rq = nextrq;
5928 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5929 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5931 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5932 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5934 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5935 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5937 LOOP(unit->mRate->mFilterRemain,
5938 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5939 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5940 y2 = y1;
5941 y1 = y0;
5942 unit->m_freq = ZXP(freq);
5943 unit->m_rq = ZXP(rq);
5946 unit->m_a0 = a0;
5947 unit->m_a1 = a1;
5948 unit->m_a2 = a2;
5949 unit->m_b1 = b1;
5950 unit->m_b2 = b2;
5951 unit->m_y1 = zapgremlins(y1);
5952 unit->m_y2 = zapgremlins(y2);
5956 void BAllPass_next_kk(BAllPass *unit, int inNumSamples)
5958 float *out = ZOUT(0);
5959 float *in = ZIN(0);
5960 float nextfreq = ZIN0(1);
5961 float nextrq = ZIN0(2);
5963 double a0, a1, a2, b1, b2;
5964 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextalpha, nextb0rz;
5965 double y0;
5966 double y1 = unit->m_y1;
5967 double y2 = unit->m_y2;
5968 double a0slope, a1slope, a2slope, b1slope, b2slope;
5970 a0 = unit->m_a0;
5971 a1 = unit->m_a1;
5972 a2 = unit->m_a2;
5973 b1 = unit->m_b1;
5974 b2 = unit->m_b2;
5976 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)) {
5977 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5978 nextalpha = sin(nextw0) * 0.5 * (double)nextrq;
5979 nextb0rz = 1. / (1. + nextalpha);
5980 nextb1 = cos(nextw0) * 2. * nextb0rz;
5981 nexta0 = (1. - nextalpha) * nextb0rz;
5982 nexta1 = -nextb1;
5983 nexta2 = 1.;
5984 nextb2 = -nexta0;
5985 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope;
5986 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope;
5987 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope;
5988 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope;
5989 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope;
5990 unit->m_freq = nextfreq;
5991 unit->m_rq = nextrq;
5992 LOOP(unit->mRate->mFilterLoops,
5993 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5994 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5996 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5997 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5999 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6000 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6001 a0 += a0slope;
6002 a1 += a1slope;
6003 a2 += a2slope;
6004 b1 += b1slope;
6005 b2 += b2slope;
6007 LOOP(unit->mRate->mFilterRemain,
6008 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6009 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6010 y2 = y1;
6011 y1 = y0;
6014 } else {
6015 LOOP(unit->mRate->mFilterLoops,
6016 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6017 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6019 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6020 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6022 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6023 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6025 LOOP(unit->mRate->mFilterRemain,
6026 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6027 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6028 y2 = y1;
6029 y1 = y0;
6033 unit->m_a0 = a0;
6034 unit->m_a1 = a1;
6035 unit->m_a2 = a2;
6036 unit->m_b1 = b1;
6037 unit->m_b2 = b2;
6038 unit->m_y1 = zapgremlins(y1);
6039 unit->m_y2 = zapgremlins(y2);
6043 /* BLowShelf */
6044 struct BLowShelf : public Unit
6046 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
6047 float m_freq, m_rs, m_db;
6050 extern "C"
6052 void BLowShelf_next_kkk(BLowShelf *unit, int inNumSamples);
6053 void BLowShelf_next_aaa(BLowShelf *unit, int inNumSamples);
6054 void BLowShelf_Ctor(BLowShelf* unit);
6057 void BLowShelf_Ctor(BLowShelf* unit)
6059 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate) && (INRATE(3) == calc_FullRate))
6060 SETCALC(BLowShelf_next_aaa);
6061 else
6062 SETCALC(BLowShelf_next_kkk);
6064 float freq = unit->m_freq = ZIN0(1);
6065 float rs = unit->m_rs = ZIN0(2);
6066 float db = unit->m_db = ZIN0(3);
6067 double a = pow(10., (double)db * 0.025);
6068 double w0 = twopi * (double)freq * SAMPLEDUR;
6069 double cosw0 = cos(w0);
6070 double sinw0 = sin(w0);
6071 double alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)rs - 1.) + 2.);
6072 double i = (a + 1.) * cosw0;
6073 double j = (a - 1.) * cosw0;
6074 double k = 2. * sqrt(a) * alpha;
6075 double b0rz = 1. / ((a + 1.) + j + k);
6076 unit->m_a0 = a * (( a + 1.) - j + k) * b0rz;
6077 unit->m_a1 = 2. * a * ((a - 1.) - i) * b0rz;
6078 unit->m_a2 = a * ((a + 1.) - j - k) * b0rz;
6079 unit->m_b1 = 2. * ((a - 1.) + i) * b0rz;
6080 unit->m_b2 = ((a + 1.) + j - k) * -b0rz;
6082 unit->m_y1 = 0.;
6084 unit->m_y2 = 0.;
6085 PUSH_LOOPVALS
6086 BLowShelf_next_kkk(unit, 1);
6087 POP_LOOPVALS
6090 void BLowShelf_next_aaa(BLowShelf *unit, int inNumSamples)
6092 float *out = ZOUT(0);
6093 float *in = ZIN(0);
6094 float *freq = ZIN(1);
6095 float *rs = ZIN(2);
6096 float *db = ZIN(3);
6098 double a0, a1, a2, b1, b2, a, w0, cosw0, sinw0, alpha, i, j, k, b0rz;
6099 double y0, y1, y2;
6100 float nextfreq, nextrs, nextdb;
6102 y1 = unit->m_y1;
6103 y2 = unit->m_y2;
6105 a0 = unit->m_a0;
6106 a1 = unit->m_a1;
6107 a2 = unit->m_a2;
6108 b1 = unit->m_b1;
6109 b2 = unit->m_b2;
6111 LOOP(unit->mRate->mFilterLoops,
6112 nextfreq = ZXP(freq);
6113 nextrs = ZXP(rs);
6114 nextdb = ZXP(db);
6115 if ((unit->m_freq != nextfreq) || (unit->m_rs != nextrs) || (unit->m_db != nextdb)) {
6116 a = pow(10., (double)nextdb * 0.025);
6117 w0 = twopi * (double)nextfreq * SAMPLEDUR;
6118 sinw0 = sin(w0);
6119 cosw0 = cos(w0);
6120 alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)nextrs - 1.) + 2.);
6121 i = (a + 1.) * cosw0;
6122 j = (a - 1.) * cosw0;
6123 k = 2. * sqrt(a) * alpha;
6124 b0rz = 1. / ((a + 1.) + j + k);
6125 a0 = a * (( a + 1.) - j + k) * b0rz;
6126 a1 = 2. * a * ((a - 1.) - i) * b0rz;
6127 a2 = a * ((a + 1.) - j - k) * b0rz;
6128 b1 = 2. * ((a - 1.) + i) * b0rz;
6129 b2 = ((a + 1.) + j - k) * -b0rz;
6130 unit->m_freq = nextfreq;
6131 unit->m_rs = nextrs;
6132 unit->m_db = nextdb;
6134 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6135 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6137 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6138 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6140 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6141 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6143 LOOP(unit->mRate->mFilterRemain,
6144 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6145 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6146 y2 = y1;
6147 y1 = y0;
6148 unit->m_freq = ZXP(freq);
6149 unit->m_rs = ZXP(rs);
6150 unit->m_db = ZXP(db);
6153 unit->m_a0 = a0;
6154 unit->m_a1 = a1;
6155 unit->m_a2 = a2;
6156 unit->m_b1 = b1;
6157 unit->m_b2 = b2;
6158 unit->m_y1 = zapgremlins(y1);
6159 unit->m_y2 = zapgremlins(y2);
6162 void BLowShelf_next_kkk(BLowShelf *unit, int inNumSamples)
6164 float *out = ZOUT(0);
6165 float *in = ZIN(0);
6166 float nextfreq = ZIN0(1);
6167 float nextrs = ZIN0(2);
6168 float nextdb = ZIN0(3);
6170 double a0, a1, a2, b1, b2, a, w0, cosw0, sinw0, alpha, i, j, k, b0rz;
6171 double y0, y1, y2, a0slope, a1slope, a2slope, b1slope, b2slope, nexta0, nexta1, nexta2, nextb1, nextb2;
6173 y1 = unit->m_y1;
6174 y2 = unit->m_y2;
6176 a0 = unit->m_a0;
6177 a1 = unit->m_a1;
6178 a2 = unit->m_a2;
6179 b1 = unit->m_b1;
6180 b2 = unit->m_b2;
6182 if ((unit->m_freq != nextfreq) || (unit->m_rs != nextrs) || (unit->m_db != nextdb)) {
6183 a = pow(10., (double)nextdb * 0.025);
6184 w0 = twopi * (double)nextfreq * SAMPLEDUR;
6185 sinw0 = sin(w0);
6186 cosw0 = cos(w0);
6187 alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)nextrs - 1.) + 2.);
6188 i = (a + 1.) * cosw0;
6189 j = (a - 1.) * cosw0;
6190 k = 2. * sqrt(a) * alpha;
6191 b0rz = 1. / ((a + 1.) + j + k);
6192 nexta0 = a * (( a + 1.) - j + k) * b0rz;
6193 nexta1 = 2. * a * ((a - 1.) - i) * b0rz;
6194 nexta2 = a * ((a + 1.) - j - k) * b0rz;
6195 nextb1 = 2. * ((a - 1.) + i) * b0rz;
6196 nextb2 = ((a + 1.) + j - k) * -b0rz;
6197 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
6198 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
6199 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
6200 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
6201 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
6202 unit->m_freq = nextfreq;
6203 unit->m_db = nextdb;
6204 unit->m_rs = nextrs;
6205 LOOP(unit->mRate->mFilterLoops,
6206 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6207 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6209 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6210 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6212 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6213 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6215 a0 += a0slope;
6216 a1 += a1slope;
6217 a2 += a2slope;
6218 b1 += b1slope;
6219 b2 += b2slope;
6222 LOOP(unit->mRate->mFilterRemain,
6223 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6224 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6225 y2 = y1;
6226 y1 = y0;
6229 } else {
6230 LOOP(unit->mRate->mFilterLoops,
6231 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6232 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6234 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6235 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6237 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6238 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6241 LOOP(unit->mRate->mFilterRemain,
6242 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6243 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6244 y2 = y1;
6245 y1 = y0;
6249 unit->m_a0 = a0;
6250 unit->m_a1 = a1;
6251 unit->m_a2 = a2;
6252 unit->m_b1 = b1;
6253 unit->m_b2 = b2;
6254 unit->m_y1 = zapgremlins(y1);
6255 unit->m_y2 = zapgremlins(y2);
6258 /* BHiShelf */
6259 struct BHiShelf : public Unit
6261 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
6262 float m_freq, m_rs, m_db;
6265 extern "C"
6267 void BHiShelf_next_kkk(BHiShelf *unit, int inNumSamples);
6268 void BHiShelf_next_aaa(BHiShelf *unit, int inNumSamples);
6269 void BHiShelf_Ctor(BHiShelf* unit);
6272 void BHiShelf_Ctor(BHiShelf* unit)
6274 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate) && (INRATE(3) == calc_FullRate))
6275 SETCALC(BHiShelf_next_aaa);
6276 else
6277 SETCALC(BHiShelf_next_kkk);
6279 float freq = unit->m_freq = ZIN0(1);
6280 float rs = unit->m_rs = ZIN0(2);
6281 float db = unit->m_db = ZIN0(3);
6282 double a = pow(10., (double)db * 0.025);
6283 double w0 = twopi * (double)freq * SAMPLEDUR;
6284 double cosw0 = cos(w0);
6285 double sinw0 = sin(w0);
6286 double alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)rs - 1.) + 2.);
6287 double i = (a + 1.) * cosw0;
6288 double j = (a - 1.) * cosw0;
6289 double k = 2. * sqrt(a) * alpha;
6291 double b0rz = 1. / ((a + 1.) - j + k);
6292 unit->m_a0 = a * (( a + 1.) + j + k) * b0rz;
6293 unit->m_a1 = -2. * a * ((a - 1.) + i) * b0rz;
6294 unit->m_a2 = a * ((a + 1.) + j - k) * b0rz;
6295 unit->m_b1 = -2. * ((a - 1.) - i) * b0rz;
6296 unit->m_b2 = ((a + 1.) - j - k) * -b0rz;
6298 unit->m_y1 = 0.;
6300 unit->m_y2 = 0.;
6301 PUSH_LOOPVALS
6302 BHiShelf_next_kkk(unit, 1);
6303 POP_LOOPVALS
6306 void BHiShelf_next_aaa(BHiShelf *unit, int inNumSamples)
6308 float *out = ZOUT(0);
6309 float *in = ZIN(0);
6310 float *freq = ZIN(1);
6311 float *rs = ZIN(2);
6312 float *db = ZIN(3);
6314 double a0, a1, a2, b1, b2, a, w0, cosw0, sinw0, alpha, i, j, k, b0rz;
6315 double y0, y1, y2;
6316 float nextfreq, nextrs, nextdb;
6318 y1 = unit->m_y1;
6319 y2 = unit->m_y2;
6321 a0 = unit->m_a0;
6322 a1 = unit->m_a1;
6323 a2 = unit->m_a2;
6324 b1 = unit->m_b1;
6325 b2 = unit->m_b2;
6327 LOOP(unit->mRate->mFilterLoops,
6328 nextfreq = ZXP(freq);
6329 nextrs = ZXP(rs);
6330 nextdb = ZXP(db);
6331 if ((unit->m_freq != nextfreq) || (unit->m_rs != nextrs) || (unit->m_db != nextdb)) {
6332 a = pow(10., (double)nextdb * 0.025);
6333 w0 = twopi * (double)nextfreq * SAMPLEDUR;
6334 sinw0 = sin(w0);
6335 cosw0 = cos(w0);
6336 alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)nextrs - 1.) + 2.);
6337 i = (a + 1.) * cosw0;
6338 j = (a - 1.) * cosw0;
6339 k = 2. * sqrt(a) * alpha;
6340 b0rz = 1. / ((a + 1.) - j + k);
6341 a0 = a * (( a + 1.) + j + k) * b0rz;
6342 a1 = -2. * a * ((a - 1.) + i) * b0rz;
6343 a2 = a * ((a + 1.) + j - k) * b0rz;
6344 b1 = -2. * ((a - 1.) - i) * b0rz;
6345 b2 = ((a + 1.) - j - k) * -b0rz;
6346 unit->m_freq = ZXP(freq);
6347 unit->m_rs = ZXP(rs);
6348 unit->m_db = ZXP(db);
6350 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6351 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6353 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6354 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6356 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6357 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6359 LOOP(unit->mRate->mFilterRemain,
6360 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6361 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6362 y2 = y1;
6363 y1 = y0;
6364 unit->m_freq = ZXP(freq);
6365 unit->m_rs = ZXP(rs);
6366 unit->m_db = ZXP(db);
6369 unit->m_a0 = a0;
6370 unit->m_a1 = a1;
6371 unit->m_a2 = a2;
6372 unit->m_b1 = b1;
6373 unit->m_b2 = b2;
6374 unit->m_y1 = zapgremlins(y1);
6375 unit->m_y2 = zapgremlins(y2);
6378 void BHiShelf_next_kkk(BHiShelf *unit, int inNumSamples)
6380 float *out = ZOUT(0);
6381 float *in = ZIN(0);
6382 float nextfreq = ZIN0(1);
6383 float nextrs = ZIN0(2);
6384 float nextdb = ZIN0(3);
6386 double a0, a1, a2, b1, b2, a, w0, cosw0, sinw0, alpha, i, j, k, b0rz;
6387 double y0, y1, y2, a0slope, a1slope, a2slope, b1slope, b2slope, nexta0, nexta1, nexta2, nextb1, nextb2;
6389 y1 = unit->m_y1;
6390 y2 = unit->m_y2;
6392 a0 = unit->m_a0;
6393 a1 = unit->m_a1;
6394 a2 = unit->m_a2;
6395 b1 = unit->m_b1;
6396 b2 = unit->m_b2;
6398 if ((unit->m_freq != nextfreq) || (unit->m_rs != nextrs) || (unit->m_db != nextdb)) {
6399 a = pow(10., (double)nextdb * 0.025);
6400 w0 = twopi * (double)nextfreq * SAMPLEDUR;
6401 sinw0 = sin(w0);
6402 cosw0 = cos(w0);
6403 alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)nextrs - 1.) + 2.);
6404 i = (a + 1.) * cosw0;
6405 j = (a - 1.) * cosw0;
6406 k = 2. * sqrt(a) * alpha;
6407 b0rz = 1. / ((a + 1.) - j + k);
6408 nexta0 = a * (( a + 1.) + j + k) * b0rz;
6409 nexta1 = -2. * a * ((a - 1.) + i) * b0rz;
6410 nexta2 = a * ((a + 1.) + j - k) * b0rz;
6411 nextb1 = -2. * ((a - 1.) - i) * b0rz;
6412 nextb2 = ((a + 1.) - j - k) * -b0rz;
6413 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
6414 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
6415 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
6416 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
6417 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
6418 unit->m_freq = nextfreq;
6419 unit->m_db = nextdb;
6420 unit->m_rs = nextrs;
6421 LOOP(unit->mRate->mFilterLoops,
6422 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6423 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6425 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6426 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6428 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6429 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6431 a0 += a0slope;
6432 a1 += a1slope;
6433 a2 += a2slope;
6434 b1 += b1slope;
6435 b2 += b2slope;
6438 LOOP(unit->mRate->mFilterRemain,
6439 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6440 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6441 y2 = y1;
6442 y1 = y0;
6445 } else {
6446 LOOP(unit->mRate->mFilterLoops,
6447 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6448 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6450 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6451 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6453 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6454 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6457 LOOP(unit->mRate->mFilterRemain,
6458 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6459 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6460 y2 = y1;
6461 y1 = y0;
6464 unit->m_a0 = a0;
6465 unit->m_a1 = a1;
6466 unit->m_a2 = a2;
6467 unit->m_b1 = b1;
6468 unit->m_b2 = b2;
6469 unit->m_y1 = zapgremlins(y1);
6470 unit->m_y2 = zapgremlins(y2);
6473 ////////////////////////////////////////////////////////////////////////////////////////////////////////
6474 PluginLoad(Filter)
6476 ft = inTable;
6478 DefineSimpleUnit(Ramp);
6479 DefineSimpleUnit(Lag);
6480 DefineSimpleUnit(Lag2);
6481 DefineSimpleUnit(Lag3);
6482 DefineSimpleUnit(LagUD);
6483 DefineSimpleUnit(Lag2UD);
6484 DefineSimpleUnit(Lag3UD);
6485 DefineSimpleUnit(VarLag);
6486 DefineSimpleUnit(OnePole);
6487 DefineSimpleUnit(OneZero);
6488 DefineSimpleUnit(TwoPole);
6489 DefineSimpleUnit(TwoZero);
6490 DefineSimpleUnit(Decay);
6491 DefineSimpleUnit(Decay2);
6492 DefineSimpleUnit(Flip);
6493 DefineSimpleUnit(Delay1);
6494 DefineSimpleUnit(Delay2);
6495 DefineSimpleUnit(Integrator);
6496 DefineSimpleUnit(LeakDC);
6497 DefineSimpleUnit(LPZ1);
6498 DefineSimpleUnit(HPZ1);
6499 DefineSimpleUnit(LPZ2);
6500 DefineSimpleUnit(HPZ2);
6501 DefineSimpleUnit(BPZ2);
6502 DefineSimpleUnit(BRZ2);
6503 DefineSimpleUnit(APF);
6504 DefineSimpleUnit(LPF);
6505 DefineSimpleUnit(HPF);
6506 DefineSimpleUnit(BPF);
6507 DefineSimpleUnit(BRF);
6508 DefineSimpleUnit(RLPF);
6509 DefineSimpleUnit(RHPF);
6511 DefineSimpleUnit(Slew);
6512 DefineSimpleUnit(Slope);
6514 DefineSimpleUnit(MidEQ);
6515 DefineSimpleUnit(Median);
6517 DefineSimpleUnit(Resonz);
6518 DefineSimpleUnit(Ringz);
6519 DefineSimpleUnit(Formlet);
6521 DefineSimpleUnit(FOS);
6522 DefineSimpleUnit(SOS);
6524 DefineSimpleUnit(Compander);
6525 DefineDtorUnit(Limiter);
6526 DefineDtorUnit(Normalizer);
6528 DefineSimpleUnit(Amplitude);
6529 DefineSimpleUnit(DetectSilence);
6531 DefineSimpleUnit(Hilbert);
6532 DefineSimpleUnit(FreqShift);
6533 DefineSimpleUnit(MoogFF);
6535 /* BEQSuite UGens */
6536 DefineSimpleUnit(BLowPass);
6537 DefineSimpleUnit(BHiPass);
6538 DefineSimpleUnit(BBandPass);
6539 DefineSimpleUnit(BBandStop);
6540 DefineSimpleUnit(BPeakEQ);
6541 DefineSimpleUnit(BAllPass);
6542 DefineSimpleUnit(BLowShelf);
6543 DefineSimpleUnit(BHiShelf);
6547 //////////////////////////////////////////////////////////////////////////////////////////////////