-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiFX.cpp
205 lines (163 loc) · 4.81 KB
/
MultiFX.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
#include "daisy_pod.h"
#include "daisysp.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
using namespace daisysp;
using namespace daisy;
static DaisyPod pod;
static Svf filtl, filtr;
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;
int mode = REV;
float currentDelay, feedback, delayTarget, cutoff;
int crushmod, crushcount;
float crushsl, crushsr;
float drywet = 0.5f;
//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 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;
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();
filtl.Init(sample_rate);
filtr.Init(sample_rate);
rev.Init(sample_rate);
dell.Init();
delr.Init();
tone.Init(sample_rate);
//fixed hpf before the reverb
filtl.SetDrive(.5f);
filtl.SetRes(0.7f);
filtl.SetFreq(120.f);
filtr.SetDrive(.5f);
filtr.SetRes(0.7f);
filtr.SetFreq(120.f);
//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);
// 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:
rev.SetFeedback(k1);
rev.SetLpFreq(k2 * 18000.f);
break;
case DEL:
delayTarget = deltime.Process();
feedback = k2;
break;
case CRU:
cutoff = cutoffParam.Process();
tone.SetFreq(cutoff);
crushmod = (int)crushrate.Process();
}
}
void UpdateEncoder()
{
mode = mode + pod.encoder.Increment();
mode = (mode % 3 + 3) % 3;
}
void UpdateLeds(float k1, float k2)
{
pod.led1.Set(
k1 * (mode == 2), k1 * (mode == 1), k1 * (mode == 0 || mode == 2));
pod.led2.Set(
k2 * (mode == 2), k2 * (mode == 1), k2 * (mode == 0 || mode == 2));
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)
{
//filter before the reverb
filtl.Process(inl);
filtr.Process(inr);
rev.Process(filtl.High(), filtr.High(), &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);
}