USB MIDI: Fix incorrect timestamps
Timestamp is calculated before waiting for USB data. When USB data comes in, the timestamp from when it starts to wait is used. This makes the timestamp very inaccurate. The fix is to move "timestamp = System.nanoTime()" after getting the USB response. Bug: 267519645 Test: Connect phone with MIDI Scope app to USB MIDI 2.0 keyboard Test: Play notes on the keyboard and verify timestamps look reasonable Change-Id: Ic3bccd89b65787badf3139964983572f83d99eaa
This commit is contained in:
@@ -379,8 +379,6 @@ public final class UsbDirectMidiDevice implements Closeable {
|
||||
Log.w(TAG, "input thread interrupted");
|
||||
break;
|
||||
}
|
||||
// Record time of event immediately after waking.
|
||||
long timestamp = System.nanoTime();
|
||||
final ByteBuffer byteBuffer = ByteBuffer.wrap(inputBuffer);
|
||||
if (!request.queue(byteBuffer)) {
|
||||
Log.w(TAG, "Cannot queue request");
|
||||
@@ -396,6 +394,9 @@ public final class UsbDirectMidiDevice implements Closeable {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Record time of event after receiving response.
|
||||
long timestamp = System.nanoTime();
|
||||
|
||||
int bytesRead = byteBuffer.position();
|
||||
|
||||
if (bytesRead > 0) {
|
||||
|
||||
Reference in New Issue
Block a user