forked from grame-cncm/faustlibraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compressors.lib
1399 lines (1302 loc) · 65.6 KB
/
compressors.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
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//#################################### compressors.lib ###################################
// A library of compressor effects. Its official prefix is `co`.
//
// #### References
// * <https://github.com/grame-cncm/faustlibraries/blob/master/compressors.lib>
//########################################################################################
/************************************************************************
************************************************************************
FAUST library file
Copyright (C) 2003-2016 GRAME, Centre National de Creation Musicale
----------------------------------------------------------------------
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.
************************************************************************
************************************************************************/
ba = library("basics.lib");
si = library("signals.lib");
an = library("analyzers.lib");
ro = library("routes.lib");
ma = library("maths.lib");
it = library("interpolators.lib");
declare name "Faust Compressor Effect Library";
declare version "1.6.0";
//================================Conversion Tools=======================================
// Useful conversion tools for compressors.
//========================================================================================
//--------------------`(co.)ratio2strength `-------------------
// Most compressors have a ratio parameter to define the amount of compression.
// A ratio of 1 means no compression, a ratio of 2 means that for every dB the input goes above the threshold,
// the output gets turned down half a dB.
// To use a compressor as a brick wall limiter, the ratio needs to be infinity.
// This is hard to express in a faust UI element, and overcompression can not be expressed at all,
// therefore most compressors in this library use a strength parameter instead, where
// 0 means no compression, 1 means hard limiting and bigger than 1 means over-compression.
//
// This utility converts a ratio to a strength.
//
// #### Usage
//
// ```
// ratio2strength(ratio) : _
// ```
//
// Where:
//
// * `ratio`: compression ratio, between 1 and infinity (1=no compression, infinity means hard limiting)
//------------------------------------------------------------
declare ratio2strength author "Bart Brouns";
declare ratio2strength license "GPLv3";
ratio2strength(ratio) = 1-(1/ratio);
//--------------------`(co.)strength2ratio `-------------------
// Most compressors have a ratio parameter to define the amount of compression.
// A ratio of 1 means no compression, a ratio of 2 means that for every dB the input goes above the threshold,
// the output gets turned down half a dB.
// To use a compressor as a brick wall limiter, the ratio needs to be infinity.
// This is hard to express in a faust UI element, and overcompression can not be expressed at all,
// therefore most compressors in this library use a strength parameter instead, where
// 0 means no compression, 1 means hard limiting and bigger than 1 means over-compression.
//
// This utility converts a strength to a ratio.
//
// #### Usage
//
// ```
// strength2ratio(strength) : _
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
//------------------------------------------------------------
declare strength2ratio author "Bart Brouns";
declare strength2ratio license "GPLv3";
strength2ratio(strength) = 1/(1-strength);
//=============================Functions Reference========================================
//========================================================================================
//--------------------`(co.)peak_compression_gain_mono_db`-------------------
// Mono dynamic range compressor gain computer with dB output.
// `peak_compression_gain_mono_db` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : peak_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost) : _
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare peak_compression_gain_mono_db author "Bart Brouns";
declare peak_compression_gain_mono_db license "GPLv3";
peak_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost) =
abs : ba.bypass1(prePost,si.onePoleSwitching(att,rel)) : ba.linear2db : gain_computer(strength,thresh,knee) : ba.bypass1((prePost !=1),si.onePoleSwitching(rel,att))
with {
gain_computer(strength,thresh,knee,level) =
select3((level>(thresh-(knee/2)))+(level>(thresh+(knee/2))),
0,
((level-thresh+(knee/2)) : pow(2)/(2*max(ma.EPSILON,knee))),
(level-thresh))
: max(0)*-strength;
};
//--------------------`(co.)peak_compression_gain_N_chan_db`-------------------
// N channels dynamic range compressor gain computer with dB output.
// `peak_compression_gain_N_chan_db` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : peak_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
// * `link`: the amount of linkage between the channels: 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `N`: the number of channels of the compressor, known at compile time
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare peak_compression_gain_N_chan_db author "Bart Brouns";
declare peak_compression_gain_N_chan_db license "GPLv3";
// generalise compression gains for N channels.
// first we define a mono version:
peak_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,1) =
peak_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost);
// The actual N-channels version:
// Calculate the maximum gain reduction of N channels,
// and then crossfade between that and each channel's own gain reduction,
// to link/unlink channels
peak_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,N) =
par(i, N, peak_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost))
<: (si.bus(N),(ba.parallelMin(N) <: si.bus(N))) : ro.interleave(N,2) : par(i,N,(it.interpolate_linear(link)));
//--------------------`(co.)FFcompressor_N_chan`-------------------
// Feed forward N channels dynamic range compressor.
// `FFcompressor_N_chan` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : FFcompressor_N_chan(strength,thresh,att,rel,knee,prePost,link,meter,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
// * `link`: the amount of linkage between the channels: 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `meter`: a gain reduction meter. It can be implemented like so:
// `meter = _<:(_, (ba.linear2db:max(maxGR):meter_group((hbargraph("[1][unit:dB][tooltip: gain reduction in dB]", maxGR, 0))))):attach;`
// * `N`: the number of channels of the compressor, known at compile time
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare FFcompressor_N_chan author "Bart Brouns";
declare FFcompressor_N_chan license "GPLv3";
// feed forward compressor
FFcompressor_N_chan(strength,thresh,att,rel,knee,prePost,link,meter,N) =
si.bus(N) <: (peak_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,N),si.bus(N)) : ro.interleave(N,2) : par(i,N,(meter: ba.db2linear)*_);
//--------------------`(co.)FBcompressor_N_chan`-------------------
// Feed back N channels dynamic range compressor.
// `FBcompressor_N_chan` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : FBcompressor_N_chan(strength,thresh,att,rel,knee,prePost,link,meter,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
// * `link`: the amount of linkage between the channels. 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `meter`: a gain reduction meter. It can be implemented with:
// `meter = _ <: (_,(ba.linear2db:max(maxGR):meter_group((hbargraph("[1][unit:dB][tooltip: gain reduction in dB]", maxGR, 0))))):attach;`
// or it can be omitted by defining `meter = _;`.
// * `N`: the number of channels of the compressor, known at compile time
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare FBcompressor_N_chan author "Bart Brouns";
declare FBcompressor_N_chan license "GPLv3";
FBcompressor_N_chan(strength,thresh,att,rel,knee,prePost,link,meter,N) =
(peak_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,N),si.bus(N) : (ro.interleave(N,2) : par(i,N,(meter : ba.db2linear)*_))) ~ si.bus(N);
//--------------------`(co.)FBFFcompressor_N_chan`-------------------
// Feed forward / feed back N channels dynamic range compressor.
// The feedback part has a much higher strength, so they end up sounding similar.
// `FBFFcompressor_N_chan` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : FBFFcompressor_N_chan(strength,thresh,att,rel,knee,prePost,link,FBFF,meter,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
// * `link`: the amount of linkage between the channels: 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `FBFF`: fade between feed forward (0) and feed back (1) compression
// * `meter`: a gain reduction meter. It can be implemented like so:
// `meter = _<:(_,(max(maxGR):meter_group((hbargraph("[1][unit:dB][tooltip: gain reduction in dB]", maxGR, 0))))):attach;`
// * `N`: the number of channels of the compressor, known at compile time
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare FBFFcompressor_N_chan author "Bart Brouns";
declare FBFFcompressor_N_chan license "GPLv3";
FBFFcompressor_N_chan(strength,thresh,att,rel,knee,prePost,link,FBFF,meter,N) =
si.bus(N) <: si.bus(N*2) :
(
((par(i,2,peak_compression_gain_N_chan_db(strength*(1+((i==0)*2)),thresh,att,rel,knee,prePost,link,N)) : ro.interleave(N,2) : par(i,N,it.interpolate_linear(FBFF))),si.bus(N))
: (ro.interleave(N,2) : par(i,N,(meter : ba.db2linear)*_))
)
~ si.bus(N);
//--------------------`(co.)RMS_compression_gain_mono_db`-------------------
// Mono RMS dynamic range compressor gain computer with dB output.
// `RMS_compression_gain_mono_db` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : RMS_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost) : _
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare RMS_compression_gain_mono_db author "Bart Brouns";
declare RMS_compression_gain_mono_db license "GPLv3";
RMS_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost) =
RMS(rel) : ba.bypass1(prePost,si.onePoleSwitching(att,0)) : ba.linear2db : gain_computer(strength,thresh,knee) : ba.bypass1((prePost!=1),si.onePoleSwitching(0,att))
with {
gain_computer(strength,thresh,knee,level) =
select3((level>(thresh-(knee/2)))+(level>(thresh+(knee/2))),
0,
((level-thresh+(knee/2)) : pow(2)/(2*max(ma.EPSILON,knee))),
(level-thresh))
: max(0)*-strength;
RMS(time) = ba.slidingRMS(s) with {
s = ba.sec2samp(time):int:max(1);
};
};
//--------------------`(co.)RMS_compression_gain_N_chan_db`-------------------
// RMS N channels dynamic range compressor gain computer with dB output.
// `RMS_compression_gain_N_chan_db` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : RMS_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
// * `link`: the amount of linkage between the channels: 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `N`: the number of channels of the compressor
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare RMS_compression_gain_N_chan_db author "Bart Brouns";
declare RMS_compression_gain_N_chan_db license "GPLv3";
RMS_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,1) =
RMS_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost);
RMS_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,N) =
par(i,N,RMS_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost))
<: (si.bus(N),(ba.parallelMin(N) <: si.bus(N))) : ro.interleave(N,2) : par(i,N,(it.interpolate_linear(link)));
//--------------------`(co.)RMS_FBFFcompressor_N_chan`-------------------
// RMS feed forward / feed back N channels dynamic range compressor.
// The feedback part has a much higher strength, so they end up sounding similar.
// `RMS_FBFFcompressor_N_chan` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : RMS_FBFFcompressor_N_chan(strength,thresh,att,rel,knee,prePost,link,FBFF,meter,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
// * `link`: the amount of linkage between the channels: 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `FBFF`: fade between feed forward (0) and feed back (1) compression.
// * `meter`: a gain reduction meter. It can be implemented with:
// `meter = _<:(_,(max(maxGR):meter_group((hbargraph("[1][unit:dB][tooltip: gain reduction in dB]", maxGR, 0))))):attach;`
// * `N`: the number of channels of the compressor, known at compile time
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// To save CPU we cheat a bit, in a similar way as in the original libs:
// instead of crosfading between two sets of gain calculators as above,
// we take the `abs` of the audio from both the FF and FB, and crossfade between those,
// and feed that into one set of gain calculators
// again the strength is much higher when in FB mode, but implemented differently.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare RMS_FBFFcompressor_N_chan author "Bart Brouns";
declare RMS_FBFFcompressor_N_chan license "GPLv3";
RMS_FBFFcompressor_N_chan(strength,thresh,att,rel,knee,prePost,link,FBFF,meter,N) =
si.bus(N) <: si.bus(N*2):
(
((ro.interleave(N,2) : par(i,N*2,abs) :par(i,N,it.interpolate_linear(FBFF)) : RMS_compression_gain_N_chan_db(strength*(1+((FBFF*-1)+1)),thresh,att,rel,knee,prePost,link,N)),si.bus(N))
: (ro.interleave(N,2) : par(i,N,(meter: ba.db2linear)*_))
)
~ si.bus(N);
//--------------------`(co.)RMS_FBcompressor_peak_limiter_N_chan`-------------------
// N channel RMS feed back compressor into peak limiter feeding back into the FB compressor.
// By combining them this way, they complement each other optimally:
// the RMS compressor doesn't have to deal with the peaks,
// and the peak limiter get's spared from the steady state signal.
// The feedback part has a much higher strength, so they end up sounding similar.
// `RMS_FBcompressor_peak_limiter_N_chan` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : RMS_FBcompressor_peak_limiter_N_chan(strength,thresh,threshLim,att,rel,knee,link,meter,meterLim,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `threshLim`: dB level threshold above which the brickwall limiter kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// this is also used as the release time of the limiter
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// the limiter uses a knee half this size
// * `link`: the amount of linkage between the channels: 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `meter`: compressor gain reduction meter. It can be implemented with:
// `meter = _<:(_,(max(maxGR):meter_group((hbargraph("[1][unit:dB][tooltip: gain reduction in dB]", maxGR, 0))))):attach;`
// * `meterLim`: brickwall limiter gain reduction meter. It can be implemented with:
// `meterLim = _<:(_,(max(maxGR):meter_group((hbargraph("[1][unit:dB][tooltip: gain reduction in dB]", maxGR, 0))))):attach;`
// * `N`: the number of channels of the compressor, known at compile time
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare RMS_FBcompressor_peak_limiter_N_chan author "Bart Brouns";
declare RMS_FBcompressor_peak_limiter_N_chan license "GPLv3";
RMS_FBcompressor_peak_limiter_N_chan(strength,thresh,threshLim,att,rel,knee,link,meter,meterLim,N) =
(((RMS_compression_gain_N_chan_db(strength,thresh,att,rel,knee,0,link,N)),si.bus(N)) : ro.interleave(N,2) : par(i,N,(meter : ba.db2linear)*_) : FFcompressor_N_chan(1,threshLim,0,att:min(rel),knee*0.5,0,link,meterLim,N))
~ si.bus(N);
//===========================Linear gain computer section=================================
// The gain computer functions in this section have been replaced by a version that outputs dBs,
// but we retain the linear output version for backward compatibility.
//========================================================================================
//
//--------------------`(co.)peak_compression_gain_mono`-------------------
// Mono dynamic range compressor gain computer with linear output.
// `peak_compression_gain_mono` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : peak_compression_gain_mono(strength,thresh,att,rel,knee,prePost) : _
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare peak_compression_gain_mono author "Bart Brouns";
declare peak_compression_gain_mono license "GPLv3";
peak_compression_gain_mono(strength,thresh,att,rel,knee,prePost) =
peak_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost):ba.db2linear;
//--------------------`(co.)peak_compression_gain_N_chan`-------------------
// N channels dynamic range compressor gain computer with linear output.
// `peak_compression_gain_N_chan` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : peak_compression_gain_N_chan(strength,thresh,att,rel,knee,prePost,link,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
// * `link`: the amount of linkage between the channels: 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `N`: the number of channels of the compressor, known at compile time
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare peak_compression_gain_N_chan author "Bart Brouns";
declare peak_compression_gain_N_chan license "GPLv3";
// generalise compression gains for N channels.
// first we define a mono version:
peak_compression_gain_N_chan(strength,thresh,att,rel,knee,prePost,link,N) =
peak_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,N)
: par(i, N, ba.db2linear);
//--------------------`(co.)RMS_compression_gain_mono`-------------------
// Mono RMS dynamic range compressor gain computer with linear output.
// `RMS_compression_gain_mono` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : RMS_compression_gain_mono(strength,thresh,att,rel,knee,prePost) : _
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare RMS_compression_gain_mono author "Bart Brouns";
declare RMS_compression_gain_mono license "GPLv3";
RMS_compression_gain_mono(strength,thresh,att,rel,knee,prePost) =
RMS_compression_gain_mono_db(strength,thresh,att,rel,knee,prePost):ba.db2linear;
//--------------------`(co.)RMS_compression_gain_N_chan`-------------------
// RMS N channels dynamic range compressor gain computer with linear output.
// `RMS_compression_gain_N_chan` is a standard Faust function.
//
// #### Usage
//
// ```
// si.bus(N) : RMS_compression_gain_N_chan(strength,thresh,att,rel,knee,prePost,link,N) : si.bus(N)
// ```
//
// Where:
//
// * `strength`: strength of the compression (0 = no compression, 1 means hard limiting, >1 means over-compression)
// * `thresh`: dB level threshold above which compression kicks in
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
// * `knee`: a gradual increase in gain reduction around the threshold:
// below thresh-(knee/2) there is no gain reduction,
// above thresh+(knee/2) there is the same gain reduction as without a knee,
// and in between there is a gradual increase in gain reduction
// * `prePost`: places the level detector either at the input or after the gain computer;
// this turns it from a linear return-to-zero detector into a log domain return-to-threshold detector
// * `link`: the amount of linkage between the channels: 0 = each channel is independent, 1 = all channels have the same amount of gain reduction
// * `N`: the number of channels of the compressor, known at compile time
//
// It uses a strength parameter instead of the traditional ratio, in order to be able to
// function as a hard limiter.
// For that you'd need a ratio of infinity:1, and you cannot express that in Faust.
//
// Sometimes even bigger ratios are useful:
// for example a group recording where one instrument is recorded with both a close microphone and a room microphone,
// and the instrument is loud enough in the room mic when playing loud, but you want to boost it when it is playing soft.
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * Digital Dynamic Range Compressor Design,
// A Tutorial and Analysis,
// Dimitrios GIANNOULIS (<[email protected]>),
// Michael MASSBERG (<[email protected]>),
// and Josuah D.REISS (<[email protected]>)
//------------------------------------------------------------
declare RMS_compression_gain_N_chan author "Bart Brouns";
declare RMS_compression_gain_N_chan license "GPLv3";
RMS_compression_gain_N_chan(strength,thresh,att,rel,knee,prePost,link,N) =
RMS_compression_gain_N_chan_db(strength,thresh,att,rel,knee,prePost,link,N)
: par(i, N, ba.db2linear);
//=============================Original versions section=============================
// The functions in this section are largely superseded by the limiters above, but we
// retain them for backward compatibility and for situations in which a more permissive,
// MIT-style license is required.
//========================================================================================
//--------------------`(co.)compressor_lad_mono`-------------------
// Mono dynamic range compressor with lookahead delay.
// `compressor_lad_mono` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : compressor_lad_mono(lad,ratio,thresh,att,rel) : _
// ```
//
// Where:
//
// * `lad`: lookahead delay in seconds (nonnegative) - gets rounded to nearest sample.
// The effective attack time is a good setting
// * `ratio`: compression ratio (1 = no compression, >1 means compression)
// Ratios: 4 is moderate compression, 8 is strong compression,
// 12 is mild limiting, and 20 is pretty hard limiting at the threshold
// * `thresh`: dB level threshold above which compression kicks in (0 dB = max level)
// * `att`: attack time = time constant (sec) when level & compression are going up
// * `rel`: release time = time constant (sec) coming out of compression
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * <https://ccrma.stanford.edu/~jos/filters/Nonlinear_Filter_Example_Dynamic.html>
// * Albert Graef's "faust2pd"/examples/synth/compressor_.dsp
// * More features: <https://github.com/magnetophon/faustCompressors>
//------------------------------------------------------------
declare compressor_lad_mono author "Julius O. Smith III";
declare compressor_lad_mono copyright
"Copyright (C) 2014-2020 by Julius O. Smith III <[email protected]>";
declare compressor_lad_mono license "MIT-style STK-4.3 license";
compressor_lad_mono(lad,ratio,thresh,att,rel,x)
= x@max(0,floor(0.5+ma.SR*lad)) * compression_gain_mono(ratio,thresh,att,rel,x);
//--------------------`(co.)compressor_mono`-------------------
// Mono dynamic range compressors.
// `compressor_mono` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : compressor_mono(ratio,thresh,att,rel) : _
// ```
//
// Where:
//
// * `ratio`: compression ratio (1 = no compression, >1 means compression)
// Ratios: 4 is moderate compression, 8 is strong compression,
// 12 is mild limiting, and 20 is pretty hard limiting at the threshold
// * `thresh`: dB level threshold above which compression kicks in (0 dB = max level)
// * `att`: attack time = time constant (sec) when level & compression are going up
// * `rel`: release time = time constant (sec) coming out of compression
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * <https://ccrma.stanford.edu/~jos/filters/Nonlinear_Filter_Example_Dynamic.html>
// * Albert Graef's "faust2pd"/examples/synth/compressor_.dsp
// * More features: <https://github.com/magnetophon/faustCompressors>
//------------------------------------------------------------
declare compressor_mono author "Julius O. Smith III";
declare compressor_mono copyright
"Copyright (C) 2014-2020 by Julius O. Smith III <[email protected]>";
declare compressor_mono license "MIT-style STK-4.3 license";
compressor_mono = compressor_lad_mono(0);
//--------------------`(co.)compressor_stereo`-------------------
// Stereo dynamic range compressors.
//
// #### Usage
//
// ```
// _,_ : compressor_stereo(ratio,thresh,att,rel) : _,_
// ```
//
// Where:
//
// * `ratio`: compression ratio (1 = no compression, >1 means compression)
// * `thresh`: dB level threshold above which compression kicks in (0 dB = max level)
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * <https://ccrma.stanford.edu/~jos/filters/Nonlinear_Filter_Example_Dynamic.html>
// * Albert Graef's "faust2pd"/examples/synth/compressor_.dsp
// * More features: <https://github.com/magnetophon/faustCompressors>
//------------------------------------------------------------
declare compressor_stereo author "Julius O. Smith III";
declare compressor_stereo copyright
"Copyright (C) 2014-2020 by Julius O. Smith III <[email protected]>";
declare compressor_stereo license "MIT-style STK-4.3 license";
compressor_stereo(ratio,thresh,att,rel,x,y) = cgm*x, cgm*y with {
cgm = compression_gain_mono(ratio,thresh,att,rel,abs(x)+abs(y));
};
//--------------------`(co.)compression_gain_mono`-------------------
// Compression-gain calculation for dynamic range compressors.
//
// #### Usage
//
// ```
// _ : compression_gain_mono(ratio,thresh,att,rel) : _
// ```
//
// Where:
//
// * `ratio`: compression ratio (1 = no compression, >1 means compression)
// * `thresh`: dB level threshold above which compression kicks in (0 dB = max level)
// * `att`: attack time = time constant (sec) when level & compression going up
// * `rel`: release time = time constant (sec) coming out of compression
//
// #### References
//
// * <http://en.wikipedia.org/wiki/Dynamic_range_compression>
// * <https://ccrma.stanford.edu/~jos/filters/Nonlinear_Filter_Example_Dynamic.html>
// * Albert Graef's "faust2pd"/examples/synth/compressor_.dsp
// * More features: <https://github.com/magnetophon/faustCompressors>
//------------------------------------------------------------
declare compression_gain_mono author "Julius O. Smith III";
declare compression_gain_mono copyright
"Copyright (C) 2014-2020 by Julius O. Smith III <[email protected]>";
declare compression_gain_mono license "MIT-style STK-4.3 license";
compression_gain_mono(ratio,thresh,att,rel) =
an.amp_follower_ar(att,rel) : ba.linear2db : outminusindb(ratio,thresh) :
kneesmooth(att) : ba.db2linear
with {
// kneesmooth(att) installs a "knee" in the dynamic-range compression,
// where knee smoothness is set equal to half that of the compression-attack.
// A general 'knee' parameter could be used instead of tying it to att/2:
kneesmooth(att) = si.smooth(ba.tau2pole(att/2.0));
// compression gain in dB:
outminusindb(ratio,thresh,level) = max(level-thresh,0.0) * (1.0/max(ma.EPSILON,float(ratio))-1.0);
// Note: "float(ratio)" REQUIRED when ratio is an integer > 1!
};
//----------------`(co.)limiter_1176_R4_mono`----------------------
// A limiter guards against hard-clipping. It can be
// implemented as a compressor having a high threshold (near the
// clipping level), fast attack, and high ratio. Since
// the compression ratio is so high, some knee smoothing is
// desirable (for softer limiting). This example is intended
// to get you started using compressors as limiters, so all
// parameters are hardwired here to nominal values.
//
// `ratio`: 4 (moderate compression).
// See `compressor_mono` comments for a guide to other choices.
// Mike Shipley likes this (lowest) setting on the 1176.
// (Grammy award-winning mixer for Queen, Tom Petty, etc.).
//
// `thresh`: -6 dB, meaning 4:1 compression begins at amplitude 1/2.
//
// `att`: 800 MICROseconds (Note: scaled by ratio in the 1176)
// The 1176 range is said to be 20-800 microseconds.
// Faster attack gives "more bite" (e.g. on vocals),
// and makes hard-clipping less likely on fast overloads.
//
// `rel`: 0.5 s (Note: scaled by ratio in the 1176)
// The 1176 range is said to be 50-1100 ms.
//