LWJGL Forum

Programming => OpenAL => Topic started by: Estraven on November 29, 2010, 16:48:36

Title: Start sound with offset
Post by: Estraven on November 29, 2010, 16:48:36
Hello everyone,

I'm using OpenAL to read wav files, however, I sometimes need to start playing other than from beginning.
Let's say, I've a 3minute wav, and I want to play it from 1min35sec the end.
How can I do that using OpenAL ? I've found alSourcePlay/Stop, but now way to control where to start.

Thanks,
Estraven.
Title: Re: Start sound with offset
Post by: jediTofu on December 08, 2010, 06:22:09
You'll need to use either AL11.AL_BYTE_OFFSET, AL11.AL_SAMPLE_OFFSET, or AL11.AL_SEC_OFFSET.
You'll probably want to use AL11.AL_SEC_OFFSET, but beware that it rounds the seconds as best it can to the bytes, so bytes and samples will be more accurate.

//Code:
IntBuffer secondsOffset = BufferUtils.createIntBuffer(1).put(5); //Play at 5 seconds in
secondsOffset.rewind();
AL11.alSource(source,AL11.AL_SEC_OFFSET,secondsOffset);
AL10.alSourcePlay(source);


It's kind of dumb that they didn't add this until version 1.1; I'm not sure if this was on purpose or on accident, unless there is another way to do this in version 1.0.  This code works for me though in LWJGL.  8)