[Openal] Get Audio time or buffer position
Chris Robinson
chris.kcat at gmail.com
Sat Nov 24 16:20:44 PST 2007
On Saturday 24 November 2007 03:46:43 pm Casey Borders wrote:
> I want to be able to "save" the current position in an audio stream so I
> can come back and start that source right where it left off. I want to be
> able to do this because I am working on some code to manage hardware
> sources and I'll need to steal sources and shift them around from time to
> time, so when I start a sound back up I'll need to know where to start it
> up at. Does anyone have any suggestions?
You can use the AL_SAMPLE_OFFSET (or AL_BYTE_OFFSET or AL_SEC_OFFSET(*))
source attribute. eg:
ALint stop_source(ALint source)
{
ALint pos;
// Pause the source to prevent the offset from incrementing between
// getting it and stopping the source (alSourceStop rewinds the source
// back to 0)
alSourcePause(source);
alGetSourcei(source, AL_SAMPLE_OFFSET, &pos);
alSourceStop(source);
return pos;
}
void restore_source(ALint source, ALint pos)
{
alSourcei(source, AL_SAMPLE_OFFSET, pos);
alSourcePlay(source);
}
(*) Using AL_BYTE_OFFSET may behave a little quirky with compressed formats,
but should be fine otherwise. AL_SEC_OFFSET uses a float (ALfloat,
alGetSourcef, alSourcef).
More information about the Openal
mailing list