I use that API to read wav file at Java: Reading and Writing Wav Files in Java
I read a wav file with Java and want to put all the values into an arraylist. I wrote:
// Open the wav file specified as the first argument
WavFile wavFile = WavFile.openWavFile(fileToRemoveSilence);
List allBuffer = new ArrayList();
....
do {
// Read frames into buffer
framesRead = wavFile.readFrames(buffer, 50);
for (double aBuffer : buffer) {
allBuffer.add(aBuffer);
}
} while (framesRead != 0);
When I check the size of allBuffer at debugger it says:
74700
However at the code it whe I use:
wavFile.display();
the output of it:
....
... Frames: 74613
....
My allbuffer is bigger than frames as displayed by that API. How it comes?
PS: My previous questions about this:
PS2:
I fixed the bugs however when I run the program I get that error sometimes: What may be the problem?
java.lang.InterruptedException
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134)
at sun.java2d.Disposer.run(Disposer.java:127)
at java.lang.Thread.run(Thread.java:662)
Exception while removing reference: java.lang.InterruptedException
解决方案
you need to account for framesRead when copying from the buffer into your list. on the last call, you are copying more doubles than you actually read from the file. (i.e. exactly like the example code in your first link).