Hi everyone ,

I hope somebody might be able to shine some light on this. I contacted XXXXXX XXXXX (A Java Sound API Guy that knows his stuff) about this a few weeks ago, and though he suggested I wasn't using the API correctly, I was making some progress....

So let me quickly explain..
Firstly, I was using the JFlac decoder "org.kc7bfi.jflac.apps.Decoder" application for my project but I was getting an intermittent glitch with it, where it would just hang and not complete decoding. I found one WAV file that always decoded successfully, and I used this as the first file given for the decoder to work on and this would to "jump start" the decoder. If any one knows why this is Let me know and I'll revert back to using the Decoder instead....

Instead I tried to write my own code, which with the right SPI .jar and when tweaked for a given Audio Encoding such as .ogg or .mp3 will work

In the code below I should just be asking the Java Sound API "AudioSystem" class to get the AudioInputStream in both cases where I directly use JFLAC classes, however this doesn't recognize the "FLAC" file format, even though Netbeans imports the JFlac library fine it throws



public static File convertFlacToWav(File flacFile) {

String fileString = flacFile.getAbsolutePath().toString();
File wavfile = new File(fileString.substring(0, fileString.lastIndexOf(".")) + ".wav");

try {

AudioInputStream flacAIS = new FlacAudioFileReader().getAudioInputStream(flacFile );

AudioFormat audioFormat = new AudioFormat(
flacAIS.getFormat().getChannels() * 2,

AudioInputStream audioInputStream = new FlacFormatConversionProvider().getAudioInputStream (audioFormat, flacAIS);
AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE, wavfile);
} catch (Exception e) {
return wavfile;

And the Error Trace using the code above throws up the following error with ANY .flac file:

at org.kc7bfi.jflac.io.BitInputStream.readFromStream( BitInputStream.java:106)
at org.kc7bfi.jflac.io.BitInputStream.readByteBlockAl ignedNoCRC(BitInputStream.java:389)
at org.kc7bfi.jflac.metadata.Unknown.<init>(Unknown.j ava:45)
at org.kc7bfi.jflac.FLACDecoder.readNextMetadata(FLAC Decoder.java:609)
at org.kc7bfi.jflac.FLACDecoder.readMetadata(FLACDeco der.java:232)
at org.kc7bfi.jflac.sound.spi.Flac2PcmAudioInputStrea m.initDecoder(Flac2PcmAudioInputStream.java:107)
at org.kc7bfi.jflac.sound.spi.Flac2PcmAudioInputStrea m.fill(Flac2PcmAudioInputStream.java:86)
at org.kc7bfi.jflac.sound.spi.RingedAudioInputStream. read(RingedAudioInputStream.java:339)
at java.io.SequenceInputStream.read(SequenceInputStre am.java:191)
at java.io.SequenceInputStream.read(SequenceInputStre am.java:194)
at java.io.InputStream.read(InputStream.java:82)
at com.sun.media.sound.WaveFileWriter.writeWaveFile(W aveFileWriter.java:234)
at com.sun.media.sound.WaveFileWriter.write(WaveFileW riter.java:130)
at javax.sound.sampled.AudioSystem.write(AudioSystem. java:1337)
at AudioUploadServer.KEncoder.convertFlacToWav(KEncod er.java:73)
at AudioUploadServer.KEncoder.main(KEncoder.java:29)

(NOTE: I'm using the javaFlacEncoder.FLAC_FileEncoder to encode the .wav file initially which is then decoded at a later point)

Any Ideas where, or what I'm doing wrong?

Much appreciated............