just calling ALutInit(0,0) costs 20% of CPU

View: New views
5 Messages — Rating Filter:   Alert me  

just calling ALutInit(0,0) costs 20% of CPU

by jviklaus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I'm a new user of OpenAl for a video player on Linux , I would like to understand why calling Alutinit uses so much CPU memory (20%). it is the same if creating directly a context.

when launching a video, it keeps the same level of memory, even when I call for a pause... until I'm doing en Exit().

It's really weird, since anyone else seems to complain about it, if you could help me...

Re: just calling ALutInit(0,0) costs 20% of CPU

by jviklaus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everyone,
I went to search a bit more on this, and found that an infinite loop with no pause is done in the file alsa.c of the library,
within the function :
        static ALuint ALSANoMMapProc(ALvoid *ptr);
the function is launched by a thread launched during the initialization (ALutInit)
this function watches if a new sound has arrived and sent it to the alsa layer,
the fact is even if there is nothing to play the loop is running,
so it requires a lot of memory..
Is this normal ?

Re: just calling ALutInit(0,0) costs 20% of CPU

by Chris Robinson-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wednesday 04 March 2009 6:47:17 am jviklaus wrote:
> Hello everyone,
> I went to search a bit more on this, and found that an infinite loop with
> no pause is done in the file alsa.c of the library,
> within the function :
>         static ALuint ALSANoMMapProc(ALvoid *ptr);

It actually does pause. The snd_pcm_writei function will block until all the
given audio data is written to the card, which can only happen at a defined
speed (the playback frequency/sample rate).

> this function watches if a new sound has arrived and sent it to the alsa
> layer,
> the fact is even if there is nothing to play the loop is running,
> so it requires a lot of memory..
> Is this normal ?

Yes, that behavior's normal. Even if no sources are playing, something still
needs to be written to the sound card (usually silence).

However it taking up 20% CPU, while not doing anything, isn't normal. What
kind of CPU do you have? Also, what sound card, and are you using pulseaudio?
Are you doing anything else in the app that could be taking up that much?
_______________________________________________
Openal-devel mailing list
Openal-devel@...
http://opensource.creative.com/mailman/listinfo/openal-devel

Re: just calling ALutInit(0,0) costs 20% of CPU

by jviklaus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>It actually does pause. The snd_pcm_writei function will block until all the
>given audio data is written to the card, which can only happen at a defined
>speed (the playback frequency/sample rate).

as I see, it doesn't seem to block...
so I went to add a sleep when the state isn't AL_PLAYING
the sample rate is always 48000

>Yes, that behavior's normal. Even if no sources are playing, something still
>needs to be written to the sound card (usually silence).

>However it taking up 20% CPU, while not doing anything, isn't normal. What
>kind of CPU do you have? Also, what sound card, and are you using pulseaudio?
>Are you doing anything else in the app that could be taking up that much?

my CPU is a dual Core 2,4 Ghz (a DELL XPS1330) so I just don't understand,
graphic card is a 8400 NVIDIA, card sound is integrated
and yes I'm using PulseAudio, even if I don't know much about it...
but PulseAudio uses 40 % of my CPU when my app is using 20% for the sound...

I deeply checked that the 20% CPU comes from this thread going on without any blocking...



Re: just calling ALutInit(0,0) costs 20% of CPU

by Chris Robinson-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Saturday 07 March 2009 12:23:27 am jviklaus wrote:
> >It actually does pause. The snd_pcm_writei function will block until all
> > the given audio data is written to the card, which can only happen at a
> > defined speed (the playback frequency/sample rate).
>
> as I see, it doesn't seem to block...
> so I went to add a sleep when the state isn't AL_PLAYING

snd_pcm_writei itself will put the thread to sleep until all the data gets
written. You can't really force a rest when all the sources aren't playing
because something still needs to get written to the card or else it
stalls/loops.

> and yes I'm using PulseAudio, even if I don't know much about it...
> but PulseAudio uses 40 % of my CPU when my app is using 20% for the
> sound...

PulseAudio is a sound server, which can take over ALSA so the app's sound goes
through it instead of ALSA's user libs. PulseAudio's ALSA emulation has been
known to cause numerous problems, including poor performance and lag.

The simplest way would be to check what the app is like with PulseAudio turned
off. IIRC, this can be done by running the app like:
pasuspend my_app app_arguments...

If it runs well that way, it's likely a PulseAudio issue. If it still runs
poorly, the issue is probably elsewhere.
_______________________________________________
Openal-devel mailing list
Openal-devel@...
http://opensource.creative.com/mailman/listinfo/openal-devel