I am transferring a small (<10 classes) C ++ project in Java. The project manages audio files, and in C ++ it does this with libsndfile . The code includes things like:
const int channels = audioFileInfo.channels; ... sf_readf_double( audioFile, inputBuffer, MAX_ECHO ); ... sf_writef_double( outputAudioFile, ¤tAudioBuffer[WINDOW_SIZE * channels], SEGMENTATION_LENGTH );
In Java, what's the best way to manipulate audio files at a low level? I'm talking about things like normalization, adding echoes, etc.
Progress Report
After a little digging, I found javax.sound.sampled that looks like it can do the job.
Edit 2 Upon closer inspection, it will not work (or at least not available) since it relies on the com.sun.sound package.
Edit 3 With even more testing and experimentation, the com.sun.sound and sun.misc released under the GNU GPLv2, and I loaded them into my project. Renaming javax.sound.sampled to imp.javax.sound.sampled , the project compiles, and I can create AudioFileFormat objects without exception. I had no chance to play a lot, but I will keep you posted.
Edit 4 Ok, some things work with javax.sound.sampled, others don't. For example, calls such as:
AudioInputStream stream = AudioSystem.getAudioInputStream(waveFile));
doesn't work, however I can get around this by doing:
WaveFileReader wfr = new WaveFileReader(); AudioInputStream stream = wfr.getAudioInputStream(waveFile);
In general, calls to things like AudioSystem.getAudioFileTypes() return empty lists. I can delve into the packages and see how it relates to providers, but I donβt understand how to fix it. Having received my stream object, it correctly reports its encoding, etc., which is encouraging.
My biggest problem right now is creating a Clip object. This must be created using the Line object, which usually comes from the AudioSystem. Can anyone think of this?