Skip to content
Advertisement

Read OGG as stream of samples for LWJGL 3 OpenAL

I’m making a game with LWJGL 3, and for the first time I’m learning about the OpenAL library. I’m going to have to include long audio files, and I have decided that OGG will be used for the audio, since music would otherwise take up a lot of space.

What I don’t know, though, is anything about how to get the audio data out of the OGG and put them into the OpenAL buffers, which need a ShortBuffer of signed short PCM samples.

I’ve already been trying to look for answers, but everything I find seems to be outdated or irrelevant to my case.

So to summarize: I have OGG files and I need to be able to load them to OpenAL buffers. Also the ability to stream from the files is obviously a must (in this case, read the files one chunk at a time into a double buffer), since music is involved.

Example:

JavaScript

Where the function readOggSamplesToBuffer would be something like this:

JavaScript

Advertisement

Answer

The STBVorbis class can read Ogg Vorbis files. For streaming you probably want to use

JavaScript
Advertisement