Skip to content

Commit

Permalink
BLE Midi roundtrip latency info
Browse files Browse the repository at this point in the history
  • Loading branch information
JorenSix committed Oct 23, 2024
1 parent 23015c5 commit 5d1938b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#define LED 2
#include <BLEMidi.h>

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");
}
}

0 comments on commit 5d1938b

Please sign in to comment.