YuuichiAkagawa / USBH_MIDI

USB MIDI 1.0 class driver for Arduino USB Host Shield 2.0 Library
GNU General Public License v2.0
154 stars 32 forks source link

Note-off messages are being dropped. #43

Closed cdw2000 closed 5 years ago

cdw2000 commented 5 years ago

Based on Issue #9, this appears to be an old problem that was fixed, but I am having this problem using my M-Audio Oxygen 49 keyboard. Single notes are fine, but playing multiple notes simultaneously in a repetitive manner sometimes causes a note to be stuck on.

I'm using an Arduino Uno R3 with a USB Host Shield 2.0 along with the current Arduino IDE, MIDI library 4.3.1, USB Host Shield library 2.0, and your current USBH_MIDI release. I'm using your USB_MIDI_converter example sketch. Based on reading Issue #9 should I be using the USB_MIDI_converter_multi sketch instead?

YuuichiAkagawa commented 5 years ago

Please run "USBH_MIDI_dump" example.

cdw2000 commented 5 years ago

I will do that tonight (EST) and post the results.

cdw2000 commented 5 years ago

Here is my dump file. I basically played a C chord repeatedly. Since the USB MIDI Converter code uses the TXO on the Arduino for the MIDI out, I couldn't connect my MIDI sound device (Sparkfun WAV Trigger) to hear if any of the notes got stuck on. Hopefully I captured what you need. Oxygen 49 Dump.txt

YuuichiAkagawa commented 5 years ago

Please try to remove or reduce the delay time. https://github.com/YuuichiAkagawa/USBH_MIDI/blob/master/examples/USB_MIDI_converter/USB_MIDI_converter.ino#L76

  //delay(1ms)
  //doDelay(t1, (uint32_t)micros(), 1000);
  //or
  doDelay(t1, (uint32_t)micros(), 100);
cdw2000 commented 5 years ago

OK. I'll give that a try and will let you know the results.

cdw2000 commented 5 years ago

Changing the timing worked. Thanks for your help. I used 480 usec. Here's my rational: MIDI data rate is 31250 bits/sec. A 3 byte MIDI message (Note On/Off, Note No., Velocity) is 30 bits. 31250/30 is 1041.67 messages/second. Taking the reciprocal yields one message possible every 960 usec. Setting the sample interval at half that (480 usec) would ensure no messages lost.