private static byte[] convertAudioEndianness(byte[] audioData,boolean twoByteSamples){
  ByteBuffer out=ByteBuffer.allocate(audioData.length);
  out.order(ByteOrder.nativeOrder());
  ByteBuffer in=ByteBuffer.wrap(audioData);
  in.order(ByteOrder.LITTLE_ENDIAN);
  if (twoByteSamples) {
    ShortBuffer outShort=out.asShortBuffer();
    ShortBuffer inShort=in.asShortBuffer();
    while (inShort.hasRemaining()) {
      outShort.put(inShort.get());
    }
  }
 else {
    while (in.hasRemaining()) {
      out.put(in.get());
    }
  }
  out.rewind();
  if (!out.hasArray()) {
    byte[] array=new byte[out.capacity()];
    out.get(array);
    out.clear();
    return array;
  }
  return out.array();
}

private static byte [ ] convertAudioEndianness ( byte [ ] audioData , boolean twoByteSamples ) { ByteBuffer out = ByteBuffer . allocate ( audioData . length ) ; out . order ( ByteOrder . nativeOrder ( ) ) ; ByteBuffer in = ByteBuffer . wrap ( audioData ) ; in . order ( ByteOrder . LITTLE_ENDIAN ) ; if ( twoByteSamples ) { ShortBuffer outShort = out . asShortBuffer ( ) ; ShortBuffer inShort = in . asShortBuffer ( ) ; while ( inShort . hasRemaining ( ) ) { outShort . put ( inShort . get ( ) ) ; } } else { while ( in . hasRemaining ( ) ) { out . put ( in . get ( ) ) ; } } out . rewind ( ) ; if ( ! out . hasArray ( ) ) { byte [ ] array = new byte [ out . capacity ( ) ] ; out . get ( array ) ; out . clear ( ) ; return array ; } return out . array ( ) ; }
converts the endianness of an audiobuffer to the format required by the jre .
