Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / server / plugins / FilterUGens.cpp
blobd3234b3afc4750dec802a471b1b18d49a94b6d3a
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 float out0 = 0.5f * (x0 + x1);
1747 x1 = ZXP(in);
1748 float out1 = 0.5f * (x1 + x0);
1749 x0 = ZXP(in);
1750 float out2 = 0.5f * (x0 + x1);
1751 x1 = ZXP(in);
1752 float out3 = 0.5f * (x1 + x0);
1754 ZXP(out) = out0;
1755 ZXP(out) = out1;
1756 ZXP(out) = out2;
1757 ZXP(out) = out3;
1759 LOOP(inNumSamples & 3,
1760 x0 = ZXP(in);
1761 ZXP(out) = 0.5f * (x0 + x1);
1762 x1 = x0;
1765 unit->m_x1 = x1;
1768 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1771 void HPZ1_Ctor(HPZ1* unit)
1773 //printf("HPZ1_Reset\n");
1774 SETCALC(HPZ1_next);
1775 unit->m_x1 = ZIN0(0);
1776 HPZ1_next(unit, 1);
1780 void HPZ1_next(HPZ1* unit, int inNumSamples)
1782 //printf("HPZ1_next\n");
1784 float *out = ZOUT(0);
1785 float *in = ZIN(0);
1787 float x0;
1788 float x1 = unit->m_x1;
1790 LOOP(inNumSamples >> 2,
1791 x0 = ZXP(in);
1792 float out0 = 0.5f * (x0 - x1);
1793 x1 = ZXP(in);
1794 float out1 = 0.5f * (x1 - x0);
1795 x0 = ZXP(in);
1796 float out2 = 0.5f * (x0 - x1);
1797 x1 = ZXP(in);
1798 float out3 = 0.5f * (x1 - x0);
1800 ZXP(out) = out0;
1801 ZXP(out) = out1;
1802 ZXP(out) = out2;
1803 ZXP(out) = out3;
1805 LOOP(inNumSamples & 3,
1806 x0 = ZXP(in);
1807 //printf("%d %d %g %g\n", this, inNumSamples, x0, x1);
1808 ZXP(out) = 0.5f * (x0 - x1);
1809 x1 = x0;
1812 unit->m_x1 = x1;
1815 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1817 void Slope_Ctor(Slope* unit)
1819 //printf("Slope_Reset\n");
1820 SETCALC(Slope_next);
1821 unit->m_x1 = ZIN0(0);
1822 //printf("Slope_Reset %g\n", unit->m_x1);
1823 Slope_next(unit, 1);
1827 void Slope_next(Slope* unit, int inNumSamples)
1829 //printf("Slope_next_a %g\n", unit->m_x1);
1831 float *out = ZOUT(0);
1832 float *in = ZIN(0);
1834 float x1 = unit->m_x1;
1836 float sr = SAMPLERATE;
1837 LOOP1(inNumSamples,
1838 float x0 = ZXP(in);
1839 ZXP(out) = sr * (x0 - x1);
1840 x1 = x0;
1843 unit->m_x1 = x1;
1846 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1848 void Delay1_Ctor(Delay1* unit)
1850 //printf("Delay1_Reset\n");
1851 SETCALC(Delay1_next);
1852 unit->m_x1 = ZIN0(0);
1853 Delay1_next(unit, 1);
1857 void Delay1_next(Delay1* unit, int inNumSamples)
1859 //printf("Delay1_next_a\n");
1861 float *out = ZOUT(0);
1862 float *in = ZIN(0);
1864 float x0;
1865 float x1 = unit->m_x1;
1867 LOOP(inNumSamples >> 2,
1868 x0 = ZXP(in);
1869 ZXP(out) = x1;
1870 x1 = ZXP(in);
1871 ZXP(out) = x0;
1872 x0 = ZXP(in);
1873 ZXP(out) = x1;
1874 x1 = ZXP(in);
1875 ZXP(out) = x0;
1877 LOOP(inNumSamples & 3,
1878 x0 = ZXP(in);
1879 ZXP(out) = x1;
1880 x1 = x0;
1883 unit->m_x1 = x1;
1886 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1888 void Flip_Ctor(Flip* unit)
1890 if (unit->mBufLength & 1) {
1891 SETCALC(Flip_next_odd);
1892 Flip_next_odd(unit, 1);
1893 } else {
1894 SETCALC(Flip_next_even);
1895 ZOUT0(0) = ZIN0(0);
1900 void Flip_next_even(Flip* unit, int inNumSamples)
1902 float *out = ZOUT(0);
1903 float *in = ZIN(0);
1905 LOOP(inNumSamples >> 1,
1906 ZXP(out) = -ZXP(in);
1907 ZXP(out) = ZXP(in);
1911 void Flip_next_odd(Flip* unit, int inNumSamples)
1913 float *out = ZOUT(0);
1914 float *in = ZIN(0);
1916 if (unit->mWorld->mBufCounter & 1) {
1917 ZXP(out) = ZXP(in);
1918 LOOP(inNumSamples >> 1,
1919 ZXP(out) = -ZXP(in);
1920 ZXP(out) = ZXP(in);
1922 } else {
1923 LOOP(inNumSamples >> 1,
1924 ZXP(out) = -ZXP(in);
1925 ZXP(out) = ZXP(in);
1927 ZXP(out) = -ZXP(in);
1931 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1933 void Delay2_Ctor(Delay2* unit)
1935 SETCALC(Delay2_next);
1936 unit->m_x1 = ZIN0(0);
1937 ZOUT0(0) = 0.f;
1941 void Delay2_next(Delay2* unit, int inNumSamples)
1943 float *out = ZOUT(0);
1944 float *in = ZIN(0);
1946 float x0;
1947 float x1 = unit->m_x1;
1948 float x2 = unit->m_x2;
1950 LOOP(unit->mRate->mFilterLoops,
1951 x0 = ZXP(in);
1952 ZXP(out) = x2;
1953 x2 = ZXP(in);
1954 ZXP(out) = x1;
1955 x1 = ZXP(in);
1956 ZXP(out) = x0;
1958 LOOP(unit->mRate->mFilterRemain,
1959 x0 = ZXP(in);
1960 ZXP(out) = x2;
1961 x2 = x1;
1962 x1 = x0;
1965 unit->m_x1 = x1;
1966 unit->m_x2 = x2;
1969 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1972 void LPZ2_Ctor(LPZ2* unit)
1974 //printf("LPZ2_Reset\n");
1975 SETCALC(LPZ2_next);
1976 unit->m_x1 = unit->m_x2 = ZIN0(0);
1977 PUSH_LOOPVALS
1978 LPZ2_next(unit, 1);
1979 POP_LOOPVALS
1983 void LPZ2_next(LPZ2* unit, int inNumSamples)
1985 //printf("LPZ2_next_a\n");
1987 float *out = ZOUT(0);
1988 float *in = ZIN(0);
1990 float x0;
1991 float x1 = unit->m_x1;
1992 float x2 = unit->m_x2;
1994 LOOP(unit->mRate->mFilterLoops,
1995 x0 = ZXP(in);
1996 float out0 = (x0 + 2.f * x1 + x2) * 0.25f;
1997 x2 = ZXP(in);
1998 float out1 = (x2 + 2.f * x0 + x1) * 0.25f;
1999 x1 = ZXP(in);
2000 float out2 = (x1 + 2.f * x2 + x0) * 0.25f;
2002 ZXP(out) = out0;
2003 ZXP(out) = out1;
2004 ZXP(out) = out2;
2006 LOOP(unit->mRate->mFilterRemain,
2007 x0 = ZXP(in);
2008 ZXP(out) = (x0 + 2.f * x1 + x2) * 0.25f;
2009 x2 = x1;
2010 x1 = x0;
2013 unit->m_x1 = x1;
2014 unit->m_x2 = x2;
2017 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2019 void HPZ2_Ctor(HPZ2* unit)
2021 //printf("HPZ2_Reset\n");
2022 SETCALC(HPZ2_next);
2023 unit->m_x1 = unit->m_x2 = ZIN0(0);
2024 PUSH_LOOPVALS
2025 HPZ2_next(unit, 1);
2026 POP_LOOPVALS
2030 void HPZ2_next(HPZ2* unit, int inNumSamples)
2032 //printf("HPZ2_next_a\n");
2034 float *out = ZOUT(0);
2035 float *in = ZIN(0);
2037 float x0;
2038 float x1 = unit->m_x1;
2039 float x2 = unit->m_x2;
2041 LOOP(unit->mRate->mFilterLoops,
2042 x0 = ZXP(in);
2043 float out0 = (x0 - 2.f * x1 + x2) * 0.25f;
2044 x2 = ZXP(in);
2045 float out1 = (x2 - 2.f * x0 + x1) * 0.25f;
2046 x1 = ZXP(in);
2047 float out2 = (x1 - 2.f * x2 + x0) * 0.25f;
2048 ZXP(out) = out0;
2049 ZXP(out) = out1;
2050 ZXP(out) = out2;
2052 LOOP(unit->mRate->mFilterRemain,
2053 x0 = ZXP(in);
2054 ZXP(out) = (x0 - 2.f * x1 + x2) * 0.25f;
2055 x2 = x1;
2056 x1 = x0;
2059 unit->m_x1 = x1;
2060 unit->m_x2 = x2;
2063 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2065 void BPZ2_Ctor(BPZ2* unit)
2067 //printf("BPZ2_Reset\n");
2068 SETCALC(BPZ2_next);
2069 unit->m_x1 = unit->m_x2 = ZIN0(0);
2070 PUSH_LOOPVALS
2071 BPZ2_next(unit, 1);
2072 POP_LOOPVALS
2076 void BPZ2_next(BPZ2* unit, int inNumSamples)
2078 //printf("BPZ2_next_a\n");
2080 float *out = ZOUT(0);
2081 float *in = ZIN(0);
2083 float x0;
2084 float x1 = unit->m_x1;
2085 float x2 = unit->m_x2;
2087 LOOP(unit->mRate->mFilterLoops,
2088 x0 = ZXP(in);
2089 ZXP(out) = (x0 - x2) * 0.5f;
2090 x2 = ZXP(in);
2091 ZXP(out) = (x2 - x1) * 0.5f;
2092 x1 = ZXP(in);
2093 ZXP(out) = (x1 - x0) * 0.5f;
2095 LOOP(unit->mRate->mFilterRemain,
2096 x0 = ZXP(in);
2097 ZXP(out) = (x0 - x2) * 0.5f;
2098 x2 = x1;
2099 x1 = x0;
2102 unit->m_x1 = x1;
2103 unit->m_x2 = x2;
2106 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2108 void BRZ2_Ctor(BRZ2* unit)
2110 //printf("BRZ2_Reset\n");
2111 SETCALC(BRZ2_next);
2112 unit->m_x1 = unit->m_x2 = ZIN0(0);
2113 PUSH_LOOPVALS
2114 BRZ2_next(unit, 1);
2115 POP_LOOPVALS
2119 void BRZ2_next(BRZ2* unit, int inNumSamples)
2121 //printf("BRZ2_next_a\n");
2123 float *out = ZOUT(0);
2124 float *in = ZIN(0);
2126 float x0;
2127 float x1 = unit->m_x1;
2128 float x2 = unit->m_x2;
2130 LOOP(unit->mRate->mFilterLoops,
2131 x0 = ZXP(in);
2132 ZXP(out) = (x0 + x2) * 0.5f;
2133 x2 = ZXP(in);
2134 ZXP(out) = (x2 + x1) * 0.5f;
2135 x1 = ZXP(in);
2136 ZXP(out) = (x1 + x0) * 0.5f;
2138 LOOP(unit->mRate->mFilterRemain,
2139 x0 = ZXP(in);
2140 ZXP(out) = (x0 + x2) * 0.5f;
2141 x2 = x1;
2142 x1 = x0;
2145 unit->m_x1 = x1;
2146 unit->m_x2 = x2;
2149 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2151 void Slew_Ctor(Slew* unit)
2153 //printf("Slew_Reset\n");
2154 SETCALC(Slew_next);
2155 unit->mLevel = ZIN0(0);
2156 Slew_next(unit, 1);
2160 void Slew_next(Slew* unit, int inNumSamples)
2162 //printf("Slew_next_a\n");
2164 float sampleDur = unit->mRate->mSampleDur;
2165 float *out = ZOUT(0);
2166 float *in = ZIN(0);
2167 float upf = ZIN0(1) * sampleDur;
2168 float dnf = 0.f - ZIN0(2) * sampleDur;
2169 float level = unit->mLevel;
2170 LOOP1(inNumSamples,
2171 float slope = ZXP(in) - level;
2172 level += sc_clip(slope, dnf, upf);
2173 ZXP(out) = level;
2175 unit->mLevel = level;
2178 /*void Slew_next_1(Slew* unit, int inNumSamples)
2180 //printf("Slew_next_a\n");
2182 float *out = ZOUT(0);
2183 float in = ZIN0(0);
2184 float upf = ZIN0(1);
2185 float dnf = ZIN0(2);
2186 float level = unit->mLevel;
2187 float slope = ZXP(in) - level;
2188 if (slope > upf) slope = upf;
2189 else if (slope < dnf) slope = dnf;
2190 level += slope;
2191 ZXP(out) = level;
2192 unit->mLevel = level;
2196 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2198 void RLPF_Ctor(RLPF* unit)
2200 //printf("RLPF_Reset\n");
2201 if (unit->mBufLength == 1) {
2202 SETCALC(RLPF_next_1);
2203 } else {
2204 SETCALC(RLPF_next);
2207 unit->m_a0 = 0.f;
2208 unit->m_b1 = 0.f;
2209 unit->m_b2 = 0.f;
2210 unit->m_y1 = 0.f;
2211 unit->m_y2 = 0.f;
2212 unit->m_freq = 0.f;
2213 unit->m_reson = 0.f;
2214 RLPF_next_1(unit, 1);
2218 void RLPF_next(RLPF* unit, int inNumSamples)
2220 //printf("RLPF_next\n");
2222 float *out = ZOUT(0);
2223 float *in = ZIN(0);
2224 float freq = ZIN0(1);
2225 float reson = ZIN0(2);
2227 float y0;
2228 float y1 = unit->m_y1;
2229 float y2 = unit->m_y2;
2230 float a0 = unit->m_a0;
2231 float b1 = unit->m_b1;
2232 float b2 = unit->m_b2;
2234 if (freq != unit->m_freq || reson != unit->m_reson) {
2236 float qres = sc_max(0.001, reson);
2237 float pfreq = freq * unit->mRate->mRadiansPerSample;
2239 float D = tan(pfreq * qres * 0.5);
2240 float C = ((1.f-D)/(1.f+D));
2241 float cosf = cos(pfreq);
2243 float next_b1 = (1.f + C) * cosf;
2244 float next_b2 = -C;
2245 float next_a0 = (1.f + C - next_b1) * .25;
2246 //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);
2248 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2249 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2250 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2251 LOOP(unit->mRate->mFilterLoops,
2252 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2253 ZXP(out) = y0 + 2.f * y1 + y2;
2255 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
2256 ZXP(out) = y2 + 2.f * y0 + y1;
2258 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
2259 ZXP(out) = y1 + 2.f * y2 + y0;
2261 a0 += a0_slope;
2262 b1 += b1_slope;
2263 b2 += b2_slope;
2265 LOOP(unit->mRate->mFilterRemain,
2266 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2267 ZXP(out) = y0 + 2.f * y1 + y2;
2268 y2 = y1;
2269 y1 = y0;
2272 unit->m_freq = freq;
2273 unit->m_reson = reson;
2274 unit->m_a0 = a0;
2275 unit->m_b1 = b1;
2276 unit->m_b2 = b2;
2277 } else {
2278 LOOP(unit->mRate->mFilterLoops,
2279 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2280 ZXP(out) = y0 + 2.f * y1 + y2;
2282 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
2283 ZXP(out) = y2 + 2.f * y0 + y1;
2285 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
2286 ZXP(out) = y1 + 2.f * y2 + y0;
2288 LOOP(unit->mRate->mFilterRemain,
2289 y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2290 ZXP(out) = y0 + 2.f * y1 + y2;
2291 y2 = y1;
2292 y1 = y0;
2295 unit->m_y1 = zapgremlins(y1);
2296 unit->m_y2 = zapgremlins(y2);
2300 void RLPF_next_1(RLPF* unit, int inNumSamples)
2302 //printf("RLPF_next_1\n");
2304 float in = ZIN0(0);
2305 float freq = ZIN0(1);
2306 float reson = ZIN0(2);
2308 float y0;
2309 float y1 = unit->m_y1;
2310 float y2 = unit->m_y2;
2311 float a0 = unit->m_a0;
2312 float b1 = unit->m_b1;
2313 float b2 = unit->m_b2;
2315 if (freq != unit->m_freq || reson != unit->m_reson) {
2316 float qres = sc_max(0.001f, reson);
2317 float pfreq = freq * unit->mRate->mRadiansPerSample;
2319 float D = tan(pfreq * qres * 0.5f);
2320 float C = ((1.f-D)/(1.f+D));
2321 float cosf = cos(pfreq);
2323 b1 = (1.f + C) * cosf;
2324 b2 = -C;
2325 a0 = (1.f + C - b1) * .25f;
2327 y0 = a0 * in + b1 * y1 + b2 * y2;
2328 ZOUT0(0) = y0 + 2.f * y1 + y2;
2329 y2 = y1;
2330 y1 = y0;
2332 unit->m_freq = freq;
2333 unit->m_reson = reson;
2334 unit->m_a0 = a0;
2335 unit->m_b1 = b1;
2336 unit->m_b2 = b2;
2337 } else {
2338 y0 = a0 * in + b1 * y1 + b2 * y2;
2339 ZOUT0(0) = y0 + 2.f * y1 + y2;
2340 y2 = y1;
2341 y1 = y0;
2343 unit->m_y1 = zapgremlins(y1);
2344 unit->m_y2 = zapgremlins(y2);
2349 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2351 void RHPF_Ctor(RHPF* unit)
2353 if (unit->mBufLength == 1)
2354 SETCALC(RHPF_next_1);
2355 else
2356 SETCALC(RHPF_next);
2358 unit->m_a0 = 0.;
2359 unit->m_b1 = 0.;
2360 unit->m_b2 = 0.;
2361 unit->m_y1 = 0.;
2362 unit->m_y2 = 0.;
2363 unit->m_freq = 0.f;
2364 unit->m_reson = 0.f;
2365 RHPF_next_1(unit, 1);
2369 void RHPF_next(RHPF* unit, int inNumSamples)
2371 //printf("RHPFs_next\n");
2373 float *out = ZOUT(0);
2374 float *in = ZIN(0);
2375 float freq = ZIN0(1);
2376 float reson = ZIN0(2);
2378 double y1 = unit->m_y1;
2379 double y2 = unit->m_y2;
2380 double a0 = unit->m_a0;
2381 double b1 = unit->m_b1;
2382 double b2 = unit->m_b2;
2384 if (freq != unit->m_freq || reson != unit->m_reson) {
2385 float qres = sc_max(0.001f, reson);
2386 float pfreq = freq * unit->mRate->mRadiansPerSample;
2388 double D = tan(pfreq * qres * 0.5f);
2389 double C = ((1.-D)/(1.+D));
2390 double cosf = cos(pfreq);
2392 double next_b1 = (1. + C) * cosf;
2393 double next_b2 = -C;
2394 double next_a0 = (1. + C + next_b1) * .25;
2396 //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);
2398 double a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2399 double b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2400 double b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2401 LOOP(unit->mRate->mFilterLoops,
2402 double y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2403 ZXP(out) = y0 - 2.f * y1 + y2;
2405 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
2406 ZXP(out) = y2 - 2.f * y0 + y1;
2408 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
2409 ZXP(out) = y1 - 2.f * y2 + y0;
2411 a0 += a0_slope;
2412 b1 += b1_slope;
2413 b2 += b2_slope;
2415 LOOP(unit->mRate->mFilterRemain,
2416 double y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2417 ZXP(out) = y0 - 2.f * y1 + y2;
2418 y2 = y1;
2419 y1 = y0;
2422 unit->m_freq = freq;
2423 unit->m_reson = reson;
2424 unit->m_a0 = a0;
2425 unit->m_b1 = b1;
2426 unit->m_b2 = b2;
2427 } else {
2428 LOOP(unit->mRate->mFilterLoops,
2429 double y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2430 ZXP(out) = y0 - 2.f * y1 + y2;
2432 y2 = a0 * ZXP(in) + b1 * y0 + b2 * y1;
2433 ZXP(out) = y2 - 2.f * y0 + y1;
2435 y1 = a0 * ZXP(in) + b1 * y2 + b2 * y0;
2436 ZXP(out) = y1 - 2.f * y2 + y0;
2438 LOOP(unit->mRate->mFilterRemain,
2439 double y0 = a0 * ZXP(in) + b1 * y1 + b2 * y2;
2440 ZXP(out) = y0 - 2.f * y1 + y2;
2441 y2 = y1;
2442 y1 = y0;
2445 unit->m_y1 = zapgremlins(y1);
2446 unit->m_y2 = zapgremlins(y2);
2449 void RHPF_next_1(RHPF* unit, int inNumSamples)
2451 //printf("RHPFs_next_1\n");
2453 float in = ZIN0(0);
2454 float freq = ZIN0(1);
2455 float reson = ZIN0(2);
2457 double y1 = unit->m_y1;
2458 double y2 = unit->m_y2;
2459 double a0 = unit->m_a0;
2460 double b1 = unit->m_b1;
2461 double b2 = unit->m_b2;
2463 if (freq != unit->m_freq || reson != unit->m_reson) {
2464 float qres = sc_max(0.001f, reson);
2465 float pfreq = freq * unit->mRate->mRadiansPerSample;
2467 double D = tan(pfreq * qres * 0.5f);
2468 double C = ((1.-D)/(1.+D));
2469 double cosf = cos(pfreq);
2471 b1 = (1. + C) * cosf;
2472 b2 = -C;
2473 a0 = (1. + C + b1) * .25;
2475 double y0 = a0 * in + b1 * y1 + b2 * y2;
2476 ZOUT0(0) = y0 - 2.f * y1 + y2;
2477 y2 = y1;
2478 y1 = y0;
2480 unit->m_freq = freq;
2481 unit->m_reson = reson;
2482 unit->m_a0 = a0;
2483 unit->m_b1 = b1;
2484 unit->m_b2 = b2;
2485 } else {
2486 double y0 = a0 * in + b1 * y1 + b2 * y2;
2487 ZOUT0(0) = y0 - 2.f * y1 + y2;
2488 y2 = y1;
2489 y1 = y0;
2491 unit->m_y1 = zapgremlins(y1);
2492 unit->m_y2 = zapgremlins(y2);
2496 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2498 void LPF_Ctor(LPF* unit)
2500 if (unit->mBufLength == 1)
2501 SETCALC(LPF_next_1);
2502 else
2503 SETCALC(LPF_next);
2505 unit->m_a0 = 0.f;
2506 unit->m_b1 = 0.f;
2507 unit->m_b2 = 0.f;
2508 unit->m_y1 = 0.f;
2509 unit->m_y2 = 0.f;
2510 unit->m_freq = 0.f;
2511 LPF_next_1(unit, 1);
2515 void LPF_next(LPF* unit, int inNumSamples)
2517 //printf("LPF_next\n");
2519 float *out = ZOUT(0);
2520 float *in = ZIN(0);
2521 float freq = ZIN0(1);
2523 float y0;
2524 float y1 = unit->m_y1;
2525 float y2 = unit->m_y2;
2526 float a0 = unit->m_a0;
2527 float b1 = unit->m_b1;
2528 float b2 = unit->m_b2;
2530 if (freq != unit->m_freq) {
2532 float pfreq = freq * unit->mRate->mRadiansPerSample * 0.5;
2534 float C = 1.f / tan(pfreq);
2535 float C2 = C * C;
2536 float sqrt2C = C * sqrt2_f;
2537 float next_a0 = 1.f / (1.f + sqrt2C + C2);
2538 float next_b1 = -2.f * (1.f - C2) * next_a0 ;
2539 float next_b2 = -(1.f - sqrt2C + C2) * next_a0;
2541 //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);
2543 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2544 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2545 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2546 LOOP(unit->mRate->mFilterLoops,
2547 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2548 ZXP(out) = a0 * (y0 + 2.f * y1 + y2);
2550 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2551 ZXP(out) = a0 * (y2 + 2.f * y0 + y1);
2553 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2554 ZXP(out) = a0 * (y1 + 2.f * y2 + y0);
2556 a0 += a0_slope;
2557 b1 += b1_slope;
2558 b2 += b2_slope;
2560 LOOP(unit->mRate->mFilterRemain,
2561 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2562 ZXP(out) = a0 * (y0 + 2.f * y1 + y2);
2563 y2 = y1;
2564 y1 = y0;
2567 unit->m_freq = freq;
2568 unit->m_a0 = a0;
2569 unit->m_b1 = b1;
2570 unit->m_b2 = b2;
2571 } else {
2572 LOOP(unit->mRate->mFilterLoops,
2573 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2574 float out0 = a0 * (y0 + 2.f * y1 + y2);
2576 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2577 float out1 = a0 * (y2 + 2.f * y0 + y1);
2579 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2580 float out2 = a0 * (y1 + 2.f * y2 + y0);
2581 ZXP(out) = out0;
2582 ZXP(out) = out1;
2583 ZXP(out) = out2;
2585 LOOP(unit->mRate->mFilterRemain,
2586 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2587 ZXP(out) = a0 * (y0 + 2.f * y1 + y2);
2588 y2 = y1;
2589 y1 = y0;
2592 unit->m_y1 = zapgremlins(y1);
2593 unit->m_y2 = zapgremlins(y2);
2596 void LPF_next_1(LPF* unit, int inNumSamples)
2598 //printf("LPF_next\n");
2599 float in = ZIN0(0);
2600 float freq = ZIN0(1);
2602 float y0;
2603 float y1 = unit->m_y1;
2604 float y2 = unit->m_y2;
2605 float a0 = unit->m_a0;
2606 float b1 = unit->m_b1;
2607 float b2 = unit->m_b2;
2609 if (freq != unit->m_freq) {
2611 float pfreq = freq * unit->mRate->mRadiansPerSample * 0.5;
2613 float C = 1.f / tan(pfreq);
2614 float C2 = C * C;
2615 float sqrt2C = C * sqrt2_f;
2616 a0 = 1.f / (1.f + sqrt2C + C2);
2617 b1 = -2.f * (1.f - C2) * a0 ;
2618 b2 = -(1.f - sqrt2C + C2) * a0;
2620 y0 = in + b1 * y1 + b2 * y2;
2621 ZOUT0(0) = a0 * (y0 + 2.f * y1 + y2);
2622 y2 = y1;
2623 y1 = y0;
2625 unit->m_freq = freq;
2626 unit->m_a0 = a0;
2627 unit->m_b1 = b1;
2628 unit->m_b2 = b2;
2629 } else {
2631 y0 = in + b1 * y1 + b2 * y2;
2632 ZOUT0(0) = a0 * (y0 + 2.f * y1 + y2);
2633 y2 = y1;
2634 y1 = y0;
2637 unit->m_y1 = zapgremlins(y1);
2638 unit->m_y2 = zapgremlins(y2);
2642 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2644 void HPF_Ctor(HPF* unit)
2646 if (unit->mBufLength == 1)
2647 SETCALC(HPF_next_1);
2648 else
2649 SETCALC(HPF_next);
2650 unit->m_a0 = 0.;
2651 unit->m_b1 = 0.;
2652 unit->m_b2 = 0.;
2653 unit->m_y1 = 0.;
2654 unit->m_y2 = 0.;
2655 unit->m_freq = -1e6f;
2657 HPF_next_1(unit, 1);
2661 void HPF_next(HPF* unit, int inNumSamples)
2663 float *out = ZOUT(0);
2664 float *in = ZIN(0);
2665 float freq = ZIN0(1);
2667 double y1 = unit->m_y1;
2668 double y2 = unit->m_y2;
2669 double a0 = unit->m_a0;
2670 double b1 = unit->m_b1;
2671 double b2 = unit->m_b2;
2673 if (freq != unit->m_freq) {
2674 float pfreq = freq * unit->mRate->mRadiansPerSample * 0.5;
2676 double C = tan(pfreq);
2677 double C2 = C * C;
2678 double sqrt2C = C * sqrt2_f;
2679 double next_a0 = 1. / (1. + sqrt2C + C2);
2680 double next_b1 = 2. * (1. - C2) * next_a0 ;
2681 double next_b2 = -(1. - sqrt2C + C2) * next_a0;
2683 //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);
2685 double a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2686 double b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2687 double b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2688 LOOP(unit->mRate->mFilterLoops,
2689 double y0 = ZXP(in) + b1 * y1 + b2 * y2;
2690 ZXP(out) = a0 * (y0 - 2. * y1 + y2);
2692 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2693 ZXP(out) = a0 * (y2 - 2. * y0 + y1);
2695 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2696 ZXP(out) = a0 * (y1 - 2. * y2 + y0);
2698 a0 += a0_slope;
2699 b1 += b1_slope;
2700 b2 += b2_slope;
2702 LOOP(unit->mRate->mFilterRemain,
2703 double y0 = ZXP(in) + b1 * y1 + b2 * y2;
2704 ZXP(out) = a0 * (y0 - 2. * y1 + y2);
2705 y2 = y1;
2706 y1 = y0;
2709 unit->m_freq = freq;
2710 unit->m_a0 = a0;
2711 unit->m_b1 = b1;
2712 unit->m_b2 = b2;
2713 } else {
2714 LOOP(unit->mRate->mFilterLoops,
2715 double y0 = ZXP(in) + b1 * y1 + b2 * y2;
2716 ZXP(out) = a0 * (y0 - 2. * y1 + y2);
2718 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2719 ZXP(out) = a0 * (y2 - 2. * y0 + y1);
2721 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2722 ZXP(out) = a0 * (y1 - 2. * y2 + y0);
2724 LOOP(unit->mRate->mFilterRemain,
2725 double y0 = ZXP(in) + b1 * y1 + b2 * y2;
2726 ZXP(out) = a0 * (y0 - 2. * y1 + y2);
2727 y2 = y1;
2728 y1 = y0;
2731 unit->m_y1 = zapgremlins(y1);
2732 unit->m_y2 = zapgremlins(y2);
2735 void HPF_next_1(HPF* unit, int inNumSamples)
2737 double in = ZIN0(0);
2738 double freq = ZIN0(1);
2740 double y1 = unit->m_y1;
2741 double y2 = unit->m_y2;
2742 double a0 = unit->m_a0;
2743 double b1 = unit->m_b1;
2744 double b2 = unit->m_b2;
2746 if (freq != unit->m_freq) {
2747 float pfreq = freq * unit->mRate->mRadiansPerSample * 0.5f;
2749 double C = tan(pfreq);
2750 double C2 = C * C;
2751 double sqrt2C = C * sqrt2_f;
2752 a0 = 1. / (1. + sqrt2C + C2);
2753 b1 = 2. * (1. - C2) * a0 ;
2754 b2 = -(1. - sqrt2C + C2) * a0;
2756 double y0 = in + b1 * y1 + b2 * y2;
2757 ZOUT0(0) = a0 * (y0 - 2. * y1 + y2);
2758 y2 = y1;
2759 y1 = y0;
2761 unit->m_freq = freq;
2762 unit->m_a0 = a0;
2763 unit->m_b1 = b1;
2764 unit->m_b2 = b2;
2765 } else {
2766 double y0 = in + b1 * y1 + b2 * y2;
2767 ZOUT0(0) = a0 * (y0 - 2. * y1 + y2);
2768 y2 = y1;
2769 y1 = y0;
2772 unit->m_y1 = zapgremlins(y1);
2773 unit->m_y2 = zapgremlins(y2);
2776 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2778 void BPF_Ctor(BPF* unit)
2780 //printf("BPF_Reset\n");
2781 if (unit->mBufLength == 1) {
2782 SETCALC(BPF_next_1);
2783 } else {
2784 SETCALC(BPF_next);
2786 unit->m_a0 = 0.f;
2787 unit->m_b1 = 0.f;
2788 unit->m_b2 = 0.f;
2789 unit->m_y1 = 0.f;
2790 unit->m_y2 = 0.f;
2791 unit->m_freq = 0.f;
2792 unit->m_bw = 0.f;
2794 BPF_next_1(unit, 1);
2797 void BPF_next(BPF* unit, int inNumSamples)
2799 //printf("BPF_next\n");
2801 float *out = ZOUT(0);
2802 float *in = ZIN(0);
2803 float freq = ZIN0(1);
2804 float bw = ZIN0(2);
2806 float y0;
2807 float y1 = unit->m_y1;
2808 float y2 = unit->m_y2;
2809 float a0 = unit->m_a0;
2810 float b1 = unit->m_b1;
2811 float b2 = unit->m_b2;
2813 if (freq != unit->m_freq || bw != unit->m_bw) {
2815 float pfreq = freq * unit->mRate->mRadiansPerSample;
2816 float pbw = bw * pfreq * 0.5f;
2818 float C = 1.f / tan(pbw);
2819 float D = 2.f * cos(pfreq);
2821 float next_a0 = 1.f / (1.f + C);
2822 float next_b1 = C * D * next_a0 ;
2823 float next_b2 = (1.f - C) * next_a0;
2825 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2826 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
2827 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2828 LOOP(unit->mRate->mFilterLoops,
2829 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2830 ZXP(out) = a0 * (y0 - y2);
2832 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2833 ZXP(out) = a0 * (y2 - y1);
2835 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2836 ZXP(out) = a0 * (y1 - y0);
2838 a0 += a0_slope;
2839 b1 += b1_slope;
2840 b2 += b2_slope;
2842 LOOP(unit->mRate->mFilterRemain,
2843 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2844 ZXP(out) = a0 * (y0 - y2);
2845 y2 = y1;
2846 y1 = y0;
2849 unit->m_freq = freq;
2850 unit->m_bw = bw;
2851 unit->m_a0 = a0;
2852 unit->m_b1 = b1;
2853 unit->m_b2 = b2;
2854 } else {
2855 LOOP(unit->mRate->mFilterLoops,
2856 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2857 ZXP(out) = a0 * (y0 - y2);
2859 y2 = ZXP(in) + b1 * y0 + b2 * y1;
2860 ZXP(out) = a0 * (y2 - y1);
2862 y1 = ZXP(in) + b1 * y2 + b2 * y0;
2863 ZXP(out) = a0 * (y1 - y0);
2865 LOOP(unit->mRate->mFilterRemain,
2866 y0 = ZXP(in) + b1 * y1 + b2 * y2;
2867 ZXP(out) = a0 * (y0 - y2);
2868 y2 = y1;
2869 y1 = y0;
2872 unit->m_y1 = zapgremlins(y1);
2873 unit->m_y2 = zapgremlins(y2);
2876 void BPF_next_1(BPF* unit, int inNumSamples)
2878 //printf("BPF_next_1\n");
2880 float in = ZIN0(0);
2881 float freq = ZIN0(1);
2882 float bw = ZIN0(2);
2884 float y0;
2885 float y1 = unit->m_y1;
2886 float y2 = unit->m_y2;
2887 float a0 = unit->m_a0;
2888 float b1 = unit->m_b1;
2889 float b2 = unit->m_b2;
2891 if (freq != unit->m_freq || bw != unit->m_bw) {
2893 float pfreq = freq * unit->mRate->mRadiansPerSample;
2894 float pbw = bw * pfreq * 0.5;
2896 float C = 1.f / tan(pbw);
2897 float D = 2.f * cos(pfreq);
2899 float a0 = 1.f / (1.f + C);
2900 float b1 = C * D * a0 ;
2901 float b2 = (1.f - C) * a0;
2903 y0 = in + b1 * y1 + b2 * y2;
2904 ZOUT0(0) = a0 * (y0 - y2);
2905 y2 = y1;
2906 y1 = y0;
2908 unit->m_freq = freq;
2909 unit->m_bw = bw;
2910 unit->m_a0 = a0;
2911 unit->m_b1 = b1;
2912 unit->m_b2 = b2;
2913 } else {
2914 y0 = in + b1 * y1 + b2 * y2;
2915 ZOUT0(0) = a0 * (y0 - y2);
2916 y2 = y1;
2917 y1 = y0;
2919 unit->m_y1 = zapgremlins(y1);
2920 unit->m_y2 = zapgremlins(y2);
2924 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2926 void BRF_Ctor(BRF* unit)
2928 //printf("BRF_Reset\n");
2929 if (unit->mBufLength == 1) {
2930 SETCALC(BRF_next_1);
2931 } else {
2932 SETCALC(BRF_next);
2934 unit->m_a0 = 0.f;
2935 unit->m_a1 = 0.f;
2936 unit->m_b2 = 0.f;
2937 unit->m_y1 = 0.f;
2938 unit->m_y2 = 0.f;
2939 unit->m_freq = 0.f;
2940 unit->m_bw = 0.f;
2941 BRF_next_1(unit, 1);
2945 void BRF_next(BRF* unit, int inNumSamples)
2947 //printf("BRF_next\n");
2949 float *out = ZOUT(0);
2950 float *in = ZIN(0);
2951 float freq = ZIN0(1);
2952 float bw = ZIN0(2);
2954 float ay;
2955 float y0;
2956 float y1 = unit->m_y1;
2957 float y2 = unit->m_y2;
2958 float a0 = unit->m_a0;
2959 float a1 = unit->m_a1;
2960 float b2 = unit->m_b2;
2962 if (freq != unit->m_freq || bw != unit->m_bw) {
2963 float pfreq = freq * unit->mRate->mRadiansPerSample;
2964 float pbw = bw * pfreq * 0.5f;
2966 float C = tan(pbw);
2967 float D = 2.f * cos(pfreq);
2969 float next_a0 = 1.f / (1.f + C);
2970 float next_a1 = -D * next_a0;
2971 float next_b2 = (1.f - C) * next_a0;
2973 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
2974 float a1_slope = (next_a1 - a1) * unit->mRate->mFilterSlope;
2975 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
2977 LOOP(unit->mRate->mFilterLoops,
2978 ay = a1 * y1;
2979 y0 = ZXP(in) - ay - b2 * y2;
2980 ZXP(out) = a0 * (y0 + y2) + ay;
2982 ay = a1 * y0;
2983 y2 = ZXP(in) - ay - b2 * y1;
2984 ZXP(out) = a0 * (y2 + y1) + ay;
2986 ay = a1 * y2;
2987 y1 = ZXP(in) - ay - b2 * y0;
2988 ZXP(out) = a0 * (y1 + y0) + ay;
2990 a0 += a0_slope;
2991 a1 += a1_slope;
2992 b2 += b2_slope;
2994 LOOP(unit->mRate->mFilterRemain,
2995 ay = a1 * y1;
2996 y0 = ZXP(in) - ay - b2 * y2;
2997 ZXP(out) = a0 * (y0 + y2) + ay;
2998 y2 = y1;
2999 y1 = y0;
3002 unit->m_freq = freq;
3003 unit->m_bw = bw;
3004 unit->m_a0 = a0;
3005 unit->m_a1 = a1;
3006 unit->m_b2 = b2;
3007 } else {
3008 LOOP(unit->mRate->mFilterLoops,
3009 ay = a1 * y1;
3010 y0 = ZXP(in) - ay - b2 * y2;
3011 ZXP(out) = a0 * (y0 + y2) + ay;
3013 ay = a1 * y0;
3014 y2 = ZXP(in) - ay - b2 * y1;
3015 ZXP(out) = a0 * (y2 + y1) + ay;
3017 ay = a1 * y2;
3018 y1 = ZXP(in) - ay - b2 * y0;
3019 ZXP(out) = a0 * (y1 + y0) + ay;
3021 LOOP(unit->mRate->mFilterRemain,
3022 ay = a1 * y1;
3023 y0 = ZXP(in) - ay - b2 * y2;
3024 ZXP(out) = a0 * (y0 + y2) + ay;
3025 y2 = y1;
3026 y1 = y0;
3029 unit->m_y1 = zapgremlins(y1);
3030 unit->m_y2 = zapgremlins(y2);
3035 void BRF_next_1(BRF* unit, int inNumSamples)
3037 //printf("BRF_next_1\n");
3039 float in = ZIN0(0);
3040 float freq = ZIN0(1);
3041 float bw = ZIN0(2);
3043 float ay;
3044 float y0;
3045 float y1 = unit->m_y1;
3046 float y2 = unit->m_y2;
3047 float a0 = unit->m_a0;
3048 float a1 = unit->m_a1;
3049 float b2 = unit->m_b2;
3051 if (freq != unit->m_freq || bw != unit->m_bw) {
3052 float pfreq = freq * unit->mRate->mRadiansPerSample;
3053 float pbw = bw * pfreq * 0.5f;
3055 float C = tan(pbw);
3056 float D = 2.f * cos(pfreq);
3058 float a0 = 1.f / (1.f + C);
3059 float a1 = -D * a0;
3060 float b2 = (1.f - C) * a0;
3062 ay = a1 * y1;
3063 y0 = in - ay - b2 * y2;
3064 ZOUT0(0) = a0 * (y0 + y2) + ay;
3065 y2 = y1;
3066 y1 = y0;
3068 unit->m_freq = freq;
3069 unit->m_bw = bw;
3070 unit->m_a0 = a0;
3071 unit->m_a1 = a1;
3072 unit->m_b2 = b2;
3073 } else {
3075 ay = a1 * y1;
3076 y0 = in - ay - b2 * y2;
3077 ZOUT0(0) = a0 * (y0 + y2) + ay;
3078 y2 = y1;
3079 y1 = y0;
3082 unit->m_y1 = zapgremlins(y1);
3083 unit->m_y2 = zapgremlins(y2);
3087 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3089 void MidEQ_Ctor(MidEQ* unit)
3091 //printf("MidEQ_Reset\n");
3092 SETCALC(MidEQ_next);
3093 unit->m_a0 = 0.f;
3094 unit->m_b1 = 0.f;
3095 unit->m_b2 = 0.f;
3096 unit->m_y1 = 0.f;
3097 unit->m_y2 = 0.f;
3098 unit->m_freq = 0.f;
3099 unit->m_bw = 0.f;
3100 unit->m_db = 0.f;
3101 PUSH_LOOPVALS
3102 MidEQ_next(unit, 1);
3103 POP_LOOPVALS
3107 void MidEQ_next(MidEQ* unit, int inNumSamples)
3109 //printf("MidEQ_next\n");
3111 float *out = ZOUT(0);
3112 float *in = ZIN(0);
3113 float freq = ZIN0(1);
3114 float bw = ZIN0(2);
3115 float db = ZIN0(3);
3117 float y0;
3118 float y1 = unit->m_y1;
3119 float y2 = unit->m_y2;
3120 float a0 = unit->m_a0;
3121 float b1 = unit->m_b1;
3122 float b2 = unit->m_b2;
3123 if (freq != unit->m_freq || bw != unit->m_bw || db != unit->m_db) {
3125 float amp = sc_dbamp(db) - 1.0f;
3126 float pfreq = freq * unit->mRate->mRadiansPerSample;
3127 float pbw = bw * pfreq * 0.5f;
3129 float C = 1.f / tan(pbw);
3130 float D = 2.f * cos(pfreq);
3132 float next_a0 = 1.f / (1.f + C);
3133 float next_b1 = C * D * next_a0 ;
3134 float next_b2 = (1.f - C) * next_a0;
3135 next_a0 *= amp;
3136 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
3137 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
3138 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
3139 float zin;
3140 LOOP(unit->mRate->mFilterLoops,
3141 zin = ZXP(in);
3142 y0 = zin + b1 * y1 + b2 * y2;
3143 ZXP(out) = zin + a0 * (y0 - y2);
3145 zin = ZXP(in);
3146 y2 = zin + b1 * y0 + b2 * y1;
3147 ZXP(out) = zin + a0 * (y2 - y1);
3149 zin = ZXP(in);
3150 y1 = zin + b1 * y2 + b2 * y0;
3151 ZXP(out) = zin + a0 * (y1 - y0);
3153 a0 += a0_slope;
3154 b1 += b1_slope;
3155 b2 += b2_slope;
3157 LOOP(unit->mRate->mFilterRemain,
3158 zin = ZXP(in);
3159 y0 = zin + b1 * y1 + b2 * y2;
3160 ZXP(out) = zin + a0 * (y0 - y2);
3161 y2 = y1;
3162 y1 = y0;
3165 unit->m_freq = freq;
3166 unit->m_bw = bw;
3167 unit->m_db = db;
3168 unit->m_a0 = a0;
3169 unit->m_b1 = b1;
3170 unit->m_b2 = b2;
3171 } else {
3172 float zin;
3173 LOOP(unit->mRate->mFilterLoops,
3174 zin = ZXP(in);
3175 y0 = zin + b1 * y1 + b2 * y2;
3176 ZXP(out) = zin + a0 * (y0 - y2);
3178 zin = ZXP(in);
3179 y2 = zin + b1 * y0 + b2 * y1;
3180 ZXP(out) = zin + a0 * (y2 - y1);
3182 zin = ZXP(in);
3183 y1 = zin + b1 * y2 + b2 * y0;
3184 ZXP(out) = zin + a0 * (y1 - y0);
3186 LOOP(unit->mRate->mFilterRemain,
3187 zin = ZXP(in);
3188 y0 = zin + b1 * y1 + b2 * y2;
3189 ZXP(out) = zin + a0 * (y0 - y2);
3190 y2 = y1;
3191 y1 = y0;
3194 unit->m_y1 = zapgremlins(y1);
3195 unit->m_y2 = zapgremlins(y2);
3198 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3200 static void Median_InitMedian(Median* unit, long size, float value);
3201 static float Median_InsertMedian(Median* unit, float value);
3203 void Median_Ctor(Median* unit)
3205 //printf("Median_Reset\n");
3206 SETCALC(Median_next);
3207 float in = ZIN0(1);
3208 unit->m_medianSize = sc_clip((int)ZIN0(0), 0, kMAXMEDIANSIZE);
3209 Median_InitMedian(unit, unit->m_medianSize, in);
3210 ZOUT0(0) = Median_InsertMedian(unit, in);
3214 float Median_InsertMedian(Median* unit, float value)
3216 long pos=-1;
3218 // keeps a sorted list of the previous n=size values
3219 // the oldest is removed and the newest is inserted.
3220 // values between the oldest and the newest are shifted over by one.
3222 // values and ages are both arrays that are 'size' long.
3223 // the median value is always values[size>>1]
3225 long last = unit->m_medianSize - 1;
3226 // find oldest bin and age the other bins.
3227 for (int i=0; i<unit->m_medianSize; ++i) {
3228 if (unit->m_medianAge[i] == last) { // is it the oldest bin ?
3229 pos = i;
3230 } else {
3231 unit->m_medianAge[i]++; // age the bin
3234 // move values to fill in place of the oldest and make a space for the newest
3235 // search lower if value is too small for the open space
3236 while (pos != 0 && value < unit->m_medianValue[pos-1]) {
3237 unit->m_medianValue[pos] = unit->m_medianValue[pos-1];
3238 unit->m_medianAge[pos] = unit->m_medianAge[pos-1];
3239 pos--;
3241 // search higher if value is too big for the open space
3242 while (pos != last && value > unit->m_medianValue[pos+1]) {
3243 unit->m_medianValue[pos] = unit->m_medianValue[pos+1];
3244 unit->m_medianAge[pos] = unit->m_medianAge[pos+1];
3245 pos++;
3247 unit->m_medianValue[pos] = value;
3248 unit->m_medianAge[pos] = 0; // this is the newest bin, age = 0
3249 return unit->m_medianValue[unit->m_medianSize>>1];
3252 void Median_InitMedian(Median* unit, long size, float value)
3254 // initialize the arrays with the first value
3255 unit->m_medianSize = size;
3256 for (int i=0; i<size; ++i) {
3257 unit->m_medianValue[i] = value;
3258 unit->m_medianAge[i] = i;
3262 void Median_next(Median* unit, int inNumSamples)
3264 //printf("Median_next_a\n");
3266 float *out = ZOUT(0);
3267 float *in = ZIN(1);
3269 LOOP1(inNumSamples,
3270 ZXP(out) = Median_InsertMedian(unit, ZXP(in));
3275 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3277 void Resonz_Ctor(Resonz* unit)
3279 //printf("Resonz_Reset\n");
3280 SETCALC(Resonz_next);
3281 unit->m_a0 = 0.f;
3282 unit->m_b1 = 0.f;
3283 unit->m_b2 = 0.f;
3284 unit->m_y1 = 0.f;
3285 unit->m_y2 = 0.f;
3286 unit->m_freq = 0.f;
3287 unit->m_rq = 0.f;
3288 PUSH_LOOPVALS
3289 Resonz_next(unit, 1);
3290 POP_LOOPVALS
3294 void Resonz_next(Resonz* unit, int inNumSamples)
3296 //printf("Resonz_next\n");
3298 float *out = ZOUT(0);
3299 float *in = ZIN(0);
3300 float freq = ZIN0(1);
3301 float rq = ZIN0(2);
3303 float y0;
3304 float y1 = unit->m_y1;
3305 float y2 = unit->m_y2;
3306 float a0 = unit->m_a0;
3307 float b1 = unit->m_b1;
3308 float b2 = unit->m_b2;
3310 if (freq != unit->m_freq || rq != unit->m_rq) {
3311 float ffreq = freq * unit->mRate->mRadiansPerSample;
3312 float B = ffreq * rq;
3313 float R = 1.f - B * 0.5f;
3314 float twoR = 2.f * R;
3315 float R2 = R * R;
3316 float cost = (twoR * cos(ffreq)) / (1.f + R2);
3317 float b1_next = twoR * cost;
3318 float b2_next = -R2;
3319 float a0_next = (1.f - R2) * 0.5f;
3320 float a0_slope = (a0_next - a0) * unit->mRate->mFilterSlope;
3321 float b1_slope = (b1_next - b1) * unit->mRate->mFilterSlope;
3322 float b2_slope = (b2_next - b2) * unit->mRate->mFilterSlope;
3323 LOOP(unit->mRate->mFilterLoops,
3324 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3325 ZXP(out) = a0 * (y0 - y2);
3327 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3328 ZXP(out) = a0 * (y2 - y1);
3330 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3331 ZXP(out) = a0 * (y1 - y0);
3333 a0 += a0_slope;
3334 b1 += b1_slope;
3335 b2 += b2_slope;
3337 LOOP(unit->mRate->mFilterRemain,
3338 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3339 ZXP(out) = a0 * (y0 - y2);
3340 y2 = y1;
3341 y1 = y0;
3344 unit->m_freq = freq;
3345 unit->m_rq = rq;
3346 unit->m_a0 = a0_next;
3347 unit->m_b1 = b1_next;
3348 unit->m_b2 = b2_next;
3349 } else {
3350 LOOP(unit->mRate->mFilterLoops,
3351 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3352 ZXP(out) = a0 * (y0 - y2);
3354 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3355 ZXP(out) = a0 * (y2 - y1);
3357 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3358 ZXP(out) = a0 * (y1 - y0);
3360 LOOP(unit->mRate->mFilterRemain,
3361 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3362 ZXP(out) = a0 * (y0 - y2);
3363 y2 = y1;
3364 y1 = y0;
3367 unit->m_y1 = zapgremlins(y1);
3368 unit->m_y2 = zapgremlins(y2);
3372 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3374 void Ringz_Ctor(Ringz* unit)
3376 //printf("Ringz_ctor\n");
3377 SETCALC(Ringz_next);
3378 unit->m_b1 = 0.f;
3379 unit->m_b2 = 0.f;
3380 unit->m_y1 = 0.f;
3381 unit->m_y2 = 0.f;
3382 unit->m_freq = 0.f;
3383 unit->m_decayTime = 0.f;
3384 PUSH_LOOPVALS
3385 Ringz_next(unit, 1);
3386 POP_LOOPVALS
3390 void Ringz_next(Ringz* unit, int inNumSamples)
3392 //printf("Ringz_next\n");
3394 float *out = ZOUT(0);
3395 float *in = ZIN(0);
3396 float freq = ZIN0(1);
3397 float decayTime = ZIN0(2);
3399 float y0;
3400 float y1 = unit->m_y1;
3401 float y2 = unit->m_y2;
3402 float a0 = 0.5f;
3403 float b1 = unit->m_b1;
3404 float b2 = unit->m_b2;
3406 if (freq != unit->m_freq || decayTime != unit->m_decayTime) {
3407 float ffreq = freq * unit->mRate->mRadiansPerSample;
3408 float R = decayTime == 0.f ? 0.f : exp(log001/(decayTime * SAMPLERATE));
3409 float twoR = 2.f * R;
3410 float R2 = R * R;
3411 float cost = (twoR * cos(ffreq)) / (1.f + R2);
3412 float b1_next = twoR * cost;
3413 float b2_next = -R2;
3414 float b1_slope = (b1_next - b1) * unit->mRate->mFilterSlope;
3415 float b2_slope = (b2_next - b2) * unit->mRate->mFilterSlope;
3416 LOOP(unit->mRate->mFilterLoops,
3417 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3418 ZXP(out) = a0 * (y0 - y2);
3420 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3421 ZXP(out) = a0 * (y2 - y1);
3423 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3424 ZXP(out) = a0 * (y1 - y0);
3426 b1 += b1_slope;
3427 b2 += b2_slope;
3429 LOOP(unit->mRate->mFilterRemain,
3430 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3431 ZXP(out) = a0 * (y0 - y2);
3432 y2 = y1;
3433 y1 = y0;
3436 unit->m_freq = freq;
3437 unit->m_decayTime = decayTime;
3438 unit->m_b1 = b1_next;
3439 unit->m_b2 = b2_next;
3440 } else {
3441 LOOP(unit->mRate->mFilterLoops,
3442 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3443 ZXP(out) = a0 * (y0 - y2);
3445 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3446 ZXP(out) = a0 * (y2 - y1);
3448 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3449 ZXP(out) = a0 * (y1 - y0);
3451 LOOP(unit->mRate->mFilterRemain,
3452 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3453 ZXP(out) = a0 * (y0 - y2);
3454 y2 = y1;
3455 y1 = y0;
3458 unit->m_y1 = zapgremlins(y1);
3459 unit->m_y2 = zapgremlins(y2);
3463 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3465 void Formlet_Ctor(Formlet* unit)
3467 //printf("Formlet_Reset\n");
3468 if (unit->mBufLength == 1) {
3469 SETCALC(Formlet_next_1);
3470 } else {
3471 SETCALC(Formlet_next);
3473 unit->m_b01 = 0.f;
3474 unit->m_b02 = 0.f;
3475 unit->m_y01 = 0.f;
3476 unit->m_y02 = 0.f;
3477 unit->m_b11 = 0.f;
3478 unit->m_b12 = 0.f;
3479 unit->m_y11 = 0.f;
3480 unit->m_y12 = 0.f;
3481 unit->m_freq = 0.f;
3482 unit->m_attackTime = 0.f;
3483 unit->m_decayTime = 0.f;
3484 Formlet_next_1(unit, 1);
3487 void Formlet_next(Formlet* unit, int inNumSamples)
3489 //printf("Formlet_next\n");
3491 float *out = ZOUT(0);
3492 float *in = ZIN(0);
3493 float freq = ZIN0(1);
3494 float attackTime = ZIN0(2);
3495 float decayTime = ZIN0(3);
3497 float y00;
3498 float y10;
3499 float y01 = unit->m_y01;
3500 float y11 = unit->m_y11;
3501 float y02 = unit->m_y02;
3502 float y12 = unit->m_y12;
3504 float b01 = unit->m_b01;
3505 float b11 = unit->m_b11;
3506 float b02 = unit->m_b02;
3507 float b12 = unit->m_b12;
3508 float ain;
3510 if (freq != unit->m_freq || decayTime != unit->m_decayTime || attackTime != unit->m_attackTime) {
3511 float ffreq = freq * unit->mRate->mRadiansPerSample;
3513 float R = decayTime == 0.f ? 0.f : exp(log001/(decayTime * SAMPLERATE));
3514 float twoR = 2.f * R;
3515 float R2 = R * R;
3516 float cost = (twoR * cos(ffreq)) / (1.f + R2);
3517 float b01_next = twoR * cost;
3518 float b02_next = -R2;
3519 float b01_slope = (b01_next - b01) * unit->mRate->mFilterSlope;
3520 float b02_slope = (b02_next - b02) * unit->mRate->mFilterSlope;
3522 R = attackTime == 0.f ? 0.f : exp(log001/(attackTime * SAMPLERATE));
3523 twoR = 2.f * R;
3524 R2 = R * R;
3525 cost = (twoR * cos(ffreq)) / (1.f + R2);
3526 float b11_next = twoR * cost;
3527 float b12_next = -R2;
3528 float b11_slope = (b11_next - b11) * unit->mRate->mFilterSlope;
3529 float b12_slope = (b12_next - b12) * unit->mRate->mFilterSlope;
3531 LOOP(unit->mRate->mFilterLoops,
3532 ain = ZXP(in);
3533 y00 = ain + b01 * y01 + b02 * y02;
3534 y10 = ain + b11 * y11 + b12 * y12;
3535 ZXP(out) = 0.25f * ((y00 - y02) - (y10 - y12));
3537 ain = ZXP(in);
3538 y02 = ain + b01 * y00 + b02 * y01;
3539 y12 = ain + b11 * y10 + b12 * y11;
3540 ZXP(out) = 0.25f * ((y02 - y01) - (y12 - y11));
3542 ain = ZXP(in);
3543 y01 = ain + b01 * y02 + b02 * y00;
3544 y11 = ain + b11 * y12 + b12 * y10;
3545 ZXP(out) = 0.25f * ((y01 - y00) - (y11 - y10));
3547 b01 += b01_slope;
3548 b02 += b02_slope;
3549 b11 += b11_slope;
3550 b12 += b12_slope;
3552 LOOP(unit->mRate->mFilterRemain,
3553 ain = ZXP(in);
3554 y00 = ain + b01 * y01 + b02 * y02;
3555 y10 = ain + b11 * y11 + b12 * y12;
3556 ZXP(out) = 0.25f * ((y00 - y02) - (y10 - y12));
3557 y02 = y01;
3558 y01 = y00;
3559 y12 = y11;
3560 y11 = y10;
3563 unit->m_freq = freq;
3564 unit->m_attackTime = attackTime;
3565 unit->m_decayTime = decayTime;
3566 unit->m_b01 = b01_next;
3567 unit->m_b02 = b02_next;
3568 unit->m_b11 = b11_next;
3569 unit->m_b12 = b12_next;
3570 } else {
3571 LOOP(unit->mRate->mFilterLoops,
3572 ain = ZXP(in);
3573 y00 = ain + b01 * y01 + b02 * y02;
3574 y10 = ain + b11 * y11 + b12 * y12;
3575 ZXP(out) = 0.25f * ((y00 - y02) - (y10 - y12));
3577 ain = ZXP(in);
3578 y02 = ain + b01 * y00 + b02 * y01;
3579 y12 = ain + b11 * y10 + b12 * y11;
3580 ZXP(out) = 0.25f * ((y02 - y01) - (y12 - y11));
3582 ain = ZXP(in);
3583 y01 = ain + b01 * y02 + b02 * y00;
3584 y11 = ain + b11 * y12 + b12 * y10;
3585 ZXP(out) = 0.25f * ((y01 - y00) - (y11 - y10));
3587 LOOP(unit->mRate->mFilterRemain,
3588 ain = ZXP(in);
3589 y00 = ain + b01 * y01 + b02 * y02;
3590 y10 = ain + b11 * y11 + b12 * y12;
3591 ZXP(out) = 0.25f * ((y00 - y02) - (y10 - y12));
3592 y02 = y01;
3593 y01 = y00;
3594 y12 = y11;
3595 y11 = y10;
3598 unit->m_y01 = y01;
3599 unit->m_y02 = y02;
3600 unit->m_y11 = y11;
3601 unit->m_y12 = y12;
3604 void Formlet_next_1(Formlet* unit, int inNumSamples)
3606 //printf("Formlet_next\n");
3608 float in = ZIN0(0);
3609 float freq = ZIN0(1);
3610 float attackTime = ZIN0(2);
3611 float decayTime = ZIN0(3);
3613 float y00;
3614 float y10;
3615 float y01 = unit->m_y01;
3616 float y11 = unit->m_y11;
3617 float y02 = unit->m_y02;
3618 float y12 = unit->m_y12;
3620 float b01 = unit->m_b01;
3621 float b11 = unit->m_b11;
3622 float b02 = unit->m_b02;
3623 float b12 = unit->m_b12;
3624 float ain;
3626 if (freq != unit->m_freq || decayTime != unit->m_decayTime || attackTime != unit->m_attackTime) {
3627 float ffreq = freq * unit->mRate->mRadiansPerSample;
3629 float R = decayTime == 0.f ? 0.f : exp(log001/(decayTime * SAMPLERATE));
3630 float twoR = 2.f * R;
3631 float R2 = R * R;
3632 float cost = (twoR * cos(ffreq)) / (1.f + R2);
3633 b01 = twoR * cost;
3634 b02 = -R2;
3636 R = attackTime == 0.f ? 0.f : exp(log001/(attackTime * SAMPLERATE));
3637 twoR = 2.f * R;
3638 R2 = R * R;
3639 cost = (twoR * cos(ffreq)) / (1.f + R2);
3640 b11 = twoR * cost;
3641 b12 = -R2;
3643 ain = in;
3644 y00 = ain + b01 * y01 + b02 * y02;
3645 y10 = ain + b11 * y11 + b12 * y12;
3646 ZOUT0(0) = 0.25f * ((y00 - y02) - (y10 - y12));
3648 y02 = y01;
3649 y01 = y00;
3650 y12 = y11;
3651 y11 = y10;
3653 unit->m_freq = freq;
3654 unit->m_attackTime = attackTime;
3655 unit->m_decayTime = decayTime;
3656 unit->m_b01 = b01;
3657 unit->m_b02 = b02;
3658 unit->m_b11 = b11;
3659 unit->m_b12 = b12;
3660 } else {
3661 ain = in;
3662 y00 = ain + b01 * y01 + b02 * y02;
3663 y10 = ain + b11 * y11 + b12 * y12;
3664 ZOUT0(0) = 0.25f * ((y00 - y02) - (y10 - y12));
3666 y02 = y01;
3667 y01 = y00;
3668 y12 = y11;
3669 y11 = y10;
3671 unit->m_y01 = y01;
3672 unit->m_y02 = y02;
3673 unit->m_y11 = y11;
3674 unit->m_y12 = y12;
3678 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3680 void FOS_Ctor(FOS* unit)
3682 //printf("FOS_Reset\n");
3683 if (unit->mBufLength == 1) {
3684 SETCALC(FOS_next_1);
3685 } else {
3686 if (INRATE(1) == calc_FullRate
3687 && INRATE(2) == calc_FullRate
3688 && INRATE(3) == calc_FullRate) {
3689 SETCALC(FOS_next_a);
3690 } else {
3691 SETCALC(FOS_next_k);
3694 unit->m_y1 = 0.f;
3695 unit->m_a0 = 0.f;
3696 unit->m_a1 = 0.f;
3697 unit->m_b1 = 0.f;
3698 FOS_next_1(unit, 1);
3701 void FOS_next_a(FOS* unit, int inNumSamples)
3703 float *out = ZOUT(0);
3704 float *in = ZIN(0);
3705 float *a0 = ZIN(1);
3706 float *a1 = ZIN(2);
3707 float *b1 = ZIN(3);
3709 float y1 = unit->m_y1;
3710 LOOP1(inNumSamples,
3711 float y0 = ZXP(in) + ZXP(b1) * y1;
3712 ZXP(out) = ZXP(a0) * y0 + ZXP(a1) * y1;
3713 y1 = y0;
3715 unit->m_y1 = zapgremlins(y1);
3718 void FOS_next_1(FOS* unit, int inNumSamples)
3720 float in = ZIN0(0);
3721 float a0 = ZIN0(1);
3722 float a1 = ZIN0(2);
3723 float b1 = ZIN0(3);
3725 float y1 = unit->m_y1;
3727 float y0 = in + b1 * y1;
3728 ZOUT0(0) = a0 * y0 + a1 * y1;
3729 y1 = y0;
3731 unit->m_y1 = zapgremlins(y1);
3735 void FOS_next_k(FOS* unit, int inNumSamples)
3737 float *out = ZOUT(0);
3738 float *in = ZIN(0);
3739 float next_a0 = ZIN0(1);
3740 float next_a1 = ZIN0(2);
3741 float next_b1 = ZIN0(3);
3743 float y1 = unit->m_y1;
3744 float a0 = unit->m_a0;
3745 float a1 = unit->m_a1;
3746 float b1 = unit->m_b1;
3747 float a0_slope = CALCSLOPE(next_a0, a0);
3748 float a1_slope = CALCSLOPE(next_a1, a1);
3749 float b1_slope = CALCSLOPE(next_b1, b1);
3750 LOOP1(inNumSamples,
3751 float y0 = ZXP(in) + b1 * y1;
3752 ZXP(out) = a0 * y0 + a1 * y1;
3753 y1 = y0;
3755 a0 += a0_slope;
3756 a1 += a1_slope;
3757 b1 += b1_slope;
3759 unit->m_y1 = zapgremlins(y1);
3760 unit->m_a0 = next_a0;
3761 unit->m_a1 = next_a1;
3762 unit->m_b1 = next_b1;
3765 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3767 void SOS_Ctor(SOS* unit)
3769 // printf("SOS_Reset\n");
3770 if (unit->mBufLength != 1) {
3771 if (INRATE(1) == calc_FullRate
3772 && INRATE(2) == calc_FullRate
3773 && INRATE(3) == calc_FullRate
3774 && INRATE(4) == calc_FullRate
3775 && INRATE(5) == calc_FullRate) {
3776 SETCALC(SOS_next_a);
3777 // printf("SOS_next_a\n");
3778 } else {
3779 SETCALC(SOS_next_k);
3780 // printf("SOS_next_k\n");
3782 } else {
3783 SETCALC(SOS_next_1);
3784 // printf("SOS_next_1\n");
3786 unit->m_y1 = 0.f;
3787 unit->m_y2 = 0.f;
3788 unit->m_a0 = 0.f;
3789 unit->m_a1 = 0.f;
3790 unit->m_a2 = 0.f;
3791 unit->m_b1 = 0.f;
3792 unit->m_b2 = 0.f;
3793 SOS_next_1(unit, 1);
3796 void SOS_next_a(SOS *unit, int inNumSamples)
3798 float *out = ZOUT(0);
3799 float *in = ZIN(0);
3800 float *a0 = ZIN(1);
3801 float *a1 = ZIN(2);
3802 float *a2 = ZIN(3);
3803 float *b1 = ZIN(4);
3804 float *b2 = ZIN(5);
3806 float y0;
3807 float y1 = unit->m_y1;
3808 float y2 = unit->m_y2;
3809 LOOP(unit->mRate->mFilterLoops,
3810 y0 = ZXP(in) + ZXP(b1) * y1 + ZXP(b2) * y2;
3811 ZXP(out) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2;
3813 y2 = ZXP(in) + ZXP(b1) * y0 + ZXP(b2) * y1;
3814 ZXP(out) = ZXP(a0) * y2 + ZXP(a1) * y0 + ZXP(a2) * y1;
3816 y1 = ZXP(in) + ZXP(b1) * y2 + ZXP(b2) * y0;
3817 ZXP(out) = ZXP(a0) * y1 + ZXP(a1) * y2 + ZXP(a2) * y0;
3819 LOOP(unit->mRate->mFilterRemain,
3820 y0 = ZXP(in) + ZXP(b1) * y1 + ZXP(b2) * y2;
3821 ZXP(out) = ZXP(a0) * y0 + ZXP(a1) * y1 + ZXP(a2) * y2;
3822 y2 = y1;
3823 y1 = y0;
3826 unit->m_y1 = zapgremlins(y1);
3827 unit->m_y2 = zapgremlins(y2);
3830 void SOS_next_k(SOS *unit, int inNumSamples)
3832 float *out = ZOUT(0);
3833 float *in = ZIN(0);
3834 float next_a0 = ZIN0(1);
3835 float next_a1 = ZIN0(2);
3836 float next_a2 = ZIN0(3);
3837 float next_b1 = ZIN0(4);
3838 float next_b2 = ZIN0(5);
3840 float y0;
3841 float y1 = unit->m_y1;
3842 float y2 = unit->m_y2;
3843 float a0 = unit->m_a0;
3844 float a1 = unit->m_a1;
3845 float a2 = unit->m_a2;
3846 float b1 = unit->m_b1;
3847 float b2 = unit->m_b2;
3848 float a0_slope = (next_a0 - a0) * unit->mRate->mFilterSlope;
3849 float a1_slope = (next_a1 - a1) * unit->mRate->mFilterSlope;
3850 float a2_slope = (next_a2 - a2) * unit->mRate->mFilterSlope;
3851 float b1_slope = (next_b1 - b1) * unit->mRate->mFilterSlope;
3852 float b2_slope = (next_b2 - b2) * unit->mRate->mFilterSlope;
3853 LOOP(unit->mRate->mFilterLoops,
3854 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3855 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
3857 y2 = ZXP(in) + b1 * y0 + b2 * y1;
3858 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
3860 y1 = ZXP(in) + b1 * y2 + b2 * y0;
3861 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
3863 a0 += a0_slope;
3864 a1 += a1_slope;
3865 a2 += a2_slope;
3866 b1 += b1_slope;
3867 b2 += b2_slope;
3869 LOOP(unit->mRate->mFilterRemain,
3870 y0 = ZXP(in) + b1 * y1 + b2 * y2;
3871 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
3872 y2 = y1;
3873 y1 = y0;
3876 unit->m_a0 = a0;
3877 unit->m_a1 = a1;
3878 unit->m_a2 = a2;
3879 unit->m_b1 = b1;
3880 unit->m_b2 = b2;
3881 unit->m_y1 = zapgremlins(y1);
3882 unit->m_y2 = zapgremlins(y2);
3885 void SOS_next_1(SOS *unit, int inNumSamples) // optimized for SOS.kr
3887 float in = ZIN0(0);
3888 float a0 = ZIN0(1);
3889 float a1 = ZIN0(2);
3890 float a2 = ZIN0(3);
3891 float b1 = ZIN0(4);
3892 float b2 = ZIN0(5);
3894 float y0;
3895 float y1 = unit->m_y1;
3896 float y2 = unit->m_y2;
3898 y0 = in + b1 * y1 + b2 * y2;
3899 ZOUT0(0) = a0 * y0 + a1 * y1 + a2 * y2;
3900 y2 = y1;
3901 y1 = y0;
3903 unit->m_y1 = zapgremlins(y1);
3904 unit->m_y2 = zapgremlins(y2);
3907 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3909 void Compander_Ctor(Compander* unit)
3911 //printf("Compander_Reset\n");
3912 SETCALC(Compander_next);
3913 unit->m_clamp = 0.f;
3914 unit->m_clampcoef = 0.f;
3915 unit->m_relax = 0.f;
3916 unit->m_relaxcoef = 0.f;
3917 unit->m_prevmaxval = 0.f;
3918 unit->m_gain = 0.f;
3919 Compander_next(unit, 1);
3922 void Compander_next(Compander* unit, int inNumSamples)
3924 float *out = ZOUT(0);
3925 float *in = ZIN(0);
3926 float *control = ZIN(1);
3927 float thresh = ZIN0(2);
3928 float slope_below = ZIN0(3);
3929 float slope_above = ZIN0(4);
3930 float clamp = ZIN0(5);
3931 float relax = ZIN0(6);
3933 if (clamp != unit->m_clamp) {
3934 unit->m_clampcoef = clamp == 0.0 ? 0.0 : exp(log1/(clamp * SAMPLERATE));
3935 unit->m_clamp = clamp;
3937 if (relax != unit->m_relax) {
3938 unit->m_relaxcoef = relax == 0.0 ? 0.0 : exp(log1/(relax * SAMPLERATE));
3939 unit->m_relax = relax;
3942 float gain = unit->m_gain;
3944 float relaxcoef = unit->m_relaxcoef;
3945 float clampcoef = unit->m_clampcoef;
3947 float prevmaxval = unit->m_prevmaxval;
3949 float val;
3950 LOOP1(inNumSamples,
3951 val = std::abs(ZXP(control));
3952 if (val < prevmaxval) {
3953 val = val + (prevmaxval - val) * relaxcoef;
3954 } else {
3955 val = val + (prevmaxval - val) * clampcoef;
3957 prevmaxval = val;
3960 unit->m_prevmaxval = prevmaxval;
3962 float next_gain;//,absx;
3963 if (prevmaxval < thresh) {
3964 if (slope_below == 1.f) {
3965 next_gain = 1.f;
3966 } else {
3967 next_gain = pow(prevmaxval / thresh, slope_below - 1.f);
3968 //blows up here
3969 float32 absx = std::abs(next_gain);
3970 //zap gremlins, but returns 0. if gain is too small and 1. if gain is too big
3971 next_gain =
3972 (absx < (float32)1e-15) ? (float32)0. :
3973 (absx > (float32)1e15) ? (float32)1. : next_gain;
3975 } else {
3976 if (slope_above == 1.f) {
3977 next_gain = 1.f;
3978 } else {
3979 next_gain = pow(prevmaxval / thresh, slope_above - 1.f);
3983 float gain_slope = CALCSLOPE(next_gain, gain);
3984 LOOP1(inNumSamples, ZXP(out) = ZXP(in) * gain; gain += gain_slope;);
3985 unit->m_gain = gain;
3988 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3991 void Normalizer_Dtor(Normalizer* unit)
3993 RTFree(unit->mWorld, unit->m_table);
3996 void Normalizer_Ctor(Normalizer* unit)
3998 SETCALC(Normalizer_next);
3999 //printf("Normalizer_Reset\n");
4001 float dur = ZIN0(2);
4002 unit->m_bufsize = (long)(ceil(dur * SAMPLERATE));
4003 long allocsize = unit->m_bufsize * 3;
4004 //allocsize = NEXTPOWEROFTWO(allocsize);
4006 unit->m_table = (float*)RTAlloc(unit->mWorld, allocsize * sizeof(float));
4008 unit->m_pos = 0;
4009 unit->m_flips = 0;
4010 unit->m_level = 1.f;
4011 unit->m_slope = 0.f;
4012 unit->m_prevmaxval = 0.0;
4013 unit->m_curmaxval = 0.0;
4014 unit->m_slopefactor = 1.f / unit->m_bufsize;
4016 unit->m_xinbuf = unit->m_table - ZOFF;
4017 unit->m_xmidbuf = unit->m_xinbuf + unit->m_bufsize;
4018 unit->m_xoutbuf = unit->m_xmidbuf + unit->m_bufsize;
4019 Normalizer_next(unit, 1);
4023 void Normalizer_next(Normalizer* unit, int inNumSamples)
4025 float *out = ZOUT(0);
4026 float *in = ZIN(0);
4027 float amp = ZIN0(1);
4029 long pos = unit->m_pos;
4030 float slope = unit->m_slope;
4031 float level = unit->m_level;
4032 float curmaxval = unit->m_curmaxval;
4033 float val;
4035 long bufsize = unit->m_bufsize;
4036 long buf_remain = bufsize - pos;
4038 long remain = inNumSamples;
4039 while (remain > 0) {
4040 long nsmps = sc_min(remain, buf_remain);
4041 float* xinbuf = unit->m_xinbuf + pos;
4042 float* xoutbuf = unit->m_xoutbuf + pos;
4043 if (unit->m_flips >= 2) {
4044 LOOP(nsmps,
4045 ZXP(xinbuf) = val = ZXP(in);
4046 ZXP(out) = level * ZXP(xoutbuf);
4047 level += slope;
4048 val = std::abs(val);
4049 if (val > curmaxval) curmaxval = val;
4051 } else {
4052 LOOP(nsmps,
4053 ZXP(xinbuf) = val = ZXP(in);
4054 ZXP(out) = 0.f;
4055 level += slope;
4056 val = std::abs(val);
4057 if (val > curmaxval) curmaxval = val;
4060 pos += nsmps;
4061 if (pos >= bufsize) {
4062 pos = 0;
4063 buf_remain = bufsize;
4065 float maxval2 = sc_max(unit->m_prevmaxval, curmaxval);
4066 unit->m_prevmaxval = curmaxval;
4067 unit->m_curmaxval = curmaxval = 0.f;
4069 float next_level;
4070 if (maxval2 <= 0.00001f) next_level = 100000.f * amp;
4071 else next_level = amp / maxval2;
4073 slope = unit->m_slope = (next_level - level) * unit->m_slopefactor;
4075 float* temp = unit->m_xoutbuf;
4076 unit->m_xoutbuf = unit->m_xmidbuf;
4077 unit->m_xmidbuf = unit->m_xinbuf;
4078 unit->m_xinbuf = temp;
4080 unit->m_flips++;
4082 remain -= nsmps;
4085 unit->m_pos = pos;
4086 unit->m_level = level;
4087 unit->m_curmaxval = curmaxval;
4090 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4092 void Limiter_Dtor(Limiter* unit)
4094 RTFree(unit->mWorld, unit->m_table);
4097 void Limiter_Ctor(Limiter* unit)
4099 //printf("Limiter_Reset\n");
4100 SETCALC(Limiter_next);
4102 float dur = ZIN0(2);
4103 unit->m_bufsize = (long)(ceil(dur * SAMPLERATE));
4104 long allocsize = unit->m_bufsize * 3;
4105 allocsize = NEXTPOWEROFTWO(allocsize);
4107 unit->m_table = (float*)RTAlloc(unit->mWorld, allocsize * sizeof(float));
4109 unit->m_flips = 0;
4110 unit->m_pos = 0;
4111 unit->m_slope = 0.f;
4112 unit->m_level = 1.f;
4113 unit->m_prevmaxval = 0.0;
4114 unit->m_curmaxval = 0.0;
4115 unit->m_slopefactor = 1.f / unit->m_bufsize;
4117 unit->m_xinbuf = unit->m_table - ZOFF;
4118 unit->m_xmidbuf = unit->m_xinbuf + unit->m_bufsize;
4119 unit->m_xoutbuf = unit->m_xmidbuf + unit->m_bufsize;
4120 Limiter_next(unit, 1);
4124 void Limiter_next(Limiter* unit, int inNumSamples)
4126 float *out = ZOUT(0);
4127 float *in = ZIN(0);
4128 float amp = ZIN0(1);
4130 long pos = unit->m_pos;
4131 float slope = unit->m_slope;
4132 float level = unit->m_level;
4133 float curmaxval = unit->m_curmaxval;
4134 float val;
4136 long bufsize = unit->m_bufsize;
4137 long buf_remain = bufsize - pos;
4139 long remain = inNumSamples;
4140 while (remain > 0) {
4141 long nsmps = sc_min(remain, buf_remain);
4142 float* xinbuf = unit->m_xinbuf + pos;
4143 float* xoutbuf = unit->m_xoutbuf + pos;
4144 if (unit->m_flips >= 2) {
4145 LOOP(nsmps,
4146 ZXP(xinbuf) = val = ZXP(in);
4147 ZXP(out) = level * ZXP(xoutbuf);
4148 level += slope;
4149 val = std::abs(val);
4150 if (val > curmaxval) curmaxval = val;
4152 } else {
4153 LOOP(nsmps,
4154 ZXP(xinbuf) = val = ZXP(in);
4155 ZXP(out) = 0.f;
4156 level += slope;
4157 val = std::abs(val);
4158 if (val > curmaxval) curmaxval = val;
4161 pos += nsmps;
4162 if (pos >= bufsize) {
4163 pos = 0;
4164 buf_remain = bufsize;
4166 float maxval2 = sc_max(unit->m_prevmaxval, curmaxval);
4167 unit->m_prevmaxval = curmaxval;
4168 unit->m_curmaxval = curmaxval = 0.f;
4170 float next_level;
4171 if (maxval2 > amp) next_level = amp / maxval2;
4172 else next_level = 1.0;
4174 slope = unit->m_slope = (next_level - level) * unit->m_slopefactor;
4176 float* temp = unit->m_xoutbuf;
4177 unit->m_xoutbuf = unit->m_xmidbuf;
4178 unit->m_xmidbuf = unit->m_xinbuf;
4179 unit->m_xinbuf = temp;
4181 unit->m_flips++;
4183 remain -= nsmps;
4186 unit->m_pos = pos;
4187 unit->m_level = level;
4188 unit->m_curmaxval = curmaxval;
4191 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4193 void Amplitude_Ctor(Amplitude* unit)
4195 if(INRATE(1) != calc_ScalarRate || INRATE(2) != calc_ScalarRate) {
4196 if(INRATE(0) == calc_FullRate && unit->mCalcRate == calc_BufRate){
4197 SETCALC(Amplitude_next_atok_kk);
4198 } else {
4199 SETCALC(Amplitude_next_kk);
4202 } else {
4203 if(INRATE(0) == calc_FullRate && unit->mCalcRate == calc_BufRate){
4204 SETCALC(Amplitude_next_atok);
4205 } else {
4206 SETCALC(Amplitude_next);
4210 float clamp = ZIN0(1);
4211 unit->m_clampcoef = clamp == 0.0 ? 0.0 : exp(log1/(clamp * SAMPLERATE));
4213 float relax = ZIN0(2);
4214 unit->m_relaxcoef = relax == 0.0 ? 0.0 : exp(log1/(relax * SAMPLERATE));
4216 unit->m_previn = std::abs(ZIN0(0));
4217 Amplitude_next(unit, 1);
4220 void Amplitude_next(Amplitude* unit, int inNumSamples)
4222 float *out = ZOUT(0);
4223 float *in = ZIN(0);
4225 float relaxcoef = unit->m_relaxcoef;
4226 float clampcoef = unit->m_clampcoef;
4227 float previn = unit->m_previn;
4229 float val;
4230 LOOP1(inNumSamples,
4231 val = std::abs(ZXP(in));
4232 if (val < previn) {
4233 val = val + (previn - val) * relaxcoef;
4234 } else {
4235 val = val + (previn - val) * clampcoef;
4237 ZXP(out) = previn = val;
4240 unit->m_previn = previn;
4243 void Amplitude_next_atok(Amplitude* unit, int inNumSamples)
4245 float *in = ZIN(0);
4247 float relaxcoef = unit->m_relaxcoef;
4248 float clampcoef = unit->m_clampcoef;
4249 float previn = unit->m_previn;
4251 float val;
4252 LOOP1(FULLBUFLENGTH,
4253 val = std::abs(ZXP(in));
4254 if (val < previn) {
4255 val = val + (previn - val) * relaxcoef;
4256 } else {
4257 val = val + (previn - val) * clampcoef;
4259 previn = val;
4261 ZOUT0(0) = val;
4263 unit->m_previn = previn;
4266 void Amplitude_next_kk(Amplitude* unit, int inNumSamples)
4268 float *out = ZOUT(0);
4269 float *in = ZIN(0);
4270 float relaxcoef, clampcoef;
4272 if(ZIN0(1) != unit->m_clamp_in) {
4273 clampcoef = unit->m_clampcoef = exp(log1/(ZIN0(1) * SAMPLERATE));
4274 unit->m_clamp_in = ZIN0(1);
4275 } else {
4276 clampcoef = unit->m_clampcoef;
4279 if(ZIN0(2) != unit->m_relax_in) {
4280 relaxcoef = unit->m_relaxcoef = exp(log1/(ZIN0(2) * SAMPLERATE));
4281 unit->m_relax_in = ZIN0(2);
4282 } else {
4283 relaxcoef = unit->m_relaxcoef;
4286 float previn = unit->m_previn;
4288 float val;
4289 LOOP1(inNumSamples,
4290 val = std::abs(ZXP(in));
4291 if (val < previn) {
4292 val = val + (previn - val) * relaxcoef;
4293 } else {
4294 val = val + (previn - val) * clampcoef;
4296 ZXP(out) = previn = val;
4299 unit->m_previn = previn;
4302 void Amplitude_next_atok_kk(Amplitude* unit, int inNumSamples)
4304 float *in = ZIN(0);
4305 float relaxcoef, clampcoef;
4307 if(ZIN0(1) != unit->m_clamp_in) {
4308 clampcoef = unit->m_clampcoef = exp(log1/(ZIN0(1) * SAMPLERATE));
4309 unit->m_clamp_in = ZIN0(1);
4310 } else {
4311 clampcoef = unit->m_clampcoef;
4314 if(ZIN0(2) != unit->m_relax_in) {
4315 relaxcoef = unit->m_relaxcoef = exp(log1/(ZIN0(2) * SAMPLERATE));
4316 unit->m_relax_in = ZIN0(2);
4317 } else {
4318 relaxcoef = unit->m_relaxcoef;
4321 float previn = unit->m_previn;
4323 float val;
4324 LOOP1(FULLBUFLENGTH,
4325 val = std::abs(ZXP(in));
4326 if (val < previn) {
4327 val = val + (previn - val) * relaxcoef;
4328 } else {
4329 val = val + (previn - val) * clampcoef;
4331 previn = val;
4333 ZOUT0(0) = val;
4335 unit->m_previn = previn;
4338 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4340 void DetectSilence_Ctor(DetectSilence* unit)
4342 //printf("DetectSilence_Reset\n");
4343 SETCALC(DetectSilence_next);
4345 unit->mThresh = ZIN0(1);
4346 unit->mEndCounter = (int32)(SAMPLERATE * ZIN0(2));
4347 unit->mCounter = -1;
4351 void DetectSilence_next(DetectSilence* unit, int inNumSamples)
4353 float thresh = unit->mThresh;
4354 int counter = unit->mCounter;
4355 float val;
4357 // I thought of a better way to do this...
4359 for (int i=0; i<inNumSamples; ++i) {
4360 float val = std::abs(ZXP(in));
4361 if (val >= thresh) counter = 0;
4362 else if (counter >= 0) {
4363 if (++counter >= unit->mEndCounter && doneAction) {
4364 int doneAction = (int)ZIN0(3);
4365 DoneAction(doneAction, unit);
4366 SETCALC(DetectSilence_done);
4369 ZXP(out) = 0.f;
4372 float *in = IN(0);
4373 float *out = OUT(0);
4374 for (int i=0; i<inNumSamples; ++i) {
4375 val = std::abs(*in++);
4376 if (val > thresh) {
4377 counter = 0;
4378 *out++ = 0.f;
4379 } else if (counter >= 0) {
4380 if (++counter >= unit->mEndCounter) {
4381 int doneAction = (int)ZIN0(3);
4382 DoneAction(doneAction, unit);
4383 *out++ = 1.f;
4384 // SETCALC(DetectSilence_done);
4385 } else {
4386 *out++ = 0.f;
4389 else
4390 *out++ = 0.f;
4392 unit->mCounter = counter;
4395 void DetectSilence_done(DetectSilence* unit, int inNumSamples)
4398 ///////////////////////////////////////////////////////////////////////////////////////////////////////
4399 // Based on HilbertIIR from SC2
4400 // a 12 pole (6 per side) Hilbert IIR filter
4401 // based on Sean Costello and Bernie Hutchins
4402 // created by jl anderson - 7 jan 2001
4403 // UGen created by Josh Parmenter
4405 #define HILBERT_FILTER \
4406 y0_1 = thisin - (coefs[0]) * y1[0]; \
4407 ay1 = coefs[0] * y0_1 + 1 * y1[0]; \
4408 y1[0] = y0_1; \
4409 y0_2 = ay1 - (coefs[1]) * y1[1]; \
4410 ay2 = coefs[1] * y0_2 + 1 * y1[1]; \
4411 y1[1] = y0_2; \
4412 y0_3 = ay2 - (coefs[2]) * y1[2]; \
4413 ay3 = coefs[2] * y0_3 + 1 * y1[2]; \
4414 y1[2] = y0_3; \
4415 y0_4 = ay3 - (coefs[3]) * y1[3]; \
4416 ay4 =coefs[3] * y0_4 + 1 * y1[3]; \
4417 y1[3] = y0_4; \
4418 y0_5 = ay4 - (coefs[4]) * y1[4]; \
4419 ay5 = coefs[4] * y0_5 + 1 * y1[4]; \
4420 y1[4] = y0_5; \
4421 y0_6 = ay5 - (coefs[5]) * y1[5]; \
4422 ay6 = coefs[5] * y0_6 + 1 * y1[5]; \
4423 y1[5] = y0_6; \
4425 y0_7 = thisin - (coefs[6]) * y1[6]; \
4426 ay7 = coefs[6] * y0_7 + 1 * y1[6]; \
4427 y1[6] = y0_7; \
4428 y0_8 = ay7 - (coefs[7]) * y1[7]; \
4429 ay8 = coefs[7] * y0_8 + 1 * y1[7]; \
4430 y1[7] = y0_8; \
4431 y0_9 = ay8 - (coefs[8]) * y1[8]; \
4432 ay9 = coefs[8] * y0_9 + 1 * y1[8]; \
4433 y1[8] = y0_9; \
4434 y0_10 = ay9 - (coefs[9]) * y1[9]; \
4435 ay10 = coefs[9] * y0_10 + 1 * y1[9]; \
4436 y1[9] = y0_10; \
4437 y0_11 = ay10 - (coefs[10]) * y1[10]; \
4438 ay11 = coefs[10] * y0_11 + 1 * y1[10]; \
4439 y1[10] = y0_11; \
4440 y0_12 = ay11 - (coefs[11]) * y1[11]; \
4441 ay12 = coefs[11] * y0_12 + 1 * y1[11]; \
4442 y1[11] = y0_12; \
4445 void Hilbert_Ctor(Hilbert *unit)
4447 // calculate coefs based on SampleRate, store in the struct
4448 SETCALC(Hilbert_next);
4450 float gamconst = (15.0f * pi_f) / SAMPLERATE;
4451 float gamma01 = gamconst * 0.3609f;
4452 float gamma02 = gamconst * 2.7412f;
4453 float gamma03 = gamconst * 11.1573f;
4454 float gamma04 = gamconst * 44.7581f;
4455 float gamma05 = gamconst * 179.6242f;
4456 float gamma06 = gamconst * 798.4578f;
4457 float gamma07 = gamconst * 1.2524f;
4458 float gamma08 = gamconst * 5.5671f;
4459 float gamma09 = gamconst * 22.3423f;
4460 float gamma10 = gamconst * 89.6271f;
4461 float gamma11 = gamconst * 364.7914f;
4462 float gamma12 = gamconst * 2770.1114f;
4463 unit->m_coefs[0] = (gamma01 - 1.f) / (gamma01 + 1.f);
4464 unit->m_coefs[1] = (gamma02 - 1.f) / (gamma02 + 1.f);
4465 unit->m_coefs[2] = (gamma03 - 1.f) / (gamma03 + 1.f);
4466 unit->m_coefs[3] = (gamma04 - 1.f) / (gamma04 + 1.f);
4467 unit->m_coefs[4] = (gamma05 - 1.f) / (gamma05 + 1.f);
4468 unit->m_coefs[5] = (gamma06 - 1.f) / (gamma06 + 1.f);
4469 unit->m_coefs[6] = (gamma07 - 1.f) / (gamma07 + 1.f);
4470 unit->m_coefs[7] = (gamma08 - 1.f) / (gamma08 + 1.f);
4471 unit->m_coefs[8] = (gamma09 - 1.f) / (gamma09 + 1.f);
4472 unit->m_coefs[9] = (gamma10 - 1.f) / (gamma10 + 1.f);
4473 unit->m_coefs[10] = (gamma11 - 1.f) / (gamma11 + 1.f);
4474 unit->m_coefs[11] = (gamma12 - 1.f) / (gamma12 + 1.f);
4475 Clear(12, unit->m_y1);
4476 Hilbert_next(unit, 1);
4479 void Hilbert_next(Hilbert *unit, int inNumSamples)
4481 float *in = ZIN(0);
4482 float *outcos = ZOUT(0);
4483 float *outsin = ZOUT(1);
4484 float y1[12];
4485 float coefs[12];
4487 // each filter's last sample
4488 for(int i = 0; i < 12; ++i){
4489 y1[i] = unit->m_y1[i];
4490 coefs[i] = unit->m_coefs[i];
4493 float ay1, ay2, ay3, ay4, ay5, ay6;
4494 float ay7, ay8, ay9, ay10, ay11, ay12;
4496 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4497 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4499 LOOP1(inNumSamples,
4500 float thisin = ZXP(in);
4502 HILBERT_FILTER
4503 ZXP(outcos) = ay6;
4504 ZXP(outsin) = ay12;
4507 for(int i = 0; i < 12; ++i)
4508 unit->m_y1[i] = zapgremlins(y1[i]);
4512 /* Hilbert based SSB FreqShifter */
4514 void FreqShift_Ctor(FreqShift *unit)
4516 // calculate coefs based on SampleRate, store in the struct
4517 // SETCALC(FreqShift_next_kk);
4518 unit->m_phase = 0;
4519 if(INRATE(1) == calc_FullRate) {
4520 if(INRATE(2) == calc_FullRate)
4521 SETCALC(FreqShift_next_aa);
4522 else
4523 SETCALC(FreqShift_next_ak);
4524 } else {
4525 if(INRATE(2) == calc_FullRate)
4526 SETCALC(FreqShift_next_ka);
4527 else {
4528 SETCALC(FreqShift_next_kk);
4529 unit->m_phase = (int32)(unit->m_radtoinc * IN0(2));
4532 // set up for the oscil for the modualtion
4534 int tableSizeSin = ft->mSineSize;
4535 unit->m_lomask = (tableSizeSin - 1) << 3;
4536 unit->m_radtoinc = tableSizeSin * (rtwopi * 65536.);
4537 unit->m_cpstoinc = tableSizeSin * SAMPLEDUR * 65536.;
4538 unit->m_phasein = IN0(2);
4540 float gamconst = (15.0 * pi) / SAMPLERATE;
4541 float gamma01 = gamconst * 0.3609f;
4542 float gamma02 = gamconst * 2.7412f;
4543 float gamma03 = gamconst * 11.1573f;
4544 float gamma04 = gamconst * 44.7581f;
4545 float gamma05 = gamconst * 179.6242f;
4546 float gamma06 = gamconst * 798.4578f;
4547 float gamma07 = gamconst * 1.2524f;
4548 float gamma08 = gamconst * 5.5671f;
4549 float gamma09 = gamconst * 22.3423f;
4550 float gamma10 = gamconst * 89.6271f;
4551 float gamma11 = gamconst * 364.7914f;
4552 float gamma12 = gamconst * 2770.1114f;
4553 unit->m_coefs[0] = (gamma01 - 1.f) / (gamma01 + 1.f);
4554 unit->m_coefs[1] = (gamma02 - 1.f) / (gamma02 + 1.f);
4555 unit->m_coefs[2] = (gamma03 - 1.f) / (gamma03 + 1.f);
4556 unit->m_coefs[3] = (gamma04 - 1.f) / (gamma04 + 1.f);
4557 unit->m_coefs[4] = (gamma05 - 1.f) / (gamma05 + 1.f);
4558 unit->m_coefs[5] = (gamma06 - 1.f) / (gamma06 + 1.f);
4559 unit->m_coefs[6] = (gamma07 - 1.f) / (gamma07 + 1.f);
4560 unit->m_coefs[7] = (gamma08 - 1.f) / (gamma08 + 1.f);
4561 unit->m_coefs[8] = (gamma09 - 1.f) / (gamma09 + 1.f);
4562 unit->m_coefs[9] = (gamma10 - 1.f) / (gamma10 + 1.f);
4563 unit->m_coefs[10] = (gamma11 - 1.f) / (gamma11 + 1.f);
4564 unit->m_coefs[11] = (gamma12 - 1.f) / (gamma12 + 1.f);
4566 Clear(12, unit->m_y1);
4567 FreqShift_next_kk(unit, 1);
4570 void FreqShift_next_kk(FreqShift *unit, int inNumSamples)
4572 float *in = ZIN(0);
4573 float *out = ZOUT(0);
4574 float phasein = ZIN0(2);
4575 float freqin = ZIN0(1);
4576 float outcos, outsin; // the sample by sample output of the Hilbert
4577 float outsinosc, outsinoscHalfPi; // the samples from the oscil.
4578 int32 halfPi = (int32)(unit->m_radtoinc * (0.5 * pi));
4579 float y1[12];
4580 float coefs[12];
4582 float *table0 = ft->mSineWavetable;
4583 float *table1 = table0 + 1;
4584 int32 lomask = unit->m_lomask;
4585 int32 phase = unit->m_phase;
4587 int32 freq = (int32)(unit->m_cpstoinc * freqin);
4588 int32 phaseinc = freq + (int32)(CALCSLOPE(phasein, unit->m_phasein) * unit->m_radtoinc);
4589 unit->m_phasein = phasein;
4591 // each filter's last sample
4592 for(int i = 0; i < 12; ++i) {
4593 y1[i] = unit->m_y1[i];
4594 coefs[i] = unit->m_coefs[i];
4597 float ay1, ay2, ay3, ay4, ay5, ay6;
4598 float ay7, ay8, ay9, ay10, ay11, ay12;
4600 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4601 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4603 LOOP1(inNumSamples,
4604 float thisin = ZXP(in);
4606 HILBERT_FILTER
4608 outcos = ay6;
4609 outsin = ay12;
4611 outsinosc = lookupi1(table0, table1, phase, lomask);
4612 outsinoscHalfPi = lookupi1(table0, table1, phase + halfPi, lomask);
4614 ZXP(out) = (outcos * outsinoscHalfPi) + (outsinosc * outsin);
4616 phase += phaseinc;
4619 unit->m_phase = phase;
4621 for(int i = 0; i < 12; ++i)
4622 unit->m_y1[i] = zapgremlins(y1[i]);
4625 void FreqShift_next_aa(FreqShift *unit, int inNumSamples)
4627 float *in = ZIN(0);
4628 float *out = ZOUT(0);
4629 float *phasein = ZIN(2);
4630 float *freqin = ZIN(1);
4631 float outcos, outsin; // the sample by sample output of the Hilbert
4632 float outsinosc, outsinoscHalfPi; // the samples from the oscil.
4633 int32 halfPi = (int32)(unit->m_radtoinc * (0.5 * pi));
4634 float y1[12];
4635 float coefs[12];
4637 float *table0 = ft->mSineWavetable;
4638 float *table1 = table0 + 1;
4639 int32 lomask = unit->m_lomask;
4640 int32 phase = unit->m_phase;
4642 // each filter's last sample
4643 for(int i = 0; i < 12; ++i){
4644 y1[i] = unit->m_y1[i];
4645 coefs[i] = unit->m_coefs[i];
4648 float ay1, ay2, ay3, ay4, ay5, ay6;
4649 float ay7, ay8, ay9, ay10, ay11, ay12;
4651 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4652 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4654 LOOP1(inNumSamples,
4655 float thisin = ZXP(in);
4657 HILBERT_FILTER
4659 outcos = ay6;
4660 outsin = ay12;
4662 int32 phaseoffset = phase + (int32)(unit->m_radtoinc * ZXP(phasein));
4663 outsinosc = lookupi1(table0, table1, phaseoffset, lomask);
4664 outsinoscHalfPi = lookupi1(table0, table1, phaseoffset + halfPi, lomask);
4665 phase += (int32)(unit->m_cpstoinc * ZXP(freqin));
4667 ZXP(out) = (outcos * outsinoscHalfPi) + (outsinosc * outsin);
4670 unit->m_phase = phase;
4672 for(int i = 0; i < 12; ++i)
4673 unit->m_y1[i] = zapgremlins(y1[i]);
4676 void FreqShift_next_ak(FreqShift *unit, int inNumSamples)
4678 float *in = ZIN(0);
4679 float *out = ZOUT(0);
4680 float phasein = ZIN0(2);
4681 float *freqin = ZIN(1);
4682 float outcos, outsin; // the sample by sample output of the Hilbert
4683 float outsinosc, outsinoscHalfPi; // the samples from the oscil.
4684 int32 halfPi = (int32)(unit->m_radtoinc * (0.5 * pi));
4685 float y1[12];
4686 float coefs[12];
4688 float *table0 = ft->mSineWavetable;
4689 float *table1 = table0 + 1;
4690 int32 lomask = unit->m_lomask;
4691 int32 phase = unit->m_phase;
4692 float phasemod = unit->m_phasein;
4693 float phaseslope = CALCSLOPE(phasein, phasemod);
4695 // each filter's last sample
4696 for(int i = 0; i < 12; ++i) {
4697 y1[i] = unit->m_y1[i];
4698 coefs[i] = unit->m_coefs[i];
4701 float ay1, ay2, ay3, ay4, ay5, ay6;
4702 float ay7, ay8, ay9, ay10, ay11, ay12;
4704 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4705 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4707 LOOP1(inNumSamples,
4708 float thisin = ZXP(in);
4710 HILBERT_FILTER
4712 outcos = ay6;
4713 outsin = ay12;
4715 int32 pphase = phase + (int32)(unit->m_radtoinc * phasemod);
4716 phasemod += phaseslope;
4717 outsinosc = lookupi1(table0, table1, pphase, lomask);
4718 outsinoscHalfPi = lookupi1(table0, table1, pphase + halfPi, lomask);
4719 phase += (int32)(unit->m_cpstoinc * ZXP(freqin));
4721 ZXP(out) = (outcos * outsinoscHalfPi) + (outsinosc * outsin);
4724 unit->m_phase = phase;
4725 unit->m_phasein = phasein;
4727 for(int i = 0; i < 12; ++i)
4728 unit->m_y1[i] = zapgremlins(y1[i]);
4731 void FreqShift_next_ka(FreqShift *unit, int inNumSamples)
4733 float *in = ZIN(0);
4734 float *out = ZOUT(0);
4735 float *phasein = ZIN(2);
4736 float freqin = ZIN0(1);
4737 float outcos, outsin; // the sample by sample output of the Hilbert
4738 float outsinosc, outsinoscHalfPi; // the samples from the oscil.
4739 int32 halfPi = (int32)(unit->m_radtoinc * (0.5 * pi));
4740 float y1[12];
4741 float coefs[12];
4743 float *table0 = ft->mSineWavetable;
4744 float *table1 = table0 + 1;
4745 int32 lomask = unit->m_lomask;
4746 int32 phase = unit->m_phase;
4748 int32 freq = (int32)(unit->m_cpstoinc * freqin);
4750 // each filter's last sample
4751 for(int i = 0; i < 12; ++i) {
4752 y1[i] = unit->m_y1[i];
4753 coefs[i] = unit->m_coefs[i];
4756 float ay1, ay2, ay3, ay4, ay5, ay6;
4757 float ay7, ay8, ay9, ay10, ay11, ay12;
4759 float y0_1, y0_2, y0_3, y0_4, y0_5, y0_6;
4760 float y0_7, y0_8, y0_9, y0_10, y0_11, y0_12;
4762 LOOP1(inNumSamples,
4763 float thisin = ZXP(in);
4765 HILBERT_FILTER
4767 outcos = ay6;
4768 outsin = ay12;
4770 int32 phaseoffset = phase + (int32)(unit->m_radtoinc * ZXP(phasein));
4771 outsinosc = lookupi1(table0, table1, phaseoffset, lomask);
4772 outsinoscHalfPi = lookupi1(table0, table1, phaseoffset + halfPi, lomask);
4773 phase += freq;
4775 ZXP(out) = (outcos * outsinoscHalfPi) + (outsinosc * outsin);
4778 unit->m_phase = phase;
4780 for(int i = 0; i < 12; ++i)
4781 unit->m_y1[i] = zapgremlins(y1[i]);
4786 "MoogFF" - Moog VCF digital implementation.
4787 As described in the paper entitled
4788 "Preserving the Digital Structure of the Moog VCF"
4789 by Federico Fontana
4790 appeared in the Proc. ICMC07, Copenhagen, 25-31 August 2007
4792 Original Java code Copyright F. Fontana - August 2007
4793 federico.fontana@univr.it
4795 Ported to C++ for SuperCollider by Dan Stowell - August 2007
4796 http://www.mcld.co.uk/
4798 This program is free software; you can redistribute it and/or modify
4799 it under the terms of the GNU General Public License as published by
4800 the Free Software Foundation; either version 2 of the License, or
4801 (at your option) any later version.
4803 This program is distributed in the hope that it will be useful,
4804 but WITHOUT ANY WARRANTY; without even the implied warranty of
4805 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4806 GNU General Public License for more details.
4808 You should have received a copy of the GNU General Public License
4809 along with this program; if not, write to the Free Software
4810 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4812 //////////////////////////////////////////////////////////////////
4814 void MoogFF_Ctor(MoogFF* unit)
4816 SETCALC(MoogFF_next);
4818 // initialize the unit generator state variables.
4819 unit->m_freq = -10000.3f; // Force the freq to update on first run
4820 unit->m_s1 = 0.f;
4821 unit->m_s2 = 0.f;
4822 unit->m_s3 = 0.f;
4823 unit->m_s4 = 0.f;
4825 // calculate one sample of output.
4826 MoogFF_next(unit, 1);
4829 void MoogFF_next(MoogFF *unit, int inNumSamples)
4831 float *out = ZOUT(0);
4833 float *in = ZIN(0);
4834 float k = IN0(2);
4835 k = k > 4.f? 4.f : (k<0.f ? 0.f : k);
4837 // Load state from the struct
4838 float s1 = unit->m_s1;
4839 float s2 = unit->m_s2;
4840 float s3 = unit->m_s3;
4841 float s4 = unit->m_s4;
4842 float freq = unit->m_freq;///
4844 // Reset filter state if requested
4845 if(IN0(3)>0)
4846 s1 = s2 = s3 = s4 = 0.f;
4848 float a1 = unit->m_a1, b0 = unit->m_b0; // Filter coefficient parameters
4849 float o, u; // System's null response, loop input
4851 // Update filter coefficients, but only if freq changes since it involves some expensive operations
4852 if(freq != IN0(1)) {
4853 freq = IN0(1);
4854 //Print("Updated freq to %g\n", freq);
4855 double wcD=unit->m_wcD;
4856 double T = SAMPLEDUR;
4857 wcD = 2.0 * tan ( T * PI * freq ) * SAMPLERATE;
4858 if(wcD<0)
4859 wcD = 0; // Protect against negative cutoff freq
4860 double TwcD = T*wcD;
4861 b0 = (float)(TwcD/(TwcD + 2.));
4862 a1 = (float)((TwcD - 2.)/(TwcD + 2.));
4863 unit->m_freq = freq;
4864 unit->m_b0 = b0;
4865 unit->m_a1 = a1;
4866 unit->m_wcD = wcD;
4869 LOOP1(inNumSamples,
4870 // compute loop values
4871 o = s4 + b0*(s3 + b0*(s2 + b0*s1));
4872 float ins = ZXP(in);
4873 float outs = (b0*b0*b0*b0*ins + o)/(1.f + b0*b0*b0*b0*k);
4874 ZXP(out) = outs;
4875 u = ins - k*outs;
4877 // update 1st order filter states
4878 float past = u;
4879 float future = b0*past + s1;
4880 s1 = b0*past - a1*future;
4882 past = future;
4883 future = b0*past + s2;
4884 s2 = b0*past - a1*future;
4886 past = future;
4887 future = b0*past + s3;
4888 s3 = b0*past - a1*future;
4890 s4 = b0*future - a1*outs;
4893 // Store state
4894 unit->m_s1 = s1;
4895 unit->m_s2 = s2;
4896 unit->m_s3 = s3;
4897 unit->m_s4 = s4;
4900 /* BEQSuite */
4903 struct BLowPass : public Unit
4905 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
4906 float m_freq, m_rq;
4909 extern "C"
4911 void BLowPass_next_kk(BLowPass *unit, int inNumSamples);
4912 void BLowPass_next_aa(BLowPass *unit, int inNumSamples);
4913 void BLowPass_Ctor(BLowPass* unit);
4917 void BLowPass_Ctor(BLowPass* unit)
4919 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
4920 SETCALC(BLowPass_next_aa);
4921 else
4922 SETCALC(BLowPass_next_kk);
4923 float rq = unit->m_rq = ZIN0(2);
4924 float freq = unit->m_freq = ZIN0(1);
4925 double w0 = twopi * (double)freq * SAMPLEDUR;
4926 double cosw0 = cos(w0);
4927 double i = 1. - cosw0;
4928 double alpha = sin(w0) * 0.5 * (double)rq;
4929 double b0rz = 1. / (1. + alpha);
4930 double a0 = unit->m_a0 = i * 0.5 * b0rz;
4931 unit->m_a1 = i * b0rz;
4932 unit->m_a2 = a0;
4933 unit->m_b1 = cosw0 * 2. * b0rz;
4934 unit->m_b2 = (1. - alpha) * -b0rz;
4935 unit->m_y1 = 0.;
4937 unit->m_y2 = 0.;
4938 PUSH_LOOPVALS
4939 BLowPass_next_kk(unit, 1);
4940 POP_LOOPVALS
4943 void BLowPass_next_aa(BLowPass *unit, int inNumSamples)
4945 float *out = ZOUT(0);
4946 float *in = ZIN(0);
4947 float *freq = ZIN(1);
4948 float *rq = ZIN(2);
4950 double a0, a1, a2, b1, b2, w0, cosw0, i, alpha, b0rz;
4951 double y0, y1, y2;
4952 float nextfreq, nextrq;
4954 y1 = unit->m_y1;
4955 y2 = unit->m_y2;
4957 a0 = unit->m_a0;
4958 a1 = unit->m_a1;
4959 a2 = unit->m_a2;
4960 b1 = unit->m_b1;
4961 b2 = unit->m_b2;
4963 LOOP(unit->mRate->mFilterLoops,
4964 nextfreq = ZXP(freq);
4965 nextrq = ZXP(rq);
4966 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)) {
4967 w0 = twopi * (double)nextfreq * SAMPLEDUR;
4968 cosw0 = cos(w0);
4969 i = 1. - cosw0;
4970 alpha = sin(w0) * 0.5 * (double)nextrq;
4971 b0rz = 1. / (1. + alpha);
4972 a0 = i * 0.5 * b0rz;
4973 a1 = i * b0rz;
4974 a2 = a0;
4975 b1 = cosw0 * 2. * b0rz;
4976 b2 = (1. - alpha) * -b0rz;
4977 unit->m_freq = nextfreq;
4978 unit->m_rq = nextrq;
4980 y0 = ZXP(in) + b1 * y1 + b2 * y2;
4981 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
4983 y2 = ZXP(in) + b1 * y0 + b2 * y1;
4984 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
4986 y1 = ZXP(in) + b1 * y2 + b2 * y0;
4987 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
4990 LOOP(unit->mRate->mFilterRemain,
4991 y0 = ZXP(in) + b1 * y1 + b2 * y2;
4992 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
4993 y2 = y1;
4994 y1 = y0;
4995 unit->m_freq = ZXP(freq);
4996 unit->m_rq = ZXP(rq);
4999 unit->m_a0 = a0;
5000 unit->m_a1 = a1;
5001 unit->m_a2 = a2;
5002 unit->m_b1 = b1;
5003 unit->m_b2 = b2;
5004 unit->m_y1 = zapgremlins(y1);
5005 unit->m_y2 = zapgremlins(y2);
5009 void BLowPass_next_kk(BLowPass *unit, int inNumSamples)
5011 float *out = ZOUT(0);
5012 float *in = ZIN(0);
5013 float nextfreq = ZIN0(1);
5014 float nextrq = ZIN0(2);
5016 double a0, a1, a2, b1, b2;
5017 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextcosw0, nexti, nextalpha, nextb0rz;
5018 double y0;
5019 double y1 = unit->m_y1;
5020 double y2 = unit->m_y2;
5021 double a0slope, a1slope, a2slope, b1slope, b2slope;
5023 a0 = unit->m_a0;
5024 a1 = unit->m_a1;
5025 a2 = unit->m_a2;
5026 b1 = unit->m_b1;
5027 b2 = unit->m_b2;
5029 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)){
5030 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5031 nextcosw0 = cos(nextw0);
5032 nexti = 1. - nextcosw0;
5033 nextalpha = sin(nextw0) * 0.5 * (double)nextrq;
5034 nextb0rz = 1. / (1. + nextalpha);
5035 nexta0 = nexti * 0.5 * nextb0rz;
5036 nexta1 = nexti * nextb0rz;
5037 nexta2 = nexta0;
5038 nextb1 = nextcosw0 * 2. * nextb0rz;
5039 nextb2 = ((1. - nextalpha) * -nextb0rz);
5040 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope;
5041 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope;
5042 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope;
5043 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope;
5044 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope;
5045 unit->m_freq = nextfreq;
5046 unit->m_rq = nextrq;
5047 LOOP(unit->mRate->mFilterLoops,
5048 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5049 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5051 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5052 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5054 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5055 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5056 a0 += a0slope;
5057 a1 += a1slope;
5058 a2 += a2slope;
5059 b1 += b1slope;
5060 b2 += b2slope;
5062 LOOP(unit->mRate->mFilterRemain,
5063 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5064 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5065 y2 = y1;
5066 y1 = y0;
5069 } else {
5070 LOOP(unit->mRate->mFilterLoops,
5071 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5072 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5074 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5075 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5077 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5078 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5080 LOOP(unit->mRate->mFilterRemain,
5081 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5082 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5083 y2 = y1;
5084 y1 = y0;
5087 unit->m_y1 = zapgremlins(y1);
5088 unit->m_y2 = zapgremlins(y2);
5089 unit->m_a0 = a0;
5090 unit->m_a1 = a1;
5091 unit->m_a2 = a2;
5092 unit->m_b1 = b1;
5093 unit->m_b2 = b2;
5096 struct BHiPass : public Unit
5098 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5099 float m_freq, m_rq;
5103 extern "C"
5105 void BHiPass_next_kk(BHiPass *unit, int inNumSamples);
5106 void BHiPass_next_aa(BHiPass *unit, int inNumSamples);
5107 void BHiPass_Ctor(BHiPass* unit);
5110 void BHiPass_Ctor(BHiPass* unit)
5112 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
5113 SETCALC(BHiPass_next_aa);
5114 else
5115 SETCALC(BHiPass_next_kk);
5116 float freq = unit->m_freq = ZIN0(1);
5117 float rq = unit->m_rq = ZIN0(2);
5118 double w0 = twopi * (double)freq * SAMPLEDUR;
5119 double cosw0 = cos(w0);
5120 double i = 1. + cosw0;
5121 double alpha = sin(w0) * 0.5 * (double)rq;
5122 double b0rz = 1. / (1. + alpha);
5123 double a0 = unit->m_a0 = i * 0.5 * b0rz;
5124 unit->m_a1 = -i * b0rz;
5125 unit->m_a2 = a0;
5126 unit->m_b1 = cosw0 * 2. * b0rz;
5127 unit->m_b2 = (1. - alpha) * -b0rz;
5128 unit->m_y1 = 0.;
5130 unit->m_y2 = 0.;
5131 PUSH_LOOPVALS
5132 BHiPass_next_kk(unit, 1);
5133 POP_LOOPVALS
5136 void BHiPass_next_aa(BHiPass *unit, int inNumSamples)
5138 float *out = ZOUT(0);
5139 float *in = ZIN(0);
5140 float *freq = ZIN(1);
5141 float *rq = ZIN(2);
5143 double a0, a1, a2, b1, b2, w0, cosw0, i, alpha, b0rz;
5144 double y0, y1, y2;
5145 float nextfreq, nextrq;
5147 y1 = unit->m_y1;
5148 y2 = unit->m_y2;
5150 a0 = unit->m_a0;
5151 a1 = unit->m_a1;
5152 a2 = unit->m_a2;
5153 b1 = unit->m_b1;
5154 b2 = unit->m_b2;
5156 LOOP(unit->mRate->mFilterLoops,
5157 nextfreq = ZXP(freq);
5158 nextrq = ZXP(rq);
5159 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)) {
5160 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5161 cosw0 = cos(w0);
5162 i = 1. + cosw0;
5163 alpha = sin(w0) * 0.5 * (double)nextrq;
5164 b0rz = 1. / (1. + alpha);
5165 a0 = i * 0.5 * b0rz;
5166 a1 = -i * b0rz;
5167 a2 = a0;
5168 b1 = cosw0 * 2. * b0rz;
5169 b2 = (1. - alpha) * -b0rz;
5170 unit->m_freq = nextfreq;
5171 unit->m_rq = nextrq;
5173 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5174 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5176 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5177 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5179 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5180 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5182 LOOP(unit->mRate->mFilterRemain,
5183 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5184 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5185 y2 = y1;
5186 y1 = y0;
5189 unit->m_a0 = a0;
5190 unit->m_a1 = a1;
5191 unit->m_a2 = a2;
5192 unit->m_b1 = b1;
5193 unit->m_b2 = b2;
5194 unit->m_y1 = zapgremlins(y1);
5195 unit->m_y2 = zapgremlins(y2);
5199 void BHiPass_next_kk(BHiPass *unit, int inNumSamples)
5201 float *out = ZOUT(0);
5202 float *in = ZIN(0);
5203 float nextfreq = ZIN0(1);
5204 float nextrq = ZIN0(2);
5206 double a0, a1, a2, b1, b2;
5207 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextcosw0, nexti, nextalpha, nextb0rz;
5208 double y0;
5209 double y1 = unit->m_y1;
5210 double y2 = unit->m_y2;
5211 double a0slope, a1slope, a2slope, b1slope, b2slope;
5213 a0 = unit->m_a0;
5214 a1 = unit->m_a1;
5215 a2 = unit->m_a2;
5216 b1 = unit->m_b1;
5217 b2 = unit->m_b2;
5219 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)){
5220 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5221 nextcosw0 = cos(nextw0);
5222 nexti = 1. + nextcosw0;
5223 nextalpha = sin(nextw0) * 0.5 * (double)nextrq;
5224 nextb0rz = 1. / (1. + nextalpha);
5225 nexta0 = nexti * 0.5 * nextb0rz;
5226 nexta1 = -nexti * nextb0rz;
5227 nexta2 = nexta0;
5228 nextb1 = nextcosw0 * 2. * nextb0rz;
5229 nextb2 = (1. - nextalpha) * -nextb0rz;
5230 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
5231 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
5232 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
5233 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
5234 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
5236 LOOP(unit->mRate->mFilterLoops,
5237 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5238 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5240 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5241 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5243 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5244 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5245 a0 += a0slope;
5246 a1 += a1slope;
5247 a2 += a2slope;
5248 b1 += b1slope;
5249 b2 += b2slope;
5251 LOOP(unit->mRate->mFilterRemain,
5252 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5253 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5254 y2 = y1;
5255 y1 = y0;
5257 unit->m_freq = nextfreq;
5258 unit->m_rq = nextrq;
5259 unit->m_a0 = a0;
5260 unit->m_a1 = a1;
5261 unit->m_a2 = a2;
5262 unit->m_b1 = b1;
5263 unit->m_b2 = b2;
5265 } else {
5267 LOOP(unit->mRate->mFilterLoops,
5268 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5269 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5271 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5272 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5274 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5275 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5277 LOOP(unit->mRate->mFilterRemain,
5278 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5279 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5280 y2 = y1;
5281 y1 = y0;
5285 unit->m_y1 = zapgremlins(y1);
5286 unit->m_y2 = zapgremlins(y2);
5289 /* BBandPass */
5291 struct BBandPass : public Unit
5293 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5294 float m_freq, m_bw;
5297 extern "C"
5299 void BBandPass_next_kk(BBandPass *unit, int inNumSamples);
5300 void BBandPass_next_aa(BBandPass *unit, int inNumSamples);
5301 void BBandPass_Ctor(BBandPass* unit);
5304 void BBandPass_Ctor(BBandPass* unit)
5306 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
5307 SETCALC(BBandPass_next_aa);
5308 else
5309 SETCALC(BBandPass_next_kk);
5310 float freq = unit->m_freq = ZIN0(1);
5311 float bw = unit->m_bw = ZIN0(2);
5313 double w0 = twopi * (double)freq * SAMPLEDUR;
5314 double sinw0 = sin(w0);
5315 double alpha = sinw0 * (sinh((0.34657359027997 * (double)bw * w0) / sinw0));
5316 double b0rz = 1. / (1. + alpha);
5317 double a0 = unit->m_a0 = alpha * b0rz;
5318 unit->m_a1 = 0.0f;
5319 unit->m_a2 = -a0;
5320 unit->m_b1 = cos(w0) * 2. * b0rz;
5321 unit->m_b2 = (1. - alpha) * -b0rz;
5323 unit->m_y1 = 0.;
5325 unit->m_y2 = 0.;
5326 PUSH_LOOPVALS
5327 BBandPass_next_kk(unit, 1);
5328 POP_LOOPVALS
5331 void BBandPass_next_aa(BBandPass *unit, int inNumSamples)
5333 float *out = ZOUT(0);
5334 float *in = ZIN(0);
5335 float *freq = ZIN(1);
5336 float *bw = ZIN(2);
5338 double a0, a1, a2, b1, b2, w0, sinw0, alpha, b0rz;
5339 double y0, y1, y2;
5340 float nextfreq, nextbw;
5342 y1 = unit->m_y1;
5343 y2 = unit->m_y2;
5345 a0 = unit->m_a0;
5346 a1 = unit->m_a1;
5347 a2 = unit->m_a2;
5348 b1 = unit->m_b1;
5349 b2 = unit->m_b2;
5351 LOOP(unit->mRate->mFilterLoops,
5352 nextfreq = ZXP(freq);
5353 nextbw = ZXP(bw);
5354 if ((unit->m_freq != nextfreq) || (unit->m_bw != nextbw)) {
5355 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5356 sinw0 = sin(w0);
5357 alpha = sinw0 * (sinh((0.34657359027997 * (double)nextbw * w0) / sinw0));
5358 b0rz = 1. / (1. + alpha);
5359 a0 = alpha * b0rz;
5360 a1 = 0.0f;
5361 a2 = -a0;
5362 b1 = cos(w0) * 2. * b0rz;
5363 b2 = (1. - alpha) * -b0rz;
5364 unit->m_freq = ZXP(freq);
5365 unit->m_bw = ZXP(bw);
5367 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5368 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5370 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5371 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5373 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5374 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5376 LOOP(unit->mRate->mFilterRemain,
5377 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5378 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5379 y2 = y1;
5380 y1 = y0;
5381 unit->m_freq = nextfreq;
5382 unit->m_bw = nextbw;
5385 unit->m_a0 = a0;
5386 unit->m_a1 = a1;
5387 unit->m_a2 = a2;
5388 unit->m_b1 = b1;
5389 unit->m_b2 = b2;
5390 unit->m_y1 = zapgremlins(y1);
5391 unit->m_y2 = zapgremlins(y2);
5395 void BBandPass_next_kk(BBandPass *unit, int inNumSamples)
5397 float *out = ZOUT(0);
5398 float *in = ZIN(0);
5399 float nextfreq = ZIN0(1);
5400 float nextbw = ZIN0(2);
5402 double a0, a1, a2, b1, b2;
5403 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextalpha, nextb0rz;
5404 double y0;
5405 double y1 = unit->m_y1;
5406 double y2 = unit->m_y2;
5407 double a0slope, a1slope, a2slope, b1slope, b2slope;
5409 a0 = unit->m_a0;
5410 a1 = unit->m_a1;
5411 a2 = unit->m_a2;
5412 b1 = unit->m_b1;
5413 b2 = unit->m_b2;
5414 if ((unit->m_freq != nextfreq) || (unit->m_bw != nextbw)){
5415 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5416 nextalpha = sin(nextw0) * (sinh((0.34657359027997 * (double)nextbw * nextw0) / sin(nextw0)));
5417 nextb0rz = 1. / (1. + nextalpha);
5418 nexta0 = nextalpha * nextb0rz;
5419 nexta1 = 0.;
5420 nexta2 = -nexta0;
5421 nextb1 = cos(nextw0) * 2. * nextb0rz;
5422 nextb2 = ((1. - nextalpha) * -nextb0rz);
5423 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
5424 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
5425 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
5426 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
5427 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
5428 unit->m_freq = nextfreq;
5429 unit->m_bw = nextbw;
5430 LOOP(unit->mRate->mFilterLoops,
5431 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5432 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5434 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5435 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5437 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5438 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5439 a0 += a0slope;
5440 a1 += a1slope;
5441 a2 += a2slope;
5442 b1 += b1slope;
5443 b2 += b2slope;
5445 LOOP(unit->mRate->mFilterRemain,
5446 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5447 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5448 y2 = y1;
5449 y1 = y0;
5451 } else {
5452 LOOP(unit->mRate->mFilterLoops,
5453 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5454 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5456 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5457 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5459 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5460 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5462 LOOP(unit->mRate->mFilterRemain,
5463 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5464 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5465 y2 = y1;
5466 y1 = y0;
5470 unit->m_a0 = a0;
5471 unit->m_a1 = a1;
5472 unit->m_a2 = a2;
5473 unit->m_b1 = b1;
5474 unit->m_b2 = b2;
5475 unit->m_y1 = zapgremlins(y1);
5476 unit->m_y2 = zapgremlins(y2);
5479 /* BBandStop */
5480 struct BBandStop : public Unit
5482 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5483 float m_freq, m_bw;
5486 extern "C"
5488 void BBandStop_next_kk(BBandStop *unit, int inNumSamples);
5489 void BBandStop_next_aa(BBandStop *unit, int inNumSamples);
5490 void BBandStop_Ctor(BBandStop* unit);
5493 void BBandStop_Ctor(BBandStop* unit)
5495 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
5496 SETCALC(BBandStop_next_aa);
5497 else
5498 SETCALC(BBandStop_next_kk);
5499 float freq = unit->m_freq = ZIN0(1);
5500 float bw = unit->m_bw = ZIN0(2);
5502 double w0 = twopi * (double)freq * SAMPLEDUR;
5503 double sinw0 = sin(w0);
5504 double alpha = sinw0 * (sinh((0.34657359027997 * (double)bw * w0) / sinw0));
5505 double b0rz = 1. / (1. + alpha);
5506 double b1 = unit->m_b1 = 2. * b0rz * cos(w0);
5507 unit->m_a0 = b0rz;
5508 unit->m_a1 = -b1;
5509 unit->m_a2 = b0rz;
5510 unit->m_b2 = (1. - alpha) * -b0rz;
5512 unit->m_y1 = 0.;
5514 unit->m_y2 = 0.;
5515 PUSH_LOOPVALS
5516 BBandStop_next_kk(unit, 1);
5517 POP_LOOPVALS
5520 void BBandStop_next_aa(BBandStop *unit, int inNumSamples)
5522 float *out = ZOUT(0);
5523 float *in = ZIN(0);
5524 float *freq = ZIN(1);
5525 float *bw = ZIN(2);
5527 double a0, a1, a2, b1, b2, w0, sinw0, alpha, b0rz;
5528 double y0, y1, y2;
5529 float nextfreq, nextbw;
5531 y1 = unit->m_y1;
5532 y2 = unit->m_y2;
5534 a0 = unit->m_a0;
5535 a1 = unit->m_a1;
5536 a2 = unit->m_a2;
5537 b1 = unit->m_b1;
5538 b2 = unit->m_b2;
5540 LOOP(unit->mRate->mFilterLoops,
5541 nextfreq = ZXP(freq);
5542 nextbw = ZXP(bw);
5543 if ((unit->m_freq != nextfreq) || (unit->m_bw != nextbw)) {
5544 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5545 sinw0 = sin(w0);
5546 alpha = sinw0 * (sinh((0.34657359027997 * (double)nextbw * w0) / sinw0));
5547 b0rz = 1. / (1. + alpha);
5548 b1 = 2. * b0rz * cos(w0);
5549 a0 = b0rz;
5550 a1 = -b1;
5551 a2 = b0rz;
5552 b2 = (1. - alpha) * -b0rz;
5553 unit->m_freq = ZXP(freq);
5554 unit->m_bw = ZXP(bw);
5556 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5557 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5559 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5560 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5562 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5563 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5565 LOOP(unit->mRate->mFilterRemain,
5566 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5567 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5568 y2 = y1;
5569 y1 = y0;
5570 unit->m_freq = nextfreq;
5571 unit->m_bw = nextbw;
5574 unit->m_a0 = a0;
5575 unit->m_a1 = a1;
5576 unit->m_a2 = a2;
5577 unit->m_b1 = b1;
5578 unit->m_b2 = b2;
5579 unit->m_y1 = zapgremlins(y1);
5580 unit->m_y2 = zapgremlins(y2);
5584 void BBandStop_next_kk(BBandStop *unit, int inNumSamples)
5586 float *out = ZOUT(0);
5587 float *in = ZIN(0);
5588 float nextfreq = ZIN0(1);
5589 float nextbw = ZIN0(2);
5591 double a0, a1, a2, b1, b2;
5592 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextalpha, nextb0rz;
5593 double y0;
5594 double y1 = unit->m_y1;
5595 double y2 = unit->m_y2;
5596 double a0slope, a1slope, a2slope, b1slope, b2slope;
5598 a0 = unit->m_a0;
5599 a1 = unit->m_a1;
5600 a2 = unit->m_a2;
5601 b1 = unit->m_b1;
5602 b2 = unit->m_b2;
5604 if ((unit->m_freq != nextfreq) || (unit->m_bw != nextbw)){
5605 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5606 nextalpha = sin(nextw0) * (sinh((0.34657359027997 * (double)nextbw * nextw0) / sin(nextw0)));
5607 nextb0rz = 1. / (1. + nextalpha);
5608 nextb1 = cos(nextw0) * 2. * nextb0rz;
5609 nexta0 = nextb0rz;
5610 nexta1 = -nextb1;
5611 nexta2 = nextb0rz;
5612 nextb2 = ((1. - nextalpha) * -nextb0rz);
5613 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
5614 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
5615 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
5616 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
5617 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
5618 unit->m_freq = nextfreq;
5619 unit->m_bw = nextbw;
5620 LOOP(unit->mRate->mFilterLoops,
5621 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5622 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5624 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5625 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5627 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5628 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5629 a0 += a0slope;
5630 a1 += a1slope;
5631 a2 += a2slope;
5632 b1 += b1slope;
5633 b2 += b2slope;
5635 LOOP(unit->mRate->mFilterRemain,
5636 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5637 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5638 y2 = y1;
5639 y1 = y0;
5642 } else {
5643 LOOP(unit->mRate->mFilterLoops,
5644 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5645 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5647 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5648 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5650 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5651 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5653 LOOP(unit->mRate->mFilterRemain,
5654 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5655 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5656 y2 = y1;
5657 y1 = y0;
5661 unit->m_a0 = a0;
5662 unit->m_a1 = a1;
5663 unit->m_a2 = a2;
5664 unit->m_b1 = b1;
5665 unit->m_b2 = b2;
5666 unit->m_y1 = zapgremlins(y1);
5667 unit->m_y2 = zapgremlins(y2);
5670 /* BPeakEQ */
5671 struct BPeakEQ : public Unit
5673 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5674 float m_freq, m_rq, m_db;
5677 extern "C"
5679 void BPeakEQ_next_kkk(BPeakEQ *unit, int inNumSamples);
5680 void BPeakEQ_next_aaa(BPeakEQ *unit, int inNumSamples);
5681 void BPeakEQ_Ctor(BPeakEQ* unit);
5684 void BPeakEQ_Ctor(BPeakEQ* unit)
5686 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate) && (INRATE(3) == calc_FullRate))
5687 SETCALC(BPeakEQ_next_aaa);
5688 else
5689 SETCALC(BPeakEQ_next_kkk);
5691 float freq = unit->m_freq = ZIN0(1);
5692 float rq = unit->m_rq = ZIN0(2);
5693 float db = unit->m_db = ZIN0(3);
5694 double a = pow(10., (double)db * 0.025);
5695 double w0 = twopi * (double)freq * SAMPLEDUR;
5696 double alpha = sin(w0) * 0.5 * (double)rq;
5697 double b0rz = 1. / (1. + (alpha / a));
5698 double b1 = unit->m_b1 = 2. * b0rz * cos(w0);
5699 unit->m_a0 = (1. + (alpha * a)) * b0rz;
5700 unit->m_a1 = -b1;
5701 unit->m_a2 = (1. - (alpha * a)) * b0rz;
5702 unit->m_b2 = (1. - (alpha / a)) * -b0rz;
5704 unit->m_y1 = 0.;
5705 unit->m_y2 = 0.;
5706 PUSH_LOOPVALS
5707 BPeakEQ_next_kkk(unit, 1);
5708 POP_LOOPVALS
5711 void BPeakEQ_next_aaa(BPeakEQ *unit, int inNumSamples)
5713 float *out = ZOUT(0);
5714 float *in = ZIN(0);
5715 float *freq = ZIN(1);
5716 float *rq = ZIN(2);
5717 float *db = ZIN(3);
5719 double a0, a1, a2, b1, b2, a, w0, alpha, b0rz;
5720 double y0, y1, y2;
5721 float nextfreq, nextrq, nextdb;
5723 y1 = unit->m_y1;
5724 y2 = unit->m_y2;
5726 a0 = unit->m_a0;
5727 a1 = unit->m_a1;
5728 a2 = unit->m_a2;
5729 b1 = unit->m_b1;
5730 b2 = unit->m_b2;
5733 LOOP(unit->mRate->mFilterLoops,
5734 nextfreq = ZXP(freq);
5735 nextrq = ZXP(rq);
5736 nextdb = ZXP(db);
5737 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq) || (unit->m_db != nextdb)) {
5738 a = pow(10., (double)nextdb * 0.025);
5739 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5740 alpha = sin(w0) * 0.5 * (double)nextrq;
5741 b0rz = 1. / (1. + (alpha / a));
5742 b1 = 2. * b0rz * cos(w0);
5743 a0 = (1. + (alpha * a)) * b0rz;
5744 a1 = -b1;
5745 a2 = (1. - (alpha * a)) * b0rz;
5746 b2 = (1. - (alpha / a)) * -b0rz;
5747 unit->m_freq = nextfreq;
5748 unit->m_rq = nextrq;
5749 unit->m_db = nextdb;
5751 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5752 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5754 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5755 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5757 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5758 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5760 LOOP(unit->mRate->mFilterRemain,
5761 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5762 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5763 y2 = y1;
5764 y1 = y0;
5765 unit->m_freq = ZXP(freq);
5766 unit->m_rq = ZXP(rq);
5767 unit->m_db = ZXP(db);
5770 unit->m_a0 = a0;
5771 unit->m_a1 = a1;
5772 unit->m_a2 = a2;
5773 unit->m_b1 = b1;
5774 unit->m_b2 = b2;
5775 unit->m_y1 = zapgremlins(y1);
5776 unit->m_y2 = zapgremlins(y2);
5780 void BPeakEQ_next_kkk(BPeakEQ *unit, int inNumSamples)
5782 float *out = ZOUT(0);
5783 float *in = ZIN(0);
5784 float nextfreq = ZIN0(1);
5785 float nextrq = ZIN0(2);
5786 float nextdb = ZIN0(3);
5788 double a0, a1, a2, b1, b2, a, w0, alpha, b0rz;
5789 double y0, y1, y2, a0slope, a1slope, a2slope, b1slope, b2slope, nexta0, nexta1, nexta2, nextb1, nextb2;
5791 y1 = unit->m_y1;
5792 y2 = unit->m_y2;
5794 a0 = unit->m_a0;
5795 a1 = unit->m_a1;
5796 a2 = unit->m_a2;
5797 b1 = unit->m_b1;
5798 b2 = unit->m_b2;
5800 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq) || (unit->m_db != nextdb)) {
5801 a = pow(10., (double)nextdb * 0.025);
5802 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5803 alpha = sin(w0) * 0.5 * (double)nextrq;
5804 b0rz = 1. / (1. + (alpha / a));
5805 nextb1 = 2. * b0rz * cos(w0);
5806 nexta0 = (1. + (alpha * a)) * b0rz;
5807 nexta1 = -nextb1;
5808 nexta2 = (1. - (alpha * a)) * b0rz;
5809 nextb2 = (1. - (alpha / a)) * -b0rz;
5810 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
5811 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
5812 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
5813 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
5814 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
5815 unit->m_freq = nextfreq;
5816 unit->m_db = nextdb;
5817 unit->m_rq = nextrq;
5818 LOOP(unit->mRate->mFilterLoops,
5819 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5820 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5822 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5823 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5825 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5826 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5828 a0 += a0slope;
5829 a1 += a1slope;
5830 a2 += a2slope;
5831 b1 += b1slope;
5832 b2 += b2slope;
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;
5842 } else {
5843 LOOP(unit->mRate->mFilterLoops,
5844 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5845 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5847 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5848 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5850 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5851 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5854 LOOP(unit->mRate->mFilterRemain,
5855 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5856 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5857 y2 = y1;
5858 y1 = y0;
5862 unit->m_a0 = a0;
5863 unit->m_a1 = a1;
5864 unit->m_a2 = a2;
5865 unit->m_b1 = b1;
5866 unit->m_b2 = b2;
5867 unit->m_y1 = zapgremlins(y1);
5868 unit->m_y2 = zapgremlins(y2);
5871 /* BAllPass */
5872 struct BAllPass : public Unit
5874 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
5875 float m_freq, m_rq;
5878 extern "C"
5880 void BAllPass_next_kk(BAllPass *unit, int inNumSamples);
5881 void BAllPass_next_aa(BAllPass *unit, int inNumSamples);
5882 void BAllPass_Ctor(BAllPass* unit);
5885 void BAllPass_Ctor(BAllPass* unit)
5887 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate))
5888 SETCALC(BAllPass_next_aa);
5889 else
5890 SETCALC(BAllPass_next_kk);
5892 float freq = unit->m_freq = ZIN0(1);
5893 float rq = unit->m_rq = ZIN0(2);
5895 double w0 = twopi * (double)freq * SAMPLEDUR;
5896 double alpha = sin(w0) * 0.5 * (double)rq;
5897 double b0rz = 1. / (1. + alpha);
5898 double a0 = unit->m_a0 = (1. - alpha) * b0rz;
5899 double b1 = unit->m_b1 = 2. * b0rz * cos(w0);
5900 unit->m_a1 = -b1;
5901 unit->m_a2 = 1.;
5902 unit->m_b2 = -a0;
5904 unit->m_y1 = 0.;
5906 unit->m_y2 = 0.;
5907 PUSH_LOOPVALS
5908 BAllPass_next_kk(unit, 1);
5909 POP_LOOPVALS
5912 void BAllPass_next_aa(BAllPass *unit, int inNumSamples)
5914 float *out = ZOUT(0);
5915 float *in = ZIN(0);
5916 float *freq = ZIN(1);
5917 float *rq = ZIN(2);
5919 double a0, a1, a2, b1, b2, w0, alpha, b0rz;
5920 double y0, y1, y2;
5921 float nextfreq, nextrq;
5923 y1 = unit->m_y1;
5924 y2 = unit->m_y2;
5926 a0 = unit->m_a0;
5927 a1 = unit->m_a1;
5928 a2 = unit->m_a2;
5929 b1 = unit->m_b1;
5930 b2 = unit->m_b2;
5932 LOOP(unit->mRate->mFilterLoops,
5933 nextfreq = ZXP(freq);
5934 nextrq = ZXP(rq);
5935 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)) {
5936 w0 = twopi * (double)nextfreq * SAMPLEDUR;
5937 alpha = sin(w0) * (double)nextrq * 0.5;
5938 b0rz = 1. / (1. + alpha);
5939 b1 = 2. * b0rz * cos(w0);
5940 a0 = (1. - alpha) * b0rz;
5941 a1 = -b1;
5942 a2 = 1.;
5943 b2 = -a0;
5944 unit->m_freq = nextfreq;
5945 unit->m_rq = nextrq;
5947 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5948 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5950 y2 = ZXP(in) + b1 * y0 + b2 * y1;
5951 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
5953 y1 = ZXP(in) + b1 * y2 + b2 * y0;
5954 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
5956 LOOP(unit->mRate->mFilterRemain,
5957 y0 = ZXP(in) + b1 * y1 + b2 * y2;
5958 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
5959 y2 = y1;
5960 y1 = y0;
5961 unit->m_freq = ZXP(freq);
5962 unit->m_rq = ZXP(rq);
5965 unit->m_a0 = a0;
5966 unit->m_a1 = a1;
5967 unit->m_a2 = a2;
5968 unit->m_b1 = b1;
5969 unit->m_b2 = b2;
5970 unit->m_y1 = zapgremlins(y1);
5971 unit->m_y2 = zapgremlins(y2);
5975 void BAllPass_next_kk(BAllPass *unit, int inNumSamples)
5977 float *out = ZOUT(0);
5978 float *in = ZIN(0);
5979 float nextfreq = ZIN0(1);
5980 float nextrq = ZIN0(2);
5982 double a0, a1, a2, b1, b2;
5983 double nexta0, nexta1, nexta2, nextb1, nextb2, nextw0, nextalpha, nextb0rz;
5984 double y0;
5985 double y1 = unit->m_y1;
5986 double y2 = unit->m_y2;
5987 double a0slope, a1slope, a2slope, b1slope, b2slope;
5989 a0 = unit->m_a0;
5990 a1 = unit->m_a1;
5991 a2 = unit->m_a2;
5992 b1 = unit->m_b1;
5993 b2 = unit->m_b2;
5995 if ((unit->m_freq != nextfreq) || (unit->m_rq != nextrq)) {
5996 nextw0 = twopi * (double)nextfreq * SAMPLEDUR;
5997 nextalpha = sin(nextw0) * 0.5 * (double)nextrq;
5998 nextb0rz = 1. / (1. + nextalpha);
5999 nextb1 = cos(nextw0) * 2. * nextb0rz;
6000 nexta0 = (1. - nextalpha) * nextb0rz;
6001 nexta1 = -nextb1;
6002 nexta2 = 1.;
6003 nextb2 = -nexta0;
6004 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope;
6005 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope;
6006 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope;
6007 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope;
6008 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope;
6009 unit->m_freq = nextfreq;
6010 unit->m_rq = nextrq;
6011 LOOP(unit->mRate->mFilterLoops,
6012 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6013 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6015 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6016 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6018 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6019 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6020 a0 += a0slope;
6021 a1 += a1slope;
6022 a2 += a2slope;
6023 b1 += b1slope;
6024 b2 += b2slope;
6026 LOOP(unit->mRate->mFilterRemain,
6027 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6028 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6029 y2 = y1;
6030 y1 = y0;
6033 } else {
6034 LOOP(unit->mRate->mFilterLoops,
6035 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6036 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6038 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6039 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6041 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6042 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6044 LOOP(unit->mRate->mFilterRemain,
6045 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6046 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6047 y2 = y1;
6048 y1 = y0;
6052 unit->m_a0 = a0;
6053 unit->m_a1 = a1;
6054 unit->m_a2 = a2;
6055 unit->m_b1 = b1;
6056 unit->m_b2 = b2;
6057 unit->m_y1 = zapgremlins(y1);
6058 unit->m_y2 = zapgremlins(y2);
6062 /* BLowShelf */
6063 struct BLowShelf : public Unit
6065 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
6066 float m_freq, m_rs, m_db;
6069 extern "C"
6071 void BLowShelf_next_kkk(BLowShelf *unit, int inNumSamples);
6072 void BLowShelf_next_aaa(BLowShelf *unit, int inNumSamples);
6073 void BLowShelf_Ctor(BLowShelf* unit);
6076 void BLowShelf_Ctor(BLowShelf* unit)
6078 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate) && (INRATE(3) == calc_FullRate))
6079 SETCALC(BLowShelf_next_aaa);
6080 else
6081 SETCALC(BLowShelf_next_kkk);
6083 float freq = unit->m_freq = ZIN0(1);
6084 float rs = unit->m_rs = ZIN0(2);
6085 float db = unit->m_db = ZIN0(3);
6086 double a = pow(10., (double)db * 0.025);
6087 double w0 = twopi * (double)freq * SAMPLEDUR;
6088 double cosw0 = cos(w0);
6089 double sinw0 = sin(w0);
6090 double alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)rs - 1.) + 2.);
6091 double i = (a + 1.) * cosw0;
6092 double j = (a - 1.) * cosw0;
6093 double k = 2. * sqrt(a) * alpha;
6094 double b0rz = 1. / ((a + 1.) + j + k);
6095 unit->m_a0 = a * (( a + 1.) - j + k) * b0rz;
6096 unit->m_a1 = 2. * a * ((a - 1.) - i) * b0rz;
6097 unit->m_a2 = a * ((a + 1.) - j - k) * b0rz;
6098 unit->m_b1 = 2. * ((a - 1.) + i) * b0rz;
6099 unit->m_b2 = ((a + 1.) + j - k) * -b0rz;
6101 unit->m_y1 = 0.;
6103 unit->m_y2 = 0.;
6104 PUSH_LOOPVALS
6105 BLowShelf_next_kkk(unit, 1);
6106 POP_LOOPVALS
6109 void BLowShelf_next_aaa(BLowShelf *unit, int inNumSamples)
6111 float *out = ZOUT(0);
6112 float *in = ZIN(0);
6113 float *freq = ZIN(1);
6114 float *rs = ZIN(2);
6115 float *db = ZIN(3);
6117 double a0, a1, a2, b1, b2, a, w0, cosw0, sinw0, alpha, i, j, k, b0rz;
6118 double y0, y1, y2;
6119 float nextfreq, nextrs, nextdb;
6121 y1 = unit->m_y1;
6122 y2 = unit->m_y2;
6124 a0 = unit->m_a0;
6125 a1 = unit->m_a1;
6126 a2 = unit->m_a2;
6127 b1 = unit->m_b1;
6128 b2 = unit->m_b2;
6130 LOOP(unit->mRate->mFilterLoops,
6131 nextfreq = ZXP(freq);
6132 nextrs = ZXP(rs);
6133 nextdb = ZXP(db);
6134 if ((unit->m_freq != nextfreq) || (unit->m_rs != nextrs) || (unit->m_db != nextdb)) {
6135 a = pow(10., (double)nextdb * 0.025);
6136 w0 = twopi * (double)nextfreq * SAMPLEDUR;
6137 sinw0 = sin(w0);
6138 cosw0 = cos(w0);
6139 alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)nextrs - 1.) + 2.);
6140 i = (a + 1.) * cosw0;
6141 j = (a - 1.) * cosw0;
6142 k = 2. * sqrt(a) * alpha;
6143 b0rz = 1. / ((a + 1.) + j + k);
6144 a0 = a * (( a + 1.) - j + k) * b0rz;
6145 a1 = 2. * a * ((a - 1.) - i) * b0rz;
6146 a2 = a * ((a + 1.) - j - k) * b0rz;
6147 b1 = 2. * ((a - 1.) + i) * b0rz;
6148 b2 = ((a + 1.) + j - k) * -b0rz;
6149 unit->m_freq = nextfreq;
6150 unit->m_rs = nextrs;
6151 unit->m_db = nextdb;
6153 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6154 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6156 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6157 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6159 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6160 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6162 LOOP(unit->mRate->mFilterRemain,
6163 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6164 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6165 y2 = y1;
6166 y1 = y0;
6167 unit->m_freq = ZXP(freq);
6168 unit->m_rs = ZXP(rs);
6169 unit->m_db = ZXP(db);
6172 unit->m_a0 = a0;
6173 unit->m_a1 = a1;
6174 unit->m_a2 = a2;
6175 unit->m_b1 = b1;
6176 unit->m_b2 = b2;
6177 unit->m_y1 = zapgremlins(y1);
6178 unit->m_y2 = zapgremlins(y2);
6181 void BLowShelf_next_kkk(BLowShelf *unit, int inNumSamples)
6183 float *out = ZOUT(0);
6184 float *in = ZIN(0);
6185 float nextfreq = ZIN0(1);
6186 float nextrs = ZIN0(2);
6187 float nextdb = ZIN0(3);
6189 double a0, a1, a2, b1, b2, a, w0, cosw0, sinw0, alpha, i, j, k, b0rz;
6190 double y0, y1, y2, a0slope, a1slope, a2slope, b1slope, b2slope, nexta0, nexta1, nexta2, nextb1, nextb2;
6192 y1 = unit->m_y1;
6193 y2 = unit->m_y2;
6195 a0 = unit->m_a0;
6196 a1 = unit->m_a1;
6197 a2 = unit->m_a2;
6198 b1 = unit->m_b1;
6199 b2 = unit->m_b2;
6201 if ((unit->m_freq != nextfreq) || (unit->m_rs != nextrs) || (unit->m_db != nextdb)) {
6202 a = pow(10., (double)nextdb * 0.025);
6203 w0 = twopi * (double)nextfreq * SAMPLEDUR;
6204 sinw0 = sin(w0);
6205 cosw0 = cos(w0);
6206 alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)nextrs - 1.) + 2.);
6207 i = (a + 1.) * cosw0;
6208 j = (a - 1.) * cosw0;
6209 k = 2. * sqrt(a) * alpha;
6210 b0rz = 1. / ((a + 1.) + j + k);
6211 nexta0 = a * (( a + 1.) - j + k) * b0rz;
6212 nexta1 = 2. * a * ((a - 1.) - i) * b0rz;
6213 nexta2 = a * ((a + 1.) - j - k) * b0rz;
6214 nextb1 = 2. * ((a - 1.) + i) * b0rz;
6215 nextb2 = ((a + 1.) + j - k) * -b0rz;
6216 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
6217 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
6218 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
6219 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
6220 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
6221 unit->m_freq = nextfreq;
6222 unit->m_db = nextdb;
6223 unit->m_rs = nextrs;
6224 LOOP(unit->mRate->mFilterLoops,
6225 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6226 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6228 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6229 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6231 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6232 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6234 a0 += a0slope;
6235 a1 += a1slope;
6236 a2 += a2slope;
6237 b1 += b1slope;
6238 b2 += b2slope;
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;
6248 } else {
6249 LOOP(unit->mRate->mFilterLoops,
6250 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6251 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6253 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6254 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6256 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6257 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6260 LOOP(unit->mRate->mFilterRemain,
6261 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6262 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6263 y2 = y1;
6264 y1 = y0;
6268 unit->m_a0 = a0;
6269 unit->m_a1 = a1;
6270 unit->m_a2 = a2;
6271 unit->m_b1 = b1;
6272 unit->m_b2 = b2;
6273 unit->m_y1 = zapgremlins(y1);
6274 unit->m_y2 = zapgremlins(y2);
6277 /* BHiShelf */
6278 struct BHiShelf : public Unit
6280 double m_y1, m_y2, m_a0, m_a1, m_a2, m_b1, m_b2;
6281 float m_freq, m_rs, m_db;
6284 extern "C"
6286 void BHiShelf_next_kkk(BHiShelf *unit, int inNumSamples);
6287 void BHiShelf_next_aaa(BHiShelf *unit, int inNumSamples);
6288 void BHiShelf_Ctor(BHiShelf* unit);
6291 void BHiShelf_Ctor(BHiShelf* unit)
6293 if ((INRATE(1) == calc_FullRate) && (INRATE(2) == calc_FullRate) && (INRATE(3) == calc_FullRate))
6294 SETCALC(BHiShelf_next_aaa);
6295 else
6296 SETCALC(BHiShelf_next_kkk);
6298 float freq = unit->m_freq = ZIN0(1);
6299 float rs = unit->m_rs = ZIN0(2);
6300 float db = unit->m_db = ZIN0(3);
6301 double a = pow(10., (double)db * 0.025);
6302 double w0 = twopi * (double)freq * SAMPLEDUR;
6303 double cosw0 = cos(w0);
6304 double sinw0 = sin(w0);
6305 double alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)rs - 1.) + 2.);
6306 double i = (a + 1.) * cosw0;
6307 double j = (a - 1.) * cosw0;
6308 double k = 2. * sqrt(a) * alpha;
6310 double b0rz = 1. / ((a + 1.) - j + k);
6311 unit->m_a0 = a * (( a + 1.) + j + k) * b0rz;
6312 unit->m_a1 = -2. * a * ((a - 1.) + i) * b0rz;
6313 unit->m_a2 = a * ((a + 1.) + j - k) * b0rz;
6314 unit->m_b1 = -2. * ((a - 1.) - i) * b0rz;
6315 unit->m_b2 = ((a + 1.) - j - k) * -b0rz;
6317 unit->m_y1 = 0.;
6319 unit->m_y2 = 0.;
6320 PUSH_LOOPVALS
6321 BHiShelf_next_kkk(unit, 1);
6322 POP_LOOPVALS
6325 void BHiShelf_next_aaa(BHiShelf *unit, int inNumSamples)
6327 float *out = ZOUT(0);
6328 float *in = ZIN(0);
6329 float *freq = ZIN(1);
6330 float *rs = ZIN(2);
6331 float *db = ZIN(3);
6333 double a0, a1, a2, b1, b2, a, w0, cosw0, sinw0, alpha, i, j, k, b0rz;
6334 double y0, y1, y2;
6335 float nextfreq, nextrs, nextdb;
6337 y1 = unit->m_y1;
6338 y2 = unit->m_y2;
6340 a0 = unit->m_a0;
6341 a1 = unit->m_a1;
6342 a2 = unit->m_a2;
6343 b1 = unit->m_b1;
6344 b2 = unit->m_b2;
6346 LOOP(unit->mRate->mFilterLoops,
6347 nextfreq = ZXP(freq);
6348 nextrs = ZXP(rs);
6349 nextdb = ZXP(db);
6350 if ((unit->m_freq != nextfreq) || (unit->m_rs != nextrs) || (unit->m_db != nextdb)) {
6351 a = pow(10., (double)nextdb * 0.025);
6352 w0 = twopi * (double)nextfreq * SAMPLEDUR;
6353 sinw0 = sin(w0);
6354 cosw0 = cos(w0);
6355 alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)nextrs - 1.) + 2.);
6356 i = (a + 1.) * cosw0;
6357 j = (a - 1.) * cosw0;
6358 k = 2. * sqrt(a) * alpha;
6359 b0rz = 1. / ((a + 1.) - j + k);
6360 a0 = a * (( a + 1.) + j + k) * b0rz;
6361 a1 = -2. * a * ((a - 1.) + i) * b0rz;
6362 a2 = a * ((a + 1.) + j - k) * b0rz;
6363 b1 = -2. * ((a - 1.) - i) * b0rz;
6364 b2 = ((a + 1.) - j - k) * -b0rz;
6365 unit->m_freq = ZXP(freq);
6366 unit->m_rs = ZXP(rs);
6367 unit->m_db = ZXP(db);
6369 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6370 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6372 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6373 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6375 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6376 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6378 LOOP(unit->mRate->mFilterRemain,
6379 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6380 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6381 y2 = y1;
6382 y1 = y0;
6383 unit->m_freq = ZXP(freq);
6384 unit->m_rs = ZXP(rs);
6385 unit->m_db = ZXP(db);
6388 unit->m_a0 = a0;
6389 unit->m_a1 = a1;
6390 unit->m_a2 = a2;
6391 unit->m_b1 = b1;
6392 unit->m_b2 = b2;
6393 unit->m_y1 = zapgremlins(y1);
6394 unit->m_y2 = zapgremlins(y2);
6397 void BHiShelf_next_kkk(BHiShelf *unit, int inNumSamples)
6399 float *out = ZOUT(0);
6400 float *in = ZIN(0);
6401 float nextfreq = ZIN0(1);
6402 float nextrs = ZIN0(2);
6403 float nextdb = ZIN0(3);
6405 double a0, a1, a2, b1, b2, a, w0, cosw0, sinw0, alpha, i, j, k, b0rz;
6406 double y0, y1, y2, a0slope, a1slope, a2slope, b1slope, b2slope, nexta0, nexta1, nexta2, nextb1, nextb2;
6408 y1 = unit->m_y1;
6409 y2 = unit->m_y2;
6411 a0 = unit->m_a0;
6412 a1 = unit->m_a1;
6413 a2 = unit->m_a2;
6414 b1 = unit->m_b1;
6415 b2 = unit->m_b2;
6417 if ((unit->m_freq != nextfreq) || (unit->m_rs != nextrs) || (unit->m_db != nextdb)) {
6418 a = pow(10., (double)nextdb * 0.025);
6419 w0 = twopi * (double)nextfreq * SAMPLEDUR;
6420 sinw0 = sin(w0);
6421 cosw0 = cos(w0);
6422 alpha = sinw0 * 0.5 * sqrt((a + (1./a)) * ((double)nextrs - 1.) + 2.);
6423 i = (a + 1.) * cosw0;
6424 j = (a - 1.) * cosw0;
6425 k = 2. * sqrt(a) * alpha;
6426 b0rz = 1. / ((a + 1.) - j + k);
6427 nexta0 = a * (( a + 1.) + j + k) * b0rz;
6428 nexta1 = -2. * a * ((a - 1.) + i) * b0rz;
6429 nexta2 = a * ((a + 1.) + j - k) * b0rz;
6430 nextb1 = -2. * ((a - 1.) - i) * b0rz;
6431 nextb2 = ((a + 1.) - j - k) * -b0rz;
6432 a0slope = (nexta0 - a0) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta0, a0);
6433 a1slope = (nexta1 - a1) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta1, a1);
6434 a2slope = (nexta2 - a2) * unit->mRate->mFilterSlope; //CALCSLOPE(nexta2, a2);
6435 b1slope = (nextb1 - b1) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb1, b1);
6436 b2slope = (nextb2 - b2) * unit->mRate->mFilterSlope; //CALCSLOPE(nextb2, b2);
6437 unit->m_freq = nextfreq;
6438 unit->m_db = nextdb;
6439 unit->m_rs = nextrs;
6440 LOOP(unit->mRate->mFilterLoops,
6441 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6442 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6444 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6445 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6447 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6448 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6450 a0 += a0slope;
6451 a1 += a1slope;
6452 a2 += a2slope;
6453 b1 += b1slope;
6454 b2 += b2slope;
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 } else {
6465 LOOP(unit->mRate->mFilterLoops,
6466 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6467 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6469 y2 = ZXP(in) + b1 * y0 + b2 * y1;
6470 ZXP(out) = a0 * y2 + a1 * y0 + a2 * y1;
6472 y1 = ZXP(in) + b1 * y2 + b2 * y0;
6473 ZXP(out) = a0 * y1 + a1 * y2 + a2 * y0;
6476 LOOP(unit->mRate->mFilterRemain,
6477 y0 = ZXP(in) + b1 * y1 + b2 * y2;
6478 ZXP(out) = a0 * y0 + a1 * y1 + a2 * y2;
6479 y2 = y1;
6480 y1 = y0;
6483 unit->m_a0 = a0;
6484 unit->m_a1 = a1;
6485 unit->m_a2 = a2;
6486 unit->m_b1 = b1;
6487 unit->m_b2 = b2;
6488 unit->m_y1 = zapgremlins(y1);
6489 unit->m_y2 = zapgremlins(y2);
6492 ////////////////////////////////////////////////////////////////////////////////////////////////////////
6493 PluginLoad(Filter)
6495 ft = inTable;
6497 DefineSimpleUnit(Ramp);
6498 DefineSimpleUnit(Lag);
6499 DefineSimpleUnit(Lag2);
6500 DefineSimpleUnit(Lag3);
6501 DefineSimpleUnit(LagUD);
6502 DefineSimpleUnit(Lag2UD);
6503 DefineSimpleUnit(Lag3UD);
6504 DefineSimpleUnit(VarLag);
6505 DefineSimpleUnit(OnePole);
6506 DefineSimpleUnit(OneZero);
6507 DefineSimpleUnit(TwoPole);
6508 DefineSimpleUnit(TwoZero);
6509 DefineSimpleUnit(Decay);
6510 DefineSimpleUnit(Decay2);
6511 DefineSimpleUnit(Flip);
6512 DefineSimpleUnit(Delay1);
6513 DefineSimpleUnit(Delay2);
6514 DefineSimpleUnit(Integrator);
6515 DefineSimpleUnit(LeakDC);
6516 DefineSimpleUnit(LPZ1);
6517 DefineSimpleUnit(HPZ1);
6518 DefineSimpleUnit(LPZ2);
6519 DefineSimpleUnit(HPZ2);
6520 DefineSimpleUnit(BPZ2);
6521 DefineSimpleUnit(BRZ2);
6522 DefineSimpleUnit(APF);
6523 DefineSimpleUnit(LPF);
6524 DefineSimpleUnit(HPF);
6525 DefineSimpleUnit(BPF);
6526 DefineSimpleUnit(BRF);
6527 DefineSimpleUnit(RLPF);
6528 DefineSimpleUnit(RHPF);
6530 DefineSimpleUnit(Slew);
6531 DefineSimpleUnit(Slope);
6533 DefineSimpleUnit(MidEQ);
6534 DefineSimpleUnit(Median);
6536 DefineSimpleUnit(Resonz);
6537 DefineSimpleUnit(Ringz);
6538 DefineSimpleUnit(Formlet);
6540 DefineSimpleUnit(FOS);
6541 DefineSimpleUnit(SOS);
6543 DefineSimpleUnit(Compander);
6544 DefineDtorUnit(Limiter);
6545 DefineDtorUnit(Normalizer);
6547 DefineSimpleUnit(Amplitude);
6548 DefineSimpleUnit(DetectSilence);
6550 DefineSimpleUnit(Hilbert);
6551 DefineSimpleUnit(FreqShift);
6552 DefineSimpleUnit(MoogFF);
6554 /* BEQSuite UGens */
6555 DefineSimpleUnit(BLowPass);
6556 DefineSimpleUnit(BHiPass);
6557 DefineSimpleUnit(BBandPass);
6558 DefineSimpleUnit(BBandStop);
6559 DefineSimpleUnit(BPeakEQ);
6560 DefineSimpleUnit(BAllPass);
6561 DefineSimpleUnit(BLowShelf);
6562 DefineSimpleUnit(BHiShelf);
6566 //////////////////////////////////////////////////////////////////////////////////////////////////