10

I am reading a wav file through AudioInputStream into a byte array,

    AudioInputStream audiofile = AudioSystem.getAudioInputStream(f);
    byte[] audio=new byte[numberofframes*framesize];
    int bytes=audiofile.read(audio);

do I need to arrange the bytes of a sample considering that the data is arranged in little endian or does the AudioInputStream do it for me?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433

1 Answers1

1

Big- versus little-endian matters if the data is encoded in more than a single byte, e.g., bit depths of 16 or more, regardless of the number of channels. Java does not automatically arrange the PCM bytes in a default order, it just accepts them.

The following is the clearest, best written single section of the java audio tutorials, imho, and covers issues pertaining to formats and their conversions:

http://docs.oracle.com/javase/tutorial/sound/converters.html

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41
  • SO you say the byte array will have Formatted Audio Data i.e. in Little Endian which I'll have to convert by my self to read the samples? – Romantic Electron Jan 03 '13 at 04:47
  • Output lines can either be Big- or Little-Endian, yes? If you input the opposite type, then I'm 90% sure you will have to do a swap of the bytes before outputting. But there likely will be a converter for this, so you don't necessarily have to get your hands dirty at the byte level. Did you look at the link I sent? I'm not sure how appropriate the term "Formatted Audio Data" is for PCM data. If the encoding is 16-bit or more, the bytes have to be in one order or the other, regardless. I don't think the AudioInputStream "cares," it just brings in raw bytes of PCM. – Phil Freihofner Jan 03 '13 at 18:58