forked from s-e-a-m/faust-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcyclone.lib
More file actions
195 lines (168 loc) · 6.9 KB
/
cyclone.lib
File metadata and controls
195 lines (168 loc) · 6.9 KB
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
//############################################################## cyclone.lib ###
//
// A library for the exploration of maxmsp algorythms
//
// * gen~ library and examples
// *
// *
// *
// *
//
//##############################################################################
/*******************************************************************************
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 "CYclone Faust Library";
declare version "0.1";
declare author "Giuseppe Silvi";
declare license "CC4";
//================================================== GEN~ LIBRARY AND EXAMPLES =
//==============================================================================
//-------------------------------------------------------- CLIP TO MIN ~ MAX ---
clip(a,b) = max(a) : min(b);
//------------------------------------------------------------------------------
// CROSSOVER.gendsp
//------------------------------------------------------------------------------
// A crossover shelf filter that sums to an allpass. This cross over filter
// should have equal phase response. It is useful when used in a spatializer,
// to not distort the final image.
//
// #### Usage
//
// ```
// freq = hslider("Crossover Freq[scale:exp][style:knob]", 600, 1, 20000, 1);
// process = no.noise:lxover;
// ```
//
// Where the four outpust are respectively:
// Front,Right,Rear,Left
//
//
//------------------------------------------------------------------------------
crossover(freq) = _ <: low,hi
with{
f2rad = (freq*2*ma.PI)/ma.SR;
// filter coefficients
ffc = (sin(f2rad)-1) / cos(f2rad); // 1st
sfc = (ffc+1)/2; // 2nd
b1(x) = loop~_ : *(ffc), _ : +
with{loop = _ <: *(ffc), _ : x-_,_;};
b2(x) = loop~_ : !,_
with{loop = _ <: x-_,_ : *(sfc),_ <:_,!,_+_ <: +,!,_ ;};
hi = _<:b1-low;
low = b2:b2;
};
onepole(fc) = *(a) : +~*(ac)
with{
a= sin(abs(fc)*2*ma.PI/ma.SR) : clip(0,1);
ac = 1-a;
};
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//==============================================================================
//============================================================== SCRATCH BOOK ==
//==============================================================================
// The output consists of samples that are the difference between
// the current input sample and the previous input sample.
// For example, if the input signal contained 1,.5,2,.5,
// the output would be 1,-.5,1.5,-1.5.
delta(x) = x - x'; // Signal of sample differences
stepcounter = ba.time;
rampsmooth(rampup, rampdown) = _ : ba.time
with {
rampup = max(x, 1);
rampdown = max(x, 1);
delta(x) = x - x'; // Signal of sample differences
ba.if (
(delta(x) == 0) & (delta(rampup) == 0) & (delta(rampdown) == 0),
ba.time(x),
ba.time(x)
);
};
//
//
// linetilde (value, time) = state~(_,_):!,_
// with {
// state (t, c) = nt, ba.if (nt <= 0, value, c+(value - c) / nt)
// with {
// nt = ba.if( value != value', samples, t-1);
// samples = time*ma.SR/1000.0;
// };
// };
History last(0.);
History dirflag(0);
History stepcounter(0);
History increment(0.);
// deltavar = 0;
// non serve dichiararlo perché viene inizializzato nell'else
insig = in1;
rampup = max(in2, 1);
rampdown = max(in3, 1);
outsig = last;
// se il delta è uguale a 0 e non ci sono modifiche ai tempi di rampsmooth
// si procede con il precedente incremento
if((delta(insig) == 0) && (delta(rampup)==0) && (delta(rampdown)==0)) {
if (dirflag > 0) {
if (stepcounter < rampup) {
outsig += increment;
stepcounter += 1;
} else { outsig = insig; }
} else if (stepcounter < rampdown) {
outsig += increment;
stepcounter += 1;
} else { outsig = insig; }
}
// altrimenti si verifica se il segnale deve salire o scendere
// e si incrementa opportunamente
// outsig rappresenta l'uscita precedente
else {
deltavar = insig - outsig;
if (deltavar > 0) {
increment = deltavar / rampup;
outsig += increment;
stepcounter = 1;
dirflag = 1;
} else {
increment = deltavar / rampdown;
outsig += increment;
stepcounter = 1;
dirflag = -1;
}
}
last = outsig;
out = outsig;