From bda0caf07b786633381a029f782b9d2e1caa8a3f Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Tue, 18 Aug 2015 16:43:22 -0700 Subject: [PATCH] MIDI docs: fix buffer allocation Also describe NoteOn more clearly. Bug: 23303608 Change-Id: I35f88022c854c2eb16ec606e58f28e06c52d18b7 Signed-off-by: Phil Burk --- media/java/android/media/midi/package.html | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/media/java/android/media/midi/package.html b/media/java/android/media/midi/package.html index 7baa5bc42bd2c..45fb5791dfa79 100644 --- a/media/java/android/media/midi/package.html +++ b/media/java/android/media/midi/package.html @@ -202,11 +202,12 @@ MidiInputPort inputPort = device.openInputPort(index);

MIDI messages are sent as byte arrays. Here we encode a NoteOn message.

-byte[] buffer = new buffer[64];
+byte[] buffer = new byte[32];
 int numBytes = 0;
-buffer[numBytes++] = 0x90 + channel; // note on
-buffer[numBytes++] = pitch;
-buffer[numBytes++] = velocity;
+int channel = 3; // MIDI channels 1-16 are encoded as 0-15.
+buffer[numBytes++] = (byte)(0x90 + (channel - 1)); // note on
+buffer[numBytes++] = (byte)60; // pitch is middle C
+buffer[numBytes++] = (byte)127; // max velocity
 int offset = 0;
 // post is non-blocking
 inputPort.send(buffer, offset, numBytes);