-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormants.soul
217 lines (174 loc) · 6.33 KB
/
Formants.soul
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
graph Formants()
{
input stream float<2> in;
output stream float<2> out;
input tp.type sType;
input event float vowel, intensity, vType;
input stream float vowel_lfo, vowel_env;
namespace eq = soul::filters(float<2>)::tpt::simper_eq;
let
{
tp = SoundTypeProcessor;
lfo = soul::oscillators::lfo::Processor (0, 0, 3.0f, 0.5f);
vtl = VowelToLfoPrams;
mc = MonoConverter;
env = ADSREnvelope;
f1 = Formant;
f2 = Formant;
f3 = Formant;
f4 = Formant;
eq1 = eq::Processor;
eq2 = eq::Processor;
eq3 = eq::Processor;
eq4 = eq::Processor;
eq_mode = Values(float[] (2)); //bandpass filter
eq_q = Values(float[] (10.0f));
gain = soul::gain::FixedGain (float<2>, 0.8f);
}
connection
{
//user parameter pass to Formants
vowel -> f1.vowel, f2.vowel, f3.vowel, f4.vowel;
vType -> f1.vType, f2.vType, f3.vType, f4.vType;
//vowel to LFO
vowel -> vtl.vowel;
intensity -> vtl.intensity;
vType -> vtl.lfoOn;
vtl.rateHz -> lfo.rateHzIn;
vtl.depth -> lfo.depthIn;
lfo.out -> f1.vowel_lfo, f2.vowel_lfo,f3.vowel_lfo, f4.vowel_lfo;
//vowel to envelope
vowel -> env.threshhold;
// intensity -> env.attack, env.release;
in -> mc.in;
mc.out -> env.triggerLevel;
env.envelopeLevel -> f1.vowel_env, f2.vowel_env, f3.vowel_env, f4.vowel_env;
//resolve user parameter value to formant table
tp.freq_min[0] -> f1.freq_min_in;
tp.freq_max[0] -> f1.freq_max_in;
tp.gain_min[0] -> f1.gain_min_in;
tp.gain_max[0] -> f1.gain_max_in;
tp.freq_min[1] -> f2.freq_min_in;
tp.freq_max[1] -> f2.freq_max_in;
tp.gain_min[1] -> f2.gain_min_in;
tp.gain_max[1] -> f2.gain_max_in;
tp.freq_min[2] -> f3.freq_min_in;
tp.freq_max[2] -> f3.freq_max_in;
tp.gain_min[2] -> f3.gain_min_in;
tp.gain_max[2] -> f3.gain_max_in;
tp.freq_min[3] -> f4.freq_min_in;
tp.freq_max[3] -> f4.freq_max_in;
tp.gain_min[3] -> f4.gain_min_in;
tp.gain_max[3] -> f4.gain_max_in;
// Pass frequency and gain information to bandpass filter
f1.freq -> eq1.frequencyIn;
f2.freq -> eq2.frequencyIn;
f3.freq -> eq3.frequencyIn;
f4.freq -> eq4.frequencyIn;
f1.gain -> eq1.gainIn;
f2.gain -> eq2.gainIn;
f3.gain -> eq3.gainIn;
f4.gain -> eq4.gainIn;
eq_mode.out -> eq1.modeIn, eq2.modeIn, eq3.modeIn, eq4.modeIn;
intensity -> eq1.qualityIn, eq2.qualityIn, eq3.qualityIn, eq4.qualityIn;
//input & ouput connection
in -> eq1.in, eq2.in, eq3.in, eq4.in;
eq1.out, eq2.out, eq3.out, eq4.out -> gain -> out;
}
}
// resolve parameters to frequency and gain
processor Formant()
{
input event float vowel, vType, freq_max_in, freq_min_in, gain_max_in, gain_min_in;
input stream float vowel_lfo, vowel_env;
output event float freq, gain, Q;
float freq_max, freq_min, gain_max, gain_min, percentage;
bool manual, lfo, envelop;
event vType(float val) {
if (val == 0){ manual = true; lfo = false; envelop = false;}
else if (val == 1){ manual = false; lfo = true; envelop = false;}
else if (val == 2){ manual = false; lfo = false; envelop = true;}
}
event vowel(float val) {
if(manual){
percentage = val; onUpdate();
}
}
event freq_max_in (float val) { freq_max = val; onUpdate(); }
event freq_min_in (float val) { freq_min = val; onUpdate(); }
event gain_max_in (float val) { gain_max = val; onUpdate(); }
event gain_min_in (float val) { gain_min = val; onUpdate(); }
void onUpdate()
{
if (manual){
freq << lerp (freq_min, freq_max, percentage * (1.0f / 100.0f));
gain << soul::dBtoGain( lerp (gain_min, gain_max, percentage * (1.0f / 100.0f)) );
}
}
void run()
{
loop{
if (lfo){
freq << lerp (freq_min, freq_max, (abs(vowel_lfo)*10000) * (1.0f / 100.0f));
gain << soul::dBtoGain( lerp (gain_min, gain_max, (abs(vowel_lfo)*10000) * (1.0f / 100.0f)) );
}
else if (envelop){
freq << lerp (freq_min, freq_max, (abs(vowel_env)*100) * (1.0f / 100.0f));
gain << soul::dBtoGain( lerp (gain_min, gain_max, (abs(vowel_env)*100) * (1.0f / 100.0f)) );
}
advance();
}
}
}
// Resolve vowel/intensity input to LFO rate/depth
processor VowelToLfoPrams()
{
input event float vowel, intensity, lfoOn;
output event float rateHz, depth;
bool lfo;
event lfoOn (float on){ lfo = (on == 1) ? true:false; }
event vowel(float val){
rateHz << lerp(0.0f , 8.0f, val/100);
}
event intensity(float val){
depth << lerp(0.0f , 5.0f, val/100);
}
}
// Resolve type parameter to frequency band based on formant table
processor SoundTypeProcessor()
{
input event float type;
output event float freq_min[4], freq_max[4], gain_min[4], gain_max[4];
event type (float type) {
if (type == 0.0f) {
freq_min << float[] (350.0f, 600.0f, 2400.0f, 2675.0f);
gain_min << float[] (0.0f, -20.0f, -32.0f, -28.0f);
freq_max << float[] (600.0f, 1040.0f, 2250.0f, 2450.0f);
gain_max << float[] (0.0f, -7.0f, -9.0f, -9.0f);
}
if (type == 1.0f){
freq_min << float[] (600.0f, 1040.0f, 2250.0f, 2450.0f);
freq_max << float[] (250.0f, 1750.0f, 2600.0f, 3050.0f);
gain_min << float[] (0.0f, -7.0f, -9.0f, -9.0f);
gain_max << float[] (-5.0f, -30.0f, -16.0f, -22.0f);
}
if (type == 2.0f){
freq_min << float[] (400.0f, 750.0f, 2400.0f, 2600.0f);
freq_max << float[] (450.0f, 1620.0f, 2400.0f, 2800.0f);
gain_min << float[] (-7.0f, -11.0f, -21.0f, -20.0f);
gain_max << float[] (0.0f, -12.0f, -9.0f, -12.0f);
}
}
}
processor MonoConverter
{
input stream float<2> in;
output stream float out;
void run(){
loop{
let mono = (in[0] + in[1])/2;
out << mono;
advance();
}
}
}