OpenAL - 2 channel OGG sound

From my understanding when there is 1 channel we use the format AL_FORMAT_MONO16
when there are 2 we use AL_FORMAT_STEREO16.

Currently sounds with one channel work perfectly. However sounds with 2 channels throw no errors when uploaded and don’t play.

They do play in the AL_FORMAT_MONO16 format, but it’s all messed up.

Has anyone ran into this issue? There is not much info online about this.

I think it might be this bit of code: (changed it a bit)
It throws an error if I use rewind instead of flip. It had rewind in the original source. OpenAL errors aren’t very descriptive.
honestly it looks silly to me, or missing something. However this is what I found as an official LWJGL example

private static ByteBuffer convertAudioBytes(ByteBuffer samples, boolean stereo) {
        if (!stereo) {
            return samples;
        }
        ByteBuffer dest = BufferUtils.createByteBuffer(samples.capacity());
        ShortBuffer dest_short = dest.asShortBuffer();
        ShortBuffer src_short = samples.asShortBuffer();

        while (src_short.hasRemaining()) {
            dest_short.put(src_short.get());
        }
        dest.flip();

        return dest;
    }

openal uses pcm format, how are you converting ogg in to pcm? Are you doing all of channel1 then channel2 or are you interleaving them?

It’s interleaved into 1 bytebuffer using

stb_vorbis_get_samples_short_interleaved

This is how I do using STB_Vorbis, and it works fine for me.

OggReader.java ISoundReader

I think it would be better if you post what OpenAL error you are getting.

Why are you using that convertAudioBytes method? Is that from LWJGL 2?

OpenAL can play interleaved-stereo short samples directly. See the Vorbis player sample in the LWJGL 3 repository. The result of [icode]stb_vorbis_get_samples_short_interleaved[/icode] is fed into [icode]alBufferData[/icode] directly with an [icode]AL_FORMAT_STEREO16[/icode] format.

edit: the latest stb_vorbis supports seeking now, I have updated the sample (use left/right keys or drag with the mouse).

@Spasi That’s what I figured. I was just fishing when I found that snippet. But no there is no sound when an ogg has 2 channels. There is sound when I convert that same file to mono. Going to check out the new example now.

@SHC Thanks. That helps

Edit: It has something to do with the file itself. I downloaded the original sound from youtube. Sounds from other sources work fine in stereo.

Thanks again guys.

Confirmed. It was a conversion issue. From MP3 to OGG. Decided to start using FLAC instead. Then converting to OGG.