Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94ec584b authored by Phil Burk's avatar Phil Burk
Browse files

bluetoothmidiservice: fix timestamp for BLE-MIDI transmitted packets



Transmitted packets that contained multiple MIDI messages and that did not
use running status were missing a timestamp! This CL fixes that bug.

Bug: 34708799
Test: a manual test using MidiMatrix is described in the bug report
Change-Id: Iddb55e01c60625787c5907fe8e4b202ef1415e59
Signed-off-by: default avatarPhil Burk <philburk@google.com>
parent dcdaaec8
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -60,6 +60,8 @@ public class BluetoothPacketEncoder extends PacketEncoder {
                int milliTimestamp = (int)(timestamp / MILLISECOND_NANOS) & MILLISECOND_MASK;
                int milliTimestamp = (int)(timestamp / MILLISECOND_NANOS) & MILLISECOND_MASK;
                byte status = msg[offset];
                byte status = msg[offset];
                boolean isSysExStart = (status == MidiConstants.STATUS_SYSTEM_EXCLUSIVE);
                boolean isSysExStart = (status == MidiConstants.STATUS_SYSTEM_EXCLUSIVE);
                // Because of the MidiFramer, if it is not a status byte then it
                // must be a continuation.
                boolean isSysExContinuation = ((status & 0x80) == 0);
                boolean isSysExContinuation = ((status & 0x80) == 0);


                int bytesNeeded;
                int bytesNeeded;
@@ -70,7 +72,9 @@ public class BluetoothPacketEncoder extends PacketEncoder {
                    bytesNeeded = count;
                    bytesNeeded = count;
                }
                }


                boolean needsTimestamp = (milliTimestamp != mPacketTimestamp);
                // Status bytes must be preceded by a timestamp
                boolean needsTimestamp = (status != mRunningStatus)
                        || (milliTimestamp != mPacketTimestamp);
                if (isSysExStart) {
                if (isSysExStart) {
                    // SysEx start byte must be preceded by a timestamp
                    // SysEx start byte must be preceded by a timestamp
                    needsTimestamp = true;
                    needsTimestamp = true;
@@ -78,6 +82,7 @@ public class BluetoothPacketEncoder extends PacketEncoder {
                    // SysEx continuation packets must not have timestamp byte
                    // SysEx continuation packets must not have timestamp byte
                    needsTimestamp = false;
                    needsTimestamp = false;
                }
                }

                if (needsTimestamp) bytesNeeded++;  // add one for timestamp byte
                if (needsTimestamp) bytesNeeded++;  // add one for timestamp byte
                if (status == mRunningStatus) bytesNeeded--;    // subtract one for status byte
                if (status == mRunningStatus) bytesNeeded--;    // subtract one for status byte