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
;
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
;
80 float m_in
, m_lagTime
;
83 struct OnePole
: public Unit
88 struct OneZero
: public Unit
93 struct Integrator
: public Unit
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
134 struct HPZ1
: public Unit
139 struct HPZ2
: public Unit
144 struct BPZ2
: public Unit
149 struct BRZ2
: public Unit
154 struct LPZ2
: public Unit
159 struct Flip
: public Unit
163 struct Delay1
: public Unit
168 struct Delay2
: public Unit
173 struct Slope
: public Unit
178 struct Slew
: public Unit
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
;
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
284 int32 mCounter
, mEndCounter
;
287 struct Hilbert
: public Unit
293 struct FreqShift
: public Unit
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
308 double m_T
; // 1/SAMPLEFREQ
309 float m_s1
, m_s2
, m_s3
, m_s4
; // 1st order filter states
312 //////////////////////////////////////////////////////////////////////////////////////////////////
318 void Ramp_next(Ramp
*unit
, int inNumSamples
);
319 void Ramp_next_1(Ramp
*unit
, int inNumSamples
);
320 void Ramp_Ctor(Ramp
* unit
);
322 void Lag_next(Lag
*unit
, int inNumSamples
);
323 void Lag_Ctor(Lag
* unit
);
325 void Lag2_next(Lag2
*unit
, int inNumSamples
);
326 void Lag2_Ctor(Lag2
* unit
);
328 void Lag3_next(Lag3
*unit
, int inNumSamples
);
329 void Lag3_Ctor(Lag3
* unit
);
331 void LagUD_next(LagUD
*unit
, int inNumSamples
);
332 void LagUD_Ctor(LagUD
* unit
);
334 void Lag2UD_next(Lag2UD
*unit
, int inNumSamples
);
335 void Lag2UD_Ctor(Lag2UD
* unit
);
337 void Lag3UD_next(Lag3UD
*unit
, int inNumSamples
);
338 void Lag3UD_Ctor(Lag3UD
* unit
);
340 void VarLag_next(VarLag
*unit
, int inNumSamples
);
341 void VarLag_Ctor(VarLag
* unit
);
343 void OnePole_next_a(OnePole
*unit
, int inNumSamples
);
344 void OnePole_next_k(OnePole
*unit
, int inNumSamples
);
345 void OnePole_Ctor(OnePole
* unit
);
347 void OneZero_next(OneZero
* unit
, int inNumSamples
);
348 void OneZero_Ctor(OneZero
* unit
);
350 void Integrator_next(Integrator
*unit
, int inNumSamples
);
351 void Integrator_Ctor(Integrator
* unit
);
353 void Decay_next(Decay
*unit
, int inNumSamples
);
354 void Decay_Ctor(Decay
* unit
);
356 void Decay2_next(Decay2
*unit
, int inNumSamples
);
357 void Decay2_Ctor(Decay2
* unit
);
359 void LeakDC_next(LeakDC
*unit
, int inNumSamples
);
360 void LeakDC_next_1(LeakDC
* unit
, int inNumSamples
);
361 void LeakDC_Ctor(LeakDC
* unit
);
363 void TwoPole_next(TwoPole
*unit
, int inNumSamples
);
364 void TwoPole_Ctor(TwoPole
* unit
);
366 void TwoZero_next(TwoZero
*unit
, int inNumSamples
);
367 void TwoZero_Ctor(TwoZero
* unit
);
369 void APF_next(APF
*unit
, int inNumSamples
);
370 void APF_Ctor(APF
* unit
);
372 void LPZ1_next(LPZ1
*unit
, int inNumSamples
);
373 void LPZ1_Ctor(LPZ1
* unit
);
375 void HPZ1_next(HPZ1
*unit
, int inNumSamples
);
376 void HPZ1_Ctor(HPZ1
* unit
);
378 void Slope_next(Slope
*unit
, int inNumSamples
);
379 void Slope_Ctor(Slope
* unit
);
381 void Delay1_next(Delay1
*unit
, int inNumSamples
);
382 void Delay1_Ctor(Delay1
* unit
);
384 void Flip_Ctor(Flip
* unit
);
385 void Flip_next_even(Flip
*unit
, int inNumSamples
);
386 void Flip_next_odd(Flip
*unit
, int inNumSamples
);
388 void Delay2_next(Delay2
*unit
, int inNumSamples
);
389 void Delay2_Ctor(Delay2
* unit
);
391 void LPZ2_next(LPZ2
*unit
, int inNumSamples
);
392 void LPZ2_Ctor(LPZ2
* unit
);
394 void HPZ2_next(HPZ2
*unit
, int inNumSamples
);
395 void HPZ2_Ctor(HPZ2
* unit
);
397 void BPZ2_next(BPZ2
*unit
, int inNumSamples
);
398 void BPZ2_Ctor(BPZ2
* unit
);
400 void BRZ2_next(BRZ2
*unit
, int inNumSamples
);
401 void BRZ2_Ctor(BRZ2
* unit
);
403 void Slew_next(Slew
*unit
, int inNumSamples
);
404 void Slew_Ctor(Slew
* unit
);
406 void RLPF_next(RLPF
*unit
, int inNumSamples
);
407 void RLPF_next_1(RLPF
*unit
, int inNumSamples
);
408 void RLPF_Ctor(RLPF
* unit
);
410 void RHPF_next(RHPF
*unit
, int inNumSamples
);
411 void RHPF_next_1(RHPF
*unit
, int inNumSamples
);
412 void RHPF_Ctor(RHPF
* unit
);
414 void LPF_next(LPF
*unit
, int inNumSamples
);
415 void LPF_next_1(LPF
*unit
, int inNumSamples
);
416 void LPF_Ctor(LPF
* unit
);
418 void HPF_next(HPF
*unit
, int inNumSamples
);
419 void HPF_next_1(HPF
*unit
, int inNumSamples
);
420 void HPF_Ctor(HPF
* unit
);
422 void BPF_next(BPF
*unit
, int inNumSamples
);
423 void BPF_next_1(BPF
*unit
, int inNumSamples
);
424 void BPF_Ctor(BPF
* unit
);
426 void BRF_next(BRF
*unit
, int inNumSamples
);
427 void BRF_next_1(BRF
*unit
, int inNumSamples
);
428 void BRF_Ctor(BRF
* unit
);
430 void Median_next(Median
*unit
, int inNumSamples
);
431 void Median_Ctor(Median
* unit
);
433 void MidEQ_next(MidEQ
*unit
, int inNumSamples
);
434 void MidEQ_Ctor(MidEQ
* unit
);
436 void Resonz_next(Resonz
*unit
, int inNumSamples
);
437 void Resonz_Ctor(Resonz
* unit
);
439 void Ringz_next(Ringz
*unit
, int inNumSamples
);
440 void Ringz_Ctor(Ringz
* unit
);
442 void Formlet_next(Formlet
*unit
, int inNumSamples
);
443 void Formlet_next_1(Formlet
*unit
, int inNumSamples
);
444 void Formlet_Ctor(Formlet
* unit
);
446 void FOS_next_k(FOS
*unit
, int inNumSamples
);
447 void FOS_next_a(FOS
*unit
, int inNumSamples
);
448 void FOS_next_1(FOS
*unit
, int inNumSamples
);
449 void FOS_Ctor(FOS
* unit
);
451 void SOS_next_k(SOS
*unit
, int inNumSamples
);
452 void SOS_next_a(SOS
*unit
, int inNumSamples
);
453 void SOS_next_1(SOS
*unit
, int inNumSamples
);
454 void SOS_Ctor(SOS
* unit
);
456 void Normalizer_next(Normalizer
*unit
, int inNumSamples
);
457 void Normalizer_Ctor(Normalizer
* unit
);
458 void Normalizer_Dtor(Normalizer
* unit
);
460 void Limiter_next(Limiter
*unit
, int inNumSamples
);
461 void Limiter_Ctor(Limiter
* unit
);
462 void Limiter_Dtor(Limiter
* unit
);
464 void Compander_next(Compander
*unit
, int inNumSamples
);
465 void Compander_Ctor(Compander
* unit
);
467 void Amplitude_next(Amplitude
*unit
, int inNumSamples
);
468 void Amplitude_next_kk(Amplitude
*unit
, int inNumSamples
);
469 void Amplitude_next_atok(Amplitude
*unit
, int inNumSamples
);
470 void Amplitude_next_atok_kk(Amplitude
*unit
, int inNumSamples
);
471 void Amplitude_Ctor(Amplitude
* unit
);
473 void DetectSilence_next(DetectSilence
*unit
, int inNumSamples
);
474 void DetectSilence_done(DetectSilence
*unit
, int inNumSamples
);
475 void DetectSilence_Ctor(DetectSilence
* unit
);
477 void Hilbert_Ctor(Hilbert
* unit
);
478 void Hilbert_next(Hilbert
*unit
, int inNumSamples
);
480 void FreqShift_Ctor(FreqShift
* unit
);
481 void FreqShift_next_kk(FreqShift
*unit
, int inNumSamples
);
482 void FreqShift_next_aa(FreqShift
*unit
, int inNumSamples
);
483 void FreqShift_next_ak(FreqShift
*unit
, int inNumSamples
);
484 void FreqShift_next_ka(FreqShift
*unit
, int inNumSamples
);
486 void MoogFF_next(MoogFF
*unit
, int inNumSamples
);
487 void MoogFF_Ctor(MoogFF
* unit
);
490 void Lag_next(Lag *unit, int inNumSamples);
491 void Lag_Ctor(Lag* unit);
493 void Lag_next(Lag *unit, int inNumSamples);
494 void Lag_Ctor(Lag* unit);
498 //////////////////////////////////////////////////////////////////////////////////////////////////
500 void Ramp_next(Ramp
*unit
, int inNumSamples
)
502 float *out
= ZOUT(0);
504 float period
= ZIN0(1);
506 double slope
= unit
->m_slope
;
507 double level
= unit
->m_level
;
508 int counter
= unit
->m_counter
;
509 int remain
= inNumSamples
;
511 int nsmps
= sc_min(remain
, counter
);
520 counter
= (int)(period
* SAMPLERATE
);
521 counter
= sc_max(1, counter
);
522 slope
= (*in
- level
) / counter
;
525 unit
->m_level
= level
;
526 unit
->m_slope
= slope
;
527 unit
->m_counter
= counter
;
530 void Ramp_next_1(Ramp
*unit
, int inNumSamples
)
534 *out
= unit
->m_level
;
535 unit
->m_level
+= unit
->m_slope
;
536 if (--unit
->m_counter
<= 0) {
538 float period
= ZIN0(1);
539 int counter
= (int)(period
* SAMPLERATE
);
540 unit
->m_counter
= counter
= sc_max(1, counter
);
541 unit
->m_slope
= (in
- unit
->m_level
) / counter
;
545 void Ramp_Ctor(Ramp
* unit
)
547 if (BUFLENGTH
== 1) {
548 SETCALC(Ramp_next_1
);
554 unit
->m_level
= ZIN0(0);
556 ZOUT0(0) = unit
->m_level
;
559 //////////////////////////////////////////////////////////////////////////////////////////////////
561 void Lag_next(Lag
*unit
, int inNumSamples
)
563 float *out
= ZOUT(0);
568 float y1
= unit
->m_y1
;
569 float b1
= unit
->m_b1
;
571 if (lag
== unit
->m_lag
) {
574 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
577 unit
->m_b1
= lag
== 0.f
? 0.f
: exp(log001
/ (lag
* unit
->mRate
->mSampleRate
));
578 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
583 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
586 unit
->m_y1
= zapgremlins(y1
);
589 void Lag_next_1(Lag
*unit
, int inNumSamples
)
595 float y1
= unit
->m_y1
;
596 float b1
= unit
->m_b1
;
598 if (lag
== unit
->m_lag
) {
600 *out
= y1
= y0
+ b1
* (y1
- y0
);
602 unit
->m_b1
= b1
= lag
== 0.f
? 0.f
: exp(log001
/ (lag
* unit
->mRate
->mSampleRate
));
605 *out
= y1
= y0
+ b1
* (y1
- y0
);
607 unit
->m_y1
= zapgremlins(y1
);
610 void Lag_Ctor(Lag
* unit
)
619 unit
->m_y1
= ZIN0(0);
623 //////////////////////////////////////////////////////////////////////////////////////////////////
624 void LagUD_next(LagUD
*unit
, int inNumSamples
)
626 float *out
= ZOUT(0);
628 float lagu
= ZIN0(1);
629 float lagd
= ZIN0(2);
631 float y1
= unit
->m_y1
;
632 float b1u
= unit
->m_b1u
;
633 float b1d
= unit
->m_b1d
;
635 if ( (lagu
== unit
->m_lagu
) && (lagd
== unit
->m_lagd
) ) {
639 ZXP(out
) = y1
= y0
+ b1u
* (y1
- y0
);
641 ZXP(out
) = y1
= y0
+ b1d
* (y1
- y0
);
644 unit
->m_b1u
= lagu
== 0.f
? 0.f
: exp(log001
/ (lagu
* unit
->mRate
->mSampleRate
));
645 float b1u_slope
= CALCSLOPE(unit
->m_b1u
, b1u
);
647 unit
->m_b1d
= lagd
== 0.f
? 0.f
: exp(log001
/ (lagd
* unit
->mRate
->mSampleRate
));
648 float b1d_slope
= CALCSLOPE(unit
->m_b1d
, b1d
);
655 ZXP(out
) = y1
= y0
+ b1u
* (y1
- y0
);
657 ZXP(out
) = y1
= y0
+ b1d
* (y1
- y0
);
660 unit
->m_y1
= zapgremlins(y1
);
663 void LagUD_Ctor(LagUD
* unit
)
671 unit
->m_y1
= ZIN0(0);
675 //////////////////////////////////////////////////////////////////////////////////////////////////
677 void Lag2_next(Lag2
*unit
, int inNumSamples
)
679 float *out
= ZOUT(0);
683 float y1a
= unit
->m_y1a
;
684 float y1b
= unit
->m_y1b
;
685 float b1
= unit
->m_b1
;
687 if (lag
== unit
->m_lag
) {
690 y1a
= y0a
+ b1
* (y1a
- y0a
);
691 y1b
= y1a
+ b1
* (y1b
- y1a
);
695 unit
->m_b1
= lag
== 0.f
? 0.f
: exp(log001
/ (lag
* unit
->mRate
->mSampleRate
));
696 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
701 y1a
= y0a
+ b1
* (y1a
- y0a
);
702 y1b
= y1a
+ b1
* (y1b
- y1a
);
706 unit
->m_y1a
= zapgremlins(y1a
);
707 unit
->m_y1b
= zapgremlins(y1b
);
710 void Lag2_Ctor(Lag2
* unit
)
716 unit
->m_y1a
= unit
->m_y1b
= ZIN0(0);
720 //////////////////////////////////////////////////////////////////////////////////////////////////
722 void Lag2UD_next(Lag2UD
*unit
, int inNumSamples
)
724 float *out
= ZOUT(0);
726 float lagu
= ZIN0(1);
727 float lagd
= ZIN0(2);
729 float y1a
= unit
->m_y1a
;
730 float y1b
= unit
->m_y1b
;
731 float b1u
= unit
->m_b1u
;
732 float b1d
= unit
->m_b1d
;
734 if ( (lagu
== unit
->m_lagu
) && (lagd
== unit
->m_lagd
) ) {
738 y1a
= y0a
+ b1u
* (y1a
- y0a
);
740 y1a
= y0a
+ b1d
* (y1a
- y0a
);
743 y1b
= y1a
+ b1u
* (y1b
- y1a
);
745 y1b
= y1a
+ b1d
* (y1b
- y1a
);
749 unit
->m_b1u
= lagu
== 0.f
? 0.f
: exp(log001
/ (lagu
* unit
->mRate
->mSampleRate
));
750 float b1u_slope
= CALCSLOPE(unit
->m_b1u
, b1u
);
752 unit
->m_b1d
= lagd
== 0.f
? 0.f
: exp(log001
/ (lagd
* unit
->mRate
->mSampleRate
));
753 float b1d_slope
= CALCSLOPE(unit
->m_b1d
, b1d
);
760 y1a
= y0a
+ b1u
* (y1a
- y0a
);
762 y1a
= y0a
+ b1d
* (y1a
- y0a
);
765 y1b
= y1a
+ b1u
* (y1b
- y1a
);
767 y1b
= y1a
+ b1d
* (y1b
- y1a
);
771 unit
->m_y1a
= zapgremlins(y1a
);
772 unit
->m_y1b
= zapgremlins(y1b
);
775 void Lag2UD_Ctor(Lag2UD
* unit
)
777 SETCALC(Lag2UD_next
);
783 unit
->m_y1a
= unit
->m_y1b
= ZIN0(0);
784 Lag2UD_next(unit
, 1);
787 //////////////////////////////////////////////////////////////////////////////////////////////////
789 void Lag3_next(Lag3
*unit
, int inNumSamples
)
791 float *out
= ZOUT(0);
795 float y1a
= unit
->m_y1a
;
796 float y1b
= unit
->m_y1b
;
797 float y1c
= unit
->m_y1c
;
798 float b1
= unit
->m_b1
;
800 if (lag
== unit
->m_lag
) {
803 y1a
= y0a
+ b1
* (y1a
- y0a
);
804 y1b
= y1a
+ b1
* (y1b
- y1a
);
805 y1c
= y1b
+ b1
* (y1c
- y1b
);
809 unit
->m_b1
= lag
== 0.f
? 0.f
: exp(log001
/ (lag
* unit
->mRate
->mSampleRate
));
810 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
815 y1a
= y0a
+ b1
* (y1a
- y0a
);
816 y1b
= y1a
+ b1
* (y1b
- y1a
);
817 y1c
= y1b
+ b1
* (y1c
- y1b
);
821 unit
->m_y1a
= zapgremlins(y1a
);
822 unit
->m_y1b
= zapgremlins(y1b
);
823 unit
->m_y1c
= zapgremlins(y1c
);
826 void Lag3_Ctor(Lag3
* unit
)
832 unit
->m_y1a
= unit
->m_y1b
= unit
->m_y1c
= ZIN0(0);
836 //////////////////////////////////////////////////////////////////////////////////////////////////
838 void Lag3UD_next(Lag3UD
*unit
, int inNumSamples
)
840 float *out
= ZOUT(0);
842 float lagu
= ZIN0(1);
843 float lagd
= ZIN0(2);
845 float y1a
= unit
->m_y1a
;
846 float y1b
= unit
->m_y1b
;
847 float y1c
= unit
->m_y1c
;
848 float b1u
= unit
->m_b1u
;
849 float b1d
= unit
->m_b1d
;
851 if ( (lagu
== unit
->m_lagu
) && (lagd
== unit
->m_lagd
) ) {
855 y1a
= y0a
+ b1u
* (y1a
- y0a
);
857 y1a
= y0a
+ b1d
* (y1a
- y0a
);
860 y1b
= y1a
+ b1u
* (y1b
- y1a
);
862 y1b
= y1a
+ b1d
* (y1b
- y1a
);
865 y1c
= y1b
+ b1u
* (y1c
- y1b
);
867 y1c
= y1b
+ b1d
* (y1c
- y1b
);
872 unit
->m_b1u
= lagu
== 0.f
? 0.f
: exp(log001
/ (lagu
* unit
->mRate
->mSampleRate
));
873 float b1u_slope
= CALCSLOPE(unit
->m_b1u
, b1u
);
875 unit
->m_b1d
= lagd
== 0.f
? 0.f
: exp(log001
/ (lagd
* unit
->mRate
->mSampleRate
));
876 float b1d_slope
= CALCSLOPE(unit
->m_b1d
, b1d
);
883 y1a
= y0a
+ b1u
* (y1a
- y0a
);
885 y1a
= y0a
+ b1d
* (y1a
- y0a
);
888 y1b
= y1a
+ b1u
* (y1b
- y1a
);
890 y1b
= y1a
+ b1d
* (y1b
- y1a
);
893 y1c
= y1b
+ b1u
* (y1c
- y1b
);
895 y1c
= y1b
+ b1d
* (y1c
- y1b
);
900 unit
->m_y1a
= zapgremlins(y1a
);
901 unit
->m_y1b
= zapgremlins(y1b
);
902 unit
->m_y1c
= zapgremlins(y1c
);
905 void Lag3UD_Ctor(Lag3UD
* unit
)
907 SETCALC(Lag3UD_next
);
914 unit
->m_y1a
= unit
->m_y1b
= unit
->m_y1c
= ZIN0(0);
915 Lag3UD_next(unit
, 1);
918 //////////////////////////////////////////////////////////////////////////////////////////////////
920 void VarLag_next(VarLag
*unit
, int inNumSamples
)
922 float *out
= ZOUT(0);
924 float lagTime
= ZIN0(1);
925 double slope
= unit
->m_slope
;
926 double level
= unit
->m_level
;
927 int counter
= unit
->m_counter
;
928 int remain
= inNumSamples
;
930 if ( *in
!= unit
->m_in
) {
931 counter
= (int)(lagTime
* SAMPLERATE
);
932 counter
= unit
->m_counter
= sc_max(1, counter
);
933 slope
= unit
->m_slope
= ( *in
- unit
->m_level
) / counter
;
935 unit
->m_lagTime
= lagTime
;
937 if (lagTime
!= unit
->m_lagTime
) {
938 float scaleFactor
= lagTime
/unit
->m_lagTime
;
939 counter
= (int) (unit
->m_counter
* scaleFactor
);
940 counter
= unit
->m_counter
= sc_max(1, counter
);
941 slope
= unit
->m_slope
/ scaleFactor
;
942 unit
->m_lagTime
= lagTime
;
949 level
+= slope
; --counter
;
955 LOOP(remain
, ZXP(out
) = level
);
958 unit
->m_level
= level
;
959 unit
->m_slope
= slope
;
960 unit
->m_counter
= counter
;
964 void VarLag_next_1(VarLag
*unit
, int inNumSamples
)
968 float lagTime
= ZIN0(1);
969 int counter
= unit
->m_counter
;
970 if ( in
!= unit
->m_in
) {
971 counter
= (int)(lagTime
* SAMPLERATE
);
972 unit
->m_counter
= counter
= sc_max(1, counter
);
973 unit
->m_slope
= ( in
- unit
->m_level
) / counter
;
975 unit
->m_lagTime
= lagTime
;
977 if (lagTime
!= unit
->m_lagTime
) {
979 double scaleFactor
= lagTime
/unit
->m_lagTime
;
980 counter
= (int) (unit
->m_counter
* scaleFactor
);
981 unit
->m_counter
= counter
= sc_max(1, counter
);
982 unit
->m_slope
= unit
->m_slope
/ scaleFactor
; }
983 unit
->m_lagTime
= lagTime
; }
985 *out
= unit
->m_level
;
987 if (unit
->m_counter
> 0) {
988 unit
->m_level
+= unit
->m_slope
;
991 unit
->m_level
= unit
->m_in
;
996 void VarLag_Ctor(VarLag
* unit
)
998 if (BUFLENGTH
== 1) {
999 SETCALC(VarLag_next_1
);
1001 SETCALC(VarLag_next
);
1004 float lagTime
= ZIN0(1);
1005 unit
->m_level
= ZIN0(2);
1006 int counter
= (int)(lagTime
* SAMPLERATE
);
1007 unit
->m_counter
= counter
= sc_max(1, counter
);
1008 unit
->m_slope
= ( in
- unit
->m_level
) / counter
;
1010 unit
->m_lagTime
= lagTime
;
1011 ZOUT0(0) = unit
->m_level
;
1015 //////////////////////////////////////////////////////////////////////////////////////////////////
1017 void OnePole_next_a(OnePole
*unit
, int inNumSamples
)
1019 //printf("OnePole_next_a\n");
1021 float *out
= ZOUT(0);
1023 float *b1p
= ZIN(1);
1025 float y1
= unit
->m_y1
;
1029 float b1
= ZXP(b1p
);
1030 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
1032 unit
->m_y1
= zapgremlins(y1
);
1035 void OnePole_next_k(OnePole
*unit
, int inNumSamples
)
1037 //printf("OnePole_next_a\n");
1039 float *out
= ZOUT(0);
1041 float b1
= unit
->m_b1
;
1042 unit
->m_b1
= ZIN0(1);
1044 float y1
= unit
->m_y1
;
1046 if (b1
== unit
->m_b1
) {
1050 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
1055 ZXP(out
) = y1
= y0
+ b1
* (y1
+ y0
);
1059 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1060 if (b1
>= 0.f
&& unit
->m_b1
>= 0) {
1063 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
1066 } else if (b1
<= 0.f
&& unit
->m_b1
<= 0) {
1069 ZXP(out
) = y1
= y0
+ b1
* (y1
+ y0
);
1075 ZXP(out
) = y1
= (1.f
- std::abs(b1
)) * y0
+ b1
* y1
;
1080 unit
->m_y1
= zapgremlins(y1
);
1083 void OnePole_Ctor(OnePole
* unit
)
1085 if (INRATE(1) == calc_FullRate
) {
1086 SETCALC(OnePole_next_a
);
1088 SETCALC(OnePole_next_k
);
1092 OnePole_next_a(unit
, 1);
1095 //////////////////////////////////////////////////////////////////////////////////////////////////
1097 void OneZero_Ctor(OneZero
* unit
)
1099 SETCALC(OneZero_next
);
1101 unit
->m_x1
= ZIN0(0);
1102 OneZero_next(unit
, 1);
1106 void OneZero_next(OneZero
* unit
, int inNumSamples
)
1108 //printf("OneZero::next\n");
1110 float *out
= ZOUT(0);
1112 float b1
= unit
->m_b1
;
1113 unit
->m_b1
= ZIN0(1);
1115 float x1
= unit
->m_x1
;
1116 if (b1
== unit
->m_b1
) {
1120 ZXP(out
) = x0
+ b1
* (x1
- x0
);
1126 ZXP(out
) = x0
+ b1
* (x1
+ x0
);
1131 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1132 if (b1
>= 0.f
&& unit
->m_b1
>= 0) {
1135 ZXP(out
) = x0
+ b1
* (x1
- x0
);
1139 } else if (b1
<= 0.f
&& unit
->m_b1
<= 0) {
1142 ZXP(out
) = x0
+ b1
* (x1
+ x0
);
1149 ZXP(out
) = (1.f
- std::abs(b1
)) * x0
+ b1
* x1
;
1158 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1160 void Integrator_Ctor(Integrator
* unit
)
1162 //printf("Integrator_Reset\n");
1163 SETCALC(Integrator_next
);
1166 Integrator_next(unit
, 1);
1169 void Integrator_next(Integrator
* unit
, int inNumSamples
)
1171 //printf("Integrator_next_a\n");
1173 float *out
= ZOUT(0);
1175 float b1
= unit
->m_b1
;
1176 unit
->m_b1
= ZIN0(1);
1178 float y1
= unit
->m_y1
;
1180 if (b1
== unit
->m_b1
) {
1184 ZXP(out
) = y1
= y0
+ y1
;
1186 } else if (b1
== 0.f
) {
1194 ZXP(out
) = y1
= y0
+ b1
* y1
;
1198 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1201 ZXP(out
) = y1
= y0
+ b1
* y1
;
1205 unit
->m_y1
= zapgremlins(y1
);
1208 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1210 void Decay_Ctor(Decay
* unit
)
1212 SETCALC(Decay_next
);
1213 unit
->m_decayTime
= 0.f
;
1216 Decay_next(unit
, 1);
1219 void Decay_next(Decay
* unit
, int inNumSamples
)
1221 //printf("Decay_next_a\n");
1223 float *out
= ZOUT(0);
1225 float decayTime
= ZIN0(1);
1227 float y1
= unit
->m_y1
;
1228 float b1
= unit
->m_b1
;
1229 if (decayTime
== unit
->m_decayTime
) {
1238 ZXP(out
) = y1
= y0
+ b1
* y1
;
1242 unit
->m_b1
= decayTime
== 0.f
? 0.f
: exp(log001
/ (decayTime
* SAMPLERATE
));
1243 unit
->m_decayTime
= decayTime
;
1244 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1245 //printf("decayTime %g %g %g\n", unit->m_decayTime, next_b1, b1);
1248 ZXP(out
) = y1
= y0
+ b1
* y1
;
1252 unit
->m_y1
= zapgremlins(y1
);
1255 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1258 void Decay2_Ctor(Decay2
*unit
)
1260 SETCALC(Decay2_next
);
1262 float attackTime
= ZIN0(1);
1263 float decayTime
= ZIN0(2);
1264 unit
->m_b1a
= decayTime
== 0.f
? 0.f
: exp(log001
/ (decayTime
* SAMPLERATE
));
1265 unit
->m_b1b
= attackTime
== 0.f
? 0.f
: exp(log001
/ (attackTime
* SAMPLERATE
));
1266 unit
->m_decayTime
= decayTime
;
1267 unit
->m_attackTime
= attackTime
;
1275 void Decay2_next(Decay2
* unit
, int inNumSamples
)
1277 //printf("Decay2_next_a\n");
1279 float *out
= ZOUT(0);
1281 float attackTime
= ZIN0(1);
1282 float decayTime
= ZIN0(2);
1284 float y1a
= unit
->m_y1a
;
1285 float y1b
= unit
->m_y1b
;
1286 float b1a
= unit
->m_b1a
;
1287 float b1b
= unit
->m_b1b
;
1288 if (decayTime
== unit
->m_decayTime
&& attackTime
== unit
->m_attackTime
) {
1291 y1a
= y0
+ b1a
* y1a
;
1292 y1b
= y0
+ b1b
* y1b
;
1293 ZXP(out
) = y1a
- y1b
;
1296 unit
->m_decayTime
= decayTime
;
1297 unit
->m_attackTime
= attackTime
;
1298 float next_b1a
= decayTime
== 0.f
? 0.f
: exp(log001
/ (decayTime
* SAMPLERATE
));
1299 float next_b1b
= attackTime
== 0.f
? 0.f
: exp(log001
/ (attackTime
* SAMPLERATE
));
1300 unit
->m_decayTime
= decayTime
;
1301 float b1a_slope
= CALCSLOPE(next_b1a
, b1a
);
1302 float b1b_slope
= CALCSLOPE(next_b1b
, b1b
);
1303 unit
->m_b1a
= next_b1a
;
1304 unit
->m_b1b
= next_b1b
;
1307 y1a
= y0
+ b1a
* y1a
;
1308 y1b
= y0
+ b1b
* y1b
;
1309 ZXP(out
) = y1a
- y1b
;
1320 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1322 void LeakDC_next_i_4(LeakDC
* unit
, int inNumSamples
)
1324 float *out
= ZOUT(0);
1326 double b1
= unit
->m_b1
;
1327 double y1
= unit
->m_y1
;
1328 double x1
= unit
->m_x1
;
1330 LOOP1(inNumSamples
/4,
1331 double x00
= ZXP(in
);
1332 double x01
= ZXP(in
);
1333 double x02
= ZXP(in
);
1334 double x03
= ZXP(in
);
1335 ZXP(out
) = y1
= x00
- x1
+ b1
* y1
;
1336 ZXP(out
) = y1
= x01
- x00
+ b1
* y1
;
1337 ZXP(out
) = y1
= x02
- x01
+ b1
* y1
;
1338 ZXP(out
) = y1
= x03
- x02
+ b1
* y1
;
1343 unit
->m_y1
= zapgremlins(y1
);
1346 void LeakDC_next_i(LeakDC
* unit
, int inNumSamples
)
1348 float *out
= ZOUT(0);
1350 double b1
= unit
->m_b1
;
1351 double y1
= unit
->m_y1
;
1352 double x1
= unit
->m_x1
;
1355 double x0
= ZXP(in
);
1356 ZXP(out
) = y1
= x0
- x1
+ b1
* y1
;
1360 unit
->m_y1
= zapgremlins(y1
);
1363 void LeakDC_next(LeakDC
* unit
, int inNumSamples
)
1365 if (ZIN0(1) == unit
->m_b1
) {
1366 if ((inNumSamples
& 3) == 0)
1367 LeakDC_next_i_4(unit
, inNumSamples
);
1369 LeakDC_next_i(unit
, inNumSamples
);
1371 float *out
= ZOUT(0);
1373 double b1
= unit
->m_b1
;
1374 unit
->m_b1
= ZIN0(1);
1376 double y1
= unit
->m_y1
;
1377 double x1
= unit
->m_x1
;
1379 double b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1381 double x0
= ZXP(in
);
1382 ZXP(out
) = y1
= x0
- x1
+ b1
* y1
;
1387 unit
->m_y1
= zapgremlins(y1
);
1392 void LeakDC_next_1(LeakDC
* unit
, int inNumSamples
)
1394 double b1
= unit
->m_b1
= ZIN0(1);
1396 double y1
= unit
->m_y1
;
1397 double x1
= unit
->m_x1
;
1399 double x0
= ZIN0(0);
1400 ZOUT0(0) = y1
= x0
- x1
+ b1
* y1
;
1404 unit
->m_y1
= zapgremlins(y1
);
1407 void LeakDC_Ctor(LeakDC
*unit
)
1409 //printf("LeakDC_Ctor\n");
1411 SETCALC(LeakDC_next_1
);
1413 if (INRATE(1) == calc_ScalarRate
) {
1414 if ((BUFLENGTH
& 3) == 0)
1415 SETCALC(LeakDC_next_i_4
);
1417 SETCALC(LeakDC_next_i
);
1419 SETCALC(LeakDC_next
);
1422 unit
->m_x1
= ZIN0(0);
1424 LeakDC_next_1(unit
, 1);
1428 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1430 void TwoPole_Ctor(TwoPole
*unit
)
1432 //printf("TwoPole_Reset\n");
1433 SETCALC(TwoPole_next
);
1439 unit
->m_reson
= 0.f
;
1441 TwoPole_next(unit
, 1);
1446 void TwoPole_next(TwoPole
* unit
, int inNumSamples
)
1448 //printf("TwoPole_next_a\n");
1450 float *out
= ZOUT(0);
1452 float freq
= ZIN0(1);
1453 float reson
= ZIN0(2);
1456 float y1
= unit
->m_y1
;
1457 float y2
= unit
->m_y2
;
1459 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
1460 float b1
= unit
->m_b1
;
1461 float b2
= unit
->m_b2
;
1462 float b1_next
= 2.f
* reson
* cos(freq
* unit
->mRate
->mRadiansPerSample
);
1463 float b2_next
= -(reson
* reson
);
1464 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
1465 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
1466 LOOP(unit
->mRate
->mFilterLoops
,
1467 ZXP(out
) = y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
1468 ZXP(out
) = y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
1469 ZXP(out
) = y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
1474 LOOP(unit
->mRate
->mFilterRemain
,
1475 ZXP(out
) = y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
1480 unit
->m_freq
= freq
;
1481 unit
->m_reson
= reson
;
1485 float b1
= unit
->m_b1
;
1486 float b2
= unit
->m_b2
;
1487 LOOP(unit
->mRate
->mFilterLoops
,
1488 ZXP(out
) = y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
1489 ZXP(out
) = y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
1490 ZXP(out
) = y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
1492 LOOP(unit
->mRate
->mFilterRemain
,
1493 ZXP(out
) = y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
1498 unit
->m_y1
= zapgremlins(y1
);
1499 unit
->m_y2
= zapgremlins(y2
);
1503 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1506 void TwoZero_Ctor(TwoZero
* unit
)
1508 //printf("TwoZero_Reset\n");
1509 SETCALC(TwoZero_next
);
1515 unit
->m_reson
= 0.f
;
1517 TwoZero_next(unit
, 1);
1521 void TwoZero_next(TwoZero
* unit
, int inNumSamples
)
1523 //printf("TwoZero_next\n");
1525 float *out
= ZOUT(0);
1527 float freq
= ZIN0(1);
1528 float reson
= ZIN0(2);
1531 float x1
= unit
->m_x1
;
1532 float x2
= unit
->m_x2
;
1534 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
1535 float b1
= unit
->m_b1
;
1536 float b2
= unit
->m_b2
;
1537 float b1_next
= -2.f
* reson
* cos(freq
* unit
->mRate
->mRadiansPerSample
);
1538 float b2_next
= (reson
* reson
);
1539 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
1540 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
1541 LOOP(unit
->mRate
->mFilterLoops
,
1543 ZXP(out
) = x0
+ b1
* x1
+ b2
* x2
;
1545 ZXP(out
) = x2
+ b1
* x0
+ b2
* x1
;
1547 ZXP(out
) = x1
+ b1
* x2
+ b2
* x0
;
1552 LOOP(unit
->mRate
->mFilterRemain
,
1554 ZXP(out
) = x0
+ b1
* x1
+ b2
* x2
;
1559 unit
->m_freq
= freq
;
1560 unit
->m_reson
= reson
;
1564 float b1
= unit
->m_b1
;
1565 float b2
= unit
->m_b2
;
1566 LOOP(unit
->mRate
->mFilterLoops
,
1568 ZXP(out
) = x0
+ b1
* x1
+ b2
* x2
;
1570 ZXP(out
) = x2
+ b1
* x0
+ b2
* x1
;
1572 ZXP(out
) = x1
+ b1
* x2
+ b2
* x0
;
1574 LOOP(unit
->mRate
->mFilterRemain
,
1576 ZXP(out
) = x0
+ b1
* x1
+ b2
* x2
;
1586 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1589 void APF_Ctor(APF
* unit
)
1591 //printf("APF_Reset\n");
1600 unit
->m_reson
= 0.f
;
1607 void APF_next(APF
* unit
, int inNumSamples
)
1609 //printf("APF_next_a\n");
1611 float *out
= ZOUT(0);
1613 float freq
= ZIN0(1);
1614 float reson
= ZIN0(2);
1617 float y1
= unit
->m_y1
;
1618 float y2
= unit
->m_y2
;
1619 float x1
= unit
->m_x1
;
1620 float x2
= unit
->m_x2
;
1622 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
1623 float b1
= unit
->m_b1
;
1624 float b2
= unit
->m_b2
;
1625 float b1_next
= 2.f
* reson
* cos(freq
* unit
->mRate
->mRadiansPerSample
);
1626 float b2_next
= -(reson
* reson
);
1627 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
1628 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
1629 LOOP(unit
->mRate
->mFilterLoops
,
1631 ZXP(out
) = y0
= x0
+ b1
* (y1
- x1
) + b2
* (y2
- x2
);
1633 ZXP(out
) = y2
= x2
+ b1
* (y0
- x0
) + b2
* (y2
- x1
);
1635 ZXP(out
) = y1
= x1
+ b1
* (y2
- x2
) + b2
* (y2
- x0
);
1640 LOOP(unit
->mRate
->mFilterRemain
,
1642 ZXP(out
) = y0
= x0
+ b1
* (y1
- x1
) + b2
* (y2
- x2
);
1649 unit
->m_freq
= freq
;
1650 unit
->m_reson
= reson
;
1654 float b1
= unit
->m_b1
;
1655 float b2
= unit
->m_b2
;
1656 LOOP(unit
->mRate
->mFilterLoops
,
1658 ZXP(out
) = y0
= x0
+ b1
* (y1
- x1
) + b2
* (y2
- x2
);
1660 ZXP(out
) = y2
= x2
+ b1
* (y0
- x0
) + b2
* (y2
- x1
);
1662 ZXP(out
) = y1
= x1
+ b1
* (y2
- x2
) + b2
* (y2
- x0
);
1664 LOOP(unit
->mRate
->mFilterRemain
,
1666 ZXP(out
) = y0
= x0
+ b1
* (y1
- x1
) + b2
* (y2
- x2
);
1673 unit
->m_y1
= zapgremlins(y1
);
1674 unit
->m_y2
= zapgremlins(y2
);
1679 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1681 void LPZ1_Ctor(LPZ1
* unit
)
1683 //printf("LPZ1_Reset\n");
1685 unit
->m_x1
= ZIN0(0);
1690 void LPZ1_next(LPZ1
* unit
, int inNumSamples
)
1692 //printf("LPZ1_next_a\n");
1694 float *out
= ZOUT(0);
1698 float x1
= unit
->m_x1
;
1700 LOOP(inNumSamples
>> 2,
1702 ZXP(out
) = 0.5f
* (x0
+ x1
);
1704 ZXP(out
) = 0.5f
* (x1
+ x0
);
1706 ZXP(out
) = 0.5f
* (x0
+ x1
);
1708 ZXP(out
) = 0.5f
* (x1
+ x0
);
1710 LOOP(inNumSamples
& 3,
1712 ZXP(out
) = 0.5f
* (x0
+ x1
);
1719 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1722 void HPZ1_Ctor(HPZ1
* unit
)
1724 //printf("HPZ1_Reset\n");
1726 unit
->m_x1
= ZIN0(0);
1731 void HPZ1_next(HPZ1
* unit
, int inNumSamples
)
1733 //printf("HPZ1_next\n");
1735 float *out
= ZOUT(0);
1739 float x1
= unit
->m_x1
;
1741 LOOP(inNumSamples
>> 2,
1743 ZXP(out
) = 0.5f
* (x0
- x1
);
1745 ZXP(out
) = 0.5f
* (x1
- x0
);
1747 ZXP(out
) = 0.5f
* (x0
- x1
);
1749 ZXP(out
) = 0.5f
* (x1
- x0
);
1751 LOOP(inNumSamples
& 3,
1753 //printf("%d %d %g %g\n", this, inNumSamples, x0, x1);
1754 ZXP(out
) = 0.5f
* (x0
- x1
);
1761 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1763 void Slope_Ctor(Slope
* unit
)
1765 //printf("Slope_Reset\n");
1766 SETCALC(Slope_next
);
1767 unit
->m_x1
= ZIN0(0);
1768 //printf("Slope_Reset %g\n", unit->m_x1);
1769 Slope_next(unit
, 1);
1773 void Slope_next(Slope
* unit
, int inNumSamples
)
1775 //printf("Slope_next_a %g\n", unit->m_x1);
1777 float *out
= ZOUT(0);
1780 float x1
= unit
->m_x1
;
1782 float sr
= SAMPLERATE
;
1785 ZXP(out
) = sr
* (x0
- x1
);
1792 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1794 void Delay1_Ctor(Delay1
* unit
)
1796 //printf("Delay1_Reset\n");
1797 SETCALC(Delay1_next
);
1798 unit
->m_x1
= ZIN0(0);
1799 Delay1_next(unit
, 1);
1803 void Delay1_next(Delay1
* unit
, int inNumSamples
)
1805 //printf("Delay1_next_a\n");
1807 float *out
= ZOUT(0);
1811 float x1
= unit
->m_x1
;
1813 LOOP(inNumSamples
>> 2,
1823 LOOP(inNumSamples
& 3,
1832 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1834 void Flip_Ctor(Flip
* unit
)
1836 if (unit
->mBufLength
& 1) {
1837 SETCALC(Flip_next_odd
);
1838 Flip_next_odd(unit
, 1);
1840 SETCALC(Flip_next_even
);
1846 void Flip_next_even(Flip
* unit
, int inNumSamples
)
1848 float *out
= ZOUT(0);
1851 LOOP(inNumSamples
>> 1,
1852 ZXP(out
) = -ZXP(in
);
1857 void Flip_next_odd(Flip
* unit
, int inNumSamples
)
1859 float *out
= ZOUT(0);
1862 if (unit
->mWorld
->mBufCounter
& 1) {
1864 LOOP(inNumSamples
>> 1,
1865 ZXP(out
) = -ZXP(in
);
1869 LOOP(inNumSamples
>> 1,
1870 ZXP(out
) = -ZXP(in
);
1873 ZXP(out
) = -ZXP(in
);
1877 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1879 void Delay2_Ctor(Delay2
* unit
)
1881 SETCALC(Delay2_next
);
1882 unit
->m_x1
= ZIN0(0);
1887 void Delay2_next(Delay2
* unit
, int inNumSamples
)
1889 float *out
= ZOUT(0);
1893 float x1
= unit
->m_x1
;
1894 float x2
= unit
->m_x2
;
1896 LOOP(unit
->mRate
->mFilterLoops
,
1904 LOOP(unit
->mRate
->mFilterRemain
,
1915 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1918 void LPZ2_Ctor(LPZ2
* unit
)
1920 //printf("LPZ2_Reset\n");
1922 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
1929 void LPZ2_next(LPZ2
* unit
, int inNumSamples
)
1931 //printf("LPZ2_next_a\n");
1933 float *out
= ZOUT(0);
1937 float x1
= unit
->m_x1
;
1938 float x2
= unit
->m_x2
;
1940 LOOP(unit
->mRate
->mFilterLoops
,
1942 ZXP(out
) = (x0
+ 2.f
* x1
+ x2
) * 0.25f
;
1944 ZXP(out
) = (x2
+ 2.f
* x0
+ x1
) * 0.25f
;
1946 ZXP(out
) = (x1
+ 2.f
* x2
+ x0
) * 0.25f
;
1948 LOOP(unit
->mRate
->mFilterRemain
,
1950 ZXP(out
) = (x0
+ 2.f
* x1
+ x2
) * 0.25f
;
1959 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1961 void HPZ2_Ctor(HPZ2
* unit
)
1963 //printf("HPZ2_Reset\n");
1965 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
1972 void HPZ2_next(HPZ2
* unit
, int inNumSamples
)
1974 //printf("HPZ2_next_a\n");
1976 float *out
= ZOUT(0);
1980 float x1
= unit
->m_x1
;
1981 float x2
= unit
->m_x2
;
1983 LOOP(unit
->mRate
->mFilterLoops
,
1985 ZXP(out
) = (x0
- 2.f
* x1
+ x2
) * 0.25f
;
1987 ZXP(out
) = (x2
- 2.f
* x0
+ x1
) * 0.25f
;
1989 ZXP(out
) = (x1
- 2.f
* x2
+ x0
) * 0.25f
;
1991 LOOP(unit
->mRate
->mFilterRemain
,
1993 ZXP(out
) = (x0
- 2.f
* x1
+ x2
) * 0.25f
;
2002 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2004 void BPZ2_Ctor(BPZ2
* unit
)
2006 //printf("BPZ2_Reset\n");
2008 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
2015 void BPZ2_next(BPZ2
* unit
, int inNumSamples
)
2017 //printf("BPZ2_next_a\n");
2019 float *out
= ZOUT(0);
2023 float x1
= unit
->m_x1
;
2024 float x2
= unit
->m_x2
;
2026 LOOP(unit
->mRate
->mFilterLoops
,
2028 ZXP(out
) = (x0
- x2
) * 0.5f
;
2030 ZXP(out
) = (x2
- x1
) * 0.5f
;
2032 ZXP(out
) = (x1
- x0
) * 0.5f
;
2034 LOOP(unit
->mRate
->mFilterRemain
,
2036 ZXP(out
) = (x0
- x2
) * 0.5f
;
2045 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2047 void BRZ2_Ctor(BRZ2
* unit
)
2049 //printf("BRZ2_Reset\n");
2051 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
2058 void BRZ2_next(BRZ2
* unit
, int inNumSamples
)
2060 //printf("BRZ2_next_a\n");
2062 float *out
= ZOUT(0);
2066 float x1
= unit
->m_x1
;
2067 float x2
= unit
->m_x2
;
2069 LOOP(unit
->mRate
->mFilterLoops
,
2071 ZXP(out
) = (x0
+ x2
) * 0.5f
;
2073 ZXP(out
) = (x2
+ x1
) * 0.5f
;
2075 ZXP(out
) = (x1
+ x0
) * 0.5f
;
2077 LOOP(unit
->mRate
->mFilterRemain
,
2079 ZXP(out
) = (x0
+ x2
) * 0.5f
;
2088 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2090 void Slew_Ctor(Slew
* unit
)
2092 //printf("Slew_Reset\n");
2094 unit
->mLevel
= ZIN0(0);
2099 void Slew_next(Slew
* unit
, int inNumSamples
)
2101 //printf("Slew_next_a\n");
2103 float *out
= ZOUT(0);
2105 float upf
= ZIN0(1) * unit
->mRate
->mSampleDur
;
2106 float dnf
= 0.f
- ZIN0(2) * unit
->mRate
->mSampleDur
;
2107 float level
= unit
->mLevel
;
2109 float slope
= ZXP(in
) - level
;
2110 level
+= sc_clip(slope
,dnf
,upf
);
2113 unit
->mLevel
= level
;
2116 /*void Slew_next_1(Slew* unit, int inNumSamples)
2118 //printf("Slew_next_a\n");
2120 float *out = ZOUT(0);
2122 float upf = ZIN0(1);
2123 float dnf = ZIN0(2);
2124 float level = unit->mLevel;
2125 float slope = ZXP(in) - level;
2126 if (slope > upf) slope = upf;
2127 else if (slope < dnf) slope = dnf;
2130 unit->mLevel = level;
2134 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2136 void RLPF_Ctor(RLPF
* unit
)
2138 //printf("RLPF_Reset\n");
2139 if (unit
->mBufLength
== 1) {
2140 SETCALC(RLPF_next_1
);
2151 unit
->m_reson
= 0.f
;
2152 RLPF_next_1(unit
, 1);
2156 void RLPF_next(RLPF
* unit
, int inNumSamples
)
2158 //printf("RLPF_next\n");
2160 float *out
= ZOUT(0);
2162 float freq
= ZIN0(1);
2163 float reson
= ZIN0(2);
2166 float y1
= unit
->m_y1
;
2167 float y2
= unit
->m_y2
;
2168 float a0
= unit
->m_a0
;
2169 float b1
= unit
->m_b1
;
2170 float b2
= unit
->m_b2
;
2172 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2174 float qres
= sc_max(0.001, reson
);
2175 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2177 float D
= tan(pfreq
* qres
* 0.5);
2178 float C
= ((1.f
-D
)/(1.f
+D
));
2179 float cosf
= cos(pfreq
);
2181 float next_b1
= (1.f
+ C
) * cosf
;
2183 float next_a0
= (1.f
+ C
- next_b1
) * .25;
2184 //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);
2186 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2187 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2188 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2189 LOOP(unit
->mRate
->mFilterLoops
,
2190 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2191 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2193 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2194 ZXP(out
) = y2
+ 2.f
* y0
+ y1
;
2196 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2197 ZXP(out
) = y1
+ 2.f
* y2
+ y0
;
2203 LOOP(unit
->mRate
->mFilterRemain
,
2204 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2205 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2210 unit
->m_freq
= freq
;
2211 unit
->m_reson
= reson
;
2216 LOOP(unit
->mRate
->mFilterLoops
,
2217 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2218 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2220 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2221 ZXP(out
) = y2
+ 2.f
* y0
+ y1
;
2223 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2224 ZXP(out
) = y1
+ 2.f
* y2
+ y0
;
2226 LOOP(unit
->mRate
->mFilterRemain
,
2227 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2228 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2233 unit
->m_y1
= zapgremlins(y1
);
2234 unit
->m_y2
= zapgremlins(y2
);
2238 void RLPF_next_1(RLPF
* unit
, int inNumSamples
)
2240 //printf("RLPF_next_1\n");
2243 float freq
= ZIN0(1);
2244 float reson
= ZIN0(2);
2247 float y1
= unit
->m_y1
;
2248 float y2
= unit
->m_y2
;
2249 float a0
= unit
->m_a0
;
2250 float b1
= unit
->m_b1
;
2251 float b2
= unit
->m_b2
;
2253 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2254 float qres
= sc_max(0.001f
, reson
);
2255 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2257 float D
= tan(pfreq
* qres
* 0.5f
);
2258 float C
= ((1.f
-D
)/(1.f
+D
));
2259 float cosf
= cos(pfreq
);
2261 b1
= (1.f
+ C
) * cosf
;
2263 a0
= (1.f
+ C
- b1
) * .25f
;
2265 y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2266 ZOUT0(0) = y0
+ 2.f
* y1
+ y2
;
2270 unit
->m_freq
= freq
;
2271 unit
->m_reson
= reson
;
2276 y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2277 ZOUT0(0) = y0
+ 2.f
* y1
+ y2
;
2281 unit
->m_y1
= zapgremlins(y1
);
2282 unit
->m_y2
= zapgremlins(y2
);
2287 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2289 void RHPF_Ctor(RHPF
* unit
)
2291 if (unit
->mBufLength
== 1)
2292 SETCALC(RHPF_next_1
);
2302 unit
->m_reson
= 0.f
;
2303 RHPF_next_1(unit
, 1);
2307 void RHPF_next(RHPF
* unit
, int inNumSamples
)
2309 //printf("RHPFs_next\n");
2311 float *out
= ZOUT(0);
2313 float freq
= ZIN0(1);
2314 float reson
= ZIN0(2);
2316 double y1
= unit
->m_y1
;
2317 double y2
= unit
->m_y2
;
2318 double a0
= unit
->m_a0
;
2319 double b1
= unit
->m_b1
;
2320 double b2
= unit
->m_b2
;
2322 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2323 float qres
= sc_max(0.001f
, reson
);
2324 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2326 double D
= tan(pfreq
* qres
* 0.5f
);
2327 double C
= ((1.-D
)/(1.+D
));
2328 double cosf
= cos(pfreq
);
2330 double next_b1
= (1. + C
) * cosf
;
2331 double next_b2
= -C
;
2332 double next_a0
= (1. + C
+ next_b1
) * .25;
2334 //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);
2336 double a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2337 double b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2338 double b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2339 LOOP(unit
->mRate
->mFilterLoops
,
2340 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2341 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2343 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2344 ZXP(out
) = y2
- 2.f
* y0
+ y1
;
2346 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2347 ZXP(out
) = y1
- 2.f
* y2
+ y0
;
2353 LOOP(unit
->mRate
->mFilterRemain
,
2354 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2355 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2360 unit
->m_freq
= freq
;
2361 unit
->m_reson
= reson
;
2366 LOOP(unit
->mRate
->mFilterLoops
,
2367 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2368 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2370 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2371 ZXP(out
) = y2
- 2.f
* y0
+ y1
;
2373 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2374 ZXP(out
) = y1
- 2.f
* y2
+ y0
;
2376 LOOP(unit
->mRate
->mFilterRemain
,
2377 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2378 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2383 unit
->m_y1
= zapgremlins(y1
);
2384 unit
->m_y2
= zapgremlins(y2
);
2387 void RHPF_next_1(RHPF
* unit
, int inNumSamples
)
2389 //printf("RHPFs_next_1\n");
2392 float freq
= ZIN0(1);
2393 float reson
= ZIN0(2);
2395 double y1
= unit
->m_y1
;
2396 double y2
= unit
->m_y2
;
2397 double a0
= unit
->m_a0
;
2398 double b1
= unit
->m_b1
;
2399 double b2
= unit
->m_b2
;
2401 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2402 float qres
= sc_max(0.001f
, reson
);
2403 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2405 double D
= tan(pfreq
* qres
* 0.5f
);
2406 double C
= ((1.-D
)/(1.+D
));
2407 double cosf
= cos(pfreq
);
2409 b1
= (1. + C
) * cosf
;
2411 a0
= (1. + C
+ b1
) * .25;
2413 double y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2414 ZOUT0(0) = y0
- 2.f
* y1
+ y2
;
2418 unit
->m_freq
= freq
;
2419 unit
->m_reson
= reson
;
2424 double y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2425 ZOUT0(0) = y0
- 2.f
* y1
+ y2
;
2429 unit
->m_y1
= zapgremlins(y1
);
2430 unit
->m_y2
= zapgremlins(y2
);
2434 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2436 void LPF_Ctor(LPF
* unit
)
2438 if (unit
->mBufLength
== 1)
2439 SETCALC(LPF_next_1
);
2449 LPF_next_1(unit
, 1);
2453 void LPF_next(LPF
* unit
, int inNumSamples
)
2455 //printf("LPF_next\n");
2457 float *out
= ZOUT(0);
2459 float freq
= ZIN0(1);
2462 float y1
= unit
->m_y1
;
2463 float y2
= unit
->m_y2
;
2464 float a0
= unit
->m_a0
;
2465 float b1
= unit
->m_b1
;
2466 float b2
= unit
->m_b2
;
2468 if (freq
!= unit
->m_freq
) {
2470 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2472 float C
= 1.f
/ tan(pfreq
);
2474 float sqrt2C
= C
* sqrt2_f
;
2475 float next_a0
= 1.f
/ (1.f
+ sqrt2C
+ C2
);
2476 float next_b1
= -2.f
* (1.f
- C2
) * next_a0
;
2477 float next_b2
= -(1.f
- sqrt2C
+ C2
) * next_a0
;
2479 //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);
2481 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2482 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2483 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2484 LOOP(unit
->mRate
->mFilterLoops
,
2485 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2486 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2488 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2489 ZXP(out
) = a0
* (y2
+ 2.f
* y0
+ y1
);
2491 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2492 ZXP(out
) = a0
* (y1
+ 2.f
* y2
+ y0
);
2498 LOOP(unit
->mRate
->mFilterRemain
,
2499 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2500 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2505 unit
->m_freq
= freq
;
2510 LOOP(unit
->mRate
->mFilterLoops
,
2511 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2512 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2514 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2515 ZXP(out
) = a0
* (y2
+ 2.f
* y0
+ y1
);
2517 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2518 ZXP(out
) = a0
* (y1
+ 2.f
* y2
+ y0
);
2520 LOOP(unit
->mRate
->mFilterRemain
,
2521 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2522 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2527 unit
->m_y1
= zapgremlins(y1
);
2528 unit
->m_y2
= zapgremlins(y2
);
2531 void LPF_next_1(LPF
* unit
, int inNumSamples
)
2533 //printf("LPF_next\n");
2535 float freq
= ZIN0(1);
2538 float y1
= unit
->m_y1
;
2539 float y2
= unit
->m_y2
;
2540 float a0
= unit
->m_a0
;
2541 float b1
= unit
->m_b1
;
2542 float b2
= unit
->m_b2
;
2544 if (freq
!= unit
->m_freq
) {
2546 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2548 float C
= 1.f
/ tan(pfreq
);
2550 float sqrt2C
= C
* sqrt2_f
;
2551 a0
= 1.f
/ (1.f
+ sqrt2C
+ C2
);
2552 b1
= -2.f
* (1.f
- C2
) * a0
;
2553 b2
= -(1.f
- sqrt2C
+ C2
) * a0
;
2555 y0
= in
+ b1
* y1
+ b2
* y2
;
2556 ZOUT0(0) = a0
* (y0
+ 2.f
* y1
+ y2
);
2560 unit
->m_freq
= freq
;
2566 y0
= in
+ b1
* y1
+ b2
* y2
;
2567 ZOUT0(0) = a0
* (y0
+ 2.f
* y1
+ y2
);
2572 unit
->m_y1
= zapgremlins(y1
);
2573 unit
->m_y2
= zapgremlins(y2
);
2577 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2579 void HPF_Ctor(HPF
* unit
)
2581 if (unit
->mBufLength
== 1)
2582 SETCALC(HPF_next_1
);
2590 unit
->m_freq
= -1e6f
;
2592 HPF_next_1(unit
, 1);
2596 void HPF_next(HPF
* unit
, int inNumSamples
)
2598 float *out
= ZOUT(0);
2600 float freq
= ZIN0(1);
2602 double y1
= unit
->m_y1
;
2603 double y2
= unit
->m_y2
;
2604 double a0
= unit
->m_a0
;
2605 double b1
= unit
->m_b1
;
2606 double b2
= unit
->m_b2
;
2608 if (freq
!= unit
->m_freq
) {
2609 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2611 double C
= tan(pfreq
);
2613 double sqrt2C
= C
* sqrt2_f
;
2614 double next_a0
= 1. / (1. + sqrt2C
+ C2
);
2615 double next_b1
= 2. * (1. - C2
) * next_a0
;
2616 double next_b2
= -(1. - sqrt2C
+ C2
) * next_a0
;
2618 //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);
2620 double a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2621 double b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2622 double b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2623 LOOP(unit
->mRate
->mFilterLoops
,
2624 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2625 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2627 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2628 ZXP(out
) = a0
* (y2
- 2. * y0
+ y1
);
2630 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2631 ZXP(out
) = a0
* (y1
- 2. * y2
+ y0
);
2637 LOOP(unit
->mRate
->mFilterRemain
,
2638 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2639 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2644 unit
->m_freq
= freq
;
2649 LOOP(unit
->mRate
->mFilterLoops
,
2650 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2651 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2653 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2654 ZXP(out
) = a0
* (y2
- 2. * y0
+ y1
);
2656 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2657 ZXP(out
) = a0
* (y1
- 2. * y2
+ y0
);
2659 LOOP(unit
->mRate
->mFilterRemain
,
2660 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2661 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2666 unit
->m_y1
= zapgremlins(y1
);
2667 unit
->m_y2
= zapgremlins(y2
);
2670 void HPF_next_1(HPF
* unit
, int inNumSamples
)
2672 double in
= ZIN0(0);
2673 double freq
= ZIN0(1);
2675 double y1
= unit
->m_y1
;
2676 double y2
= unit
->m_y2
;
2677 double a0
= unit
->m_a0
;
2678 double b1
= unit
->m_b1
;
2679 double b2
= unit
->m_b2
;
2681 if (freq
!= unit
->m_freq
) {
2682 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5f
;
2684 double C
= tan(pfreq
);
2686 double sqrt2C
= C
* sqrt2_f
;
2687 a0
= 1. / (1. + sqrt2C
+ C2
);
2688 b1
= 2. * (1. - C2
) * a0
;
2689 b2
= -(1. - sqrt2C
+ C2
) * a0
;
2691 double y0
= in
+ b1
* y1
+ b2
* y2
;
2692 ZOUT0(0) = a0
* (y0
- 2. * y1
+ y2
);
2696 unit
->m_freq
= freq
;
2701 double y0
= in
+ b1
* y1
+ b2
* y2
;
2702 ZOUT0(0) = a0
* (y0
- 2. * y1
+ y2
);
2707 unit
->m_y1
= zapgremlins(y1
);
2708 unit
->m_y2
= zapgremlins(y2
);
2711 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2713 void BPF_Ctor(BPF
* unit
)
2715 //printf("BPF_Reset\n");
2716 if (unit
->mBufLength
== 1) {
2717 SETCALC(BPF_next_1
);
2729 BPF_next_1(unit
, 1);
2732 void BPF_next(BPF
* unit
, int inNumSamples
)
2734 //printf("BPF_next\n");
2736 float *out
= ZOUT(0);
2738 float freq
= ZIN0(1);
2742 float y1
= unit
->m_y1
;
2743 float y2
= unit
->m_y2
;
2744 float a0
= unit
->m_a0
;
2745 float b1
= unit
->m_b1
;
2746 float b2
= unit
->m_b2
;
2748 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2750 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2751 float pbw
= bw
* pfreq
* 0.5f
;
2753 float C
= 1.f
/ tan(pbw
);
2754 float D
= 2.f
* cos(pfreq
);
2756 float next_a0
= 1.f
/ (1.f
+ C
);
2757 float next_b1
= C
* D
* next_a0
;
2758 float next_b2
= (1.f
- C
) * next_a0
;
2760 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2761 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2762 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2763 LOOP(unit
->mRate
->mFilterLoops
,
2764 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2765 ZXP(out
) = a0
* (y0
- y2
);
2767 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2768 ZXP(out
) = a0
* (y2
- y1
);
2770 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2771 ZXP(out
) = a0
* (y1
- y0
);
2777 LOOP(unit
->mRate
->mFilterRemain
,
2778 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2779 ZXP(out
) = a0
* (y0
- y2
);
2784 unit
->m_freq
= freq
;
2790 LOOP(unit
->mRate
->mFilterLoops
,
2791 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2792 ZXP(out
) = a0
* (y0
- y2
);
2794 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2795 ZXP(out
) = a0
* (y2
- y1
);
2797 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2798 ZXP(out
) = a0
* (y1
- y0
);
2800 LOOP(unit
->mRate
->mFilterRemain
,
2801 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2802 ZXP(out
) = a0
* (y0
- y2
);
2807 unit
->m_y1
= zapgremlins(y1
);
2808 unit
->m_y2
= zapgremlins(y2
);
2811 void BPF_next_1(BPF
* unit
, int inNumSamples
)
2813 //printf("BPF_next_1\n");
2816 float freq
= ZIN0(1);
2820 float y1
= unit
->m_y1
;
2821 float y2
= unit
->m_y2
;
2822 float a0
= unit
->m_a0
;
2823 float b1
= unit
->m_b1
;
2824 float b2
= unit
->m_b2
;
2826 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2828 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2829 float pbw
= bw
* pfreq
* 0.5;
2831 float C
= 1.f
/ tan(pbw
);
2832 float D
= 2.f
* cos(pfreq
);
2834 float a0
= 1.f
/ (1.f
+ C
);
2835 float b1
= C
* D
* a0
;
2836 float b2
= (1.f
- C
) * a0
;
2838 y0
= in
+ b1
* y1
+ b2
* y2
;
2839 ZOUT0(0) = a0
* (y0
- y2
);
2843 unit
->m_freq
= freq
;
2849 y0
= in
+ b1
* y1
+ b2
* y2
;
2850 ZOUT0(0) = a0
* (y0
- y2
);
2854 unit
->m_y1
= zapgremlins(y1
);
2855 unit
->m_y2
= zapgremlins(y2
);
2859 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2861 void BRF_Ctor(BRF
* unit
)
2863 //printf("BRF_Reset\n");
2864 if (unit
->mBufLength
== 1) {
2865 SETCALC(BRF_next_1
);
2876 BRF_next_1(unit
, 1);
2880 void BRF_next(BRF
* unit
, int inNumSamples
)
2882 //printf("BRF_next\n");
2884 float *out
= ZOUT(0);
2886 float freq
= ZIN0(1);
2891 float y1
= unit
->m_y1
;
2892 float y2
= unit
->m_y2
;
2893 float a0
= unit
->m_a0
;
2894 float a1
= unit
->m_a1
;
2895 float b2
= unit
->m_b2
;
2897 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2898 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2899 float pbw
= bw
* pfreq
* 0.5f
;
2902 float D
= 2.f
* cos(pfreq
);
2904 float next_a0
= 1.f
/ (1.f
+ C
);
2905 float next_a1
= -D
* next_a0
;
2906 float next_b2
= (1.f
- C
) * next_a0
;
2908 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2909 float a1_slope
= (next_a1
- a1
) * unit
->mRate
->mFilterSlope
;
2910 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2912 LOOP(unit
->mRate
->mFilterLoops
,
2914 y0
= ZXP(in
) - ay
- b2
* y2
;
2915 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
2918 y2
= ZXP(in
) - ay
- b2
* y1
;
2919 ZXP(out
) = a0
* (y2
+ y1
) + ay
;
2922 y1
= ZXP(in
) - ay
- b2
* y0
;
2923 ZXP(out
) = a0
* (y1
+ y0
) + ay
;
2929 LOOP(unit
->mRate
->mFilterRemain
,
2931 y0
= ZXP(in
) - ay
- b2
* y2
;
2932 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
2937 unit
->m_freq
= freq
;
2943 LOOP(unit
->mRate
->mFilterLoops
,
2945 y0
= ZXP(in
) - ay
- b2
* y2
;
2946 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
2949 y2
= ZXP(in
) - ay
- b2
* y1
;
2950 ZXP(out
) = a0
* (y2
+ y1
) + ay
;
2953 y1
= ZXP(in
) - ay
- b2
* y0
;
2954 ZXP(out
) = a0
* (y1
+ y0
) + ay
;
2956 LOOP(unit
->mRate
->mFilterRemain
,
2958 y0
= ZXP(in
) - ay
- b2
* y2
;
2959 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
2964 unit
->m_y1
= zapgremlins(y1
);
2965 unit
->m_y2
= zapgremlins(y2
);
2970 void BRF_next_1(BRF
* unit
, int inNumSamples
)
2972 //printf("BRF_next_1\n");
2975 float freq
= ZIN0(1);
2980 float y1
= unit
->m_y1
;
2981 float y2
= unit
->m_y2
;
2982 float a0
= unit
->m_a0
;
2983 float a1
= unit
->m_a1
;
2984 float b2
= unit
->m_b2
;
2986 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2987 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2988 float pbw
= bw
* pfreq
* 0.5f
;
2991 float D
= 2.f
* cos(pfreq
);
2993 float a0
= 1.f
/ (1.f
+ C
);
2995 float b2
= (1.f
- C
) * a0
;
2998 y0
= in
- ay
- b2
* y2
;
2999 ZOUT0(0) = a0
* (y0
+ y2
) + ay
;
3003 unit
->m_freq
= freq
;
3011 y0
= in
- ay
- b2
* y2
;
3012 ZOUT0(0) = a0
* (y0
+ y2
) + ay
;
3017 unit
->m_y1
= zapgremlins(y1
);
3018 unit
->m_y2
= zapgremlins(y2
);
3022 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3024 void MidEQ_Ctor(MidEQ
* unit
)
3026 //printf("MidEQ_Reset\n");
3027 SETCALC(MidEQ_next
);
3037 MidEQ_next(unit
, 1);
3042 void MidEQ_next(MidEQ
* unit
, int inNumSamples
)
3044 //printf("MidEQ_next\n");
3046 float *out
= ZOUT(0);
3048 float freq
= ZIN0(1);
3053 float y1
= unit
->m_y1
;
3054 float y2
= unit
->m_y2
;
3055 float a0
= unit
->m_a0
;
3056 float b1
= unit
->m_b1
;
3057 float b2
= unit
->m_b2
;
3058 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
|| db
!= unit
->m_db
) {
3060 float amp
= sc_dbamp(db
) - 1.0f
;
3061 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3062 float pbw
= bw
* pfreq
* 0.5f
;
3064 float C
= 1.f
/ tan(pbw
);
3065 float D
= 2.f
* cos(pfreq
);
3067 float next_a0
= 1.f
/ (1.f
+ C
);
3068 float next_b1
= C
* D
* next_a0
;
3069 float next_b2
= (1.f
- C
) * next_a0
;
3071 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
3072 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
3073 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
3075 LOOP(unit
->mRate
->mFilterLoops
,
3077 y0
= zin
+ b1
* y1
+ b2
* y2
;
3078 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3081 y2
= zin
+ b1
* y0
+ b2
* y1
;
3082 ZXP(out
) = zin
+ a0
* (y2
- y1
);
3085 y1
= zin
+ b1
* y2
+ b2
* y0
;
3086 ZXP(out
) = zin
+ a0
* (y1
- y0
);
3092 LOOP(unit
->mRate
->mFilterRemain
,
3094 y0
= zin
+ b1
* y1
+ b2
* y2
;
3095 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3100 unit
->m_freq
= freq
;
3108 LOOP(unit
->mRate
->mFilterLoops
,
3110 y0
= zin
+ b1
* y1
+ b2
* y2
;
3111 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3114 y2
= zin
+ b1
* y0
+ b2
* y1
;
3115 ZXP(out
) = zin
+ a0
* (y2
- y1
);
3118 y1
= zin
+ b1
* y2
+ b2
* y0
;
3119 ZXP(out
) = zin
+ a0
* (y1
- y0
);
3121 LOOP(unit
->mRate
->mFilterRemain
,
3123 y0
= zin
+ b1
* y1
+ b2
* y2
;
3124 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3129 unit
->m_y1
= zapgremlins(y1
);
3130 unit
->m_y2
= zapgremlins(y2
);
3133 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3135 static void Median_InitMedian(Median
* unit
, long size
, float value
);
3136 static float Median_InsertMedian(Median
* unit
, float value
);
3138 void Median_Ctor(Median
* unit
)
3140 //printf("Median_Reset\n");
3141 SETCALC(Median_next
);
3143 unit
->m_medianSize
= sc_clip((int)ZIN0(0), 0, kMAXMEDIANSIZE
);
3144 Median_InitMedian(unit
, unit
->m_medianSize
, in
);
3145 ZOUT0(0) = Median_InsertMedian(unit
, in
);
3149 float Median_InsertMedian(Median
* unit
, float value
)
3153 // keeps a sorted list of the previous n=size values
3154 // the oldest is removed and the newest is inserted.
3155 // values between the oldest and the newest are shifted over by one.
3157 // values and ages are both arrays that are 'size' long.
3158 // the median value is always values[size>>1]
3160 long last
= unit
->m_medianSize
- 1;
3161 // find oldest bin and age the other bins.
3162 for (int i
=0; i
<unit
->m_medianSize
; ++i
) {
3163 if (unit
->m_medianAge
[i
] == last
) { // is it the oldest bin ?
3166 unit
->m_medianAge
[i
]++; // age the bin
3169 // move values to fill in place of the oldest and make a space for the newest
3170 // search lower if value is too small for the open space
3171 while (pos
!= 0 && value
< unit
->m_medianValue
[pos
-1]) {
3172 unit
->m_medianValue
[pos
] = unit
->m_medianValue
[pos
-1];
3173 unit
->m_medianAge
[pos
] = unit
->m_medianAge
[pos
-1];
3176 // search higher if value is too big for the open space
3177 while (pos
!= last
&& value
> unit
->m_medianValue
[pos
+1]) {
3178 unit
->m_medianValue
[pos
] = unit
->m_medianValue
[pos
+1];
3179 unit
->m_medianAge
[pos
] = unit
->m_medianAge
[pos
+1];
3182 unit
->m_medianValue
[pos
] = value
;
3183 unit
->m_medianAge
[pos
] = 0; // this is the newest bin, age = 0
3184 return unit
->m_medianValue
[unit
->m_medianSize
>>1];
3187 void Median_InitMedian(Median
* unit
, long size
, float value
)
3189 // initialize the arrays with the first value
3190 unit
->m_medianSize
= size
;
3191 for (int i
=0; i
<size
; ++i
) {
3192 unit
->m_medianValue
[i
] = value
;
3193 unit
->m_medianAge
[i
] = i
;
3197 void Median_next(Median
* unit
, int inNumSamples
)
3199 //printf("Median_next_a\n");
3201 float *out
= ZOUT(0);
3205 ZXP(out
) = Median_InsertMedian(unit
, ZXP(in
));
3210 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3212 void Resonz_Ctor(Resonz
* unit
)
3214 //printf("Resonz_Reset\n");
3215 SETCALC(Resonz_next
);
3224 Resonz_next(unit
, 1);
3229 void Resonz_next(Resonz
* unit
, int inNumSamples
)
3231 //printf("Resonz_next\n");
3233 float *out
= ZOUT(0);
3235 float freq
= ZIN0(1);
3239 float y1
= unit
->m_y1
;
3240 float y2
= unit
->m_y2
;
3241 float a0
= unit
->m_a0
;
3242 float b1
= unit
->m_b1
;
3243 float b2
= unit
->m_b2
;
3245 if (freq
!= unit
->m_freq
|| rq
!= unit
->m_rq
) {
3246 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3247 float B
= ffreq
* rq
;
3248 float R
= 1.f
- B
* 0.5f
;
3249 float twoR
= 2.f
* R
;
3251 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3252 float b1_next
= twoR
* cost
;
3253 float b2_next
= -R2
;
3254 float a0_next
= (1.f
- R2
) * 0.5f
;
3255 float a0_slope
= (a0_next
- a0
) * unit
->mRate
->mFilterSlope
;
3256 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
3257 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
3258 LOOP(unit
->mRate
->mFilterLoops
,
3259 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3260 ZXP(out
) = a0
* (y0
- y2
);
3262 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3263 ZXP(out
) = a0
* (y2
- y1
);
3265 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3266 ZXP(out
) = a0
* (y1
- y0
);
3272 LOOP(unit
->mRate
->mFilterRemain
,
3273 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3274 ZXP(out
) = a0
* (y0
- y2
);
3279 unit
->m_freq
= freq
;
3281 unit
->m_a0
= a0_next
;
3282 unit
->m_b1
= b1_next
;
3283 unit
->m_b2
= b2_next
;
3285 LOOP(unit
->mRate
->mFilterLoops
,
3286 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3287 ZXP(out
) = a0
* (y0
- y2
);
3289 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3290 ZXP(out
) = a0
* (y2
- y1
);
3292 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3293 ZXP(out
) = a0
* (y1
- y0
);
3295 LOOP(unit
->mRate
->mFilterRemain
,
3296 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3297 ZXP(out
) = a0
* (y0
- y2
);
3302 unit
->m_y1
= zapgremlins(y1
);
3303 unit
->m_y2
= zapgremlins(y2
);
3307 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3309 void Ringz_Ctor(Ringz
* unit
)
3311 //printf("Ringz_ctor\n");
3312 SETCALC(Ringz_next
);
3318 unit
->m_decayTime
= 0.f
;
3320 Ringz_next(unit
, 1);
3325 void Ringz_next(Ringz
* unit
, int inNumSamples
)
3327 //printf("Ringz_next\n");
3329 float *out
= ZOUT(0);
3331 float freq
= ZIN0(1);
3332 float decayTime
= ZIN0(2);
3335 float y1
= unit
->m_y1
;
3336 float y2
= unit
->m_y2
;
3338 float b1
= unit
->m_b1
;
3339 float b2
= unit
->m_b2
;
3341 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
) {
3342 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3343 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3344 float twoR
= 2.f
* R
;
3346 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3347 float b1_next
= twoR
* cost
;
3348 float b2_next
= -R2
;
3349 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
3350 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
3351 LOOP(unit
->mRate
->mFilterLoops
,
3352 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3353 ZXP(out
) = a0
* (y0
- y2
);
3355 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3356 ZXP(out
) = a0
* (y2
- y1
);
3358 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3359 ZXP(out
) = a0
* (y1
- y0
);
3364 LOOP(unit
->mRate
->mFilterRemain
,
3365 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3366 ZXP(out
) = a0
* (y0
- y2
);
3371 unit
->m_freq
= freq
;
3372 unit
->m_decayTime
= decayTime
;
3373 unit
->m_b1
= b1_next
;
3374 unit
->m_b2
= b2_next
;
3376 LOOP(unit
->mRate
->mFilterLoops
,
3377 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3378 ZXP(out
) = a0
* (y0
- y2
);
3380 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3381 ZXP(out
) = a0
* (y2
- y1
);
3383 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3384 ZXP(out
) = a0
* (y1
- y0
);
3386 LOOP(unit
->mRate
->mFilterRemain
,
3387 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3388 ZXP(out
) = a0
* (y0
- y2
);
3393 unit
->m_y1
= zapgremlins(y1
);
3394 unit
->m_y2
= zapgremlins(y2
);
3398 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3400 void Formlet_Ctor(Formlet
* unit
)
3402 //printf("Formlet_Reset\n");
3403 if (unit
->mBufLength
== 1) {
3404 SETCALC(Formlet_next_1
);
3406 SETCALC(Formlet_next
);
3417 unit
->m_attackTime
= 0.f
;
3418 unit
->m_decayTime
= 0.f
;
3419 Formlet_next_1(unit
, 1);
3422 void Formlet_next(Formlet
* unit
, int inNumSamples
)
3424 //printf("Formlet_next\n");
3426 float *out
= ZOUT(0);
3428 float freq
= ZIN0(1);
3429 float attackTime
= ZIN0(2);
3430 float decayTime
= ZIN0(3);
3434 float y01
= unit
->m_y01
;
3435 float y11
= unit
->m_y11
;
3436 float y02
= unit
->m_y02
;
3437 float y12
= unit
->m_y12
;
3439 float b01
= unit
->m_b01
;
3440 float b11
= unit
->m_b11
;
3441 float b02
= unit
->m_b02
;
3442 float b12
= unit
->m_b12
;
3445 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
|| attackTime
!= unit
->m_attackTime
) {
3446 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3448 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3449 float twoR
= 2.f
* R
;
3451 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3452 float b01_next
= twoR
* cost
;
3453 float b02_next
= -R2
;
3454 float b01_slope
= (b01_next
- b01
) * unit
->mRate
->mFilterSlope
;
3455 float b02_slope
= (b02_next
- b02
) * unit
->mRate
->mFilterSlope
;
3457 R
= attackTime
== 0.f
? 0.f
: exp(log001
/(attackTime
* SAMPLERATE
));
3460 cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3461 float b11_next
= twoR
* cost
;
3462 float b12_next
= -R2
;
3463 float b11_slope
= (b11_next
- b11
) * unit
->mRate
->mFilterSlope
;
3464 float b12_slope
= (b12_next
- b12
) * unit
->mRate
->mFilterSlope
;
3466 LOOP(unit
->mRate
->mFilterLoops
,
3468 y00
= ain
+ b01
* y01
+ b02
* y02
;
3469 y10
= ain
+ b11
* y11
+ b12
* y12
;
3470 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3473 y02
= ain
+ b01
* y00
+ b02
* y01
;
3474 y12
= ain
+ b11
* y10
+ b12
* y11
;
3475 ZXP(out
) = 0.25f
* ((y02
- y01
) - (y12
- y11
));
3478 y01
= ain
+ b01
* y02
+ b02
* y00
;
3479 y11
= ain
+ b11
* y12
+ b12
* y10
;
3480 ZXP(out
) = 0.25f
* ((y01
- y00
) - (y11
- y10
));
3487 LOOP(unit
->mRate
->mFilterRemain
,
3489 y00
= ain
+ b01
* y01
+ b02
* y02
;
3490 y10
= ain
+ b11
* y11
+ b12
* y12
;
3491 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3498 unit
->m_freq
= freq
;
3499 unit
->m_attackTime
= attackTime
;
3500 unit
->m_decayTime
= decayTime
;
3501 unit
->m_b01
= b01_next
;
3502 unit
->m_b02
= b02_next
;
3503 unit
->m_b11
= b11_next
;
3504 unit
->m_b12
= b12_next
;
3506 LOOP(unit
->mRate
->mFilterLoops
,
3508 y00
= ain
+ b01
* y01
+ b02
* y02
;
3509 y10
= ain
+ b11
* y11
+ b12
* y12
;
3510 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3513 y02
= ain
+ b01
* y00
+ b02
* y01
;
3514 y12
= ain
+ b11
* y10
+ b12
* y11
;
3515 ZXP(out
) = 0.25f
* ((y02
- y01
) - (y12
- y11
));
3518 y01
= ain
+ b01
* y02
+ b02
* y00
;
3519 y11
= ain
+ b11
* y12
+ b12
* y10
;
3520 ZXP(out
) = 0.25f
* ((y01
- y00
) - (y11
- y10
));
3522 LOOP(unit
->mRate
->mFilterRemain
,
3524 y00
= ain
+ b01
* y01
+ b02
* y02
;
3525 y10
= ain
+ b11
* y11
+ b12
* y12
;
3526 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3539 void Formlet_next_1(Formlet
* unit
, int inNumSamples
)
3541 //printf("Formlet_next\n");
3544 float freq
= ZIN0(1);
3545 float attackTime
= ZIN0(2);
3546 float decayTime
= ZIN0(3);
3550 float y01
= unit
->m_y01
;
3551 float y11
= unit
->m_y11
;
3552 float y02
= unit
->m_y02
;
3553 float y12
= unit
->m_y12
;
3555 float b01
= unit
->m_b01
;
3556 float b11
= unit
->m_b11
;
3557 float b02
= unit
->m_b02
;
3558 float b12
= unit
->m_b12
;
3561 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
|| attackTime
!= unit
->m_attackTime
) {
3562 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3564 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3565 float twoR
= 2.f
* R
;
3567 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3571 R
= attackTime
== 0.f
? 0.f
: exp(log001
/(attackTime
* SAMPLERATE
));
3574 cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3579 y00
= ain
+ b01
* y01
+ b02
* y02
;
3580 y10
= ain
+ b11
* y11
+ b12
* y12
;
3581 ZOUT0(0) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3588 unit
->m_freq
= freq
;
3589 unit
->m_attackTime
= attackTime
;
3590 unit
->m_decayTime
= decayTime
;
3597 y00
= ain
+ b01
* y01
+ b02
* y02
;
3598 y10
= ain
+ b11
* y11
+ b12
* y12
;
3599 ZOUT0(0) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3613 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3615 void FOS_Ctor(FOS
* unit
)
3617 //printf("FOS_Reset\n");
3618 if (unit
->mBufLength
== 1) {
3619 SETCALC(FOS_next_1
);
3621 if (INRATE(1) == calc_FullRate
3622 && INRATE(2) == calc_FullRate
3623 && INRATE(3) == calc_FullRate
) {
3624 SETCALC(FOS_next_a
);
3626 SETCALC(FOS_next_k
);
3633 FOS_next_1(unit
, 1);
3636 void FOS_next_a(FOS
* unit
, int inNumSamples
)
3638 float *out
= ZOUT(0);
3644 float y1
= unit
->m_y1
;
3646 float y0
= ZXP(in
) + ZXP(b1
) * y1
;
3647 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
;
3650 unit
->m_y1
= zapgremlins(y1
);
3653 void FOS_next_1(FOS
* unit
, int inNumSamples
)
3660 float y1
= unit
->m_y1
;
3662 float y0
= in
+ b1
* y1
;
3663 ZOUT0(0) = a0
* y0
+ a1
* y1
;
3666 unit
->m_y1
= zapgremlins(y1
);
3670 void FOS_next_k(FOS
* unit
, int inNumSamples
)
3672 float *out
= ZOUT(0);
3674 float next_a0
= ZIN0(1);
3675 float next_a1
= ZIN0(2);
3676 float next_b1
= ZIN0(3);
3678 float y1
= unit
->m_y1
;
3679 float a0
= unit
->m_a0
;
3680 float a1
= unit
->m_a1
;
3681 float b1
= unit
->m_b1
;
3682 float a0_slope
= CALCSLOPE(next_a0
, a0
);
3683 float a1_slope
= CALCSLOPE(next_a1
, a1
);
3684 float b1_slope
= CALCSLOPE(next_b1
, b1
);
3686 float y0
= ZXP(in
) + b1
* y1
;
3687 ZXP(out
) = a0
* y0
+ a1
* y1
;
3694 unit
->m_y1
= zapgremlins(y1
);
3695 unit
->m_a0
= next_a0
;
3696 unit
->m_a1
= next_a1
;
3697 unit
->m_b1
= next_b1
;
3700 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3702 void SOS_Ctor(SOS
* unit
)
3704 // printf("SOS_Reset\n");
3705 if (unit
->mBufLength
!= 1) {
3706 if (INRATE(1) == calc_FullRate
3707 && INRATE(2) == calc_FullRate
3708 && INRATE(3) == calc_FullRate
3709 && INRATE(4) == calc_FullRate
3710 && INRATE(5) == calc_FullRate
) {
3711 SETCALC(SOS_next_a
);
3712 // printf("SOS_next_a\n");
3714 SETCALC(SOS_next_k
);
3715 // printf("SOS_next_k\n");
3718 SETCALC(SOS_next_1
);
3719 // printf("SOS_next_1\n");
3728 SOS_next_1(unit
, 1);
3731 void SOS_next_a(SOS
*unit
, int inNumSamples
)
3733 float *out
= ZOUT(0);
3742 float y1
= unit
->m_y1
;
3743 float y2
= unit
->m_y2
;
3744 LOOP(unit
->mRate
->mFilterLoops
,
3745 y0
= ZXP(in
) + ZXP(b1
) * y1
+ ZXP(b2
) * y2
;
3746 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
+ ZXP(a2
) * y2
;
3748 y2
= ZXP(in
) + ZXP(b1
) * y0
+ ZXP(b2
) * y1
;
3749 ZXP(out
) = ZXP(a0
) * y2
+ ZXP(a1
) * y0
+ ZXP(a2
) * y1
;
3751 y1
= ZXP(in
) + ZXP(b1
) * y2
+ ZXP(b2
) * y0
;
3752 ZXP(out
) = ZXP(a0
) * y1
+ ZXP(a1
) * y2
+ ZXP(a2
) * y0
;
3754 LOOP(unit
->mRate
->mFilterRemain
,
3755 y0
= ZXP(in
) + ZXP(b1
) * y1
+ ZXP(b2
) * y2
;
3756 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
+ ZXP(a2
) * y2
;
3761 unit
->m_y1
= zapgremlins(y1
);
3762 unit
->m_y2
= zapgremlins(y2
);
3765 void SOS_next_k(SOS
*unit
, int inNumSamples
)
3767 float *out
= ZOUT(0);
3769 float next_a0
= ZIN0(1);
3770 float next_a1
= ZIN0(2);
3771 float next_a2
= ZIN0(3);
3772 float next_b1
= ZIN0(4);
3773 float next_b2
= ZIN0(5);
3776 float y1
= unit
->m_y1
;
3777 float y2
= unit
->m_y2
;
3778 float a0
= unit
->m_a0
;
3779 float a1
= unit
->m_a1
;
3780 float a2
= unit
->m_a2
;
3781 float b1
= unit
->m_b1
;
3782 float b2
= unit
->m_b2
;
3783 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
3784 float a1_slope
= (next_a1
- a1
) * unit
->mRate
->mFilterSlope
;
3785 float a2_slope
= (next_a2
- a2
) * unit
->mRate
->mFilterSlope
;
3786 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
3787 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
3788 LOOP(unit
->mRate
->mFilterLoops
,
3789 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3790 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3792 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3793 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
3795 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3796 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
3804 LOOP(unit
->mRate
->mFilterRemain
,
3805 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3806 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3816 unit
->m_y1
= zapgremlins(y1
);
3817 unit
->m_y2
= zapgremlins(y2
);
3820 void SOS_next_1(SOS
*unit
, int inNumSamples
) // optimized for SOS.kr
3830 float y1
= unit
->m_y1
;
3831 float y2
= unit
->m_y2
;
3833 y0
= in
+ b1
* y1
+ b2
* y2
;
3834 ZOUT0(0) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3838 unit
->m_y1
= zapgremlins(y1
);
3839 unit
->m_y2
= zapgremlins(y2
);
3842 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3844 void Compander_Ctor(Compander
* unit
)
3846 //printf("Compander_Reset\n");
3847 SETCALC(Compander_next
);
3848 unit
->m_clamp
= 0.f
;
3849 unit
->m_clampcoef
= 0.f
;
3850 unit
->m_relax
= 0.f
;
3851 unit
->m_relaxcoef
= 0.f
;
3852 unit
->m_prevmaxval
= 0.f
;
3854 Compander_next(unit
, 1);
3857 void Compander_next(Compander
* unit
, int inNumSamples
)
3859 float *out
= ZOUT(0);
3861 float *control
= ZIN(1);
3862 float thresh
= ZIN0(2);
3863 float slope_below
= ZIN0(3);
3864 float slope_above
= ZIN0(4);
3865 float clamp
= ZIN0(5);
3866 float relax
= ZIN0(6);
3868 if (clamp
!= unit
->m_clamp
) {
3869 unit
->m_clampcoef
= clamp
== 0.0 ? 0.0 : exp(log1
/(clamp
* SAMPLERATE
));
3870 unit
->m_clamp
= clamp
;
3872 if (relax
!= unit
->m_relax
) {
3873 unit
->m_relaxcoef
= relax
== 0.0 ? 0.0 : exp(log1
/(relax
* SAMPLERATE
));
3874 unit
->m_relax
= relax
;
3877 float gain
= unit
->m_gain
;
3879 float relaxcoef
= unit
->m_relaxcoef
;
3880 float clampcoef
= unit
->m_clampcoef
;
3882 float prevmaxval
= unit
->m_prevmaxval
;
3886 val
= std::abs(ZXP(control
));
3887 if (val
< prevmaxval
) {
3888 val
= val
+ (prevmaxval
- val
) * relaxcoef
;
3890 val
= val
+ (prevmaxval
- val
) * clampcoef
;
3895 unit
->m_prevmaxval
= prevmaxval
;
3897 float next_gain
;//,absx;
3898 if (prevmaxval
< thresh
) {
3899 if (slope_below
== 1.f
) {
3902 next_gain
= pow(prevmaxval
/ thresh
, slope_below
- 1.f
);
3904 float32 absx
= std::abs(next_gain
);
3905 //zap gremlins, but returns 0. if gain is too small and 1. if gain is too big
3907 (absx
< (float32
)1e-15) ? (float32
)0. :
3908 (absx
> (float32
)1e15
) ? (float32
)1. : next_gain
;
3911 if (slope_above
== 1.f
) {
3914 next_gain
= pow(prevmaxval
/ thresh
, slope_above
- 1.f
);
3918 float gain_slope
= CALCSLOPE(next_gain
, gain
);
3919 LOOP1(inNumSamples
, ZXP(out
) = ZXP(in
) * gain
; gain
+= gain_slope
;);
3920 unit
->m_gain
= gain
;
3923 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3926 void Normalizer_Dtor(Normalizer
* unit
)
3928 RTFree(unit
->mWorld
, unit
->m_table
);
3931 void Normalizer_Ctor(Normalizer
* unit
)
3933 SETCALC(Normalizer_next
);
3934 //printf("Normalizer_Reset\n");
3936 float dur
= ZIN0(2);
3937 unit
->m_bufsize
= (long)(ceil(dur
* SAMPLERATE
));
3938 long allocsize
= unit
->m_bufsize
* 3;
3939 //allocsize = NEXTPOWEROFTWO(allocsize);
3941 unit
->m_table
= (float*)RTAlloc(unit
->mWorld
, allocsize
* sizeof(float));
3945 unit
->m_level
= 1.f
;
3946 unit
->m_slope
= 0.f
;
3947 unit
->m_prevmaxval
= 0.0;
3948 unit
->m_curmaxval
= 0.0;
3949 unit
->m_slopefactor
= 1.f
/ unit
->m_bufsize
;
3951 unit
->m_xinbuf
= unit
->m_table
- ZOFF
;
3952 unit
->m_xmidbuf
= unit
->m_xinbuf
+ unit
->m_bufsize
;
3953 unit
->m_xoutbuf
= unit
->m_xmidbuf
+ unit
->m_bufsize
;
3954 Normalizer_next(unit
, 1);
3958 void Normalizer_next(Normalizer
* unit
, int inNumSamples
)
3960 float *out
= ZOUT(0);
3962 float amp
= ZIN0(1);
3964 long pos
= unit
->m_pos
;
3965 float slope
= unit
->m_slope
;
3966 float level
= unit
->m_level
;
3967 float curmaxval
= unit
->m_curmaxval
;
3970 long bufsize
= unit
->m_bufsize
;
3971 long buf_remain
= bufsize
- pos
;
3973 long remain
= inNumSamples
;
3974 while (remain
> 0) {
3975 long nsmps
= sc_min(remain
, buf_remain
);
3976 float* xinbuf
= unit
->m_xinbuf
+ pos
;
3977 float* xoutbuf
= unit
->m_xoutbuf
+ pos
;
3978 if (unit
->m_flips
>= 2) {
3980 ZXP(xinbuf
) = val
= ZXP(in
);
3981 ZXP(out
) = level
* ZXP(xoutbuf
);
3983 val
= std::abs(val
);
3984 if (val
> curmaxval
) curmaxval
= val
;
3988 ZXP(xinbuf
) = val
= ZXP(in
);
3991 val
= std::abs(val
);
3992 if (val
> curmaxval
) curmaxval
= val
;
3996 if (pos
>= bufsize
) {
3998 buf_remain
= bufsize
;
4000 float maxval2
= sc_max(unit
->m_prevmaxval
, curmaxval
);
4001 unit
->m_prevmaxval
= curmaxval
;
4002 unit
->m_curmaxval
= curmaxval
= 0.f
;
4005 if (maxval2
<= 0.00001f
) next_level
= 100000.f
* amp
;
4006 else next_level
= amp
/ maxval2
;
4008 slope
= unit
->m_slope
= (next_level
- level
) * unit
->m_slopefactor
;
4010 float* temp
= unit
->m_xoutbuf
;
4011 unit
->m_xoutbuf
= unit
->m_xmidbuf
;
4012 unit
->m_xmidbuf
= unit
->m_xinbuf
;
4013 unit
->m_xinbuf
= temp
;
4021 unit
->m_level
= level
;
4022 unit
->m_curmaxval
= curmaxval
;
4025 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4027 void Limiter_Dtor(Limiter
* unit
)
4029 RTFree(unit
->mWorld
, unit
->m_table
);
4032 void Limiter_Ctor(Limiter
* unit
)
4034 //printf("Limiter_Reset\n");
4035 SETCALC(Limiter_next
);
4037 float dur
= ZIN0(2);
4038 unit
->m_bufsize
= (long)(ceil(dur
* SAMPLERATE
));
4039 long allocsize
= unit
->m_bufsize
* 3;
4040 allocsize
= NEXTPOWEROFTWO(allocsize
);
4042 unit
->m_table
= (float*)RTAlloc(unit
->mWorld
, allocsize
* sizeof(float));
4046 unit
->m_slope
= 0.f
;
4047 unit
->m_level
= 1.f
;
4048 unit
->m_prevmaxval
= 0.0;
4049 unit
->m_curmaxval
= 0.0;
4050 unit
->m_slopefactor
= 1.f
/ unit
->m_bufsize
;
4052 unit
->m_xinbuf
= unit
->m_table
- ZOFF
;
4053 unit
->m_xmidbuf
= unit
->m_xinbuf
+ unit
->m_bufsize
;
4054 unit
->m_xoutbuf
= unit
->m_xmidbuf
+ unit
->m_bufsize
;
4055 Limiter_next(unit
, 1);
4059 void Limiter_next(Limiter
* unit
, int inNumSamples
)
4061 float *out
= ZOUT(0);
4063 float amp
= ZIN0(1);
4065 long pos
= unit
->m_pos
;
4066 float slope
= unit
->m_slope
;
4067 float level
= unit
->m_level
;
4068 float curmaxval
= unit
->m_curmaxval
;
4071 long bufsize
= unit
->m_bufsize
;
4072 long buf_remain
= bufsize
- pos
;
4074 long remain
= inNumSamples
;
4075 while (remain
> 0) {
4076 long nsmps
= sc_min(remain
, buf_remain
);
4077 float* xinbuf
= unit
->m_xinbuf
+ pos
;
4078 float* xoutbuf
= unit
->m_xoutbuf
+ pos
;
4079 if (unit
->m_flips
>= 2) {
4081 ZXP(xinbuf
) = val
= ZXP(in
);
4082 ZXP(out
) = level
* ZXP(xoutbuf
);
4084 val
= std::abs(val
);
4085 if (val
> curmaxval
) curmaxval
= val
;
4089 ZXP(xinbuf
) = val
= ZXP(in
);
4092 val
= std::abs(val
);
4093 if (val
> curmaxval
) curmaxval
= val
;
4097 if (pos
>= bufsize
) {
4099 buf_remain
= bufsize
;
4101 float maxval2
= sc_max(unit
->m_prevmaxval
, curmaxval
);
4102 unit
->m_prevmaxval
= curmaxval
;
4103 unit
->m_curmaxval
= curmaxval
= 0.f
;
4106 if (maxval2
> amp
) next_level
= amp
/ maxval2
;
4107 else next_level
= 1.0;
4109 slope
= unit
->m_slope
= (next_level
- level
) * unit
->m_slopefactor
;
4111 float* temp
= unit
->m_xoutbuf
;
4112 unit
->m_xoutbuf
= unit
->m_xmidbuf
;
4113 unit
->m_xmidbuf
= unit
->m_xinbuf
;
4114 unit
->m_xinbuf
= temp
;
4122 unit
->m_level
= level
;
4123 unit
->m_curmaxval
= curmaxval
;
4126 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4128 void Amplitude_Ctor(Amplitude
* unit
)
4130 if(INRATE(1) != calc_ScalarRate
|| INRATE(2) != calc_ScalarRate
) {
4131 if(INRATE(0) == calc_FullRate
&& unit
->mCalcRate
== calc_BufRate
){
4132 SETCALC(Amplitude_next_atok_kk
);
4134 SETCALC(Amplitude_next_kk
);
4138 if(INRATE(0) == calc_FullRate
&& unit
->mCalcRate
== calc_BufRate
){
4139 SETCALC(Amplitude_next_atok
);
4141 SETCALC(Amplitude_next
);
4145 float clamp
= ZIN0(1);
4146 unit
->m_clampcoef
= clamp
== 0.0 ? 0.0 : exp(log1
/(clamp
* SAMPLERATE
));
4148 float relax
= ZIN0(2);
4149 unit
->m_relaxcoef
= relax
== 0.0 ? 0.0 : exp(log1
/(relax
* SAMPLERATE
));
4152 Amplitude_next(unit
, 1);
4155 void Amplitude_next(Amplitude
* unit
, int inNumSamples
)
4157 float *out
= ZOUT(0);
4160 float relaxcoef
= unit
->m_relaxcoef
;
4161 float clampcoef
= unit
->m_clampcoef
;
4162 float previn
= unit
->m_previn
;
4166 val
= std::abs(ZXP(in
));
4168 val
= val
+ (previn
- val
) * relaxcoef
;
4170 val
= val
+ (previn
- val
) * clampcoef
;
4172 ZXP(out
) = previn
= val
;
4175 unit
->m_previn
= previn
;
4178 void Amplitude_next_atok(Amplitude
* unit
, int inNumSamples
)
4182 float relaxcoef
= unit
->m_relaxcoef
;
4183 float clampcoef
= unit
->m_clampcoef
;
4184 float previn
= unit
->m_previn
;
4187 LOOP1(FULLBUFLENGTH
,
4188 val
= std::abs(ZXP(in
));
4190 val
= val
+ (previn
- val
) * relaxcoef
;
4192 val
= val
+ (previn
- val
) * clampcoef
;
4198 unit
->m_previn
= previn
;
4201 void Amplitude_next_kk(Amplitude
* unit
, int inNumSamples
)
4203 float *out
= ZOUT(0);
4205 float relaxcoef
, clampcoef
;
4207 if(ZIN0(1) != unit
->m_clamp_in
) {
4208 clampcoef
= unit
->m_clampcoef
= exp(log1
/(ZIN0(1) * SAMPLERATE
));
4209 unit
->m_clamp_in
= ZIN0(1);
4211 clampcoef
= unit
->m_clampcoef
;
4214 if(ZIN0(2) != unit
->m_relax_in
) {
4215 relaxcoef
= unit
->m_relaxcoef
= exp(log1
/(ZIN0(2) * SAMPLERATE
));
4216 unit
->m_relax_in
= ZIN0(2);
4218 relaxcoef
= unit
->m_relaxcoef
;
4221 float previn
= unit
->m_previn
;
4225 val
= std::abs(ZXP(in
));
4227 val
= val
+ (previn
- val
) * relaxcoef
;
4229 val
= val
+ (previn
- val
) * clampcoef
;
4231 ZXP(out
) = previn
= val
;
4234 unit
->m_previn
= previn
;
4237 void Amplitude_next_atok_kk(Amplitude
* unit
, int inNumSamples
)
4240 float relaxcoef
, clampcoef
;
4242 if(ZIN0(1) != unit
->m_clamp_in
) {
4243 clampcoef
= unit
->m_clampcoef
= exp(log1
/(ZIN0(1) * SAMPLERATE
));
4244 unit
->m_clamp_in
= ZIN0(1);
4246 clampcoef
= unit
->m_clampcoef
;
4249 if(ZIN0(2) != unit
->m_relax_in
) {
4250 relaxcoef
= unit
->m_relaxcoef
= exp(log1
/(ZIN0(2) * SAMPLERATE
));
4251 unit
->m_relax_in
= ZIN0(2);
4253 relaxcoef
= unit
->m_relaxcoef
;
4256 float previn
= unit
->m_previn
;
4259 LOOP1(FULLBUFLENGTH
,
4260 val
= std::abs(ZXP(in
));
4262 val
= val
+ (previn
- val
) * relaxcoef
;
4264 val
= val
+ (previn
- val
) * clampcoef
;
4270 unit
->m_previn
= previn
;
4273 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4275 void DetectSilence_Ctor(DetectSilence
* unit
)
4277 //printf("DetectSilence_Reset\n");
4278 SETCALC(DetectSilence_next
);
4280 unit
->mThresh
= ZIN0(1);
4281 unit
->mEndCounter
= (int32
)(SAMPLERATE
* ZIN0(2));
4282 unit
->mCounter
= -1;
4286 void DetectSilence_next(DetectSilence
* unit
, int inNumSamples
)
4288 float thresh
= unit
->mThresh
;
4289 int counter
= unit
->mCounter
;
4292 // I thought of a better way to do this...
4294 for (int i=0; i<inNumSamples; ++i) {
4295 float val = std::abs(ZXP(in));
4296 if (val >= thresh) counter = 0;
4297 else if (counter >= 0) {
4298 if (++counter >= unit->mEndCounter && doneAction) {
4299 int doneAction = (int)ZIN0(3);
4300 DoneAction(doneAction, unit);
4301 SETCALC(DetectSilence_done);
4308 float *out
= OUT(0);
4309 for (int i
=0; i
<inNumSamples
; ++i
) {
4310 val
= std::abs(*in
++);
4314 } else if (counter
>= 0) {
4315 if (++counter
>= unit
->mEndCounter
) {
4316 int doneAction
= (int)ZIN0(3);
4317 DoneAction(doneAction
, unit
);
4319 // SETCALC(DetectSilence_done);
4327 unit
->mCounter
= counter
;
4330 void DetectSilence_done(DetectSilence
* unit
, int inNumSamples
)
4333 ///////////////////////////////////////////////////////////////////////////////////////////////////////
4334 // Based on HilbertIIR from SC2
4335 // a 12 pole (6 per side) Hilbert IIR filter
4336 // based on Sean Costello and Bernie Hutchins
4337 // created by jl anderson - 7 jan 2001
4338 // UGen created by Josh Parmenter
4340 #define HILBERT_FILTER \
4341 y0_1 = thisin - (coefs[0]) * y1[0]; \
4342 ay1 = coefs[0] * y0_1 + 1 * y1[0]; \
4344 y0_2 = ay1 - (coefs[1]) * y1[1]; \
4345 ay2 = coefs[1] * y0_2 + 1 * y1[1]; \
4347 y0_3 = ay2 - (coefs[2]) * y1[2]; \
4348 ay3 = coefs[2] * y0_3 + 1 * y1[2]; \
4350 y0_4 = ay3 - (coefs[3]) * y1[3]; \
4351 ay4 =coefs[3] * y0_4 + 1 * y1[3]; \
4353 y0_5 = ay4 - (coefs[4]) * y1[4]; \
4354 ay5 = coefs[4] * y0_5 + 1 * y1[4]; \
4356 y0_6 = ay5 - (coefs[5]) * y1[5]; \
4357 ay6 = coefs[5] * y0_6 + 1 * y1[5]; \
4360 y0_7 = thisin - (coefs[6]) * y1[6]; \
4361 ay7 = coefs[6] * y0_7 + 1 * y1[6]; \
4363 y0_8 = ay7 - (coefs[7]) * y1[7]; \
4364 ay8 = coefs[7] * y0_8 + 1 * y1[7]; \
4366 y0_9 = ay8 - (coefs[8]) * y1[8]; \
4367 ay9 = coefs[8] * y0_9 + 1 * y1[8]; \
4369 y0_10 = ay9 - (coefs[9]) * y1[9]; \
4370 ay10 = coefs[9] * y0_10 + 1 * y1[9]; \
4372 y0_11 = ay10 - (coefs[10]) * y1[10]; \
4373 ay11 = coefs[10] * y0_11 + 1 * y1[10]; \
4375 y0_12 = ay11 - (coefs[11]) * y1[11]; \
4376 ay12 = coefs[11] * y0_12 + 1 * y1[11]; \
4380 void Hilbert_Ctor(Hilbert *unit)
4382 // calculate coefs based on SampleRate, store in the struct
4383 SETCALC(Hilbert_next
);
4385 float gamconst
= (15.0f
* pi_f
) / SAMPLERATE
;
4386 float gamma01
= gamconst
* 0.3609f
;
4387 float gamma02
= gamconst
* 2.7412f
;
4388 float gamma03
= gamconst
* 11.1573f
;
4389 float gamma04
= gamconst
* 44.7581f
;
4390 float gamma05
= gamconst
* 179.6242f
;
4391 float gamma06
= gamconst
* 798.4578f
;
4392 float gamma07
= gamconst
* 1.2524f
;
4393 float gamma08
= gamconst
* 5.5671f
;
4394 float gamma09
= gamconst
* 22.3423f
;
4395 float gamma10
= gamconst
* 89.6271f
;
4396 float gamma11
= gamconst
* 364.7914f
;
4397 float gamma12
= gamconst
* 2770.1114f
;
4398 unit
->m_coefs
[0] = (gamma01
- 1.f
) / (gamma01
+ 1.f
);
4399 unit
->m_coefs
[1] = (gamma02
- 1.f
) / (gamma02
+ 1.f
);
4400 unit
->m_coefs
[2] = (gamma03
- 1.f
) / (gamma03
+ 1.f
);
4401 unit
->m_coefs
[3] = (gamma04
- 1.f
) / (gamma04
+ 1.f
);
4402 unit
->m_coefs
[4] = (gamma05
- 1.f
) / (gamma05
+ 1.f
);
4403 unit
->m_coefs
[5] = (gamma06
- 1.f
) / (gamma06
+ 1.f
);
4404 unit
->m_coefs
[6] = (gamma07
- 1.f
) / (gamma07
+ 1.f
);
4405 unit
->m_coefs
[7] = (gamma08
- 1.f
) / (gamma08
+ 1.f
);
4406 unit
->m_coefs
[8] = (gamma09
- 1.f
) / (gamma09
+ 1.f
);
4407 unit
->m_coefs
[9] = (gamma10
- 1.f
) / (gamma10
+ 1.f
);
4408 unit
->m_coefs
[10] = (gamma11
- 1.f
) / (gamma11
+ 1.f
);
4409 unit
->m_coefs
[11] = (gamma12
- 1.f
) / (gamma12
+ 1.f
);
4410 Clear(12, unit
->m_y1
);
4411 Hilbert_next(unit
, 1);
4414 void Hilbert_next(Hilbert
*unit
, int inNumSamples
)
4417 float *outcos
= ZOUT(0);
4418 float *outsin
= ZOUT(1);
4422 // each filter's last sample
4423 for(int i
= 0; i
< 12; ++i
){
4424 y1
[i
] = unit
->m_y1
[i
];
4425 coefs
[i
] = unit
->m_coefs
[i
];
4428 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4429 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4431 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4432 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4435 float thisin
= ZXP(in
);
4442 for(int i
= 0; i
< 12; ++i
)
4443 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4447 /* Hilbert based SSB FreqShifter */
4449 void FreqShift_Ctor(FreqShift
*unit
)
4451 // calculate coefs based on SampleRate, store in the struct
4452 // SETCALC(FreqShift_next_kk);
4454 if(INRATE(1) == calc_FullRate
) {
4455 if(INRATE(2) == calc_FullRate
)
4456 SETCALC(FreqShift_next_aa
);
4458 SETCALC(FreqShift_next_ak
);
4460 if(INRATE(2) == calc_FullRate
)
4461 SETCALC(FreqShift_next_ka
);
4463 SETCALC(FreqShift_next_kk
);
4464 unit
->m_phase
= (int32
)(unit
->m_radtoinc
* IN0(2));
4467 // set up for the oscil for the modualtion
4469 int tableSizeSin
= ft
->mSineSize
;
4470 unit
->m_lomask
= (tableSizeSin
- 1) << 3;
4471 unit
->m_radtoinc
= tableSizeSin
* (rtwopi
* 65536.);
4472 unit
->m_cpstoinc
= tableSizeSin
* SAMPLEDUR
* 65536.;
4473 unit
->m_phasein
= IN0(2);
4475 float gamconst
= (15.0 * pi
) / SAMPLERATE
;
4476 float gamma01
= gamconst
* 0.3609f
;
4477 float gamma02
= gamconst
* 2.7412f
;
4478 float gamma03
= gamconst
* 11.1573f
;
4479 float gamma04
= gamconst
* 44.7581f
;
4480 float gamma05
= gamconst
* 179.6242f
;
4481 float gamma06
= gamconst
* 798.4578f
;
4482 float gamma07
= gamconst
* 1.2524f
;
4483 float gamma08
= gamconst
* 5.5671f
;
4484 float gamma09
= gamconst
* 22.3423f
;
4485 float gamma10
= gamconst
* 89.6271f
;
4486 float gamma11
= gamconst
* 364.7914f
;
4487 float gamma12
= gamconst
* 2770.1114f
;
4488 unit
->m_coefs
[0] = (gamma01
- 1.f
) / (gamma01
+ 1.f
);
4489 unit
->m_coefs
[1] = (gamma02
- 1.f
) / (gamma02
+ 1.f
);
4490 unit
->m_coefs
[2] = (gamma03
- 1.f
) / (gamma03
+ 1.f
);
4491 unit
->m_coefs
[3] = (gamma04
- 1.f
) / (gamma04
+ 1.f
);
4492 unit
->m_coefs
[4] = (gamma05
- 1.f
) / (gamma05
+ 1.f
);
4493 unit
->m_coefs
[5] = (gamma06
- 1.f
) / (gamma06
+ 1.f
);
4494 unit
->m_coefs
[6] = (gamma07
- 1.f
) / (gamma07
+ 1.f
);
4495 unit
->m_coefs
[7] = (gamma08
- 1.f
) / (gamma08
+ 1.f
);
4496 unit
->m_coefs
[8] = (gamma09
- 1.f
) / (gamma09
+ 1.f
);
4497 unit
->m_coefs
[9] = (gamma10
- 1.f
) / (gamma10
+ 1.f
);
4498 unit
->m_coefs
[10] = (gamma11
- 1.f
) / (gamma11
+ 1.f
);
4499 unit
->m_coefs
[11] = (gamma12
- 1.f
) / (gamma12
+ 1.f
);
4501 Clear(12, unit
->m_y1
);
4502 FreqShift_next_kk(unit
, 1);
4505 void FreqShift_next_kk(FreqShift
*unit
, int inNumSamples
)
4508 float *out
= ZOUT(0);
4509 float phasein
= ZIN0(2);
4510 float freqin
= ZIN0(1);
4511 float outcos
, outsin
; // the sample by sample output of the Hilbert
4512 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4513 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4517 float *table0
= ft
->mSineWavetable
;
4518 float *table1
= table0
+ 1;
4519 int32 lomask
= unit
->m_lomask
;
4520 int32 phase
= unit
->m_phase
;
4522 int32 freq
= (int32
)(unit
->m_cpstoinc
* freqin
);
4523 int32 phaseinc
= freq
+ (int32
)(CALCSLOPE(phasein
, unit
->m_phasein
) * unit
->m_radtoinc
);
4524 unit
->m_phasein
= phasein
;
4526 // each filter's last sample
4527 for(int i
= 0; i
< 12; ++i
) {
4528 y1
[i
] = unit
->m_y1
[i
];
4529 coefs
[i
] = unit
->m_coefs
[i
];
4532 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4533 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4535 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4536 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4539 float thisin
= ZXP(in
);
4546 outsinosc
= lookupi1(table0
, table1
, phase
, lomask
);
4547 outsinoscHalfPi
= lookupi1(table0
, table1
, phase
+ halfPi
, lomask
);
4549 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4554 unit
->m_phase
= phase
;
4556 for(int i
= 0; i
< 12; ++i
)
4557 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4560 void FreqShift_next_aa(FreqShift
*unit
, int inNumSamples
)
4563 float *out
= ZOUT(0);
4564 float *phasein
= ZIN(2);
4565 float *freqin
= ZIN(1);
4566 float outcos
, outsin
; // the sample by sample output of the Hilbert
4567 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4568 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4572 float *table0
= ft
->mSineWavetable
;
4573 float *table1
= table0
+ 1;
4574 int32 lomask
= unit
->m_lomask
;
4575 int32 phase
= unit
->m_phase
;
4577 // each filter's last sample
4578 for(int i
= 0; i
< 12; ++i
){
4579 y1
[i
] = unit
->m_y1
[i
];
4580 coefs
[i
] = unit
->m_coefs
[i
];
4583 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4584 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4586 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4587 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4590 float thisin
= ZXP(in
);
4597 int32 phaseoffset
= phase
+ (int32
)(unit
->m_radtoinc
* ZXP(phasein
));
4598 outsinosc
= lookupi1(table0
, table1
, phaseoffset
, lomask
);
4599 outsinoscHalfPi
= lookupi1(table0
, table1
, phaseoffset
+ halfPi
, lomask
);
4600 phase
+= (int32
)(unit
->m_cpstoinc
* ZXP(freqin
));
4602 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4605 unit
->m_phase
= phase
;
4607 for(int i
= 0; i
< 12; ++i
)
4608 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4611 void FreqShift_next_ak(FreqShift
*unit
, int inNumSamples
)
4614 float *out
= ZOUT(0);
4615 float phasein
= ZIN0(2);
4616 float *freqin
= ZIN(1);
4617 float outcos
, outsin
; // the sample by sample output of the Hilbert
4618 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4619 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4623 float *table0
= ft
->mSineWavetable
;
4624 float *table1
= table0
+ 1;
4625 int32 lomask
= unit
->m_lomask
;
4626 int32 phase
= unit
->m_phase
;
4627 float phasemod
= unit
->m_phasein
;
4628 float phaseslope
= CALCSLOPE(phasein
, phasemod
);
4630 // each filter's last sample
4631 for(int i
= 0; i
< 12; ++i
) {
4632 y1
[i
] = unit
->m_y1
[i
];
4633 coefs
[i
] = unit
->m_coefs
[i
];
4636 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4637 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4639 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4640 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4643 float thisin
= ZXP(in
);
4650 int32 pphase
= phase
+ (int32
)(unit
->m_radtoinc
* phasemod
);
4651 phasemod
+= phaseslope
;
4652 outsinosc
= lookupi1(table0
, table1
, pphase
, lomask
);
4653 outsinoscHalfPi
= lookupi1(table0
, table1
, pphase
+ halfPi
, lomask
);
4654 phase
+= (int32
)(unit
->m_cpstoinc
* ZXP(freqin
));
4656 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4659 unit
->m_phase
= phase
;
4660 unit
->m_phasein
= phasein
;
4662 for(int i
= 0; i
< 12; ++i
)
4663 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4666 void FreqShift_next_ka(FreqShift
*unit
, int inNumSamples
)
4669 float *out
= ZOUT(0);
4670 float *phasein
= ZIN(2);
4671 float freqin
= ZIN0(1);
4672 float outcos
, outsin
; // the sample by sample output of the Hilbert
4673 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4674 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4678 float *table0
= ft
->mSineWavetable
;
4679 float *table1
= table0
+ 1;
4680 int32 lomask
= unit
->m_lomask
;
4681 int32 phase
= unit
->m_phase
;
4682 float phasemod
= unit
->m_phasein
;
4684 int32 freq
= (int32
)(unit
->m_cpstoinc
* freqin
);
4686 // each filter's last sample
4687 for(int i
= 0; i
< 12; ++i
) {
4688 y1
[i
] = unit
->m_y1
[i
];
4689 coefs
[i
] = unit
->m_coefs
[i
];
4692 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4693 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4695 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4696 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4699 float thisin
= ZXP(in
);
4706 int32 phaseoffset
= phase
+ (int32
)(unit
->m_radtoinc
* ZXP(phasein
));
4707 outsinosc
= lookupi1(table0
, table1
, phaseoffset
, lomask
);
4708 outsinoscHalfPi
= lookupi1(table0
, table1
, phaseoffset
+ halfPi
, lomask
);
4711 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4714 unit
->m_phase
= phase
;
4716 for(int i
= 0; i
< 12; ++i
)
4717 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4722 "MoogFF" - Moog VCF digital implementation.
4723 As described in the paper entitled
4724 "Preserving the Digital Structure of the Moog VCF"
4726 appeared in the Proc. ICMC07, Copenhagen, 25-31 August 2007
4728 Original Java code Copyright F. Fontana - August 2007
4729 federico.fontana@univr.it
4731 Ported to C++ for SuperCollider by Dan Stowell - August 2007
4732 http://www.mcld.co.uk/
4734 This program is free software; you can redistribute it and/or modify
4735 it under the terms of the GNU General Public License as published by
4736 the Free Software Foundation; either version 2 of the License, or
4737 (at your option) any later version.
4739 This program is distributed in the hope that it will be useful,
4740 but WITHOUT ANY WARRANTY; without even the implied warranty of
4741 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4742 GNU General Public License for more details.
4744 You should have received a copy of the GNU General Public License
4745 along with this program; if not, write to the Free Software
4746 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4748 //////////////////////////////////////////////////////////////////
4750 void MoogFF_Ctor(MoogFF
* unit
)
4752 SETCALC(MoogFF_next
);
4754 // initialize the unit generator state variables.
4755 unit
->m_freq
= -10000.3f
; // Force the freq to update on first run
4756 unit
->m_T
= 1.0 / SAMPLERATE
;
4762 // calculate one sample of output.
4763 MoogFF_next(unit
, 1);
4766 void MoogFF_next(MoogFF
*unit
, int inNumSamples
)
4768 float *out
= ZOUT(0);
4772 k
= k
> 4.f
? 4.f
: (k
<0.f
? 0.f
: k
);
4774 // Load state from the struct
4775 float s1
= unit
->m_s1
;
4776 float s2
= unit
->m_s2
;
4777 float s3
= unit
->m_s3
;
4778 float s4
= unit
->m_s4
;
4779 float freq
= unit
->m_freq
;///
4780 double T
= unit
->m_T
;
4782 // Reset filter state if requested
4784 s1
= s2
= s3
= s4
= 0.f
;
4786 double wcD
=unit
->m_wcD
;
4787 float a1
= unit
->m_a1
, b0
= unit
->m_b0
; // Filter coefficient parameters
4788 float o
, u
; // System's null response, loop input
4790 // Update filter coefficients, but only if freq changes since it involves some expensive operations
4791 if(freq
!= IN0(1)) {
4793 //Print("Updated freq to %g\n", freq);
4794 wcD
= 2.0 * tan(T
* PI
* freq
) * SAMPLERATE
;
4796 wcD
= 0; // Protect against negative cutoff freq
4797 double TwcD
= T
*wcD
;
4798 b0
= (float)(TwcD
/(TwcD
+ 2.));
4799 a1
= (float)((TwcD
- 2.)/(TwcD
+ 2.));
4800 unit
->m_freq
= freq
;
4807 // compute loop values
4808 o
= s4
+ b0
*(s3
+ b0
*(s2
+ b0
*s1
));
4809 float ins
= ZXP(in
);
4810 float outs
= (b0
*b0
*b0
*b0
*ins
+ o
)/(1.f
+ b0
*b0
*b0
*b0
*k
);
4814 // update 1st order filter states
4816 float future
= b0
*past
+ s1
;
4817 s1
= b0
*past
- a1
*future
;
4820 future
= b0
*past
+ s2
;
4821 s2
= b0
*past
- a1
*future
;
4824 future
= b0
*past
+ s3
;
4825 s3
= b0
*past
- a1
*future
;
4827 s4
= b0
*future
- a1
*outs
;
4840 struct BLowPass
: public Unit
4842 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
4848 void BLowPass_next_kk(BLowPass
*unit
, int inNumSamples
);
4849 void BLowPass_next_aa(BLowPass
*unit
, int inNumSamples
);
4850 void BLowPass_Ctor(BLowPass
* unit
);
4854 void BLowPass_Ctor(BLowPass
* unit
)
4856 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
4857 SETCALC(BLowPass_next_aa
);
4859 SETCALC(BLowPass_next_kk
);
4860 float rq
= unit
->m_rq
= ZIN0(2);
4861 float freq
= unit
->m_freq
= ZIN0(1);
4862 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
4863 double cosw0
= cos(w0
);
4864 double i
= 1. - cosw0
;
4865 double alpha
= sin(w0
) * 0.5 * (double)rq
;
4866 double b0rz
= 1. / (1. + alpha
);
4867 double a0
= unit
->m_a0
= i
* 0.5 * b0rz
;
4868 unit
->m_a1
= i
* b0rz
;
4870 unit
->m_b1
= cosw0
* 2. * b0rz
;
4871 unit
->m_b2
= (1. - alpha
) * -b0rz
;
4876 BLowPass_next_kk(unit
, 1);
4880 void BLowPass_next_aa(BLowPass
*unit
, int inNumSamples
)
4882 float *out
= ZOUT(0);
4884 float *freq
= ZIN(1);
4887 double a0
, a1
, a2
, b1
, b2
, w0
, cosw0
, i
, alpha
, b0rz
;
4889 float nextfreq
, nextrq
;
4900 LOOP(unit
->mRate
->mFilterLoops
,
4901 nextfreq
= ZXP(freq
);
4903 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
4904 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
4907 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
4908 b0rz
= 1. / (1. + alpha
);
4909 a0
= i
* 0.5 * b0rz
;
4912 b1
= cosw0
* 2. * b0rz
;
4913 b2
= (1. - alpha
) * -b0rz
;
4914 unit
->m_freq
= nextfreq
;
4915 unit
->m_rq
= nextrq
;
4917 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
4918 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
4920 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
4921 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
4923 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
4924 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
4927 LOOP(unit
->mRate
->mFilterRemain
,
4928 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
4929 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
4932 unit
->m_freq
= ZXP(freq
);
4933 unit
->m_rq
= ZXP(rq
);
4941 unit
->m_y1
= zapgremlins(y1
);
4942 unit
->m_y2
= zapgremlins(y2
);
4946 void BLowPass_next_kk(BLowPass
*unit
, int inNumSamples
)
4948 float *out
= ZOUT(0);
4950 float nextfreq
= ZIN0(1);
4951 float nextrq
= ZIN0(2);
4953 double a0
, a1
, a2
, b1
, b2
;
4954 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextcosw0
, nexti
, nextalpha
, nextb0rz
;
4956 double y1
= unit
->m_y1
;
4957 double y2
= unit
->m_y2
;
4958 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
4966 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)){
4967 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
4968 nextcosw0
= cos(nextw0
);
4969 nexti
= 1. - nextcosw0
;
4970 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
4971 nextb0rz
= 1. / (1. + nextalpha
);
4972 nexta0
= nexti
* 0.5 * nextb0rz
;
4973 nexta1
= nexti
* nextb0rz
;
4975 nextb1
= nextcosw0
* 2. * nextb0rz
;
4976 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
4977 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
;
4978 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
;
4979 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
;
4980 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
;
4981 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
;
4982 unit
->m_freq
= nextfreq
;
4983 unit
->m_rq
= nextrq
;
4984 LOOP(unit
->mRate
->mFilterLoops
,
4985 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
4986 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
4988 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
4989 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
4991 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
4992 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
4999 LOOP(unit
->mRate
->mFilterRemain
,
5000 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5001 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5007 LOOP(unit
->mRate
->mFilterLoops
,
5008 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5009 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5011 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5012 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5014 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5015 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5017 LOOP(unit
->mRate
->mFilterRemain
,
5018 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5019 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5024 unit
->m_y1
= zapgremlins(y1
);
5025 unit
->m_y2
= zapgremlins(y2
);
5033 struct BHiPass
: public Unit
5035 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5042 void BHiPass_next_kk(BHiPass
*unit
, int inNumSamples
);
5043 void BHiPass_next_aa(BHiPass
*unit
, int inNumSamples
);
5044 void BHiPass_Ctor(BHiPass
* unit
);
5047 void BHiPass_Ctor(BHiPass
* unit
)
5049 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5050 SETCALC(BHiPass_next_aa
);
5052 SETCALC(BHiPass_next_kk
);
5053 float freq
= unit
->m_freq
= ZIN0(1);
5054 float rq
= unit
->m_rq
= ZIN0(2);
5055 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5056 double cosw0
= cos(w0
);
5057 double i
= 1. + cosw0
;
5058 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5059 double b0rz
= 1. / (1. + alpha
);
5060 double a0
= unit
->m_a0
= i
* 0.5 * b0rz
;
5061 unit
->m_a1
= -i
* b0rz
;
5063 unit
->m_b1
= cosw0
* 2. * b0rz
;
5064 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5069 BHiPass_next_kk(unit
, 1);
5073 void BHiPass_next_aa(BHiPass
*unit
, int inNumSamples
)
5075 float *out
= ZOUT(0);
5077 float *freq
= ZIN(1);
5080 double a0
, a1
, a2
, b1
, b2
, w0
, cosw0
, i
, alpha
, b0rz
;
5082 float nextfreq
, nextrq
;
5093 LOOP(unit
->mRate
->mFilterLoops
,
5094 nextfreq
= ZXP(freq
);
5096 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5097 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5100 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
5101 b0rz
= 1. / (1. + alpha
);
5102 a0
= i
* 0.5 * b0rz
;
5105 b1
= cosw0
* 2. * b0rz
;
5106 b2
= (1. - alpha
) * -b0rz
;
5107 unit
->m_freq
= nextfreq
;
5108 unit
->m_rq
= nextrq
;
5110 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5111 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5113 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5114 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5116 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5117 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5119 LOOP(unit
->mRate
->mFilterRemain
,
5120 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5121 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5131 unit
->m_y1
= zapgremlins(y1
);
5132 unit
->m_y2
= zapgremlins(y2
);
5136 void BHiPass_next_kk(BHiPass
*unit
, int inNumSamples
)
5138 float *out
= ZOUT(0);
5140 float nextfreq
= ZIN0(1);
5141 float nextrq
= ZIN0(2);
5143 double a0
, a1
, a2
, b1
, b2
;
5144 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextcosw0
, nexti
, nextalpha
, nextb0rz
;
5146 double y1
= unit
->m_y1
;
5147 double y2
= unit
->m_y2
;
5148 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5156 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)){
5157 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5158 nextcosw0
= cos(nextw0
);
5159 nexti
= 1. + nextcosw0
;
5160 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
5161 nextb0rz
= 1. / (1. + nextalpha
);
5162 nexta0
= nexti
* 0.5 * nextb0rz
;
5163 nexta1
= -nexti
* nextb0rz
;
5165 nextb1
= nextcosw0
* 2. * nextb0rz
;
5166 nextb2
= (1. - nextalpha
) * -nextb0rz
;
5167 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5168 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5169 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5170 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5171 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5173 LOOP(unit
->mRate
->mFilterLoops
,
5174 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5175 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5177 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5178 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5180 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5181 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5188 LOOP(unit
->mRate
->mFilterRemain
,
5189 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5190 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5194 unit
->m_freq
= nextfreq
;
5195 unit
->m_rq
= nextrq
;
5204 LOOP(unit
->mRate
->mFilterLoops
,
5205 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5206 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5208 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5209 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5211 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5212 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5214 LOOP(unit
->mRate
->mFilterRemain
,
5215 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5216 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5222 unit
->m_y1
= zapgremlins(y1
);
5223 unit
->m_y2
= zapgremlins(y2
);
5228 struct BBandPass
: public Unit
5230 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5236 void BBandPass_next_kk(BBandPass
*unit
, int inNumSamples
);
5237 void BBandPass_next_aa(BBandPass
*unit
, int inNumSamples
);
5238 void BBandPass_Ctor(BBandPass
* unit
);
5241 void BBandPass_Ctor(BBandPass
* unit
)
5243 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5244 SETCALC(BBandPass_next_aa
);
5246 SETCALC(BBandPass_next_kk
);
5247 float freq
= unit
->m_freq
= ZIN0(1);
5248 float bw
= unit
->m_bw
= ZIN0(2);
5250 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5251 double sinw0
= sin(w0
);
5252 double alpha
= sinw0
* (sinh((0.34657359027997 * (double)bw
* w0
) / sinw0
));
5253 double b0rz
= 1. / (1. + alpha
);
5254 double a0
= unit
->m_a0
= alpha
* b0rz
;
5257 unit
->m_b1
= cos(w0
) * 2. * b0rz
;
5258 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5264 BBandPass_next_kk(unit
, 1);
5268 void BBandPass_next_aa(BBandPass
*unit
, int inNumSamples
)
5270 float *out
= ZOUT(0);
5272 float *freq
= ZIN(1);
5275 double a0
, a1
, a2
, b1
, b2
, w0
, sinw0
, alpha
, b0rz
;
5277 float nextfreq
, nextbw
;
5288 LOOP(unit
->mRate
->mFilterLoops
,
5289 nextfreq
= ZXP(freq
);
5291 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)) {
5292 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5294 alpha
= sinw0
* (sinh((0.34657359027997 * (double)nextbw
* w0
) / sinw0
));
5295 b0rz
= 1. / (1. + alpha
);
5299 b1
= cos(w0
) * 2. * b0rz
;
5300 b2
= (1. - alpha
) * -b0rz
;
5301 unit
->m_freq
= ZXP(freq
);
5302 unit
->m_bw
= ZXP(bw
);
5304 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5305 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5307 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5308 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5310 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5311 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5313 LOOP(unit
->mRate
->mFilterRemain
,
5314 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5315 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5318 unit
->m_freq
= nextfreq
;
5319 unit
->m_bw
= nextbw
;
5327 unit
->m_y1
= zapgremlins(y1
);
5328 unit
->m_y2
= zapgremlins(y2
);
5332 void BBandPass_next_kk(BBandPass
*unit
, int inNumSamples
)
5334 float *out
= ZOUT(0);
5336 float nextfreq
= ZIN0(1);
5337 float nextbw
= ZIN0(2);
5339 double a0
, a1
, a2
, b1
, b2
;
5340 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5342 double y1
= unit
->m_y1
;
5343 double y2
= unit
->m_y2
;
5344 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5351 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)){
5352 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5353 nextalpha
= sin(nextw0
) * (sinh((0.34657359027997 * (double)nextbw
* nextw0
) / sin(nextw0
)));
5354 nextb0rz
= 1. / (1. + nextalpha
);
5355 nexta0
= nextalpha
* nextb0rz
;
5358 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
5359 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
5360 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5361 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5362 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5363 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5364 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5365 unit
->m_freq
= nextfreq
;
5366 unit
->m_bw
= nextbw
;
5367 LOOP(unit
->mRate
->mFilterLoops
,
5368 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5369 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5371 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5372 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5374 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5375 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5382 LOOP(unit
->mRate
->mFilterRemain
,
5383 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5384 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5389 LOOP(unit
->mRate
->mFilterLoops
,
5390 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5391 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5393 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5394 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5396 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5397 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5399 LOOP(unit
->mRate
->mFilterRemain
,
5400 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5401 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5412 unit
->m_y1
= zapgremlins(y1
);
5413 unit
->m_y2
= zapgremlins(y2
);
5417 struct BBandStop
: public Unit
5419 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5425 void BBandStop_next_kk(BBandStop
*unit
, int inNumSamples
);
5426 void BBandStop_next_aa(BBandStop
*unit
, int inNumSamples
);
5427 void BBandStop_Ctor(BBandStop
* unit
);
5430 void BBandStop_Ctor(BBandStop
* unit
)
5432 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5433 SETCALC(BBandStop_next_aa
);
5435 SETCALC(BBandStop_next_kk
);
5436 float freq
= unit
->m_freq
= ZIN0(1);
5437 float bw
= unit
->m_bw
= ZIN0(2);
5439 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5440 double sinw0
= sin(w0
);
5441 double alpha
= sinw0
* (sinh((0.34657359027997 * (double)bw
* w0
) / sinw0
));
5442 double b0rz
= 1. / (1. + alpha
);
5443 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5447 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5453 BBandStop_next_kk(unit
, 1);
5457 void BBandStop_next_aa(BBandStop
*unit
, int inNumSamples
)
5459 float *out
= ZOUT(0);
5461 float *freq
= ZIN(1);
5464 double a0
, a1
, a2
, b1
, b2
, w0
, sinw0
, alpha
, b0rz
;
5466 float nextfreq
, nextbw
;
5477 LOOP(unit
->mRate
->mFilterLoops
,
5478 nextfreq
= ZXP(freq
);
5480 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)) {
5481 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5483 alpha
= sinw0
* (sinh((0.34657359027997 * (double)nextbw
* w0
) / sinw0
));
5484 b0rz
= 1. / (1. + alpha
);
5485 b1
= 2. * b0rz
* cos(w0
);
5489 b2
= (1. - alpha
) * -b0rz
;
5490 unit
->m_freq
= ZXP(freq
);
5491 unit
->m_bw
= ZXP(bw
);
5493 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5494 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5496 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5497 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5499 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5500 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5502 LOOP(unit
->mRate
->mFilterRemain
,
5503 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5504 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5507 unit
->m_freq
= nextfreq
;
5508 unit
->m_bw
= nextbw
;
5516 unit
->m_y1
= zapgremlins(y1
);
5517 unit
->m_y2
= zapgremlins(y2
);
5521 void BBandStop_next_kk(BBandStop
*unit
, int inNumSamples
)
5523 float *out
= ZOUT(0);
5525 float nextfreq
= ZIN0(1);
5526 float nextbw
= ZIN0(2);
5528 double a0
, a1
, a2
, b1
, b2
;
5529 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5531 double y1
= unit
->m_y1
;
5532 double y2
= unit
->m_y2
;
5533 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5541 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)){
5542 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5543 nextalpha
= sin(nextw0
) * (sinh((0.34657359027997 * (double)nextbw
* nextw0
) / sin(nextw0
)));
5544 nextb0rz
= 1. / (1. + nextalpha
);
5545 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
5549 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
5550 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5551 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5552 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5553 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5554 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5555 unit
->m_freq
= nextfreq
;
5556 unit
->m_bw
= nextbw
;
5557 LOOP(unit
->mRate
->mFilterLoops
,
5558 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5559 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5561 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5562 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5564 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5565 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5572 LOOP(unit
->mRate
->mFilterRemain
,
5573 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5574 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5580 LOOP(unit
->mRate
->mFilterLoops
,
5581 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5582 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5584 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5585 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5587 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5588 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5590 LOOP(unit
->mRate
->mFilterRemain
,
5591 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5592 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5603 unit
->m_y1
= zapgremlins(y1
);
5604 unit
->m_y2
= zapgremlins(y2
);
5608 struct BPeakEQ
: public Unit
5610 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5611 float m_freq
, m_rq
, m_db
;
5616 void BPeakEQ_next_kkk(BPeakEQ
*unit
, int inNumSamples
);
5617 void BPeakEQ_next_aaa(BPeakEQ
*unit
, int inNumSamples
);
5618 void BPeakEQ_Ctor(BPeakEQ
* unit
);
5621 void BPeakEQ_Ctor(BPeakEQ
* unit
)
5623 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
5624 SETCALC(BPeakEQ_next_aaa
);
5626 SETCALC(BPeakEQ_next_kkk
);
5628 float freq
= unit
->m_freq
= ZIN0(1);
5629 float rq
= unit
->m_rq
= ZIN0(2);
5630 float db
= unit
->m_db
= ZIN0(3);
5631 double a
= pow(10., (double)db
* 0.025);
5632 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5633 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5634 double b0rz
= 1. / (1. + (alpha
/ a
));
5635 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5636 unit
->m_a0
= (1. + (alpha
* a
)) * b0rz
;
5638 unit
->m_a2
= (1. - (alpha
* a
)) * b0rz
;
5639 unit
->m_b2
= (1. - (alpha
/ a
)) * -b0rz
;
5644 BPeakEQ_next_kkk(unit
, 1);
5648 void BPeakEQ_next_aaa(BPeakEQ
*unit
, int inNumSamples
)
5650 float *out
= ZOUT(0);
5652 float *freq
= ZIN(1);
5656 double a0
, a1
, a2
, b1
, b2
, a
, w0
, alpha
, b0rz
;
5658 float nextfreq
, nextrq
, nextdb
;
5670 LOOP(unit
->mRate
->mFilterLoops
,
5671 nextfreq
= ZXP(freq
);
5674 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
) || (unit
->m_db
!= nextdb
)) {
5675 a
= pow(10., (double)nextdb
* 0.025);
5676 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5677 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
5678 b0rz
= 1. / (1. + (alpha
/ a
));
5679 b1
= 2. * b0rz
* cos(w0
);
5680 a0
= (1. + (alpha
* a
)) * b0rz
;
5682 a2
= (1. - (alpha
* a
)) * b0rz
;
5683 b2
= (1. - (alpha
/ a
)) * -b0rz
;
5684 unit
->m_freq
= nextfreq
;
5685 unit
->m_rq
= nextrq
;
5686 unit
->m_db
= nextdb
;
5688 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5689 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5691 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5692 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5694 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5695 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5697 LOOP(unit
->mRate
->mFilterRemain
,
5698 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5699 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5702 unit
->m_freq
= ZXP(freq
);
5703 unit
->m_rq
= ZXP(rq
);
5704 unit
->m_db
= ZXP(db
);
5712 unit
->m_y1
= zapgremlins(y1
);
5713 unit
->m_y2
= zapgremlins(y2
);
5717 void BPeakEQ_next_kkk(BPeakEQ
*unit
, int inNumSamples
)
5719 float *out
= ZOUT(0);
5721 float nextfreq
= ZIN0(1);
5722 float nextrq
= ZIN0(2);
5723 float nextdb
= ZIN0(3);
5725 double a0
, a1
, a2
, b1
, b2
, a
, w0
, alpha
, b0rz
;
5726 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
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 nextb1
= 2. * b0rz
* cos(w0
);
5743 nexta0
= (1. + (alpha
* a
)) * b0rz
;
5745 nexta2
= (1. - (alpha
* a
)) * b0rz
;
5746 nextb2
= (1. - (alpha
/ a
)) * -b0rz
;
5747 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5748 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5749 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5750 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5751 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5752 unit
->m_freq
= nextfreq
;
5753 unit
->m_db
= nextdb
;
5754 unit
->m_rq
= nextrq
;
5755 LOOP(unit
->mRate
->mFilterLoops
,
5756 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5757 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5759 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5760 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5762 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5763 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5772 LOOP(unit
->mRate
->mFilterRemain
,
5773 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5774 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5780 LOOP(unit
->mRate
->mFilterLoops
,
5781 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5782 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5784 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5785 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5787 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5788 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5791 LOOP(unit
->mRate
->mFilterRemain
,
5792 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5793 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5804 unit
->m_y1
= zapgremlins(y1
);
5805 unit
->m_y2
= zapgremlins(y2
);
5809 struct BAllPass
: public Unit
5811 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5817 void BAllPass_next_kk(BAllPass
*unit
, int inNumSamples
);
5818 void BAllPass_next_aa(BAllPass
*unit
, int inNumSamples
);
5819 void BAllPass_Ctor(BAllPass
* unit
);
5822 void BAllPass_Ctor(BAllPass
* unit
)
5824 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5825 SETCALC(BAllPass_next_aa
);
5827 SETCALC(BAllPass_next_kk
);
5829 float freq
= unit
->m_freq
= ZIN0(1);
5830 float rq
= unit
->m_rq
= ZIN0(2);
5832 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5833 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5834 double b0rz
= 1. / (1. + alpha
);
5835 double a0
= unit
->m_a0
= (1. - alpha
) * b0rz
;
5836 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5845 BAllPass_next_kk(unit
, 1);
5849 void BAllPass_next_aa(BAllPass
*unit
, int inNumSamples
)
5851 float *out
= ZOUT(0);
5853 float *freq
= ZIN(1);
5856 double a0
, a1
, a2
, b1
, b2
, w0
, alpha
, b0rz
;
5858 float nextfreq
, nextrq
;
5869 LOOP(unit
->mRate
->mFilterLoops
,
5870 nextfreq
= ZXP(freq
);
5872 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5873 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5874 alpha
= sin(w0
) * (double)nextrq
* 0.5;
5875 b0rz
= 1. / (1. + alpha
);
5876 b1
= 2. * b0rz
* cos(w0
);
5877 a0
= (1. - alpha
) * b0rz
;
5881 unit
->m_freq
= nextfreq
;
5882 unit
->m_rq
= nextrq
;
5884 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5885 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5887 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5888 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5890 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5891 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5893 LOOP(unit
->mRate
->mFilterRemain
,
5894 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5895 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5898 unit
->m_freq
= ZXP(freq
);
5899 unit
->m_rq
= ZXP(rq
);
5907 unit
->m_y1
= zapgremlins(y1
);
5908 unit
->m_y2
= zapgremlins(y2
);
5912 void BAllPass_next_kk(BAllPass
*unit
, int inNumSamples
)
5914 float *out
= ZOUT(0);
5916 float nextfreq
= ZIN0(1);
5917 float nextrq
= ZIN0(2);
5919 double a0
, a1
, a2
, b1
, b2
;
5920 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5922 double y1
= unit
->m_y1
;
5923 double y2
= unit
->m_y2
;
5924 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5932 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5933 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5934 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
5935 nextb0rz
= 1. / (1. + nextalpha
);
5936 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
5937 nexta0
= (1. - nextalpha
) * nextb0rz
;
5941 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
;
5942 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
;
5943 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
;
5944 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
;
5945 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
;
5946 unit
->m_freq
= nextfreq
;
5947 unit
->m_rq
= nextrq
;
5948 LOOP(unit
->mRate
->mFilterLoops
,
5949 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5950 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5952 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5953 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5955 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5956 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5963 LOOP(unit
->mRate
->mFilterRemain
,
5964 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5965 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5971 LOOP(unit
->mRate
->mFilterLoops
,
5972 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5973 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5975 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5976 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5978 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5979 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5981 LOOP(unit
->mRate
->mFilterRemain
,
5982 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5983 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5994 unit
->m_y1
= zapgremlins(y1
);
5995 unit
->m_y2
= zapgremlins(y2
);
6000 struct BLowShelf
: public Unit
6002 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
6003 float m_freq
, m_rs
, m_db
;
6008 void BLowShelf_next_kkk(BLowShelf
*unit
, int inNumSamples
);
6009 void BLowShelf_next_aaa(BLowShelf
*unit
, int inNumSamples
);
6010 void BLowShelf_Ctor(BLowShelf
* unit
);
6013 void BLowShelf_Ctor(BLowShelf
* unit
)
6015 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
6016 SETCALC(BLowShelf_next_aaa
);
6018 SETCALC(BLowShelf_next_kkk
);
6020 float freq
= unit
->m_freq
= ZIN0(1);
6021 float rs
= unit
->m_rs
= ZIN0(2);
6022 float db
= unit
->m_db
= ZIN0(3);
6023 double a
= pow(10., (double)db
* 0.025);
6024 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
6025 double cosw0
= cos(w0
);
6026 double sinw0
= sin(w0
);
6027 double alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)rs
- 1.) + 2.);
6028 double i
= (a
+ 1.) * cosw0
;
6029 double j
= (a
- 1.) * cosw0
;
6030 double k
= 2. * sqrt(a
) * alpha
;
6031 double b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6032 unit
->m_a0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6033 unit
->m_a1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6034 unit
->m_a2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6035 unit
->m_b1
= 2. * ((a
- 1.) + i
) * b0rz
;
6036 unit
->m_b2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6042 BLowShelf_next_kkk(unit
, 1);
6046 void BLowShelf_next_aaa(BLowShelf
*unit
, int inNumSamples
)
6048 float *out
= ZOUT(0);
6050 float *freq
= ZIN(1);
6054 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6056 float nextfreq
, nextrs
, nextdb
;
6067 LOOP(unit
->mRate
->mFilterLoops
,
6068 nextfreq
= ZXP(freq
);
6071 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6072 a
= pow(10., (double)nextdb
* 0.025);
6073 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6076 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6077 i
= (a
+ 1.) * cosw0
;
6078 j
= (a
- 1.) * cosw0
;
6079 k
= 2. * sqrt(a
) * alpha
;
6080 b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6081 a0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6082 a1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6083 a2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6084 b1
= 2. * ((a
- 1.) + i
) * b0rz
;
6085 b2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6086 unit
->m_freq
= nextfreq
;
6087 unit
->m_rs
= nextrs
;
6088 unit
->m_db
= nextdb
;
6090 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6091 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6093 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6094 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6096 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6097 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6099 LOOP(unit
->mRate
->mFilterRemain
,
6100 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6101 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6104 unit
->m_freq
= ZXP(freq
);
6105 unit
->m_rs
= ZXP(rs
);
6106 unit
->m_db
= ZXP(db
);
6114 unit
->m_y1
= zapgremlins(y1
);
6115 unit
->m_y2
= zapgremlins(y2
);
6118 void BLowShelf_next_kkk(BLowShelf
*unit
, int inNumSamples
)
6120 float *out
= ZOUT(0);
6122 float nextfreq
= ZIN0(1);
6123 float nextrs
= ZIN0(2);
6124 float nextdb
= ZIN0(3);
6126 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6127 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
6138 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6139 a
= pow(10., (double)nextdb
* 0.025);
6140 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6143 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6144 i
= (a
+ 1.) * cosw0
;
6145 j
= (a
- 1.) * cosw0
;
6146 k
= 2. * sqrt(a
) * alpha
;
6147 b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6148 nexta0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6149 nexta1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6150 nexta2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6151 nextb1
= 2. * ((a
- 1.) + i
) * b0rz
;
6152 nextb2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6153 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
6154 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
6155 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
6156 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
6157 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
6158 unit
->m_freq
= nextfreq
;
6159 unit
->m_db
= nextdb
;
6160 unit
->m_rs
= nextrs
;
6161 LOOP(unit
->mRate
->mFilterLoops
,
6162 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6163 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6165 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6166 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6168 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6169 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6178 LOOP(unit
->mRate
->mFilterRemain
,
6179 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6180 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6186 LOOP(unit
->mRate
->mFilterLoops
,
6187 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6188 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6190 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6191 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6193 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6194 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6197 LOOP(unit
->mRate
->mFilterRemain
,
6198 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6199 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6210 unit
->m_y1
= zapgremlins(y1
);
6211 unit
->m_y2
= zapgremlins(y2
);
6215 struct BHiShelf
: public Unit
6217 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
6218 float m_freq
, m_rs
, m_db
;
6223 void BHiShelf_next_kkk(BHiShelf
*unit
, int inNumSamples
);
6224 void BHiShelf_next_aaa(BHiShelf
*unit
, int inNumSamples
);
6225 void BHiShelf_Ctor(BHiShelf
* unit
);
6228 void BHiShelf_Ctor(BHiShelf
* unit
)
6230 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
6231 SETCALC(BHiShelf_next_aaa
);
6233 SETCALC(BHiShelf_next_kkk
);
6235 float freq
= unit
->m_freq
= ZIN0(1);
6236 float rs
= unit
->m_rs
= ZIN0(2);
6237 float db
= unit
->m_db
= ZIN0(3);
6238 double a
= pow(10., (double)db
* 0.025);
6239 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
6240 double cosw0
= cos(w0
);
6241 double sinw0
= sin(w0
);
6242 double alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)rs
- 1.) + 2.);
6243 double i
= (a
+ 1.) * cosw0
;
6244 double j
= (a
- 1.) * cosw0
;
6245 double k
= 2. * sqrt(a
) * alpha
;
6247 double b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6248 unit
->m_a0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6249 unit
->m_a1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6250 unit
->m_a2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6251 unit
->m_b1
= -2. * ((a
- 1.) - i
) * b0rz
;
6252 unit
->m_b2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6258 BHiShelf_next_kkk(unit
, 1);
6262 void BHiShelf_next_aaa(BHiShelf
*unit
, int inNumSamples
)
6264 float *out
= ZOUT(0);
6266 float *freq
= ZIN(1);
6270 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6272 float nextfreq
, nextrs
, nextdb
;
6283 LOOP(unit
->mRate
->mFilterLoops
,
6284 nextfreq
= ZXP(freq
);
6287 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6288 a
= pow(10., (double)nextdb
* 0.025);
6289 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6292 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6293 i
= (a
+ 1.) * cosw0
;
6294 j
= (a
- 1.) * cosw0
;
6295 k
= 2. * sqrt(a
) * alpha
;
6296 b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6297 a0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6298 a1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6299 a2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6300 b1
= -2. * ((a
- 1.) - i
) * b0rz
;
6301 b2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6302 unit
->m_freq
= ZXP(freq
);
6303 unit
->m_rs
= ZXP(rs
);
6304 unit
->m_db
= ZXP(db
);
6306 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6307 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6309 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6310 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6312 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6313 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6315 LOOP(unit
->mRate
->mFilterRemain
,
6316 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6317 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6320 unit
->m_freq
= ZXP(freq
);
6321 unit
->m_rs
= ZXP(rs
);
6322 unit
->m_db
= ZXP(db
);
6330 unit
->m_y1
= zapgremlins(y1
);
6331 unit
->m_y2
= zapgremlins(y2
);
6334 void BHiShelf_next_kkk(BHiShelf
*unit
, int inNumSamples
)
6336 float *out
= ZOUT(0);
6338 float nextfreq
= ZIN0(1);
6339 float nextrs
= ZIN0(2);
6340 float nextdb
= ZIN0(3);
6342 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6343 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
6354 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6355 a
= pow(10., (double)nextdb
* 0.025);
6356 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6359 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6360 i
= (a
+ 1.) * cosw0
;
6361 j
= (a
- 1.) * cosw0
;
6362 k
= 2. * sqrt(a
) * alpha
;
6363 b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6364 nexta0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6365 nexta1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6366 nexta2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6367 nextb1
= -2. * ((a
- 1.) - i
) * b0rz
;
6368 nextb2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6369 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
6370 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
6371 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
6372 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
6373 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
6374 unit
->m_freq
= nextfreq
;
6375 unit
->m_db
= nextdb
;
6376 unit
->m_rs
= nextrs
;
6377 LOOP(unit
->mRate
->mFilterLoops
,
6378 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6379 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6381 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6382 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6384 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6385 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6394 LOOP(unit
->mRate
->mFilterRemain
,
6395 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6396 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6402 LOOP(unit
->mRate
->mFilterLoops
,
6403 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6404 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6406 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6407 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6409 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6410 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6413 LOOP(unit
->mRate
->mFilterRemain
,
6414 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6415 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6425 unit
->m_y1
= zapgremlins(y1
);
6426 unit
->m_y2
= zapgremlins(y2
);
6429 ////////////////////////////////////////////////////////////////////////////////////////////////////////
6434 DefineSimpleUnit(Ramp
);
6435 DefineSimpleUnit(Lag
);
6436 DefineSimpleUnit(Lag2
);
6437 DefineSimpleUnit(Lag3
);
6438 DefineSimpleUnit(LagUD
);
6439 DefineSimpleUnit(Lag2UD
);
6440 DefineSimpleUnit(Lag3UD
);
6441 DefineSimpleUnit(VarLag
);
6442 DefineSimpleUnit(OnePole
);
6443 DefineSimpleUnit(OneZero
);
6444 DefineSimpleUnit(TwoPole
);
6445 DefineSimpleUnit(TwoZero
);
6446 DefineSimpleUnit(Decay
);
6447 DefineSimpleUnit(Decay2
);
6448 DefineSimpleUnit(Flip
);
6449 DefineSimpleUnit(Delay1
);
6450 DefineSimpleUnit(Delay2
);
6451 DefineSimpleUnit(Integrator
);
6452 DefineSimpleUnit(LeakDC
);
6453 DefineSimpleUnit(LPZ1
);
6454 DefineSimpleUnit(HPZ1
);
6455 DefineSimpleUnit(LPZ2
);
6456 DefineSimpleUnit(HPZ2
);
6457 DefineSimpleUnit(BPZ2
);
6458 DefineSimpleUnit(BRZ2
);
6459 DefineSimpleUnit(APF
);
6460 DefineSimpleUnit(LPF
);
6461 DefineSimpleUnit(HPF
);
6462 DefineSimpleUnit(BPF
);
6463 DefineSimpleUnit(BRF
);
6464 DefineSimpleUnit(RLPF
);
6465 DefineSimpleUnit(RHPF
);
6467 DefineSimpleUnit(Slew
);
6468 DefineSimpleUnit(Slope
);
6470 DefineSimpleUnit(MidEQ
);
6471 DefineSimpleUnit(Median
);
6473 DefineSimpleUnit(Resonz
);
6474 DefineSimpleUnit(Ringz
);
6475 DefineSimpleUnit(Formlet
);
6477 DefineSimpleUnit(FOS
);
6478 DefineSimpleUnit(SOS
);
6480 DefineSimpleUnit(Compander
);
6481 DefineDtorUnit(Limiter
);
6482 DefineDtorUnit(Normalizer
);
6484 DefineSimpleUnit(Amplitude
);
6485 DefineSimpleUnit(DetectSilence
);
6487 DefineSimpleUnit(Hilbert
);
6488 DefineSimpleUnit(FreqShift
);
6489 DefineSimpleUnit(MoogFF
);
6491 /* BEQSuite UGens */
6492 DefineSimpleUnit(BLowPass
);
6493 DefineSimpleUnit(BHiPass
);
6494 DefineSimpleUnit(BBandPass
);
6495 DefineSimpleUnit(BBandStop
);
6496 DefineSimpleUnit(BPeakEQ
);
6497 DefineSimpleUnit(BAllPass
);
6498 DefineSimpleUnit(BLowShelf
);
6499 DefineSimpleUnit(BHiShelf
);
6503 //////////////////////////////////////////////////////////////////////////////////////////////////