-
Notifications
You must be signed in to change notification settings - Fork 63
/
phaflangers.lib
235 lines (211 loc) · 9.79 KB
/
phaflangers.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
//#################################### phaflangers.lib ########################################
// A library of phasor and flanger effects. Its official prefix is `pf`.
//
// #### References
// * <https://github.com/grame-cncm/faustlibraries/blob/master/phaflangers.lib>
//########################################################################################
ma = library("maths.lib");
de = library("delays.lib");
fi = library("filters.lib");
os = library("oscillators.lib");
pf = library("phaflangers.lib");
declare name "Faust Phaser and Flanger Library";
declare version "1.1.0";
//########################################################################################
/************************************************************************
FAUST library file, JOS section
Except where noted otherwise, The Faust functions below in this
section are Copyright (C) 2003-2017 by Julius O. Smith III <[email protected]>
([jos](http://ccrma.stanford.edu/~jos/)), and released under the
(MIT-style) [STK-4.3](#stk-4.3-license) license.
All MarkDown comments in this section are Copyright 2016-2017 by Romain
Michon and Julius O. Smith III, and are released under the
[CCA4I](https://creativecommons.org/licenses/by/4.0/) license (TODO: if/when Romain agrees!)
************************************************************************/
//=============================Functions Reference========================================
//========================================================================================
//---------------`(pf.)flanger_mono`-------------
// Mono flanging effect.
//
// #### Usage:
//
// ```
// _ : flanger_mono(dmax,curdel,depth,fb,invert) : _
// ```
//
// Where:
//
// * `dmax`: maximum delay-line length (power of 2) - 10 ms typical
// * `curdel`: current dynamic delay (not to exceed dmax)
// * `depth`: effect strength between 0 and 1 (1 typical)
// * `fb`: feedback gain between 0 and 1 (0 typical)
// * `invert`: 0 for normal, 1 to invert sign of flanging sum
//
// #### Reference
//
// <https://ccrma.stanford.edu/~jos/pasp/Flanging.html>
//------------------------------------------------------------
flanger_mono(dmax,curdel,depth,fb,invert)
= _ <: _, (- : de.fdelay(dmax,curdel)) ~ *(fb) : _,
*(select2(invert,depth,0-depth))
: + : *(0.5);
//---------------`(pf.)flanger_stereo`-------------
// Stereo flanging effect.
// `flanger_stereo` is a standard Faust function.
//
// #### Usage:
//
// ```
// _,_ : flanger_stereo(dmax,curdel1,curdel2,depth,fb,invert) : _,_
// ```
//
// Where:
//
// * `dmax`: maximum delay-line length (power of 2) - 10 ms typical
// * `curdel1`: current dynamic delay for the left channel (not to exceed dmax)
// * `curdel2`: current dynamic delay for the right channel (not to exceed dmax)
// * `depth`: effect strength between 0 and 1 (1 typical)
// * `fb`: feedback gain between 0 and 1 (0 typical)
// * `invert`: 0 for normal, 1 to invert sign of flanging sum
//
// #### Reference
//
// <https://ccrma.stanford.edu/~jos/pasp/Flanging.html>
//------------------------------------------------------------
flanger_stereo(dmax,curdel1,curdel2,depth,fb,invert)
= flanger_mono(dmax,curdel1,depth,fb,invert),
flanger_mono(dmax,curdel2,depth,fb,invert);
vibrato2_mono(sections,phase01,fb,width,frqmin,fratio,frqmax,speed) =
(+ : seq(i,sections,ap2p(R,th(i)))) ~ *(fb)
with {
//tf2 = component("filters.lib").tf2;
// second-order resonant digital allpass given pole radius and angle:
ap2p(R,th) = fi.tf2(a2,a1,1,a1,a2) with {
a2 = R^2;
a1 = -2*R*cos(th);
};
R = exp(-pi*width/ma.SR);
cososc = os.oscrc; // oscillators.lib
sinosc = os.oscrs; // oscillators.lib
osc = cososc(speed) * phase01 + sinosc(speed) * (1-phase01);
lfo = (1-osc)/2; // in [0,1]
pi = 4*atan(1);
thmin = 2*pi*frqmin/ma.SR;
thmax = 2*pi*frqmax/ma.SR;
th1 = thmin + (thmax-thmin)*lfo;
th(i) = (fratio^(i+1))*th1;
};
//-------`(pf.)phaser2_mono`-----------------
// Mono phasing effect.
//
// #### Phaser
//
// ```
// _ : phaser2_mono(Notches,phase,width,frqmin,fratio,frqmax,speed,depth,fb,invert) : _
// ```
//
// Where:
//
// * `Notches`: number of spectral notches (MACRO ARGUMENT - not a signal)
// * `phase`: phase of the oscillator (0-1)
// * `width`: approximate width of spectral notches in Hz
// * `frqmin`: approximate minimum frequency of first spectral notch in Hz
// * `fratio`: ratio of adjacent notch frequencies
// * `frqmax`: approximate maximum frequency of first spectral notch in Hz
// * `speed`: LFO frequency in Hz (rate of periodic notch sweep cycles)
// * `depth`: effect strength between 0 and 1 (1 typical) (aka "intensity")
// when depth=2, "vibrato mode" is obtained (pure allpass chain)
// * `fb`: feedback gain between -1 and 1 (0 typical)
// * `invert`: 0 for normal, 1 to invert sign of flanging sum
//
// Reference:
//
// * <https://ccrma.stanford.edu/~jos/pasp/Phasing.html>
// * <http://www.geofex.com/Article_Folders/phasers/phase.html>
// * 'An Allpass Approach to Digital Phasing and Flanging', Julius O. Smith III,
// Proc. Int. Computer Music Conf. (ICMC-84), pp. 103-109, Paris, 1984.
// * CCRMA Tech. Report STAN-M-21: <https://ccrma.stanford.edu/STANM/stanms/stanm21/>
//------------------------------------------------------------
phaser2_mono(Notches,phase01,width,frqmin,fratio,frqmax,speed,depth,fb,invert) =
_ <: *(g1) + g2mi*vibrato2_mono(Notches,phase01,fb,width,frqmin,fratio,frqmax,speed)
with { // depth=0 => direct-signal only
g1 = 1-depth/2; // depth=1 => phaser mode (equal sum of direct and allpass-chain)
g2 = depth/2; // depth=2 => vibrato mode (allpass-chain signal only)
g2mi = select2(invert,g2,-g2); // inversion negates the allpass-chain signal
};
//-------`(pf.)phaser2_stereo`-------
// Stereo phasing effect.
// `phaser2_stereo` is a standard Faust function.
//
// #### Phaser
//
// ```
// _,_ : phaser2_stereo(Notches,width,frqmin,fratio,frqmax,speed,depth,fb,invert) : _,_
// ```
//
// Where:
//
// * `Notches`: number of spectral notches (MACRO ARGUMENT - not a signal)
// * `width`: approximate width of spectral notches in Hz
// * `frqmin`: approximate minimum frequency of first spectral notch in Hz
// * `fratio`: ratio of adjacent notch frequencies
// * `frqmax`: approximate maximum frequency of first spectral notch in Hz
// * `speed`: LFO frequency in Hz (rate of periodic notch sweep cycles)
// * `depth`: effect strength between 0 and 1 (1 typical) (aka "intensity")
// when depth=2, "vibrato mode" is obtained (pure allpass chain)
// * `fb`: feedback gain between -1 and 1 (0 typical)
// * `invert`: 0 for normal, 1 to invert sign of flanging sum
//
// Reference:
//
// * <https://ccrma.stanford.edu/~jos/pasp/Phasing.html>
// * <http://www.geofex.com/Article_Folders/phasers/phase.html>
// * 'An Allpass Approach to Digital Phasing and Flanging', Julius O. Smith III,
// Proc. Int. Computer Music Conf. (ICMC-84), pp. 103-109, Paris, 1984.
// * CCRMA Tech. Report STAN-M-21: <https://ccrma.stanford.edu/STANM/stanms/stanm21/>
//------------------------------------------------------------
phaser2_stereo(Notches,width,frqmin,fratio,frqmax,speed,depth,fb,invert)
= phaser2_mono(Notches,0,width,frqmin,fratio,frqmax,speed,depth,fb,invert),
phaser2_mono(Notches,1,width,frqmin,fratio,frqmax,speed,depth,fb,invert);
// end jos section
/************************************************************************
************************************************************************
FAUST library file, GRAME section
Except where noted otherwise, Copyright (C) 2003-2017 by GRAME,
Centre National de Creation Musicale.
----------------------------------------------------------------------
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.
************************************************************************
************************************************************************/
// TODO: Add GRAME functions here
//########################################################################################
/************************************************************************
FAUST library file, further contributions section
All contributions below should indicate both the contributor and terms
of license. If no such indication is found, "git blame" will say who
last edited each line, and that person can be emailed to inquire about
license disposition, if their license choice is not already indicated
elsewhere among the libraries. It is expected that all software will be
released under LGPL, STK-4.3, MIT, BSD, or a similar FOSS license.
************************************************************************/