Simultaneous MIDI and OSC over USB

Status
Not open for further replies.

recursinging

Well-known member
I have been trying to get USB MIDI and OSC over SLIP encoded serial to play nicely together using the standard https://github.com/CNMAT/OSC library with its included SLIPEncodedUSBSerial class.

There is a guard in place to prevent it from being compiled with any build flag other than USB_SERIAL - which it turns out is quite appropriate because it seems if this is removed, Either MIDI or OSC will work fine, but not both at the same time. Here is an little example program:

Code:
#include <Arduino.h>
#include <SLIPEncodedUSBSerial.h>
#include <OSCMessage.h>

SLIPEncodedUSBSerial SLIPSerial(Serial); 

void sendMIDIMessage() {
  usbMIDI.sendControlChange(10,10,10);
}

void sendOSCMessage() {
  OSCMessage msg("/foo"); 
  msg.add("bar"); 
  SLIPSerial.beginPacket();
  msg.send(SLIPSerial);
  SLIPSerial.endPacket();
  msg.empty();
}

void setup() {
    SLIPSerial.begin(115200);
}

void loop() {
    sendMIDIMessage();
    sendOSCMessage();
}

When the CMNAT OSC lib is modified to compile with the USB_MIDI_SERIAL build flag, my Teensy 3.6 will successfully inundate the connected PC with either OSC or MIDI messages as fast as they can be generated, given one of the two send* methods is removed. Both methods invoked together as with the example cause the Teensy to freeze after a small number of messages from both protocols. Leading me to believe there is some shared buffer being exhausted here.

Perhaps someone with better insight into the inner working of the USB serial and MIDI interfaces could shed a little light on this, Perhaps there is a way to work around it? I'd like to transport both protocols over the USB cable if possible.
 
Leading me to believe there is some shared buffer being exhausted here.

Could be the USB buffer pool, though I don't see why either wouldn't just wait a brief moment until another buffer becomes available.

Usually these sorts of lockups only happen is the PC is sending data which your code doesn't read. That's been a problem for many MIDI controllers, where things work fine until used with a setup where the PC echos MIDI messages. In all the USB MIDI examples, we recommend always reading and ignoring any incoming MIDI messages on every loop(). Is there any chance the test you're doing with both may also be sending a lot of data from the PC to the Teensy?

If you want to experiment with more buffers, edit usb_desc.h. 32 is the maximum supported.
 
Status
Not open for further replies.
Back
Top