views:

288

answers:

2

Imagine this function:

void SoundManager::playSource(ALuint sourceID, float offset)
{
    alSourceStop(sourceID);

    ALint iTotal = 0;
    ALint iCurrent = 0;
    ALint uiBuffer = 0;
    alGetSourcei(sourceID, AL_BUFFER, &uiBuffer);
    alGetBufferi(uiBuffer, AL_SIZE, &iTotal);
    iCurrent = iTotal * offset;

    alSourcei(sourceID, AL_BYTE_OFFSET, iCurrent);
    alSourcePlay(sourceID);
}

The idea is calling playSource(x, 0.5f) would jump to (roughly) halfway through the buffer, etc.

It works fine the first time I call it, but if I call it again on the same source (whether that source is playing or not) it begins playing as though I'd called it with offset 0.

Any ideas why?

A: 

I think you will have a better chance of getting an answer at irc.freenode.net ##openal

digitalSurgeon
+3  A: 

Solved!

Even though the API claims that setting the offsets works on sources in any state, the problem was I should have been calling alSourceRewind instead of alSourceStop at the start.

It seems setting offsets only works on sources in the AL_INITIAL state.

frezned