Your outer for
loop does not read from the audio input stream on the first pass through the loop
for (int n = 0; n != -1; n = audioInputStream.read(buffer, 0,
buffer.length)) {
is equivalent to:
int n = 0;
while (n != -1) {
// Inner loop
n = audioInputStream.read(buffer, 0, buffer.length);
}
so on the first loop the buffer is just the zero initialized array from new byte[16]
.
You should not assume the read fills the whole buffer, use the value returned by the read.