How to read/write high-resolution (24-bit, 8 channel) .wav files in Java?
Posted
by
dB'
on Stack Overflow
See other posts from Stack Overflow
or by dB'
Published on 2011-06-23T17:45:59Z
Indexed on
2012/09/19
21:38 UTC
Read the original article
Hit count: 339
I'm trying to write a Java application that manipulates high resolution .wav files. I'm having trouble importing the audio data, i.e. converting the .wav file into an array of doubles.
When I use a standard approach an exception is thrown.
AudioFileFormat as = AudioSystem.getAudioFileFormat(new File("orig.wav"));
-->
javax.sound.sampled.UnsupportedAudioFileException: file is not a supported file type
Here's the file format info according to soxi:
dB$ soxi orig.wav
soxi WARN wav: wave header missing FmtExt chunk
Input File : 'orig.wav'
Channels : 8
Sample Rate : 96000
Precision : 24-bit
Duration : 00:00:03.16 = 303526 samples ~ 237.13 CDDA sectors
File Size : 9.71M
Bit Rate : 24.6M
Sample Encoding: 32-bit Floating Point PCM
Can anyone suggest the simplest method for getting this audio into Java?
I've tried using a few techniques. As stated above, I've experimented with the Java AudioSystem (on both Mac and Windows). I've also tried using Andrew Greensted's WavFile class, but this also fails (WavFileException: Compression Code 3 not supported). One workaround is to convert the audio to 16 bits using sox (with the -b 16 flag), but this is suboptimal since it increases the noise floor.
Incidentally, I've noticed that the file CAN be read by libsndfile. Is my best bet to write a jni wrapper around libsndfile, or can you suggest something quicker?
Note that I don't need to play the audio, I just need to analyze it, manipulate it, and then write it out to a new .wav file.
* UPDATE *
I solved this problem by modifying Andrew Greensted's WavFile class. His original version only read files encoded as integer values ("format code 1"); my files were encoded as floats ("format code 3"), and that's what was causing the problem.
I'll post the modified version of Greensted's code when I get a chance. In the meantime, if anyone wants it, send me a message.
© Stack Overflow or respective owner