-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmulti-effect.cpp
More file actions
217 lines (172 loc) · 5.19 KB
/
Copy pathmulti-effect.cpp
File metadata and controls
217 lines (172 loc) · 5.19 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#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 REV 0
#define DEL 1
#define CRU 2
#define PS 3
using namespace daisysp;
using namespace daisy;
static DaisyPod pod;
static ReverbSc rev;
static DelayLine<float, MAX_DELAY> DSY_SDRAM_BSS dell;
static DelayLine<float, MAX_DELAY> DSY_SDRAM_BSS delr;
static Tone tone;
static Parameter deltime, cutoffParam, crushrate;
PitchShifter DSY_SDRAM_BSS ps;
static Oscillator osc;
int mode = REV;
float currentDelay, feedback, delayTarget, cutoff;
int crushmod, crushcount;
float crushsl, crushsr, drywet;
float shifted, unshifted;
//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 GetCrushSample(float &outl, float &outr, float inl, float inr);
void GetPitchShifterSample(float &outl, float &outr, float inl, float inr);
void AudioCallback(AudioHandle::InterleavingInputBuffer in,
AudioHandle::InterleavingOutputBuffer 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 REV: GetReverbSample(outl, outr, inl, inr); break;
case DEL: GetDelaySample(outl, outr, inl, inr); break;
case CRU: GetCrushSample(outl, outr, inl, inr); break;
case PS: GetPitchShifterSample(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();
pod.SetAudioBlockSize(4);
sample_rate = pod.AudioSampleRate();
rev.Init(sample_rate);
dell.Init();
delr.Init();
tone.Init(sample_rate);
//set parameters
deltime.Init(pod.knob1, sample_rate * .05, MAX_DELAY, deltime.LOGARITHMIC);
cutoffParam.Init(pod.knob1, 500, 20000, cutoffParam.LOGARITHMIC);
crushrate.Init(pod.knob2, 1, 50, crushrate.LOGARITHMIC);
//reverb parameters
rev.SetLpFreq(18000.0f);
rev.SetFeedback(0.85f);
//delay parameters
currentDelay = delayTarget = sample_rate * 0.75f;
dell.SetDelay(currentDelay);
delr.SetDelay(currentDelay);
ps.Init(sample_rate);
ps.SetTransposition(12.0f);
// setup oscilator
osc.Init(sample_rate);
osc.SetFreq(440.f);
osc.SetWaveform(Oscillator::WAVE_POLYBLEP_TRI);
// 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)
{
case REV:
drywet = k1;
rev.SetFeedback(k2);
break;
case DEL:
delayTarget = deltime.Process();
feedback = k2;
break;
case CRU:
cutoff = cutoffParam.Process();
tone.SetFreq(cutoff);
crushmod = (int)crushrate.Process();
case PS:
ps.SetTransposition(k1);
// may need some additional part here with shifted
}
}
void UpdateEncoder()
{
mode = mode + pod.encoder.Increment();
mode = (mode % 4 + 4) % 4;
}
void UpdateLeds(float k1, float k2)
{
pod.led1.Set(
k1 * (mode == 2 || mode == 3), k1 * (mode == 1 || mode == 3), k1 * (mode == 0 || mode == 2 || mode == 3));
pod.led2.Set(
k2 * (mode == 2 || mode == 3), k2 * (mode == 1 || mode == 3), k2 * (mode == 0 || mode == 2 || mode == 3));
pod.UpdateLeds();
}
void Controls()
{
float k1, k2;
delayTarget = feedback = drywet = 0;
pod.ProcessAnalogControls();
pod.ProcessDigitalControls();
UpdateKnobs(k1, k2);
UpdateEncoder();
UpdateLeds(k1, k2);
}
void GetReverbSample(float &outl, float &outr, float inl, float inr)
{
rev.Process(inl, inr, &outl, &outr);
outl = drywet * outl + (1 - drywet) * inl;
outr = drywet * outr + (1 - drywet) * inr;
}
void GetDelaySample(float &outl, float &outr, float inl, float inr)
{
fonepole(currentDelay, delayTarget, .00007f);
delr.SetDelay(currentDelay);
dell.SetDelay(currentDelay);
outl = dell.Read();
outr = delr.Read();
dell.Write((feedback * outl) + inl);
outl = (feedback * outl) + ((1.0f - feedback) * inl);
delr.Write((feedback * outr) + inr);
outr = (feedback * outr) + ((1.0f - feedback) * inr);
}
void GetCrushSample(float &outl, float &outr, float inl, float inr)
{
crushcount++;
crushcount %= crushmod;
if(crushcount == 0)
{
crushsr = inr;
crushsl = inl;
}
outl = tone.Process(crushsl);
outr = tone.Process(crushsr);
}
// TODO;
void GetPitchShifterSample(float &outl, float &outr, float inl, float inr)
{
unshifted = osc.Process();
shifted = ps.Process(unshifted);
outl = shifted;
outr = unshifted;
}