Serial to Usb midi transfer

Hello to all. I have a conundrum that I can't figure out. I am using a Teensy 2.0....
Below is a piece of code that allows me to listen on Serial1 for midi clock messages (example, a drum machine with 5pin midi) and then pass them through USB to keep all connected electronic equipment in sync.
In this case I have guitar delay pedals connected via USB. The pedals all sync perfectly with tempo and any tempo changes that occur on purpose. However, the audio repeats from the delay pedal are slightly garbled. When I use code that acts as a master clock this problem doesn't really exist.
I expect this is because of some variation in the timing of the messages constantly updating the pedal? If this is the case, can anyone suggest how I might alter the code to keep the clock messages rock solid?

#include <MIDI.h>

byte midi_clock = 0xf8;

MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);

void setup() {
  MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop() {

  if (MIDI.read()) {               // Is there a MIDI message incoming ?
  byte type = MIDI.getType();
    if (type == midi_clock) {
        usbMIDI.sendRealTime(usbMIDI.Clock);
    }
  }
}

If I run this code below I don't have any issues at all...

float bpm = 70; 
float delay_time = (60000000 / bpm) / 24; 


void setup() {
  delay(3000); 
  usbMIDI.sendRealTime(usbMIDI.Start);
}

void loop() {
  usbMIDI.sendRealTime(usbMIDI.Clock);
  delayMicroseconds(delay_time); 
}

Any ideas at all will be helpful thank you

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.