[alsa-devel] ALSA processor usage is too high
Adam Rosenberg
adam at alcorn.com
Fri Nov 5 19:45:41 CET 2010
On Fri, Nov 5, 2010 at 1:58 PM, Clemens Ladisch <clemens at ladisch.de> wrote:
> Adam Rosenberg wrote:
>> On Fri, Nov 5, 2010 at 10:31 AM, Clemens Ladisch <clemens at ladisch.de> wrote:
>> > How much CPU does "aplay -D hw -t raw -f dat /dev/zero" use?
>>
>> I do not know how to calculate CPU usage for a given process.
>
> The time utility (if you have it) measures both elapsed and actually
> used CPU time.
I am not sure how to interpret this, but I told aplay to play for 3
minutes from /dev/zero and here are the results:
root:/> time aplay -d 180 -D hw -t raw -f dat /dev/zero
Playing raw data '/dev/zero' : Signed 16 bit Little Endian, Rate 48000
Hz, Stereo
real 3m 0.10s
user 0m 0.22s
sys 0m 8.48s
>
>> For the audio playback I am polling the streams using
>> snd_pcm_avail_update() and then writing the number of frames available
>> using snd_pcm_writei().
>
> And what does your program do when avail_update returns 0 frames?
If it returns 0 then I do not write any frames. I then check the next
stream. This continues in an infinite loop.
> You cannot write data faster than it's playing; the audio ring buffer
> has a finite size.
>
> You would have a problem if the processing and/or the driver would
> make everything so slow that you wouldn't be able to write new data
> to the device fast enough, which would result in an buffer underrun.
> Does this actually happen?
I am currently writing the decoded mp3 data to a buffer in RAM so that
the program is decoding the mp3 data as fast as it can. I then run
the audio process separately and just play silence. I am doing this
so that I can tell how much time is being spent decoding mp3 data and
processing audio data so that I know how much time remains for other
tasks. From the times I have calculated I can tell that a buffer
underrun would occur frequently if I was actually writing the decoded
mp3 data to the pcm streams.
-Adam
More information about the Alsa-devel
mailing list