diff --git a/README.md b/README.md index 0ae932d..9e0bcf5 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,10 @@ This application sends out a MIDI message as quickly as possible when a MIDI mes ![MIDI round trip latency](misc/round_trip.webp "Round_trip latency measurement") +The roundtrip time for a midi message send over BTLE is much worse: with an ESP32 I measured an average of 43 +- 6 milliseconds with the worst rountrip time around 60 ms. There is also a BT LE MIDI + + + ## Browser to OSC example One of the ways to send OSC messages from a browser to a local network is by using the MIDI out capability of browsers and - using `mot` - translating MIDI to OSC an example can be seen below. diff --git a/misc/midi_roundtrip_latency_blemidi_esp32/midi_roundtrip_latency_blemidi_esp32.ino b/misc/midi_roundtrip_latency_blemidi_esp32/midi_roundtrip_latency_blemidi_esp32.ino new file mode 100644 index 0000000..8163060 --- /dev/null +++ b/misc/midi_roundtrip_latency_blemidi_esp32/midi_roundtrip_latency_blemidi_esp32.ino @@ -0,0 +1,51 @@ +#define LED 2 +#include + +hw_timer_t *timer = NULL; + +boolean sendMidi = false; + +unsigned long midiMessagSendTime = 0; + +void ARDUINO_ISR_ATTR onTimer(){ + // Increment the counter and set the time of ISR + sendMidi = true; + digitalWrite(LED, !digitalRead(LED)); +} + +void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity, uint16_t timestamp){ + unsigned long midiMessageReceiveTime = micros(); + unsigned long roundtripMidiMessageTime = midiMessageReceiveTime - midiMessagSendTime; + Serial.printf("Received note on : round trip time %d microsecond\n", roundtripMidiMessageTime); +} + +void setup() { + pinMode(LED, OUTPUT); + + //set timer callback function + timer = timerBegin(1000000); + // Attach onTimer function to our timer. + timerAttachInterrupt(timer, &onTimer); + // Set alarm to call onTimer function every second (value in microseconds). + // Repeat the alarm (third parameter) with unlimited count = 0 (fourth parameter). + timerAlarm(timer, 1000000, true, 0); + + Serial.begin(115200); + Serial.println("Initializing bluetooth"); + + BLEMidiServer.begin("MIDI_Roundtrip"); + BLEMidiServer.setNoteOnCallback(onNoteOn); + while( ! BLEMidiServer.isConnected() ){ + Serial.println("Waiting for BLE MIDI connection..."); + delay(1000); + } +} + +void loop() { + if(sendMidi){ + sendMidi = false; + midiMessagSendTime = micros(); + BLEMidiServer.noteOn(0, 69, 127); + Serial.println("Midi Message send"); + } +} \ No newline at end of file