How to sync passing data to callback function

Hi,

I’m new to SDL.
I’m developing a media player using SDL, and now I met the problem that the
audio callback function is sometimes not called in time, and cause the
audio a little fitful.

My Problem is instead of providing whole wav file through SDL_LoadWAV, I
want to pass PCM samples (probably 1024 samples).(Design is like this I
will be getting PCM samples)

But issue is, callback function is not called in time or calling is delayed
which causes the sound to be fitful. I’m not able to syn passing of data to
callback function.

Can you please suggest a way to synchronize passing data (Samples) to
callback function or provide some application where data is passed in
samples?

Regards,

Praveen

Hmm… I had a similar problem on windows using the default driver (I think
it was winmm). You might like to tell us what driver is loaded for audio by
printing SDL_GetCurrentAudioDriver() to the console. There is the other
possibility (I don’t know) that you are doing too much work in the audio
callback. Audio callbacks are all realtime, which mean that you shouldn’t
do any unbounded operations like allocating memory with malloc or new,
reading from disk, etc.

Good luck.On Mon, Jan 16, 2012 at 1:52 PM, praveen gupta <praveen.apr87 at gmail.com>wrote:

Hi,

I’m new to SDL.
I’m developing a media player using SDL, and now I met the problem that
the audio callback function is sometimes not called in time, and cause the
audio a little fitful.

My Problem is instead of providing whole wav file through SDL_LoadWAV, I
want to pass PCM samples (probably 1024 samples).(Design is like this I
will be getting PCM samples)

But issue is, callback function is not called in time or calling is
delayed which causes the sound to be fitful. I’m not able to syn passing of
data to callback function.

Can you please suggest a way to synchronize passing data (Samples) to
callback function or provide some application where data is passed in
samples?

Regards,

Praveen


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If the callback really isn’t called in time (test by just generating a sine
wave or something), all you can do is using larger buffers, or tweaking the
OS/driver settings, replacing hardware etc until performance is satisfactory.
A PC with a standard OS isn’t built for real time applications…

Synchronization between a “disk I/O thread” (main program call or whatever)
and the audio callback can be done by means of locks or lock-free constructs,
such as a lock-free single reader/single writer FIFO.

I suppose a ring of 1024 sample (or so) buffers would be nice and efficient
here; I/O thread queues them up for the callback, which reads one buffer at a
time, then sending it back.

Locks should generally be avoided during normal operation, as they can result
in priority inversion, meaning it’s not safe even if your code is nice and
clean. Will work most of the time, but using them in a serious audio
application is asking for trouble.On Monday 16 January 2012, at 06.52.04, praveen gupta <praveen.apr87 at gmail.com> wrote:

Hi,

I’m new to SDL.
I’m developing a media player using SDL, and now I met the problem that the
audio callback function is sometimes not called in time, and cause the
audio a little fitful.

My Problem is instead of providing whole wav file through SDL_LoadWAV, I
want to pass PCM samples (probably 1024 samples).(Design is like this I
will be getting PCM samples)

But issue is, callback function is not called in time or calling is delayed
which causes the sound to be fitful. I’m not able to syn passing of data to
callback function.

Can you please suggest a way to synchronize passing data (Samples) to
callback function or provide some application where data is passed in
samples?


//David Olofson - Consultant, Developer, Artist, Open Source Advocate

.— Games, examples, libraries, scripting, sound, music, graphics —.
| http://consulting.olofson.net http://olofsonarcade.com |
’---------------------------------------------------------------------’