I have the following code snippet:
File file = new File(sourceFile);
AudioInputStream in = AudioSystem.getAudioInputStream(file);
AudioInputStream din = null;
AudioFormat baseFormat = in.getFormat();
AudioFormat decodedFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(),
16, baseFormat.getChannels(), baseFormat.getChannels() * 2,
baseFormat.getSampleRate(), false);
din = AudioSystem.getAudioInputStream(decodedFormat, in);
AudioSystem.write(din, AudioFileFormat.Type.WAVE, new File(targetFile));
I wrote this code to transfrom MP3 and OGG files to WAV files. These formats are not supported by java by default as I understand, so I had to add different jars to my classpath as described here:
http://www.javazoom.net/mp3spi/documents.html
http://www.javazoom.net/vorbisspi/documents.html
The code runs fine when I'm converting MP3 files. But when I try to convert OGG files I get the following error:
java.lang.IllegalArgumentException: Unsupported conversion: PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian from VORBISENC 44100.0 Hz, unknown bits per sample, stereo, 1 bytes/frame, 16000.0 frames/second
Now this is thrown only when getting the decoded inputstream itself, which means that the ogg file was parsed successfuly.
AudioSystem.getTargetEncodings(sourceFormat)
The code above will not return any values, when processing neither MP3 or OGG files. The only difference is that MP3 works fine.
I added all jars referenced by the previous link needed for the ogg conversion except the latest version of the jogg-0.0.7.jar because I could not find it.
I tried different solutions like JAVE but I need it run on MAC as well, and JAVE will not run on MAC without some special implementation.
Does anyone have any suggestion what may cause the problem? May there be any workaround to convert OGG file to WAV?
EDIT:
Ow wow I realized what the problem is... After reading everthing on the manual, I learned that using two different kind of SPIs (like in this case MP3 and OGG) can cause problems. I removed the MP3 spi maven dependency and the error disappeared. Thought the result wav is basically empty. Any suggestions on that? I will be happy if I can get OGG to WAV transformation to work, I can transform MP3 in another way.
My pom dependency looks like this:
<dependency>
<groupId>com.googlecode.soundlibs</groupId>
<artifactId>vorbisspi</artifactId>
<version>1.0.3-1</version>
</dependency>
This downloads I guess all jars I need to make OGG transformation work. (Looks like not.)