The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Problem with SDL_OpenAudio and callback period ?
reddog0000


Joined: 18 Aug 2014
Posts: 3
Hi all,

"My first post" (c)

I'm writing a 2D game engine and have the image, sprite, background and app working etc.

I want my code to be able to run on Linux later.

Everything works as expected and compiles using various IDE gnu combinations: SDL 1.2.x,
c++ and the ming toolset on windows - IDE's netbeans codebase, dev-cpp.

BUT no matter what combinations of parameters I pass to SDL_OpenAudio [eg see partial log below],
I cannot get the callback period below ~ 250ms which is a problem as there is a ~ 1/4 sec
delay between sprite event eg explosions and sound.
Code:

000001 000 00 [000000] zeng_audio           : desired:  freq [22050] samples[512] size[0]
000002 000 00 [000000] zeng_audio           : desired:  (samples*1000) / freq =  23
000003 000 00 [000000] zeng_audio           : calling SDL_OpenAudio...
000004 000 00 [000051] zeng_audio           : desired:  freq [22050] samples[5512] size[11024]
000005 000 00 [000051] zeng_audio           : desired:  (samples*1000) / freq = 249
000006 000 00 [000051] zeng_audio           : obtained:  freq [22050] samples[5512] size[11024]
000007 000 00 [000051] zeng_audio           : obtained:  (samples*1000) / freq = 249

000001 000 00 [000000] zeng_audio           : desired:  freq [48000] samples[512] size[0]
000002 000 00 [000000] zeng_audio           : desired:  (samples*1000) / freq =  10
000003 000 00 [000000] zeng_audio           : calling SDL_OpenAudio...
000004 000 00 [000056] zeng_audio           : desired:  freq [48000] samples[12000] size[24000]
000005 000 00 [000056] zeng_audio           : desired:  (samples*1000) / freq = 250
000006 000 00 [000056] zeng_audio           : obtained:  freq [48000] samples[12000] size[24000]
000007 000 00 [000056] zeng_audio           : obtained:  (samples*1000) / freq = 250

000122 000 06 [006322] AudioCallback        :  elasped ms[254]
000123 000 06 [006576] AudioCallback        :  elasped ms[254]
000124 000 06 [006820] AudioCallback        :  elasped ms[244]
000125 000 06 [006863] sprites_updateWC     : setDying spritesid[36] id[34]
000126 000 06 [006863] sprites_imagePut     : dying: replace sprite pos [16] id[34] with explosion id[37]
000127 000 06 [006863] sprites_imagePut     : dying: delete sprite  id[34]
000128 000 06 [006863] soundplay            : playarray[0]
000129 000 06 [006863] sprites_imagePut     : dying: replace sprite pos [17] id[36] with explosion id[38]
000130 000 06 [006863] sprites_imagePut     : dying: delete sprite  id[36]
000131 000 06 [006863] soundplay            : playarray[1]
000132 000 07 [007073] AudioCallback        :  elasped ms[253]


As you can see above the routine playsound fires twice at ~ 6863ms [two explosions] but the audio
callback is on a ~ 250ms delay !

I've browsed some of the SDL audio lib code and it seems that no matter what you pass to
SDL_OpenAudio it sets a callback delay using parameters [ (samples*1000) / freq] from the
audio driver itself -

Does anyone know how to get this callback delay down from 250ms ?

Thanks in advance,

woof
reddog0000


Joined: 18 Aug 2014
Posts: 3
SOLVED ----

I removed all the SDL headers, libs and dll from my default installations and downloaded the current development version
from the SDL web site ie SDL-1.2.15 and updated all project and IDE configuration files to use the new version.

It worked !

000001 000 00 [000000] zeng_audio : desired: freq [22050] samples[1024] size[0]
000002 000 00 [000000] zeng_audio : desired: (samples*1000) / freq = 46
000003 000 00 [000000] zeng_audio : calling SDL_OpenAudio...
000004 000 00 [000030] zeng_audio : desired: freq [22050] samples[1024] size[2048]
000005 000 00 [000030] zeng_audio : desired: (samples*1000) / freq = 46
000006 000 00 [000030] zeng_audio : obtained: freq [22050] samples[1024] size[2048]
000007 000 00 [000030] zeng_audio : obtained: (samples*1000) / freq = 46

As the above log shows SDL now calculates the callback period correctly eg ~45ms

So now the user can an explosions and hear it without the previous 250ms delay ...

woof