Vorbis Support - All-in-One OGG Vorbis Decoder in Java

What is Vorbis Support?

Ogg/Vorbis is a free audio format featuring high compression ratios. It is widely used and there are libraries who enable support for Ogg in Java. JOrbis by JCraft is a pure Java Ogg/Vorbis decoder and Ogg Vorbis SPI by JavaZoom registers JOrbis as a service for the Java Sound API. The later also relies partly on the Tritonus library (shared plugin). They are however inactive now for several years. The reference implementation for Ogg/Vorbis is libvorbis in C.

Vorbis Support is the all-in-one combination of JOrbis, JavaSPI and Tritonus-Share.

Alternatives are Paul's SoundSystem (full support of Java Sound, JOAL, LWJGL gaming libraries, wrappers around JOrbis, J-OGG), Vorbis-Java (Java encoder and decoder at xiph.org), EasyOgg (wrapper around JOrbis) and J-OGG (independent ogg/vorbis decode). Except the first they have stopped development for years now.

Why Vorbis Support?

The three libraries are almost always bundled together. Together they constitute a complete plattform independent Ogg/Vorbis support for the Java Sound API. Fortunately they share the same open source license. Combining them together makes distribution and handling easier, can reduce the size of the download and makes testing and debugging easier. Also increasing the efficiency by optimizing the code is easier.

However since these libraries already exist, this project does not need to take care of backwards compatibility, since there is always the fallback to the original libraries. Therefore to ease maintenance and use newer features of the Java language, the required version of Java is 7 or later.

Download

Latest version: 1.0 (27th January 2013) - Bundling of the libraries, cleanup of the code and testing

License: LGPLv3+

Requirement: Java 7 or later

Download library: vorbis-support-1.0.jar (110 kB only)

Download sources: vorbis-support-1.0-sources.zip

Example

This library used the Services Provider Interface to enable Ogg/Vorbis playback under the hood without changing any of the code on the client's library side. Just put this library in the classpath and access your sound resources (SourceDataLine or Clip) as you would without Ogg/Vorbis support. See the Java Tutorial on Playing Back Audio for more information. And here is also an example that would play an entire ogg file.

try { AudioInputStream in = AudioSystem.getAudioInputStream(new File("xyz.ogg"); if (in != null) { AudioFormat baseFormat = in.getFormat(); AudioFormat targetFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16, baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false); AudioInputStream dataIn = AudioSystem.getAudioInputStream(targetFormat, in); byte[] buffer = new byte[4096]; // get a line from a mixer in the system with the wanted format DataLine.Info info = new DataLine.Info(SourceDataLine.class, targetFormat); SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info); if (line != null) { line.open(); line.start(); int nBytesRead = 0, nBytesWritten = 0; while (nBytesRead != -1) { nBytesRead = dataIn.read(buffer, 0, buffer.length); if (nBytesRead != -1) { nBytesWritten = line.write(buffer, 0, nBytesRead); } } line.drain(); line.stop(); line.close(); dataIn.close(); } in.close(); // playback finished } } catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) { // failed }

Support

Contact the author (just use the contact form) or post in the support thread (guests can post, but you can also register, the forum is part of a game remake where vorbis support is a side project).

Bug reports as well as enhancement request or just any kind of feedback - all is welcome.