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 float m_s1
, m_s2
, m_s3
, m_s4
; // 1st order filter states
311 //////////////////////////////////////////////////////////////////////////////////////////////////
317 void Ramp_next(Ramp
*unit
, int inNumSamples
);
318 void Ramp_next_1(Ramp
*unit
, int inNumSamples
);
319 void Ramp_Ctor(Ramp
* unit
);
321 void Lag_next(Lag
*unit
, int inNumSamples
);
322 void Lag_Ctor(Lag
* unit
);
324 void Lag2_Ctor(Lag2
* unit
);
326 void Lag3_next(Lag3
*unit
, int inNumSamples
);
327 void Lag3_Ctor(Lag3
* unit
);
329 void LagUD_next(LagUD
*unit
, int inNumSamples
);
330 void LagUD_Ctor(LagUD
* unit
);
332 void Lag2UD_next(Lag2UD
*unit
, int inNumSamples
);
333 void Lag2UD_Ctor(Lag2UD
* unit
);
335 void Lag3UD_next(Lag3UD
*unit
, int inNumSamples
);
336 void Lag3UD_Ctor(Lag3UD
* unit
);
338 void VarLag_next(VarLag
*unit
, int inNumSamples
);
339 void VarLag_Ctor(VarLag
* unit
);
341 void OnePole_next_a(OnePole
*unit
, int inNumSamples
);
342 void OnePole_next_k(OnePole
*unit
, int inNumSamples
);
343 void OnePole_Ctor(OnePole
* unit
);
345 void OneZero_next(OneZero
* unit
, int inNumSamples
);
346 void OneZero_Ctor(OneZero
* unit
);
348 void Integrator_next(Integrator
*unit
, int inNumSamples
);
349 void Integrator_Ctor(Integrator
* unit
);
351 void Decay_next(Decay
*unit
, int inNumSamples
);
352 void Decay_Ctor(Decay
* unit
);
354 void Decay2_next(Decay2
*unit
, int inNumSamples
);
355 void Decay2_Ctor(Decay2
* unit
);
357 void LeakDC_next(LeakDC
*unit
, int inNumSamples
);
358 void LeakDC_next_1(LeakDC
* unit
, int inNumSamples
);
359 void LeakDC_Ctor(LeakDC
* unit
);
361 void TwoPole_next(TwoPole
*unit
, int inNumSamples
);
362 void TwoPole_Ctor(TwoPole
* unit
);
364 void TwoZero_next(TwoZero
*unit
, int inNumSamples
);
365 void TwoZero_Ctor(TwoZero
* unit
);
367 void APF_next(APF
*unit
, int inNumSamples
);
368 void APF_Ctor(APF
* unit
);
370 void LPZ1_next(LPZ1
*unit
, int inNumSamples
);
371 void LPZ1_Ctor(LPZ1
* unit
);
373 void HPZ1_next(HPZ1
*unit
, int inNumSamples
);
374 void HPZ1_Ctor(HPZ1
* unit
);
376 void Slope_next(Slope
*unit
, int inNumSamples
);
377 void Slope_Ctor(Slope
* unit
);
379 void Delay1_next(Delay1
*unit
, int inNumSamples
);
380 void Delay1_Ctor(Delay1
* unit
);
382 void Flip_Ctor(Flip
* unit
);
383 void Flip_next_even(Flip
*unit
, int inNumSamples
);
384 void Flip_next_odd(Flip
*unit
, int inNumSamples
);
386 void Delay2_next(Delay2
*unit
, int inNumSamples
);
387 void Delay2_Ctor(Delay2
* unit
);
389 void LPZ2_next(LPZ2
*unit
, int inNumSamples
);
390 void LPZ2_Ctor(LPZ2
* unit
);
392 void HPZ2_next(HPZ2
*unit
, int inNumSamples
);
393 void HPZ2_Ctor(HPZ2
* unit
);
395 void BPZ2_next(BPZ2
*unit
, int inNumSamples
);
396 void BPZ2_Ctor(BPZ2
* unit
);
398 void BRZ2_next(BRZ2
*unit
, int inNumSamples
);
399 void BRZ2_Ctor(BRZ2
* unit
);
401 void Slew_next(Slew
*unit
, int inNumSamples
);
402 void Slew_Ctor(Slew
* unit
);
404 void RLPF_next(RLPF
*unit
, int inNumSamples
);
405 void RLPF_next_1(RLPF
*unit
, int inNumSamples
);
406 void RLPF_Ctor(RLPF
* unit
);
408 void RHPF_next(RHPF
*unit
, int inNumSamples
);
409 void RHPF_next_1(RHPF
*unit
, int inNumSamples
);
410 void RHPF_Ctor(RHPF
* unit
);
412 void LPF_next(LPF
*unit
, int inNumSamples
);
413 void LPF_next_1(LPF
*unit
, int inNumSamples
);
414 void LPF_Ctor(LPF
* unit
);
416 void HPF_next(HPF
*unit
, int inNumSamples
);
417 void HPF_next_1(HPF
*unit
, int inNumSamples
);
418 void HPF_Ctor(HPF
* unit
);
420 void BPF_next(BPF
*unit
, int inNumSamples
);
421 void BPF_next_1(BPF
*unit
, int inNumSamples
);
422 void BPF_Ctor(BPF
* unit
);
424 void BRF_next(BRF
*unit
, int inNumSamples
);
425 void BRF_next_1(BRF
*unit
, int inNumSamples
);
426 void BRF_Ctor(BRF
* unit
);
428 void Median_next(Median
*unit
, int inNumSamples
);
429 void Median_Ctor(Median
* unit
);
431 void MidEQ_next(MidEQ
*unit
, int inNumSamples
);
432 void MidEQ_Ctor(MidEQ
* unit
);
434 void Resonz_next(Resonz
*unit
, int inNumSamples
);
435 void Resonz_Ctor(Resonz
* unit
);
437 void Ringz_next(Ringz
*unit
, int inNumSamples
);
438 void Ringz_Ctor(Ringz
* unit
);
440 void Formlet_next(Formlet
*unit
, int inNumSamples
);
441 void Formlet_next_1(Formlet
*unit
, int inNumSamples
);
442 void Formlet_Ctor(Formlet
* unit
);
444 void FOS_next_k(FOS
*unit
, int inNumSamples
);
445 void FOS_next_a(FOS
*unit
, int inNumSamples
);
446 void FOS_next_1(FOS
*unit
, int inNumSamples
);
447 void FOS_Ctor(FOS
* unit
);
449 void SOS_next_k(SOS
*unit
, int inNumSamples
);
450 void SOS_next_a(SOS
*unit
, int inNumSamples
);
451 void SOS_next_1(SOS
*unit
, int inNumSamples
);
452 void SOS_Ctor(SOS
* unit
);
454 void Normalizer_next(Normalizer
*unit
, int inNumSamples
);
455 void Normalizer_Ctor(Normalizer
* unit
);
456 void Normalizer_Dtor(Normalizer
* unit
);
458 void Limiter_next(Limiter
*unit
, int inNumSamples
);
459 void Limiter_Ctor(Limiter
* unit
);
460 void Limiter_Dtor(Limiter
* unit
);
462 void Compander_next(Compander
*unit
, int inNumSamples
);
463 void Compander_Ctor(Compander
* unit
);
465 void Amplitude_next(Amplitude
*unit
, int inNumSamples
);
466 void Amplitude_next_kk(Amplitude
*unit
, int inNumSamples
);
467 void Amplitude_next_atok(Amplitude
*unit
, int inNumSamples
);
468 void Amplitude_next_atok_kk(Amplitude
*unit
, int inNumSamples
);
469 void Amplitude_Ctor(Amplitude
* unit
);
471 void DetectSilence_next(DetectSilence
*unit
, int inNumSamples
);
472 void DetectSilence_done(DetectSilence
*unit
, int inNumSamples
);
473 void DetectSilence_Ctor(DetectSilence
* unit
);
475 void Hilbert_Ctor(Hilbert
* unit
);
476 void Hilbert_next(Hilbert
*unit
, int inNumSamples
);
478 void FreqShift_Ctor(FreqShift
* unit
);
479 void FreqShift_next_kk(FreqShift
*unit
, int inNumSamples
);
480 void FreqShift_next_aa(FreqShift
*unit
, int inNumSamples
);
481 void FreqShift_next_ak(FreqShift
*unit
, int inNumSamples
);
482 void FreqShift_next_ka(FreqShift
*unit
, int inNumSamples
);
484 void MoogFF_next(MoogFF
*unit
, int inNumSamples
);
485 void MoogFF_Ctor(MoogFF
* unit
);
488 void Lag_next(Lag *unit, int inNumSamples);
489 void Lag_Ctor(Lag* unit);
491 void Lag_next(Lag *unit, int inNumSamples);
492 void Lag_Ctor(Lag* unit);
496 //////////////////////////////////////////////////////////////////////////////////////////////////
498 void Ramp_next(Ramp
*unit
, int inNumSamples
)
500 float *out
= ZOUT(0);
502 float period
= ZIN0(1);
504 double slope
= unit
->m_slope
;
505 double level
= unit
->m_level
;
506 int counter
= unit
->m_counter
;
507 int remain
= inNumSamples
;
509 int nsmps
= sc_min(remain
, counter
);
518 counter
= (int)(period
* SAMPLERATE
);
519 counter
= sc_max(1, counter
);
520 slope
= (*in
- level
) / counter
;
523 unit
->m_level
= level
;
524 unit
->m_slope
= slope
;
525 unit
->m_counter
= counter
;
528 void Ramp_next_1(Ramp
*unit
, int inNumSamples
)
532 *out
= unit
->m_level
;
533 unit
->m_level
+= unit
->m_slope
;
534 if (--unit
->m_counter
<= 0) {
536 float period
= ZIN0(1);
537 int counter
= (int)(period
* SAMPLERATE
);
538 unit
->m_counter
= counter
= sc_max(1, counter
);
539 unit
->m_slope
= (in
- unit
->m_level
) / counter
;
543 void Ramp_Ctor(Ramp
* unit
)
545 if (BUFLENGTH
== 1) {
546 SETCALC(Ramp_next_1
);
552 unit
->m_level
= ZIN0(0);
554 ZOUT0(0) = unit
->m_level
;
557 //////////////////////////////////////////////////////////////////////////////////////////////////
559 void Lag_next(Lag
*unit
, int inNumSamples
)
561 float *out
= ZOUT(0);
566 float y1
= unit
->m_y1
;
567 float b1
= unit
->m_b1
;
569 if (lag
== unit
->m_lag
) {
572 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
575 unit
->m_b1
= lag
== 0.f
? 0.f
: exp(log001
/ (lag
* unit
->mRate
->mSampleRate
));
576 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
581 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
584 unit
->m_y1
= zapgremlins(y1
);
587 void Lag_next_1(Lag
*unit
, int inNumSamples
)
593 float y1
= unit
->m_y1
;
594 float b1
= unit
->m_b1
;
596 if (lag
== unit
->m_lag
) {
598 *out
= y1
= y0
+ b1
* (y1
- y0
);
600 unit
->m_b1
= b1
= lag
== 0.f
? 0.f
: exp(log001
/ (lag
* unit
->mRate
->mSampleRate
));
603 *out
= y1
= y0
+ b1
* (y1
- y0
);
605 unit
->m_y1
= zapgremlins(y1
);
608 void Lag_Ctor(Lag
* unit
)
617 unit
->m_y1
= ZIN0(0);
621 //////////////////////////////////////////////////////////////////////////////////////////////////
622 void LagUD_next(LagUD
*unit
, int inNumSamples
)
624 float *out
= ZOUT(0);
626 float lagu
= ZIN0(1);
627 float lagd
= ZIN0(2);
629 float y1
= unit
->m_y1
;
630 float b1u
= unit
->m_b1u
;
631 float b1d
= unit
->m_b1d
;
633 if ( (lagu
== unit
->m_lagu
) && (lagd
== unit
->m_lagd
) ) {
637 ZXP(out
) = y1
= y0
+ b1u
* (y1
- y0
);
639 ZXP(out
) = y1
= y0
+ b1d
* (y1
- y0
);
642 unit
->m_b1u
= lagu
== 0.f
? 0.f
: exp(log001
/ (lagu
* unit
->mRate
->mSampleRate
));
643 float b1u_slope
= CALCSLOPE(unit
->m_b1u
, b1u
);
645 unit
->m_b1d
= lagd
== 0.f
? 0.f
: exp(log001
/ (lagd
* unit
->mRate
->mSampleRate
));
646 float b1d_slope
= CALCSLOPE(unit
->m_b1d
, b1d
);
653 ZXP(out
) = y1
= y0
+ b1u
* (y1
- y0
);
655 ZXP(out
) = y1
= y0
+ b1d
* (y1
- y0
);
658 unit
->m_y1
= zapgremlins(y1
);
661 void LagUD_Ctor(LagUD
* unit
)
669 unit
->m_y1
= ZIN0(0);
673 //////////////////////////////////////////////////////////////////////////////////////////////////
675 static void Lag2_next_k(Lag2
*unit
, int inNumSamples
)
677 float *out
= ZOUT(0);
681 float y1a
= unit
->m_y1a
;
682 float y1b
= unit
->m_y1b
;
683 float b1
= unit
->m_b1
;
685 if (lag
== unit
->m_lag
) {
688 y1a
= y0a
+ b1
* (y1a
- y0a
);
689 y1b
= y1a
+ b1
* (y1b
- y1a
);
693 unit
->m_b1
= lag
== 0.f
? 0.f
: exp(log001
/ (lag
* unit
->mRate
->mSampleRate
));
694 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
699 y1a
= y0a
+ b1
* (y1a
- y0a
);
700 y1b
= y1a
+ b1
* (y1b
- y1a
);
704 unit
->m_y1a
= zapgremlins(y1a
);
705 unit
->m_y1b
= zapgremlins(y1b
);
708 static void Lag2_next_i(Lag2
*unit
, int inNumSamples
)
710 float *out
= ZOUT(0);
713 float y1a
= unit
->m_y1a
;
714 float y1b
= unit
->m_y1b
;
715 float b1
= unit
->m_b1
;
719 y1a
= y0a
+ b1
* (y1a
- y0a
);
720 y1b
= y1a
+ b1
* (y1b
- y1a
);
723 unit
->m_y1a
= zapgremlins(y1a
);
724 unit
->m_y1b
= zapgremlins(y1b
);
727 static void Lag2_next_1_i(Lag2
*unit
, int inNumSamples
)
729 float y1a
= unit
->m_y1a
;
730 float y1b
= unit
->m_y1b
;
731 float b1
= unit
->m_b1
;
734 y1a
= y0a
+ b1
* (y1a
- y0a
);
735 y1b
= y1a
+ b1
* (y1b
- y1a
);
738 unit
->m_y1a
= zapgremlins(y1a
);
739 unit
->m_y1b
= zapgremlins(y1b
);
742 void Lag2_Ctor(Lag2
* unit
)
747 SETCALC(Lag2_next_k
);
752 SETCALC(Lag2_next_1_i
);
754 SETCALC(Lag2_next_i
);
760 unit
->m_y1a
= unit
->m_y1b
= ZIN0(0);
761 Lag2_next_k(unit
, 1);
764 //////////////////////////////////////////////////////////////////////////////////////////////////
766 void Lag2UD_next(Lag2UD
*unit
, int inNumSamples
)
768 float *out
= ZOUT(0);
770 float lagu
= ZIN0(1);
771 float lagd
= ZIN0(2);
773 float y1a
= unit
->m_y1a
;
774 float y1b
= unit
->m_y1b
;
775 float b1u
= unit
->m_b1u
;
776 float b1d
= unit
->m_b1d
;
778 if ( (lagu
== unit
->m_lagu
) && (lagd
== unit
->m_lagd
) ) {
782 y1a
= y0a
+ b1u
* (y1a
- y0a
);
784 y1a
= y0a
+ b1d
* (y1a
- y0a
);
787 y1b
= y1a
+ b1u
* (y1b
- y1a
);
789 y1b
= y1a
+ b1d
* (y1b
- y1a
);
793 unit
->m_b1u
= lagu
== 0.f
? 0.f
: exp(log001
/ (lagu
* unit
->mRate
->mSampleRate
));
794 float b1u_slope
= CALCSLOPE(unit
->m_b1u
, b1u
);
796 unit
->m_b1d
= lagd
== 0.f
? 0.f
: exp(log001
/ (lagd
* unit
->mRate
->mSampleRate
));
797 float b1d_slope
= CALCSLOPE(unit
->m_b1d
, b1d
);
804 y1a
= y0a
+ b1u
* (y1a
- y0a
);
806 y1a
= y0a
+ b1d
* (y1a
- y0a
);
809 y1b
= y1a
+ b1u
* (y1b
- y1a
);
811 y1b
= y1a
+ b1d
* (y1b
- y1a
);
815 unit
->m_y1a
= zapgremlins(y1a
);
816 unit
->m_y1b
= zapgremlins(y1b
);
819 void Lag2UD_Ctor(Lag2UD
* unit
)
821 SETCALC(Lag2UD_next
);
827 unit
->m_y1a
= unit
->m_y1b
= ZIN0(0);
828 Lag2UD_next(unit
, 1);
831 //////////////////////////////////////////////////////////////////////////////////////////////////
833 void Lag3_next(Lag3
*unit
, int inNumSamples
)
835 float *out
= ZOUT(0);
839 float y1a
= unit
->m_y1a
;
840 float y1b
= unit
->m_y1b
;
841 float y1c
= unit
->m_y1c
;
842 float b1
= unit
->m_b1
;
844 if (lag
== unit
->m_lag
) {
847 y1a
= y0a
+ b1
* (y1a
- y0a
);
848 y1b
= y1a
+ b1
* (y1b
- y1a
);
849 y1c
= y1b
+ b1
* (y1c
- y1b
);
853 unit
->m_b1
= lag
== 0.f
? 0.f
: exp(log001
/ (lag
* unit
->mRate
->mSampleRate
));
854 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
859 y1a
= y0a
+ b1
* (y1a
- y0a
);
860 y1b
= y1a
+ b1
* (y1b
- y1a
);
861 y1c
= y1b
+ b1
* (y1c
- y1b
);
865 unit
->m_y1a
= zapgremlins(y1a
);
866 unit
->m_y1b
= zapgremlins(y1b
);
867 unit
->m_y1c
= zapgremlins(y1c
);
870 void Lag3_Ctor(Lag3
* unit
)
876 unit
->m_y1a
= unit
->m_y1b
= unit
->m_y1c
= ZIN0(0);
880 //////////////////////////////////////////////////////////////////////////////////////////////////
882 void Lag3UD_next(Lag3UD
*unit
, int inNumSamples
)
884 float *out
= ZOUT(0);
886 float lagu
= ZIN0(1);
887 float lagd
= ZIN0(2);
889 float y1a
= unit
->m_y1a
;
890 float y1b
= unit
->m_y1b
;
891 float y1c
= unit
->m_y1c
;
892 float b1u
= unit
->m_b1u
;
893 float b1d
= unit
->m_b1d
;
895 if ( (lagu
== unit
->m_lagu
) && (lagd
== unit
->m_lagd
) ) {
899 y1a
= y0a
+ b1u
* (y1a
- y0a
);
901 y1a
= y0a
+ b1d
* (y1a
- y0a
);
904 y1b
= y1a
+ b1u
* (y1b
- y1a
);
906 y1b
= y1a
+ b1d
* (y1b
- y1a
);
909 y1c
= y1b
+ b1u
* (y1c
- y1b
);
911 y1c
= y1b
+ b1d
* (y1c
- y1b
);
916 unit
->m_b1u
= lagu
== 0.f
? 0.f
: exp(log001
/ (lagu
* unit
->mRate
->mSampleRate
));
917 float b1u_slope
= CALCSLOPE(unit
->m_b1u
, b1u
);
919 unit
->m_b1d
= lagd
== 0.f
? 0.f
: exp(log001
/ (lagd
* unit
->mRate
->mSampleRate
));
920 float b1d_slope
= CALCSLOPE(unit
->m_b1d
, b1d
);
927 y1a
= y0a
+ b1u
* (y1a
- y0a
);
929 y1a
= y0a
+ b1d
* (y1a
- y0a
);
932 y1b
= y1a
+ b1u
* (y1b
- y1a
);
934 y1b
= y1a
+ b1d
* (y1b
- y1a
);
937 y1c
= y1b
+ b1u
* (y1c
- y1b
);
939 y1c
= y1b
+ b1d
* (y1c
- y1b
);
944 unit
->m_y1a
= zapgremlins(y1a
);
945 unit
->m_y1b
= zapgremlins(y1b
);
946 unit
->m_y1c
= zapgremlins(y1c
);
949 void Lag3UD_Ctor(Lag3UD
* unit
)
951 SETCALC(Lag3UD_next
);
958 unit
->m_y1a
= unit
->m_y1b
= unit
->m_y1c
= ZIN0(0);
959 Lag3UD_next(unit
, 1);
962 //////////////////////////////////////////////////////////////////////////////////////////////////
964 void VarLag_next(VarLag
*unit
, int inNumSamples
)
966 float *out
= ZOUT(0);
968 float lagTime
= ZIN0(1);
969 double slope
= unit
->m_slope
;
970 double level
= unit
->m_level
;
971 int counter
= unit
->m_counter
;
972 int remain
= inNumSamples
;
974 if ( *in
!= unit
->m_in
) {
975 counter
= (int)(lagTime
* SAMPLERATE
);
976 counter
= unit
->m_counter
= sc_max(1, counter
);
977 slope
= unit
->m_slope
= ( *in
- unit
->m_level
) / counter
;
979 unit
->m_lagTime
= lagTime
;
981 if (lagTime
!= unit
->m_lagTime
) {
982 float scaleFactor
= lagTime
/unit
->m_lagTime
;
983 counter
= (int) (unit
->m_counter
* scaleFactor
);
984 counter
= unit
->m_counter
= sc_max(1, counter
);
985 slope
= unit
->m_slope
/ scaleFactor
;
986 unit
->m_lagTime
= lagTime
;
993 level
+= slope
; --counter
;
999 LOOP(remain
, ZXP(out
) = level
);
1002 unit
->m_level
= level
;
1003 unit
->m_slope
= slope
;
1004 unit
->m_counter
= counter
;
1008 void VarLag_next_1(VarLag
*unit
, int inNumSamples
)
1010 float *out
= OUT(0);
1012 float lagTime
= ZIN0(1);
1013 int counter
= unit
->m_counter
;
1014 if ( in
!= unit
->m_in
) {
1015 counter
= (int)(lagTime
* SAMPLERATE
);
1016 unit
->m_counter
= counter
= sc_max(1, counter
);
1017 unit
->m_slope
= ( in
- unit
->m_level
) / counter
;
1019 unit
->m_lagTime
= lagTime
;
1021 if (lagTime
!= unit
->m_lagTime
) {
1023 double scaleFactor
= lagTime
/unit
->m_lagTime
;
1024 counter
= (int) (unit
->m_counter
* scaleFactor
);
1025 unit
->m_counter
= counter
= sc_max(1, counter
);
1026 unit
->m_slope
= unit
->m_slope
/ scaleFactor
; }
1027 unit
->m_lagTime
= lagTime
; }
1029 *out
= unit
->m_level
;
1031 if (unit
->m_counter
> 0) {
1032 unit
->m_level
+= unit
->m_slope
;
1035 unit
->m_level
= unit
->m_in
;
1040 void VarLag_Ctor(VarLag
* unit
)
1042 if (BUFLENGTH
== 1) {
1043 SETCALC(VarLag_next_1
);
1045 SETCALC(VarLag_next
);
1048 float lagTime
= ZIN0(1);
1049 unit
->m_level
= ZIN0(2);
1050 int counter
= (int)(lagTime
* SAMPLERATE
);
1051 unit
->m_counter
= counter
= sc_max(1, counter
);
1052 unit
->m_slope
= ( in
- unit
->m_level
) / counter
;
1054 unit
->m_lagTime
= lagTime
;
1055 ZOUT0(0) = unit
->m_level
;
1059 //////////////////////////////////////////////////////////////////////////////////////////////////
1061 void OnePole_next_a(OnePole
*unit
, int inNumSamples
)
1063 //printf("OnePole_next_a\n");
1065 float *out
= ZOUT(0);
1067 float *b1p
= ZIN(1);
1069 float y1
= unit
->m_y1
;
1073 float b1
= ZXP(b1p
);
1074 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
1076 unit
->m_y1
= zapgremlins(y1
);
1079 void OnePole_next_k(OnePole
*unit
, int inNumSamples
)
1081 //printf("OnePole_next_a\n");
1083 float *out
= ZOUT(0);
1085 float b1
= unit
->m_b1
;
1086 unit
->m_b1
= ZIN0(1);
1088 float y1
= unit
->m_y1
;
1090 if (b1
== unit
->m_b1
) {
1094 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
1099 ZXP(out
) = y1
= y0
+ b1
* (y1
+ y0
);
1103 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1104 if (b1
>= 0.f
&& unit
->m_b1
>= 0) {
1107 ZXP(out
) = y1
= y0
+ b1
* (y1
- y0
);
1110 } else if (b1
<= 0.f
&& unit
->m_b1
<= 0) {
1113 ZXP(out
) = y1
= y0
+ b1
* (y1
+ y0
);
1119 ZXP(out
) = y1
= (1.f
- std::abs(b1
)) * y0
+ b1
* y1
;
1124 unit
->m_y1
= zapgremlins(y1
);
1127 void OnePole_Ctor(OnePole
* unit
)
1129 if (INRATE(1) == calc_FullRate
) {
1130 SETCALC(OnePole_next_a
);
1132 SETCALC(OnePole_next_k
);
1136 OnePole_next_a(unit
, 1);
1139 //////////////////////////////////////////////////////////////////////////////////////////////////
1141 void OneZero_Ctor(OneZero
* unit
)
1143 SETCALC(OneZero_next
);
1145 unit
->m_x1
= ZIN0(0);
1146 OneZero_next(unit
, 1);
1150 void OneZero_next(OneZero
* unit
, int inNumSamples
)
1152 //printf("OneZero::next\n");
1154 float *out
= ZOUT(0);
1156 float b1
= unit
->m_b1
;
1157 unit
->m_b1
= ZIN0(1);
1159 float x1
= unit
->m_x1
;
1160 if (b1
== unit
->m_b1
) {
1164 ZXP(out
) = x0
+ b1
* (x1
- x0
);
1170 ZXP(out
) = x0
+ b1
* (x1
+ x0
);
1175 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1176 if (b1
>= 0.f
&& unit
->m_b1
>= 0) {
1179 ZXP(out
) = x0
+ b1
* (x1
- x0
);
1183 } else if (b1
<= 0.f
&& unit
->m_b1
<= 0) {
1186 ZXP(out
) = x0
+ b1
* (x1
+ x0
);
1193 ZXP(out
) = (1.f
- std::abs(b1
)) * x0
+ b1
* x1
;
1202 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1204 void Integrator_Ctor(Integrator
* unit
)
1206 //printf("Integrator_Reset\n");
1207 SETCALC(Integrator_next
);
1210 Integrator_next(unit
, 1);
1213 void Integrator_next(Integrator
* unit
, int inNumSamples
)
1215 //printf("Integrator_next_a\n");
1217 float *out
= ZOUT(0);
1219 float b1
= unit
->m_b1
;
1220 unit
->m_b1
= ZIN0(1);
1222 float y1
= unit
->m_y1
;
1224 if (b1
== unit
->m_b1
) {
1228 ZXP(out
) = y1
= y0
+ y1
;
1230 } else if (b1
== 0.f
) {
1238 ZXP(out
) = y1
= y0
+ b1
* y1
;
1242 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1245 ZXP(out
) = y1
= y0
+ b1
* y1
;
1249 unit
->m_y1
= zapgremlins(y1
);
1252 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1254 void Decay_Ctor(Decay
* unit
)
1256 SETCALC(Decay_next
);
1257 unit
->m_decayTime
= 0.f
;
1260 Decay_next(unit
, 1);
1263 void Decay_next(Decay
* unit
, int inNumSamples
)
1265 //printf("Decay_next_a\n");
1267 float *out
= ZOUT(0);
1269 float decayTime
= ZIN0(1);
1271 float y1
= unit
->m_y1
;
1272 float b1
= unit
->m_b1
;
1273 if (decayTime
== unit
->m_decayTime
) {
1282 ZXP(out
) = y1
= y0
+ b1
* y1
;
1286 unit
->m_b1
= decayTime
== 0.f
? 0.f
: exp(log001
/ (decayTime
* SAMPLERATE
));
1287 unit
->m_decayTime
= decayTime
;
1288 float b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1289 //printf("decayTime %g %g %g\n", unit->m_decayTime, next_b1, b1);
1292 ZXP(out
) = y1
= y0
+ b1
* y1
;
1296 unit
->m_y1
= zapgremlins(y1
);
1299 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1302 void Decay2_Ctor(Decay2
*unit
)
1304 SETCALC(Decay2_next
);
1306 float attackTime
= ZIN0(1);
1307 float decayTime
= ZIN0(2);
1308 unit
->m_b1a
= decayTime
== 0.f
? 0.f
: exp(log001
/ (decayTime
* SAMPLERATE
));
1309 unit
->m_b1b
= attackTime
== 0.f
? 0.f
: exp(log001
/ (attackTime
* SAMPLERATE
));
1310 unit
->m_decayTime
= decayTime
;
1311 unit
->m_attackTime
= attackTime
;
1319 void Decay2_next(Decay2
* unit
, int inNumSamples
)
1321 //printf("Decay2_next_a\n");
1323 float *out
= ZOUT(0);
1325 float attackTime
= ZIN0(1);
1326 float decayTime
= ZIN0(2);
1328 float y1a
= unit
->m_y1a
;
1329 float y1b
= unit
->m_y1b
;
1330 float b1a
= unit
->m_b1a
;
1331 float b1b
= unit
->m_b1b
;
1332 if (decayTime
== unit
->m_decayTime
&& attackTime
== unit
->m_attackTime
) {
1335 y1a
= y0
+ b1a
* y1a
;
1336 y1b
= y0
+ b1b
* y1b
;
1337 ZXP(out
) = y1a
- y1b
;
1340 unit
->m_decayTime
= decayTime
;
1341 unit
->m_attackTime
= attackTime
;
1342 float next_b1a
= decayTime
== 0.f
? 0.f
: exp(log001
/ (decayTime
* SAMPLERATE
));
1343 float next_b1b
= attackTime
== 0.f
? 0.f
: exp(log001
/ (attackTime
* SAMPLERATE
));
1344 unit
->m_decayTime
= decayTime
;
1345 float b1a_slope
= CALCSLOPE(next_b1a
, b1a
);
1346 float b1b_slope
= CALCSLOPE(next_b1b
, b1b
);
1347 unit
->m_b1a
= next_b1a
;
1348 unit
->m_b1b
= next_b1b
;
1351 y1a
= y0
+ b1a
* y1a
;
1352 y1b
= y0
+ b1b
* y1b
;
1353 ZXP(out
) = y1a
- y1b
;
1364 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1366 void LeakDC_next_i_4(LeakDC
* unit
, int inNumSamples
)
1368 float *out
= ZOUT(0);
1370 double b1
= unit
->m_b1
;
1371 double y1
= unit
->m_y1
;
1372 double x1
= unit
->m_x1
;
1374 LOOP1(inNumSamples
/4,
1375 double x00
= ZXP(in
);
1376 double x01
= ZXP(in
);
1377 double x02
= ZXP(in
);
1378 double x03
= ZXP(in
);
1379 ZXP(out
) = y1
= x00
- x1
+ b1
* y1
;
1380 ZXP(out
) = y1
= x01
- x00
+ b1
* y1
;
1381 ZXP(out
) = y1
= x02
- x01
+ b1
* y1
;
1382 ZXP(out
) = y1
= x03
- x02
+ b1
* y1
;
1387 unit
->m_y1
= zapgremlins(y1
);
1390 void LeakDC_next_i(LeakDC
* unit
, int inNumSamples
)
1392 float *out
= ZOUT(0);
1394 double b1
= unit
->m_b1
;
1395 double y1
= unit
->m_y1
;
1396 double x1
= unit
->m_x1
;
1399 double x0
= ZXP(in
);
1400 ZXP(out
) = y1
= x0
- x1
+ b1
* y1
;
1404 unit
->m_y1
= zapgremlins(y1
);
1407 void LeakDC_next(LeakDC
* unit
, int inNumSamples
)
1409 if (ZIN0(1) == unit
->m_b1
) {
1410 if ((inNumSamples
& 3) == 0)
1411 LeakDC_next_i_4(unit
, inNumSamples
);
1413 LeakDC_next_i(unit
, inNumSamples
);
1415 float *out
= ZOUT(0);
1417 double b1
= unit
->m_b1
;
1418 unit
->m_b1
= ZIN0(1);
1420 double y1
= unit
->m_y1
;
1421 double x1
= unit
->m_x1
;
1423 double b1_slope
= CALCSLOPE(unit
->m_b1
, b1
);
1425 double x0
= ZXP(in
);
1426 ZXP(out
) = y1
= x0
- x1
+ b1
* y1
;
1431 unit
->m_y1
= zapgremlins(y1
);
1436 void LeakDC_next_1(LeakDC
* unit
, int inNumSamples
)
1438 double b1
= unit
->m_b1
= ZIN0(1);
1440 double y1
= unit
->m_y1
;
1441 double x1
= unit
->m_x1
;
1443 double x0
= ZIN0(0);
1444 ZOUT0(0) = y1
= x0
- x1
+ b1
* y1
;
1448 unit
->m_y1
= zapgremlins(y1
);
1451 void LeakDC_Ctor(LeakDC
*unit
)
1453 //printf("LeakDC_Ctor\n");
1455 SETCALC(LeakDC_next_1
);
1457 if (INRATE(1) == calc_ScalarRate
) {
1458 if ((BUFLENGTH
& 3) == 0)
1459 SETCALC(LeakDC_next_i_4
);
1461 SETCALC(LeakDC_next_i
);
1463 SETCALC(LeakDC_next
);
1466 unit
->m_x1
= ZIN0(0);
1468 LeakDC_next_1(unit
, 1);
1472 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1474 void TwoPole_Ctor(TwoPole
*unit
)
1476 //printf("TwoPole_Reset\n");
1477 SETCALC(TwoPole_next
);
1483 unit
->m_reson
= 0.f
;
1485 TwoPole_next(unit
, 1);
1490 void TwoPole_next(TwoPole
* unit
, int inNumSamples
)
1492 //printf("TwoPole_next_a\n");
1494 float *out
= ZOUT(0);
1496 float freq
= ZIN0(1);
1497 float reson
= ZIN0(2);
1500 float y1
= unit
->m_y1
;
1501 float y2
= unit
->m_y2
;
1503 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
1504 float b1
= unit
->m_b1
;
1505 float b2
= unit
->m_b2
;
1506 float b1_next
= 2.f
* reson
* cos(freq
* unit
->mRate
->mRadiansPerSample
);
1507 float b2_next
= -(reson
* reson
);
1508 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
1509 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
1510 LOOP(unit
->mRate
->mFilterLoops
,
1511 ZXP(out
) = y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
1512 ZXP(out
) = y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
1513 ZXP(out
) = y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
1518 LOOP(unit
->mRate
->mFilterRemain
,
1519 ZXP(out
) = y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
1524 unit
->m_freq
= freq
;
1525 unit
->m_reson
= reson
;
1529 float b1
= unit
->m_b1
;
1530 float b2
= unit
->m_b2
;
1531 LOOP(unit
->mRate
->mFilterLoops
,
1532 ZXP(out
) = y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
1533 ZXP(out
) = y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
1534 ZXP(out
) = y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
1536 LOOP(unit
->mRate
->mFilterRemain
,
1537 ZXP(out
) = y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
1542 unit
->m_y1
= zapgremlins(y1
);
1543 unit
->m_y2
= zapgremlins(y2
);
1547 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1550 void TwoZero_Ctor(TwoZero
* unit
)
1552 //printf("TwoZero_Reset\n");
1553 SETCALC(TwoZero_next
);
1559 unit
->m_reson
= 0.f
;
1561 TwoZero_next(unit
, 1);
1565 void TwoZero_next(TwoZero
* unit
, int inNumSamples
)
1567 //printf("TwoZero_next\n");
1569 float *out
= ZOUT(0);
1571 float freq
= ZIN0(1);
1572 float reson
= ZIN0(2);
1575 float x1
= unit
->m_x1
;
1576 float x2
= unit
->m_x2
;
1578 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
1579 float b1
= unit
->m_b1
;
1580 float b2
= unit
->m_b2
;
1581 float b1_next
= -2.f
* reson
* cos(freq
* unit
->mRate
->mRadiansPerSample
);
1582 float b2_next
= (reson
* reson
);
1583 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
1584 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
1585 LOOP(unit
->mRate
->mFilterLoops
,
1587 ZXP(out
) = x0
+ b1
* x1
+ b2
* x2
;
1589 ZXP(out
) = x2
+ b1
* x0
+ b2
* x1
;
1591 ZXP(out
) = x1
+ b1
* x2
+ b2
* x0
;
1596 LOOP(unit
->mRate
->mFilterRemain
,
1598 ZXP(out
) = x0
+ b1
* x1
+ b2
* x2
;
1603 unit
->m_freq
= freq
;
1604 unit
->m_reson
= reson
;
1608 float b1
= unit
->m_b1
;
1609 float b2
= unit
->m_b2
;
1610 LOOP(unit
->mRate
->mFilterLoops
,
1612 ZXP(out
) = x0
+ b1
* x1
+ b2
* x2
;
1614 ZXP(out
) = x2
+ b1
* x0
+ b2
* x1
;
1616 ZXP(out
) = x1
+ b1
* x2
+ b2
* x0
;
1618 LOOP(unit
->mRate
->mFilterRemain
,
1620 ZXP(out
) = x0
+ b1
* x1
+ b2
* x2
;
1630 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1633 void APF_Ctor(APF
* unit
)
1635 //printf("APF_Reset\n");
1644 unit
->m_reson
= 0.f
;
1651 void APF_next(APF
* unit
, int inNumSamples
)
1653 //printf("APF_next_a\n");
1655 float *out
= ZOUT(0);
1657 float freq
= ZIN0(1);
1658 float reson
= ZIN0(2);
1661 float y1
= unit
->m_y1
;
1662 float y2
= unit
->m_y2
;
1663 float x1
= unit
->m_x1
;
1664 float x2
= unit
->m_x2
;
1666 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
1667 float b1
= unit
->m_b1
;
1668 float b2
= unit
->m_b2
;
1669 float b1_next
= 2.f
* reson
* cos(freq
* unit
->mRate
->mRadiansPerSample
);
1670 float b2_next
= -(reson
* reson
);
1671 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
1672 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
1673 LOOP(unit
->mRate
->mFilterLoops
,
1675 ZXP(out
) = y0
= x0
+ b1
* (y1
- x1
) + b2
* (y2
- x2
);
1677 ZXP(out
) = y2
= x2
+ b1
* (y0
- x0
) + b2
* (y2
- x1
);
1679 ZXP(out
) = y1
= x1
+ b1
* (y2
- x2
) + b2
* (y2
- x0
);
1684 LOOP(unit
->mRate
->mFilterRemain
,
1686 ZXP(out
) = y0
= x0
+ b1
* (y1
- x1
) + b2
* (y2
- x2
);
1693 unit
->m_freq
= freq
;
1694 unit
->m_reson
= reson
;
1698 float b1
= unit
->m_b1
;
1699 float b2
= unit
->m_b2
;
1700 LOOP(unit
->mRate
->mFilterLoops
,
1702 ZXP(out
) = y0
= x0
+ b1
* (y1
- x1
) + b2
* (y2
- x2
);
1704 ZXP(out
) = y2
= x2
+ b1
* (y0
- x0
) + b2
* (y2
- x1
);
1706 ZXP(out
) = y1
= x1
+ b1
* (y2
- x2
) + b2
* (y2
- x0
);
1708 LOOP(unit
->mRate
->mFilterRemain
,
1710 ZXP(out
) = y0
= x0
+ b1
* (y1
- x1
) + b2
* (y2
- x2
);
1717 unit
->m_y1
= zapgremlins(y1
);
1718 unit
->m_y2
= zapgremlins(y2
);
1723 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1725 void LPZ1_Ctor(LPZ1
* unit
)
1727 //printf("LPZ1_Reset\n");
1729 unit
->m_x1
= ZIN0(0);
1734 void LPZ1_next(LPZ1
* unit
, int inNumSamples
)
1736 //printf("LPZ1_next_a\n");
1738 float *out
= ZOUT(0);
1742 float x1
= unit
->m_x1
;
1744 LOOP(inNumSamples
>> 2,
1746 ZXP(out
) = 0.5f
* (x0
+ x1
);
1748 ZXP(out
) = 0.5f
* (x1
+ x0
);
1750 ZXP(out
) = 0.5f
* (x0
+ x1
);
1752 ZXP(out
) = 0.5f
* (x1
+ x0
);
1754 LOOP(inNumSamples
& 3,
1756 ZXP(out
) = 0.5f
* (x0
+ x1
);
1763 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1766 void HPZ1_Ctor(HPZ1
* unit
)
1768 //printf("HPZ1_Reset\n");
1770 unit
->m_x1
= ZIN0(0);
1775 void HPZ1_next(HPZ1
* unit
, int inNumSamples
)
1777 //printf("HPZ1_next\n");
1779 float *out
= ZOUT(0);
1783 float x1
= unit
->m_x1
;
1785 LOOP(inNumSamples
>> 2,
1787 ZXP(out
) = 0.5f
* (x0
- x1
);
1789 ZXP(out
) = 0.5f
* (x1
- x0
);
1791 ZXP(out
) = 0.5f
* (x0
- x1
);
1793 ZXP(out
) = 0.5f
* (x1
- x0
);
1795 LOOP(inNumSamples
& 3,
1797 //printf("%d %d %g %g\n", this, inNumSamples, x0, x1);
1798 ZXP(out
) = 0.5f
* (x0
- x1
);
1805 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1807 void Slope_Ctor(Slope
* unit
)
1809 //printf("Slope_Reset\n");
1810 SETCALC(Slope_next
);
1811 unit
->m_x1
= ZIN0(0);
1812 //printf("Slope_Reset %g\n", unit->m_x1);
1813 Slope_next(unit
, 1);
1817 void Slope_next(Slope
* unit
, int inNumSamples
)
1819 //printf("Slope_next_a %g\n", unit->m_x1);
1821 float *out
= ZOUT(0);
1824 float x1
= unit
->m_x1
;
1826 float sr
= SAMPLERATE
;
1829 ZXP(out
) = sr
* (x0
- x1
);
1836 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1838 void Delay1_Ctor(Delay1
* unit
)
1840 //printf("Delay1_Reset\n");
1841 SETCALC(Delay1_next
);
1842 unit
->m_x1
= ZIN0(0);
1843 Delay1_next(unit
, 1);
1847 void Delay1_next(Delay1
* unit
, int inNumSamples
)
1849 //printf("Delay1_next_a\n");
1851 float *out
= ZOUT(0);
1855 float x1
= unit
->m_x1
;
1857 LOOP(inNumSamples
>> 2,
1867 LOOP(inNumSamples
& 3,
1876 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1878 void Flip_Ctor(Flip
* unit
)
1880 if (unit
->mBufLength
& 1) {
1881 SETCALC(Flip_next_odd
);
1882 Flip_next_odd(unit
, 1);
1884 SETCALC(Flip_next_even
);
1890 void Flip_next_even(Flip
* unit
, int inNumSamples
)
1892 float *out
= ZOUT(0);
1895 LOOP(inNumSamples
>> 1,
1896 ZXP(out
) = -ZXP(in
);
1901 void Flip_next_odd(Flip
* unit
, int inNumSamples
)
1903 float *out
= ZOUT(0);
1906 if (unit
->mWorld
->mBufCounter
& 1) {
1908 LOOP(inNumSamples
>> 1,
1909 ZXP(out
) = -ZXP(in
);
1913 LOOP(inNumSamples
>> 1,
1914 ZXP(out
) = -ZXP(in
);
1917 ZXP(out
) = -ZXP(in
);
1921 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1923 void Delay2_Ctor(Delay2
* unit
)
1925 SETCALC(Delay2_next
);
1926 unit
->m_x1
= ZIN0(0);
1931 void Delay2_next(Delay2
* unit
, int inNumSamples
)
1933 float *out
= ZOUT(0);
1937 float x1
= unit
->m_x1
;
1938 float x2
= unit
->m_x2
;
1940 LOOP(unit
->mRate
->mFilterLoops
,
1948 LOOP(unit
->mRate
->mFilterRemain
,
1959 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1962 void LPZ2_Ctor(LPZ2
* unit
)
1964 //printf("LPZ2_Reset\n");
1966 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
1973 void LPZ2_next(LPZ2
* unit
, int inNumSamples
)
1975 //printf("LPZ2_next_a\n");
1977 float *out
= ZOUT(0);
1981 float x1
= unit
->m_x1
;
1982 float x2
= unit
->m_x2
;
1984 LOOP(unit
->mRate
->mFilterLoops
,
1986 ZXP(out
) = (x0
+ 2.f
* x1
+ x2
) * 0.25f
;
1988 ZXP(out
) = (x2
+ 2.f
* x0
+ x1
) * 0.25f
;
1990 ZXP(out
) = (x1
+ 2.f
* x2
+ x0
) * 0.25f
;
1992 LOOP(unit
->mRate
->mFilterRemain
,
1994 ZXP(out
) = (x0
+ 2.f
* x1
+ x2
) * 0.25f
;
2003 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2005 void HPZ2_Ctor(HPZ2
* unit
)
2007 //printf("HPZ2_Reset\n");
2009 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
2016 void HPZ2_next(HPZ2
* unit
, int inNumSamples
)
2018 //printf("HPZ2_next_a\n");
2020 float *out
= ZOUT(0);
2024 float x1
= unit
->m_x1
;
2025 float x2
= unit
->m_x2
;
2027 LOOP(unit
->mRate
->mFilterLoops
,
2029 ZXP(out
) = (x0
- 2.f
* x1
+ x2
) * 0.25f
;
2031 ZXP(out
) = (x2
- 2.f
* x0
+ x1
) * 0.25f
;
2033 ZXP(out
) = (x1
- 2.f
* x2
+ x0
) * 0.25f
;
2035 LOOP(unit
->mRate
->mFilterRemain
,
2037 ZXP(out
) = (x0
- 2.f
* x1
+ x2
) * 0.25f
;
2046 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2048 void BPZ2_Ctor(BPZ2
* unit
)
2050 //printf("BPZ2_Reset\n");
2052 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
2059 void BPZ2_next(BPZ2
* unit
, int inNumSamples
)
2061 //printf("BPZ2_next_a\n");
2063 float *out
= ZOUT(0);
2067 float x1
= unit
->m_x1
;
2068 float x2
= unit
->m_x2
;
2070 LOOP(unit
->mRate
->mFilterLoops
,
2072 ZXP(out
) = (x0
- x2
) * 0.5f
;
2074 ZXP(out
) = (x2
- x1
) * 0.5f
;
2076 ZXP(out
) = (x1
- x0
) * 0.5f
;
2078 LOOP(unit
->mRate
->mFilterRemain
,
2080 ZXP(out
) = (x0
- x2
) * 0.5f
;
2089 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2091 void BRZ2_Ctor(BRZ2
* unit
)
2093 //printf("BRZ2_Reset\n");
2095 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
2102 void BRZ2_next(BRZ2
* unit
, int inNumSamples
)
2104 //printf("BRZ2_next_a\n");
2106 float *out
= ZOUT(0);
2110 float x1
= unit
->m_x1
;
2111 float x2
= unit
->m_x2
;
2113 LOOP(unit
->mRate
->mFilterLoops
,
2115 ZXP(out
) = (x0
+ x2
) * 0.5f
;
2117 ZXP(out
) = (x2
+ x1
) * 0.5f
;
2119 ZXP(out
) = (x1
+ x0
) * 0.5f
;
2121 LOOP(unit
->mRate
->mFilterRemain
,
2123 ZXP(out
) = (x0
+ x2
) * 0.5f
;
2132 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2134 void Slew_Ctor(Slew
* unit
)
2136 //printf("Slew_Reset\n");
2138 unit
->mLevel
= ZIN0(0);
2143 void Slew_next(Slew
* unit
, int inNumSamples
)
2145 //printf("Slew_next_a\n");
2147 float sampleDur
= unit
->mRate
->mSampleDur
;
2148 float *out
= ZOUT(0);
2150 float upf
= ZIN0(1) * sampleDur
;
2151 float dnf
= 0.f
- ZIN0(2) * sampleDur
;
2152 float level
= unit
->mLevel
;
2154 float slope
= ZXP(in
) - level
;
2155 level
+= sc_clip(slope
, dnf
, upf
);
2158 unit
->mLevel
= level
;
2161 /*void Slew_next_1(Slew* unit, int inNumSamples)
2163 //printf("Slew_next_a\n");
2165 float *out = ZOUT(0);
2167 float upf = ZIN0(1);
2168 float dnf = ZIN0(2);
2169 float level = unit->mLevel;
2170 float slope = ZXP(in) - level;
2171 if (slope > upf) slope = upf;
2172 else if (slope < dnf) slope = dnf;
2175 unit->mLevel = level;
2179 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2181 void RLPF_Ctor(RLPF
* unit
)
2183 //printf("RLPF_Reset\n");
2184 if (unit
->mBufLength
== 1) {
2185 SETCALC(RLPF_next_1
);
2196 unit
->m_reson
= 0.f
;
2197 RLPF_next_1(unit
, 1);
2201 void RLPF_next(RLPF
* unit
, int inNumSamples
)
2203 //printf("RLPF_next\n");
2205 float *out
= ZOUT(0);
2207 float freq
= ZIN0(1);
2208 float reson
= ZIN0(2);
2211 float y1
= unit
->m_y1
;
2212 float y2
= unit
->m_y2
;
2213 float a0
= unit
->m_a0
;
2214 float b1
= unit
->m_b1
;
2215 float b2
= unit
->m_b2
;
2217 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2219 float qres
= sc_max(0.001, reson
);
2220 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2222 float D
= tan(pfreq
* qres
* 0.5);
2223 float C
= ((1.f
-D
)/(1.f
+D
));
2224 float cosf
= cos(pfreq
);
2226 float next_b1
= (1.f
+ C
) * cosf
;
2228 float next_a0
= (1.f
+ C
- next_b1
) * .25;
2229 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2231 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2232 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2233 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2234 LOOP(unit
->mRate
->mFilterLoops
,
2235 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2236 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2238 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2239 ZXP(out
) = y2
+ 2.f
* y0
+ y1
;
2241 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2242 ZXP(out
) = y1
+ 2.f
* y2
+ y0
;
2248 LOOP(unit
->mRate
->mFilterRemain
,
2249 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2250 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2255 unit
->m_freq
= freq
;
2256 unit
->m_reson
= reson
;
2261 LOOP(unit
->mRate
->mFilterLoops
,
2262 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2263 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2265 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2266 ZXP(out
) = y2
+ 2.f
* y0
+ y1
;
2268 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2269 ZXP(out
) = y1
+ 2.f
* y2
+ y0
;
2271 LOOP(unit
->mRate
->mFilterRemain
,
2272 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2273 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2278 unit
->m_y1
= zapgremlins(y1
);
2279 unit
->m_y2
= zapgremlins(y2
);
2283 void RLPF_next_1(RLPF
* unit
, int inNumSamples
)
2285 //printf("RLPF_next_1\n");
2288 float freq
= ZIN0(1);
2289 float reson
= ZIN0(2);
2292 float y1
= unit
->m_y1
;
2293 float y2
= unit
->m_y2
;
2294 float a0
= unit
->m_a0
;
2295 float b1
= unit
->m_b1
;
2296 float b2
= unit
->m_b2
;
2298 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2299 float qres
= sc_max(0.001f
, reson
);
2300 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2302 float D
= tan(pfreq
* qres
* 0.5f
);
2303 float C
= ((1.f
-D
)/(1.f
+D
));
2304 float cosf
= cos(pfreq
);
2306 b1
= (1.f
+ C
) * cosf
;
2308 a0
= (1.f
+ C
- b1
) * .25f
;
2310 y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2311 ZOUT0(0) = y0
+ 2.f
* y1
+ y2
;
2315 unit
->m_freq
= freq
;
2316 unit
->m_reson
= reson
;
2321 y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2322 ZOUT0(0) = y0
+ 2.f
* y1
+ y2
;
2326 unit
->m_y1
= zapgremlins(y1
);
2327 unit
->m_y2
= zapgremlins(y2
);
2332 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2334 void RHPF_Ctor(RHPF
* unit
)
2336 if (unit
->mBufLength
== 1)
2337 SETCALC(RHPF_next_1
);
2347 unit
->m_reson
= 0.f
;
2348 RHPF_next_1(unit
, 1);
2352 void RHPF_next(RHPF
* unit
, int inNumSamples
)
2354 //printf("RHPFs_next\n");
2356 float *out
= ZOUT(0);
2358 float freq
= ZIN0(1);
2359 float reson
= ZIN0(2);
2361 double y1
= unit
->m_y1
;
2362 double y2
= unit
->m_y2
;
2363 double a0
= unit
->m_a0
;
2364 double b1
= unit
->m_b1
;
2365 double b2
= unit
->m_b2
;
2367 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2368 float qres
= sc_max(0.001f
, reson
);
2369 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2371 double D
= tan(pfreq
* qres
* 0.5f
);
2372 double C
= ((1.-D
)/(1.+D
));
2373 double cosf
= cos(pfreq
);
2375 double next_b1
= (1. + C
) * cosf
;
2376 double next_b2
= -C
;
2377 double next_a0
= (1. + C
+ next_b1
) * .25;
2379 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2381 double a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2382 double b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2383 double b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2384 LOOP(unit
->mRate
->mFilterLoops
,
2385 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2386 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2388 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2389 ZXP(out
) = y2
- 2.f
* y0
+ y1
;
2391 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2392 ZXP(out
) = y1
- 2.f
* y2
+ y0
;
2398 LOOP(unit
->mRate
->mFilterRemain
,
2399 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2400 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2405 unit
->m_freq
= freq
;
2406 unit
->m_reson
= reson
;
2411 LOOP(unit
->mRate
->mFilterLoops
,
2412 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2413 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2415 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2416 ZXP(out
) = y2
- 2.f
* y0
+ y1
;
2418 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2419 ZXP(out
) = y1
- 2.f
* y2
+ y0
;
2421 LOOP(unit
->mRate
->mFilterRemain
,
2422 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2423 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2428 unit
->m_y1
= zapgremlins(y1
);
2429 unit
->m_y2
= zapgremlins(y2
);
2432 void RHPF_next_1(RHPF
* unit
, int inNumSamples
)
2434 //printf("RHPFs_next_1\n");
2437 float freq
= ZIN0(1);
2438 float reson
= ZIN0(2);
2440 double y1
= unit
->m_y1
;
2441 double y2
= unit
->m_y2
;
2442 double a0
= unit
->m_a0
;
2443 double b1
= unit
->m_b1
;
2444 double b2
= unit
->m_b2
;
2446 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2447 float qres
= sc_max(0.001f
, reson
);
2448 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2450 double D
= tan(pfreq
* qres
* 0.5f
);
2451 double C
= ((1.-D
)/(1.+D
));
2452 double cosf
= cos(pfreq
);
2454 b1
= (1. + C
) * cosf
;
2456 a0
= (1. + C
+ b1
) * .25;
2458 double y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2459 ZOUT0(0) = y0
- 2.f
* y1
+ y2
;
2463 unit
->m_freq
= freq
;
2464 unit
->m_reson
= reson
;
2469 double y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2470 ZOUT0(0) = y0
- 2.f
* y1
+ y2
;
2474 unit
->m_y1
= zapgremlins(y1
);
2475 unit
->m_y2
= zapgremlins(y2
);
2479 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2481 void LPF_Ctor(LPF
* unit
)
2483 if (unit
->mBufLength
== 1)
2484 SETCALC(LPF_next_1
);
2494 LPF_next_1(unit
, 1);
2498 void LPF_next(LPF
* unit
, int inNumSamples
)
2500 //printf("LPF_next\n");
2502 float *out
= ZOUT(0);
2504 float freq
= ZIN0(1);
2507 float y1
= unit
->m_y1
;
2508 float y2
= unit
->m_y2
;
2509 float a0
= unit
->m_a0
;
2510 float b1
= unit
->m_b1
;
2511 float b2
= unit
->m_b2
;
2513 if (freq
!= unit
->m_freq
) {
2515 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2517 float C
= 1.f
/ tan(pfreq
);
2519 float sqrt2C
= C
* sqrt2_f
;
2520 float next_a0
= 1.f
/ (1.f
+ sqrt2C
+ C2
);
2521 float next_b1
= -2.f
* (1.f
- C2
) * next_a0
;
2522 float next_b2
= -(1.f
- sqrt2C
+ C2
) * next_a0
;
2524 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2526 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2527 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2528 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2529 LOOP(unit
->mRate
->mFilterLoops
,
2530 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2531 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2533 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2534 ZXP(out
) = a0
* (y2
+ 2.f
* y0
+ y1
);
2536 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2537 ZXP(out
) = a0
* (y1
+ 2.f
* y2
+ y0
);
2543 LOOP(unit
->mRate
->mFilterRemain
,
2544 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2545 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2550 unit
->m_freq
= freq
;
2555 LOOP(unit
->mRate
->mFilterLoops
,
2556 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2557 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2559 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2560 ZXP(out
) = a0
* (y2
+ 2.f
* y0
+ y1
);
2562 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2563 ZXP(out
) = a0
* (y1
+ 2.f
* y2
+ y0
);
2565 LOOP(unit
->mRate
->mFilterRemain
,
2566 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2567 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2572 unit
->m_y1
= zapgremlins(y1
);
2573 unit
->m_y2
= zapgremlins(y2
);
2576 void LPF_next_1(LPF
* unit
, int inNumSamples
)
2578 //printf("LPF_next\n");
2580 float freq
= ZIN0(1);
2583 float y1
= unit
->m_y1
;
2584 float y2
= unit
->m_y2
;
2585 float a0
= unit
->m_a0
;
2586 float b1
= unit
->m_b1
;
2587 float b2
= unit
->m_b2
;
2589 if (freq
!= unit
->m_freq
) {
2591 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2593 float C
= 1.f
/ tan(pfreq
);
2595 float sqrt2C
= C
* sqrt2_f
;
2596 a0
= 1.f
/ (1.f
+ sqrt2C
+ C2
);
2597 b1
= -2.f
* (1.f
- C2
) * a0
;
2598 b2
= -(1.f
- sqrt2C
+ C2
) * a0
;
2600 y0
= in
+ b1
* y1
+ b2
* y2
;
2601 ZOUT0(0) = a0
* (y0
+ 2.f
* y1
+ y2
);
2605 unit
->m_freq
= freq
;
2611 y0
= in
+ b1
* y1
+ b2
* y2
;
2612 ZOUT0(0) = a0
* (y0
+ 2.f
* y1
+ y2
);
2617 unit
->m_y1
= zapgremlins(y1
);
2618 unit
->m_y2
= zapgremlins(y2
);
2622 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2624 void HPF_Ctor(HPF
* unit
)
2626 if (unit
->mBufLength
== 1)
2627 SETCALC(HPF_next_1
);
2635 unit
->m_freq
= -1e6f
;
2637 HPF_next_1(unit
, 1);
2641 void HPF_next(HPF
* unit
, int inNumSamples
)
2643 float *out
= ZOUT(0);
2645 float freq
= ZIN0(1);
2647 double y1
= unit
->m_y1
;
2648 double y2
= unit
->m_y2
;
2649 double a0
= unit
->m_a0
;
2650 double b1
= unit
->m_b1
;
2651 double b2
= unit
->m_b2
;
2653 if (freq
!= unit
->m_freq
) {
2654 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2656 double C
= tan(pfreq
);
2658 double sqrt2C
= C
* sqrt2_f
;
2659 double next_a0
= 1. / (1. + sqrt2C
+ C2
);
2660 double next_b1
= 2. * (1. - C2
) * next_a0
;
2661 double next_b2
= -(1. - sqrt2C
+ C2
) * next_a0
;
2663 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2665 double a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2666 double b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2667 double b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2668 LOOP(unit
->mRate
->mFilterLoops
,
2669 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2670 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2672 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2673 ZXP(out
) = a0
* (y2
- 2. * y0
+ y1
);
2675 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2676 ZXP(out
) = a0
* (y1
- 2. * y2
+ y0
);
2682 LOOP(unit
->mRate
->mFilterRemain
,
2683 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2684 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2689 unit
->m_freq
= freq
;
2694 LOOP(unit
->mRate
->mFilterLoops
,
2695 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2696 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2698 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2699 ZXP(out
) = a0
* (y2
- 2. * y0
+ y1
);
2701 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2702 ZXP(out
) = a0
* (y1
- 2. * y2
+ y0
);
2704 LOOP(unit
->mRate
->mFilterRemain
,
2705 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2706 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2711 unit
->m_y1
= zapgremlins(y1
);
2712 unit
->m_y2
= zapgremlins(y2
);
2715 void HPF_next_1(HPF
* unit
, int inNumSamples
)
2717 double in
= ZIN0(0);
2718 double freq
= ZIN0(1);
2720 double y1
= unit
->m_y1
;
2721 double y2
= unit
->m_y2
;
2722 double a0
= unit
->m_a0
;
2723 double b1
= unit
->m_b1
;
2724 double b2
= unit
->m_b2
;
2726 if (freq
!= unit
->m_freq
) {
2727 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5f
;
2729 double C
= tan(pfreq
);
2731 double sqrt2C
= C
* sqrt2_f
;
2732 a0
= 1. / (1. + sqrt2C
+ C2
);
2733 b1
= 2. * (1. - C2
) * a0
;
2734 b2
= -(1. - sqrt2C
+ C2
) * a0
;
2736 double y0
= in
+ b1
* y1
+ b2
* y2
;
2737 ZOUT0(0) = a0
* (y0
- 2. * y1
+ y2
);
2741 unit
->m_freq
= freq
;
2746 double y0
= in
+ b1
* y1
+ b2
* y2
;
2747 ZOUT0(0) = a0
* (y0
- 2. * y1
+ y2
);
2752 unit
->m_y1
= zapgremlins(y1
);
2753 unit
->m_y2
= zapgremlins(y2
);
2756 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2758 void BPF_Ctor(BPF
* unit
)
2760 //printf("BPF_Reset\n");
2761 if (unit
->mBufLength
== 1) {
2762 SETCALC(BPF_next_1
);
2774 BPF_next_1(unit
, 1);
2777 void BPF_next(BPF
* unit
, int inNumSamples
)
2779 //printf("BPF_next\n");
2781 float *out
= ZOUT(0);
2783 float freq
= ZIN0(1);
2787 float y1
= unit
->m_y1
;
2788 float y2
= unit
->m_y2
;
2789 float a0
= unit
->m_a0
;
2790 float b1
= unit
->m_b1
;
2791 float b2
= unit
->m_b2
;
2793 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2795 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2796 float pbw
= bw
* pfreq
* 0.5f
;
2798 float C
= 1.f
/ tan(pbw
);
2799 float D
= 2.f
* cos(pfreq
);
2801 float next_a0
= 1.f
/ (1.f
+ C
);
2802 float next_b1
= C
* D
* next_a0
;
2803 float next_b2
= (1.f
- C
) * next_a0
;
2805 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2806 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2807 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2808 LOOP(unit
->mRate
->mFilterLoops
,
2809 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2810 ZXP(out
) = a0
* (y0
- y2
);
2812 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2813 ZXP(out
) = a0
* (y2
- y1
);
2815 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2816 ZXP(out
) = a0
* (y1
- y0
);
2822 LOOP(unit
->mRate
->mFilterRemain
,
2823 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2824 ZXP(out
) = a0
* (y0
- y2
);
2829 unit
->m_freq
= freq
;
2835 LOOP(unit
->mRate
->mFilterLoops
,
2836 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2837 ZXP(out
) = a0
* (y0
- y2
);
2839 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2840 ZXP(out
) = a0
* (y2
- y1
);
2842 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2843 ZXP(out
) = a0
* (y1
- y0
);
2845 LOOP(unit
->mRate
->mFilterRemain
,
2846 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2847 ZXP(out
) = a0
* (y0
- y2
);
2852 unit
->m_y1
= zapgremlins(y1
);
2853 unit
->m_y2
= zapgremlins(y2
);
2856 void BPF_next_1(BPF
* unit
, int inNumSamples
)
2858 //printf("BPF_next_1\n");
2861 float freq
= ZIN0(1);
2865 float y1
= unit
->m_y1
;
2866 float y2
= unit
->m_y2
;
2867 float a0
= unit
->m_a0
;
2868 float b1
= unit
->m_b1
;
2869 float b2
= unit
->m_b2
;
2871 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2873 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2874 float pbw
= bw
* pfreq
* 0.5;
2876 float C
= 1.f
/ tan(pbw
);
2877 float D
= 2.f
* cos(pfreq
);
2879 float a0
= 1.f
/ (1.f
+ C
);
2880 float b1
= C
* D
* a0
;
2881 float b2
= (1.f
- C
) * a0
;
2883 y0
= in
+ b1
* y1
+ b2
* y2
;
2884 ZOUT0(0) = a0
* (y0
- y2
);
2888 unit
->m_freq
= freq
;
2894 y0
= in
+ b1
* y1
+ b2
* y2
;
2895 ZOUT0(0) = a0
* (y0
- y2
);
2899 unit
->m_y1
= zapgremlins(y1
);
2900 unit
->m_y2
= zapgremlins(y2
);
2904 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2906 void BRF_Ctor(BRF
* unit
)
2908 //printf("BRF_Reset\n");
2909 if (unit
->mBufLength
== 1) {
2910 SETCALC(BRF_next_1
);
2921 BRF_next_1(unit
, 1);
2925 void BRF_next(BRF
* unit
, int inNumSamples
)
2927 //printf("BRF_next\n");
2929 float *out
= ZOUT(0);
2931 float freq
= ZIN0(1);
2936 float y1
= unit
->m_y1
;
2937 float y2
= unit
->m_y2
;
2938 float a0
= unit
->m_a0
;
2939 float a1
= unit
->m_a1
;
2940 float b2
= unit
->m_b2
;
2942 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2943 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2944 float pbw
= bw
* pfreq
* 0.5f
;
2947 float D
= 2.f
* cos(pfreq
);
2949 float next_a0
= 1.f
/ (1.f
+ C
);
2950 float next_a1
= -D
* next_a0
;
2951 float next_b2
= (1.f
- C
) * next_a0
;
2953 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2954 float a1_slope
= (next_a1
- a1
) * unit
->mRate
->mFilterSlope
;
2955 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2957 LOOP(unit
->mRate
->mFilterLoops
,
2959 y0
= ZXP(in
) - ay
- b2
* y2
;
2960 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
2963 y2
= ZXP(in
) - ay
- b2
* y1
;
2964 ZXP(out
) = a0
* (y2
+ y1
) + ay
;
2967 y1
= ZXP(in
) - ay
- b2
* y0
;
2968 ZXP(out
) = a0
* (y1
+ y0
) + ay
;
2974 LOOP(unit
->mRate
->mFilterRemain
,
2976 y0
= ZXP(in
) - ay
- b2
* y2
;
2977 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
2982 unit
->m_freq
= freq
;
2988 LOOP(unit
->mRate
->mFilterLoops
,
2990 y0
= ZXP(in
) - ay
- b2
* y2
;
2991 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
2994 y2
= ZXP(in
) - ay
- b2
* y1
;
2995 ZXP(out
) = a0
* (y2
+ y1
) + ay
;
2998 y1
= ZXP(in
) - ay
- b2
* y0
;
2999 ZXP(out
) = a0
* (y1
+ y0
) + ay
;
3001 LOOP(unit
->mRate
->mFilterRemain
,
3003 y0
= ZXP(in
) - ay
- b2
* y2
;
3004 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
3009 unit
->m_y1
= zapgremlins(y1
);
3010 unit
->m_y2
= zapgremlins(y2
);
3015 void BRF_next_1(BRF
* unit
, int inNumSamples
)
3017 //printf("BRF_next_1\n");
3020 float freq
= ZIN0(1);
3025 float y1
= unit
->m_y1
;
3026 float y2
= unit
->m_y2
;
3027 float a0
= unit
->m_a0
;
3028 float a1
= unit
->m_a1
;
3029 float b2
= unit
->m_b2
;
3031 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
3032 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3033 float pbw
= bw
* pfreq
* 0.5f
;
3036 float D
= 2.f
* cos(pfreq
);
3038 float a0
= 1.f
/ (1.f
+ C
);
3040 float b2
= (1.f
- C
) * a0
;
3043 y0
= in
- ay
- b2
* y2
;
3044 ZOUT0(0) = a0
* (y0
+ y2
) + ay
;
3048 unit
->m_freq
= freq
;
3056 y0
= in
- ay
- b2
* y2
;
3057 ZOUT0(0) = a0
* (y0
+ y2
) + ay
;
3062 unit
->m_y1
= zapgremlins(y1
);
3063 unit
->m_y2
= zapgremlins(y2
);
3067 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3069 void MidEQ_Ctor(MidEQ
* unit
)
3071 //printf("MidEQ_Reset\n");
3072 SETCALC(MidEQ_next
);
3082 MidEQ_next(unit
, 1);
3087 void MidEQ_next(MidEQ
* unit
, int inNumSamples
)
3089 //printf("MidEQ_next\n");
3091 float *out
= ZOUT(0);
3093 float freq
= ZIN0(1);
3098 float y1
= unit
->m_y1
;
3099 float y2
= unit
->m_y2
;
3100 float a0
= unit
->m_a0
;
3101 float b1
= unit
->m_b1
;
3102 float b2
= unit
->m_b2
;
3103 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
|| db
!= unit
->m_db
) {
3105 float amp
= sc_dbamp(db
) - 1.0f
;
3106 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3107 float pbw
= bw
* pfreq
* 0.5f
;
3109 float C
= 1.f
/ tan(pbw
);
3110 float D
= 2.f
* cos(pfreq
);
3112 float next_a0
= 1.f
/ (1.f
+ C
);
3113 float next_b1
= C
* D
* next_a0
;
3114 float next_b2
= (1.f
- C
) * next_a0
;
3116 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
3117 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
3118 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
3120 LOOP(unit
->mRate
->mFilterLoops
,
3122 y0
= zin
+ b1
* y1
+ b2
* y2
;
3123 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3126 y2
= zin
+ b1
* y0
+ b2
* y1
;
3127 ZXP(out
) = zin
+ a0
* (y2
- y1
);
3130 y1
= zin
+ b1
* y2
+ b2
* y0
;
3131 ZXP(out
) = zin
+ a0
* (y1
- y0
);
3137 LOOP(unit
->mRate
->mFilterRemain
,
3139 y0
= zin
+ b1
* y1
+ b2
* y2
;
3140 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3145 unit
->m_freq
= freq
;
3153 LOOP(unit
->mRate
->mFilterLoops
,
3155 y0
= zin
+ b1
* y1
+ b2
* y2
;
3156 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3159 y2
= zin
+ b1
* y0
+ b2
* y1
;
3160 ZXP(out
) = zin
+ a0
* (y2
- y1
);
3163 y1
= zin
+ b1
* y2
+ b2
* y0
;
3164 ZXP(out
) = zin
+ a0
* (y1
- y0
);
3166 LOOP(unit
->mRate
->mFilterRemain
,
3168 y0
= zin
+ b1
* y1
+ b2
* y2
;
3169 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3174 unit
->m_y1
= zapgremlins(y1
);
3175 unit
->m_y2
= zapgremlins(y2
);
3178 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3180 static void Median_InitMedian(Median
* unit
, long size
, float value
);
3181 static float Median_InsertMedian(Median
* unit
, float value
);
3183 void Median_Ctor(Median
* unit
)
3185 //printf("Median_Reset\n");
3186 SETCALC(Median_next
);
3188 unit
->m_medianSize
= sc_clip((int)ZIN0(0), 0, kMAXMEDIANSIZE
);
3189 Median_InitMedian(unit
, unit
->m_medianSize
, in
);
3190 ZOUT0(0) = Median_InsertMedian(unit
, in
);
3194 float Median_InsertMedian(Median
* unit
, float value
)
3198 // keeps a sorted list of the previous n=size values
3199 // the oldest is removed and the newest is inserted.
3200 // values between the oldest and the newest are shifted over by one.
3202 // values and ages are both arrays that are 'size' long.
3203 // the median value is always values[size>>1]
3205 long last
= unit
->m_medianSize
- 1;
3206 // find oldest bin and age the other bins.
3207 for (int i
=0; i
<unit
->m_medianSize
; ++i
) {
3208 if (unit
->m_medianAge
[i
] == last
) { // is it the oldest bin ?
3211 unit
->m_medianAge
[i
]++; // age the bin
3214 // move values to fill in place of the oldest and make a space for the newest
3215 // search lower if value is too small for the open space
3216 while (pos
!= 0 && value
< unit
->m_medianValue
[pos
-1]) {
3217 unit
->m_medianValue
[pos
] = unit
->m_medianValue
[pos
-1];
3218 unit
->m_medianAge
[pos
] = unit
->m_medianAge
[pos
-1];
3221 // search higher if value is too big for the open space
3222 while (pos
!= last
&& value
> unit
->m_medianValue
[pos
+1]) {
3223 unit
->m_medianValue
[pos
] = unit
->m_medianValue
[pos
+1];
3224 unit
->m_medianAge
[pos
] = unit
->m_medianAge
[pos
+1];
3227 unit
->m_medianValue
[pos
] = value
;
3228 unit
->m_medianAge
[pos
] = 0; // this is the newest bin, age = 0
3229 return unit
->m_medianValue
[unit
->m_medianSize
>>1];
3232 void Median_InitMedian(Median
* unit
, long size
, float value
)
3234 // initialize the arrays with the first value
3235 unit
->m_medianSize
= size
;
3236 for (int i
=0; i
<size
; ++i
) {
3237 unit
->m_medianValue
[i
] = value
;
3238 unit
->m_medianAge
[i
] = i
;
3242 void Median_next(Median
* unit
, int inNumSamples
)
3244 //printf("Median_next_a\n");
3246 float *out
= ZOUT(0);
3250 ZXP(out
) = Median_InsertMedian(unit
, ZXP(in
));
3255 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3257 void Resonz_Ctor(Resonz
* unit
)
3259 //printf("Resonz_Reset\n");
3260 SETCALC(Resonz_next
);
3269 Resonz_next(unit
, 1);
3274 void Resonz_next(Resonz
* unit
, int inNumSamples
)
3276 //printf("Resonz_next\n");
3278 float *out
= ZOUT(0);
3280 float freq
= ZIN0(1);
3284 float y1
= unit
->m_y1
;
3285 float y2
= unit
->m_y2
;
3286 float a0
= unit
->m_a0
;
3287 float b1
= unit
->m_b1
;
3288 float b2
= unit
->m_b2
;
3290 if (freq
!= unit
->m_freq
|| rq
!= unit
->m_rq
) {
3291 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3292 float B
= ffreq
* rq
;
3293 float R
= 1.f
- B
* 0.5f
;
3294 float twoR
= 2.f
* R
;
3296 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3297 float b1_next
= twoR
* cost
;
3298 float b2_next
= -R2
;
3299 float a0_next
= (1.f
- R2
) * 0.5f
;
3300 float a0_slope
= (a0_next
- a0
) * unit
->mRate
->mFilterSlope
;
3301 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
3302 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
3303 LOOP(unit
->mRate
->mFilterLoops
,
3304 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3305 ZXP(out
) = a0
* (y0
- y2
);
3307 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3308 ZXP(out
) = a0
* (y2
- y1
);
3310 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3311 ZXP(out
) = a0
* (y1
- y0
);
3317 LOOP(unit
->mRate
->mFilterRemain
,
3318 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3319 ZXP(out
) = a0
* (y0
- y2
);
3324 unit
->m_freq
= freq
;
3326 unit
->m_a0
= a0_next
;
3327 unit
->m_b1
= b1_next
;
3328 unit
->m_b2
= b2_next
;
3330 LOOP(unit
->mRate
->mFilterLoops
,
3331 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3332 ZXP(out
) = a0
* (y0
- y2
);
3334 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3335 ZXP(out
) = a0
* (y2
- y1
);
3337 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3338 ZXP(out
) = a0
* (y1
- y0
);
3340 LOOP(unit
->mRate
->mFilterRemain
,
3341 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3342 ZXP(out
) = a0
* (y0
- y2
);
3347 unit
->m_y1
= zapgremlins(y1
);
3348 unit
->m_y2
= zapgremlins(y2
);
3352 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3354 void Ringz_Ctor(Ringz
* unit
)
3356 //printf("Ringz_ctor\n");
3357 SETCALC(Ringz_next
);
3363 unit
->m_decayTime
= 0.f
;
3365 Ringz_next(unit
, 1);
3370 void Ringz_next(Ringz
* unit
, int inNumSamples
)
3372 //printf("Ringz_next\n");
3374 float *out
= ZOUT(0);
3376 float freq
= ZIN0(1);
3377 float decayTime
= ZIN0(2);
3380 float y1
= unit
->m_y1
;
3381 float y2
= unit
->m_y2
;
3383 float b1
= unit
->m_b1
;
3384 float b2
= unit
->m_b2
;
3386 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
) {
3387 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3388 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3389 float twoR
= 2.f
* R
;
3391 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3392 float b1_next
= twoR
* cost
;
3393 float b2_next
= -R2
;
3394 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
3395 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
3396 LOOP(unit
->mRate
->mFilterLoops
,
3397 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3398 ZXP(out
) = a0
* (y0
- y2
);
3400 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3401 ZXP(out
) = a0
* (y2
- y1
);
3403 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3404 ZXP(out
) = a0
* (y1
- y0
);
3409 LOOP(unit
->mRate
->mFilterRemain
,
3410 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3411 ZXP(out
) = a0
* (y0
- y2
);
3416 unit
->m_freq
= freq
;
3417 unit
->m_decayTime
= decayTime
;
3418 unit
->m_b1
= b1_next
;
3419 unit
->m_b2
= b2_next
;
3421 LOOP(unit
->mRate
->mFilterLoops
,
3422 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3423 ZXP(out
) = a0
* (y0
- y2
);
3425 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3426 ZXP(out
) = a0
* (y2
- y1
);
3428 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3429 ZXP(out
) = a0
* (y1
- y0
);
3431 LOOP(unit
->mRate
->mFilterRemain
,
3432 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3433 ZXP(out
) = a0
* (y0
- y2
);
3438 unit
->m_y1
= zapgremlins(y1
);
3439 unit
->m_y2
= zapgremlins(y2
);
3443 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3445 void Formlet_Ctor(Formlet
* unit
)
3447 //printf("Formlet_Reset\n");
3448 if (unit
->mBufLength
== 1) {
3449 SETCALC(Formlet_next_1
);
3451 SETCALC(Formlet_next
);
3462 unit
->m_attackTime
= 0.f
;
3463 unit
->m_decayTime
= 0.f
;
3464 Formlet_next_1(unit
, 1);
3467 void Formlet_next(Formlet
* unit
, int inNumSamples
)
3469 //printf("Formlet_next\n");
3471 float *out
= ZOUT(0);
3473 float freq
= ZIN0(1);
3474 float attackTime
= ZIN0(2);
3475 float decayTime
= ZIN0(3);
3479 float y01
= unit
->m_y01
;
3480 float y11
= unit
->m_y11
;
3481 float y02
= unit
->m_y02
;
3482 float y12
= unit
->m_y12
;
3484 float b01
= unit
->m_b01
;
3485 float b11
= unit
->m_b11
;
3486 float b02
= unit
->m_b02
;
3487 float b12
= unit
->m_b12
;
3490 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
|| attackTime
!= unit
->m_attackTime
) {
3491 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3493 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3494 float twoR
= 2.f
* R
;
3496 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3497 float b01_next
= twoR
* cost
;
3498 float b02_next
= -R2
;
3499 float b01_slope
= (b01_next
- b01
) * unit
->mRate
->mFilterSlope
;
3500 float b02_slope
= (b02_next
- b02
) * unit
->mRate
->mFilterSlope
;
3502 R
= attackTime
== 0.f
? 0.f
: exp(log001
/(attackTime
* SAMPLERATE
));
3505 cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3506 float b11_next
= twoR
* cost
;
3507 float b12_next
= -R2
;
3508 float b11_slope
= (b11_next
- b11
) * unit
->mRate
->mFilterSlope
;
3509 float b12_slope
= (b12_next
- b12
) * unit
->mRate
->mFilterSlope
;
3511 LOOP(unit
->mRate
->mFilterLoops
,
3513 y00
= ain
+ b01
* y01
+ b02
* y02
;
3514 y10
= ain
+ b11
* y11
+ b12
* y12
;
3515 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3518 y02
= ain
+ b01
* y00
+ b02
* y01
;
3519 y12
= ain
+ b11
* y10
+ b12
* y11
;
3520 ZXP(out
) = 0.25f
* ((y02
- y01
) - (y12
- y11
));
3523 y01
= ain
+ b01
* y02
+ b02
* y00
;
3524 y11
= ain
+ b11
* y12
+ b12
* y10
;
3525 ZXP(out
) = 0.25f
* ((y01
- y00
) - (y11
- y10
));
3532 LOOP(unit
->mRate
->mFilterRemain
,
3534 y00
= ain
+ b01
* y01
+ b02
* y02
;
3535 y10
= ain
+ b11
* y11
+ b12
* y12
;
3536 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3543 unit
->m_freq
= freq
;
3544 unit
->m_attackTime
= attackTime
;
3545 unit
->m_decayTime
= decayTime
;
3546 unit
->m_b01
= b01_next
;
3547 unit
->m_b02
= b02_next
;
3548 unit
->m_b11
= b11_next
;
3549 unit
->m_b12
= b12_next
;
3551 LOOP(unit
->mRate
->mFilterLoops
,
3553 y00
= ain
+ b01
* y01
+ b02
* y02
;
3554 y10
= ain
+ b11
* y11
+ b12
* y12
;
3555 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3558 y02
= ain
+ b01
* y00
+ b02
* y01
;
3559 y12
= ain
+ b11
* y10
+ b12
* y11
;
3560 ZXP(out
) = 0.25f
* ((y02
- y01
) - (y12
- y11
));
3563 y01
= ain
+ b01
* y02
+ b02
* y00
;
3564 y11
= ain
+ b11
* y12
+ b12
* y10
;
3565 ZXP(out
) = 0.25f
* ((y01
- y00
) - (y11
- y10
));
3567 LOOP(unit
->mRate
->mFilterRemain
,
3569 y00
= ain
+ b01
* y01
+ b02
* y02
;
3570 y10
= ain
+ b11
* y11
+ b12
* y12
;
3571 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3584 void Formlet_next_1(Formlet
* unit
, int inNumSamples
)
3586 //printf("Formlet_next\n");
3589 float freq
= ZIN0(1);
3590 float attackTime
= ZIN0(2);
3591 float decayTime
= ZIN0(3);
3595 float y01
= unit
->m_y01
;
3596 float y11
= unit
->m_y11
;
3597 float y02
= unit
->m_y02
;
3598 float y12
= unit
->m_y12
;
3600 float b01
= unit
->m_b01
;
3601 float b11
= unit
->m_b11
;
3602 float b02
= unit
->m_b02
;
3603 float b12
= unit
->m_b12
;
3606 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
|| attackTime
!= unit
->m_attackTime
) {
3607 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3609 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3610 float twoR
= 2.f
* R
;
3612 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3616 R
= attackTime
== 0.f
? 0.f
: exp(log001
/(attackTime
* SAMPLERATE
));
3619 cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3624 y00
= ain
+ b01
* y01
+ b02
* y02
;
3625 y10
= ain
+ b11
* y11
+ b12
* y12
;
3626 ZOUT0(0) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3633 unit
->m_freq
= freq
;
3634 unit
->m_attackTime
= attackTime
;
3635 unit
->m_decayTime
= decayTime
;
3642 y00
= ain
+ b01
* y01
+ b02
* y02
;
3643 y10
= ain
+ b11
* y11
+ b12
* y12
;
3644 ZOUT0(0) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3658 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3660 void FOS_Ctor(FOS
* unit
)
3662 //printf("FOS_Reset\n");
3663 if (unit
->mBufLength
== 1) {
3664 SETCALC(FOS_next_1
);
3666 if (INRATE(1) == calc_FullRate
3667 && INRATE(2) == calc_FullRate
3668 && INRATE(3) == calc_FullRate
) {
3669 SETCALC(FOS_next_a
);
3671 SETCALC(FOS_next_k
);
3678 FOS_next_1(unit
, 1);
3681 void FOS_next_a(FOS
* unit
, int inNumSamples
)
3683 float *out
= ZOUT(0);
3689 float y1
= unit
->m_y1
;
3691 float y0
= ZXP(in
) + ZXP(b1
) * y1
;
3692 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
;
3695 unit
->m_y1
= zapgremlins(y1
);
3698 void FOS_next_1(FOS
* unit
, int inNumSamples
)
3705 float y1
= unit
->m_y1
;
3707 float y0
= in
+ b1
* y1
;
3708 ZOUT0(0) = a0
* y0
+ a1
* y1
;
3711 unit
->m_y1
= zapgremlins(y1
);
3715 void FOS_next_k(FOS
* unit
, int inNumSamples
)
3717 float *out
= ZOUT(0);
3719 float next_a0
= ZIN0(1);
3720 float next_a1
= ZIN0(2);
3721 float next_b1
= ZIN0(3);
3723 float y1
= unit
->m_y1
;
3724 float a0
= unit
->m_a0
;
3725 float a1
= unit
->m_a1
;
3726 float b1
= unit
->m_b1
;
3727 float a0_slope
= CALCSLOPE(next_a0
, a0
);
3728 float a1_slope
= CALCSLOPE(next_a1
, a1
);
3729 float b1_slope
= CALCSLOPE(next_b1
, b1
);
3731 float y0
= ZXP(in
) + b1
* y1
;
3732 ZXP(out
) = a0
* y0
+ a1
* y1
;
3739 unit
->m_y1
= zapgremlins(y1
);
3740 unit
->m_a0
= next_a0
;
3741 unit
->m_a1
= next_a1
;
3742 unit
->m_b1
= next_b1
;
3745 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3747 void SOS_Ctor(SOS
* unit
)
3749 // printf("SOS_Reset\n");
3750 if (unit
->mBufLength
!= 1) {
3751 if (INRATE(1) == calc_FullRate
3752 && INRATE(2) == calc_FullRate
3753 && INRATE(3) == calc_FullRate
3754 && INRATE(4) == calc_FullRate
3755 && INRATE(5) == calc_FullRate
) {
3756 SETCALC(SOS_next_a
);
3757 // printf("SOS_next_a\n");
3759 SETCALC(SOS_next_k
);
3760 // printf("SOS_next_k\n");
3763 SETCALC(SOS_next_1
);
3764 // printf("SOS_next_1\n");
3773 SOS_next_1(unit
, 1);
3776 void SOS_next_a(SOS
*unit
, int inNumSamples
)
3778 float *out
= ZOUT(0);
3787 float y1
= unit
->m_y1
;
3788 float y2
= unit
->m_y2
;
3789 LOOP(unit
->mRate
->mFilterLoops
,
3790 y0
= ZXP(in
) + ZXP(b1
) * y1
+ ZXP(b2
) * y2
;
3791 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
+ ZXP(a2
) * y2
;
3793 y2
= ZXP(in
) + ZXP(b1
) * y0
+ ZXP(b2
) * y1
;
3794 ZXP(out
) = ZXP(a0
) * y2
+ ZXP(a1
) * y0
+ ZXP(a2
) * y1
;
3796 y1
= ZXP(in
) + ZXP(b1
) * y2
+ ZXP(b2
) * y0
;
3797 ZXP(out
) = ZXP(a0
) * y1
+ ZXP(a1
) * y2
+ ZXP(a2
) * y0
;
3799 LOOP(unit
->mRate
->mFilterRemain
,
3800 y0
= ZXP(in
) + ZXP(b1
) * y1
+ ZXP(b2
) * y2
;
3801 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
+ ZXP(a2
) * y2
;
3806 unit
->m_y1
= zapgremlins(y1
);
3807 unit
->m_y2
= zapgremlins(y2
);
3810 void SOS_next_k(SOS
*unit
, int inNumSamples
)
3812 float *out
= ZOUT(0);
3814 float next_a0
= ZIN0(1);
3815 float next_a1
= ZIN0(2);
3816 float next_a2
= ZIN0(3);
3817 float next_b1
= ZIN0(4);
3818 float next_b2
= ZIN0(5);
3821 float y1
= unit
->m_y1
;
3822 float y2
= unit
->m_y2
;
3823 float a0
= unit
->m_a0
;
3824 float a1
= unit
->m_a1
;
3825 float a2
= unit
->m_a2
;
3826 float b1
= unit
->m_b1
;
3827 float b2
= unit
->m_b2
;
3828 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
3829 float a1_slope
= (next_a1
- a1
) * unit
->mRate
->mFilterSlope
;
3830 float a2_slope
= (next_a2
- a2
) * unit
->mRate
->mFilterSlope
;
3831 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
3832 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
3833 LOOP(unit
->mRate
->mFilterLoops
,
3834 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3835 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3837 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3838 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
3840 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3841 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
3849 LOOP(unit
->mRate
->mFilterRemain
,
3850 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3851 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3861 unit
->m_y1
= zapgremlins(y1
);
3862 unit
->m_y2
= zapgremlins(y2
);
3865 void SOS_next_1(SOS
*unit
, int inNumSamples
) // optimized for SOS.kr
3875 float y1
= unit
->m_y1
;
3876 float y2
= unit
->m_y2
;
3878 y0
= in
+ b1
* y1
+ b2
* y2
;
3879 ZOUT0(0) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3883 unit
->m_y1
= zapgremlins(y1
);
3884 unit
->m_y2
= zapgremlins(y2
);
3887 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3889 void Compander_Ctor(Compander
* unit
)
3891 //printf("Compander_Reset\n");
3892 SETCALC(Compander_next
);
3893 unit
->m_clamp
= 0.f
;
3894 unit
->m_clampcoef
= 0.f
;
3895 unit
->m_relax
= 0.f
;
3896 unit
->m_relaxcoef
= 0.f
;
3897 unit
->m_prevmaxval
= 0.f
;
3899 Compander_next(unit
, 1);
3902 void Compander_next(Compander
* unit
, int inNumSamples
)
3904 float *out
= ZOUT(0);
3906 float *control
= ZIN(1);
3907 float thresh
= ZIN0(2);
3908 float slope_below
= ZIN0(3);
3909 float slope_above
= ZIN0(4);
3910 float clamp
= ZIN0(5);
3911 float relax
= ZIN0(6);
3913 if (clamp
!= unit
->m_clamp
) {
3914 unit
->m_clampcoef
= clamp
== 0.0 ? 0.0 : exp(log1
/(clamp
* SAMPLERATE
));
3915 unit
->m_clamp
= clamp
;
3917 if (relax
!= unit
->m_relax
) {
3918 unit
->m_relaxcoef
= relax
== 0.0 ? 0.0 : exp(log1
/(relax
* SAMPLERATE
));
3919 unit
->m_relax
= relax
;
3922 float gain
= unit
->m_gain
;
3924 float relaxcoef
= unit
->m_relaxcoef
;
3925 float clampcoef
= unit
->m_clampcoef
;
3927 float prevmaxval
= unit
->m_prevmaxval
;
3931 val
= std::abs(ZXP(control
));
3932 if (val
< prevmaxval
) {
3933 val
= val
+ (prevmaxval
- val
) * relaxcoef
;
3935 val
= val
+ (prevmaxval
- val
) * clampcoef
;
3940 unit
->m_prevmaxval
= prevmaxval
;
3942 float next_gain
;//,absx;
3943 if (prevmaxval
< thresh
) {
3944 if (slope_below
== 1.f
) {
3947 next_gain
= pow(prevmaxval
/ thresh
, slope_below
- 1.f
);
3949 float32 absx
= std::abs(next_gain
);
3950 //zap gremlins, but returns 0. if gain is too small and 1. if gain is too big
3952 (absx
< (float32
)1e-15) ? (float32
)0. :
3953 (absx
> (float32
)1e15
) ? (float32
)1. : next_gain
;
3956 if (slope_above
== 1.f
) {
3959 next_gain
= pow(prevmaxval
/ thresh
, slope_above
- 1.f
);
3963 float gain_slope
= CALCSLOPE(next_gain
, gain
);
3964 LOOP1(inNumSamples
, ZXP(out
) = ZXP(in
) * gain
; gain
+= gain_slope
;);
3965 unit
->m_gain
= gain
;
3968 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3971 void Normalizer_Dtor(Normalizer
* unit
)
3973 RTFree(unit
->mWorld
, unit
->m_table
);
3976 void Normalizer_Ctor(Normalizer
* unit
)
3978 SETCALC(Normalizer_next
);
3979 //printf("Normalizer_Reset\n");
3981 float dur
= ZIN0(2);
3982 unit
->m_bufsize
= (long)(ceil(dur
* SAMPLERATE
));
3983 long allocsize
= unit
->m_bufsize
* 3;
3984 //allocsize = NEXTPOWEROFTWO(allocsize);
3986 unit
->m_table
= (float*)RTAlloc(unit
->mWorld
, allocsize
* sizeof(float));
3990 unit
->m_level
= 1.f
;
3991 unit
->m_slope
= 0.f
;
3992 unit
->m_prevmaxval
= 0.0;
3993 unit
->m_curmaxval
= 0.0;
3994 unit
->m_slopefactor
= 1.f
/ unit
->m_bufsize
;
3996 unit
->m_xinbuf
= unit
->m_table
- ZOFF
;
3997 unit
->m_xmidbuf
= unit
->m_xinbuf
+ unit
->m_bufsize
;
3998 unit
->m_xoutbuf
= unit
->m_xmidbuf
+ unit
->m_bufsize
;
3999 Normalizer_next(unit
, 1);
4003 void Normalizer_next(Normalizer
* unit
, int inNumSamples
)
4005 float *out
= ZOUT(0);
4007 float amp
= ZIN0(1);
4009 long pos
= unit
->m_pos
;
4010 float slope
= unit
->m_slope
;
4011 float level
= unit
->m_level
;
4012 float curmaxval
= unit
->m_curmaxval
;
4015 long bufsize
= unit
->m_bufsize
;
4016 long buf_remain
= bufsize
- pos
;
4018 long remain
= inNumSamples
;
4019 while (remain
> 0) {
4020 long nsmps
= sc_min(remain
, buf_remain
);
4021 float* xinbuf
= unit
->m_xinbuf
+ pos
;
4022 float* xoutbuf
= unit
->m_xoutbuf
+ pos
;
4023 if (unit
->m_flips
>= 2) {
4025 ZXP(xinbuf
) = val
= ZXP(in
);
4026 ZXP(out
) = level
* ZXP(xoutbuf
);
4028 val
= std::abs(val
);
4029 if (val
> curmaxval
) curmaxval
= val
;
4033 ZXP(xinbuf
) = val
= ZXP(in
);
4036 val
= std::abs(val
);
4037 if (val
> curmaxval
) curmaxval
= val
;
4041 if (pos
>= bufsize
) {
4043 buf_remain
= bufsize
;
4045 float maxval2
= sc_max(unit
->m_prevmaxval
, curmaxval
);
4046 unit
->m_prevmaxval
= curmaxval
;
4047 unit
->m_curmaxval
= curmaxval
= 0.f
;
4050 if (maxval2
<= 0.00001f
) next_level
= 100000.f
* amp
;
4051 else next_level
= amp
/ maxval2
;
4053 slope
= unit
->m_slope
= (next_level
- level
) * unit
->m_slopefactor
;
4055 float* temp
= unit
->m_xoutbuf
;
4056 unit
->m_xoutbuf
= unit
->m_xmidbuf
;
4057 unit
->m_xmidbuf
= unit
->m_xinbuf
;
4058 unit
->m_xinbuf
= temp
;
4066 unit
->m_level
= level
;
4067 unit
->m_curmaxval
= curmaxval
;
4070 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4072 void Limiter_Dtor(Limiter
* unit
)
4074 RTFree(unit
->mWorld
, unit
->m_table
);
4077 void Limiter_Ctor(Limiter
* unit
)
4079 //printf("Limiter_Reset\n");
4080 SETCALC(Limiter_next
);
4082 float dur
= ZIN0(2);
4083 unit
->m_bufsize
= (long)(ceil(dur
* SAMPLERATE
));
4084 long allocsize
= unit
->m_bufsize
* 3;
4085 allocsize
= NEXTPOWEROFTWO(allocsize
);
4087 unit
->m_table
= (float*)RTAlloc(unit
->mWorld
, allocsize
* sizeof(float));
4091 unit
->m_slope
= 0.f
;
4092 unit
->m_level
= 1.f
;
4093 unit
->m_prevmaxval
= 0.0;
4094 unit
->m_curmaxval
= 0.0;
4095 unit
->m_slopefactor
= 1.f
/ unit
->m_bufsize
;
4097 unit
->m_xinbuf
= unit
->m_table
- ZOFF
;
4098 unit
->m_xmidbuf
= unit
->m_xinbuf
+ unit
->m_bufsize
;
4099 unit
->m_xoutbuf
= unit
->m_xmidbuf
+ unit
->m_bufsize
;
4100 Limiter_next(unit
, 1);
4104 void Limiter_next(Limiter
* unit
, int inNumSamples
)
4106 float *out
= ZOUT(0);
4108 float amp
= ZIN0(1);
4110 long pos
= unit
->m_pos
;
4111 float slope
= unit
->m_slope
;
4112 float level
= unit
->m_level
;
4113 float curmaxval
= unit
->m_curmaxval
;
4116 long bufsize
= unit
->m_bufsize
;
4117 long buf_remain
= bufsize
- pos
;
4119 long remain
= inNumSamples
;
4120 while (remain
> 0) {
4121 long nsmps
= sc_min(remain
, buf_remain
);
4122 float* xinbuf
= unit
->m_xinbuf
+ pos
;
4123 float* xoutbuf
= unit
->m_xoutbuf
+ pos
;
4124 if (unit
->m_flips
>= 2) {
4126 ZXP(xinbuf
) = val
= ZXP(in
);
4127 ZXP(out
) = level
* ZXP(xoutbuf
);
4129 val
= std::abs(val
);
4130 if (val
> curmaxval
) curmaxval
= val
;
4134 ZXP(xinbuf
) = val
= ZXP(in
);
4137 val
= std::abs(val
);
4138 if (val
> curmaxval
) curmaxval
= val
;
4142 if (pos
>= bufsize
) {
4144 buf_remain
= bufsize
;
4146 float maxval2
= sc_max(unit
->m_prevmaxval
, curmaxval
);
4147 unit
->m_prevmaxval
= curmaxval
;
4148 unit
->m_curmaxval
= curmaxval
= 0.f
;
4151 if (maxval2
> amp
) next_level
= amp
/ maxval2
;
4152 else next_level
= 1.0;
4154 slope
= unit
->m_slope
= (next_level
- level
) * unit
->m_slopefactor
;
4156 float* temp
= unit
->m_xoutbuf
;
4157 unit
->m_xoutbuf
= unit
->m_xmidbuf
;
4158 unit
->m_xmidbuf
= unit
->m_xinbuf
;
4159 unit
->m_xinbuf
= temp
;
4167 unit
->m_level
= level
;
4168 unit
->m_curmaxval
= curmaxval
;
4171 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4173 void Amplitude_Ctor(Amplitude
* unit
)
4175 if(INRATE(1) != calc_ScalarRate
|| INRATE(2) != calc_ScalarRate
) {
4176 if(INRATE(0) == calc_FullRate
&& unit
->mCalcRate
== calc_BufRate
){
4177 SETCALC(Amplitude_next_atok_kk
);
4179 SETCALC(Amplitude_next_kk
);
4183 if(INRATE(0) == calc_FullRate
&& unit
->mCalcRate
== calc_BufRate
){
4184 SETCALC(Amplitude_next_atok
);
4186 SETCALC(Amplitude_next
);
4190 float clamp
= ZIN0(1);
4191 unit
->m_clampcoef
= clamp
== 0.0 ? 0.0 : exp(log1
/(clamp
* SAMPLERATE
));
4193 float relax
= ZIN0(2);
4194 unit
->m_relaxcoef
= relax
== 0.0 ? 0.0 : exp(log1
/(relax
* SAMPLERATE
));
4196 unit
->m_previn
= std::abs(ZIN0(0));
4197 Amplitude_next(unit
, 1);
4200 void Amplitude_next(Amplitude
* unit
, int inNumSamples
)
4202 float *out
= ZOUT(0);
4205 float relaxcoef
= unit
->m_relaxcoef
;
4206 float clampcoef
= unit
->m_clampcoef
;
4207 float previn
= unit
->m_previn
;
4211 val
= std::abs(ZXP(in
));
4213 val
= val
+ (previn
- val
) * relaxcoef
;
4215 val
= val
+ (previn
- val
) * clampcoef
;
4217 ZXP(out
) = previn
= val
;
4220 unit
->m_previn
= previn
;
4223 void Amplitude_next_atok(Amplitude
* unit
, int inNumSamples
)
4227 float relaxcoef
= unit
->m_relaxcoef
;
4228 float clampcoef
= unit
->m_clampcoef
;
4229 float previn
= unit
->m_previn
;
4232 LOOP1(FULLBUFLENGTH
,
4233 val
= std::abs(ZXP(in
));
4235 val
= val
+ (previn
- val
) * relaxcoef
;
4237 val
= val
+ (previn
- val
) * clampcoef
;
4243 unit
->m_previn
= previn
;
4246 void Amplitude_next_kk(Amplitude
* unit
, int inNumSamples
)
4248 float *out
= ZOUT(0);
4250 float relaxcoef
, clampcoef
;
4252 if(ZIN0(1) != unit
->m_clamp_in
) {
4253 clampcoef
= unit
->m_clampcoef
= exp(log1
/(ZIN0(1) * SAMPLERATE
));
4254 unit
->m_clamp_in
= ZIN0(1);
4256 clampcoef
= unit
->m_clampcoef
;
4259 if(ZIN0(2) != unit
->m_relax_in
) {
4260 relaxcoef
= unit
->m_relaxcoef
= exp(log1
/(ZIN0(2) * SAMPLERATE
));
4261 unit
->m_relax_in
= ZIN0(2);
4263 relaxcoef
= unit
->m_relaxcoef
;
4266 float previn
= unit
->m_previn
;
4270 val
= std::abs(ZXP(in
));
4272 val
= val
+ (previn
- val
) * relaxcoef
;
4274 val
= val
+ (previn
- val
) * clampcoef
;
4276 ZXP(out
) = previn
= val
;
4279 unit
->m_previn
= previn
;
4282 void Amplitude_next_atok_kk(Amplitude
* unit
, int inNumSamples
)
4285 float relaxcoef
, clampcoef
;
4287 if(ZIN0(1) != unit
->m_clamp_in
) {
4288 clampcoef
= unit
->m_clampcoef
= exp(log1
/(ZIN0(1) * SAMPLERATE
));
4289 unit
->m_clamp_in
= ZIN0(1);
4291 clampcoef
= unit
->m_clampcoef
;
4294 if(ZIN0(2) != unit
->m_relax_in
) {
4295 relaxcoef
= unit
->m_relaxcoef
= exp(log1
/(ZIN0(2) * SAMPLERATE
));
4296 unit
->m_relax_in
= ZIN0(2);
4298 relaxcoef
= unit
->m_relaxcoef
;
4301 float previn
= unit
->m_previn
;
4304 LOOP1(FULLBUFLENGTH
,
4305 val
= std::abs(ZXP(in
));
4307 val
= val
+ (previn
- val
) * relaxcoef
;
4309 val
= val
+ (previn
- val
) * clampcoef
;
4315 unit
->m_previn
= previn
;
4318 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4320 void DetectSilence_Ctor(DetectSilence
* unit
)
4322 //printf("DetectSilence_Reset\n");
4323 SETCALC(DetectSilence_next
);
4325 unit
->mThresh
= ZIN0(1);
4326 unit
->mEndCounter
= (int32
)(SAMPLERATE
* ZIN0(2));
4327 unit
->mCounter
= -1;
4331 void DetectSilence_next(DetectSilence
* unit
, int inNumSamples
)
4333 float thresh
= unit
->mThresh
;
4334 int counter
= unit
->mCounter
;
4337 // I thought of a better way to do this...
4339 for (int i=0; i<inNumSamples; ++i) {
4340 float val = std::abs(ZXP(in));
4341 if (val >= thresh) counter = 0;
4342 else if (counter >= 0) {
4343 if (++counter >= unit->mEndCounter && doneAction) {
4344 int doneAction = (int)ZIN0(3);
4345 DoneAction(doneAction, unit);
4346 SETCALC(DetectSilence_done);
4353 float *out
= OUT(0);
4354 for (int i
=0; i
<inNumSamples
; ++i
) {
4355 val
= std::abs(*in
++);
4359 } else if (counter
>= 0) {
4360 if (++counter
>= unit
->mEndCounter
) {
4361 int doneAction
= (int)ZIN0(3);
4362 DoneAction(doneAction
, unit
);
4364 // SETCALC(DetectSilence_done);
4372 unit
->mCounter
= counter
;
4375 void DetectSilence_done(DetectSilence
* unit
, int inNumSamples
)
4378 ///////////////////////////////////////////////////////////////////////////////////////////////////////
4379 // Based on HilbertIIR from SC2
4380 // a 12 pole (6 per side) Hilbert IIR filter
4381 // based on Sean Costello and Bernie Hutchins
4382 // created by jl anderson - 7 jan 2001
4383 // UGen created by Josh Parmenter
4385 #define HILBERT_FILTER \
4386 y0_1 = thisin - (coefs[0]) * y1[0]; \
4387 ay1 = coefs[0] * y0_1 + 1 * y1[0]; \
4389 y0_2 = ay1 - (coefs[1]) * y1[1]; \
4390 ay2 = coefs[1] * y0_2 + 1 * y1[1]; \
4392 y0_3 = ay2 - (coefs[2]) * y1[2]; \
4393 ay3 = coefs[2] * y0_3 + 1 * y1[2]; \
4395 y0_4 = ay3 - (coefs[3]) * y1[3]; \
4396 ay4 =coefs[3] * y0_4 + 1 * y1[3]; \
4398 y0_5 = ay4 - (coefs[4]) * y1[4]; \
4399 ay5 = coefs[4] * y0_5 + 1 * y1[4]; \
4401 y0_6 = ay5 - (coefs[5]) * y1[5]; \
4402 ay6 = coefs[5] * y0_6 + 1 * y1[5]; \
4405 y0_7 = thisin - (coefs[6]) * y1[6]; \
4406 ay7 = coefs[6] * y0_7 + 1 * y1[6]; \
4408 y0_8 = ay7 - (coefs[7]) * y1[7]; \
4409 ay8 = coefs[7] * y0_8 + 1 * y1[7]; \
4411 y0_9 = ay8 - (coefs[8]) * y1[8]; \
4412 ay9 = coefs[8] * y0_9 + 1 * y1[8]; \
4414 y0_10 = ay9 - (coefs[9]) * y1[9]; \
4415 ay10 = coefs[9] * y0_10 + 1 * y1[9]; \
4417 y0_11 = ay10 - (coefs[10]) * y1[10]; \
4418 ay11 = coefs[10] * y0_11 + 1 * y1[10]; \
4420 y0_12 = ay11 - (coefs[11]) * y1[11]; \
4421 ay12 = coefs[11] * y0_12 + 1 * y1[11]; \
4425 void Hilbert_Ctor(Hilbert *unit)
4427 // calculate coefs based on SampleRate, store in the struct
4428 SETCALC(Hilbert_next
);
4430 float gamconst
= (15.0f
* pi_f
) / SAMPLERATE
;
4431 float gamma01
= gamconst
* 0.3609f
;
4432 float gamma02
= gamconst
* 2.7412f
;
4433 float gamma03
= gamconst
* 11.1573f
;
4434 float gamma04
= gamconst
* 44.7581f
;
4435 float gamma05
= gamconst
* 179.6242f
;
4436 float gamma06
= gamconst
* 798.4578f
;
4437 float gamma07
= gamconst
* 1.2524f
;
4438 float gamma08
= gamconst
* 5.5671f
;
4439 float gamma09
= gamconst
* 22.3423f
;
4440 float gamma10
= gamconst
* 89.6271f
;
4441 float gamma11
= gamconst
* 364.7914f
;
4442 float gamma12
= gamconst
* 2770.1114f
;
4443 unit
->m_coefs
[0] = (gamma01
- 1.f
) / (gamma01
+ 1.f
);
4444 unit
->m_coefs
[1] = (gamma02
- 1.f
) / (gamma02
+ 1.f
);
4445 unit
->m_coefs
[2] = (gamma03
- 1.f
) / (gamma03
+ 1.f
);
4446 unit
->m_coefs
[3] = (gamma04
- 1.f
) / (gamma04
+ 1.f
);
4447 unit
->m_coefs
[4] = (gamma05
- 1.f
) / (gamma05
+ 1.f
);
4448 unit
->m_coefs
[5] = (gamma06
- 1.f
) / (gamma06
+ 1.f
);
4449 unit
->m_coefs
[6] = (gamma07
- 1.f
) / (gamma07
+ 1.f
);
4450 unit
->m_coefs
[7] = (gamma08
- 1.f
) / (gamma08
+ 1.f
);
4451 unit
->m_coefs
[8] = (gamma09
- 1.f
) / (gamma09
+ 1.f
);
4452 unit
->m_coefs
[9] = (gamma10
- 1.f
) / (gamma10
+ 1.f
);
4453 unit
->m_coefs
[10] = (gamma11
- 1.f
) / (gamma11
+ 1.f
);
4454 unit
->m_coefs
[11] = (gamma12
- 1.f
) / (gamma12
+ 1.f
);
4455 Clear(12, unit
->m_y1
);
4456 Hilbert_next(unit
, 1);
4459 void Hilbert_next(Hilbert
*unit
, int inNumSamples
)
4462 float *outcos
= ZOUT(0);
4463 float *outsin
= ZOUT(1);
4467 // each filter's last sample
4468 for(int i
= 0; i
< 12; ++i
){
4469 y1
[i
] = unit
->m_y1
[i
];
4470 coefs
[i
] = unit
->m_coefs
[i
];
4473 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4474 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4476 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4477 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4480 float thisin
= ZXP(in
);
4487 for(int i
= 0; i
< 12; ++i
)
4488 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4492 /* Hilbert based SSB FreqShifter */
4494 void FreqShift_Ctor(FreqShift
*unit
)
4496 // calculate coefs based on SampleRate, store in the struct
4497 // SETCALC(FreqShift_next_kk);
4499 if(INRATE(1) == calc_FullRate
) {
4500 if(INRATE(2) == calc_FullRate
)
4501 SETCALC(FreqShift_next_aa
);
4503 SETCALC(FreqShift_next_ak
);
4505 if(INRATE(2) == calc_FullRate
)
4506 SETCALC(FreqShift_next_ka
);
4508 SETCALC(FreqShift_next_kk
);
4509 unit
->m_phase
= (int32
)(unit
->m_radtoinc
* IN0(2));
4512 // set up for the oscil for the modualtion
4514 int tableSizeSin
= ft
->mSineSize
;
4515 unit
->m_lomask
= (tableSizeSin
- 1) << 3;
4516 unit
->m_radtoinc
= tableSizeSin
* (rtwopi
* 65536.);
4517 unit
->m_cpstoinc
= tableSizeSin
* SAMPLEDUR
* 65536.;
4518 unit
->m_phasein
= IN0(2);
4520 float gamconst
= (15.0 * pi
) / SAMPLERATE
;
4521 float gamma01
= gamconst
* 0.3609f
;
4522 float gamma02
= gamconst
* 2.7412f
;
4523 float gamma03
= gamconst
* 11.1573f
;
4524 float gamma04
= gamconst
* 44.7581f
;
4525 float gamma05
= gamconst
* 179.6242f
;
4526 float gamma06
= gamconst
* 798.4578f
;
4527 float gamma07
= gamconst
* 1.2524f
;
4528 float gamma08
= gamconst
* 5.5671f
;
4529 float gamma09
= gamconst
* 22.3423f
;
4530 float gamma10
= gamconst
* 89.6271f
;
4531 float gamma11
= gamconst
* 364.7914f
;
4532 float gamma12
= gamconst
* 2770.1114f
;
4533 unit
->m_coefs
[0] = (gamma01
- 1.f
) / (gamma01
+ 1.f
);
4534 unit
->m_coefs
[1] = (gamma02
- 1.f
) / (gamma02
+ 1.f
);
4535 unit
->m_coefs
[2] = (gamma03
- 1.f
) / (gamma03
+ 1.f
);
4536 unit
->m_coefs
[3] = (gamma04
- 1.f
) / (gamma04
+ 1.f
);
4537 unit
->m_coefs
[4] = (gamma05
- 1.f
) / (gamma05
+ 1.f
);
4538 unit
->m_coefs
[5] = (gamma06
- 1.f
) / (gamma06
+ 1.f
);
4539 unit
->m_coefs
[6] = (gamma07
- 1.f
) / (gamma07
+ 1.f
);
4540 unit
->m_coefs
[7] = (gamma08
- 1.f
) / (gamma08
+ 1.f
);
4541 unit
->m_coefs
[8] = (gamma09
- 1.f
) / (gamma09
+ 1.f
);
4542 unit
->m_coefs
[9] = (gamma10
- 1.f
) / (gamma10
+ 1.f
);
4543 unit
->m_coefs
[10] = (gamma11
- 1.f
) / (gamma11
+ 1.f
);
4544 unit
->m_coefs
[11] = (gamma12
- 1.f
) / (gamma12
+ 1.f
);
4546 Clear(12, unit
->m_y1
);
4547 FreqShift_next_kk(unit
, 1);
4550 void FreqShift_next_kk(FreqShift
*unit
, int inNumSamples
)
4553 float *out
= ZOUT(0);
4554 float phasein
= ZIN0(2);
4555 float freqin
= ZIN0(1);
4556 float outcos
, outsin
; // the sample by sample output of the Hilbert
4557 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4558 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4562 float *table0
= ft
->mSineWavetable
;
4563 float *table1
= table0
+ 1;
4564 int32 lomask
= unit
->m_lomask
;
4565 int32 phase
= unit
->m_phase
;
4567 int32 freq
= (int32
)(unit
->m_cpstoinc
* freqin
);
4568 int32 phaseinc
= freq
+ (int32
)(CALCSLOPE(phasein
, unit
->m_phasein
) * unit
->m_radtoinc
);
4569 unit
->m_phasein
= phasein
;
4571 // each filter's last sample
4572 for(int i
= 0; i
< 12; ++i
) {
4573 y1
[i
] = unit
->m_y1
[i
];
4574 coefs
[i
] = unit
->m_coefs
[i
];
4577 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4578 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4580 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4581 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4584 float thisin
= ZXP(in
);
4591 outsinosc
= lookupi1(table0
, table1
, phase
, lomask
);
4592 outsinoscHalfPi
= lookupi1(table0
, table1
, phase
+ halfPi
, lomask
);
4594 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4599 unit
->m_phase
= phase
;
4601 for(int i
= 0; i
< 12; ++i
)
4602 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4605 void FreqShift_next_aa(FreqShift
*unit
, int inNumSamples
)
4608 float *out
= ZOUT(0);
4609 float *phasein
= ZIN(2);
4610 float *freqin
= ZIN(1);
4611 float outcos
, outsin
; // the sample by sample output of the Hilbert
4612 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4613 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4617 float *table0
= ft
->mSineWavetable
;
4618 float *table1
= table0
+ 1;
4619 int32 lomask
= unit
->m_lomask
;
4620 int32 phase
= unit
->m_phase
;
4622 // each filter's last sample
4623 for(int i
= 0; i
< 12; ++i
){
4624 y1
[i
] = unit
->m_y1
[i
];
4625 coefs
[i
] = unit
->m_coefs
[i
];
4628 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4629 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4631 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4632 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4635 float thisin
= ZXP(in
);
4642 int32 phaseoffset
= phase
+ (int32
)(unit
->m_radtoinc
* ZXP(phasein
));
4643 outsinosc
= lookupi1(table0
, table1
, phaseoffset
, lomask
);
4644 outsinoscHalfPi
= lookupi1(table0
, table1
, phaseoffset
+ halfPi
, lomask
);
4645 phase
+= (int32
)(unit
->m_cpstoinc
* ZXP(freqin
));
4647 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4650 unit
->m_phase
= phase
;
4652 for(int i
= 0; i
< 12; ++i
)
4653 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4656 void FreqShift_next_ak(FreqShift
*unit
, int inNumSamples
)
4659 float *out
= ZOUT(0);
4660 float phasein
= ZIN0(2);
4661 float *freqin
= ZIN(1);
4662 float outcos
, outsin
; // the sample by sample output of the Hilbert
4663 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4664 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4668 float *table0
= ft
->mSineWavetable
;
4669 float *table1
= table0
+ 1;
4670 int32 lomask
= unit
->m_lomask
;
4671 int32 phase
= unit
->m_phase
;
4672 float phasemod
= unit
->m_phasein
;
4673 float phaseslope
= CALCSLOPE(phasein
, phasemod
);
4675 // each filter's last sample
4676 for(int i
= 0; i
< 12; ++i
) {
4677 y1
[i
] = unit
->m_y1
[i
];
4678 coefs
[i
] = unit
->m_coefs
[i
];
4681 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4682 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4684 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4685 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4688 float thisin
= ZXP(in
);
4695 int32 pphase
= phase
+ (int32
)(unit
->m_radtoinc
* phasemod
);
4696 phasemod
+= phaseslope
;
4697 outsinosc
= lookupi1(table0
, table1
, pphase
, lomask
);
4698 outsinoscHalfPi
= lookupi1(table0
, table1
, pphase
+ halfPi
, lomask
);
4699 phase
+= (int32
)(unit
->m_cpstoinc
* ZXP(freqin
));
4701 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4704 unit
->m_phase
= phase
;
4705 unit
->m_phasein
= phasein
;
4707 for(int i
= 0; i
< 12; ++i
)
4708 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4711 void FreqShift_next_ka(FreqShift
*unit
, int inNumSamples
)
4714 float *out
= ZOUT(0);
4715 float *phasein
= ZIN(2);
4716 float freqin
= ZIN0(1);
4717 float outcos
, outsin
; // the sample by sample output of the Hilbert
4718 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4719 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4723 float *table0
= ft
->mSineWavetable
;
4724 float *table1
= table0
+ 1;
4725 int32 lomask
= unit
->m_lomask
;
4726 int32 phase
= unit
->m_phase
;
4727 float phasemod
= unit
->m_phasein
;
4729 int32 freq
= (int32
)(unit
->m_cpstoinc
* freqin
);
4731 // each filter's last sample
4732 for(int i
= 0; i
< 12; ++i
) {
4733 y1
[i
] = unit
->m_y1
[i
];
4734 coefs
[i
] = unit
->m_coefs
[i
];
4737 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4738 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4740 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4741 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4744 float thisin
= ZXP(in
);
4751 int32 phaseoffset
= phase
+ (int32
)(unit
->m_radtoinc
* ZXP(phasein
));
4752 outsinosc
= lookupi1(table0
, table1
, phaseoffset
, lomask
);
4753 outsinoscHalfPi
= lookupi1(table0
, table1
, phaseoffset
+ halfPi
, lomask
);
4756 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4759 unit
->m_phase
= phase
;
4761 for(int i
= 0; i
< 12; ++i
)
4762 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4767 "MoogFF" - Moog VCF digital implementation.
4768 As described in the paper entitled
4769 "Preserving the Digital Structure of the Moog VCF"
4771 appeared in the Proc. ICMC07, Copenhagen, 25-31 August 2007
4773 Original Java code Copyright F. Fontana - August 2007
4774 federico.fontana@univr.it
4776 Ported to C++ for SuperCollider by Dan Stowell - August 2007
4777 http://www.mcld.co.uk/
4779 This program is free software; you can redistribute it and/or modify
4780 it under the terms of the GNU General Public License as published by
4781 the Free Software Foundation; either version 2 of the License, or
4782 (at your option) any later version.
4784 This program is distributed in the hope that it will be useful,
4785 but WITHOUT ANY WARRANTY; without even the implied warranty of
4786 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4787 GNU General Public License for more details.
4789 You should have received a copy of the GNU General Public License
4790 along with this program; if not, write to the Free Software
4791 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4793 //////////////////////////////////////////////////////////////////
4795 void MoogFF_Ctor(MoogFF
* unit
)
4797 SETCALC(MoogFF_next
);
4799 // initialize the unit generator state variables.
4800 unit
->m_freq
= -10000.3f
; // Force the freq to update on first run
4806 // calculate one sample of output.
4807 MoogFF_next(unit
, 1);
4810 void MoogFF_next(MoogFF
*unit
, int inNumSamples
)
4812 float *out
= ZOUT(0);
4816 k
= k
> 4.f
? 4.f
: (k
<0.f
? 0.f
: k
);
4818 // Load state from the struct
4819 float s1
= unit
->m_s1
;
4820 float s2
= unit
->m_s2
;
4821 float s3
= unit
->m_s3
;
4822 float s4
= unit
->m_s4
;
4823 float freq
= unit
->m_freq
;///
4825 // Reset filter state if requested
4827 s1
= s2
= s3
= s4
= 0.f
;
4829 float a1
= unit
->m_a1
, b0
= unit
->m_b0
; // Filter coefficient parameters
4830 float o
, u
; // System's null response, loop input
4832 // Update filter coefficients, but only if freq changes since it involves some expensive operations
4833 if(freq
!= IN0(1)) {
4835 //Print("Updated freq to %g\n", freq);
4836 double wcD
=unit
->m_wcD
;
4837 double T
= SAMPLEDUR
;
4838 wcD
= 2.0 * tan ( T
* PI
* freq
) * SAMPLERATE
;
4840 wcD
= 0; // Protect against negative cutoff freq
4841 double TwcD
= T
*wcD
;
4842 b0
= (float)(TwcD
/(TwcD
+ 2.));
4843 a1
= (float)((TwcD
- 2.)/(TwcD
+ 2.));
4844 unit
->m_freq
= freq
;
4851 // compute loop values
4852 o
= s4
+ b0
*(s3
+ b0
*(s2
+ b0
*s1
));
4853 float ins
= ZXP(in
);
4854 float outs
= (b0
*b0
*b0
*b0
*ins
+ o
)/(1.f
+ b0
*b0
*b0
*b0
*k
);
4858 // update 1st order filter states
4860 float future
= b0
*past
+ s1
;
4861 s1
= b0
*past
- a1
*future
;
4864 future
= b0
*past
+ s2
;
4865 s2
= b0
*past
- a1
*future
;
4868 future
= b0
*past
+ s3
;
4869 s3
= b0
*past
- a1
*future
;
4871 s4
= b0
*future
- a1
*outs
;
4884 struct BLowPass
: public Unit
4886 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
4892 void BLowPass_next_kk(BLowPass
*unit
, int inNumSamples
);
4893 void BLowPass_next_aa(BLowPass
*unit
, int inNumSamples
);
4894 void BLowPass_Ctor(BLowPass
* unit
);
4898 void BLowPass_Ctor(BLowPass
* unit
)
4900 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
4901 SETCALC(BLowPass_next_aa
);
4903 SETCALC(BLowPass_next_kk
);
4904 float rq
= unit
->m_rq
= ZIN0(2);
4905 float freq
= unit
->m_freq
= ZIN0(1);
4906 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
4907 double cosw0
= cos(w0
);
4908 double i
= 1. - cosw0
;
4909 double alpha
= sin(w0
) * 0.5 * (double)rq
;
4910 double b0rz
= 1. / (1. + alpha
);
4911 double a0
= unit
->m_a0
= i
* 0.5 * b0rz
;
4912 unit
->m_a1
= i
* b0rz
;
4914 unit
->m_b1
= cosw0
* 2. * b0rz
;
4915 unit
->m_b2
= (1. - alpha
) * -b0rz
;
4920 BLowPass_next_kk(unit
, 1);
4924 void BLowPass_next_aa(BLowPass
*unit
, int inNumSamples
)
4926 float *out
= ZOUT(0);
4928 float *freq
= ZIN(1);
4931 double a0
, a1
, a2
, b1
, b2
, w0
, cosw0
, i
, alpha
, b0rz
;
4933 float nextfreq
, nextrq
;
4944 LOOP(unit
->mRate
->mFilterLoops
,
4945 nextfreq
= ZXP(freq
);
4947 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
4948 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
4951 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
4952 b0rz
= 1. / (1. + alpha
);
4953 a0
= i
* 0.5 * b0rz
;
4956 b1
= cosw0
* 2. * b0rz
;
4957 b2
= (1. - alpha
) * -b0rz
;
4958 unit
->m_freq
= nextfreq
;
4959 unit
->m_rq
= nextrq
;
4961 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
4962 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
4964 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
4965 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
4967 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
4968 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
4971 LOOP(unit
->mRate
->mFilterRemain
,
4972 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
4973 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
4976 unit
->m_freq
= ZXP(freq
);
4977 unit
->m_rq
= ZXP(rq
);
4985 unit
->m_y1
= zapgremlins(y1
);
4986 unit
->m_y2
= zapgremlins(y2
);
4990 void BLowPass_next_kk(BLowPass
*unit
, int inNumSamples
)
4992 float *out
= ZOUT(0);
4994 float nextfreq
= ZIN0(1);
4995 float nextrq
= ZIN0(2);
4997 double a0
, a1
, a2
, b1
, b2
;
4998 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextcosw0
, nexti
, nextalpha
, nextb0rz
;
5000 double y1
= unit
->m_y1
;
5001 double y2
= unit
->m_y2
;
5002 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5010 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)){
5011 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5012 nextcosw0
= cos(nextw0
);
5013 nexti
= 1. - nextcosw0
;
5014 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
5015 nextb0rz
= 1. / (1. + nextalpha
);
5016 nexta0
= nexti
* 0.5 * nextb0rz
;
5017 nexta1
= nexti
* nextb0rz
;
5019 nextb1
= nextcosw0
* 2. * nextb0rz
;
5020 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
5021 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
;
5022 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
;
5023 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
;
5024 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
;
5025 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
;
5026 unit
->m_freq
= nextfreq
;
5027 unit
->m_rq
= nextrq
;
5028 LOOP(unit
->mRate
->mFilterLoops
,
5029 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5030 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5032 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5033 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5035 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5036 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5043 LOOP(unit
->mRate
->mFilterRemain
,
5044 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5045 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5051 LOOP(unit
->mRate
->mFilterLoops
,
5052 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5053 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5055 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5056 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5058 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5059 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5061 LOOP(unit
->mRate
->mFilterRemain
,
5062 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5063 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5068 unit
->m_y1
= zapgremlins(y1
);
5069 unit
->m_y2
= zapgremlins(y2
);
5077 struct BHiPass
: public Unit
5079 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5086 void BHiPass_next_kk(BHiPass
*unit
, int inNumSamples
);
5087 void BHiPass_next_aa(BHiPass
*unit
, int inNumSamples
);
5088 void BHiPass_Ctor(BHiPass
* unit
);
5091 void BHiPass_Ctor(BHiPass
* unit
)
5093 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5094 SETCALC(BHiPass_next_aa
);
5096 SETCALC(BHiPass_next_kk
);
5097 float freq
= unit
->m_freq
= ZIN0(1);
5098 float rq
= unit
->m_rq
= ZIN0(2);
5099 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5100 double cosw0
= cos(w0
);
5101 double i
= 1. + cosw0
;
5102 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5103 double b0rz
= 1. / (1. + alpha
);
5104 double a0
= unit
->m_a0
= i
* 0.5 * b0rz
;
5105 unit
->m_a1
= -i
* b0rz
;
5107 unit
->m_b1
= cosw0
* 2. * b0rz
;
5108 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5113 BHiPass_next_kk(unit
, 1);
5117 void BHiPass_next_aa(BHiPass
*unit
, int inNumSamples
)
5119 float *out
= ZOUT(0);
5121 float *freq
= ZIN(1);
5124 double a0
, a1
, a2
, b1
, b2
, w0
, cosw0
, i
, alpha
, b0rz
;
5126 float nextfreq
, nextrq
;
5137 LOOP(unit
->mRate
->mFilterLoops
,
5138 nextfreq
= ZXP(freq
);
5140 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5141 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5144 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
5145 b0rz
= 1. / (1. + alpha
);
5146 a0
= i
* 0.5 * b0rz
;
5149 b1
= cosw0
* 2. * b0rz
;
5150 b2
= (1. - alpha
) * -b0rz
;
5151 unit
->m_freq
= nextfreq
;
5152 unit
->m_rq
= nextrq
;
5154 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5155 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5157 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5158 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5160 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5161 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5163 LOOP(unit
->mRate
->mFilterRemain
,
5164 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5165 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5175 unit
->m_y1
= zapgremlins(y1
);
5176 unit
->m_y2
= zapgremlins(y2
);
5180 void BHiPass_next_kk(BHiPass
*unit
, int inNumSamples
)
5182 float *out
= ZOUT(0);
5184 float nextfreq
= ZIN0(1);
5185 float nextrq
= ZIN0(2);
5187 double a0
, a1
, a2
, b1
, b2
;
5188 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextcosw0
, nexti
, nextalpha
, nextb0rz
;
5190 double y1
= unit
->m_y1
;
5191 double y2
= unit
->m_y2
;
5192 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5200 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)){
5201 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5202 nextcosw0
= cos(nextw0
);
5203 nexti
= 1. + nextcosw0
;
5204 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
5205 nextb0rz
= 1. / (1. + nextalpha
);
5206 nexta0
= nexti
* 0.5 * nextb0rz
;
5207 nexta1
= -nexti
* nextb0rz
;
5209 nextb1
= nextcosw0
* 2. * nextb0rz
;
5210 nextb2
= (1. - nextalpha
) * -nextb0rz
;
5211 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5212 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5213 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5214 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5215 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5217 LOOP(unit
->mRate
->mFilterLoops
,
5218 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5219 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5221 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5222 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5224 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5225 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5232 LOOP(unit
->mRate
->mFilterRemain
,
5233 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5234 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5238 unit
->m_freq
= nextfreq
;
5239 unit
->m_rq
= nextrq
;
5248 LOOP(unit
->mRate
->mFilterLoops
,
5249 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5250 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5252 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5253 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5255 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5256 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5258 LOOP(unit
->mRate
->mFilterRemain
,
5259 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5260 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5266 unit
->m_y1
= zapgremlins(y1
);
5267 unit
->m_y2
= zapgremlins(y2
);
5272 struct BBandPass
: public Unit
5274 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5280 void BBandPass_next_kk(BBandPass
*unit
, int inNumSamples
);
5281 void BBandPass_next_aa(BBandPass
*unit
, int inNumSamples
);
5282 void BBandPass_Ctor(BBandPass
* unit
);
5285 void BBandPass_Ctor(BBandPass
* unit
)
5287 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5288 SETCALC(BBandPass_next_aa
);
5290 SETCALC(BBandPass_next_kk
);
5291 float freq
= unit
->m_freq
= ZIN0(1);
5292 float bw
= unit
->m_bw
= ZIN0(2);
5294 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5295 double sinw0
= sin(w0
);
5296 double alpha
= sinw0
* (sinh((0.34657359027997 * (double)bw
* w0
) / sinw0
));
5297 double b0rz
= 1. / (1. + alpha
);
5298 double a0
= unit
->m_a0
= alpha
* b0rz
;
5301 unit
->m_b1
= cos(w0
) * 2. * b0rz
;
5302 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5308 BBandPass_next_kk(unit
, 1);
5312 void BBandPass_next_aa(BBandPass
*unit
, int inNumSamples
)
5314 float *out
= ZOUT(0);
5316 float *freq
= ZIN(1);
5319 double a0
, a1
, a2
, b1
, b2
, w0
, sinw0
, alpha
, b0rz
;
5321 float nextfreq
, nextbw
;
5332 LOOP(unit
->mRate
->mFilterLoops
,
5333 nextfreq
= ZXP(freq
);
5335 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)) {
5336 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5338 alpha
= sinw0
* (sinh((0.34657359027997 * (double)nextbw
* w0
) / sinw0
));
5339 b0rz
= 1. / (1. + alpha
);
5343 b1
= cos(w0
) * 2. * b0rz
;
5344 b2
= (1. - alpha
) * -b0rz
;
5345 unit
->m_freq
= ZXP(freq
);
5346 unit
->m_bw
= ZXP(bw
);
5348 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5349 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5351 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5352 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5354 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5355 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5357 LOOP(unit
->mRate
->mFilterRemain
,
5358 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5359 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5362 unit
->m_freq
= nextfreq
;
5363 unit
->m_bw
= nextbw
;
5371 unit
->m_y1
= zapgremlins(y1
);
5372 unit
->m_y2
= zapgremlins(y2
);
5376 void BBandPass_next_kk(BBandPass
*unit
, int inNumSamples
)
5378 float *out
= ZOUT(0);
5380 float nextfreq
= ZIN0(1);
5381 float nextbw
= ZIN0(2);
5383 double a0
, a1
, a2
, b1
, b2
;
5384 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5386 double y1
= unit
->m_y1
;
5387 double y2
= unit
->m_y2
;
5388 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5395 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)){
5396 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5397 nextalpha
= sin(nextw0
) * (sinh((0.34657359027997 * (double)nextbw
* nextw0
) / sin(nextw0
)));
5398 nextb0rz
= 1. / (1. + nextalpha
);
5399 nexta0
= nextalpha
* nextb0rz
;
5402 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
5403 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
5404 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5405 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5406 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5407 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5408 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5409 unit
->m_freq
= nextfreq
;
5410 unit
->m_bw
= nextbw
;
5411 LOOP(unit
->mRate
->mFilterLoops
,
5412 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5413 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5415 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5416 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5418 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5419 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5426 LOOP(unit
->mRate
->mFilterRemain
,
5427 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5428 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5433 LOOP(unit
->mRate
->mFilterLoops
,
5434 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5435 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5437 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5438 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5440 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5441 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5443 LOOP(unit
->mRate
->mFilterRemain
,
5444 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5445 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5456 unit
->m_y1
= zapgremlins(y1
);
5457 unit
->m_y2
= zapgremlins(y2
);
5461 struct BBandStop
: public Unit
5463 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5469 void BBandStop_next_kk(BBandStop
*unit
, int inNumSamples
);
5470 void BBandStop_next_aa(BBandStop
*unit
, int inNumSamples
);
5471 void BBandStop_Ctor(BBandStop
* unit
);
5474 void BBandStop_Ctor(BBandStop
* unit
)
5476 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5477 SETCALC(BBandStop_next_aa
);
5479 SETCALC(BBandStop_next_kk
);
5480 float freq
= unit
->m_freq
= ZIN0(1);
5481 float bw
= unit
->m_bw
= ZIN0(2);
5483 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5484 double sinw0
= sin(w0
);
5485 double alpha
= sinw0
* (sinh((0.34657359027997 * (double)bw
* w0
) / sinw0
));
5486 double b0rz
= 1. / (1. + alpha
);
5487 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5491 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5497 BBandStop_next_kk(unit
, 1);
5501 void BBandStop_next_aa(BBandStop
*unit
, int inNumSamples
)
5503 float *out
= ZOUT(0);
5505 float *freq
= ZIN(1);
5508 double a0
, a1
, a2
, b1
, b2
, w0
, sinw0
, alpha
, b0rz
;
5510 float nextfreq
, nextbw
;
5521 LOOP(unit
->mRate
->mFilterLoops
,
5522 nextfreq
= ZXP(freq
);
5524 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)) {
5525 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5527 alpha
= sinw0
* (sinh((0.34657359027997 * (double)nextbw
* w0
) / sinw0
));
5528 b0rz
= 1. / (1. + alpha
);
5529 b1
= 2. * b0rz
* cos(w0
);
5533 b2
= (1. - alpha
) * -b0rz
;
5534 unit
->m_freq
= ZXP(freq
);
5535 unit
->m_bw
= ZXP(bw
);
5537 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5538 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5540 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5541 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5543 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5544 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5546 LOOP(unit
->mRate
->mFilterRemain
,
5547 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5548 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5551 unit
->m_freq
= nextfreq
;
5552 unit
->m_bw
= nextbw
;
5560 unit
->m_y1
= zapgremlins(y1
);
5561 unit
->m_y2
= zapgremlins(y2
);
5565 void BBandStop_next_kk(BBandStop
*unit
, int inNumSamples
)
5567 float *out
= ZOUT(0);
5569 float nextfreq
= ZIN0(1);
5570 float nextbw
= ZIN0(2);
5572 double a0
, a1
, a2
, b1
, b2
;
5573 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5575 double y1
= unit
->m_y1
;
5576 double y2
= unit
->m_y2
;
5577 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5585 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)){
5586 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5587 nextalpha
= sin(nextw0
) * (sinh((0.34657359027997 * (double)nextbw
* nextw0
) / sin(nextw0
)));
5588 nextb0rz
= 1. / (1. + nextalpha
);
5589 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
5593 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
5594 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5595 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5596 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5597 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5598 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5599 unit
->m_freq
= nextfreq
;
5600 unit
->m_bw
= nextbw
;
5601 LOOP(unit
->mRate
->mFilterLoops
,
5602 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5603 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5605 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5606 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5608 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5609 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5616 LOOP(unit
->mRate
->mFilterRemain
,
5617 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5618 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5624 LOOP(unit
->mRate
->mFilterLoops
,
5625 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5626 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5628 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5629 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5631 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5632 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5634 LOOP(unit
->mRate
->mFilterRemain
,
5635 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5636 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5647 unit
->m_y1
= zapgremlins(y1
);
5648 unit
->m_y2
= zapgremlins(y2
);
5652 struct BPeakEQ
: public Unit
5654 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5655 float m_freq
, m_rq
, m_db
;
5660 void BPeakEQ_next_kkk(BPeakEQ
*unit
, int inNumSamples
);
5661 void BPeakEQ_next_aaa(BPeakEQ
*unit
, int inNumSamples
);
5662 void BPeakEQ_Ctor(BPeakEQ
* unit
);
5665 void BPeakEQ_Ctor(BPeakEQ
* unit
)
5667 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
5668 SETCALC(BPeakEQ_next_aaa
);
5670 SETCALC(BPeakEQ_next_kkk
);
5672 float freq
= unit
->m_freq
= ZIN0(1);
5673 float rq
= unit
->m_rq
= ZIN0(2);
5674 float db
= unit
->m_db
= ZIN0(3);
5675 double a
= pow(10., (double)db
* 0.025);
5676 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5677 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5678 double b0rz
= 1. / (1. + (alpha
/ a
));
5679 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5680 unit
->m_a0
= (1. + (alpha
* a
)) * b0rz
;
5682 unit
->m_a2
= (1. - (alpha
* a
)) * b0rz
;
5683 unit
->m_b2
= (1. - (alpha
/ a
)) * -b0rz
;
5688 BPeakEQ_next_kkk(unit
, 1);
5692 void BPeakEQ_next_aaa(BPeakEQ
*unit
, int inNumSamples
)
5694 float *out
= ZOUT(0);
5696 float *freq
= ZIN(1);
5700 double a0
, a1
, a2
, b1
, b2
, a
, w0
, alpha
, b0rz
;
5702 float nextfreq
, nextrq
, nextdb
;
5714 LOOP(unit
->mRate
->mFilterLoops
,
5715 nextfreq
= ZXP(freq
);
5718 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
) || (unit
->m_db
!= nextdb
)) {
5719 a
= pow(10., (double)nextdb
* 0.025);
5720 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5721 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
5722 b0rz
= 1. / (1. + (alpha
/ a
));
5723 b1
= 2. * b0rz
* cos(w0
);
5724 a0
= (1. + (alpha
* a
)) * b0rz
;
5726 a2
= (1. - (alpha
* a
)) * b0rz
;
5727 b2
= (1. - (alpha
/ a
)) * -b0rz
;
5728 unit
->m_freq
= nextfreq
;
5729 unit
->m_rq
= nextrq
;
5730 unit
->m_db
= nextdb
;
5732 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5733 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5735 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5736 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5738 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5739 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5741 LOOP(unit
->mRate
->mFilterRemain
,
5742 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5743 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5746 unit
->m_freq
= ZXP(freq
);
5747 unit
->m_rq
= ZXP(rq
);
5748 unit
->m_db
= ZXP(db
);
5756 unit
->m_y1
= zapgremlins(y1
);
5757 unit
->m_y2
= zapgremlins(y2
);
5761 void BPeakEQ_next_kkk(BPeakEQ
*unit
, int inNumSamples
)
5763 float *out
= ZOUT(0);
5765 float nextfreq
= ZIN0(1);
5766 float nextrq
= ZIN0(2);
5767 float nextdb
= ZIN0(3);
5769 double a0
, a1
, a2
, b1
, b2
, a
, w0
, alpha
, b0rz
;
5770 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
5781 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
) || (unit
->m_db
!= nextdb
)) {
5782 a
= pow(10., (double)nextdb
* 0.025);
5783 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5784 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
5785 b0rz
= 1. / (1. + (alpha
/ a
));
5786 nextb1
= 2. * b0rz
* cos(w0
);
5787 nexta0
= (1. + (alpha
* a
)) * b0rz
;
5789 nexta2
= (1. - (alpha
* a
)) * b0rz
;
5790 nextb2
= (1. - (alpha
/ a
)) * -b0rz
;
5791 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5792 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5793 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5794 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5795 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5796 unit
->m_freq
= nextfreq
;
5797 unit
->m_db
= nextdb
;
5798 unit
->m_rq
= nextrq
;
5799 LOOP(unit
->mRate
->mFilterLoops
,
5800 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5801 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5803 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5804 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5806 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5807 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5816 LOOP(unit
->mRate
->mFilterRemain
,
5817 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5818 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5824 LOOP(unit
->mRate
->mFilterLoops
,
5825 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5826 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5828 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5829 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5831 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5832 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5835 LOOP(unit
->mRate
->mFilterRemain
,
5836 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5837 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5848 unit
->m_y1
= zapgremlins(y1
);
5849 unit
->m_y2
= zapgremlins(y2
);
5853 struct BAllPass
: public Unit
5855 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5861 void BAllPass_next_kk(BAllPass
*unit
, int inNumSamples
);
5862 void BAllPass_next_aa(BAllPass
*unit
, int inNumSamples
);
5863 void BAllPass_Ctor(BAllPass
* unit
);
5866 void BAllPass_Ctor(BAllPass
* unit
)
5868 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5869 SETCALC(BAllPass_next_aa
);
5871 SETCALC(BAllPass_next_kk
);
5873 float freq
= unit
->m_freq
= ZIN0(1);
5874 float rq
= unit
->m_rq
= ZIN0(2);
5876 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5877 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5878 double b0rz
= 1. / (1. + alpha
);
5879 double a0
= unit
->m_a0
= (1. - alpha
) * b0rz
;
5880 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5889 BAllPass_next_kk(unit
, 1);
5893 void BAllPass_next_aa(BAllPass
*unit
, int inNumSamples
)
5895 float *out
= ZOUT(0);
5897 float *freq
= ZIN(1);
5900 double a0
, a1
, a2
, b1
, b2
, w0
, alpha
, b0rz
;
5902 float nextfreq
, nextrq
;
5913 LOOP(unit
->mRate
->mFilterLoops
,
5914 nextfreq
= ZXP(freq
);
5916 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5917 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5918 alpha
= sin(w0
) * (double)nextrq
* 0.5;
5919 b0rz
= 1. / (1. + alpha
);
5920 b1
= 2. * b0rz
* cos(w0
);
5921 a0
= (1. - alpha
) * b0rz
;
5925 unit
->m_freq
= nextfreq
;
5926 unit
->m_rq
= nextrq
;
5928 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5929 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5931 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5932 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5934 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5935 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5937 LOOP(unit
->mRate
->mFilterRemain
,
5938 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5939 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5942 unit
->m_freq
= ZXP(freq
);
5943 unit
->m_rq
= ZXP(rq
);
5951 unit
->m_y1
= zapgremlins(y1
);
5952 unit
->m_y2
= zapgremlins(y2
);
5956 void BAllPass_next_kk(BAllPass
*unit
, int inNumSamples
)
5958 float *out
= ZOUT(0);
5960 float nextfreq
= ZIN0(1);
5961 float nextrq
= ZIN0(2);
5963 double a0
, a1
, a2
, b1
, b2
;
5964 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5966 double y1
= unit
->m_y1
;
5967 double y2
= unit
->m_y2
;
5968 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5976 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5977 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5978 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
5979 nextb0rz
= 1. / (1. + nextalpha
);
5980 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
5981 nexta0
= (1. - nextalpha
) * nextb0rz
;
5985 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
;
5986 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
;
5987 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
;
5988 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
;
5989 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
;
5990 unit
->m_freq
= nextfreq
;
5991 unit
->m_rq
= nextrq
;
5992 LOOP(unit
->mRate
->mFilterLoops
,
5993 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5994 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5996 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5997 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5999 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6000 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6007 LOOP(unit
->mRate
->mFilterRemain
,
6008 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6009 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6015 LOOP(unit
->mRate
->mFilterLoops
,
6016 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6017 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6019 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6020 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6022 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6023 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6025 LOOP(unit
->mRate
->mFilterRemain
,
6026 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6027 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6038 unit
->m_y1
= zapgremlins(y1
);
6039 unit
->m_y2
= zapgremlins(y2
);
6044 struct BLowShelf
: public Unit
6046 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
6047 float m_freq
, m_rs
, m_db
;
6052 void BLowShelf_next_kkk(BLowShelf
*unit
, int inNumSamples
);
6053 void BLowShelf_next_aaa(BLowShelf
*unit
, int inNumSamples
);
6054 void BLowShelf_Ctor(BLowShelf
* unit
);
6057 void BLowShelf_Ctor(BLowShelf
* unit
)
6059 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
6060 SETCALC(BLowShelf_next_aaa
);
6062 SETCALC(BLowShelf_next_kkk
);
6064 float freq
= unit
->m_freq
= ZIN0(1);
6065 float rs
= unit
->m_rs
= ZIN0(2);
6066 float db
= unit
->m_db
= ZIN0(3);
6067 double a
= pow(10., (double)db
* 0.025);
6068 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
6069 double cosw0
= cos(w0
);
6070 double sinw0
= sin(w0
);
6071 double alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)rs
- 1.) + 2.);
6072 double i
= (a
+ 1.) * cosw0
;
6073 double j
= (a
- 1.) * cosw0
;
6074 double k
= 2. * sqrt(a
) * alpha
;
6075 double b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6076 unit
->m_a0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6077 unit
->m_a1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6078 unit
->m_a2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6079 unit
->m_b1
= 2. * ((a
- 1.) + i
) * b0rz
;
6080 unit
->m_b2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6086 BLowShelf_next_kkk(unit
, 1);
6090 void BLowShelf_next_aaa(BLowShelf
*unit
, int inNumSamples
)
6092 float *out
= ZOUT(0);
6094 float *freq
= ZIN(1);
6098 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6100 float nextfreq
, nextrs
, nextdb
;
6111 LOOP(unit
->mRate
->mFilterLoops
,
6112 nextfreq
= ZXP(freq
);
6115 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6116 a
= pow(10., (double)nextdb
* 0.025);
6117 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6120 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6121 i
= (a
+ 1.) * cosw0
;
6122 j
= (a
- 1.) * cosw0
;
6123 k
= 2. * sqrt(a
) * alpha
;
6124 b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6125 a0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6126 a1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6127 a2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6128 b1
= 2. * ((a
- 1.) + i
) * b0rz
;
6129 b2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6130 unit
->m_freq
= nextfreq
;
6131 unit
->m_rs
= nextrs
;
6132 unit
->m_db
= nextdb
;
6134 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6135 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6137 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6138 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6140 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6141 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6143 LOOP(unit
->mRate
->mFilterRemain
,
6144 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6145 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6148 unit
->m_freq
= ZXP(freq
);
6149 unit
->m_rs
= ZXP(rs
);
6150 unit
->m_db
= ZXP(db
);
6158 unit
->m_y1
= zapgremlins(y1
);
6159 unit
->m_y2
= zapgremlins(y2
);
6162 void BLowShelf_next_kkk(BLowShelf
*unit
, int inNumSamples
)
6164 float *out
= ZOUT(0);
6166 float nextfreq
= ZIN0(1);
6167 float nextrs
= ZIN0(2);
6168 float nextdb
= ZIN0(3);
6170 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6171 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
6182 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6183 a
= pow(10., (double)nextdb
* 0.025);
6184 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6187 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6188 i
= (a
+ 1.) * cosw0
;
6189 j
= (a
- 1.) * cosw0
;
6190 k
= 2. * sqrt(a
) * alpha
;
6191 b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6192 nexta0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6193 nexta1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6194 nexta2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6195 nextb1
= 2. * ((a
- 1.) + i
) * b0rz
;
6196 nextb2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6197 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
6198 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
6199 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
6200 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
6201 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
6202 unit
->m_freq
= nextfreq
;
6203 unit
->m_db
= nextdb
;
6204 unit
->m_rs
= nextrs
;
6205 LOOP(unit
->mRate
->mFilterLoops
,
6206 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6207 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6209 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6210 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6212 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6213 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6222 LOOP(unit
->mRate
->mFilterRemain
,
6223 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6224 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6230 LOOP(unit
->mRate
->mFilterLoops
,
6231 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6232 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6234 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6235 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6237 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6238 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6241 LOOP(unit
->mRate
->mFilterRemain
,
6242 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6243 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6254 unit
->m_y1
= zapgremlins(y1
);
6255 unit
->m_y2
= zapgremlins(y2
);
6259 struct BHiShelf
: public Unit
6261 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
6262 float m_freq
, m_rs
, m_db
;
6267 void BHiShelf_next_kkk(BHiShelf
*unit
, int inNumSamples
);
6268 void BHiShelf_next_aaa(BHiShelf
*unit
, int inNumSamples
);
6269 void BHiShelf_Ctor(BHiShelf
* unit
);
6272 void BHiShelf_Ctor(BHiShelf
* unit
)
6274 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
6275 SETCALC(BHiShelf_next_aaa
);
6277 SETCALC(BHiShelf_next_kkk
);
6279 float freq
= unit
->m_freq
= ZIN0(1);
6280 float rs
= unit
->m_rs
= ZIN0(2);
6281 float db
= unit
->m_db
= ZIN0(3);
6282 double a
= pow(10., (double)db
* 0.025);
6283 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
6284 double cosw0
= cos(w0
);
6285 double sinw0
= sin(w0
);
6286 double alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)rs
- 1.) + 2.);
6287 double i
= (a
+ 1.) * cosw0
;
6288 double j
= (a
- 1.) * cosw0
;
6289 double k
= 2. * sqrt(a
) * alpha
;
6291 double b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6292 unit
->m_a0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6293 unit
->m_a1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6294 unit
->m_a2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6295 unit
->m_b1
= -2. * ((a
- 1.) - i
) * b0rz
;
6296 unit
->m_b2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6302 BHiShelf_next_kkk(unit
, 1);
6306 void BHiShelf_next_aaa(BHiShelf
*unit
, int inNumSamples
)
6308 float *out
= ZOUT(0);
6310 float *freq
= ZIN(1);
6314 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6316 float nextfreq
, nextrs
, nextdb
;
6327 LOOP(unit
->mRate
->mFilterLoops
,
6328 nextfreq
= ZXP(freq
);
6331 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6332 a
= pow(10., (double)nextdb
* 0.025);
6333 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6336 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6337 i
= (a
+ 1.) * cosw0
;
6338 j
= (a
- 1.) * cosw0
;
6339 k
= 2. * sqrt(a
) * alpha
;
6340 b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6341 a0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6342 a1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6343 a2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6344 b1
= -2. * ((a
- 1.) - i
) * b0rz
;
6345 b2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6346 unit
->m_freq
= ZXP(freq
);
6347 unit
->m_rs
= ZXP(rs
);
6348 unit
->m_db
= ZXP(db
);
6350 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6351 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6353 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6354 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6356 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6357 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6359 LOOP(unit
->mRate
->mFilterRemain
,
6360 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6361 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6364 unit
->m_freq
= ZXP(freq
);
6365 unit
->m_rs
= ZXP(rs
);
6366 unit
->m_db
= ZXP(db
);
6374 unit
->m_y1
= zapgremlins(y1
);
6375 unit
->m_y2
= zapgremlins(y2
);
6378 void BHiShelf_next_kkk(BHiShelf
*unit
, int inNumSamples
)
6380 float *out
= ZOUT(0);
6382 float nextfreq
= ZIN0(1);
6383 float nextrs
= ZIN0(2);
6384 float nextdb
= ZIN0(3);
6386 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6387 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
6398 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6399 a
= pow(10., (double)nextdb
* 0.025);
6400 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6403 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6404 i
= (a
+ 1.) * cosw0
;
6405 j
= (a
- 1.) * cosw0
;
6406 k
= 2. * sqrt(a
) * alpha
;
6407 b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6408 nexta0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6409 nexta1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6410 nexta2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6411 nextb1
= -2. * ((a
- 1.) - i
) * b0rz
;
6412 nextb2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6413 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
6414 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
6415 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
6416 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
6417 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
6418 unit
->m_freq
= nextfreq
;
6419 unit
->m_db
= nextdb
;
6420 unit
->m_rs
= nextrs
;
6421 LOOP(unit
->mRate
->mFilterLoops
,
6422 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6423 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6425 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6426 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6428 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6429 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6438 LOOP(unit
->mRate
->mFilterRemain
,
6439 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6440 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6446 LOOP(unit
->mRate
->mFilterLoops
,
6447 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6448 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6450 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6451 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6453 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6454 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6457 LOOP(unit
->mRate
->mFilterRemain
,
6458 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6459 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6469 unit
->m_y1
= zapgremlins(y1
);
6470 unit
->m_y2
= zapgremlins(y2
);
6473 ////////////////////////////////////////////////////////////////////////////////////////////////////////
6478 DefineSimpleUnit(Ramp
);
6479 DefineSimpleUnit(Lag
);
6480 DefineSimpleUnit(Lag2
);
6481 DefineSimpleUnit(Lag3
);
6482 DefineSimpleUnit(LagUD
);
6483 DefineSimpleUnit(Lag2UD
);
6484 DefineSimpleUnit(Lag3UD
);
6485 DefineSimpleUnit(VarLag
);
6486 DefineSimpleUnit(OnePole
);
6487 DefineSimpleUnit(OneZero
);
6488 DefineSimpleUnit(TwoPole
);
6489 DefineSimpleUnit(TwoZero
);
6490 DefineSimpleUnit(Decay
);
6491 DefineSimpleUnit(Decay2
);
6492 DefineSimpleUnit(Flip
);
6493 DefineSimpleUnit(Delay1
);
6494 DefineSimpleUnit(Delay2
);
6495 DefineSimpleUnit(Integrator
);
6496 DefineSimpleUnit(LeakDC
);
6497 DefineSimpleUnit(LPZ1
);
6498 DefineSimpleUnit(HPZ1
);
6499 DefineSimpleUnit(LPZ2
);
6500 DefineSimpleUnit(HPZ2
);
6501 DefineSimpleUnit(BPZ2
);
6502 DefineSimpleUnit(BRZ2
);
6503 DefineSimpleUnit(APF
);
6504 DefineSimpleUnit(LPF
);
6505 DefineSimpleUnit(HPF
);
6506 DefineSimpleUnit(BPF
);
6507 DefineSimpleUnit(BRF
);
6508 DefineSimpleUnit(RLPF
);
6509 DefineSimpleUnit(RHPF
);
6511 DefineSimpleUnit(Slew
);
6512 DefineSimpleUnit(Slope
);
6514 DefineSimpleUnit(MidEQ
);
6515 DefineSimpleUnit(Median
);
6517 DefineSimpleUnit(Resonz
);
6518 DefineSimpleUnit(Ringz
);
6519 DefineSimpleUnit(Formlet
);
6521 DefineSimpleUnit(FOS
);
6522 DefineSimpleUnit(SOS
);
6524 DefineSimpleUnit(Compander
);
6525 DefineDtorUnit(Limiter
);
6526 DefineDtorUnit(Normalizer
);
6528 DefineSimpleUnit(Amplitude
);
6529 DefineSimpleUnit(DetectSilence
);
6531 DefineSimpleUnit(Hilbert
);
6532 DefineSimpleUnit(FreqShift
);
6533 DefineSimpleUnit(MoogFF
);
6535 /* BEQSuite UGens */
6536 DefineSimpleUnit(BLowPass
);
6537 DefineSimpleUnit(BHiPass
);
6538 DefineSimpleUnit(BBandPass
);
6539 DefineSimpleUnit(BBandStop
);
6540 DefineSimpleUnit(BPeakEQ
);
6541 DefineSimpleUnit(BAllPass
);
6542 DefineSimpleUnit(BLowShelf
);
6543 DefineSimpleUnit(BHiShelf
);
6547 //////////////////////////////////////////////////////////////////////////////////////////////////