Re: [AD] Alsa driver hogs CPU

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On December 19, 2003 08:30 am, Elias Pschernig wrote:
> I just noticed that Allegro programs using the Alsa driver take all the
> CPU (actually, ps says exactly 50% for some reason) as soon as
> install_sound is called, even if nothing else is done. The OSS and ESD
> drivers stay at 0%. gdb tells me that the problem is in some thread
> being busy inside alsa_update all the time.
>
> Since other ALSA using programs don't do this - it doesn't seem to be a
> problem with my ALSA version. I'm wondering if anyone knows what is
> going on? Should Allegro send data to ALSA in a different way? Or just
> put a [nano]sleep() call into alsa_update? Just asking here before
> looking into it - in case someone already knows how to fix it :)
>
> That's the code I used for testing:
>
> #include <allegro.h>
>
> int
> main (void)
> {
>    allegro_init ();
>    set_gfx_mode (GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
>    install_sound (DIGI_ALSA, MIDI_NONE, NULL);//DIGI_OSS DIGI_ESD
>    while (1)
>    {
>       struct timeval tv = {0, 1};
>       select (0, NULL, NULL, NULL, &tv);
>    }
> }
> END_OF_MAIN ();
>
> Btw., this reminds me, wouldn't it be useful to have a function
> al_sleep()? It would be like rest(), but work like yield_timeslice().
> Just a platform independent way to release the CPU for some time.
> al_sleep(0) would do the same as yield_timeslice() - which could be
> deprecated.

A far as Im aware, the alsa write function should be sleeping when theres no 
room to write to the buffer...

How much do people here know about the allegro Mixer and sound api? Does 
update_alsa get called ALL the time? then there probably should be a sleep or 
something in the update_alsa function, or something.. 50% does seem a little 
high, but at that point, update_alsa is just like an infinite loop (with it 
being repeatedly called...)

Then again, I've seen lots of problems appear when using the alsa drivers, 
corrupted audio, just plain bad drivers, etc... Does this happen when using 
the OSS emulation of ALSA? if so, then its likely ALSA's fault, otherwise, 
probably my alsa driver code ;)

> --
> Elias Pschernig <elias@xxxxxxxxxx>
>


-- 
Thomas Fjellstrom
tfjellstrom@xxxxxxxxxx
http://strangesoft.net





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/