Skip to content

Commit 5d1938b

Browse files
committed
BLE Midi roundtrip latency info
1 parent 23015c5 commit 5d1938b

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ This application sends out a MIDI message as quickly as possible when a MIDI mes
117117
![MIDI round trip latency](misc/round_trip.webp "Round_trip latency measurement")
118118

119119

120+
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
121+
122+
123+
120124
## Browser to OSC example
121125

122126
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#define LED 2
2+
#include <BLEMidi.h>
3+
4+
hw_timer_t *timer = NULL;
5+
6+
boolean sendMidi = false;
7+
8+
unsigned long midiMessagSendTime = 0;
9+
10+
void ARDUINO_ISR_ATTR onTimer(){
11+
// Increment the counter and set the time of ISR
12+
sendMidi = true;
13+
digitalWrite(LED, !digitalRead(LED));
14+
}
15+
16+
void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity, uint16_t timestamp){
17+
unsigned long midiMessageReceiveTime = micros();
18+
unsigned long roundtripMidiMessageTime = midiMessageReceiveTime - midiMessagSendTime;
19+
Serial.printf("Received note on : round trip time %d microsecond\n", roundtripMidiMessageTime);
20+
}
21+
22+
void setup() {
23+
pinMode(LED, OUTPUT);
24+
25+
//set timer callback function
26+
timer = timerBegin(1000000);
27+
// Attach onTimer function to our timer.
28+
timerAttachInterrupt(timer, &onTimer);
29+
// Set alarm to call onTimer function every second (value in microseconds).
30+
// Repeat the alarm (third parameter) with unlimited count = 0 (fourth parameter).
31+
timerAlarm(timer, 1000000, true, 0);
32+
33+
Serial.begin(115200);
34+
Serial.println("Initializing bluetooth");
35+
36+
BLEMidiServer.begin("MIDI_Roundtrip");
37+
BLEMidiServer.setNoteOnCallback(onNoteOn);
38+
while( ! BLEMidiServer.isConnected() ){
39+
Serial.println("Waiting for BLE MIDI connection...");
40+
delay(1000);
41+
}
42+
}
43+
44+
void loop() {
45+
if(sendMidi){
46+
sendMidi = false;
47+
midiMessagSendTime = micros();
48+
BLEMidiServer.noteOn(0, 69, 127);
49+
Serial.println("Midi Message send");
50+
}
51+
}

0 commit comments

Comments
 (0)