forked from Nettech15/Daisy-Seed-7-Voice-VA-Synthesizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
517 lines (495 loc) · 10.9 KB
/
main.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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
/*
This code is a modification of OscPocketD/VASynth, created by Staffan Melin, [email protected].
It was later modified by (Steven @moonfriendsynth) to work with the Daisy Pod.
I (Christopher @Nettech15) have modified it further to run on the Daisy Seed without the use of the Daisy Pod board.
Synth parameters are now controlled by a Miditech i2-61 midi keyboard.
Multiple Daisy Seeds will appear as USB-MIDI devices with the name "Daisy Seed Built in" and the device number.
Audio output/input is thru the built-in audio codec.
Specifications:
- 8 voice polyphonic.
- Dual oscillator per voice.
- VCA per voice.
- VCF (4-pole Resonant low-pass) per voice.
- Separate ADSR's for VCA and VCF
- MIDI Editable parameters.
- Ten Preset Patches.
- Ten User-Programmable Patches using QSPI Flash memory storage.
- Waveform select for both oscillators; Sine/Triangle/Saw/Square/Ramp/Polyblep-Tri/Polyblep-Saw/Polyblep-Square
- Oscillator (1/2) mix.
- Oscillator 2 De-tune.
- Scale for Oscillator 2.
- LFO for Pitch Modulation Wheel.
- LFO for Pulse Width Modulation.
- LFO for VCF Modulation.
- LFO for VCA Modulation.
- Keyboard velocity routable to VCA and/or VCF.
- VCF envelope level.
- Stereo simulation effect.
Feel free to copy, modify, and improve this code to match your equipment and sound requirements.
In the meantime, I will be actively working on implementing more features and fixing existing problems.
*/
#include "daisy_seed.h"
#include "daisysp.h"
#include "main.h"
#include "vasynth.h"
using namespace daisy;
using namespace daisysp;
// globals
DaisySeed hardware;
MidiUsbHandler midi;
float sysSampleRate;
float sysCallbackRate;
extern uint8_t preset_max;
extern VASynthSetting preset_setting[PRESET_MAX];
uint8_t param_;
float pitch_bend = 1.0f;
float master_tune = 0.0f;
// sound
VASynth vasynth;
uint8_t gPlay = PLAY_ON;
// audio callback
void AudioCallback(AudioHandle::InterleavingInputBuffer in,
AudioHandle::InterleavingOutputBuffer out,
size_t size)
{
float voice_left, voice_right;
for (size_t n = 0; n < size; n += 2)
{
if (gPlay == PLAY_ON)
{
vasynth.Process(&voice_left, &voice_right);
out[n] = voice_left + in[n];;
out[n + 1] = voice_right + in[n + 1];;
}
else
{
out[n] = 0;
out[n + 1] = 0;
}
}
}
// midi handler
void HandleMidiMessage(MidiEvent m)
{
switch(m.type)
{
case NoteOn:
{
NoteOnEvent p = m.AsNoteOn();
if ((vasynth.midi_channel_ == MIDI_CHANNEL_ALL) || (p.channel == vasynth.midi_channel_))
{
vasynth.NoteOn(p.note, p.velocity);
hardware.SetLed(true);
}
break;
}
case NoteOff:
{
NoteOnEvent p = m.AsNoteOn();
if ((vasynth.midi_channel_ == MIDI_CHANNEL_ALL) || (p.channel == vasynth.midi_channel_))
{
vasynth.NoteOff(p.note);
hardware.SetLed(false);
}
break;
}
case PitchBend:
{
PitchBendEvent p = m.AsPitchBend();
if ((vasynth.midi_channel_ == MIDI_CHANNEL_ALL) || (p.channel == vasynth.midi_channel_))
{
vasynth.PitchBend(p.value);
}
break;
}
case ControlChange:
{
ControlChangeEvent p = m.AsControlChange();
switch(p.control_number)
{
case 1: // Modulation Wheel
vasynth.lfo_amp_ = ((float)p.value / 127.0f);
vasynth.SetLFO();
break;
case 7: // Data Slider Default (Volume)
switch(param_)
{
case 0: // This is set as the default parameter
{
master_tune = 1.0f - ((float)p.value / 64.0f);
break;
}
case 1:
{
vasynth.waveform_ = p.value >> 4;
vasynth.SetWaveform();
break;
}
case 2:
{
vasynth.osc2_waveform_ = p.value >> 4;
vasynth.SetWaveform();
break;
}
case 3:
{
vasynth.osc_mix_ = ((float)p.value / 127.0f);
break;
}
case 4:
{
vasynth.osc2_detune_ = ((float)p.value / 255.0f);
break;
}
case 5:
{
vasynth.osc2_transpose_ = (1.0f + ((float)p.value / 127.0f));
break;
}
case 6:
{
vasynth.filter_res_ = ((float)p.value / 127.0f);
vasynth.SetFilter();
break;
}
case 7:
{
vasynth.osc_pw_ = ((float)p.value / 255.0f);
break;
}
case 8:
{
vasynth.osc2_pw_ = ((float)p.value / 255.0f);
break;
}
case 9:
{
vasynth.eg_f_attack_ = ((float)p.value / 127.0f);
vasynth.SetEG();
break;
}
case 10:
{
vasynth.eg_f_decay_ = ((float)p.value / 127.0f);
vasynth.SetEG();
break;
}
case 11:
{
vasynth.eg_f_sustain_ = ((float)p.value / 127.0f);
vasynth.SetEG();
break;
}
case 12:
{
vasynth.eg_f_release_ = ((float)p.value / 127.0f);
vasynth.SetEG();
break;
}
case 13:
{
vasynth.eg_a_attack_ = ((float)p.value / 127.0f);
vasynth.SetEG();
break;
}
case 14:
{
vasynth.eg_a_decay_ = ((float)p.value / 127.0f);
vasynth.SetEG();
break;
}
case 15:
{
vasynth.eg_a_sustain_ = ((float)p.value / 127.0f);
vasynth.SetEG();
break;
}
case 16:
{
vasynth.eg_a_release_ = ((float)p.value / 127.0f);
vasynth.SetEG();
break;
}
case 17:
{
break;
}
case 18:
{
break;
}
case 19:
{
vasynth.vel_select_ = p.value >> 5;
break;
}
case 20:
{
vasynth.eg_f_amount_ = ((float)p.value / 127.0f);
break;
}
case 21:
{
vasynth.lfo_freq_ = ((float)p.value / 127.0f);
vasynth.SetLFO();
break;
}
case 22:
{
vasynth.pwmlfo_freq_ = ((float)p.value / 127.0f);
vasynth.SetPWMLFO();
break;
}
case 23:
{
vasynth.pwmlfo_amp_ = ((float)p.value / 255.0f);
vasynth.SetPWMLFO();
break;
}
case 24:
{
vasynth.vcalfo_freq_ = ((float)p.value / 127.0f);
vasynth.SetVCALFO();
break;
}
case 25:
{
vasynth.vcalfo_amp_ = ((float)p.value / 127.0f);
vasynth.SetVCALFO();
break;
}
case 26:
{
vasynth.vcflfo_freq_ = ((float)p.value / 127.0f);
vasynth.SetVCFLFO();
break;
}
case 27:
{
vasynth.vcflfo_amp_ = ((float)p.value / 127.0f);
vasynth.SetVCFLFO();
break;
}
case 28:
{
vasynth.vcalfo_waveform_ = p.value >> 4;
vasynth.vcflfo_waveform_ = p.value >> 4;
vasynth.SetVCALFO();
vasynth.SetVCFLFO();
break;
}
}
break;
default: break;
}
break;
}
case ProgramChange:
{
ProgramChangeEvent p = m.AsProgramChange();
if ((vasynth.midi_channel_ == MIDI_CHANNEL_ALL) || (p.channel == vasynth.midi_channel_))
{
if(p.program >= 29)
{
switch (p.program)
{
case 29:
{
vasynth.SaveToLive(&preset_setting[0]);
break;
}
case 30:
{
vasynth.SaveToLive(&preset_setting[1]);
break;
}
case 31:
{
vasynth.SaveToLive(&preset_setting[2]);
break;
}
case 32:
{
vasynth.SaveToLive(&preset_setting[3]);
break;
}
case 33:
{
vasynth.SaveToLive(&preset_setting[4]);
break;
}
case 34:
{
vasynth.SaveToLive(&preset_setting[5]);
break;
}
case 35:
{
vasynth.SaveToLive(&preset_setting[6]);
break;
}
case 36:
{
vasynth.SaveToLive(&preset_setting[7]);
break;
}
case 37:
{
vasynth.SaveToLive(&preset_setting[8]);
break;
}
case 38:
{
vasynth.SaveToLive(&preset_setting[9]);
break;
}
case 39:
{
vasynth.FlashLoad(0);
break;
}
case 40:
{
vasynth.FlashLoad(1);
break;
}
case 41:
{
vasynth.FlashLoad(2);
break;
}
case 42:
{
vasynth.FlashLoad(3);
break;
}
case 43:
{
vasynth.FlashLoad(4);
break;
}
case 44:
{
vasynth.FlashLoad(5);
break;
}
case 45:
{
vasynth.FlashLoad(6);
break;
}
case 46:
{
vasynth.FlashLoad(7);
break;
}
case 47:
{
vasynth.FlashLoad(8);
break;
}
case 48:
{
vasynth.FlashLoad(9);
break;
}
case 49:
{
vasynth.FlashSave(0);
break;
}
case 50:
{
vasynth.FlashSave(1);
break;
}
case 51:
{
vasynth.FlashSave(2);
break;
}
case 52:
{
vasynth.FlashSave(3);
break;
}
case 53:
{
vasynth.FlashSave(4);
break;
}
case 54:
{
vasynth.FlashSave(5);
break;
}
case 55:
{
vasynth.FlashSave(6);
break;
}
case 56:
{
vasynth.FlashSave(7);
break;
}
case 57:
{
vasynth.FlashSave(8);
break;
}
case 58:
{
vasynth.FlashSave(9);
break;
}
}
}
else
{
vasynth.ProgramChange(p.program);
break;
}
}
}
default: break;
}
}
int main(void)
{
// init hardware
hardware.Init(true); // true = boost to 480MHz
sysSampleRate = hardware.AudioSampleRate();
sysCallbackRate = hardware.AudioCallbackRate();
// init qspi flash for saving and loading patches
QSPIHandle::Config qspi_config;
qspi_config.device = QSPIHandle::Config::Device::IS25LP064A;
qspi_config.mode = QSPIHandle::Config::Mode::MEMORY_MAPPED;
qspi_config.pin_config.io0 = {DSY_GPIOF, 8};
qspi_config.pin_config.io1 = {DSY_GPIOF, 9};
qspi_config.pin_config.io2 = {DSY_GPIOF, 7};
qspi_config.pin_config.io3 = {DSY_GPIOF, 6};
qspi_config.pin_config.clk = {DSY_GPIOF, 10};
qspi_config.pin_config.ncs = {DSY_GPIOG, 6};
hardware.qspi.Init(qspi_config);
// setup incl default values
vasynth.First();
// Initialize USB Midi
MidiUsbHandler::Config midi_cfg;
midi_cfg.transport_config.periph = MidiUsbTransport::Config::INTERNAL;
midi.Init(midi_cfg);
// let everything settle
System::Delay(100);
// Start calling the audio callback
hardware.StartAudio(AudioCallback);
// Loop forever
for(;;)
{
// handle MIDI Events
midi.Listen();
while(midi.HasEvents())
{
HandleMidiMessage(midi.PopEvent());
}
}
}