tags:

views:

93

answers:

1

Hi,

I'm working with java, trying to use the AudioFormat Class. I have the following piece of code:

AudioFormat Baseformat = input.getFormat(); 

AudioFormat Finalformat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
Baseformat.getSampleRate(),
16, Baseformat.getChannels(), Baseformat.getChannels()*2,
Baseformat.getSampleRate(),false);

AudioInputStream stream1 = AudioSystem.getAudioInputStream(
Finalformat, input);

numBytesRead = stream1.read(audioBytes)

Where audioBytes is an array where the data bytes are stored. I need to know how those bytes are organized. In Finalformat I'm specifying PCM enconding, stereo and 16 bits per sample. That means that for a given time instant there are 2 samples (1 for each channel) and each sample has 2 bytes. How are these bytes arranged?

If audioBytes = AABBCCDD, which bytes belong to each channel and what is the byte order of each sample? An example of the explanation I'm looking for is: AA BB is the left channel; AA is the low order byte.

Thanks to everyone who reads this.

+1  A: 

The last false in your AudioFormat constructor indicates little endian byte order (true would be big endian). With your code and the AA BB example, AA would be the low order byte. If you pass true to the constructor, BB would have been the low order byte.

jarnbjo
So AABB is channel 1 and CCDD channel2, right? Thanks!
dedalo
Yes, that's right.
jarnbjo