forked from grame-cncm/faustlibraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spats.lib
142 lines (125 loc) · 4.96 KB
/
spats.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
//#################################### spats.lib ##########################################
// This library contains a collection of tools for sound spatialization.
// Its official prefix is `sp`.
//########################################################################################
/************************************************************************
************************************************************************
FAUST library file
Copyright (C) 2003-2012 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.
************************************************************************
************************************************************************/
si = library("signals.lib");
declare name "Faust Spatialization Library";
declare version "0.0";
//-----------------------`(sp.)panner`------------------------
// A simple linear stereo panner.
// `panner` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : panner(g) : _,_
// ```
//
// Where:
//
// * `g`: the panning (0-1)
//------------------------------------------------------------
panner(g) = _ <: *(1-g), *(g);
// TODO: need demo function for panner here
//-----------------------`(sp.)spat`------------------------
// GMEM SPAT: n-outputs spatializer.
// `spat` is a standard Faust function.
//
// #### Usage
//
// ```
// _ : spat(n,r,d) : _,_,...
// ```
//
// Where:
//
// * `n`: number of outputs
// * `r`: rotation (between 0 et 1)
// * `d`: distance of the source (between 0 et 1)
//------------------------------------------------------
// TODO: author Laurent Pottier, revised by RM
spat(n,a,d) = _ <: par(i, n, *( scaler(i, n, a, d) : si.smooth(0.9999) ))
with {
scaler(i,n,a,d) = (d/2.0+0.5)
* sqrt( max(0.0, 1.0 - abs(fmod(a+0.5+float(n-i)/n, 1.0) - 0.5) * n * d) );
};
//---------------`(sp.)stereoize`-------------
// Transform an arbitrary processor `p` into a stereo processor with 2 inputs
// and 2 outputs.
//
// #### Usage
//
// ```
// _,_ : stereoize(p) : _,_
// ```
//
// Where:
//
// * `p`: the arbitrary processor
//----------------------------------------
stereoize(p) = S(inputs(p), outputs(p))
with {
// degenerated processor with no outputs
S(n,0) = !,! : 0,0; // just in case, probably a rare case
// processors with no inputs
S(0,1) = !,! : p <: _,_; // add two fake inputs and split output
S(0,2) = !,! : p;
S(0,n) = !,! : p,p :> _,_; // we are sure this will work if n is odd
// processors with one input
S(1,1) = p,p; // add two fake inputs and split output
S(1,n) = p,p :> _,_; // we are sure this will work if n is odd
// processors with two inputs
S(2,1) = p <: _,_; // split the output
S(2,2) = p; // nothing to do, p is already stereo
// processors with inputs > 2 and outputs > 2
S(n,m) = _,_ <: p,p :> _,_; // we are sure this works if n or p are odd
};
// TODO: need demo function of spat here
//////////////////////////////////////////////////////////////////////////////////////////
// UNDOCUMENTED/DISMISSED ELEMENTS
//////////////////////////////////////////////////////////////////////////////////////////
// music.lib:
// The following functions could remain available but they would have to be
// factorized and reimplemented using the `par` function...
// bus2 = _,_;
// bus3 = _,_,_;
// bus4 = _,_,_,_;
// bus5 = _,_,_,_,_;
// bus6 = _,_,_,_,_,_;
// bus7 = _,_,_,_,_,_,_;
// bus8 = _,_,_,_,_,_,_,_;
// gain2(g) = *(g),*(g);
// gain3(g) = *(g),*(g),*(g);
// gain4(g) = *(g),*(g),*(g),*(g);
// gain5(g) = *(g),*(g),*(g),*(g),*(g);
// gain6(g) = *(g),*(g),*(g),*(g),*(g),*(g);
// gain7(g) = *(g),*(g),*(g),*(g),*(g),*(g),*(g);
// gain8(g) = *(g),*(g),*(g),*(g),*(g),*(g),*(g),*(g);