java vorbis support

Vorbis SPI support. Combination of JOrbis, JavaSPI and Tritonus-Share.

License

License

GNU LIBRARY GENERAL PUBLIC LICENSE, Version 3.0
Categories

Categories

Java Languages
GroupId

GroupId

com.github.trilarion
ArtifactId

ArtifactId

java-vorbis-support
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

java vorbis support
Vorbis SPI support. Combination of JOrbis, JavaSPI and Tritonus-Share.
Project URL

Project URL

https://github.com/Trilarion/java-vorbis-support
Source Code Management

Source Code Management

https://github.com/Trilarion/java-vorbis-support

Download java-vorbis-support

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.trilarion/java-vorbis-support/ -->
<dependency>
    <groupId>com.github.trilarion</groupId>
    <artifactId>java-vorbis-support</artifactId>
    <version>1.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.trilarion/java-vorbis-support/
implementation 'com.github.trilarion:java-vorbis-support:1.2.1'
// https://jarcasting.com/artifacts/com.github.trilarion/java-vorbis-support/
implementation ("com.github.trilarion:java-vorbis-support:1.2.1")
'com.github.trilarion:java-vorbis-support:jar:1.2.1'
<dependency org="com.github.trilarion" name="java-vorbis-support" rev="1.2.1">
  <artifact name="java-vorbis-support" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.trilarion', module='java-vorbis-support', version='1.2.1')
)
libraryDependencies += "com.github.trilarion" % "java-vorbis-support" % "1.2.1"
[com.github.trilarion/java-vorbis-support "1.2.1"]

Dependencies

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

java-vorbis-support

Combination and continuation of JOrbis, JavaSPI and Tritonus-Share to provide Ogg/Vorbis playback capabilities for Java using the Sound SPI.

Download, License, Feedback

On Maven Central:

Introduction

Ogg/Vorbis is a widely used free audio format featuring high compression ratios and there are libraries who enable support for Ogg in Java. Among them are JOrbis by JCraft - a pure Java Ogg/Vorbis decoder and Ogg Vorbis SPI by JavaZoom which registers JOrbis as a service for the Java Sound API. The later also relies partly on the Tritonus share library. All three projects are inactive for several years now.

The reference implementation for Ogg/Vorbis is libvorbis written in C.

Vorbis support is the all-in-one combination and possibly continuation 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). These projects are mostly inactive for years now.

Why this project?

All three libraries, Jorbis, Vorbis SPI and Tritonus Share 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 (LGPL). Combining them together makes distribution and handling easier, can reduce the size of the download and makes testing and debugging easier. Last but not least, increasing the efficiency by optimizing the code will be a bit easier.

However since these libraries already exist, we do not need to take care of backwards compatibility, since there is always the fallback to the original libraries. Therefore to be able to use newer features of the Java language, the required Java version currently is 7 or later.

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
}

Run an example with

./gradlew run :examples:run

Alternatives

VorbisJava by Gagravarr.

Versions

Version
1.2.1
1.2.0