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";
|
assert false : "Only mono or stereo is supported";
|
||||||
}
|
}
|
||||||
|
|
||||||
//read data into buffer
|
ByteBuffer buffer;
|
||||||
ByteBuffer buffer = null;
|
|
||||||
try {
|
try {
|
||||||
int available = ais.available();
|
buffer = convertAudioBytes(ais.readAllBytes(),
|
||||||
if(available <= 0) {
|
audioformat.getSampleSizeInBits() == 16,
|
||||||
available = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
|
audioformat.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN);
|
||||||
}
|
|
||||||
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);
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//create our result
|
//create our result
|
||||||
WaveData wavedata =
|
WaveData wavedata = new WaveData(buffer, channels, (int)audioformat.getSampleRate());
|
||||||
new WaveData(buffer, channels, (int) audioformat.getSampleRate());
|
|
||||||
|
|
||||||
//close stream
|
//close stream
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user