MIDI stream getting stomped

I’m not super familiar with how the Arduino MIDI library works, but what it looks like is happening is that there is too much time being spent in the audio callback, with not enough time to listen to the MIDI input (via MIDI1.read()).

With the upcoming DaisyDuino update we’re working on you’ll be able to adjust the block size of the audio callback, which would potentially free up enough time between calls to handle the MIDI.

There’s also an upcoming fix to the core stm32 library for daisy that will allow the data-cache to be enabled, and that will add a decent boost to performance, and could resolve this issue on its own. Not sure exactly when that will go live, but I have roughly documented the steps for implementing that improvement in this thread.

Something you can try in the meantime would be to restructure your program to only copy the audio buffer in the AudioCallback, and process it in the main loop. Something like:

pseudo-code:

float synth_buffer[48];
bool fill_buffer_flag;

void AudioCallback(**in, **out,  size)
{
    for (size_t i = 0; i < size; i++)
        output[0][i] = output[1][i] = synth_buffer[i];
    fill_buffer_flag = true;
}

void loop()
{
    midi1.read();
    if (fill_buffer_flag)
    {
        for (size_t i = 0; i < 48; i++)
            // Proccess your synth stuff.
        fill_buffer_flag = false;
    }
}

This may prevent the midi.read() from getting missed, but it could result in buffer underruns in your audio path if your processing loop is too busy, or the MIDI input is for some reason slow to read.