Use modern API to read all the bytes rather than buggily hand-rolling it.
This commit is contained in:
@@ -205,28 +205,18 @@ public class WaveData {
|
||||
assert false : "Only mono or stereo is supported";
|
||||
}
|
||||
|
||||
//read data into buffer
|
||||
ByteBuffer buffer = null;
|
||||
ByteBuffer buffer;
|
||||
try {
|
||||
int available = ais.available();
|
||||
if(available <= 0) {
|
||||
available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
|
||||
}
|
||||
byte[] buf = new byte[available];
|
||||
int read = 0, total = 0;
|
||||
while ((read = ais.read(buf, total, buf.length - total)) != -1
|
||||
&& total < buf.length) {
|
||||
total += read;
|
||||
}
|
||||
buffer = convertAudioBytes(buf, audioformat.getSampleSizeInBits() == 16, audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
buffer = convertAudioBytes(ais.readAllBytes(),
|
||||
audioformat.getSampleSizeInBits() == 16,
|
||||
audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||
} catch (IOException ioe) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//create our result
|
||||
WaveData wavedata =
|
||||
new WaveData(buffer, channels, (int) audioformat.getSampleRate());
|
||||
WaveData wavedata = new WaveData(buffer, channels, (int)audioformat.getSampleRate());
|
||||
|
||||
//close stream
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user