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 float out0
= 0.5f
* (x0
+ x1
);
1748 float out1
= 0.5f
* (x1
+ x0
);
1750 float out2
= 0.5f
* (x0
+ x1
);
1752 float out3
= 0.5f
* (x1
+ x0
);
1759 LOOP(inNumSamples
& 3,
1761 ZXP(out
) = 0.5f
* (x0
+ x1
);
1768 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1771 void HPZ1_Ctor(HPZ1
* unit
)
1773 //printf("HPZ1_Reset\n");
1775 unit
->m_x1
= ZIN0(0);
1780 void HPZ1_next(HPZ1
* unit
, int inNumSamples
)
1782 //printf("HPZ1_next\n");
1784 float *out
= ZOUT(0);
1788 float x1
= unit
->m_x1
;
1790 LOOP(inNumSamples
>> 2,
1792 float out0
= 0.5f
* (x0
- x1
);
1794 float out1
= 0.5f
* (x1
- x0
);
1796 float out2
= 0.5f
* (x0
- x1
);
1798 float out3
= 0.5f
* (x1
- x0
);
1805 LOOP(inNumSamples
& 3,
1807 //printf("%d %d %g %g\n", this, inNumSamples, x0, x1);
1808 ZXP(out
) = 0.5f
* (x0
- x1
);
1815 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1817 void Slope_Ctor(Slope
* unit
)
1819 //printf("Slope_Reset\n");
1820 SETCALC(Slope_next
);
1821 unit
->m_x1
= ZIN0(0);
1822 //printf("Slope_Reset %g\n", unit->m_x1);
1823 Slope_next(unit
, 1);
1827 void Slope_next(Slope
* unit
, int inNumSamples
)
1829 //printf("Slope_next_a %g\n", unit->m_x1);
1831 float *out
= ZOUT(0);
1834 float x1
= unit
->m_x1
;
1836 float sr
= SAMPLERATE
;
1839 ZXP(out
) = sr
* (x0
- x1
);
1846 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1848 void Delay1_Ctor(Delay1
* unit
)
1850 //printf("Delay1_Reset\n");
1851 SETCALC(Delay1_next
);
1852 unit
->m_x1
= ZIN0(0);
1853 Delay1_next(unit
, 1);
1857 void Delay1_next(Delay1
* unit
, int inNumSamples
)
1859 //printf("Delay1_next_a\n");
1861 float *out
= ZOUT(0);
1865 float x1
= unit
->m_x1
;
1867 LOOP(inNumSamples
>> 2,
1877 LOOP(inNumSamples
& 3,
1886 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1888 void Flip_Ctor(Flip
* unit
)
1890 if (unit
->mBufLength
& 1) {
1891 SETCALC(Flip_next_odd
);
1892 Flip_next_odd(unit
, 1);
1894 SETCALC(Flip_next_even
);
1900 void Flip_next_even(Flip
* unit
, int inNumSamples
)
1902 float *out
= ZOUT(0);
1905 LOOP(inNumSamples
>> 1,
1906 ZXP(out
) = -ZXP(in
);
1911 void Flip_next_odd(Flip
* unit
, int inNumSamples
)
1913 float *out
= ZOUT(0);
1916 if (unit
->mWorld
->mBufCounter
& 1) {
1918 LOOP(inNumSamples
>> 1,
1919 ZXP(out
) = -ZXP(in
);
1923 LOOP(inNumSamples
>> 1,
1924 ZXP(out
) = -ZXP(in
);
1927 ZXP(out
) = -ZXP(in
);
1931 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1933 void Delay2_Ctor(Delay2
* unit
)
1935 SETCALC(Delay2_next
);
1936 unit
->m_x1
= ZIN0(0);
1941 void Delay2_next(Delay2
* unit
, int inNumSamples
)
1943 float *out
= ZOUT(0);
1947 float x1
= unit
->m_x1
;
1948 float x2
= unit
->m_x2
;
1950 LOOP(unit
->mRate
->mFilterLoops
,
1958 LOOP(unit
->mRate
->mFilterRemain
,
1969 ////////////////////////////////////////////////////////////////////////////////////////////////////////
1972 void LPZ2_Ctor(LPZ2
* unit
)
1974 //printf("LPZ2_Reset\n");
1976 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
1983 void LPZ2_next(LPZ2
* unit
, int inNumSamples
)
1985 //printf("LPZ2_next_a\n");
1987 float *out
= ZOUT(0);
1991 float x1
= unit
->m_x1
;
1992 float x2
= unit
->m_x2
;
1994 LOOP(unit
->mRate
->mFilterLoops
,
1996 float out0
= (x0
+ 2.f
* x1
+ x2
) * 0.25f
;
1998 float out1
= (x2
+ 2.f
* x0
+ x1
) * 0.25f
;
2000 float out2
= (x1
+ 2.f
* x2
+ x0
) * 0.25f
;
2006 LOOP(unit
->mRate
->mFilterRemain
,
2008 ZXP(out
) = (x0
+ 2.f
* x1
+ x2
) * 0.25f
;
2017 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2019 void HPZ2_Ctor(HPZ2
* unit
)
2021 //printf("HPZ2_Reset\n");
2023 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
2030 void HPZ2_next(HPZ2
* unit
, int inNumSamples
)
2032 //printf("HPZ2_next_a\n");
2034 float *out
= ZOUT(0);
2038 float x1
= unit
->m_x1
;
2039 float x2
= unit
->m_x2
;
2041 LOOP(unit
->mRate
->mFilterLoops
,
2043 float out0
= (x0
- 2.f
* x1
+ x2
) * 0.25f
;
2045 float out1
= (x2
- 2.f
* x0
+ x1
) * 0.25f
;
2047 float out2
= (x1
- 2.f
* x2
+ x0
) * 0.25f
;
2052 LOOP(unit
->mRate
->mFilterRemain
,
2054 ZXP(out
) = (x0
- 2.f
* x1
+ x2
) * 0.25f
;
2063 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2065 void BPZ2_Ctor(BPZ2
* unit
)
2067 //printf("BPZ2_Reset\n");
2069 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
2076 void BPZ2_next(BPZ2
* unit
, int inNumSamples
)
2078 //printf("BPZ2_next_a\n");
2080 float *out
= ZOUT(0);
2084 float x1
= unit
->m_x1
;
2085 float x2
= unit
->m_x2
;
2087 LOOP(unit
->mRate
->mFilterLoops
,
2089 ZXP(out
) = (x0
- x2
) * 0.5f
;
2091 ZXP(out
) = (x2
- x1
) * 0.5f
;
2093 ZXP(out
) = (x1
- x0
) * 0.5f
;
2095 LOOP(unit
->mRate
->mFilterRemain
,
2097 ZXP(out
) = (x0
- x2
) * 0.5f
;
2106 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2108 void BRZ2_Ctor(BRZ2
* unit
)
2110 //printf("BRZ2_Reset\n");
2112 unit
->m_x1
= unit
->m_x2
= ZIN0(0);
2119 void BRZ2_next(BRZ2
* unit
, int inNumSamples
)
2121 //printf("BRZ2_next_a\n");
2123 float *out
= ZOUT(0);
2127 float x1
= unit
->m_x1
;
2128 float x2
= unit
->m_x2
;
2130 LOOP(unit
->mRate
->mFilterLoops
,
2132 ZXP(out
) = (x0
+ x2
) * 0.5f
;
2134 ZXP(out
) = (x2
+ x1
) * 0.5f
;
2136 ZXP(out
) = (x1
+ x0
) * 0.5f
;
2138 LOOP(unit
->mRate
->mFilterRemain
,
2140 ZXP(out
) = (x0
+ x2
) * 0.5f
;
2149 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2151 void Slew_Ctor(Slew
* unit
)
2153 //printf("Slew_Reset\n");
2155 unit
->mLevel
= ZIN0(0);
2160 void Slew_next(Slew
* unit
, int inNumSamples
)
2162 //printf("Slew_next_a\n");
2164 float sampleDur
= unit
->mRate
->mSampleDur
;
2165 float *out
= ZOUT(0);
2167 float upf
= ZIN0(1) * sampleDur
;
2168 float dnf
= 0.f
- ZIN0(2) * sampleDur
;
2169 float level
= unit
->mLevel
;
2171 float slope
= ZXP(in
) - level
;
2172 level
+= sc_clip(slope
, dnf
, upf
);
2175 unit
->mLevel
= level
;
2178 /*void Slew_next_1(Slew* unit, int inNumSamples)
2180 //printf("Slew_next_a\n");
2182 float *out = ZOUT(0);
2184 float upf = ZIN0(1);
2185 float dnf = ZIN0(2);
2186 float level = unit->mLevel;
2187 float slope = ZXP(in) - level;
2188 if (slope > upf) slope = upf;
2189 else if (slope < dnf) slope = dnf;
2192 unit->mLevel = level;
2196 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2198 void RLPF_Ctor(RLPF
* unit
)
2200 //printf("RLPF_Reset\n");
2201 if (unit
->mBufLength
== 1) {
2202 SETCALC(RLPF_next_1
);
2213 unit
->m_reson
= 0.f
;
2214 RLPF_next_1(unit
, 1);
2218 void RLPF_next(RLPF
* unit
, int inNumSamples
)
2220 //printf("RLPF_next\n");
2222 float *out
= ZOUT(0);
2224 float freq
= ZIN0(1);
2225 float reson
= ZIN0(2);
2228 float y1
= unit
->m_y1
;
2229 float y2
= unit
->m_y2
;
2230 float a0
= unit
->m_a0
;
2231 float b1
= unit
->m_b1
;
2232 float b2
= unit
->m_b2
;
2234 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2236 float qres
= sc_max(0.001, reson
);
2237 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2239 float D
= tan(pfreq
* qres
* 0.5);
2240 float C
= ((1.f
-D
)/(1.f
+D
));
2241 float cosf
= cos(pfreq
);
2243 float next_b1
= (1.f
+ C
) * cosf
;
2245 float next_a0
= (1.f
+ C
- next_b1
) * .25;
2246 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2248 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2249 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2250 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2251 LOOP(unit
->mRate
->mFilterLoops
,
2252 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2253 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2255 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2256 ZXP(out
) = y2
+ 2.f
* y0
+ y1
;
2258 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2259 ZXP(out
) = y1
+ 2.f
* y2
+ y0
;
2265 LOOP(unit
->mRate
->mFilterRemain
,
2266 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2267 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2272 unit
->m_freq
= freq
;
2273 unit
->m_reson
= reson
;
2278 LOOP(unit
->mRate
->mFilterLoops
,
2279 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2280 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2282 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2283 ZXP(out
) = y2
+ 2.f
* y0
+ y1
;
2285 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2286 ZXP(out
) = y1
+ 2.f
* y2
+ y0
;
2288 LOOP(unit
->mRate
->mFilterRemain
,
2289 y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2290 ZXP(out
) = y0
+ 2.f
* y1
+ y2
;
2295 unit
->m_y1
= zapgremlins(y1
);
2296 unit
->m_y2
= zapgremlins(y2
);
2300 void RLPF_next_1(RLPF
* unit
, int inNumSamples
)
2302 //printf("RLPF_next_1\n");
2305 float freq
= ZIN0(1);
2306 float reson
= ZIN0(2);
2309 float y1
= unit
->m_y1
;
2310 float y2
= unit
->m_y2
;
2311 float a0
= unit
->m_a0
;
2312 float b1
= unit
->m_b1
;
2313 float b2
= unit
->m_b2
;
2315 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2316 float qres
= sc_max(0.001f
, reson
);
2317 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2319 float D
= tan(pfreq
* qres
* 0.5f
);
2320 float C
= ((1.f
-D
)/(1.f
+D
));
2321 float cosf
= cos(pfreq
);
2323 b1
= (1.f
+ C
) * cosf
;
2325 a0
= (1.f
+ C
- b1
) * .25f
;
2327 y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2328 ZOUT0(0) = y0
+ 2.f
* y1
+ y2
;
2332 unit
->m_freq
= freq
;
2333 unit
->m_reson
= reson
;
2338 y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2339 ZOUT0(0) = y0
+ 2.f
* y1
+ y2
;
2343 unit
->m_y1
= zapgremlins(y1
);
2344 unit
->m_y2
= zapgremlins(y2
);
2349 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2351 void RHPF_Ctor(RHPF
* unit
)
2353 if (unit
->mBufLength
== 1)
2354 SETCALC(RHPF_next_1
);
2364 unit
->m_reson
= 0.f
;
2365 RHPF_next_1(unit
, 1);
2369 void RHPF_next(RHPF
* unit
, int inNumSamples
)
2371 //printf("RHPFs_next\n");
2373 float *out
= ZOUT(0);
2375 float freq
= ZIN0(1);
2376 float reson
= ZIN0(2);
2378 double y1
= unit
->m_y1
;
2379 double y2
= unit
->m_y2
;
2380 double a0
= unit
->m_a0
;
2381 double b1
= unit
->m_b1
;
2382 double b2
= unit
->m_b2
;
2384 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2385 float qres
= sc_max(0.001f
, reson
);
2386 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2388 double D
= tan(pfreq
* qres
* 0.5f
);
2389 double C
= ((1.-D
)/(1.+D
));
2390 double cosf
= cos(pfreq
);
2392 double next_b1
= (1. + C
) * cosf
;
2393 double next_b2
= -C
;
2394 double next_a0
= (1. + C
+ next_b1
) * .25;
2396 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2398 double a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2399 double b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2400 double b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2401 LOOP(unit
->mRate
->mFilterLoops
,
2402 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2403 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2405 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2406 ZXP(out
) = y2
- 2.f
* y0
+ y1
;
2408 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2409 ZXP(out
) = y1
- 2.f
* y2
+ y0
;
2415 LOOP(unit
->mRate
->mFilterRemain
,
2416 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2417 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2422 unit
->m_freq
= freq
;
2423 unit
->m_reson
= reson
;
2428 LOOP(unit
->mRate
->mFilterLoops
,
2429 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2430 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2432 y2
= a0
* ZXP(in
) + b1
* y0
+ b2
* y1
;
2433 ZXP(out
) = y2
- 2.f
* y0
+ y1
;
2435 y1
= a0
* ZXP(in
) + b1
* y2
+ b2
* y0
;
2436 ZXP(out
) = y1
- 2.f
* y2
+ y0
;
2438 LOOP(unit
->mRate
->mFilterRemain
,
2439 double y0
= a0
* ZXP(in
) + b1
* y1
+ b2
* y2
;
2440 ZXP(out
) = y0
- 2.f
* y1
+ y2
;
2445 unit
->m_y1
= zapgremlins(y1
);
2446 unit
->m_y2
= zapgremlins(y2
);
2449 void RHPF_next_1(RHPF
* unit
, int inNumSamples
)
2451 //printf("RHPFs_next_1\n");
2454 float freq
= ZIN0(1);
2455 float reson
= ZIN0(2);
2457 double y1
= unit
->m_y1
;
2458 double y2
= unit
->m_y2
;
2459 double a0
= unit
->m_a0
;
2460 double b1
= unit
->m_b1
;
2461 double b2
= unit
->m_b2
;
2463 if (freq
!= unit
->m_freq
|| reson
!= unit
->m_reson
) {
2464 float qres
= sc_max(0.001f
, reson
);
2465 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2467 double D
= tan(pfreq
* qres
* 0.5f
);
2468 double C
= ((1.-D
)/(1.+D
));
2469 double cosf
= cos(pfreq
);
2471 b1
= (1. + C
) * cosf
;
2473 a0
= (1. + C
+ b1
) * .25;
2475 double y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2476 ZOUT0(0) = y0
- 2.f
* y1
+ y2
;
2480 unit
->m_freq
= freq
;
2481 unit
->m_reson
= reson
;
2486 double y0
= a0
* in
+ b1
* y1
+ b2
* y2
;
2487 ZOUT0(0) = y0
- 2.f
* y1
+ y2
;
2491 unit
->m_y1
= zapgremlins(y1
);
2492 unit
->m_y2
= zapgremlins(y2
);
2496 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2498 void LPF_Ctor(LPF
* unit
)
2500 if (unit
->mBufLength
== 1)
2501 SETCALC(LPF_next_1
);
2511 LPF_next_1(unit
, 1);
2515 void LPF_next(LPF
* unit
, int inNumSamples
)
2517 //printf("LPF_next\n");
2519 float *out
= ZOUT(0);
2521 float freq
= ZIN0(1);
2524 float y1
= unit
->m_y1
;
2525 float y2
= unit
->m_y2
;
2526 float a0
= unit
->m_a0
;
2527 float b1
= unit
->m_b1
;
2528 float b2
= unit
->m_b2
;
2530 if (freq
!= unit
->m_freq
) {
2532 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2534 float C
= 1.f
/ tan(pfreq
);
2536 float sqrt2C
= C
* sqrt2_f
;
2537 float next_a0
= 1.f
/ (1.f
+ sqrt2C
+ C2
);
2538 float next_b1
= -2.f
* (1.f
- C2
) * next_a0
;
2539 float next_b2
= -(1.f
- sqrt2C
+ C2
) * next_a0
;
2541 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2543 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2544 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2545 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2546 LOOP(unit
->mRate
->mFilterLoops
,
2547 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2548 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2550 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2551 ZXP(out
) = a0
* (y2
+ 2.f
* y0
+ y1
);
2553 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2554 ZXP(out
) = a0
* (y1
+ 2.f
* y2
+ y0
);
2560 LOOP(unit
->mRate
->mFilterRemain
,
2561 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2562 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2567 unit
->m_freq
= freq
;
2572 LOOP(unit
->mRate
->mFilterLoops
,
2573 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2574 float out0
= a0
* (y0
+ 2.f
* y1
+ y2
);
2576 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2577 float out1
= a0
* (y2
+ 2.f
* y0
+ y1
);
2579 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2580 float out2
= a0
* (y1
+ 2.f
* y2
+ y0
);
2585 LOOP(unit
->mRate
->mFilterRemain
,
2586 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2587 ZXP(out
) = a0
* (y0
+ 2.f
* y1
+ y2
);
2592 unit
->m_y1
= zapgremlins(y1
);
2593 unit
->m_y2
= zapgremlins(y2
);
2596 void LPF_next_1(LPF
* unit
, int inNumSamples
)
2598 //printf("LPF_next\n");
2600 float freq
= ZIN0(1);
2603 float y1
= unit
->m_y1
;
2604 float y2
= unit
->m_y2
;
2605 float a0
= unit
->m_a0
;
2606 float b1
= unit
->m_b1
;
2607 float b2
= unit
->m_b2
;
2609 if (freq
!= unit
->m_freq
) {
2611 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2613 float C
= 1.f
/ tan(pfreq
);
2615 float sqrt2C
= C
* sqrt2_f
;
2616 a0
= 1.f
/ (1.f
+ sqrt2C
+ C2
);
2617 b1
= -2.f
* (1.f
- C2
) * a0
;
2618 b2
= -(1.f
- sqrt2C
+ C2
) * a0
;
2620 y0
= in
+ b1
* y1
+ b2
* y2
;
2621 ZOUT0(0) = a0
* (y0
+ 2.f
* y1
+ y2
);
2625 unit
->m_freq
= freq
;
2631 y0
= in
+ b1
* y1
+ b2
* y2
;
2632 ZOUT0(0) = a0
* (y0
+ 2.f
* y1
+ y2
);
2637 unit
->m_y1
= zapgremlins(y1
);
2638 unit
->m_y2
= zapgremlins(y2
);
2642 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2644 void HPF_Ctor(HPF
* unit
)
2646 if (unit
->mBufLength
== 1)
2647 SETCALC(HPF_next_1
);
2655 unit
->m_freq
= -1e6f
;
2657 HPF_next_1(unit
, 1);
2661 void HPF_next(HPF
* unit
, int inNumSamples
)
2663 float *out
= ZOUT(0);
2665 float freq
= ZIN0(1);
2667 double y1
= unit
->m_y1
;
2668 double y2
= unit
->m_y2
;
2669 double a0
= unit
->m_a0
;
2670 double b1
= unit
->m_b1
;
2671 double b2
= unit
->m_b2
;
2673 if (freq
!= unit
->m_freq
) {
2674 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5;
2676 double C
= tan(pfreq
);
2678 double sqrt2C
= C
* sqrt2_f
;
2679 double next_a0
= 1. / (1. + sqrt2C
+ C2
);
2680 double next_b1
= 2. * (1. - C2
) * next_a0
;
2681 double next_b2
= -(1. - sqrt2C
+ C2
) * next_a0
;
2683 //post("%g %g %g %g %g %g %g %g %g %g\n", *freq, pfreq, qres, D, C, cosf, next_b1, next_b2, next_a0, y1, y2);
2685 double a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2686 double b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2687 double b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2688 LOOP(unit
->mRate
->mFilterLoops
,
2689 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2690 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2692 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2693 ZXP(out
) = a0
* (y2
- 2. * y0
+ y1
);
2695 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2696 ZXP(out
) = a0
* (y1
- 2. * y2
+ y0
);
2702 LOOP(unit
->mRate
->mFilterRemain
,
2703 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2704 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2709 unit
->m_freq
= freq
;
2714 LOOP(unit
->mRate
->mFilterLoops
,
2715 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2716 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2718 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2719 ZXP(out
) = a0
* (y2
- 2. * y0
+ y1
);
2721 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2722 ZXP(out
) = a0
* (y1
- 2. * y2
+ y0
);
2724 LOOP(unit
->mRate
->mFilterRemain
,
2725 double y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2726 ZXP(out
) = a0
* (y0
- 2. * y1
+ y2
);
2731 unit
->m_y1
= zapgremlins(y1
);
2732 unit
->m_y2
= zapgremlins(y2
);
2735 void HPF_next_1(HPF
* unit
, int inNumSamples
)
2737 double in
= ZIN0(0);
2738 double freq
= ZIN0(1);
2740 double y1
= unit
->m_y1
;
2741 double y2
= unit
->m_y2
;
2742 double a0
= unit
->m_a0
;
2743 double b1
= unit
->m_b1
;
2744 double b2
= unit
->m_b2
;
2746 if (freq
!= unit
->m_freq
) {
2747 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
* 0.5f
;
2749 double C
= tan(pfreq
);
2751 double sqrt2C
= C
* sqrt2_f
;
2752 a0
= 1. / (1. + sqrt2C
+ C2
);
2753 b1
= 2. * (1. - C2
) * a0
;
2754 b2
= -(1. - sqrt2C
+ C2
) * a0
;
2756 double y0
= in
+ b1
* y1
+ b2
* y2
;
2757 ZOUT0(0) = a0
* (y0
- 2. * y1
+ y2
);
2761 unit
->m_freq
= freq
;
2766 double y0
= in
+ b1
* y1
+ b2
* y2
;
2767 ZOUT0(0) = a0
* (y0
- 2. * y1
+ y2
);
2772 unit
->m_y1
= zapgremlins(y1
);
2773 unit
->m_y2
= zapgremlins(y2
);
2776 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2778 void BPF_Ctor(BPF
* unit
)
2780 //printf("BPF_Reset\n");
2781 if (unit
->mBufLength
== 1) {
2782 SETCALC(BPF_next_1
);
2794 BPF_next_1(unit
, 1);
2797 void BPF_next(BPF
* unit
, int inNumSamples
)
2799 //printf("BPF_next\n");
2801 float *out
= ZOUT(0);
2803 float freq
= ZIN0(1);
2807 float y1
= unit
->m_y1
;
2808 float y2
= unit
->m_y2
;
2809 float a0
= unit
->m_a0
;
2810 float b1
= unit
->m_b1
;
2811 float b2
= unit
->m_b2
;
2813 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2815 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2816 float pbw
= bw
* pfreq
* 0.5f
;
2818 float C
= 1.f
/ tan(pbw
);
2819 float D
= 2.f
* cos(pfreq
);
2821 float next_a0
= 1.f
/ (1.f
+ C
);
2822 float next_b1
= C
* D
* next_a0
;
2823 float next_b2
= (1.f
- C
) * next_a0
;
2825 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2826 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
2827 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2828 LOOP(unit
->mRate
->mFilterLoops
,
2829 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2830 ZXP(out
) = a0
* (y0
- y2
);
2832 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2833 ZXP(out
) = a0
* (y2
- y1
);
2835 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2836 ZXP(out
) = a0
* (y1
- y0
);
2842 LOOP(unit
->mRate
->mFilterRemain
,
2843 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2844 ZXP(out
) = a0
* (y0
- y2
);
2849 unit
->m_freq
= freq
;
2855 LOOP(unit
->mRate
->mFilterLoops
,
2856 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2857 ZXP(out
) = a0
* (y0
- y2
);
2859 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
2860 ZXP(out
) = a0
* (y2
- y1
);
2862 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
2863 ZXP(out
) = a0
* (y1
- y0
);
2865 LOOP(unit
->mRate
->mFilterRemain
,
2866 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
2867 ZXP(out
) = a0
* (y0
- y2
);
2872 unit
->m_y1
= zapgremlins(y1
);
2873 unit
->m_y2
= zapgremlins(y2
);
2876 void BPF_next_1(BPF
* unit
, int inNumSamples
)
2878 //printf("BPF_next_1\n");
2881 float freq
= ZIN0(1);
2885 float y1
= unit
->m_y1
;
2886 float y2
= unit
->m_y2
;
2887 float a0
= unit
->m_a0
;
2888 float b1
= unit
->m_b1
;
2889 float b2
= unit
->m_b2
;
2891 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2893 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2894 float pbw
= bw
* pfreq
* 0.5;
2896 float C
= 1.f
/ tan(pbw
);
2897 float D
= 2.f
* cos(pfreq
);
2899 float a0
= 1.f
/ (1.f
+ C
);
2900 float b1
= C
* D
* a0
;
2901 float b2
= (1.f
- C
) * a0
;
2903 y0
= in
+ b1
* y1
+ b2
* y2
;
2904 ZOUT0(0) = a0
* (y0
- y2
);
2908 unit
->m_freq
= freq
;
2914 y0
= in
+ b1
* y1
+ b2
* y2
;
2915 ZOUT0(0) = a0
* (y0
- y2
);
2919 unit
->m_y1
= zapgremlins(y1
);
2920 unit
->m_y2
= zapgremlins(y2
);
2924 ////////////////////////////////////////////////////////////////////////////////////////////////////////
2926 void BRF_Ctor(BRF
* unit
)
2928 //printf("BRF_Reset\n");
2929 if (unit
->mBufLength
== 1) {
2930 SETCALC(BRF_next_1
);
2941 BRF_next_1(unit
, 1);
2945 void BRF_next(BRF
* unit
, int inNumSamples
)
2947 //printf("BRF_next\n");
2949 float *out
= ZOUT(0);
2951 float freq
= ZIN0(1);
2956 float y1
= unit
->m_y1
;
2957 float y2
= unit
->m_y2
;
2958 float a0
= unit
->m_a0
;
2959 float a1
= unit
->m_a1
;
2960 float b2
= unit
->m_b2
;
2962 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
2963 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
2964 float pbw
= bw
* pfreq
* 0.5f
;
2967 float D
= 2.f
* cos(pfreq
);
2969 float next_a0
= 1.f
/ (1.f
+ C
);
2970 float next_a1
= -D
* next_a0
;
2971 float next_b2
= (1.f
- C
) * next_a0
;
2973 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
2974 float a1_slope
= (next_a1
- a1
) * unit
->mRate
->mFilterSlope
;
2975 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
2977 LOOP(unit
->mRate
->mFilterLoops
,
2979 y0
= ZXP(in
) - ay
- b2
* y2
;
2980 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
2983 y2
= ZXP(in
) - ay
- b2
* y1
;
2984 ZXP(out
) = a0
* (y2
+ y1
) + ay
;
2987 y1
= ZXP(in
) - ay
- b2
* y0
;
2988 ZXP(out
) = a0
* (y1
+ y0
) + ay
;
2994 LOOP(unit
->mRate
->mFilterRemain
,
2996 y0
= ZXP(in
) - ay
- b2
* y2
;
2997 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
3002 unit
->m_freq
= freq
;
3008 LOOP(unit
->mRate
->mFilterLoops
,
3010 y0
= ZXP(in
) - ay
- b2
* y2
;
3011 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
3014 y2
= ZXP(in
) - ay
- b2
* y1
;
3015 ZXP(out
) = a0
* (y2
+ y1
) + ay
;
3018 y1
= ZXP(in
) - ay
- b2
* y0
;
3019 ZXP(out
) = a0
* (y1
+ y0
) + ay
;
3021 LOOP(unit
->mRate
->mFilterRemain
,
3023 y0
= ZXP(in
) - ay
- b2
* y2
;
3024 ZXP(out
) = a0
* (y0
+ y2
) + ay
;
3029 unit
->m_y1
= zapgremlins(y1
);
3030 unit
->m_y2
= zapgremlins(y2
);
3035 void BRF_next_1(BRF
* unit
, int inNumSamples
)
3037 //printf("BRF_next_1\n");
3040 float freq
= ZIN0(1);
3045 float y1
= unit
->m_y1
;
3046 float y2
= unit
->m_y2
;
3047 float a0
= unit
->m_a0
;
3048 float a1
= unit
->m_a1
;
3049 float b2
= unit
->m_b2
;
3051 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
) {
3052 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3053 float pbw
= bw
* pfreq
* 0.5f
;
3056 float D
= 2.f
* cos(pfreq
);
3058 float a0
= 1.f
/ (1.f
+ C
);
3060 float b2
= (1.f
- C
) * a0
;
3063 y0
= in
- ay
- b2
* y2
;
3064 ZOUT0(0) = a0
* (y0
+ y2
) + ay
;
3068 unit
->m_freq
= freq
;
3076 y0
= in
- ay
- b2
* y2
;
3077 ZOUT0(0) = a0
* (y0
+ y2
) + ay
;
3082 unit
->m_y1
= zapgremlins(y1
);
3083 unit
->m_y2
= zapgremlins(y2
);
3087 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3089 void MidEQ_Ctor(MidEQ
* unit
)
3091 //printf("MidEQ_Reset\n");
3092 SETCALC(MidEQ_next
);
3102 MidEQ_next(unit
, 1);
3107 void MidEQ_next(MidEQ
* unit
, int inNumSamples
)
3109 //printf("MidEQ_next\n");
3111 float *out
= ZOUT(0);
3113 float freq
= ZIN0(1);
3118 float y1
= unit
->m_y1
;
3119 float y2
= unit
->m_y2
;
3120 float a0
= unit
->m_a0
;
3121 float b1
= unit
->m_b1
;
3122 float b2
= unit
->m_b2
;
3123 if (freq
!= unit
->m_freq
|| bw
!= unit
->m_bw
|| db
!= unit
->m_db
) {
3125 float amp
= sc_dbamp(db
) - 1.0f
;
3126 float pfreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3127 float pbw
= bw
* pfreq
* 0.5f
;
3129 float C
= 1.f
/ tan(pbw
);
3130 float D
= 2.f
* cos(pfreq
);
3132 float next_a0
= 1.f
/ (1.f
+ C
);
3133 float next_b1
= C
* D
* next_a0
;
3134 float next_b2
= (1.f
- C
) * next_a0
;
3136 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
3137 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
3138 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
3140 LOOP(unit
->mRate
->mFilterLoops
,
3142 y0
= zin
+ b1
* y1
+ b2
* y2
;
3143 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3146 y2
= zin
+ b1
* y0
+ b2
* y1
;
3147 ZXP(out
) = zin
+ a0
* (y2
- y1
);
3150 y1
= zin
+ b1
* y2
+ b2
* y0
;
3151 ZXP(out
) = zin
+ a0
* (y1
- y0
);
3157 LOOP(unit
->mRate
->mFilterRemain
,
3159 y0
= zin
+ b1
* y1
+ b2
* y2
;
3160 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3165 unit
->m_freq
= freq
;
3173 LOOP(unit
->mRate
->mFilterLoops
,
3175 y0
= zin
+ b1
* y1
+ b2
* y2
;
3176 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3179 y2
= zin
+ b1
* y0
+ b2
* y1
;
3180 ZXP(out
) = zin
+ a0
* (y2
- y1
);
3183 y1
= zin
+ b1
* y2
+ b2
* y0
;
3184 ZXP(out
) = zin
+ a0
* (y1
- y0
);
3186 LOOP(unit
->mRate
->mFilterRemain
,
3188 y0
= zin
+ b1
* y1
+ b2
* y2
;
3189 ZXP(out
) = zin
+ a0
* (y0
- y2
);
3194 unit
->m_y1
= zapgremlins(y1
);
3195 unit
->m_y2
= zapgremlins(y2
);
3198 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3200 static void Median_InitMedian(Median
* unit
, long size
, float value
);
3201 static float Median_InsertMedian(Median
* unit
, float value
);
3203 void Median_Ctor(Median
* unit
)
3205 //printf("Median_Reset\n");
3206 SETCALC(Median_next
);
3208 unit
->m_medianSize
= sc_clip((int)ZIN0(0), 0, kMAXMEDIANSIZE
);
3209 Median_InitMedian(unit
, unit
->m_medianSize
, in
);
3210 ZOUT0(0) = Median_InsertMedian(unit
, in
);
3214 float Median_InsertMedian(Median
* unit
, float value
)
3218 // keeps a sorted list of the previous n=size values
3219 // the oldest is removed and the newest is inserted.
3220 // values between the oldest and the newest are shifted over by one.
3222 // values and ages are both arrays that are 'size' long.
3223 // the median value is always values[size>>1]
3225 long last
= unit
->m_medianSize
- 1;
3226 // find oldest bin and age the other bins.
3227 for (int i
=0; i
<unit
->m_medianSize
; ++i
) {
3228 if (unit
->m_medianAge
[i
] == last
) { // is it the oldest bin ?
3231 unit
->m_medianAge
[i
]++; // age the bin
3234 // move values to fill in place of the oldest and make a space for the newest
3235 // search lower if value is too small for the open space
3236 while (pos
!= 0 && value
< unit
->m_medianValue
[pos
-1]) {
3237 unit
->m_medianValue
[pos
] = unit
->m_medianValue
[pos
-1];
3238 unit
->m_medianAge
[pos
] = unit
->m_medianAge
[pos
-1];
3241 // search higher if value is too big for the open space
3242 while (pos
!= last
&& value
> unit
->m_medianValue
[pos
+1]) {
3243 unit
->m_medianValue
[pos
] = unit
->m_medianValue
[pos
+1];
3244 unit
->m_medianAge
[pos
] = unit
->m_medianAge
[pos
+1];
3247 unit
->m_medianValue
[pos
] = value
;
3248 unit
->m_medianAge
[pos
] = 0; // this is the newest bin, age = 0
3249 return unit
->m_medianValue
[unit
->m_medianSize
>>1];
3252 void Median_InitMedian(Median
* unit
, long size
, float value
)
3254 // initialize the arrays with the first value
3255 unit
->m_medianSize
= size
;
3256 for (int i
=0; i
<size
; ++i
) {
3257 unit
->m_medianValue
[i
] = value
;
3258 unit
->m_medianAge
[i
] = i
;
3262 void Median_next(Median
* unit
, int inNumSamples
)
3264 //printf("Median_next_a\n");
3266 float *out
= ZOUT(0);
3270 ZXP(out
) = Median_InsertMedian(unit
, ZXP(in
));
3275 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3277 void Resonz_Ctor(Resonz
* unit
)
3279 //printf("Resonz_Reset\n");
3280 SETCALC(Resonz_next
);
3289 Resonz_next(unit
, 1);
3294 void Resonz_next(Resonz
* unit
, int inNumSamples
)
3296 //printf("Resonz_next\n");
3298 float *out
= ZOUT(0);
3300 float freq
= ZIN0(1);
3304 float y1
= unit
->m_y1
;
3305 float y2
= unit
->m_y2
;
3306 float a0
= unit
->m_a0
;
3307 float b1
= unit
->m_b1
;
3308 float b2
= unit
->m_b2
;
3310 if (freq
!= unit
->m_freq
|| rq
!= unit
->m_rq
) {
3311 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3312 float B
= ffreq
* rq
;
3313 float R
= 1.f
- B
* 0.5f
;
3314 float twoR
= 2.f
* R
;
3316 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3317 float b1_next
= twoR
* cost
;
3318 float b2_next
= -R2
;
3319 float a0_next
= (1.f
- R2
) * 0.5f
;
3320 float a0_slope
= (a0_next
- a0
) * unit
->mRate
->mFilterSlope
;
3321 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
3322 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
3323 LOOP(unit
->mRate
->mFilterLoops
,
3324 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3325 ZXP(out
) = a0
* (y0
- y2
);
3327 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3328 ZXP(out
) = a0
* (y2
- y1
);
3330 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3331 ZXP(out
) = a0
* (y1
- y0
);
3337 LOOP(unit
->mRate
->mFilterRemain
,
3338 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3339 ZXP(out
) = a0
* (y0
- y2
);
3344 unit
->m_freq
= freq
;
3346 unit
->m_a0
= a0_next
;
3347 unit
->m_b1
= b1_next
;
3348 unit
->m_b2
= b2_next
;
3350 LOOP(unit
->mRate
->mFilterLoops
,
3351 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3352 ZXP(out
) = a0
* (y0
- y2
);
3354 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3355 ZXP(out
) = a0
* (y2
- y1
);
3357 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3358 ZXP(out
) = a0
* (y1
- y0
);
3360 LOOP(unit
->mRate
->mFilterRemain
,
3361 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3362 ZXP(out
) = a0
* (y0
- y2
);
3367 unit
->m_y1
= zapgremlins(y1
);
3368 unit
->m_y2
= zapgremlins(y2
);
3372 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3374 void Ringz_Ctor(Ringz
* unit
)
3376 //printf("Ringz_ctor\n");
3377 SETCALC(Ringz_next
);
3383 unit
->m_decayTime
= 0.f
;
3385 Ringz_next(unit
, 1);
3390 void Ringz_next(Ringz
* unit
, int inNumSamples
)
3392 //printf("Ringz_next\n");
3394 float *out
= ZOUT(0);
3396 float freq
= ZIN0(1);
3397 float decayTime
= ZIN0(2);
3400 float y1
= unit
->m_y1
;
3401 float y2
= unit
->m_y2
;
3403 float b1
= unit
->m_b1
;
3404 float b2
= unit
->m_b2
;
3406 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
) {
3407 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3408 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3409 float twoR
= 2.f
* R
;
3411 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3412 float b1_next
= twoR
* cost
;
3413 float b2_next
= -R2
;
3414 float b1_slope
= (b1_next
- b1
) * unit
->mRate
->mFilterSlope
;
3415 float b2_slope
= (b2_next
- b2
) * unit
->mRate
->mFilterSlope
;
3416 LOOP(unit
->mRate
->mFilterLoops
,
3417 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3418 ZXP(out
) = a0
* (y0
- y2
);
3420 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3421 ZXP(out
) = a0
* (y2
- y1
);
3423 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3424 ZXP(out
) = a0
* (y1
- y0
);
3429 LOOP(unit
->mRate
->mFilterRemain
,
3430 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3431 ZXP(out
) = a0
* (y0
- y2
);
3436 unit
->m_freq
= freq
;
3437 unit
->m_decayTime
= decayTime
;
3438 unit
->m_b1
= b1_next
;
3439 unit
->m_b2
= b2_next
;
3441 LOOP(unit
->mRate
->mFilterLoops
,
3442 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3443 ZXP(out
) = a0
* (y0
- y2
);
3445 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3446 ZXP(out
) = a0
* (y2
- y1
);
3448 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3449 ZXP(out
) = a0
* (y1
- y0
);
3451 LOOP(unit
->mRate
->mFilterRemain
,
3452 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3453 ZXP(out
) = a0
* (y0
- y2
);
3458 unit
->m_y1
= zapgremlins(y1
);
3459 unit
->m_y2
= zapgremlins(y2
);
3463 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3465 void Formlet_Ctor(Formlet
* unit
)
3467 //printf("Formlet_Reset\n");
3468 if (unit
->mBufLength
== 1) {
3469 SETCALC(Formlet_next_1
);
3471 SETCALC(Formlet_next
);
3482 unit
->m_attackTime
= 0.f
;
3483 unit
->m_decayTime
= 0.f
;
3484 Formlet_next_1(unit
, 1);
3487 void Formlet_next(Formlet
* unit
, int inNumSamples
)
3489 //printf("Formlet_next\n");
3491 float *out
= ZOUT(0);
3493 float freq
= ZIN0(1);
3494 float attackTime
= ZIN0(2);
3495 float decayTime
= ZIN0(3);
3499 float y01
= unit
->m_y01
;
3500 float y11
= unit
->m_y11
;
3501 float y02
= unit
->m_y02
;
3502 float y12
= unit
->m_y12
;
3504 float b01
= unit
->m_b01
;
3505 float b11
= unit
->m_b11
;
3506 float b02
= unit
->m_b02
;
3507 float b12
= unit
->m_b12
;
3510 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
|| attackTime
!= unit
->m_attackTime
) {
3511 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3513 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3514 float twoR
= 2.f
* R
;
3516 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3517 float b01_next
= twoR
* cost
;
3518 float b02_next
= -R2
;
3519 float b01_slope
= (b01_next
- b01
) * unit
->mRate
->mFilterSlope
;
3520 float b02_slope
= (b02_next
- b02
) * unit
->mRate
->mFilterSlope
;
3522 R
= attackTime
== 0.f
? 0.f
: exp(log001
/(attackTime
* SAMPLERATE
));
3525 cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3526 float b11_next
= twoR
* cost
;
3527 float b12_next
= -R2
;
3528 float b11_slope
= (b11_next
- b11
) * unit
->mRate
->mFilterSlope
;
3529 float b12_slope
= (b12_next
- b12
) * unit
->mRate
->mFilterSlope
;
3531 LOOP(unit
->mRate
->mFilterLoops
,
3533 y00
= ain
+ b01
* y01
+ b02
* y02
;
3534 y10
= ain
+ b11
* y11
+ b12
* y12
;
3535 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3538 y02
= ain
+ b01
* y00
+ b02
* y01
;
3539 y12
= ain
+ b11
* y10
+ b12
* y11
;
3540 ZXP(out
) = 0.25f
* ((y02
- y01
) - (y12
- y11
));
3543 y01
= ain
+ b01
* y02
+ b02
* y00
;
3544 y11
= ain
+ b11
* y12
+ b12
* y10
;
3545 ZXP(out
) = 0.25f
* ((y01
- y00
) - (y11
- y10
));
3552 LOOP(unit
->mRate
->mFilterRemain
,
3554 y00
= ain
+ b01
* y01
+ b02
* y02
;
3555 y10
= ain
+ b11
* y11
+ b12
* y12
;
3556 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3563 unit
->m_freq
= freq
;
3564 unit
->m_attackTime
= attackTime
;
3565 unit
->m_decayTime
= decayTime
;
3566 unit
->m_b01
= b01_next
;
3567 unit
->m_b02
= b02_next
;
3568 unit
->m_b11
= b11_next
;
3569 unit
->m_b12
= b12_next
;
3571 LOOP(unit
->mRate
->mFilterLoops
,
3573 y00
= ain
+ b01
* y01
+ b02
* y02
;
3574 y10
= ain
+ b11
* y11
+ b12
* y12
;
3575 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3578 y02
= ain
+ b01
* y00
+ b02
* y01
;
3579 y12
= ain
+ b11
* y10
+ b12
* y11
;
3580 ZXP(out
) = 0.25f
* ((y02
- y01
) - (y12
- y11
));
3583 y01
= ain
+ b01
* y02
+ b02
* y00
;
3584 y11
= ain
+ b11
* y12
+ b12
* y10
;
3585 ZXP(out
) = 0.25f
* ((y01
- y00
) - (y11
- y10
));
3587 LOOP(unit
->mRate
->mFilterRemain
,
3589 y00
= ain
+ b01
* y01
+ b02
* y02
;
3590 y10
= ain
+ b11
* y11
+ b12
* y12
;
3591 ZXP(out
) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3604 void Formlet_next_1(Formlet
* unit
, int inNumSamples
)
3606 //printf("Formlet_next\n");
3609 float freq
= ZIN0(1);
3610 float attackTime
= ZIN0(2);
3611 float decayTime
= ZIN0(3);
3615 float y01
= unit
->m_y01
;
3616 float y11
= unit
->m_y11
;
3617 float y02
= unit
->m_y02
;
3618 float y12
= unit
->m_y12
;
3620 float b01
= unit
->m_b01
;
3621 float b11
= unit
->m_b11
;
3622 float b02
= unit
->m_b02
;
3623 float b12
= unit
->m_b12
;
3626 if (freq
!= unit
->m_freq
|| decayTime
!= unit
->m_decayTime
|| attackTime
!= unit
->m_attackTime
) {
3627 float ffreq
= freq
* unit
->mRate
->mRadiansPerSample
;
3629 float R
= decayTime
== 0.f
? 0.f
: exp(log001
/(decayTime
* SAMPLERATE
));
3630 float twoR
= 2.f
* R
;
3632 float cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3636 R
= attackTime
== 0.f
? 0.f
: exp(log001
/(attackTime
* SAMPLERATE
));
3639 cost
= (twoR
* cos(ffreq
)) / (1.f
+ R2
);
3644 y00
= ain
+ b01
* y01
+ b02
* y02
;
3645 y10
= ain
+ b11
* y11
+ b12
* y12
;
3646 ZOUT0(0) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3653 unit
->m_freq
= freq
;
3654 unit
->m_attackTime
= attackTime
;
3655 unit
->m_decayTime
= decayTime
;
3662 y00
= ain
+ b01
* y01
+ b02
* y02
;
3663 y10
= ain
+ b11
* y11
+ b12
* y12
;
3664 ZOUT0(0) = 0.25f
* ((y00
- y02
) - (y10
- y12
));
3678 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3680 void FOS_Ctor(FOS
* unit
)
3682 //printf("FOS_Reset\n");
3683 if (unit
->mBufLength
== 1) {
3684 SETCALC(FOS_next_1
);
3686 if (INRATE(1) == calc_FullRate
3687 && INRATE(2) == calc_FullRate
3688 && INRATE(3) == calc_FullRate
) {
3689 SETCALC(FOS_next_a
);
3691 SETCALC(FOS_next_k
);
3698 FOS_next_1(unit
, 1);
3701 void FOS_next_a(FOS
* unit
, int inNumSamples
)
3703 float *out
= ZOUT(0);
3709 float y1
= unit
->m_y1
;
3711 float y0
= ZXP(in
) + ZXP(b1
) * y1
;
3712 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
;
3715 unit
->m_y1
= zapgremlins(y1
);
3718 void FOS_next_1(FOS
* unit
, int inNumSamples
)
3725 float y1
= unit
->m_y1
;
3727 float y0
= in
+ b1
* y1
;
3728 ZOUT0(0) = a0
* y0
+ a1
* y1
;
3731 unit
->m_y1
= zapgremlins(y1
);
3735 void FOS_next_k(FOS
* unit
, int inNumSamples
)
3737 float *out
= ZOUT(0);
3739 float next_a0
= ZIN0(1);
3740 float next_a1
= ZIN0(2);
3741 float next_b1
= ZIN0(3);
3743 float y1
= unit
->m_y1
;
3744 float a0
= unit
->m_a0
;
3745 float a1
= unit
->m_a1
;
3746 float b1
= unit
->m_b1
;
3747 float a0_slope
= CALCSLOPE(next_a0
, a0
);
3748 float a1_slope
= CALCSLOPE(next_a1
, a1
);
3749 float b1_slope
= CALCSLOPE(next_b1
, b1
);
3751 float y0
= ZXP(in
) + b1
* y1
;
3752 ZXP(out
) = a0
* y0
+ a1
* y1
;
3759 unit
->m_y1
= zapgremlins(y1
);
3760 unit
->m_a0
= next_a0
;
3761 unit
->m_a1
= next_a1
;
3762 unit
->m_b1
= next_b1
;
3765 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3767 void SOS_Ctor(SOS
* unit
)
3769 // printf("SOS_Reset\n");
3770 if (unit
->mBufLength
!= 1) {
3771 if (INRATE(1) == calc_FullRate
3772 && INRATE(2) == calc_FullRate
3773 && INRATE(3) == calc_FullRate
3774 && INRATE(4) == calc_FullRate
3775 && INRATE(5) == calc_FullRate
) {
3776 SETCALC(SOS_next_a
);
3777 // printf("SOS_next_a\n");
3779 SETCALC(SOS_next_k
);
3780 // printf("SOS_next_k\n");
3783 SETCALC(SOS_next_1
);
3784 // printf("SOS_next_1\n");
3793 SOS_next_1(unit
, 1);
3796 void SOS_next_a(SOS
*unit
, int inNumSamples
)
3798 float *out
= ZOUT(0);
3807 float y1
= unit
->m_y1
;
3808 float y2
= unit
->m_y2
;
3809 LOOP(unit
->mRate
->mFilterLoops
,
3810 y0
= ZXP(in
) + ZXP(b1
) * y1
+ ZXP(b2
) * y2
;
3811 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
+ ZXP(a2
) * y2
;
3813 y2
= ZXP(in
) + ZXP(b1
) * y0
+ ZXP(b2
) * y1
;
3814 ZXP(out
) = ZXP(a0
) * y2
+ ZXP(a1
) * y0
+ ZXP(a2
) * y1
;
3816 y1
= ZXP(in
) + ZXP(b1
) * y2
+ ZXP(b2
) * y0
;
3817 ZXP(out
) = ZXP(a0
) * y1
+ ZXP(a1
) * y2
+ ZXP(a2
) * y0
;
3819 LOOP(unit
->mRate
->mFilterRemain
,
3820 y0
= ZXP(in
) + ZXP(b1
) * y1
+ ZXP(b2
) * y2
;
3821 ZXP(out
) = ZXP(a0
) * y0
+ ZXP(a1
) * y1
+ ZXP(a2
) * y2
;
3826 unit
->m_y1
= zapgremlins(y1
);
3827 unit
->m_y2
= zapgremlins(y2
);
3830 void SOS_next_k(SOS
*unit
, int inNumSamples
)
3832 float *out
= ZOUT(0);
3834 float next_a0
= ZIN0(1);
3835 float next_a1
= ZIN0(2);
3836 float next_a2
= ZIN0(3);
3837 float next_b1
= ZIN0(4);
3838 float next_b2
= ZIN0(5);
3841 float y1
= unit
->m_y1
;
3842 float y2
= unit
->m_y2
;
3843 float a0
= unit
->m_a0
;
3844 float a1
= unit
->m_a1
;
3845 float a2
= unit
->m_a2
;
3846 float b1
= unit
->m_b1
;
3847 float b2
= unit
->m_b2
;
3848 float a0_slope
= (next_a0
- a0
) * unit
->mRate
->mFilterSlope
;
3849 float a1_slope
= (next_a1
- a1
) * unit
->mRate
->mFilterSlope
;
3850 float a2_slope
= (next_a2
- a2
) * unit
->mRate
->mFilterSlope
;
3851 float b1_slope
= (next_b1
- b1
) * unit
->mRate
->mFilterSlope
;
3852 float b2_slope
= (next_b2
- b2
) * unit
->mRate
->mFilterSlope
;
3853 LOOP(unit
->mRate
->mFilterLoops
,
3854 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3855 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3857 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
3858 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
3860 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
3861 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
3869 LOOP(unit
->mRate
->mFilterRemain
,
3870 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
3871 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3881 unit
->m_y1
= zapgremlins(y1
);
3882 unit
->m_y2
= zapgremlins(y2
);
3885 void SOS_next_1(SOS
*unit
, int inNumSamples
) // optimized for SOS.kr
3895 float y1
= unit
->m_y1
;
3896 float y2
= unit
->m_y2
;
3898 y0
= in
+ b1
* y1
+ b2
* y2
;
3899 ZOUT0(0) = a0
* y0
+ a1
* y1
+ a2
* y2
;
3903 unit
->m_y1
= zapgremlins(y1
);
3904 unit
->m_y2
= zapgremlins(y2
);
3907 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3909 void Compander_Ctor(Compander
* unit
)
3911 //printf("Compander_Reset\n");
3912 SETCALC(Compander_next
);
3913 unit
->m_clamp
= 0.f
;
3914 unit
->m_clampcoef
= 0.f
;
3915 unit
->m_relax
= 0.f
;
3916 unit
->m_relaxcoef
= 0.f
;
3917 unit
->m_prevmaxval
= 0.f
;
3919 Compander_next(unit
, 1);
3922 void Compander_next(Compander
* unit
, int inNumSamples
)
3924 float *out
= ZOUT(0);
3926 float *control
= ZIN(1);
3927 float thresh
= ZIN0(2);
3928 float slope_below
= ZIN0(3);
3929 float slope_above
= ZIN0(4);
3930 float clamp
= ZIN0(5);
3931 float relax
= ZIN0(6);
3933 if (clamp
!= unit
->m_clamp
) {
3934 unit
->m_clampcoef
= clamp
== 0.0 ? 0.0 : exp(log1
/(clamp
* SAMPLERATE
));
3935 unit
->m_clamp
= clamp
;
3937 if (relax
!= unit
->m_relax
) {
3938 unit
->m_relaxcoef
= relax
== 0.0 ? 0.0 : exp(log1
/(relax
* SAMPLERATE
));
3939 unit
->m_relax
= relax
;
3942 float gain
= unit
->m_gain
;
3944 float relaxcoef
= unit
->m_relaxcoef
;
3945 float clampcoef
= unit
->m_clampcoef
;
3947 float prevmaxval
= unit
->m_prevmaxval
;
3951 val
= std::abs(ZXP(control
));
3952 if (val
< prevmaxval
) {
3953 val
= val
+ (prevmaxval
- val
) * relaxcoef
;
3955 val
= val
+ (prevmaxval
- val
) * clampcoef
;
3960 unit
->m_prevmaxval
= prevmaxval
;
3962 float next_gain
;//,absx;
3963 if (prevmaxval
< thresh
) {
3964 if (slope_below
== 1.f
) {
3967 next_gain
= pow(prevmaxval
/ thresh
, slope_below
- 1.f
);
3969 float32 absx
= std::abs(next_gain
);
3970 //zap gremlins, but returns 0. if gain is too small and 1. if gain is too big
3972 (absx
< (float32
)1e-15) ? (float32
)0. :
3973 (absx
> (float32
)1e15
) ? (float32
)1. : next_gain
;
3976 if (slope_above
== 1.f
) {
3979 next_gain
= pow(prevmaxval
/ thresh
, slope_above
- 1.f
);
3983 float gain_slope
= CALCSLOPE(next_gain
, gain
);
3984 LOOP1(inNumSamples
, ZXP(out
) = ZXP(in
) * gain
; gain
+= gain_slope
;);
3985 unit
->m_gain
= gain
;
3988 ////////////////////////////////////////////////////////////////////////////////////////////////////////
3991 void Normalizer_Dtor(Normalizer
* unit
)
3993 RTFree(unit
->mWorld
, unit
->m_table
);
3996 void Normalizer_Ctor(Normalizer
* unit
)
3998 SETCALC(Normalizer_next
);
3999 //printf("Normalizer_Reset\n");
4001 float dur
= ZIN0(2);
4002 unit
->m_bufsize
= (long)(ceil(dur
* SAMPLERATE
));
4003 long allocsize
= unit
->m_bufsize
* 3;
4004 //allocsize = NEXTPOWEROFTWO(allocsize);
4006 unit
->m_table
= (float*)RTAlloc(unit
->mWorld
, allocsize
* sizeof(float));
4010 unit
->m_level
= 1.f
;
4011 unit
->m_slope
= 0.f
;
4012 unit
->m_prevmaxval
= 0.0;
4013 unit
->m_curmaxval
= 0.0;
4014 unit
->m_slopefactor
= 1.f
/ unit
->m_bufsize
;
4016 unit
->m_xinbuf
= unit
->m_table
- ZOFF
;
4017 unit
->m_xmidbuf
= unit
->m_xinbuf
+ unit
->m_bufsize
;
4018 unit
->m_xoutbuf
= unit
->m_xmidbuf
+ unit
->m_bufsize
;
4019 Normalizer_next(unit
, 1);
4023 void Normalizer_next(Normalizer
* unit
, int inNumSamples
)
4025 float *out
= ZOUT(0);
4027 float amp
= ZIN0(1);
4029 long pos
= unit
->m_pos
;
4030 float slope
= unit
->m_slope
;
4031 float level
= unit
->m_level
;
4032 float curmaxval
= unit
->m_curmaxval
;
4035 long bufsize
= unit
->m_bufsize
;
4036 long buf_remain
= bufsize
- pos
;
4038 long remain
= inNumSamples
;
4039 while (remain
> 0) {
4040 long nsmps
= sc_min(remain
, buf_remain
);
4041 float* xinbuf
= unit
->m_xinbuf
+ pos
;
4042 float* xoutbuf
= unit
->m_xoutbuf
+ pos
;
4043 if (unit
->m_flips
>= 2) {
4045 ZXP(xinbuf
) = val
= ZXP(in
);
4046 ZXP(out
) = level
* ZXP(xoutbuf
);
4048 val
= std::abs(val
);
4049 if (val
> curmaxval
) curmaxval
= val
;
4053 ZXP(xinbuf
) = val
= ZXP(in
);
4056 val
= std::abs(val
);
4057 if (val
> curmaxval
) curmaxval
= val
;
4061 if (pos
>= bufsize
) {
4063 buf_remain
= bufsize
;
4065 float maxval2
= sc_max(unit
->m_prevmaxval
, curmaxval
);
4066 unit
->m_prevmaxval
= curmaxval
;
4067 unit
->m_curmaxval
= curmaxval
= 0.f
;
4070 if (maxval2
<= 0.00001f
) next_level
= 100000.f
* amp
;
4071 else next_level
= amp
/ maxval2
;
4073 slope
= unit
->m_slope
= (next_level
- level
) * unit
->m_slopefactor
;
4075 float* temp
= unit
->m_xoutbuf
;
4076 unit
->m_xoutbuf
= unit
->m_xmidbuf
;
4077 unit
->m_xmidbuf
= unit
->m_xinbuf
;
4078 unit
->m_xinbuf
= temp
;
4086 unit
->m_level
= level
;
4087 unit
->m_curmaxval
= curmaxval
;
4090 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4092 void Limiter_Dtor(Limiter
* unit
)
4094 RTFree(unit
->mWorld
, unit
->m_table
);
4097 void Limiter_Ctor(Limiter
* unit
)
4099 //printf("Limiter_Reset\n");
4100 SETCALC(Limiter_next
);
4102 float dur
= ZIN0(2);
4103 unit
->m_bufsize
= (long)(ceil(dur
* SAMPLERATE
));
4104 long allocsize
= unit
->m_bufsize
* 3;
4105 allocsize
= NEXTPOWEROFTWO(allocsize
);
4107 unit
->m_table
= (float*)RTAlloc(unit
->mWorld
, allocsize
* sizeof(float));
4111 unit
->m_slope
= 0.f
;
4112 unit
->m_level
= 1.f
;
4113 unit
->m_prevmaxval
= 0.0;
4114 unit
->m_curmaxval
= 0.0;
4115 unit
->m_slopefactor
= 1.f
/ unit
->m_bufsize
;
4117 unit
->m_xinbuf
= unit
->m_table
- ZOFF
;
4118 unit
->m_xmidbuf
= unit
->m_xinbuf
+ unit
->m_bufsize
;
4119 unit
->m_xoutbuf
= unit
->m_xmidbuf
+ unit
->m_bufsize
;
4120 Limiter_next(unit
, 1);
4124 void Limiter_next(Limiter
* unit
, int inNumSamples
)
4126 float *out
= ZOUT(0);
4128 float amp
= ZIN0(1);
4130 long pos
= unit
->m_pos
;
4131 float slope
= unit
->m_slope
;
4132 float level
= unit
->m_level
;
4133 float curmaxval
= unit
->m_curmaxval
;
4136 long bufsize
= unit
->m_bufsize
;
4137 long buf_remain
= bufsize
- pos
;
4139 long remain
= inNumSamples
;
4140 while (remain
> 0) {
4141 long nsmps
= sc_min(remain
, buf_remain
);
4142 float* xinbuf
= unit
->m_xinbuf
+ pos
;
4143 float* xoutbuf
= unit
->m_xoutbuf
+ pos
;
4144 if (unit
->m_flips
>= 2) {
4146 ZXP(xinbuf
) = val
= ZXP(in
);
4147 ZXP(out
) = level
* ZXP(xoutbuf
);
4149 val
= std::abs(val
);
4150 if (val
> curmaxval
) curmaxval
= val
;
4154 ZXP(xinbuf
) = val
= ZXP(in
);
4157 val
= std::abs(val
);
4158 if (val
> curmaxval
) curmaxval
= val
;
4162 if (pos
>= bufsize
) {
4164 buf_remain
= bufsize
;
4166 float maxval2
= sc_max(unit
->m_prevmaxval
, curmaxval
);
4167 unit
->m_prevmaxval
= curmaxval
;
4168 unit
->m_curmaxval
= curmaxval
= 0.f
;
4171 if (maxval2
> amp
) next_level
= amp
/ maxval2
;
4172 else next_level
= 1.0;
4174 slope
= unit
->m_slope
= (next_level
- level
) * unit
->m_slopefactor
;
4176 float* temp
= unit
->m_xoutbuf
;
4177 unit
->m_xoutbuf
= unit
->m_xmidbuf
;
4178 unit
->m_xmidbuf
= unit
->m_xinbuf
;
4179 unit
->m_xinbuf
= temp
;
4187 unit
->m_level
= level
;
4188 unit
->m_curmaxval
= curmaxval
;
4191 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4193 void Amplitude_Ctor(Amplitude
* unit
)
4195 if(INRATE(1) != calc_ScalarRate
|| INRATE(2) != calc_ScalarRate
) {
4196 if(INRATE(0) == calc_FullRate
&& unit
->mCalcRate
== calc_BufRate
){
4197 SETCALC(Amplitude_next_atok_kk
);
4199 SETCALC(Amplitude_next_kk
);
4203 if(INRATE(0) == calc_FullRate
&& unit
->mCalcRate
== calc_BufRate
){
4204 SETCALC(Amplitude_next_atok
);
4206 SETCALC(Amplitude_next
);
4210 float clamp
= ZIN0(1);
4211 unit
->m_clampcoef
= clamp
== 0.0 ? 0.0 : exp(log1
/(clamp
* SAMPLERATE
));
4213 float relax
= ZIN0(2);
4214 unit
->m_relaxcoef
= relax
== 0.0 ? 0.0 : exp(log1
/(relax
* SAMPLERATE
));
4216 unit
->m_previn
= std::abs(ZIN0(0));
4217 Amplitude_next(unit
, 1);
4220 void Amplitude_next(Amplitude
* unit
, int inNumSamples
)
4222 float *out
= ZOUT(0);
4225 float relaxcoef
= unit
->m_relaxcoef
;
4226 float clampcoef
= unit
->m_clampcoef
;
4227 float previn
= unit
->m_previn
;
4231 val
= std::abs(ZXP(in
));
4233 val
= val
+ (previn
- val
) * relaxcoef
;
4235 val
= val
+ (previn
- val
) * clampcoef
;
4237 ZXP(out
) = previn
= val
;
4240 unit
->m_previn
= previn
;
4243 void Amplitude_next_atok(Amplitude
* unit
, int inNumSamples
)
4247 float relaxcoef
= unit
->m_relaxcoef
;
4248 float clampcoef
= unit
->m_clampcoef
;
4249 float previn
= unit
->m_previn
;
4252 LOOP1(FULLBUFLENGTH
,
4253 val
= std::abs(ZXP(in
));
4255 val
= val
+ (previn
- val
) * relaxcoef
;
4257 val
= val
+ (previn
- val
) * clampcoef
;
4263 unit
->m_previn
= previn
;
4266 void Amplitude_next_kk(Amplitude
* unit
, int inNumSamples
)
4268 float *out
= ZOUT(0);
4270 float relaxcoef
, clampcoef
;
4272 if(ZIN0(1) != unit
->m_clamp_in
) {
4273 clampcoef
= unit
->m_clampcoef
= exp(log1
/(ZIN0(1) * SAMPLERATE
));
4274 unit
->m_clamp_in
= ZIN0(1);
4276 clampcoef
= unit
->m_clampcoef
;
4279 if(ZIN0(2) != unit
->m_relax_in
) {
4280 relaxcoef
= unit
->m_relaxcoef
= exp(log1
/(ZIN0(2) * SAMPLERATE
));
4281 unit
->m_relax_in
= ZIN0(2);
4283 relaxcoef
= unit
->m_relaxcoef
;
4286 float previn
= unit
->m_previn
;
4290 val
= std::abs(ZXP(in
));
4292 val
= val
+ (previn
- val
) * relaxcoef
;
4294 val
= val
+ (previn
- val
) * clampcoef
;
4296 ZXP(out
) = previn
= val
;
4299 unit
->m_previn
= previn
;
4302 void Amplitude_next_atok_kk(Amplitude
* unit
, int inNumSamples
)
4305 float relaxcoef
, clampcoef
;
4307 if(ZIN0(1) != unit
->m_clamp_in
) {
4308 clampcoef
= unit
->m_clampcoef
= exp(log1
/(ZIN0(1) * SAMPLERATE
));
4309 unit
->m_clamp_in
= ZIN0(1);
4311 clampcoef
= unit
->m_clampcoef
;
4314 if(ZIN0(2) != unit
->m_relax_in
) {
4315 relaxcoef
= unit
->m_relaxcoef
= exp(log1
/(ZIN0(2) * SAMPLERATE
));
4316 unit
->m_relax_in
= ZIN0(2);
4318 relaxcoef
= unit
->m_relaxcoef
;
4321 float previn
= unit
->m_previn
;
4324 LOOP1(FULLBUFLENGTH
,
4325 val
= std::abs(ZXP(in
));
4327 val
= val
+ (previn
- val
) * relaxcoef
;
4329 val
= val
+ (previn
- val
) * clampcoef
;
4335 unit
->m_previn
= previn
;
4338 ////////////////////////////////////////////////////////////////////////////////////////////////////////
4340 void DetectSilence_Ctor(DetectSilence
* unit
)
4342 //printf("DetectSilence_Reset\n");
4343 SETCALC(DetectSilence_next
);
4345 unit
->mThresh
= ZIN0(1);
4346 unit
->mEndCounter
= (int32
)(SAMPLERATE
* ZIN0(2));
4347 unit
->mCounter
= -1;
4351 void DetectSilence_next(DetectSilence
* unit
, int inNumSamples
)
4353 float thresh
= unit
->mThresh
;
4354 int counter
= unit
->mCounter
;
4357 // I thought of a better way to do this...
4359 for (int i=0; i<inNumSamples; ++i) {
4360 float val = std::abs(ZXP(in));
4361 if (val >= thresh) counter = 0;
4362 else if (counter >= 0) {
4363 if (++counter >= unit->mEndCounter && doneAction) {
4364 int doneAction = (int)ZIN0(3);
4365 DoneAction(doneAction, unit);
4366 SETCALC(DetectSilence_done);
4373 float *out
= OUT(0);
4374 for (int i
=0; i
<inNumSamples
; ++i
) {
4375 val
= std::abs(*in
++);
4379 } else if (counter
>= 0) {
4380 if (++counter
>= unit
->mEndCounter
) {
4381 int doneAction
= (int)ZIN0(3);
4382 DoneAction(doneAction
, unit
);
4384 // SETCALC(DetectSilence_done);
4392 unit
->mCounter
= counter
;
4395 void DetectSilence_done(DetectSilence
* unit
, int inNumSamples
)
4398 ///////////////////////////////////////////////////////////////////////////////////////////////////////
4399 // Based on HilbertIIR from SC2
4400 // a 12 pole (6 per side) Hilbert IIR filter
4401 // based on Sean Costello and Bernie Hutchins
4402 // created by jl anderson - 7 jan 2001
4403 // UGen created by Josh Parmenter
4405 #define HILBERT_FILTER \
4406 y0_1 = thisin - (coefs[0]) * y1[0]; \
4407 ay1 = coefs[0] * y0_1 + 1 * y1[0]; \
4409 y0_2 = ay1 - (coefs[1]) * y1[1]; \
4410 ay2 = coefs[1] * y0_2 + 1 * y1[1]; \
4412 y0_3 = ay2 - (coefs[2]) * y1[2]; \
4413 ay3 = coefs[2] * y0_3 + 1 * y1[2]; \
4415 y0_4 = ay3 - (coefs[3]) * y1[3]; \
4416 ay4 =coefs[3] * y0_4 + 1 * y1[3]; \
4418 y0_5 = ay4 - (coefs[4]) * y1[4]; \
4419 ay5 = coefs[4] * y0_5 + 1 * y1[4]; \
4421 y0_6 = ay5 - (coefs[5]) * y1[5]; \
4422 ay6 = coefs[5] * y0_6 + 1 * y1[5]; \
4425 y0_7 = thisin - (coefs[6]) * y1[6]; \
4426 ay7 = coefs[6] * y0_7 + 1 * y1[6]; \
4428 y0_8 = ay7 - (coefs[7]) * y1[7]; \
4429 ay8 = coefs[7] * y0_8 + 1 * y1[7]; \
4431 y0_9 = ay8 - (coefs[8]) * y1[8]; \
4432 ay9 = coefs[8] * y0_9 + 1 * y1[8]; \
4434 y0_10 = ay9 - (coefs[9]) * y1[9]; \
4435 ay10 = coefs[9] * y0_10 + 1 * y1[9]; \
4437 y0_11 = ay10 - (coefs[10]) * y1[10]; \
4438 ay11 = coefs[10] * y0_11 + 1 * y1[10]; \
4440 y0_12 = ay11 - (coefs[11]) * y1[11]; \
4441 ay12 = coefs[11] * y0_12 + 1 * y1[11]; \
4445 void Hilbert_Ctor(Hilbert *unit)
4447 // calculate coefs based on SampleRate, store in the struct
4448 SETCALC(Hilbert_next
);
4450 float gamconst
= (15.0f
* pi_f
) / SAMPLERATE
;
4451 float gamma01
= gamconst
* 0.3609f
;
4452 float gamma02
= gamconst
* 2.7412f
;
4453 float gamma03
= gamconst
* 11.1573f
;
4454 float gamma04
= gamconst
* 44.7581f
;
4455 float gamma05
= gamconst
* 179.6242f
;
4456 float gamma06
= gamconst
* 798.4578f
;
4457 float gamma07
= gamconst
* 1.2524f
;
4458 float gamma08
= gamconst
* 5.5671f
;
4459 float gamma09
= gamconst
* 22.3423f
;
4460 float gamma10
= gamconst
* 89.6271f
;
4461 float gamma11
= gamconst
* 364.7914f
;
4462 float gamma12
= gamconst
* 2770.1114f
;
4463 unit
->m_coefs
[0] = (gamma01
- 1.f
) / (gamma01
+ 1.f
);
4464 unit
->m_coefs
[1] = (gamma02
- 1.f
) / (gamma02
+ 1.f
);
4465 unit
->m_coefs
[2] = (gamma03
- 1.f
) / (gamma03
+ 1.f
);
4466 unit
->m_coefs
[3] = (gamma04
- 1.f
) / (gamma04
+ 1.f
);
4467 unit
->m_coefs
[4] = (gamma05
- 1.f
) / (gamma05
+ 1.f
);
4468 unit
->m_coefs
[5] = (gamma06
- 1.f
) / (gamma06
+ 1.f
);
4469 unit
->m_coefs
[6] = (gamma07
- 1.f
) / (gamma07
+ 1.f
);
4470 unit
->m_coefs
[7] = (gamma08
- 1.f
) / (gamma08
+ 1.f
);
4471 unit
->m_coefs
[8] = (gamma09
- 1.f
) / (gamma09
+ 1.f
);
4472 unit
->m_coefs
[9] = (gamma10
- 1.f
) / (gamma10
+ 1.f
);
4473 unit
->m_coefs
[10] = (gamma11
- 1.f
) / (gamma11
+ 1.f
);
4474 unit
->m_coefs
[11] = (gamma12
- 1.f
) / (gamma12
+ 1.f
);
4475 Clear(12, unit
->m_y1
);
4476 Hilbert_next(unit
, 1);
4479 void Hilbert_next(Hilbert
*unit
, int inNumSamples
)
4482 float *outcos
= ZOUT(0);
4483 float *outsin
= ZOUT(1);
4487 // each filter's last sample
4488 for(int i
= 0; i
< 12; ++i
){
4489 y1
[i
] = unit
->m_y1
[i
];
4490 coefs
[i
] = unit
->m_coefs
[i
];
4493 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4494 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4496 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4497 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4500 float thisin
= ZXP(in
);
4507 for(int i
= 0; i
< 12; ++i
)
4508 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4512 /* Hilbert based SSB FreqShifter */
4514 void FreqShift_Ctor(FreqShift
*unit
)
4516 // calculate coefs based on SampleRate, store in the struct
4517 // SETCALC(FreqShift_next_kk);
4519 if(INRATE(1) == calc_FullRate
) {
4520 if(INRATE(2) == calc_FullRate
)
4521 SETCALC(FreqShift_next_aa
);
4523 SETCALC(FreqShift_next_ak
);
4525 if(INRATE(2) == calc_FullRate
)
4526 SETCALC(FreqShift_next_ka
);
4528 SETCALC(FreqShift_next_kk
);
4529 unit
->m_phase
= (int32
)(unit
->m_radtoinc
* IN0(2));
4532 // set up for the oscil for the modualtion
4534 int tableSizeSin
= ft
->mSineSize
;
4535 unit
->m_lomask
= (tableSizeSin
- 1) << 3;
4536 unit
->m_radtoinc
= tableSizeSin
* (rtwopi
* 65536.);
4537 unit
->m_cpstoinc
= tableSizeSin
* SAMPLEDUR
* 65536.;
4538 unit
->m_phasein
= IN0(2);
4540 float gamconst
= (15.0 * pi
) / SAMPLERATE
;
4541 float gamma01
= gamconst
* 0.3609f
;
4542 float gamma02
= gamconst
* 2.7412f
;
4543 float gamma03
= gamconst
* 11.1573f
;
4544 float gamma04
= gamconst
* 44.7581f
;
4545 float gamma05
= gamconst
* 179.6242f
;
4546 float gamma06
= gamconst
* 798.4578f
;
4547 float gamma07
= gamconst
* 1.2524f
;
4548 float gamma08
= gamconst
* 5.5671f
;
4549 float gamma09
= gamconst
* 22.3423f
;
4550 float gamma10
= gamconst
* 89.6271f
;
4551 float gamma11
= gamconst
* 364.7914f
;
4552 float gamma12
= gamconst
* 2770.1114f
;
4553 unit
->m_coefs
[0] = (gamma01
- 1.f
) / (gamma01
+ 1.f
);
4554 unit
->m_coefs
[1] = (gamma02
- 1.f
) / (gamma02
+ 1.f
);
4555 unit
->m_coefs
[2] = (gamma03
- 1.f
) / (gamma03
+ 1.f
);
4556 unit
->m_coefs
[3] = (gamma04
- 1.f
) / (gamma04
+ 1.f
);
4557 unit
->m_coefs
[4] = (gamma05
- 1.f
) / (gamma05
+ 1.f
);
4558 unit
->m_coefs
[5] = (gamma06
- 1.f
) / (gamma06
+ 1.f
);
4559 unit
->m_coefs
[6] = (gamma07
- 1.f
) / (gamma07
+ 1.f
);
4560 unit
->m_coefs
[7] = (gamma08
- 1.f
) / (gamma08
+ 1.f
);
4561 unit
->m_coefs
[8] = (gamma09
- 1.f
) / (gamma09
+ 1.f
);
4562 unit
->m_coefs
[9] = (gamma10
- 1.f
) / (gamma10
+ 1.f
);
4563 unit
->m_coefs
[10] = (gamma11
- 1.f
) / (gamma11
+ 1.f
);
4564 unit
->m_coefs
[11] = (gamma12
- 1.f
) / (gamma12
+ 1.f
);
4566 Clear(12, unit
->m_y1
);
4567 FreqShift_next_kk(unit
, 1);
4570 void FreqShift_next_kk(FreqShift
*unit
, int inNumSamples
)
4573 float *out
= ZOUT(0);
4574 float phasein
= ZIN0(2);
4575 float freqin
= ZIN0(1);
4576 float outcos
, outsin
; // the sample by sample output of the Hilbert
4577 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4578 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4582 float *table0
= ft
->mSineWavetable
;
4583 float *table1
= table0
+ 1;
4584 int32 lomask
= unit
->m_lomask
;
4585 int32 phase
= unit
->m_phase
;
4587 int32 freq
= (int32
)(unit
->m_cpstoinc
* freqin
);
4588 int32 phaseinc
= freq
+ (int32
)(CALCSLOPE(phasein
, unit
->m_phasein
) * unit
->m_radtoinc
);
4589 unit
->m_phasein
= phasein
;
4591 // each filter's last sample
4592 for(int i
= 0; i
< 12; ++i
) {
4593 y1
[i
] = unit
->m_y1
[i
];
4594 coefs
[i
] = unit
->m_coefs
[i
];
4597 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4598 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4600 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4601 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4604 float thisin
= ZXP(in
);
4611 outsinosc
= lookupi1(table0
, table1
, phase
, lomask
);
4612 outsinoscHalfPi
= lookupi1(table0
, table1
, phase
+ halfPi
, lomask
);
4614 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4619 unit
->m_phase
= phase
;
4621 for(int i
= 0; i
< 12; ++i
)
4622 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4625 void FreqShift_next_aa(FreqShift
*unit
, int inNumSamples
)
4628 float *out
= ZOUT(0);
4629 float *phasein
= ZIN(2);
4630 float *freqin
= ZIN(1);
4631 float outcos
, outsin
; // the sample by sample output of the Hilbert
4632 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4633 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4637 float *table0
= ft
->mSineWavetable
;
4638 float *table1
= table0
+ 1;
4639 int32 lomask
= unit
->m_lomask
;
4640 int32 phase
= unit
->m_phase
;
4642 // each filter's last sample
4643 for(int i
= 0; i
< 12; ++i
){
4644 y1
[i
] = unit
->m_y1
[i
];
4645 coefs
[i
] = unit
->m_coefs
[i
];
4648 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4649 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4651 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4652 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4655 float thisin
= ZXP(in
);
4662 int32 phaseoffset
= phase
+ (int32
)(unit
->m_radtoinc
* ZXP(phasein
));
4663 outsinosc
= lookupi1(table0
, table1
, phaseoffset
, lomask
);
4664 outsinoscHalfPi
= lookupi1(table0
, table1
, phaseoffset
+ halfPi
, lomask
);
4665 phase
+= (int32
)(unit
->m_cpstoinc
* ZXP(freqin
));
4667 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4670 unit
->m_phase
= phase
;
4672 for(int i
= 0; i
< 12; ++i
)
4673 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4676 void FreqShift_next_ak(FreqShift
*unit
, int inNumSamples
)
4679 float *out
= ZOUT(0);
4680 float phasein
= ZIN0(2);
4681 float *freqin
= ZIN(1);
4682 float outcos
, outsin
; // the sample by sample output of the Hilbert
4683 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4684 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4688 float *table0
= ft
->mSineWavetable
;
4689 float *table1
= table0
+ 1;
4690 int32 lomask
= unit
->m_lomask
;
4691 int32 phase
= unit
->m_phase
;
4692 float phasemod
= unit
->m_phasein
;
4693 float phaseslope
= CALCSLOPE(phasein
, phasemod
);
4695 // each filter's last sample
4696 for(int i
= 0; i
< 12; ++i
) {
4697 y1
[i
] = unit
->m_y1
[i
];
4698 coefs
[i
] = unit
->m_coefs
[i
];
4701 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4702 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4704 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4705 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4708 float thisin
= ZXP(in
);
4715 int32 pphase
= phase
+ (int32
)(unit
->m_radtoinc
* phasemod
);
4716 phasemod
+= phaseslope
;
4717 outsinosc
= lookupi1(table0
, table1
, pphase
, lomask
);
4718 outsinoscHalfPi
= lookupi1(table0
, table1
, pphase
+ halfPi
, lomask
);
4719 phase
+= (int32
)(unit
->m_cpstoinc
* ZXP(freqin
));
4721 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4724 unit
->m_phase
= phase
;
4725 unit
->m_phasein
= phasein
;
4727 for(int i
= 0; i
< 12; ++i
)
4728 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4731 void FreqShift_next_ka(FreqShift
*unit
, int inNumSamples
)
4734 float *out
= ZOUT(0);
4735 float *phasein
= ZIN(2);
4736 float freqin
= ZIN0(1);
4737 float outcos
, outsin
; // the sample by sample output of the Hilbert
4738 float outsinosc
, outsinoscHalfPi
; // the samples from the oscil.
4739 int32 halfPi
= (int32
)(unit
->m_radtoinc
* (0.5 * pi
));
4743 float *table0
= ft
->mSineWavetable
;
4744 float *table1
= table0
+ 1;
4745 int32 lomask
= unit
->m_lomask
;
4746 int32 phase
= unit
->m_phase
;
4748 int32 freq
= (int32
)(unit
->m_cpstoinc
* freqin
);
4750 // each filter's last sample
4751 for(int i
= 0; i
< 12; ++i
) {
4752 y1
[i
] = unit
->m_y1
[i
];
4753 coefs
[i
] = unit
->m_coefs
[i
];
4756 float ay1
, ay2
, ay3
, ay4
, ay5
, ay6
;
4757 float ay7
, ay8
, ay9
, ay10
, ay11
, ay12
;
4759 float y0_1
, y0_2
, y0_3
, y0_4
, y0_5
, y0_6
;
4760 float y0_7
, y0_8
, y0_9
, y0_10
, y0_11
, y0_12
;
4763 float thisin
= ZXP(in
);
4770 int32 phaseoffset
= phase
+ (int32
)(unit
->m_radtoinc
* ZXP(phasein
));
4771 outsinosc
= lookupi1(table0
, table1
, phaseoffset
, lomask
);
4772 outsinoscHalfPi
= lookupi1(table0
, table1
, phaseoffset
+ halfPi
, lomask
);
4775 ZXP(out
) = (outcos
* outsinoscHalfPi
) + (outsinosc
* outsin
);
4778 unit
->m_phase
= phase
;
4780 for(int i
= 0; i
< 12; ++i
)
4781 unit
->m_y1
[i
] = zapgremlins(y1
[i
]);
4786 "MoogFF" - Moog VCF digital implementation.
4787 As described in the paper entitled
4788 "Preserving the Digital Structure of the Moog VCF"
4790 appeared in the Proc. ICMC07, Copenhagen, 25-31 August 2007
4792 Original Java code Copyright F. Fontana - August 2007
4793 federico.fontana@univr.it
4795 Ported to C++ for SuperCollider by Dan Stowell - August 2007
4796 http://www.mcld.co.uk/
4798 This program is free software; you can redistribute it and/or modify
4799 it under the terms of the GNU General Public License as published by
4800 the Free Software Foundation; either version 2 of the License, or
4801 (at your option) any later version.
4803 This program is distributed in the hope that it will be useful,
4804 but WITHOUT ANY WARRANTY; without even the implied warranty of
4805 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4806 GNU General Public License for more details.
4808 You should have received a copy of the GNU General Public License
4809 along with this program; if not, write to the Free Software
4810 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4812 //////////////////////////////////////////////////////////////////
4814 void MoogFF_Ctor(MoogFF
* unit
)
4816 SETCALC(MoogFF_next
);
4818 // initialize the unit generator state variables.
4819 unit
->m_freq
= -10000.3f
; // Force the freq to update on first run
4825 // calculate one sample of output.
4826 MoogFF_next(unit
, 1);
4829 void MoogFF_next(MoogFF
*unit
, int inNumSamples
)
4831 float *out
= ZOUT(0);
4835 k
= k
> 4.f
? 4.f
: (k
<0.f
? 0.f
: k
);
4837 // Load state from the struct
4838 float s1
= unit
->m_s1
;
4839 float s2
= unit
->m_s2
;
4840 float s3
= unit
->m_s3
;
4841 float s4
= unit
->m_s4
;
4842 float freq
= unit
->m_freq
;///
4844 // Reset filter state if requested
4846 s1
= s2
= s3
= s4
= 0.f
;
4848 float a1
= unit
->m_a1
, b0
= unit
->m_b0
; // Filter coefficient parameters
4849 float o
, u
; // System's null response, loop input
4851 // Update filter coefficients, but only if freq changes since it involves some expensive operations
4852 if(freq
!= IN0(1)) {
4854 //Print("Updated freq to %g\n", freq);
4855 double wcD
=unit
->m_wcD
;
4856 double T
= SAMPLEDUR
;
4857 wcD
= 2.0 * tan ( T
* PI
* freq
) * SAMPLERATE
;
4859 wcD
= 0; // Protect against negative cutoff freq
4860 double TwcD
= T
*wcD
;
4861 b0
= (float)(TwcD
/(TwcD
+ 2.));
4862 a1
= (float)((TwcD
- 2.)/(TwcD
+ 2.));
4863 unit
->m_freq
= freq
;
4870 // compute loop values
4871 o
= s4
+ b0
*(s3
+ b0
*(s2
+ b0
*s1
));
4872 float ins
= ZXP(in
);
4873 float outs
= (b0
*b0
*b0
*b0
*ins
+ o
)/(1.f
+ b0
*b0
*b0
*b0
*k
);
4877 // update 1st order filter states
4879 float future
= b0
*past
+ s1
;
4880 s1
= b0
*past
- a1
*future
;
4883 future
= b0
*past
+ s2
;
4884 s2
= b0
*past
- a1
*future
;
4887 future
= b0
*past
+ s3
;
4888 s3
= b0
*past
- a1
*future
;
4890 s4
= b0
*future
- a1
*outs
;
4903 struct BLowPass
: public Unit
4905 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
4911 void BLowPass_next_kk(BLowPass
*unit
, int inNumSamples
);
4912 void BLowPass_next_aa(BLowPass
*unit
, int inNumSamples
);
4913 void BLowPass_Ctor(BLowPass
* unit
);
4917 void BLowPass_Ctor(BLowPass
* unit
)
4919 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
4920 SETCALC(BLowPass_next_aa
);
4922 SETCALC(BLowPass_next_kk
);
4923 float rq
= unit
->m_rq
= ZIN0(2);
4924 float freq
= unit
->m_freq
= ZIN0(1);
4925 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
4926 double cosw0
= cos(w0
);
4927 double i
= 1. - cosw0
;
4928 double alpha
= sin(w0
) * 0.5 * (double)rq
;
4929 double b0rz
= 1. / (1. + alpha
);
4930 double a0
= unit
->m_a0
= i
* 0.5 * b0rz
;
4931 unit
->m_a1
= i
* b0rz
;
4933 unit
->m_b1
= cosw0
* 2. * b0rz
;
4934 unit
->m_b2
= (1. - alpha
) * -b0rz
;
4939 BLowPass_next_kk(unit
, 1);
4943 void BLowPass_next_aa(BLowPass
*unit
, int inNumSamples
)
4945 float *out
= ZOUT(0);
4947 float *freq
= ZIN(1);
4950 double a0
, a1
, a2
, b1
, b2
, w0
, cosw0
, i
, alpha
, b0rz
;
4952 float nextfreq
, nextrq
;
4963 LOOP(unit
->mRate
->mFilterLoops
,
4964 nextfreq
= ZXP(freq
);
4966 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
4967 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
4970 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
4971 b0rz
= 1. / (1. + alpha
);
4972 a0
= i
* 0.5 * b0rz
;
4975 b1
= cosw0
* 2. * b0rz
;
4976 b2
= (1. - alpha
) * -b0rz
;
4977 unit
->m_freq
= nextfreq
;
4978 unit
->m_rq
= nextrq
;
4980 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
4981 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
4983 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
4984 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
4986 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
4987 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
4990 LOOP(unit
->mRate
->mFilterRemain
,
4991 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
4992 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
4995 unit
->m_freq
= ZXP(freq
);
4996 unit
->m_rq
= ZXP(rq
);
5004 unit
->m_y1
= zapgremlins(y1
);
5005 unit
->m_y2
= zapgremlins(y2
);
5009 void BLowPass_next_kk(BLowPass
*unit
, int inNumSamples
)
5011 float *out
= ZOUT(0);
5013 float nextfreq
= ZIN0(1);
5014 float nextrq
= ZIN0(2);
5016 double a0
, a1
, a2
, b1
, b2
;
5017 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextcosw0
, nexti
, nextalpha
, nextb0rz
;
5019 double y1
= unit
->m_y1
;
5020 double y2
= unit
->m_y2
;
5021 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5029 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)){
5030 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5031 nextcosw0
= cos(nextw0
);
5032 nexti
= 1. - nextcosw0
;
5033 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
5034 nextb0rz
= 1. / (1. + nextalpha
);
5035 nexta0
= nexti
* 0.5 * nextb0rz
;
5036 nexta1
= nexti
* nextb0rz
;
5038 nextb1
= nextcosw0
* 2. * nextb0rz
;
5039 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
5040 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
;
5041 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
;
5042 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
;
5043 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
;
5044 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
;
5045 unit
->m_freq
= nextfreq
;
5046 unit
->m_rq
= nextrq
;
5047 LOOP(unit
->mRate
->mFilterLoops
,
5048 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5049 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5051 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5052 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5054 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5055 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5062 LOOP(unit
->mRate
->mFilterRemain
,
5063 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5064 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5070 LOOP(unit
->mRate
->mFilterLoops
,
5071 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5072 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5074 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5075 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5077 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5078 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5080 LOOP(unit
->mRate
->mFilterRemain
,
5081 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5082 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5087 unit
->m_y1
= zapgremlins(y1
);
5088 unit
->m_y2
= zapgremlins(y2
);
5096 struct BHiPass
: public Unit
5098 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5105 void BHiPass_next_kk(BHiPass
*unit
, int inNumSamples
);
5106 void BHiPass_next_aa(BHiPass
*unit
, int inNumSamples
);
5107 void BHiPass_Ctor(BHiPass
* unit
);
5110 void BHiPass_Ctor(BHiPass
* unit
)
5112 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5113 SETCALC(BHiPass_next_aa
);
5115 SETCALC(BHiPass_next_kk
);
5116 float freq
= unit
->m_freq
= ZIN0(1);
5117 float rq
= unit
->m_rq
= ZIN0(2);
5118 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5119 double cosw0
= cos(w0
);
5120 double i
= 1. + cosw0
;
5121 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5122 double b0rz
= 1. / (1. + alpha
);
5123 double a0
= unit
->m_a0
= i
* 0.5 * b0rz
;
5124 unit
->m_a1
= -i
* b0rz
;
5126 unit
->m_b1
= cosw0
* 2. * b0rz
;
5127 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5132 BHiPass_next_kk(unit
, 1);
5136 void BHiPass_next_aa(BHiPass
*unit
, int inNumSamples
)
5138 float *out
= ZOUT(0);
5140 float *freq
= ZIN(1);
5143 double a0
, a1
, a2
, b1
, b2
, w0
, cosw0
, i
, alpha
, b0rz
;
5145 float nextfreq
, nextrq
;
5156 LOOP(unit
->mRate
->mFilterLoops
,
5157 nextfreq
= ZXP(freq
);
5159 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5160 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5163 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
5164 b0rz
= 1. / (1. + alpha
);
5165 a0
= i
* 0.5 * b0rz
;
5168 b1
= cosw0
* 2. * b0rz
;
5169 b2
= (1. - alpha
) * -b0rz
;
5170 unit
->m_freq
= nextfreq
;
5171 unit
->m_rq
= nextrq
;
5173 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5174 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5176 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5177 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5179 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5180 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5182 LOOP(unit
->mRate
->mFilterRemain
,
5183 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5184 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5194 unit
->m_y1
= zapgremlins(y1
);
5195 unit
->m_y2
= zapgremlins(y2
);
5199 void BHiPass_next_kk(BHiPass
*unit
, int inNumSamples
)
5201 float *out
= ZOUT(0);
5203 float nextfreq
= ZIN0(1);
5204 float nextrq
= ZIN0(2);
5206 double a0
, a1
, a2
, b1
, b2
;
5207 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextcosw0
, nexti
, nextalpha
, nextb0rz
;
5209 double y1
= unit
->m_y1
;
5210 double y2
= unit
->m_y2
;
5211 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5219 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)){
5220 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5221 nextcosw0
= cos(nextw0
);
5222 nexti
= 1. + nextcosw0
;
5223 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
5224 nextb0rz
= 1. / (1. + nextalpha
);
5225 nexta0
= nexti
* 0.5 * nextb0rz
;
5226 nexta1
= -nexti
* nextb0rz
;
5228 nextb1
= nextcosw0
* 2. * nextb0rz
;
5229 nextb2
= (1. - nextalpha
) * -nextb0rz
;
5230 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5231 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5232 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5233 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5234 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5236 LOOP(unit
->mRate
->mFilterLoops
,
5237 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5238 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5240 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5241 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5243 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5244 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5251 LOOP(unit
->mRate
->mFilterRemain
,
5252 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5253 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5257 unit
->m_freq
= nextfreq
;
5258 unit
->m_rq
= nextrq
;
5267 LOOP(unit
->mRate
->mFilterLoops
,
5268 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5269 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5271 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5272 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5274 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5275 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5277 LOOP(unit
->mRate
->mFilterRemain
,
5278 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5279 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5285 unit
->m_y1
= zapgremlins(y1
);
5286 unit
->m_y2
= zapgremlins(y2
);
5291 struct BBandPass
: public Unit
5293 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5299 void BBandPass_next_kk(BBandPass
*unit
, int inNumSamples
);
5300 void BBandPass_next_aa(BBandPass
*unit
, int inNumSamples
);
5301 void BBandPass_Ctor(BBandPass
* unit
);
5304 void BBandPass_Ctor(BBandPass
* unit
)
5306 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5307 SETCALC(BBandPass_next_aa
);
5309 SETCALC(BBandPass_next_kk
);
5310 float freq
= unit
->m_freq
= ZIN0(1);
5311 float bw
= unit
->m_bw
= ZIN0(2);
5313 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5314 double sinw0
= sin(w0
);
5315 double alpha
= sinw0
* (sinh((0.34657359027997 * (double)bw
* w0
) / sinw0
));
5316 double b0rz
= 1. / (1. + alpha
);
5317 double a0
= unit
->m_a0
= alpha
* b0rz
;
5320 unit
->m_b1
= cos(w0
) * 2. * b0rz
;
5321 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5327 BBandPass_next_kk(unit
, 1);
5331 void BBandPass_next_aa(BBandPass
*unit
, int inNumSamples
)
5333 float *out
= ZOUT(0);
5335 float *freq
= ZIN(1);
5338 double a0
, a1
, a2
, b1
, b2
, w0
, sinw0
, alpha
, b0rz
;
5340 float nextfreq
, nextbw
;
5351 LOOP(unit
->mRate
->mFilterLoops
,
5352 nextfreq
= ZXP(freq
);
5354 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)) {
5355 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5357 alpha
= sinw0
* (sinh((0.34657359027997 * (double)nextbw
* w0
) / sinw0
));
5358 b0rz
= 1. / (1. + alpha
);
5362 b1
= cos(w0
) * 2. * b0rz
;
5363 b2
= (1. - alpha
) * -b0rz
;
5364 unit
->m_freq
= ZXP(freq
);
5365 unit
->m_bw
= ZXP(bw
);
5367 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5368 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5370 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5371 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5373 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5374 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5376 LOOP(unit
->mRate
->mFilterRemain
,
5377 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5378 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5381 unit
->m_freq
= nextfreq
;
5382 unit
->m_bw
= nextbw
;
5390 unit
->m_y1
= zapgremlins(y1
);
5391 unit
->m_y2
= zapgremlins(y2
);
5395 void BBandPass_next_kk(BBandPass
*unit
, int inNumSamples
)
5397 float *out
= ZOUT(0);
5399 float nextfreq
= ZIN0(1);
5400 float nextbw
= ZIN0(2);
5402 double a0
, a1
, a2
, b1
, b2
;
5403 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5405 double y1
= unit
->m_y1
;
5406 double y2
= unit
->m_y2
;
5407 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5414 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)){
5415 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5416 nextalpha
= sin(nextw0
) * (sinh((0.34657359027997 * (double)nextbw
* nextw0
) / sin(nextw0
)));
5417 nextb0rz
= 1. / (1. + nextalpha
);
5418 nexta0
= nextalpha
* nextb0rz
;
5421 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
5422 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
5423 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5424 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5425 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5426 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5427 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5428 unit
->m_freq
= nextfreq
;
5429 unit
->m_bw
= nextbw
;
5430 LOOP(unit
->mRate
->mFilterLoops
,
5431 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5432 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5434 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5435 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5437 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5438 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5445 LOOP(unit
->mRate
->mFilterRemain
,
5446 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5447 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5452 LOOP(unit
->mRate
->mFilterLoops
,
5453 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5454 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5456 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5457 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5459 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5460 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5462 LOOP(unit
->mRate
->mFilterRemain
,
5463 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5464 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5475 unit
->m_y1
= zapgremlins(y1
);
5476 unit
->m_y2
= zapgremlins(y2
);
5480 struct BBandStop
: public Unit
5482 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5488 void BBandStop_next_kk(BBandStop
*unit
, int inNumSamples
);
5489 void BBandStop_next_aa(BBandStop
*unit
, int inNumSamples
);
5490 void BBandStop_Ctor(BBandStop
* unit
);
5493 void BBandStop_Ctor(BBandStop
* unit
)
5495 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5496 SETCALC(BBandStop_next_aa
);
5498 SETCALC(BBandStop_next_kk
);
5499 float freq
= unit
->m_freq
= ZIN0(1);
5500 float bw
= unit
->m_bw
= ZIN0(2);
5502 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5503 double sinw0
= sin(w0
);
5504 double alpha
= sinw0
* (sinh((0.34657359027997 * (double)bw
* w0
) / sinw0
));
5505 double b0rz
= 1. / (1. + alpha
);
5506 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5510 unit
->m_b2
= (1. - alpha
) * -b0rz
;
5516 BBandStop_next_kk(unit
, 1);
5520 void BBandStop_next_aa(BBandStop
*unit
, int inNumSamples
)
5522 float *out
= ZOUT(0);
5524 float *freq
= ZIN(1);
5527 double a0
, a1
, a2
, b1
, b2
, w0
, sinw0
, alpha
, b0rz
;
5529 float nextfreq
, nextbw
;
5540 LOOP(unit
->mRate
->mFilterLoops
,
5541 nextfreq
= ZXP(freq
);
5543 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)) {
5544 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5546 alpha
= sinw0
* (sinh((0.34657359027997 * (double)nextbw
* w0
) / sinw0
));
5547 b0rz
= 1. / (1. + alpha
);
5548 b1
= 2. * b0rz
* cos(w0
);
5552 b2
= (1. - alpha
) * -b0rz
;
5553 unit
->m_freq
= ZXP(freq
);
5554 unit
->m_bw
= ZXP(bw
);
5556 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5557 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5559 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5560 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5562 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5563 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5565 LOOP(unit
->mRate
->mFilterRemain
,
5566 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5567 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5570 unit
->m_freq
= nextfreq
;
5571 unit
->m_bw
= nextbw
;
5579 unit
->m_y1
= zapgremlins(y1
);
5580 unit
->m_y2
= zapgremlins(y2
);
5584 void BBandStop_next_kk(BBandStop
*unit
, int inNumSamples
)
5586 float *out
= ZOUT(0);
5588 float nextfreq
= ZIN0(1);
5589 float nextbw
= ZIN0(2);
5591 double a0
, a1
, a2
, b1
, b2
;
5592 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5594 double y1
= unit
->m_y1
;
5595 double y2
= unit
->m_y2
;
5596 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5604 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_bw
!= nextbw
)){
5605 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5606 nextalpha
= sin(nextw0
) * (sinh((0.34657359027997 * (double)nextbw
* nextw0
) / sin(nextw0
)));
5607 nextb0rz
= 1. / (1. + nextalpha
);
5608 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
5612 nextb2
= ((1. - nextalpha
) * -nextb0rz
);
5613 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5614 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5615 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5616 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5617 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5618 unit
->m_freq
= nextfreq
;
5619 unit
->m_bw
= nextbw
;
5620 LOOP(unit
->mRate
->mFilterLoops
,
5621 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5622 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5624 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5625 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5627 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5628 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5635 LOOP(unit
->mRate
->mFilterRemain
,
5636 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5637 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5643 LOOP(unit
->mRate
->mFilterLoops
,
5644 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5645 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5647 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5648 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5650 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5651 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5653 LOOP(unit
->mRate
->mFilterRemain
,
5654 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5655 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5666 unit
->m_y1
= zapgremlins(y1
);
5667 unit
->m_y2
= zapgremlins(y2
);
5671 struct BPeakEQ
: public Unit
5673 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5674 float m_freq
, m_rq
, m_db
;
5679 void BPeakEQ_next_kkk(BPeakEQ
*unit
, int inNumSamples
);
5680 void BPeakEQ_next_aaa(BPeakEQ
*unit
, int inNumSamples
);
5681 void BPeakEQ_Ctor(BPeakEQ
* unit
);
5684 void BPeakEQ_Ctor(BPeakEQ
* unit
)
5686 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
5687 SETCALC(BPeakEQ_next_aaa
);
5689 SETCALC(BPeakEQ_next_kkk
);
5691 float freq
= unit
->m_freq
= ZIN0(1);
5692 float rq
= unit
->m_rq
= ZIN0(2);
5693 float db
= unit
->m_db
= ZIN0(3);
5694 double a
= pow(10., (double)db
* 0.025);
5695 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5696 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5697 double b0rz
= 1. / (1. + (alpha
/ a
));
5698 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5699 unit
->m_a0
= (1. + (alpha
* a
)) * b0rz
;
5701 unit
->m_a2
= (1. - (alpha
* a
)) * b0rz
;
5702 unit
->m_b2
= (1. - (alpha
/ a
)) * -b0rz
;
5707 BPeakEQ_next_kkk(unit
, 1);
5711 void BPeakEQ_next_aaa(BPeakEQ
*unit
, int inNumSamples
)
5713 float *out
= ZOUT(0);
5715 float *freq
= ZIN(1);
5719 double a0
, a1
, a2
, b1
, b2
, a
, w0
, alpha
, b0rz
;
5721 float nextfreq
, nextrq
, nextdb
;
5733 LOOP(unit
->mRate
->mFilterLoops
,
5734 nextfreq
= ZXP(freq
);
5737 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
) || (unit
->m_db
!= nextdb
)) {
5738 a
= pow(10., (double)nextdb
* 0.025);
5739 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5740 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
5741 b0rz
= 1. / (1. + (alpha
/ a
));
5742 b1
= 2. * b0rz
* cos(w0
);
5743 a0
= (1. + (alpha
* a
)) * b0rz
;
5745 a2
= (1. - (alpha
* a
)) * b0rz
;
5746 b2
= (1. - (alpha
/ a
)) * -b0rz
;
5747 unit
->m_freq
= nextfreq
;
5748 unit
->m_rq
= nextrq
;
5749 unit
->m_db
= nextdb
;
5751 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5752 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5754 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5755 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5757 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5758 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5760 LOOP(unit
->mRate
->mFilterRemain
,
5761 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5762 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5765 unit
->m_freq
= ZXP(freq
);
5766 unit
->m_rq
= ZXP(rq
);
5767 unit
->m_db
= ZXP(db
);
5775 unit
->m_y1
= zapgremlins(y1
);
5776 unit
->m_y2
= zapgremlins(y2
);
5780 void BPeakEQ_next_kkk(BPeakEQ
*unit
, int inNumSamples
)
5782 float *out
= ZOUT(0);
5784 float nextfreq
= ZIN0(1);
5785 float nextrq
= ZIN0(2);
5786 float nextdb
= ZIN0(3);
5788 double a0
, a1
, a2
, b1
, b2
, a
, w0
, alpha
, b0rz
;
5789 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
5800 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
) || (unit
->m_db
!= nextdb
)) {
5801 a
= pow(10., (double)nextdb
* 0.025);
5802 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5803 alpha
= sin(w0
) * 0.5 * (double)nextrq
;
5804 b0rz
= 1. / (1. + (alpha
/ a
));
5805 nextb1
= 2. * b0rz
* cos(w0
);
5806 nexta0
= (1. + (alpha
* a
)) * b0rz
;
5808 nexta2
= (1. - (alpha
* a
)) * b0rz
;
5809 nextb2
= (1. - (alpha
/ a
)) * -b0rz
;
5810 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
5811 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
5812 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
5813 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
5814 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
5815 unit
->m_freq
= nextfreq
;
5816 unit
->m_db
= nextdb
;
5817 unit
->m_rq
= nextrq
;
5818 LOOP(unit
->mRate
->mFilterLoops
,
5819 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5820 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5822 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5823 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5825 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5826 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5835 LOOP(unit
->mRate
->mFilterRemain
,
5836 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5837 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5843 LOOP(unit
->mRate
->mFilterLoops
,
5844 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5845 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5847 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5848 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5850 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5851 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5854 LOOP(unit
->mRate
->mFilterRemain
,
5855 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5856 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5867 unit
->m_y1
= zapgremlins(y1
);
5868 unit
->m_y2
= zapgremlins(y2
);
5872 struct BAllPass
: public Unit
5874 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
5880 void BAllPass_next_kk(BAllPass
*unit
, int inNumSamples
);
5881 void BAllPass_next_aa(BAllPass
*unit
, int inNumSamples
);
5882 void BAllPass_Ctor(BAllPass
* unit
);
5885 void BAllPass_Ctor(BAllPass
* unit
)
5887 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
))
5888 SETCALC(BAllPass_next_aa
);
5890 SETCALC(BAllPass_next_kk
);
5892 float freq
= unit
->m_freq
= ZIN0(1);
5893 float rq
= unit
->m_rq
= ZIN0(2);
5895 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
5896 double alpha
= sin(w0
) * 0.5 * (double)rq
;
5897 double b0rz
= 1. / (1. + alpha
);
5898 double a0
= unit
->m_a0
= (1. - alpha
) * b0rz
;
5899 double b1
= unit
->m_b1
= 2. * b0rz
* cos(w0
);
5908 BAllPass_next_kk(unit
, 1);
5912 void BAllPass_next_aa(BAllPass
*unit
, int inNumSamples
)
5914 float *out
= ZOUT(0);
5916 float *freq
= ZIN(1);
5919 double a0
, a1
, a2
, b1
, b2
, w0
, alpha
, b0rz
;
5921 float nextfreq
, nextrq
;
5932 LOOP(unit
->mRate
->mFilterLoops
,
5933 nextfreq
= ZXP(freq
);
5935 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5936 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5937 alpha
= sin(w0
) * (double)nextrq
* 0.5;
5938 b0rz
= 1. / (1. + alpha
);
5939 b1
= 2. * b0rz
* cos(w0
);
5940 a0
= (1. - alpha
) * b0rz
;
5944 unit
->m_freq
= nextfreq
;
5945 unit
->m_rq
= nextrq
;
5947 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5948 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5950 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
5951 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
5953 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
5954 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
5956 LOOP(unit
->mRate
->mFilterRemain
,
5957 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
5958 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
5961 unit
->m_freq
= ZXP(freq
);
5962 unit
->m_rq
= ZXP(rq
);
5970 unit
->m_y1
= zapgremlins(y1
);
5971 unit
->m_y2
= zapgremlins(y2
);
5975 void BAllPass_next_kk(BAllPass
*unit
, int inNumSamples
)
5977 float *out
= ZOUT(0);
5979 float nextfreq
= ZIN0(1);
5980 float nextrq
= ZIN0(2);
5982 double a0
, a1
, a2
, b1
, b2
;
5983 double nexta0
, nexta1
, nexta2
, nextb1
, nextb2
, nextw0
, nextalpha
, nextb0rz
;
5985 double y1
= unit
->m_y1
;
5986 double y2
= unit
->m_y2
;
5987 double a0slope
, a1slope
, a2slope
, b1slope
, b2slope
;
5995 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rq
!= nextrq
)) {
5996 nextw0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
5997 nextalpha
= sin(nextw0
) * 0.5 * (double)nextrq
;
5998 nextb0rz
= 1. / (1. + nextalpha
);
5999 nextb1
= cos(nextw0
) * 2. * nextb0rz
;
6000 nexta0
= (1. - nextalpha
) * nextb0rz
;
6004 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
;
6005 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
;
6006 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
;
6007 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
;
6008 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
;
6009 unit
->m_freq
= nextfreq
;
6010 unit
->m_rq
= nextrq
;
6011 LOOP(unit
->mRate
->mFilterLoops
,
6012 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6013 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6015 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6016 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6018 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6019 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6026 LOOP(unit
->mRate
->mFilterRemain
,
6027 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6028 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6034 LOOP(unit
->mRate
->mFilterLoops
,
6035 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6036 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6038 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6039 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6041 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6042 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6044 LOOP(unit
->mRate
->mFilterRemain
,
6045 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6046 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6057 unit
->m_y1
= zapgremlins(y1
);
6058 unit
->m_y2
= zapgremlins(y2
);
6063 struct BLowShelf
: public Unit
6065 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
6066 float m_freq
, m_rs
, m_db
;
6071 void BLowShelf_next_kkk(BLowShelf
*unit
, int inNumSamples
);
6072 void BLowShelf_next_aaa(BLowShelf
*unit
, int inNumSamples
);
6073 void BLowShelf_Ctor(BLowShelf
* unit
);
6076 void BLowShelf_Ctor(BLowShelf
* unit
)
6078 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
6079 SETCALC(BLowShelf_next_aaa
);
6081 SETCALC(BLowShelf_next_kkk
);
6083 float freq
= unit
->m_freq
= ZIN0(1);
6084 float rs
= unit
->m_rs
= ZIN0(2);
6085 float db
= unit
->m_db
= ZIN0(3);
6086 double a
= pow(10., (double)db
* 0.025);
6087 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
6088 double cosw0
= cos(w0
);
6089 double sinw0
= sin(w0
);
6090 double alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)rs
- 1.) + 2.);
6091 double i
= (a
+ 1.) * cosw0
;
6092 double j
= (a
- 1.) * cosw0
;
6093 double k
= 2. * sqrt(a
) * alpha
;
6094 double b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6095 unit
->m_a0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6096 unit
->m_a1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6097 unit
->m_a2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6098 unit
->m_b1
= 2. * ((a
- 1.) + i
) * b0rz
;
6099 unit
->m_b2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6105 BLowShelf_next_kkk(unit
, 1);
6109 void BLowShelf_next_aaa(BLowShelf
*unit
, int inNumSamples
)
6111 float *out
= ZOUT(0);
6113 float *freq
= ZIN(1);
6117 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6119 float nextfreq
, nextrs
, nextdb
;
6130 LOOP(unit
->mRate
->mFilterLoops
,
6131 nextfreq
= ZXP(freq
);
6134 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6135 a
= pow(10., (double)nextdb
* 0.025);
6136 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6139 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6140 i
= (a
+ 1.) * cosw0
;
6141 j
= (a
- 1.) * cosw0
;
6142 k
= 2. * sqrt(a
) * alpha
;
6143 b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6144 a0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6145 a1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6146 a2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6147 b1
= 2. * ((a
- 1.) + i
) * b0rz
;
6148 b2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6149 unit
->m_freq
= nextfreq
;
6150 unit
->m_rs
= nextrs
;
6151 unit
->m_db
= nextdb
;
6153 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6154 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6156 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6157 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6159 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6160 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6162 LOOP(unit
->mRate
->mFilterRemain
,
6163 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6164 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6167 unit
->m_freq
= ZXP(freq
);
6168 unit
->m_rs
= ZXP(rs
);
6169 unit
->m_db
= ZXP(db
);
6177 unit
->m_y1
= zapgremlins(y1
);
6178 unit
->m_y2
= zapgremlins(y2
);
6181 void BLowShelf_next_kkk(BLowShelf
*unit
, int inNumSamples
)
6183 float *out
= ZOUT(0);
6185 float nextfreq
= ZIN0(1);
6186 float nextrs
= ZIN0(2);
6187 float nextdb
= ZIN0(3);
6189 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6190 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
6201 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6202 a
= pow(10., (double)nextdb
* 0.025);
6203 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6206 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6207 i
= (a
+ 1.) * cosw0
;
6208 j
= (a
- 1.) * cosw0
;
6209 k
= 2. * sqrt(a
) * alpha
;
6210 b0rz
= 1. / ((a
+ 1.) + j
+ k
);
6211 nexta0
= a
* (( a
+ 1.) - j
+ k
) * b0rz
;
6212 nexta1
= 2. * a
* ((a
- 1.) - i
) * b0rz
;
6213 nexta2
= a
* ((a
+ 1.) - j
- k
) * b0rz
;
6214 nextb1
= 2. * ((a
- 1.) + i
) * b0rz
;
6215 nextb2
= ((a
+ 1.) + j
- k
) * -b0rz
;
6216 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
6217 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
6218 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
6219 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
6220 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
6221 unit
->m_freq
= nextfreq
;
6222 unit
->m_db
= nextdb
;
6223 unit
->m_rs
= nextrs
;
6224 LOOP(unit
->mRate
->mFilterLoops
,
6225 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6226 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6228 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6229 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6231 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6232 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6241 LOOP(unit
->mRate
->mFilterRemain
,
6242 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6243 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6249 LOOP(unit
->mRate
->mFilterLoops
,
6250 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6251 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6253 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6254 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6256 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6257 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6260 LOOP(unit
->mRate
->mFilterRemain
,
6261 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6262 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6273 unit
->m_y1
= zapgremlins(y1
);
6274 unit
->m_y2
= zapgremlins(y2
);
6278 struct BHiShelf
: public Unit
6280 double m_y1
, m_y2
, m_a0
, m_a1
, m_a2
, m_b1
, m_b2
;
6281 float m_freq
, m_rs
, m_db
;
6286 void BHiShelf_next_kkk(BHiShelf
*unit
, int inNumSamples
);
6287 void BHiShelf_next_aaa(BHiShelf
*unit
, int inNumSamples
);
6288 void BHiShelf_Ctor(BHiShelf
* unit
);
6291 void BHiShelf_Ctor(BHiShelf
* unit
)
6293 if ((INRATE(1) == calc_FullRate
) && (INRATE(2) == calc_FullRate
) && (INRATE(3) == calc_FullRate
))
6294 SETCALC(BHiShelf_next_aaa
);
6296 SETCALC(BHiShelf_next_kkk
);
6298 float freq
= unit
->m_freq
= ZIN0(1);
6299 float rs
= unit
->m_rs
= ZIN0(2);
6300 float db
= unit
->m_db
= ZIN0(3);
6301 double a
= pow(10., (double)db
* 0.025);
6302 double w0
= twopi
* (double)freq
* SAMPLEDUR
;
6303 double cosw0
= cos(w0
);
6304 double sinw0
= sin(w0
);
6305 double alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)rs
- 1.) + 2.);
6306 double i
= (a
+ 1.) * cosw0
;
6307 double j
= (a
- 1.) * cosw0
;
6308 double k
= 2. * sqrt(a
) * alpha
;
6310 double b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6311 unit
->m_a0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6312 unit
->m_a1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6313 unit
->m_a2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6314 unit
->m_b1
= -2. * ((a
- 1.) - i
) * b0rz
;
6315 unit
->m_b2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6321 BHiShelf_next_kkk(unit
, 1);
6325 void BHiShelf_next_aaa(BHiShelf
*unit
, int inNumSamples
)
6327 float *out
= ZOUT(0);
6329 float *freq
= ZIN(1);
6333 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6335 float nextfreq
, nextrs
, nextdb
;
6346 LOOP(unit
->mRate
->mFilterLoops
,
6347 nextfreq
= ZXP(freq
);
6350 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6351 a
= pow(10., (double)nextdb
* 0.025);
6352 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6355 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6356 i
= (a
+ 1.) * cosw0
;
6357 j
= (a
- 1.) * cosw0
;
6358 k
= 2. * sqrt(a
) * alpha
;
6359 b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6360 a0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6361 a1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6362 a2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6363 b1
= -2. * ((a
- 1.) - i
) * b0rz
;
6364 b2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6365 unit
->m_freq
= ZXP(freq
);
6366 unit
->m_rs
= ZXP(rs
);
6367 unit
->m_db
= ZXP(db
);
6369 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6370 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6372 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6373 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6375 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6376 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6378 LOOP(unit
->mRate
->mFilterRemain
,
6379 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6380 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6383 unit
->m_freq
= ZXP(freq
);
6384 unit
->m_rs
= ZXP(rs
);
6385 unit
->m_db
= ZXP(db
);
6393 unit
->m_y1
= zapgremlins(y1
);
6394 unit
->m_y2
= zapgremlins(y2
);
6397 void BHiShelf_next_kkk(BHiShelf
*unit
, int inNumSamples
)
6399 float *out
= ZOUT(0);
6401 float nextfreq
= ZIN0(1);
6402 float nextrs
= ZIN0(2);
6403 float nextdb
= ZIN0(3);
6405 double a0
, a1
, a2
, b1
, b2
, a
, w0
, cosw0
, sinw0
, alpha
, i
, j
, k
, b0rz
;
6406 double y0
, y1
, y2
, a0slope
, a1slope
, a2slope
, b1slope
, b2slope
, nexta0
, nexta1
, nexta2
, nextb1
, nextb2
;
6417 if ((unit
->m_freq
!= nextfreq
) || (unit
->m_rs
!= nextrs
) || (unit
->m_db
!= nextdb
)) {
6418 a
= pow(10., (double)nextdb
* 0.025);
6419 w0
= twopi
* (double)nextfreq
* SAMPLEDUR
;
6422 alpha
= sinw0
* 0.5 * sqrt((a
+ (1./a
)) * ((double)nextrs
- 1.) + 2.);
6423 i
= (a
+ 1.) * cosw0
;
6424 j
= (a
- 1.) * cosw0
;
6425 k
= 2. * sqrt(a
) * alpha
;
6426 b0rz
= 1. / ((a
+ 1.) - j
+ k
);
6427 nexta0
= a
* (( a
+ 1.) + j
+ k
) * b0rz
;
6428 nexta1
= -2. * a
* ((a
- 1.) + i
) * b0rz
;
6429 nexta2
= a
* ((a
+ 1.) + j
- k
) * b0rz
;
6430 nextb1
= -2. * ((a
- 1.) - i
) * b0rz
;
6431 nextb2
= ((a
+ 1.) - j
- k
) * -b0rz
;
6432 a0slope
= (nexta0
- a0
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta0, a0);
6433 a1slope
= (nexta1
- a1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta1, a1);
6434 a2slope
= (nexta2
- a2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nexta2, a2);
6435 b1slope
= (nextb1
- b1
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb1, b1);
6436 b2slope
= (nextb2
- b2
) * unit
->mRate
->mFilterSlope
; //CALCSLOPE(nextb2, b2);
6437 unit
->m_freq
= nextfreq
;
6438 unit
->m_db
= nextdb
;
6439 unit
->m_rs
= nextrs
;
6440 LOOP(unit
->mRate
->mFilterLoops
,
6441 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6442 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6444 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6445 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6447 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6448 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6457 LOOP(unit
->mRate
->mFilterRemain
,
6458 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6459 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6465 LOOP(unit
->mRate
->mFilterLoops
,
6466 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6467 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6469 y2
= ZXP(in
) + b1
* y0
+ b2
* y1
;
6470 ZXP(out
) = a0
* y2
+ a1
* y0
+ a2
* y1
;
6472 y1
= ZXP(in
) + b1
* y2
+ b2
* y0
;
6473 ZXP(out
) = a0
* y1
+ a1
* y2
+ a2
* y0
;
6476 LOOP(unit
->mRate
->mFilterRemain
,
6477 y0
= ZXP(in
) + b1
* y1
+ b2
* y2
;
6478 ZXP(out
) = a0
* y0
+ a1
* y1
+ a2
* y2
;
6488 unit
->m_y1
= zapgremlins(y1
);
6489 unit
->m_y2
= zapgremlins(y2
);
6492 ////////////////////////////////////////////////////////////////////////////////////////////////////////
6497 DefineSimpleUnit(Ramp
);
6498 DefineSimpleUnit(Lag
);
6499 DefineSimpleUnit(Lag2
);
6500 DefineSimpleUnit(Lag3
);
6501 DefineSimpleUnit(LagUD
);
6502 DefineSimpleUnit(Lag2UD
);
6503 DefineSimpleUnit(Lag3UD
);
6504 DefineSimpleUnit(VarLag
);
6505 DefineSimpleUnit(OnePole
);
6506 DefineSimpleUnit(OneZero
);
6507 DefineSimpleUnit(TwoPole
);
6508 DefineSimpleUnit(TwoZero
);
6509 DefineSimpleUnit(Decay
);
6510 DefineSimpleUnit(Decay2
);
6511 DefineSimpleUnit(Flip
);
6512 DefineSimpleUnit(Delay1
);
6513 DefineSimpleUnit(Delay2
);
6514 DefineSimpleUnit(Integrator
);
6515 DefineSimpleUnit(LeakDC
);
6516 DefineSimpleUnit(LPZ1
);
6517 DefineSimpleUnit(HPZ1
);
6518 DefineSimpleUnit(LPZ2
);
6519 DefineSimpleUnit(HPZ2
);
6520 DefineSimpleUnit(BPZ2
);
6521 DefineSimpleUnit(BRZ2
);
6522 DefineSimpleUnit(APF
);
6523 DefineSimpleUnit(LPF
);
6524 DefineSimpleUnit(HPF
);
6525 DefineSimpleUnit(BPF
);
6526 DefineSimpleUnit(BRF
);
6527 DefineSimpleUnit(RLPF
);
6528 DefineSimpleUnit(RHPF
);
6530 DefineSimpleUnit(Slew
);
6531 DefineSimpleUnit(Slope
);
6533 DefineSimpleUnit(MidEQ
);
6534 DefineSimpleUnit(Median
);
6536 DefineSimpleUnit(Resonz
);
6537 DefineSimpleUnit(Ringz
);
6538 DefineSimpleUnit(Formlet
);
6540 DefineSimpleUnit(FOS
);
6541 DefineSimpleUnit(SOS
);
6543 DefineSimpleUnit(Compander
);
6544 DefineDtorUnit(Limiter
);
6545 DefineDtorUnit(Normalizer
);
6547 DefineSimpleUnit(Amplitude
);
6548 DefineSimpleUnit(DetectSilence
);
6550 DefineSimpleUnit(Hilbert
);
6551 DefineSimpleUnit(FreqShift
);
6552 DefineSimpleUnit(MoogFF
);
6554 /* BEQSuite UGens */
6555 DefineSimpleUnit(BLowPass
);
6556 DefineSimpleUnit(BHiPass
);
6557 DefineSimpleUnit(BBandPass
);
6558 DefineSimpleUnit(BBandStop
);
6559 DefineSimpleUnit(BPeakEQ
);
6560 DefineSimpleUnit(BAllPass
);
6561 DefineSimpleUnit(BLowShelf
);
6562 DefineSimpleUnit(BHiShelf
);
6566 //////////////////////////////////////////////////////////////////////////////////////////////////