[openal] Synchronizing 3D sources
doug at enkisoftware.com
Thu Jan 23 10:46:26 EST 2014
I had an interesting (but short) twitter discussion with Leonard Ritter
(@paniq) about synchronizing 3D sources in OpenAL , and was wondering if
folk on this thread had ideas / input.
In brief, the problem is that there is a need to synchronize the playback
of one 3D positional source with another at a sample accurate (i.e.
sub-buffer) level. I can see a number of ways of going about this without
OpenAL alterations, but they're all fairly involved.
Due to pitch and Doppler variations I don't think it's possible to
implement an API which guarantees continuous synchronized playback of
multiple spatial sources, but timing the start of one with a sample
position of another should be possible.
My proposal would be a trigger API. Triggers have an event sample position
(likely best using AL_SAMPLE_OFFSET_LATENCY_SOFT i64v 32.32 int.fract
format), and a list of sources to play (played all at once when the trigger
Sources are modified to add a list of triggers, which are ordered when
Processing of the triggers would appear to be best done in mixer.c, at the
end of MixSource, or in alu.c during aluMixData where the source processing
takes place (which would potentially make it easier to add the sources.
This would be low overhead, in the case of no triggers one conditional
branch per source, and only one extra integer test per source with a
/* apply triggers, example for just b4 Update source info in mixer.c*/
while( Source->trigger )
ALuint timeToGo = Source->trigger->time - Source->position;
if( timeToGo < DataPosInt ) //using int pos as example
// fire off event
EnqueueSourceDelayed( Source->trigger->source, // src to play
Source, // src of event
timeToGo ); // delay
Source->trigger = Source->trigger->next;
The EnqueueSourceDelayed function would add the sources to the list of
playing sources with a delay which would attempt to time the beginning of
the source with the sample offset required.
I'd be interested to know if people think that this would be useful, or if
there is already some functionality I've missed which could achieve a
similar objective. I'd be happy to take a look at making these changes for
contribution to OpenAL, first of all detailing the API in greater depth for
Thanks for reading!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the openal