Is there a Java library for taking a raw audio stream and saving it as a .OGG file with a decent compression ratio?

In particular, I'm using the Java Beads Project, open open-source tool for sound synthesis. It has a built-in tool for writing its audio to WAV files, but not to any other format. I would like to create my own class to write to a OGG file so that I have an option for compressing my generated audio.

The interface I have for saving an audio file provided by Beads is the AuddioFileWriter interface, which looks like this:

public interface AudioFileWriter {

     * Single method to write an entire audio file in one go.
     * @param data - the data to be written
     * @param filename - the name of the file to be written
     * @param type - the type of audio file to be written (mp3, wav, etc.)
     * @param saf - a SampleAudioFormat object specifying the attributes of the sample data to be written. Can be NULL, in which case default values will be used.
    public void writeAudioFile(float[][] data, String filename, AudioFileType type, SampleAudioFormat saf) throws IOException, OperationUnsupportedException, FileFormatException;

    // snip    

So I have the raw audio in a float[][]. Each sub-array of the data is one channel, and each array contains an amplitude level for each frame of audio. So I need to save the audio represented by the float[][] to OGG and save that. If I need to, I'm willing to do some simple bit-twiddling to get the float[][] into a different format that an OGG library expects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.