-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathSAM-fx.lib
173 lines (110 loc) · 9.61 KB
/
SAM-fx.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
// Low-pass filter smoothes out parameter changes to help suppress clicking sounds
// when adjusting models; however, it is quite expensive if there are a lot of params.
//paramSmooth = onePoleBLT(10.0);
paramSmooth = _; // to bypass this functionality instead
SAMlimiter = compressor_mono(10e10,-6,0.0008,0.1);
// syntax: compressor_mono(ratio,thresh,att,rel)
// compression ratio of 10e10 means it is a very hard limiter (it is hard to make a model explode faster than this, but it is certainly possible to do so)
// thresh = -6dB means limiter kicks in above this threshold
// attach time is 0.8ms
// release time is 0.1s
defaultOutputDSP = highpass(4,20.0):SAMlimiter;
// I use my own definition of an FIR filter because I find that it compiles better for longer
myfir((oneCoef, restCoef)) = _ <: (_,_) : (*(oneCoef), (mem:myfir((restCoef)))) : + : _;
myfir((lastCoef)) = _:*(lastCoef):_;
declare name "freeverb";
declare version "1.0";
declare author "Grame";
declare license "BSD";
declare copyright "(c) GRAME 2006";
declare reference "https://ccrma.stanford.edu/~jos/pasp/Freeverb.html";
//======================================================
//
// Freeverb
// Faster version using fixed delays (20% gain)
//
//======================================================
// Constant Parameters
//--------------------
fixedgain = 0.015; //value of the gain of fxctrl
scalewet = 3.0;
scaledry = 2.0;
scaledamp = 0.4;
scaleroom = 0.28;
offsetroom = 0.7;
initialroom = 0.5;
initialdamp = 0.5;
initialwet = 1.0/scalewet;
initialdry = 0;
initialwidth= 1.0;
initialmode = 0.0;
freezemode = 0.5;
stereospread= 23;
allpassfeed = 0.5; //feedback of the delays used in allpass filters
// Filter Parameters
//------------------
combtuningL1 = 1116;
combtuningL2 = 1188;
combtuningL3 = 1277;
combtuningL4 = 1356;
combtuningL5 = 1422;
combtuningL6 = 1491;
combtuningL7 = 1557;
combtuningL8 = 1617;
allpasstuningL1 = 556;
allpasstuningL2 = 441;
allpasstuningL3 = 341;
allpasstuningL4 = 225;
// Control Sliders
//--------------------
// Damp : filters the high frequencies of the echoes (especially active for great values of RoomSize)
// RoomSize : size of the reverberation room
// Dry : original signal
// Wet : reverberated signal
//dampSlider = hslider("Damp",0.5, 0, 1, 0.025)*scaledamp;
//roomsizeSlider = hslider("RoomSize", 0.3, 0, 1, 0.025)*scaleroom + offsetroom;
//wetSlider = hslider("Wet", 0.3333, 0, 1, 0.025);
reverbParams = hgroup("Reverb", hslider("Damp",0.5, 0, 1, 0.025)*scaledamp, hslider("RoomSize", 0.5, 0, 1, 0.025)*scaleroom + offsetroom, hslider("Wet", 0.3333, 0, 1, 0.025));
dampSlider = reverbParams:(_,!,!);
roomsizeSlider = reverbParams:(!,_,!);
wetSlider = reverbParams:(!,!,_);
combfeed = roomsizeSlider;
// Comb and Allpass filters
//-------------------------
allpass(dt,fb) = (_,_ <: (*(fb),_:+:@(dt)), -) ~ _ : (!,_);
comb(dt, fb, damp) = (+:@(dt)) ~ (*(1-damp) : (+ ~ *(damp)) : *(fb));
// Reverb components
//------------------
monoReverb(fb1, fb2, damp, spread)
= _ <: comb(combtuningL1+spread, fb1, damp),
comb(combtuningL2+spread, fb1, damp),
comb(combtuningL3+spread, fb1, damp),
comb(combtuningL4+spread, fb1, damp),
comb(combtuningL5+spread, fb1, damp),
comb(combtuningL6+spread, fb1, damp),
comb(combtuningL7+spread, fb1, damp),
comb(combtuningL8+spread, fb1, damp)
+>
allpass (allpasstuningL1+spread, fb2)
: allpass (allpasstuningL2+spread, fb2)
: allpass (allpasstuningL3+spread, fb2)
: allpass (allpasstuningL4+spread, fb2)
;
stereoReverb(fb1, fb2, damp, spread)
= + <: monoReverb(fb1, fb2, damp, 0), monoReverb(fb1, fb2, damp, spread);
// fxctrl : add an input gain and a wet-dry control to a stereo FX
//----------------------------------------------------------------
fxctrl(g,w,Fx) = _,_ <: (*(g),*(g) : Fx : *(w),*(w)), *(1-w), *(1-w) +> _,_;
fxctrlMono(g,w,Fx) = _ <: (*(g) : Fx : *(w)), *(1-w) +> _;
SAMfreereverb = fxctrlMono(fixedgain, wetSlider, monoReverb(combfeed, allpassfeed, dampSlider, stereospread));
// Freeverb
//---------
//freeverb = vgroup("Freeverb", fxctrl(fixedgain, wetSlider, stereoReverb(combfeed, allpassfeed, dampSlider, stereospread)));
freeverb = vgroup("Freeverb", fxctrl(fixedgain, wetSlider, stereoReverb(combfeed, allpassfeed, dampSlider, stereospread)));
//process = monoReverb;
// Note: This body response is a shortened version of Nelson Lee's recording, which was also upsampled to 44.1kHz from 22.05kHz.
// https://ccrma.stanford.edu/realsimple/acoustic_guitar/gtrbody.wav
//
// This model can be made more efficient later using IIR filtering techniques to compress the impulse response.
bodyResp1 = myfir((0.010996,0.015940,-0.007910,-0.026386,-0.005383,0.026542,0.011975,-0.037400,-0.032969,0.070333,0.194372,0.232359,0.190335,0.160973,0.168535,0.133131,0.023154,-0.050777,0.021323,0.165130,0.196982,0.075790,-0.036540,-0.009439,0.071340,0.046519,-0.067577,-0.105893,-0.016416,0.053121,-0.016233,-0.121595,-0.084661,0.077401,0.165239,0.073721,-0.074462,-0.121952,-0.088800,-0.099127,-0.163536,-0.165065,-0.057241,0.042720,0.015107,-0.092938,-0.139567,-0.090072,-0.051656,-0.106076,-0.189538,-0.183578,-0.075222,0.030470,0.041511,-0.029060,-0.103412,-0.130613,-0.118976,-0.103357,-0.106104,-0.119855,-0.111194,-0.045970,0.069655,0.174194,0.196579,0.120249,-0.003635,-0.108026,-0.158821,-0.153813,-0.101526,-0.024638,0.028712,0.015922,-0.044615,-0.075900,-0.025782,0.061489,0.087655,0.016462,-0.078545,-0.100079,-0.040614,0.017570,0.009613,-0.037281,-0.052654,-0.019547,0.010648,-0.002509,-0.029994,-0.015162,0.045512,0.091638,0.073016,0.010135,-0.032960,-0.021580,0.017872,0.036082,0.011866,-0.035258,-0.068886,-0.063503,-0.022037,0.021296,0.023695,-0.025068,-0.082327,-0.089065,-0.033546,0.033619,0.055382,0.029691,0.001300,0.001364,0.015537,0.016883,0.007663,0.012525,0.039946,0.071880,0.090686,0.097855,0.098184,0.082556,0.044166,0.005301,0.005383,0.054411,0.109116,0.111762,0.049486,-0.030992,-0.070562,-0.052333,-0.006427,0.030744,0.052535,0.075890,0.107120,0.124845,0.100711,0.034178,-0.038783,-0.074902,-0.060179,-0.017304,0.020096,0.036906,0.041127,0.046062,0.053734,0.055428,0.044166,0.023347,0.005246,0.002142,0.018815,0.048579,0.075195,0.080651,0.058596,0.022275,-0.002481,0.000183,0.019657,0.027531,0.008826,-0.020161,-0.028217,-0.005228,0.026386,0.037519,0.023145,0.001016,-0.014841,-0.026588,-0.037291,-0.037281,-0.016160,0.015674,0.034269,0.031404,0.026606,0.040184,0.063283,0.066689,0.040367,0.011097,0.014054,0.051454,0.088470,0.088974,0.050621,0.002765,-0.023154,-0.018238,0.003259,0.020957,0.022889,0.010575,-0.006198,-0.017862,-0.022221,-0.024482,-0.030305,-0.037236,-0.035798,-0.021241,-0.003571,-0.000906,-0.019602,-0.042619,-0.044707,-0.018119,0.017963,0.037309,0.032054,0.014585,0.000082,-0.008267,-0.014621,-0.020975,-0.025068,-0.026084,-0.024345,-0.019739,-0.012168,-0.005713,-0.004111,-0.003772,0.004678,0.021442,0.032273,0.022880,-0.002280,-0.024042,-0.030818,-0.030268,-0.033921,-0.038884,-0.032859,-0.013678,0.004404,0.008231,0.000174,-0.007883,-0.011325,-0.014814,-0.020838,-0.023356,-0.016068,-0.002188,0.009174,0.011774,0.005585,-0.007508,-0.024262,-0.036732,-0.035121,-0.018036,0.002124,0.009586,0.000558,-0.013889,-0.021085,-0.018787,-0.013211,-0.009156,-0.006583,-0.005210,-0.008295,-0.018018,-0.030461,-0.037941,-0.036100,-0.027668,-0.018549,-0.013157,-0.012030,-0.013239,-0.013175,-0.008570,0.000586,0.009284,0.011216,0.005054,-0.003708,-0.008057,-0.007068,-0.006034,-0.010730,-0.019840,-0.026624,-0.025040,-0.016553,-0.008487,-0.007315,-0.012653,-0.018073,-0.018357,-0.013715,-0.009174,-0.007718,-0.008158,-0.007205,-0.004843,-0.004257,-0.008048,-0.014402,-0.018174,-0.015345,-0.006803,0.002426,0.006922,0.004825,-0.001190,-0.006748,-0.009119,-0.008313,-0.005942,-0.003259,-0.001538,-0.001538,-0.003708,-0.006207,-0.007215,-0.006015,-0.004212,-0.002802,-0.001090,0.002280,0.006656,0.009815,0.010089,0.008121,0.005667,0.003763,0.002829,0.002527,0.002005,0.000403,-0.001895,-0.001914,0.002738,0.010721,0.017139,0.018091,0.014667,0.010785,0.008103,0.004999,-0.000201,-0.005512,-0.007031,-0.003250,0.003479,0.009256,0.012168,0.012488,0.011032,0.008240,0.004221,0.000192,-0.002600,-0.003030,-0.001556,0.000531,0.002179,0.002976,0.003552,0.004166,0.004431,0.003809,0.002655,0.002353,0.003836,0.006427,0.008322,0.008277,0.006931,0.005860,0.005805,0.006015,0.005210,0.003241,0.001099,0.000046,0.000293,0.001639,0.003479,0.005329,0.006043,0.004779,0.001968,-0.000549,-0.001135,-0.000412,0.000165,-0.000229,-0.000211,0.001492,0.004212,0.005777,0.005155,0.003378,0.002417,0.002628,0.003214,0.003296,0.003232,0.003296,0.003397,0.002930,0.002261,0.002078,0.002692,0.003186,0.002673,0.001108,-0.000439,-0.001108,-0.000851,-0.000201,0.000577,0.001364,0.001996,0.002023,0.001135,-0.000412,-0.001859,-0.002783,-0.002866,-0.002243,-0.000961,0.000439,0.001474,0.001520,0.000952,0.000183,-0.000156,-0.000449,-0.000577,-0.000925,-0.000943,-0.000714,-0.000549,-0.000714,-0.001227,-0.001749,-0.001611,-0.001062,-0.000146,0.000330,0.000275,-0.000284,-0.000925,-0.001282,-0.001511,-0.001566,-0.001703,-0.001520,-0.001108,-0.000504,-0.000037,0.000046,-0.000137,-0.000467,-0.000678,-0.000696,-0.000439,-0.000110,0.000092,0.000110,-0.000073,-0.000146,-0.000137,-0.000055,-0.000018,-0.000064,-0.000018));
bodyResp2 = tf2np(1.0, 1.5667, 0.3133, -0.5509, -0.3925) : tf2np(1.0, -1.9537, 0.9542, -1.6357, 0.8697) : tf2np(1.0, -1.6683, 0.8852, -1.7674, 0.8735) : tf2np(1.0, -1.8585, 0.9653, -1.8498, 0.9516) : tf2np(1.0, -1.9299, 0.9621, -1.9354, 0.9590) : tf2np(1.0, -1.9800, 0.9888, -1.9867, 0.9923);