[SDL] How do I know how much Audio Consumed under SDL_Audio API ?

Glenn Maynard g_sdl at zewt.org
Sun Dec 8 18:27:01 PST 2002


On Fri, Dec 06, 2002 at 04:14:28PM -0500, Glenn Maynard wrote:
> On Fri, Dec 06, 2002 at 01:47:24PM -0500, Mark Whittemore wrote:
> > How do I know how much Audio Consumed under SDL_Audio API ?
> > 
> > Surely I'm not supposed to keep track of this myself ?
> 
> If you're referring to runtime detection of the play cursor, I
> believe SDL always double-buffers audio, so you can probably keep track
> of the system time of the last buffer and figure out how long it's been
> since it was sent to figure out the difference.  Ugly and hacky, but it
> seems to work.  (I'm not positive it works in all archs; I don't know of
> any other way, and I'd be interested in knowing if this doesn't
> work on all SDL ports.)  Better than OpenAL, where there seems to be
> no way to do this at all (which makes it useless to me ...)

Hmm.  This isn't accurate enough; at least with the DSound
implementation, there's a good deal of variance--the callback isn't
necessarily called right when the buffers switch.  (It's a lot closer
with the NOTIFY stuff turned on, but that's glitchy for some reason, and
it's probably still not accurate enough.)

Sigh.  I can't find any cross-platform sound library that has some way
of accurately syncing audio.  OpenAL, SDL, PortAudio--none provide
a mechanism to accurately sync output (though DirectSound does it very
easily).  It's strange, this is rather fundamental ...

(Though I'm not certain this is what the person I was originally
replying to wanted, since he never followed up, this is still something
that's been causing me problems.)

-- 
Glenn Maynard




More information about the SDL mailing list