-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiEffect.cpp
366 lines (278 loc) · 10.2 KB
/
MultiEffect.cpp
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#include "daisysp.h"
#include "daisy_pod.h"
// Set max delay time to 0.75 of samplerate.
#define MAX_DELAY static_cast<size_t>(48000 * 2.5f)
#define CHRDEL 0
#define DEL 1
#define COR 2
#define PHR 3
#define OCT 4
using namespace daisysp;
using namespace daisy;
static DaisyPod pod;
/// declare effects used
static Chorus crs;
static Chorus crs2;
static Chorus crs3;
static Chorus crs4;
static PitchShifter pst;
static Phaser psr;
static Phaser psr2;
static DelayLine<float, MAX_DELAY> DSY_SDRAM_BSS dell;
static DelayLine<float, MAX_DELAY> DSY_SDRAM_BSS delr;
static DelayLine<float, MAX_DELAY> DSY_SDRAM_BSS dell2;
static DelayLine<float, MAX_DELAY> DSY_SDRAM_BSS delr2;
static Parameter deltime;
int mode = CHRDEL;
int numstages;
uint32_t octDelSize;
float currentDelay, feedback, delayTarget, freq, freqtarget, lfotarget, lfo;
float drywet;
//Helper functions
void Controls();
void GetReverbSample(float &outl, float &outr, float inl, float inr);
void GetDelaySample(float &outl, float &outr, float inl, float inr);
void GetChorusSample(float &outl, float &outr, float inl, float inr);
void GetPhaserSample(float &outl, float &outr, float inl, float inr);
void GetOctaveSample(float &outl, float &outr, float inl, float inr);
void AudioCallback(float *in, float *out, size_t size)
{
float outl, outr, inl, inr;
Controls();
//audio
for(size_t i = 0; i < size; i += 2)
{
inl = in[i];
inr = in[i + 1];
switch(mode)
{
case CHRDEL: GetReverbSample(outl, outr, inl, inr); break;
case DEL: GetDelaySample(outl, outr, inl, inr); break;
case COR: GetChorusSample(outl, outr, inl, inr); break;
case PHR: GetPhaserSample(outl, outr, inl, inr); break;
case OCT: GetOctaveSample(outl, outr, inl, inr); break;
default: outl = outr = 0;
}
// left out
out[i] = outl;
// right out
out[i + 1] = outr;
}
}
int main(void)
{
// initialize pod hardware and oscillator daisysp module
float sample_rate;
//Inits and sample rate
pod.Init();
sample_rate = pod.AudioSampleRate();
// start effect processing
dell.Init();
delr.Init();
dell2.Init();
delr2.Init();
crs.Init(sample_rate);
crs2.Init(sample_rate);
crs3.Init(sample_rate);
crs4.Init(sample_rate);
psr.Init(sample_rate);
psr2.Init(sample_rate);
pst.Init(sample_rate);
//set parameters
deltime.Init(pod.knob1, sample_rate * .05, MAX_DELAY, deltime.LOGARITHMIC);
//delay parameters
currentDelay = delayTarget = sample_rate * 0.75f;
dell.SetDelay(currentDelay);
delr.SetDelay(currentDelay);
dell2.SetDelay(currentDelay+500);
delr2.SetDelay(currentDelay+1000);
//chorus parameters
crs.SetFeedback(.1f);
crs.SetDelay(.7f);
crs2.SetFeedback(.1f);
crs2.SetDelay(.82f);
crs3.SetFeedback(.1f);
crs3.SetDelay(.9f);
crs4.SetFeedback(.1f);
crs4.SetDelay(.97f);
// phaser parameters
numstages = 4;
psr.SetPoles(numstages);
psr2.SetPoles(numstages);
freqtarget = freq = 0.f;
lfotarget = lfo = 0.f;
//pitchshifter parameters
pst.SetTransposition(12.0f);
/***
sets delay size changing the timbre of the pitchshifting ***/
octDelSize = 256;
pst.SetDelSize(octDelSize);
// start callback
pod.StartAdc();
pod.StartAudio(AudioCallback);
while(1) {}
}
void UpdateKnobs(float &k1, float &k2)
{
k1 = pod.knob1.Process();
k2 = pod.knob2.Process();
switch(mode)
{
/// a allan holdsworth inspired chorus plus stereo delay lead sound
case CHRDEL:
drywet = k1;
delayTarget = deltime.Process();
feedback = k1*0.2 + k2*0.1;
/**
crs.SetLfoDepth(0.15f+k2*0.35f);
crs2.SetLfoDepth(0.2f+k2*0.26f);
crs3.SetLfoDepth(0.23f+k2*0.37f);
crs4.SetLfoDepth(0.25f+k2*0.29f);
**/
crs.SetLfoDepth(4.0f + k1*1.1f );
crs2.SetLfoDepth(5.0f + k1*1.2f);
crs3.SetLfoDepth(6.0f + k1*0.9f);
crs4.SetLfoDepth(7.0f + k1*0.8f);
/**Set lfo frequency Frequency in Hz */
crs.SetLfoFreq(k2*0.6f);
crs2.SetLfoFreq(k2*0.7f);
crs3.SetLfoFreq(k2*0.8f);
crs4.SetLfoFreq(k2*0.9f);
break;
// a stereo delay without chorus
case DEL:
delayTarget = deltime.Process();
feedback = k2;
break;
// a chorus with no delay/reverb
case COR:
drywet = k1;
/** How much to modulate the delay by Works 0-1. */
crs.SetLfoDepth(4.0f + k1*1.1f );
crs2.SetLfoDepth(5.0f + k1*1.2f);
crs3.SetLfoDepth(6.0f + k1*0.9f);
crs4.SetLfoDepth(7.0f + k1*0.8f);
/**Set lfo frequency Frequency in Hz */
crs.SetLfoFreq(k2*0.6f);
crs2.SetLfoFreq(k2*0.7f);
crs3.SetLfoFreq(k2*0.8f);
crs4.SetLfoFreq(k2*0.9f);
break;
case PHR:
//ap_freq Frequency in Hz
/*** = k1 * k1 * 7000;
fonepole(freq, freqtarget, .0001f); //smooth at audio rate
psr.SetFreq(freq);
//feedback Amount from 0-1.
psr.SetFeedback(k2);
//set lfo_freq Frequency in Hz
lfo = k2*10.0f;
fonepole(lfo, lfotarget, .0001f); //smooth at audio rate
psr.SetLfoDepth(lfo);
psr.SetLfoFreq(k2*10);
// depth Works 0-1
***/
drywet = k1;
lfo = k2;
break;
case OCT:
drywet = k1;
break;
}
}
void UpdateEncoder()
{
mode = mode + pod.encoder.Increment();
mode = (mode % 5 + 5) % 5;
}
void UpdateLeds(float k1, float k2)
{
pod.led1.Set(
k1 * (mode == 2), k1 * (mode == 1), k1 * (mode == 0 || mode == 3));
pod.led2.Set(
k2 * (mode == 3), k2 * (mode == 2 || mode == 4), k2 * (mode == 0 || mode == 4));
pod.UpdateLeds();
}
void Controls()
{
float k1, k2;
delayTarget = feedback = drywet = 0;
pod.ProcessAnalogControls();
pod.ProcessDigitalControls();
UpdateKnobs(k1, k2);
UpdateEncoder();
UpdateLeds(k1, k2);
}
// process audio and add delays and modulated delays in
void GetReverbSample(float &outl, float &outr, float inl, float inr)
{
fonepole(currentDelay, delayTarget, .00007f);
delr.SetDelay(currentDelay);
dell.SetDelay(currentDelay);
delr2.SetDelay(20000.0f);
dell2.SetDelay(30000.0f);
outl = dell.Read() + dell2.Read();
outr = delr.Read() + delr2.Read();
dell.Write((feedback * outl) + inl);
dell2.Write((feedback * outl) + inl);
delr.Write((feedback * outr) + inr);
delr2.Write((feedback * outr) + inr);
crs.Process(inl);
crs2.Process(inr);
crs3.Process(inl);
crs4.Process(inr);
outl = crs.GetLeft() * drywet *2.0f + crs3.GetLeft() * drywet*2.0f+ inl * (0.5f - drywet) + (feedback * outl*drywet*0.6f) + ((1.0f - feedback) * inl*drywet);;
outr = crs2.GetRight() * drywet*2.0f + + crs4.GetRight() * drywet*2.0f + inr * (0.5f - drywet) + (feedback * outr*drywet*0.6f) + ((1.0f - feedback) * inr*drywet);
}
// process audio adding in delays
void GetDelaySample(float &outl, float &outr, float inl, float inr)
{
fonepole(currentDelay, delayTarget, .00007f);
delr.SetDelay(currentDelay);
dell.SetDelay(currentDelay);
delr2.SetDelay(20000.0f);
dell2.SetDelay(30000.0f);
outl = dell.Read() + dell2.Read();
outr = delr.Read() + delr2.Read();
dell.Write((feedback * outl) + inl);
dell2.Write((feedback * outl) + inl);
outl = (feedback * outl) + ((1.0f - feedback) * inl);
delr.Write((feedback * outr) + inr);
delr2.Write((feedback * outr) + inr);
outr = (feedback * outr) + ((1.0f - feedback) * inr);
}
// process audio adding in chorus
void GetChorusSample(float &outl, float &outr, float inl, float inr)
{
crs.Process(inl);
crs2.Process(inr);
crs3.Process(inl);
crs4.Process(inr);
outl = crs.GetLeft() * drywet *2.5 + crs3.GetLeft() * drywet*2.5 + inl * (0.5f - drywet);
outr = crs2.GetRight() * drywet*2.5 + + crs4.GetRight() * drywet*2.5 + inr * (0.5f - drywet);
}
void GetPhaserSample(float &outl, float &outr, float inl, float inr){
freq = 7000.0f;
fonepole(freq, freqtarget, .0001f); //smooth at audio rate
psr.SetFreq(freq);
fonepole(lfo, lfotarget, .0001f); //smooth at audio rate
psr.SetLfoDepth(lfo);
psr.SetFeedback(.2f);
psr2.SetFeedback(.3f);
psr.SetLfoFreq(30.0f);
psr2.SetLfoFreq(40.0f);
freq = 4000.0f;
fonepole(freq, freqtarget, .0001f); //smooth at audio rate
psr2.SetFreq(freq);
fonepole(lfo, lfotarget, .0001f); //smooth at audio rate
psr2.SetLfoDepth(lfo);
crs.Process(inl);
outl = crs.GetLeft() * drywet*0.5 + psr.Process(inl) * drywet + inl * (1.f - drywet);
outr = crs.GetRight() * drywet*0.3 + psr2.Process(inr) * drywet + inr * (1.f - drywet);
//outl = psr.Process(inl * drywet) + inl*(1.0f-drywet);
// outr = psr.Process(inr * drywet) + inr*((1.0f-drywet));
}
void GetOctaveSample(float &outl, float &outr, float inl, float inr){
outl = crs.GetLeft() * drywet*0.2 + pst.Process(inl) * drywet + inl * (1.f - drywet);
outr = crs.GetRight() * drywet*0.2 + pst.Process(inr) * drywet + inr * (1.f - drywet);
}