From: Stefan Schoenleitner <dev.c0debabe@gmail.com>
To: alsa-devel <alsa-devel@alsa-project.org>
Subject: underruns and POLLERR when copying audio frames
Date: Tue, 20 Jul 2010 13:00:41 +0200 [thread overview]
Message-ID: <4C4581D9.8020309@gmail.com> (raw)
Hi,
I have some code that basically captures audio frames from one device
and then writes it for playback to another device.
Ideally mmapped IO could be used for such a task, but in my application
this is not possible at the moment, as at least one of the audio devices
does not support it.
In my application copying audio frames works with a poll() based approach:
If the capture device is ready for reading, a new audio frame is being read.
And if there is a new captured frame available AND the playback device
is ready, then it is written to the playback device.
So far so good, the approach works.
However, it doesn't take long until poll() on the playback device
returns POLLERR since an underrun has occurred.
If I just ignore POLLERR, then the next write operation to the playback
device fails and I need to snd_pcm_recover().
My question is how to avoid these underruns.
Basically I have two ideas:
1. The avail_min parameter specifies when the playback device should
start to play buffered frames back.
Hence if for example avail_min=160, then the playback device would wait
until at least 160 frames have been written to the playback device (i.e.
to the internal buffer) and then start with playing back these frames.
My idea would be to just increment avail_min to something bigger, so
that more frames are being buffered before playback starts.
Would this work ?
2. Another idea would be to do some buffering on my own in the application.
Thus I would first capture a number of frames and write them to a FIFO
buffer.
Once the buffer has been filled with enough frames, I would start to
write them to the playback device.
Therefore while the FIFO is being drained on the one side (playback), it
is also refilled on the other side (capture).
* So, which of these ideas do you think is better in terms of avoiding
underruns ?
To me it seems that both solutions would lead to the same results.
Yet just setting avail_min to something higher seems to be the easier
solution as it does not require me to implement a buffering solution on
my own.
cheers,
stefan
next reply other threads:[~2010-07-20 11:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-20 11:00 Stefan Schoenleitner [this message]
2010-07-20 13:41 ` underruns and POLLERR when copying audio frames Clemens Ladisch
2010-07-20 22:50 ` Stefan Schoenleitner
2010-07-21 7:07 ` Clemens Ladisch
2010-07-21 10:20 ` Stefan Schoenleitner
2010-08-02 3:02 ` pl bossart
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=4C4581D9.8020309@gmail.com \
--to=dev.c0debabe@gmail.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.