I’m expanding my working Daisy Seed monosynth/sequencer to be duophonic. With an additional voice added, the incoming Midi stream is getting corrupted. I’m hoping that some kind soul who has more experience with Daisy than I do (just over 10 days now!) can tell me what I’m missing, and how I might fix this. I’ve boiled my code down to a minimal sample that produces the problem. I do notice that if I reduce processing by, for example, removing the LFO, the problem becomes much less severe. Thanks in advance for any help you can offer.
Here’s the input Midi data (channel, note, velocity), produced by an Arduino Mega-based sequencer. Pairs of [channel 1, channel 2] messages are sent, about 3-4 pairs per second.
1, 36, 127
2, 36, 127
1, 36, 127
2, 36, 127
1, 36, 127
2, 36, 127
1, 36, 127
2, 36, 127
1, 36, 127
2, 36, 127
1, 36, 127
2, 36, 127
Here’s a sample of Midi as received and printed by my DaisyDuino code:
1, 36, 127
2, 36, 127
1, 127, 145
1, 36, 127
1, 36, 127
2, 36, 144
2, 36, 127
2, 36, 127
1, 36, 145
1, 36, 127
1, 36, 127
2, 36, 127
And here’s the code:
#include <MIDI.h>
#include "DaisyDuino.h"
const uint8_t NUM_VOICES = 2;
MoogLadder flt[NUM_VOICES];
Oscillator osc[NUM_VOICES];
Oscillator lfo[NUM_VOICES];
AdEnv ampEnv[NUM_VOICES];
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);
void handleNoteOn(uint8_t channel, uint8_t pitch, uint8_t velocity) {
Serial.print(channel);
Serial.print(F(", "));
Serial.print(pitch);
Serial.print(F(", "));
Serial.println(velocity);
osc[channel - 1].SetFreq(mtof(pitch));
ampEnv[channel - 1].Trigger();
}
void audioCallback(float **in, float **out, size_t size) {
for (size_t i = 0; i < size; i++) {
float totalOscSample = 0;
for (uint8_t voice = 0; voice < NUM_VOICES; ++voice) {
float sample = lfo[voice].Process() *
ampEnv[voice].Process() *
flt[voice].Process(osc[voice].Process());
totalOscSample += sample;
}
out[0][i] = totalOscSample;
out[1][i] = totalOscSample;
}
}
void setup() {
Serial.begin(9600);
delay(1000);
DAISY.init(DAISY_SEED, AUDIO_SR_48K);
float samplerate = DAISY.get_samplerate();
for (uint8_t voice = 0; voice < NUM_VOICES; ++voice) {
osc[voice].Init(samplerate);
osc[voice].SetWaveform(Oscillator::WAVE_SAW);
flt[voice].Init(samplerate);
lfo[voice].Init(samplerate);
ampEnv[voice].Init(samplerate);
}
DAISY.begin(audioCallback);
MIDI1.setHandleNoteOn(handleNoteOn);
MIDI1.begin(MIDI_CHANNEL_OMNI); // Listen to all incoming messages
}
void loop() {
MIDI1.read();
}