Thursday, June 08, 2006

Java FLAC FAQ

Q. Which of the many FLAC implementations for Java will you be using for the Xena Audio plugin?

A. Unfortunately there is only one project out there which combines Java and FLAC - JFLAC. It does a good job decoding FLAC files, however the FLAC encoding part is "to be implemented". The JFLAC website was last updated in July 2005 so I'm not holding my breath.


Q. Is this as annoying as it sounds?

A. Yes.


Q. So how will you be implementing FLAC encoding in Xena?

A. I see three options.
The first is the "Friday Afternoon" option, where I take the command-line FLAC encoder available from the FLAC website, and point the Xena audio plugin in its direction (this would be similar to our PST normalising process, which uses a program called readpst, for which we only have C code). We then sit back and wait for someone else to write an open-source Java FLAC encoder and stea-, er, share their code.
The second is the "1337 J@v@ |-|@x0r" option, where I assume that the FLAC C monkeys couldn't code to save themselves and implement a FLAC encoder from the specification.
The third is the "best of a bad bunch" option, where I write a Java FLAC encoder which is heavily based on the C version.
So option C it is. *Sigh*.

Q. So what's the Java FLAC encoder plan of attack?

A. The Java Sound Resources page has a number of examples for encoding, decoding and playing audio files, and contains code to convert various audio formats into a raw (PCM) form. And the standard Java API package javax.sound.sampled is based around a plugin architecture whereby new audio formats can be used as encoders and/or decoders. To do this all that is needed is to have some specifically-named text files in the META-INF/services directory of a jar file on the classpath, and java classes pointed to by these text files are automatically loaded as plugins.
What this means is that all that remains to be done is to write the bit that encodes a raw audio stream to FLAC (this will be a javax.sound encoding plugin) and any time we need to take care of a new audio format we will just need to write a javax.sound decoding plugin for it.
So there's nothing to it but to do it!

0 Comments:

Post a Comment

<< Home