Merge pull request #47 from sashok7241/patch-1

Fix BigEndian issue when reading files with WaveData.java, full credit to sashok7241 for patch.
This commit is contained in:
kappaOne 2013-09-03 03:02:23 -07:00
commit 248274bace
1 changed files with 3 additions and 3 deletions

View File

@ -218,7 +218,7 @@ public class WaveData {
&& total < buf.length) {
total += read;
}
buffer = convertAudioBytes(buf, audioformat.getSampleSizeInBits() == 16);
buffer = convertAudioBytes(buf, audioformat.getSampleSizeInBits() == 16, audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
} catch (IOException ioe) {
return null;
}
@ -237,11 +237,11 @@ public class WaveData {
return wavedata;
}
private static ByteBuffer convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data) {
private static ByteBuffer convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data, ByteOrder order) {
ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
dest.order(ByteOrder.nativeOrder());
ByteBuffer src = ByteBuffer.wrap(audio_bytes);
src.order(ByteOrder.LITTLE_ENDIAN);
src.order(order);
if (two_bytes_data) {
ShortBuffer dest_short = dest.asShortBuffer();
ShortBuffer src_short = src.asShortBuffer();