Problem with SDL_AddTimer()

Hi!

While playing around with the audio functions in SDL, I came to a
point where I wanted a periodically updated oscillator. Scanned the
docs, and SDL_AddTimer() seemed to be what I was looking for. However,
I am experiencing a slight problem: my callback function is never run.

It has the following prototype: Uint32 osc_callback (Uint32, void *);

SDL_AddTimer invocation: timer = SDL_AddTimer (100, osc_callback, osc);

(osc is a pointer to a local struct.)

After calling SDL_AddTimer() I do SDL_Delay (2000), and yet the
callback function is not entered once. I initialize SDL with SDL_Init
(SDL_INIT_AUDIO | SDL_INIT_TIMER), and audio callback works, as does
SDL_Delay(). I am using SDL-1.2.5a-win32 with Dev-C++.

Any help would be appreciated.

Can’t say what’s going on with your timer callback - but why use a
timer callback in the first place? All it does is add a(nother) layer
of sync issues and increase latency and complexity.

What do you want to do that isn’t better, easier and more accurately
done in the audio callback?

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`---------------------------> http://olofson.net/audiality -’
http://olofson.nethttp://www.reologica.se —On Monday 17 February 2003 17.31, Martin Evald wrote:

Hi!

While playing around with the audio functions in SDL, I came to a
point where I wanted a periodically updated oscillator. Scanned the
docs, and SDL_AddTimer() seemed to be what I was looking for.

Hi!

While playing around with the audio functions in SDL, I came to a
point where I wanted a periodically updated oscillator. Scanned the
docs, and SDL_AddTimer() seemed to be what I was looking for. However,
I am experiencing a slight problem: my callback function is never run.

What you probably want to do is keep track of elapsed samples in the
audio callback and adjust the values you write into the buffer at certain
points. This will allow precise control over the audio timing because
you’re directly working off of the audio sample rate.

That said, go ahead and post a complete minimal example that I can run
to try to debug your specific problem.

Oh, and what platform are you running on?

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment