forked from grame-cncm/faustlibraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vaeffects.lib
973 lines (901 loc) · 34.4 KB
/
vaeffects.lib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
//#################################### vaeffects.lib ########################################
// A library of virtual analog filter effects. Its official prefix is `ve`.
//########################################################################################
ma = library("maths.lib");
si = library("signals.lib");
an = library("analyzers.lib");
fi = library("filters.lib");
ef = library("misceffects.lib");
declare name "Faust Virtual Analog Filter Effect Library";
declare version "0.0";
//########################################################################################
/************************************************************************
FAUST library file, jos section
Except where noted otherwise, The Faust functions below in this
section are Copyright (C) 2003-2017 by Julius O. Smith III <[email protected]>
([jos](http://ccrma.stanford.edu/~jos/)), and released under the
(MIT-style) [STK-4.3](#stk-4.3-license) license.
All MarkDown comments in this section are Copyright 2016-2017 by Romain
Michon and Julius O. Smith III, and are released under the
[CCA4I](https://creativecommons.org/licenses/by/4.0/) license (TODO: if/when Romain agrees!)
************************************************************************/
//====================================Moog Filters========================================
//========================================================================================
//-------------------------`(ve.)moog_vcf`---------------------------
// Moog "Voltage Controlled Filter" (VCF) in "analog" form. Moog VCF
// implemented using the same logical block diagram as the classic
// analog circuit. As such, it neglects the one-sample delay associated
// with the feedback path around the four one-poles.
// This extra delay alters the response, especially at high frequencies
// (see reference [1] for details).
// See `moog_vcf_2b` below for a more accurate implementation.
//
// #### Usage
//
// ```
// moog_vcf(res,fr)
// ```
// Where:
//
// * `res`: normalized amount of corner-resonance between 0 and 1
// (0 is no resonance, 1 is maximum)
// * `fr`: corner-resonance frequency in Hz (less than SR/6.3 or so)
//
// #### References
// * <https://ccrma.stanford.edu/~stilti/papers/moogvcf.pdf>
// * <https://ccrma.stanford.edu/~jos/pasp/vegf.html>
//------------------------------------------------------------
declare moog_vcf author "Julius O. Smith III";
declare moog_vcf copyright "Copyright (C) 2003-2019 by Julius O. Smith III <[email protected]>";
declare moog_vcf license "MIT-style STK-4.3 license";
moog_vcf(res,fr) = (+ : seq(i,4,fi.pole(p)) : *(unitygain(p))) ~ *(mk)
with {
p = 1.0 - fr * 2.0 * ma.PI / ma.SR; // good approximation for fr << SR
unitygain(p) = pow(1.0-p,4.0); // one-pole unity-gain scaling
mk = -4.0*max(0,min(res,0.999999)); // need mk > -4 for stability
};
//-----------------------`(ve.)moog_vcf_2b[n]`---------------------------
// Moog "Voltage Controlled Filter" (VCF) as two biquads. Implementation
// of the ideal Moog VCF transfer function factored into second-order
// sections. As a result, it is more accurate than `moog_vcf` above, but
// its coefficient formulas are more complex when one or both parameters
// are varied. Here, res is the fourth root of that in `moog_vcf`, so, as
// the sampling rate approaches infinity, `moog_vcf(res,fr)` becomes equivalent
// to `moog_vcf_2b[n](res^4,fr)` (when res and fr are constant).
// `moog_vcf_2b` uses two direct-form biquads (`tf2`).
// `moog_vcf_2bn` uses two protected normalized-ladder biquads (`tf2np`).
//
// #### Usage
//
// ```
// moog_vcf_2b(res,fr)
// moog_vcf_2bn(res,fr)
// ```
//
// Where:
//
// * `res`: normalized amount of corner-resonance between 0 and 1
// (0 is min resonance, 1 is maximum)
// * `fr`: corner-resonance frequency in Hz
//------------------------------------------------------------
declare moog_vcf_2b author "Julius O. Smith III";
declare moog_vcf_2b copyright "Copyright (C) 2003-2019 by Julius O. Smith III <[email protected]>";
declare moog_vcf_2b license "MIT-style STK-4.3 license";
moog_vcf_2b(res,fr) = fi.tf2s(0,0,b0,a11,a01,w1) : fi.tf2s(0,0,b0,a12,a02,w1)
with {
s = 1; // minus the open-loop location of all four poles
frl = max(20,min(10000,fr)); // limit fr to reasonable 20-10k Hz range
w1 = 2*ma.PI*frl; // frequency-scaling parameter for bilinear xform
// Equivalent: w1 = 1; s = 2*PI*frl;
kmax = sqrt(2)*0.99999; // 0.99999 gives stability margin (tf2 is unprotected)
k = min(kmax,sqrt(2)*res); // fourth root of Moog VCF feedback gain
b0 = s^2;
s2k = sqrt(2) * k;
a11 = s * (2 + s2k);
a12 = s * (2 - s2k);
a01 = b0 * (1 + s2k + k^2);
a02 = b0 * (1 - s2k + k^2);
};
declare moog_vcf_2bn author "Julius O. Smith III";
declare moog_vcf_2bn copyright "Copyright (C) 2003-2019 by Julius O. Smith III <[email protected]>";
declare moog_vcf_2bn license "MIT-style STK-4.3 license";
moog_vcf_2bn(res,fr) = fi.tf2snp(0,0,b0,a11,a01,w1) : fi.tf2snp(0,0,b0,a12,a02,w1)
with {
s = 1; // minus the open-loop location of all four poles
w1 = 2*ma.PI*max(fr,20); // frequency-scaling parameter for bilinear xform
k = sqrt(2)*0.99999*res; // fourth root of Moog VCF feedback gain
b0 = s^2;
s2k = sqrt(2) * k;
a11 = s * (2 + s2k);
a12 = s * (2 - s2k);
a01 = b0 * (1 + s2k + k^2);
a02 = b0 * (1 - s2k + k^2);
};
//------------------`(ve.)moogLadder`-----------------
// Virtual analog model of the 4th-order Moog Ladder, which is arguably the
// most well-known ladder filter in analog synthesizers. Several
// 1st-order filters are cascaded in series. Feedback is then used, in part, to
// control the cut-off frequency and the resonance.
//
// This filter was implemented in Faust by Eric Tarr during the
// [2019 Embedded DSP With Faust Workshop](https://ccrma.stanford.edu/workshops/faust-embedded-19/).
//
// #### References
//
// * <https://www.willpirkle.com/706-2/>
// * <http://www.willpirkle.com/Downloads/AN-4VirtualAnalogFilters.pdf>
//
// #### Usage
//
// ```
// _ : moogLadder(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare moogLadder author "Eric Tarr";
declare moogLadder license "MIT-style STK-4.3 license";
moogLadder(normFreq,Q) = _<:(s1,s2,s3,s4,y) : !,!,!,!,_
letrec{
's1 = -(s4*k):-(s3*g*k):-(s2*g*g*k):-(s1*g*g*g*k):*(A):-(s1):*(B*2):+(s1);
's2 = -(s4*k):-(s3*g*k):-(s2*g*g*k):-(s1*g*g*g*k):*(A):-(s1):*(B):+(s1):-(s2):*(B*2):+(s2);
's3 = -(s4*k):-(s3*g*k):-(s2*g*g*k):-(s1*g*g*g*k):*(A):-(s1):*(B):+(s1):-(s2):*(B):+(s2):-(s3):*(B*2):+(s3);
's4 = -(s4*k):-(s3*g*k):-(s2*g*g*k):-(s1*g*g*g*k):*(A):-(s1):*(B):+(s1):-(s2):*(B):+(s2):-(s3):*(B):+(s3):-(s4):*(B*2):+(s4);
'y = -(s4*k):-(s3*g*k):-(s2*g*g*k):-(s1*g*g*g*k):*(A):-(s1):*(B):+(s1):-(s2):*(B):+(s2):-(s3):*(B):+(s3):-(s4):*(B):+(s4);
}
with{
freq = 2*(10^(3*normFreq+1));
k = (3.9 - (normFreq^0.2)*0.9)*(Q - 0.707)/(25.0 - 0.707);
//k = 3.9*(Q - 0.707)/(25.0 - 0.707);
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G = g*g*g*g;
A = 1/(1+(k*G));
B = g/(1+g);
};
//------------------`(ve.)moogHalfLadder`-----------------
// Virtual analog model of the 2nd-order Moog Half Ladder (simplified version of
// `(ve.)moogLadder`). Several 1st-order filters are cascaded in series.
// Feedback is then used, in part, to control the cut-off frequency and the
// resonance.
//
// This filter was implemented in Faust by Eric Tarr during the
// [2019 Embedded DSP With Faust Workshop](https://ccrma.stanford.edu/workshops/faust-embedded-19/).
//
// #### References
//
// * <https://www.willpirkle.com/app-notes/virtual-analog-moog-half-ladder-filter>
// * <http://www.willpirkle.com/Downloads/AN-8MoogHalfLadderFilter.pdf>
//
// #### Usage
//
// ```
// _ : moogHalfLadder(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare moogHalfLadder author "Eric Tarr";
declare moogHalfLadder license "MIT-style STK-4.3 license";
moogHalfLadder(normFreq,Q) = _ <: (s1,s2,s3,y) : !,!,!,_
letrec{
's1 = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha*2):+(s1);
's2 = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha):+(s1):-(s2):*(alpha*2):+(s2);
's3 = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha):+(s1):-(s2):*(alpha):+(s2):-(s3):*(alpha*2):+(s3);
'y = -(s3*B3*k):-(s2*B2*k):-(s1*B1*k):*(alpha0):-(s1):*(alpha):+(s1):-(s2):*(alpha):+(s2) <:_*-1,((-(s3):*(alpha):+(s3))*2):>_;
}
with{
freq = 2*(10^(3*normFreq+1));
k = 2.0*(Q - 0.707)/(25.0 - 0.707);
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G = g/(1.0 + g);
alpha = G;
GA = 2*G-1; // All-pass gain
B1 = GA*G/(1+g);
B2 = GA/(1+g);
B3 = 2/(1+g);
alpha0 = 1/(1 + k*GA*G*G);
};
//------------------`(ve.)diodeLadder`-----------------
// 4th order virtual analog diode ladder filter. In addition to the individual
// states used within each independent 1st-order filter, there are also additional
// feedback paths found in the block diagram. These feedback paths are labeled
// as connecting states. Rather than separately storing these connecting states
// in the Faust implementation, they are simply implicitly calculated by
// tracing back to the other states (`s1`,`s2`,`s3`,`s4`) each recursive step.
//
// This filter was implemented in Faust by Eric Tarr during the
// [2019 Embedded DSP With Faust Workshop](https://ccrma.stanford.edu/workshops/faust-embedded-19/).
//
// #### References
//
// * <https://www.willpirkle.com/virtual-analog-diode-ladder-filter/>
// * <http://www.willpirkle.com/Downloads/AN-6DiodeLadderFilter.pdf>
//
// #### Usage
//
// ```
// _ : diodeLadder(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare diodeLadder author "Eric Tarr";
declare diodeLadder license "MIT-style STK-4.3 license";
diodeLadder(normFreq,Q) = ef.cubicnl(1,0)*1.5 <:(s1,s2,s3,s4,y) : !,!,!,!,_
letrec{
's1 = _-(s4*B4*SG4*k) :
_-((s4*B4*d3+s3)*B3*SG3*k) :
_-(((s4*B4*d3+s3)*B3*d2 + s2)*B2*SG3*k) :
_-((((s4*B4*d3+s3)*B3*d2 + s2)*B2*d1 + s1)*B1*SG1*k) :
_*alpha0: _*gam1 : _+((s4*B4*d3+s3)*B3*d2 + s2)*B2 : //_+S2
_+((((s4*B4*d3+s3)*B3*d2 + s2)*B2)*d1 + s1)*B1*G2 : // _ + (S2 ...
_*a1 : _-s1 :_*alpha*2 : _+s1;
's2 = _-(s4*B4*SG4*k) :
_-((s4*B4*d3+s3)*B3*SG3*k) :
_-(((s4*B4*d3+s3)*B3*d2 + s2)*B2*SG3*k):
_-((((s4*B4*d3+s3)*B3*d2 + s2)*B2*d1 + s1)*B1*SG1*k) :
_*alpha0: _*gam1 : _+((s4*B4*d3+s3)*B3*d2 + s2)*B2 : //_+S2
_+((((s4*B4*d3+s3)*B3*d2 + s2)*B2)*d1 + s1)*B1*G2 : // _ + (S2 ...
_*a1 : _-s1 :_*alpha : _+s1 : _*gam2 :
_+(s4*B4*d3 + s3)*B3 : //_+S3 :
_+(((s4*B4*d3 + s3)*B3)*d2 + s2)*B2*G3 : //_+(S3...)
_*a2 : _-s2 : _*alpha*2 : _+s2;
's3 = _-(s4*B4*SG4*k) :
_-((s4*B4*d3+s3)*B3*SG3*k) :
_-(((s4*B4*d3+s3)*B3*d2 + s2)*B2*SG3*k) :
_-((((s4*B4*d3+s3)*B3*d2 + s2)*B2*d1 + s1)*B1*SG1*k) :
_*alpha0 : _*gam1 : _+((s4*B4*d3+s3)*B3*d2 + s2)*B2 : //_+S2
_+((((s4*B4*d3+s3)*B3*d2 + s2)*B2)*d1+s1)*B1*G2 : // _ + (S2 ...
_*a1 : _-s1 :_*alpha : _+s1 : _*gam2 :
_+(s4*B4*d3 + s3)*B3 : //_+S3 :
_+(((s4*B4*d3 + s3)*B3)*d2 + s2)*B2*G3 : //_+(S3...)
_*a2 : _-s2 : _*alpha : _+s2 : _*gam3:
_+s4*B4 : // _ + S4
_+((s4*B4)*d3 + s3)*B3*G4: // _ + S4 ...
_*a3 : _-s3 : _*alpha*2 : _+s3;
's4 = _-(s4*B4*SG4*k) :
_-((s4*B4*d3+s3)*B3*SG3*k) :
_-(((s4*B4*d3+s3)*B3*d2 + s2)*B2*SG3*k) :
_-((((s4*B4*d3+s3)*B3*d2 + s2)*B2*d1 + s1 )*B1*SG1*k) :
_*alpha0 : _*gam1 : _+((s4*B4*d3+s3)*B3*d2 + s2)*B2 : //_+S2
_+((((s4*B4*d3+s3)*B3*d2 + s2)*B2)*d1 + s1)*B1*G2 : // _ + (S2 ...
_*a1 : _-s1 :_*alpha : _+s1 : _*gam2 :
_+(s4*B4*d3 + s3)*B3 : //_+S3 :
_+(((s4*B4*d3 + s3)*B3) *d2+s2)*B2*G3 : //_+(S3...)
_*a2 : _-s2 : _*alpha : _+s2 : _*gam3 :
_+s4*B4 : // _ + S4
_+((s4*B4)*d3 + s3)*B3*G4: // _ + S4 ...
_*a3 : _-s3 : _*alpha : _+s3 : _*gam4 : _*a4 : _-s4 : _*alpha*2 : _+s4;
// Output signal
'y = _-(s4*B4*SG4*k) :
_-((s4*B4*d3+s3)*B3*SG3*k) :
_-(((s4*B4*d3+s3)*B3*d2 + s2)*B2*SG3*k) :
_-((((s4*B4*d3+s3)*B3*d2 + s2)*B2*d1 + s1 )*B1*SG1*k) :
_*alpha0: _*gam1 : _+((s4*B4*d3+s3)*B3*d2 + s2)*B2 : //_+S2
_+((((s4*B4*d3+s3)*B3*d2 + s2)*B2)*d1 + s1)*B1*G2 : // _ + (S2 ...
_*a1 : _-s1 :_*alpha : _+s1 : _*gam2 :
_+(s4*B4*d3 + s3)*B3 : //_+S3 :
_+(((s4*B4*d3 + s3)*B3)*d2 + s2)*B2*G3 : //_+(S3...)
_*a2 : _-s2 : _*alpha : _+s2 : _*gam3 :
_+s4*B4 : // _ + S4
_+((s4*B4)*d3 + s3)*B3*G4: // _ + S4 ...
_*a3 : _-s3 : _*alpha : _+s3 : _*gam4 : _*a4 : _-s4 : _*alpha : _+s4;
}
with{
freq = 2*(10^(3*normFreq+1));
k = (17 - (normFreq^10)*9.7)*(Q - 0.707)/(25.0 - 0.707);
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G4 = 0.5*g/(1 + g);
G3 = 0.5*g/(1 + g - 0.5*g*G4);
G2 = 0.5*g/(1 + g - 0.5*g*G3);
G1 = g/(1.0 + g - g*G2);
Gamma = G1*G2*G3*G4;
SG1 = G4*G3*G2; // feedback gain pre-calculated
SG2 = G4*G3;
SG3 = G4;
SG4 = 1;
alpha = g/(1+g);
alpha0 = 1/(1+k*Gamma);
gam1 = 1+G1*G2;
gam2 = 1+G2*G3;
gam3 = 1+G3*G4;
gam4 = 1;
a1 = 1; // a0 for 1st LPF
a2 = 0.5; // a0 for 2nd LPF
a3 = 0.5;
a4 = 0.5;
B1 = 1/(1+g-g*G2); // Beta for 1st block
B2 = 1/(1+g-0.5*g*G3);
B3 = 1/(1+g-0.5*g*G4);
B4 = 1/(1+g);
d1 = g; // delta for 1st block
d2 = 0.5*g;
d3 = 0.5*g;
//d4 = 0;
};
//===================================Korg 35 Filters======================================
// The following filters are virtual analog models of the Korg 35 low-pass
// filter and high-pass filter found in the MS-10 and MS-20 synthesizers.
// The virtual analog models for the LPF and HPF are different, making these
// filters more interesting than simply tapping different states of the same
// circuit.
//
// These filters were implemented in Faust by Eric Tarr during the
// [2019 Embedded DSP With Faust Workshop](https://ccrma.stanford.edu/workshops/faust-embedded-19/).
//
// #### Filter history:
//
// <https://secretlifeofsynthesizers.com/the-korg-35-filter/>
//========================================================================================
//------------------`(ve.)korg35LPF`-----------------
// Virtual analog models of the Korg 35 low-pass filter found in the MS-10 and
// MS-20 synthesizers.
//
// #### Usage
//
// ```
// _ : korg35LPF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare korg35LPF author "Eric Tarr";
declare korg35LPF license "MIT-style STK-4.3 license";
korg35LPF(normFreq,Q) = _ <: (s1,s2,s3,y) : !,!,!,_
letrec{
's1 = _-s1:_*(alpha*2):_+s1;
's2 = _-s1:_*alpha:_+s1:_+(s3*B3):_+(s2*B2):_*alpha0:_-s3:_*alpha:_+s3:_*K:_-s2:_*(alpha*2):_+s2;
's3 = _-s1:_*alpha:_+s1:_+(s3*B3):_+(s2*B2):_*alpha0:_-s3:_*(alpha*2):_+s3;
'y = _-s1:_*alpha:_+s1:_+(s3*B3):_+(s2*B2) :_*alpha0:_-s3:_*alpha:_+s3;
}
with{
freq = 2*(10^(3*normFreq+1));
K = 2.0*(Q - 0.707)/(10.0 - 0.707);
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G = g/(1.0 + g);
alpha = G;
B3 = (K - K*G)/(1 + g);
B2 = -1/(1 + g);
alpha0 = 1/(1 - K*G + K*G*G);
};
//------------------`(ve.)korg35HPF`-----------------
// Virtual analog models of the Korg 35 high-pass filter found in the MS-10 and
// MS-20 synthesizers.
//
// #### Usage
//
// ```
// _ : korg35HPF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare korg35HPF author "Eric Tarr";
declare korg35HPF license "MIT-style STK-4.3 license";
korg35HPF(normFreq,Q) = _ <: (s1,s2,s3,y) : !,!,!,_
letrec{
's1 = _-s1:_*(alpha*2):_+s1;
's2 = _<:(_-s1:_*alpha:_+s1)*-1,_:>_+(s3*B3):_+(s2*B2):_*alpha0:_*K:_-s2:_*alpha*2:_+s2;
's3 = _<:(_-s1:_*alpha:_+s1)*-1,_:>_+(s3*B3):_+(s2*B2):_*alpha0:_*K:_<:(_-s2:_*alpha:_+s2)*-1,_:>_-s3:_*alpha*2:_+s3;
'y = _<:(_-s1:_*alpha:_+s1)*-1,_:>_+(s3*B3):_+(s2*B2):_*alpha0;
}
with{
freq = 2*(10^(3*normFreq+1));
K = 2.0*(Q - 0.707)/(10.0 - 0.707);
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G = g/(1.0 + g);
alpha = G;
B3 = 1.0/(1.0 + g);
B2 = -1.0*G/(1.0 + g);
alpha0 = 1/(1 - K*G + K*G*G);
};
//==================================Oberheim Filters======================================
// The following filter (4 types) is an implementation of the virtual analog
// model described in Section 7.2 of the Will Pirkle book, "Designing Software
// Synthesizer Plug-ins in C++". It is based on the block diagram in Figure 7.5.
//
// The Oberheim filter is a state-variable filter with soft-clipping distortion
// within the circuit.
//
// In many VA filters, distortion is accomplished using the "tanh" function.
// For this Faust implementation, that distortion function was replaced with
// the `(ef.)cubicnl` function.
//========================================================================================
//------------------`(ve.)oberheim`-----------------
// Generic multi-outputs Oberheim filter that produces the BSF, BPF, HPF and LPF outputs (see description above).
//
// #### Usage
//
// ```
// _ : oberheim(normFreq,Q) : _,_,_,_
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare oberheim author "Eric Tarr";
declare oberheim license "MIT-style STK-4.3 license";
oberheim(normFreq,Q) = _<:(s1,s2,ybsf,ybpf,yhpf,ylpf) : !,!,_,_,_,_
letrec{
's1 = _-s2:_-(s1*FBs1):_*alpha0:_*g<:_,(_+s1:ef.cubicnl(0.0,0)):>_;
's2 = _-s2:_-(s1*FBs1):_*alpha0:_*g:_+s1:ef.cubicnl(0.0,0):_*g*2:_+s2;
// Compute the BSF, BPF, HPF, LPF outputs
'ybsf = _-s2:_-(s1*FBs1):_*alpha0<:(_*g:_+s1:ef.cubicnl(0.0,0):_*g:_+s2),_:>_;
'ybpf = _-s2:_-(s1*FBs1):_*alpha0:_*g:_+s1:ef.cubicnl(0.0,0);
'yhpf = _-s2:_-(s1*FBs1):_*alpha0;
'ylpf = _-s2:_-(s1*FBs1):_*alpha0:_*g :_+s1:ef.cubicnl(0.0,0):_*g:_+s2;
}
with{
freq = 2*(10^(3*normFreq+1));
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G = g/(1.0 + g);
R = 1/(2*Q);
FBs1 = (2*R+g);
alpha0 = 1/(1 + 2*R*g + g*g);
};
//------------------`(ve.)oberheimBSF`-----------------
// Band-Stop Oberheim filter (see description above).
// Specialize the generic implementation: keep the first BSF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : oberheimBSF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare oberheimBSF author "Eric Tarr";
declare oberheimBSF license "MIT-style STK-4.3 license";
oberheimBSF(normFreq,Q) = oberheim(normFreq,Q):_,!,!,!;
//------------------`(ve.)oberheimBPF`-----------------
// Band-Pass Oberheim filter (see description above).
// Specialize the generic implementation: keep the second BPF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : oberheimBPF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare oberheimBPF author "Eric Tarr";
declare oberheimBPF license "MIT-style STK-4.3 license";
oberheimBPF(normFreq,Q) = oberheim(normFreq,Q):!,_,!,!;
//------------------`(ve.)oberheimHPF`-----------------
// High-Pass Oberheim filter (see description above).
// Specialize the generic implementation: keep the third HPF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : oberheimHPF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare oberheimHPF author "Eric Tarr";
declare oberheimHPF license "MIT-style STK-4.3 license";
oberheimHPF(normFreq,Q) = oberheim(normFreq,Q):!,!,_,!;
//------------------`(ve.)oberheimLPF`-----------------
// Low-Pass Oberheim filter (see description above).
// Specialize the generic implementation: keep the fourth LPF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : oberheimLPF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare oberheimLPF author "Eric Tarr";
declare oberheimLPF license "MIT-style STK-4.3 license";
oberheimLPF(normFreq,Q) = oberheim(normFreq,Q):!,!,!,_;
//================================Sallen Key Filters======================================
// The following filters were implemented based on VA models of synthesizer
// filters.
//
// The modeling approach is based on a Topology Preserving Transform (TPT) to
// resolve the delay-free feedback loop in the corresponding analog filters.
//
// The primary processing block used to build other filters (Moog, Korg, etc.) is
// based on a 1st-order Sallen-Key filter.
//
// The filters included in this script are 1st-order LPF/HPF and 2nd-order
// state-variable filters capable of LPF, HPF, and BPF.
//
// #### Resources:
//
// * Vadim Zavalishin (2018) "The Art of VA Filter Design", v2.1.0
// <https://www.native-instruments.com/fileadmin/ni_media/downloads/pdf/VAFilterDesign_2.1.0.pdf>
// * Will Pirkle (2014) "Resolving Delay-Free Loops in Recursive Filters Using
// the Modified Härmä Method", AES 137 <http://www.aes.org/e-lib/browse.cfm?elib=17517>
// * Description and diagrams of 1st- and 2nd-order TPT filters:
// <https://www.willpirkle.com/706-2/>
//========================================================================================
//------------------`(ve.)sallenKeyOnePole`-----------------
// Sallen-Key generic One Pole filter that produces the LPF and HPF outputs (see description above).
//
// For the Faust implementation of this filter, recursion (`letrec`) is used
// for storing filter "states". The output (e.g. `y`) is calculated by using
// the input signal and the previous states of the filter.
// During the current recursive step, the states of the filter (e.g. `s`) for
// the next step are also calculated.
// Admittedly, this is not an efficient way to implement a filter because it
// requires independently calculating the output and each state during each
// recursive step. However, it works as a way to store and use "states"
// within the constraints of Faust.
// The simplest example is the 1st-order LPF (shown on the cover of Zavalishin
// 2018 and Fig 4.3 of <https://www.willpirkle.com/706-2/>). Here, the input
// signal is split in parallel for the calculation of the output signal, `y`, and
// the state `s`. The value of the state is only used for feedback to the next
// step of recursion. It is blocked (!) from also being routed to the output.
// A trick used for calculating the state `s` is to observe that the input to
// the delay block is the sum of two signal: what appears to be a feedforward
// path and a feedback path. In reality, the signals being summed are identical
// (signal*2) plus the value of the current state.
//
// #### Usage
//
// ```
// _ : sallenKeyOnePole(normFreq) : _,_
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
declare sallenKeyOnePole author "Eric Tarr";
declare sallenKeyOnePole license "MIT-style STK-4.3 license";
sallenKeyOnePole(normFreq) = _<:(s,ylpf,-(ylpf)) : !,_,_
letrec {
's = -(s):*(2*G):+(s);
'ylpf = -(s):*(G):+(s);
}
with{
freq = 2*(10^(3*normFreq+1));
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G = g/(1.0 + g);
};
//------------------`(ve.)sallenKeyOnePoleLPF`-----------------
// Sallen-Key One Pole lowpass filter (see description above).
// Specialize the generic implementation: keep the first LPF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : sallenKeyOnePoleLPF(normFreq) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
declare sallenKeyOnePoleLPF author "Eric Tarr";
declare sallenKeyOnePoleLPF license "MIT-style STK-4.3 license";
sallenKeyOnePoleLPF(normFreq) = sallenKeyOnePole(normFreq) : _,!;
//------------------`(ve.)sallenKeyOnePoleHPF`-----------------
// Sallen-Key One Pole Highpass filter (see description above). The dry input
// signal is routed in parallel to the output. The LPF'd signal is subtracted
// from the input so that the HPF remains.
// Specialize the generic implementation: keep the second HPF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : sallenKeyOnePoleHPF(normFreq) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
//---------------------------------------------------------------------
declare sallenKeyOnePoleHPF author "Eric Tarr";
declare sallenKeyOnePoleHPF license "MIT-style STK-4.3 license";
sallenKeyOnePoleHPF(normFreq) = sallenKeyOnePole(normFreq) : !,_;
//------------------`(ve.)sallenKey2ndOrder`-----------------
// Sallen-Key generic 2nd order filter that produces the LPF, BPF and HPF outputs.
//
// This is a 2nd-order Sallen-Key state-variable filter. The idea is that by
// "tapping" into different points in the circuit, different filters
// (LPF,BPF,HPF) can be achieved. See Figure 4.6 of
// <https://www.willpirkle.com/706-2/>
//
// This is also a good example of the next step for generalizing the Faust
// programming approach used for all these VA filters. In this case, there are
// three things to calculate each recursive step (`y`,`s1`,`s2`). For each thing, the
// circuit is only calculated up to that point.
//
// Comparing the LPF to BPF, the output signal (`y`) is calculated similarly.
// Except, the output of the BPF stops earlier in the circuit. Similarly, the
// states (`s1` and `s2`) only differ in that `s2` includes a couple more terms
// beyond what is used for `s1`.
//
// #### Usage
//
// ```
// _ : sallenKey2ndOrder(normFreq,Q) : _,_,_
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare sallenKey2ndOrder author "Eric Tarr";
declare sallenKey2ndOrder license "MIT-style STK-4.3 license";
sallenKey2ndOrder(normFreq,Q) = _<:(s1,s2,ylpf,ybpf,yhpf) : !,!,_,_,_
letrec{
's1 = -(s2):-(s1*FBs1):*(alpha0):*(g*2):+(s1);
's2 = -(s2):-(s1*FBs1):*(alpha0):*(g):+(s1):*(g*2):+(s2);
// Compute the LPF, BPF, HPF outputs
'ylpf = -(s2):-(s1*FBs1):*(alpha0):*(g*2):+(s1):*(g):+(s2);
'ybpf = -(s2):-(s1*FBs1):*(alpha0):*(g):+(s1);
'yhpf = -(s2):-(s1*FBs1):*(alpha0);
}
with{
freq = 2*(10^(3*normFreq+1));
wd = 2*ma.PI*freq;
T = 1/ma.SR;
wa = (2/T)*tan(wd*T/2);
g = wa*T/2;
G = g/(1.0 + g);
R = 1/(2*Q);
FBs1 = (2*R+g);
alpha0 = 1/(1 + 2*R*g + g*g);
};
//------------------`(ve.)sallenKey2ndOrderLPF`-----------------
// Sallen-Key 2nd order lowpass filter (see description above).
// Specialize the generic implementation: keep the first LPF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : sallenKey2ndOrderLPF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare sallenKey2ndOrderLPF author "Eric Tarr";
declare sallenKey2ndOrderLPF license "MIT-style STK-4.3 license";
sallenKey2ndOrderLPF(normFreq,Q) = sallenKey2ndOrder(normFreq,Q) : _,!,!;
//------------------`(ve.)sallenKey2ndOrderBPF`-----------------
// Sallen-Key 2nd order bandpass filter (see description above).
// Specialize the generic implementation: keep the second BPF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : sallenKey2ndOrderBPF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare sallenKey2ndOrderBPF author "Eric Tarr";
declare sallenKey2ndOrderBPF license "MIT-style STK-4.3 license";
sallenKey2ndOrderBPF(normFreq,Q) = sallenKey2ndOrder(normFreq,Q) : !,_,!;
//------------------`(ve.)sallenKey2ndOrderHPF`-----------------
// Sallen-Key 2nd order highpass filter (see description above).
// Specialize the generic implementation: keep the third HPF output,
// the compiler will only generate the needed code.
//
// #### Usage
//
// ```
// _ : sallenKey2ndOrderHPF(normFreq,Q) : _
// ```
//
// Where:
//
// * `normFreq`: normalized frequency (0-1)
// * `Q`: q
//---------------------------------------------------------------------
declare sallenKey2ndOrderHPF author "Eric Tarr";
declare sallenKey2ndOrderHPF license "MIT-style STK-4.3 license";
sallenKey2ndOrderHPF(normFreq,Q) = sallenKey2ndOrder(normFreq,Q) : !,!,_;
//=========================================Effects========================================
//========================================================================================
//--------------------------`(ve.)wah4`-------------------------------
// Wah effect, 4th order.
// `wah4` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : wah4(fr) : _
// ```
//
// Where:
//
// * `fr`: resonance frequency in Hz
//
// #### Reference
//
// <https://ccrma.stanford.edu/~jos/pasp/vegf.html>
//------------------------------------------------------------
wah4(fr) = 4*moog_vcf((3.2/4),fr:si.smooth(0.999));
//------------------------`(ve.)autowah`-----------------------------
// Auto-wah effect.
// `autowah` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : autowah(level) : _
// ```
//
// Where:
//
// * `level`: amount of effect desired (0 to 1).
//------------------------------------------------------------
autowah(level,x) = level * crybaby(an.amp_follower(0.1,x),x) + (1.0-level)*x;
//--------------------------`(ve.)crybaby`-----------------------------
// Digitized CryBaby wah pedal.
// `crybaby` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : crybaby(wah) : _
// ```
//
// Where:
//
// * `wah`: "pedal angle" from 0 to 1
//
// #### Reference
//
// <https://ccrma.stanford.edu/~jos/pasp/vegf.html>
//------------------------------------------------------------
crybaby(wah) = *(gs) : fi.tf2(1,-1,0,a1s,a2s)
with {
Q = pow(2.0,(2.0*(1.0-wah)+1.0)); // Resonance "quality factor"
fr = 450.0*pow(2.0,2.3*wah); // Resonance tuning
g = 0.1*pow(4.0,wah); // gain (optional)
// Biquad fit using z = exp(s T) ~ 1 + sT for low frequencies:
frn = fr/ma.SR; // Normalized pole frequency (cycles per sample)
R = 1 - ma.PI*frn/Q; // pole radius
theta = 2*ma.PI*frn; // pole angle
a1 = 0-2.0*R*cos(theta); // biquad coeff
a2 = R*R; // biquad coeff
// dezippering of slider-driven signals:
s = 0.999; // smoothing parameter (one-pole pole location)
a1s = a1 : si.smooth(s);
a2s = a2 : si.smooth(s);
gs = g : si.smooth(s);
//tf2 = component("filters.lib").tf2;
};
// end jos section
/************************************************************************
************************************************************************
FAUST library file, GRAME section
Except where noted otherwise, Copyright (C) 2003-2017 by GRAME,
Centre National de Creation Musicale.
----------------------------------------------------------------------
GRAME LICENSE
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
EXCEPTION TO THE LGPL LICENSE : As a special exception, you may create a
larger FAUST program which directly or indirectly imports this library
file and still distribute the compiled code generated by the FAUST
compiler, or a modified version of this compiled code, under your own
copyright and license. This EXCEPTION TO THE LGPL LICENSE explicitly
grants you the right to freely choose the license for the resulting
compiled code. In particular the resulting compiled code has no obligation
to be LGPL or GPL. For example you are free to choose a commercial or
closed source license or any other license if you decide so.
************************************************************************
************************************************************************/
//----------------------------`(ve.)vocoder`-------------------------
// A very simple vocoder where the spectrum of the modulation signal
// is analyzed using a filter bank.
// `vocoder` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : vocoder(nBands,att,rel,BWRatio,source,excitation) : _;
// ```
//
// Where:
//
// * `nBands`: Number of vocoder bands
// * `att`: Attack time in seconds
// * `rel`: Release time in seconds
// * `BWRatio`: Coefficient to adjust the bandwidth of each band (0.1 - 2)
// * `source`: Modulation signal
// * `excitation`: Excitation/Carrier signal
//------------------------------------------------------------
// TODO: author RM
oneVocoderBand(band,bandsNumb,bwRatio,bandGain,x) = x : fi.resonbp(bandFreq,bandQ,bandGain) with {
bandFreq = 25*pow(2,(band+1)*(9/bandsNumb));
BW = (bandFreq - 25*pow(2,(band)*(9/bandsNumb)))*bwRatio;
bandQ = bandFreq/BW;
};
vocoder(nBands,att,rel,BWRatio,source,excitation) = source <: par(i,nBands,oneVocoderBand(i,nBands,BWRatio,1) :
an.amp_follower_ar(att,rel) : _,excitation : oneVocoderBand(i,nBands,BWRatio)) :> _ ;
//########################################################################################
/************************************************************************
FAUST library file, further contributions section
All contributions below should indicate both the contributor and terms
of license. If no such indication is found, "git blame" will say who
last edited each line, and that person can be emailed to inquire about
license disposition, if their license choice is not already indicated
elsewhere among the libraries. It is expected that all software will be
released under LGPL, STK-4.3, MIT, BSD, or a similar FOSS license.
************************************************************************/
// end further further contributions section