I am trying to create an X-Y Oscilloscope in Java and I have gotten stuck. I have read through all the documentation for jFlac, the library i am using to decode my .flac audio file and the free lossless audio codec documentation here. I cannot seem to find the answer to the problem i am having. Please consider the following.
public void processPCM(ByteData pcm) {
byte[] temp = pcm.getData();
line.write(temp, 0, pcm.getLen());
leftAndRight = new int[pcm.getData().length];
for(int i = 0; i < temp.length; i+=2){
leftAndRight[i/2] = (temp[i + 1]<<8) + (temp[i] & 0xff);
}
}
This is where the sample data from my file is put into the SourceDataLine and is played. After i write the data to the line, i wish to convert the left and right audio into separate integer array variables x[] and y[], respectively.
This is the StreamInfo for the file i am using:
PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian
from the code above, pcm.getLen() returns a value of 16384 and pcm.getData() returns a byte array of length 90112. It's the data in this byte array, if I'm not mistaken, that i need to separate the left and right channels from, and then convert into integer arrays. This is the part that I do not understand how to accomplish.
Edit: I changed the above code to something i came across that i think might be how to get the byte array into an integer array, but i am still clueless to how the left and right channels are arranged.