开发者

Java Class AudioFormat: Byte ordering

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.g开发者_运维问答etAudioInputStream(
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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜