1declare id "mbc";
2declare name "Multi Band Compressor";
3declare shortname "MB Comp";
4declare category "Guitar Effects";
5declare description "Multi Band Compressor contributed by kokoko3k";
6
7import("stdfaust.lib");
8import("reducemaps.lib");
9
10vmeter1(x)		= attach(x, envelop(x) : vbargraph("v1[nomidi][log]", -70, +5));
11vmeter2(x)		= attach(x, envelop(x) : vbargraph("v2[nomidi][log]", -70, +5));
12vmeter3(x)		= attach(x, envelop(x) : vbargraph("v3[nomidi][log]", -70, +5));
13vmeter4(x)		= attach(x, envelop(x) : vbargraph("v4[nomidi][log]", -70, +5));
14vmeter5(x)		= attach(x, envelop(x) : vbargraph("v5[nomidi][log]", -70, +5));
15
16envelop         = abs : max ~ (1.0/ma.SR) : mean(4096) ; // : max(ba.db2linear(-70)) : ba.linear2db;
17
18//Mono
19process =   geq : ( gcomp5s , gcomp4s , gcomp3s, gcomp2s, gcomp1s) :>_ with {
20gcomp1s = ba.bypass1(bswitch1,co.compressor_mono(ratio1,-push1,attack1,release1)):*(Makeup1) : vmeter1;
21gcomp2s = ba.bypass1(bswitch2,co.compressor_mono(ratio2,-push2,attack2,release2)):*(Makeup2) : vmeter2;
22gcomp3s = ba.bypass1(bswitch3,co.compressor_mono(ratio3,-push3,attack3,release3)):*(Makeup3) : vmeter3;
23gcomp4s = ba.bypass1(bswitch4,co.compressor_mono(ratio4,-push4,attack4,release4)):*(Makeup4) : vmeter4;
24gcomp5s = ba.bypass1(bswitch5,co.compressor_mono(ratio5,-push5,attack5,release5)):*(Makeup5) : vmeter5;
25};
26
27sel1         = hslider("Mode1[enum:Compress|Bypass|Mute][tooltip: Compress or Mute the selected band, or Bypass The Compressor]",1,1,3,1);
28sel2         = hslider("Mode2[enum:Compress|Bypass|Mute][tooltip: Compress or Mute the selected band, or Bypass The Compressor]",1,1,3,1);
29sel3         = hslider("Mode3[enum:Compress|Bypass|Mute][tooltip: Compress or Mute the selected band, or Bypass The Compressor]",1,1,3,1);
30sel4         = hslider("Mode4[enum:Compress|Bypass|Mute][tooltip: Compress or Mute the selected band, or Bypass The Compressor]",1,1,3,1);
31sel5         = hslider("Mode5[enum:Compress|Bypass|Mute][tooltip: Compress or Mute the selected band, or Bypass The Compressor]",1,1,3,1);
32
33not(x) 	= abs(x-1);
34mute1		= not(max(0,sel1-2));
35mute2		= not(max(0,sel2-2));
36mute3		= not(max(0,sel3-2));
37mute4		= not(max(0,sel4-2));
38mute5		= not(max(0,sel5-2));
39
40bypass(switch, block) = _ <: select2(switch, _, block);
41
42bswitch1	= max(0,sel1-1);
43bswitch2	= max(0,sel2-1);
44bswitch3	= max(0,sel3-1);
45bswitch4	= max(0,sel4-1);
46bswitch5	= max(0,sel5-1);
47
48hifr1			=hslider("crossover_b1_b2 [log][name:Crossover B1-B2 (hz)][tooltip: Crossover fi.bandpass frequency]" ,80 , 20, 20000, 1.08);
49hifr2			=hslider("crossover_b2_b3 [log][name:Crossover B2-B3 (hz)][tooltip: Crossover fi.bandpass frequency]",210,20,20000,1.08);
50hifr3			=hslider("crossover_b3_b4 [log][name:Crossover B3-B4 (hz)][tooltip: Crossover fi.bandpass frequency]",1700,20,20000,1.08);
51hifr4			=hslider("crossover_b4_b5 [log][name:Crossover B4-B5 (hz)][tooltip: Crossover fi.bandpass frequency]",5000,20,20000,1.08);
52
53geq = fi.filterbank(3, (hifr1,hifr2,hifr3,hifr4));
54
55ratio1 		= hslider("[9] Ratio1 [tooltip: Compression ratio]",2,1,100,0.1);
56attack1		= hslider("[A] Attack1 [tooltip: Time before the compressor starts to kick in]", 0.012, 0.001, 1, 0.001);
57release1 	= hslider("[B] Release1 [tooltip: Time before the compressor releases the sound]", 1.25, 0.01, 10, 0.01);
58
59ratio2 		= hslider("[9] Ratio2 [tooltip: Compression ratio]",2,1,100,0.1);
60attack2		= hslider("[A] Attack2 [tooltip: Time before the compressor starts to kick in]", 0.012, 0.001, 1, 0.001);
61release2 	= hslider("[B] Release2 [tooltip: Time before the compressor releases the sound]", 1.25, 0.01, 10, 0.01);
62
63ratio3 		= hslider("[9] Ratio3 [tooltip: Compression ratio]",2,1,100,0.1);
64attack3		= hslider("[A] Attack3 [tooltip: Time before the compressor starts to kick in]", 0.012, 0.001, 1, 0.001);
65release3 	= hslider("[B] Release3 [tooltip: Time before the compressor releases the sound]", 1.25, 0.01, 10, 0.01);
66
67ratio4 		= hslider("[9] Ratio4 [tooltip: Compression ratio]",2,1,100,0.1);
68attack4		= hslider("[A] Attack4 [tooltip: Time before the compressor starts to kick in]", 0.012, 0.001, 1, 0.001);
69release4 	= hslider("[B] Release4 [tooltip: Time before the compressor releases the sound]", 1.25, 0.01, 10, 0.01);
70
71ratio5 		= hslider("[9] Ratio5 [tooltip: Compression ratio]",2,1,100,0.1);
72attack5		= hslider("[A] Attack5 [tooltip: Time before the compressor starts to kick in]", 0.012, 0.001, 1, 0.001);
73release5 	= hslider("[B] Release5 [tooltip: Time before the compressor releases the sound]", 1.25, 0.01, 10, 0.01);
74
75push1 		= hslider("[5] Makeup1 [tooltip: Post amplification and threshold]"   , 13, -50, +50, 0.1) ; // threshold-=push ;  makeup+=push
76push2 		= hslider("[5] Makeup2 [tooltip: Post amplification and threshold]"   , 10, -50, +50, 0.1) ; // threshold-=push ;  makeup+=push
77push3 		= hslider("[5] Makeup3 [tooltip: Post amplification and threshold]"   , 4,  -50, +50, 0.1) ; // threshold-=push ;  makeup+=push
78push4 		= hslider("[5] Makeup4 [tooltip: Post amplification and threshold]"   , 8,  -50, +50, 0.1) ; // threshold-=push ;  makeup+=push
79push5 		= hslider("[5] Makeup5 [tooltip: Post amplification and threshold]"   , 11, -50, +50, 0.1) ; // threshold-=push ;  makeup+=push
80
81safe1 	= hslider("[6] Makeup-Threshold1 [tooltip: Threshold correction, an anticlip measure]" , 2, 0, +10, 0.1) ; // makeup-=safe
82safe2 	= hslider("[6] Makeup-Threshold2 [tooltip: Threshold correction, an anticlip measure]" , 2, 0, +10, 0.1) ; // makeup-=safe
83safe3 	= hslider("[6] Makeup-Threshold3 [tooltip: Threshold correction, an anticlip measure]" , 2, 0, +10, 0.1) ; // makeup-=safe
84safe4 	= hslider("[6] Makeup-Threshold4 [tooltip: Threshold correction, an anticlip measure]" , 2, 0, +10, 0.1) ; // makeup-=safe
85safe5 	= hslider("[6] Makeup-Threshold5 [tooltip: Threshold correction, an anticlip measure]" , 2, 0, +10, 0.1) ; // makeup-=safe
86
87Makeup1	=  mute1* (not(bswitch1)*(push1-safe1)  : ba.db2linear : si.smooth(0.999));
88Makeup2	=  mute2* (not(bswitch2)*(push2-safe2)  : ba.db2linear : si.smooth(0.999));
89Makeup3	=  mute3* (not(bswitch3)*(push3-safe3)  : ba.db2linear : si.smooth(0.999));
90Makeup4	=  mute4* (not(bswitch4)*(push4-safe4)  : ba.db2linear : si.smooth(0.999));
91Makeup5	=  mute5* (not(bswitch5)*(push5-safe5)  : ba.db2linear : si.smooth(0.999));
92
93//Low end headsets: 13,10,4,8,11 (split 80,210,1700,5000)
94//Mid-high end headsets: 17,20.5,20,10.5,10 (split 44,180,800,5000)
95