forked from s-e-a-m/faust-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseam.stereophony.lib
351 lines (330 loc) · 11.9 KB
/
seam.stereophony.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
//########################################################## stereophony.lib ###
//
// A library for sterophonic processing. Its official prefix is `st`.
//
// * MID-SIDE MATRIX
// * STEREO PAIRS
// * PANNING
// *
// *
//
//##############################################################################
/*******************************************************************************
Except where noted otherwise, Copyright (C) 2019-2020 by SEAM
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.
*******************************************************************************/
declare name "Faust Stereophony Library";
declare version "0.1";
sst = library("seam.stereophony.lib");
//========================================================== SUM DIFF MATRIX ===
//==============================================================================
//------------------------------------------------------------------------------
// NORMALIZED SUM BETWEEN TWO SIGNALS
//------------------------------------------------------------------------------
nsum = (_+_)/2; //0.618
//------------------------------------------------------------------------------
// NORMALIZED DIFFERENCE BETWEEN TWO SIGNALS
//------------------------------------------------------------------------------
ndif = (_-_)/2;
//------------------------------------------------------------------------------
// LR <-> MS MATRIX
//------------------------------------------------------------------------------
sdmx = _,_ <: nsum, ndif;
//==============================================================================
//=================================================== STEREO PAIRS & PANNING ===
//=============================================================== COINCIDENT ===
//==============================================================================
// MID-SIDE
//------------------------------------------------------------------------------
// The Mid-Side coincident pair polar description
// #### Reference
// #### Usage
//
// ```
// _ : mspan(p,rad) : _,_
// ```
//
// Where the first input is a mono signal to be panned, the second is the
// polar coefficient (1 for non-directional, 0.5 for cardioid, 0 for figure-8),
// the third is the angular value expressed in radians -2pi > 0 > 2pi
//
// Where the two outputs are respectively:
// Mid, Side
//
//------------------------------------------------------------------------------
midside(p,rad) = _ <: m, s
with{
m = _ <: (*(p)) + ((1-p)*(*cos(rad)));
s = *(sin(rad));
};
//------------------------------------------------------------------------------
// XY 90 DEGREES COINCIDENT PANNER
//------------------------------------------------------------------------------
// Mid-Side panpot with phase inntegrity of components
//
// #### Reference
//
// #### Usage
//
// ```
// _ : mspan(p,rad) : _,_
// ```
//
// Where the first input is the mono signal to be panned, the second is the
// polar coefficient (1 for non-directional, 0.5 for cardioid, 0 for figure-8),
// the third are the radians
// rad = vslider("[01] Azimuth [style:knob]", 0, -180, 180, 0.1) : deg2rad : si.smoo;
// deg2rad is a seam.lib function
//
// Where the two outputs are respectively:
// Mid, Side
//
//------------------------------------------------------------------------------
xy90(rad) = _ <: left,right
with{
left = (*(sqrt(2))+(*(cos(rad)))+(*(sin(-rad))))/(2.83);
right = (*(sqrt(2))+(*(cos(rad)))+(*(sin(rad))))/(2.83);
};
//------------------------------------------------------------------------------
// XY 90 DEGREES COINCIDENT PANNER
//------------------------------------------------------------------------------
// Mid-Side panpot with phase inntegrity of components
//
// #### Reference
//
// #### Usage
//
// ```
// _ : mspan(p,rad) : _,_
// ```
//
// Where the first input is the mono signal to be panned, the second is the
// polar coefficient (1 for non-directional, 0.5 for cardioid, 0 for figure-8),
// the third are the radians
// rad = vslider("[01] Azimuth [style:knob]", 0, -180, 180, 0.1) : deg2rad : si.smoo;
// deg2rad is a seam.lib function
//
// Where the two outputs are respectively:
// Mid, Side
//
//------------------------------------------------------------------------------
xy120(x,rad) = left,right
with{
left = ((1*x)+(0.5*(x*(cos(rad))))+(0.866*(x*(sin(-rad)))))/2;
right = ((1*x)+(0.5*(x*(cos(rad))))+(0.866*(x*(sin(rad)))))/2;
};
//------------------------------------------------------------------------------
// XY 90 DEGREES COINCIDENT PANNER
//------------------------------------------------------------------------------
// Mid-Side panpot with phase inntegrity of components
//
// #### Reference
//
// #### Usage
//
// ```
// _ : mspan(p,rad) : _,_
// ```
//
// Where the first input is the mono signal to be panned, the second is the
// polar coefficient (1 for non-directional, 0.5 for cardioid, 0 for figure-8),
// the third are the radians
// rad = vslider("[01] Azimuth [style:knob]", 0, -180, 180, 0.1) : deg2rad : si.smoo;
// deg2rad is a seam.lib function
//
// Where the two outputs are respectively:
// Mid, Side
//
//------------------------------------------------------------------------------
xy180(x,rad) = left,right
with{
left = (0.5*x)+(0.5*(x*(sin(-rad))));
right = (0.5*x)+(0.5*(x*(sin(rad))));
};
//------------------------------------------------------------------------------
// BLUMLEIN COINCIDENT PANNER
//------------------------------------------------------------------------------
// Mid-Side panpot with phase inntegrity of components
//
// #### Reference
//
// #### Usage
//
// ```
// _ : mspan(p,rad) : _,_
// ```
//
// Where the first input is the mono signal to be panned, the second is the
// polar coefficient (1 for non-directional, 0.5 for cardioid, 0 for figure-8),
// the third are the radians
// rad = vslider("[01] Azimuth [style:knob]", 0, -180, 180, 0.1) : deg2rad : si.smoo;
// deg2rad is a seam.lib function
//
// Where the two outputs are respectively:
// Mid, Side
//
//------------------------------------------------------------------------------
blumlein(x,rad) = left,right
with{
left = 0.707*((x*(cos(rad)))+(x*(sin(-rad))));
right = 0.707*((x*(cos(rad)))-(x*(sin(-rad))));
};
//------------------------------------------------------------------------------
// ORTF PANNER
//------------------------------------------------------------------------------
// Mid-Side panpot with phase inntegrity of components
//
// #### Reference
//
// #### Usage
//
// ```
// _ : mspan(p,rad) : _,_
// ```
//
// Where the first input is the mono signal to be panned, the second is the
// polar coefficient (1 for non-directional, 0.5 for cardioid, 0 for figure-8),
// the third are the radians
// rad = vslider("[01] Azimuth [style:knob]", 0, -180, 180, 0.1) : deg2rad : si.smoo;
// deg2rad is a seam.lib function
//
// Where the two outputs are respectively:
// Mid, Side
//
//------------------------------------------------------------------------------
ortf(x,rad) = left,right
with{
d = 0.17;
quad(k) = k*k;
nrad = rad+ma.PI;
delta(d,nrad) = sqrt(1-(d*cos(nrad))+quad(d)/4)-sqrt(1+(d*cos(nrad))+quad(d)/4);
del = pm.l2s(delta);
itdl = x : de.fdelay3(1024, max(del(d,nrad), 0) + 1);
itdr = x : de.fdelay3(1014, max(-del(d,nrad), 0) + 1);
left = ((1*itdl)+(0.573*(itdl*(cos(rad))))+(0.819*(itdl*(sin(-rad)))))/2;
right = ((1*itdr)+(0.573*(itdr*(cos(rad))))+(0.819*(itdr*(sin(rad)))))/2;
};
//==============================================================================
//================================================================== PANNING ===
//==============================================================================
// MID-SIDE STEREO PANNING TO LEFT AND RIGHT LOUDSPEAKER LISTENING
//------------------------------------------------------------------------------
// Mid-Side panner with phase integrity of components to LR matrix
// #### Reference
// British Patent Specification 394, 325 - ALAN DOWER BLUMLEIN
// The invention also consists in a system of sound transmission wherein the
// sound is receive by two or more microphones, wherein at low frequencies
// difference in the phase of sound pressure at the microphone is reproduced as
// difference in volume at the loud speaker
//
// #### Usage
//
// ```
// _ : mspan_lr(p,rad) : _,_
// ```
//
// Where the input is the mono signal to be Left and Right panned
//
// Where the two outputs are respectively:
// Mid, Side
//
//------------------------------------------------------------------------------
mspan_lr(p,rad) = midside(p,rad) : sdmx;
//------------------------------------------------------------------------------
// CURTIS ROADS CONSTANT POWER PANNING
//------------------------------------------------------------------------------
// Constant Power Panning as described by Curtis Roads in Computer Music Tutorial
// #### Reference
// CMT pg460
//
// #### Usage
//
// ```
// _ : crcp(rad) : _,_
// ```
//
// Where the first input is the mono signal to be panned
//
// Where the two outputs are respectively:
// Left and Right
//
//------------------------------------------------------------------------------
crcppan(rad) = _ <: left,right
with{
left = _*((sqrt(2)/2)*(cos(rad)+sin(-rad)));
right = _*((sqrt(2)/2)*(cos(rad)-sin(-rad)));
};
//------------------------------------------------------------------------------
// STEREO PANNING FOR TWO LEFT AND RIGHT LOUDSPEAKER LISTENING
//------------------------------------------------------------------------------
// Quadratic Amplitude Pannner
// #### Reference
//
// #### Usage
//
// ```
// _ : lrpanq(p) : _,_
// ```
//
// Where the input is the mono signal to be panned
//
// Where the two outputs are respectively:
// Left and Right
//
//------------------------------------------------------------------------------
lrquad(x,p) = left,right
with{
left = sqrt(1-p)*x;
right = sqrt(p)*x;
};
aa = library("aanl.lib");
sf = library("all.lib");
an = library("analyzers.lib");
ba = library("basics.lib");
co = library("compressors.lib");
de = library("delays.lib");
dm = library("demos.lib");
dx = library("dx7.lib");
en = library("envelopes.lib");
fd = library("fds.lib");
fi = library("filters.lib");
ho = library("hoa.lib");
it = library("interpolators.lib");
ma = library("maths.lib");
mi = library("mi.lib");
ef = library("misceffects.lib");
os = library("oscillators.lib");
no = library("noises.lib");
pf = library("phaflangers.lib");
pl = library("platform.lib");
pm = library("physmodels.lib");
qu = library("quantizers.lib");
rm = library("reducemaps.lib");
re = library("reverbs.lib");
ro = library("routes.lib");
sp = library("spats.lib");
si = library("signals.lib");
so = library("soundfiles.lib");
sy = library("synths.lib");
ve = library("vaeffects.lib");
vl = library("version.lib");
wa = library("webaudio.lib");
wd = library("wdmodels.lib");