[Openal] AL_*_OFFSET resolution
Casey Borders
thebeast.13 at gmail.com
Fri Dec 7 12:35:54 PST 2007
Are you streaming the file or loading the whole thing in at once? It's hard
to pull a small cohesive example out of my code, but you can have a look at
it on Sourceforge at http://sourceforge.net/projects/ogreal You'll want to
look in the OggSound class. Here's the pertinent bit:
void OggSound::setSecondOffset(Ogre::Real seconds)
{
if(!mStream)
{
alSourcef(mSource, AL_SEC_OFFSET, seconds);
CheckError(alGetError(), "Failed to set offset");
}
else
{
bool wasPlaying = isPlaying();
pause();
ov_time_seek(&mOggStream, seconds);
if(wasPlaying) play();
}
}
Here are my helper functions:
bool Sound::isPlaying() const
{
if(mSource == AL_NONE)
{
return false;
}
State state;
alGetSourcei(mSource, AL_SOURCE_STATE, &state);
CheckError(alGetError(), "Failed to get State");
return (state == AL_PLAYING);
}
bool Sound::pause()
{
if(!isPlaying()) return true;
if(mSource != AL_NONE)
{
alSourcePause(mSource);
CheckError(alGetError(), "Failed to pause sound");
}
return false;
}
bool Sound::play()
{
if(isPlaying()) return true;
if(mStartTime == 0)
{
time(&mStartTime);
}
else if(!isPaused())
{
time_t currentTime;
time(¤tTime);
setSecondOffset(currentTime - mStartTime);
}
if(mSource != AL_NONE || (mSource =
SoundManager::getSingleton()._requestSource(this)) != AL_NONE)
{
if(!mBuffersLoaded)
{
mBuffersLoaded = loadBuffers();
}
if(!mBuffersQueued)
{
// Unqueue any buffers that may be left over
unqueueBuffers();
queueBuffers();
}
initSource();
alSourcePlay(mSource);
CheckError(alGetError(), "Failed to play sound");
}
return false;
}
On Dec 7, 2007 12:15 PM, Ben Swanson <dujiaozhu at gmail.com> wrote:
> I am attempting to sync an animation to a sound file using the
> AL_SEC_OFFSET property. The problem I am having is that the resolution of
> the command seems to be 4096 samples, which leads to a choppy animation. Is
> there a way to change this (the sound file is in ogg vorbis format)?
>
> Ben
>
> _______________________________________________
> Openal mailing list
> Openal at opensource.creative.com
> http://opensource.creative.com/mailman/listinfo/openal
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://opensource.creative.com/pipermail/openal/attachments/20071207/32260cb5/attachment.html
More information about the Openal
mailing list