forked from grame-cncm/faustlibraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.lib
213 lines (190 loc) · 6.38 KB
/
routes.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
//#################################### routes.lib ########################################
// A library to handle signal routing in Faust. Its official prefix is `ro`.
//########################################################################################
/************************************************************************
************************************************************************
FAUST library file
Copyright (C) 2003-2019 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");
sp = library("spats.lib");
declare name "Faust Signal Routing Library";
declare version "0.2";
//=============================Functions Reference========================================
//========================================================================================
//--------------------------------`(ro.)cross`-----------------------------------
// Cross n signals: `(x1,x2,..,xn) -> (xn,..,x2,x1)`.
// `cross` is a standard Faust function.
//
// #### Usage
//
// ```
// cross(n)
// _,_,_ : cross(3) : _,_,_
// ```
//
// Where:
//
// * `n`: number of signals (int, must be known at compile time)
//
// #### Note
//
// Special case: `cross2`:
//
// ```
// cross2 = _,cross(2),_;
// ```
//-----------------------------------------------------------------------------
// cross n cables : (x1,x2,..,xn) -> (xn,..,x2,x1)
cross(n) = route(n, n, par(i, n, (i+1, n-i)));
cross2 = _,cross(2),_; // for compatibility with some old misceffects.lib functions
//--------------`(ro.)crossnn`--------------
// Cross two `bus(n)`s.
//
// #### Usage
//
// ```
// (si.bus(2*n)) : crossnn(n) : (si.bus(2*n))
// ```
//
// Where:
//
// * `n`: the number of signals in the `bus`
//--------------------------------------
crossnn(n) = crossNM(n,n);
//--------------`(ro.)crossn1`--------------
// Cross bus(n) and bus(1).
//
// #### Usage
//
// ```
// (si.bus(n),_) : crossn1(n) : (_,si.bus(n))
// ```
//
// Where:
//
// * `n`: the number of signals in the first `bus`
//--------------------------------------
crossn1(n) = crossNM(n,1);
//--------------`(ro.)cross1n`--------------
// Cross bus(1) and bus(n).
//
// #### Usage
//
// ```
// (_,si.bus(n)) : crossn1(n) : (si.bus(n),_)
// ```
//
// Where:
//
// * `n`: the number of signals in the second `bus`
//--------------------------------------
cross1n(n) = crossNM(1,n);
//--------------`(ro.)crossNM`--------------
// Cross bus(n) and bus(m).
//
// #### Usage
//
// ```
// (si.bus(n),si.bus(m)) : crossNM(n,m) : (si.bus(m),si.bus(n))
// ```
//
// Where:
//
// * `n`: the number of signals in the first `bus`
// * `m`: the number of signals in the second `bus`
//--------------------------------------
crossNM(n,m) = route(n+m, n+m, par(i, n+m, i+1, ((i+m)%(n+m))+1));
//--------------------------`(ro.)interleave`------------------------------
// Interleave row*col cables from column order to row order.
// input : x(0), x(1), x(2) ..., x(row*col-1)
// output: x(0+0*row), x(0+1*row), x(0+2*row), ..., x(1+0*row), x(1+1*row), x(1+2*row), ...
//
// #### Usage
//
// ```
// _,_,_,_,_,_ : interleave(row,column) : _,_,_,_,_,_
// ```
//
// Where:
//
// * `row`: the number of row (int, known at compile time)
// * `column`: the number of column (int, known at compile time)
//-----------------------------------------------------------------------------
interleave(1,2) = _,_;
interleave(row,col) = route(row*col, row*col, par(i, row*col, (i+1, (i%row)*col + int(i/row) + 1)));
//-------------------------------`(ro.)butterfly`--------------------------------
// Addition (first half) then substraction (second half) of interleaved signals.
//
// #### Usage
//
// ```
// _,_,_,_ : butterfly(n) : _,_,_,_
// ```
//
// Where:
//
// * `n`: size of the butterfly (n is int, even and known at compile time)
//-----------------------------------------------------------------------------
butterfly(2) = si.bus(2) <: +,-;
butterfly(n) = si.bus(n) <: interleave(n/2,2), interleave(n/2,2) : par(i, n/2, +), par(i, n/2, -);
//------------------------------`(ro.)hadamard`----------------------------------
// Hadamard matrix function of size `n = 2^k`.
//
// #### Usage
//
// ```
// _,_,_,_ : hadamard(n) : _,_,_,_
// ```
//
// Where:
//
// * `n`: `2^k`, size of the matrix (int, must be known at compile time)
//
// #### Note:
//
// Implementation contributed by Remy Muller.
//-----------------------------------------------------------------------------
// TODO: author: Remy Muller, revised by RM
hadamard(2) = butterfly(2);
hadamard(n) = butterfly(n) : (hadamard(n/2) , hadamard(n/2));
//---------------`(ro.)recursivize`-------------
// Create a recursion from two arbitrary processors p and q.
//
// #### Usage
//
// ```
// _,_ : recursivize(p,q) : _,_
//
// ```
//
// Where:
//
// * `p`: the forward arbitrary processor
// * `q`: the feedback arbitrary processor
//----------------------------------------
recursivize(p,q) = (_,_,_,_ :> sp.stereoize(p)) ~ sp.stereoize(q);