-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDaikrispator.cpp
223 lines (181 loc) · 4.81 KB
/
Daikrispator.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
//-------------------------------------------------------------------------------------
//
// Dekrispator for Daisy pod platform
// by Xavier Halgand
// august 2020
//
//*************************************************************************************
#include "daisysp.h"
#include "daisy_pod.h"
#include <math.h>
#include <stdint.h>
#include <stdbool.h>
#include "constants.h"
#include "math_tools.h"
#include "random.h"
#include "sequencer.h"
#include "oscillators.h"
#include "delay.h"
#include "chorusFD.h"
#include "phaser.h"
#include "sinetable.h"
#include "notesTables.h"
#include "resonantFilter.h"
#include "adsr.h"
//#include "blepvco.h"
#include "soundGen.h"
//--------------------------------------------------------------------------
using namespace daisysp;
using namespace daisy;
extern Sequencer_t seq;
extern bool delayON _CCM_;
extern bool phaserON _CCM_;
extern bool chorusON _CCM_;
static DaisyPod pod;
float sample_rate;
Parameter p_knob1, p_knob2;
bool freeze = false;
bool demoMode = true;
bool stopSound = false;
float oldk1, oldk2, k1, k2;
//--------------------------------------------------------------------------
void ConditionalParameter(float oldVal,
float newVal,
float ¶m,
float update);
//--------------------------------------------------------------------------
void Controls();
//--------------------------------------------------------------------------
static void AudioCallback( AudioHandle::InterleavingInputBuffer in,
AudioHandle::InterleavingOutputBuffer out,
size_t size)
{
Controls();
float yL, yR;
// for (size_t i = 0; i < size; i += 2) {
// computeSound(&yL, &yR);
// // left out
// out[i] = yL;
// // right out
// out[i + 1] = yR;
// }
if(!stopSound)
{
for(size_t i = 0; i < size; i += 2)
{
computeSound(&yL, &yR);
// left out
out[i] = yL;
// right out
out[i + 1] = yR;
}
}
else
{
for(size_t i = 0; i < size; i += 2)
{
// left out
out[i] = 0;
// right out
out[i + 1] = 0;
}
}
}
//--------------------------------------------------------------------------
//Updates values if knob had changed
void ConditionalParameter(float oldVal,
float newVal,
float ¶m,
float update)
{
if(abs(oldVal - newVal) > 0.0005)
{
param = update;
}
}
//--------------------------------------------------------------------------
//Controls Helpers
void UpdateEncoder() {}
//--------------------------------------------------------------------------
void UpdateKnobs()
{
k1 = pod.knob1.Process();
k2 = pod.knob2.Process();
//ConditionalParameter(oldk1, k1, seq.tempo, k1);
seq.tempo = 480 * k1 + 20;
seq.steptime = lrintf(sample_rate * 60 / seq.tempo);
if(k2 < 0.25f)
{
delayON = false;
phaserON = false;
chorusON = false;
}
else if(k2 < 0.5)
{
delayON = true;
phaserON = false;
chorusON = false;
}
else if(k2 < 0.75)
{
delayON = true;
phaserON = true;
chorusON = false;
}
else
{
delayON = true;
phaserON = true;
chorusON = true;
}
oldk1 = k1;
oldk2 = k2;
}
//--------------------------------------------------------------------------
void UpdateLeds()
{
pod.led1.Set(freeze, freeze, freeze);
pod.led2.Set(stopSound, !stopSound, 0);
pod.UpdateLeds();
}
//--------------------------------------------------------------------------
void UpdateButtons()
{
if(pod.button1.RisingEdge())
{
freeze = !freeze;
}
if(pod.button2.RisingEdge())
{
stopSound = !stopSound;
}
}
//--------------------------------------------------------------------------
void Controls()
{
pod.ProcessAnalogControls();
pod.ProcessDigitalControls();
UpdateEncoder();
UpdateKnobs();
UpdateButtons();
UpdateLeds();
}
//**************************************************************************
int main(void)
{
oldk1 = oldk2 = 0;
k1 = k2 = 0;
//Init everything
pod.Init();
sample_rate = pod.AudioSampleRate();
p_knob1.Init(pod.knob1, 20, 500, Parameter::LINEAR);
/* Initialize the on-board random number generator ! */
randomGen_init();
/* dekrispator synth init */
Synth_Init();
// start callback
pod.StartAdc();
pod.StartAudio(AudioCallback);
while(1) {}
}
/*--------------------------------END ------------------------------------*/