All of lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: Adam Rosenberg <adam@alcorn.com>
Cc: alsa-devel@alsa-project.org
Subject: Re: ALSA processor usage is too high
Date: Fri, 05 Nov 2010 20:10:38 +0100	[thread overview]
Message-ID: <4CD456AE.7090302@ladisch.de> (raw)
In-Reply-To: <AANLkTi=kMF=_1u40yTtvA=oSpyyQn=nEF_JHY_NskiAw@mail.gmail.com>

Adam Rosenberg wrote:
> 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

9s / 180s = 5%

> > 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.

When the program is looping and waiting for some free space to become
available in any of the eight buffers, it doesn't actually process
audio data.  (And you should use poll() with all eight handles so that
you don't eat CPU while waiting.)

The aplay experiment above tells me that your program spent 95% of
its time calling snd_pcm_avail_update.  In that time, you could
decode instead.

> > 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.

Playing silence is not any faster than playing anything else, because
the sound card _cannot_ run faster than the configured sample rate.


Regards,
Clemens

  parent reply	other threads:[~2010-11-05 19:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-05 14:12 ALSA processor usage is too high Adam Rosenberg
2010-11-05 14:31 ` Clemens Ladisch
2010-11-05 15:19   ` Adam Rosenberg
2010-11-05 17:58     ` Clemens Ladisch
2010-11-05 18:45       ` Adam Rosenberg
2010-11-05 18:51         ` Mark Brown
2010-11-05 19:10         ` Clemens Ladisch [this message]
2010-11-05 19:27           ` Adam Rosenberg
2010-11-06  5:30             ` Mark Brown
2010-11-08 10:39             ` Clemens Ladisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CD456AE.7090302@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=adam@alcorn.com \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.