forked from s-e-a-m/faust-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csound.lib
142 lines (132 loc) · 5.52 KB
/
csound.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
//############################################################ ambisonic.lib ###
//
// A library for general ambisonic documentation
//
// * ENCODERS
// * DECODERS
// *
// *
// *
//
//##############################################################################
/*******************************************************************************
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 "Ambisonic Elements Faust Library";
declare version "0.1";
declare author "Giuseppe Silvi";
declare license "CC4";
//================================================================== OPCODES ===
//==============================================================================
//------------------------------------------------------------------------------
// TONE
// A first-order recursive low-pass filter with variable frequency response.
//------------------------------------------------------------------------------
// tone is a 1 term IIR filter. Its formula is:
// y[n] = c1 * x[n] + c2 * y[n-1]
// where
// b = 2 - cos(2 π hp/sr)
// c2 = b - sqrt(b2 - 1.0)
// c1 = 1 - c2
//
// #### Reference
// https://csound.com/docs/manual//tone.html
//
// #### Usage
//
// ```
// _ : tone(cf) : _
// ```
//
//------------------------------------------------------------------------------
tone(cf) = _*c1 : (+~_ *(c2))
with{
b = 2 - (cos(2*ma.PI*(cf/ma.SR)));
c1 = 1-c2;
c2 = b - sqrt((b*b)-1.0);
};
//------------------------------------------------------------------------------
// ATONE
// atone — A hi-pass filter whose transfer functions are the complements of the
// tone opcode.
//------------------------------------------------------------------------------
// atone is a filter whose transfer functions is the complement of tone.
// atone is thus a form of high-pass filter whose transfer functions represent
// the “filtered out” aspects of their complements. However, power scaling is
// not normalized in atone but remains the true complement of the corresponding
// unit. Thus an audio signal, filtered by parallel matching tone and atone
// units, would under addition simply reconstruct the original spectrum.
//
// #### Reference
// https://csound.com/docs/manual//tone.html
//
// #### Usage
//
// ```
// _ : atone(freq) : _
// ```
//
//------------------------------------------------------------------------------
atone(freq) = _ <: _ - tone(freq);
//------------------------------------------------------------------------------
// PHASER1
// First-order allpass filters arranged in a series.
//------------------------------------------------------------------------------
// An implementation of iord number of first-order allpass filters in series.
//
// phaser1 implements iord number of first-order allpass sections, serially
// connected, all sharing the same coefficient. Each allpass section can be
// represented by the following difference equation:
//
// y(n) = C * x(n) + x(n-1) - C * y(n-1)
//
// where x(n) is the input, x(n-1) is the previous input, y(n) is the output,
// y(n-1) is the previous output, and C is a coefficient which is calculated
// from the value of kfreq, using the bilinear z-transform.
//
// #### Reference
// https://csound.com/docs/manual/phaser1.html
//
// CSOUND Syntax
// ares phaser1 asig, kfreq, kord, kfeedback [, iskip]
// kfreq -- frequency (in Hz) of the filter(s). This is the frequency at which
// each filter in the series shifts its input by 90 degrees.
// kord -- the number of allpass stages in series. These are first-order filters
// and can range from 1 to 4999.
// kfeedback -- amount of the output which is fed back into the input of the
// allpass chain. With larger amounts of feedback, more prominent
// notches appear in the spectrum of the output. kfeedback must
// be between -1 and +1. for stability.
// #### Usage
//
// ```
// _ : phaser1(order,freq,g) : _
// ```
//
//------------------------------------------------------------------------------
//freq = vslider("Frequency", 0,0,1,0.01);
phaser1(order,C,g) = ( + : seq(i,order,ap(C/4/order)))~*(g)
with{
ap(C) = _ <: _*(C) + mem : -~*(C);
clip = min(1) : max(-1);
};
//process = phaser1(4,freq);