From: Lennart Poettering <mznyfn@0pointer.de>
To: ALSA Development Mailing List <alsa-devel@alsa-project.org>
Subject: snd_pcm_rewind() weirdness
Date: Sun, 20 Apr 2008 01:37:38 +0200 [thread overview]
Message-ID: <20080419233738.GA18371@tango.0pointer.de> (raw)
Hey!
On ALSA 1.0.16 with the HDA driver I am experiencing some weird things
with snd_pcm_rewind() which I think are the result of a kernel bug,
but I am not sure.
Here's what I do to trigger this:
I play some PCM. Eventually I want to rewrite what I already have
written. I call snd_pcm_hwsync() and then snd_pcm_avail_update() to
determine how "empty" the playback buffer is. I subtract that value
from the total buffer size. The resulting value should be something
resembling the number of frames that I might be able to rewind. I then
subtract enough frames to keep away from the playback pointer far
enough (50ms, the playback buffer is 370ms, period is 185ms).
Now I pass that value to snd_pcm_rewind() and it returns something that
is higher than what I passed in. Which I find quite
surprising. I had expected that the returned value could be equal or
smaller than what I passed in, but never higher!
So, my interpretation of the API was apparently wrong. It looks like
on HDA the snd_pcm_rewind() parameter is apparently rounded *up* to
the next period boundary (which in this case was equivalent to the
*entire* buffer)?
Of course, rewinding that far immediately caused an XRUN. Which is why
I think rounding up in this cases is a bad idea and the API shouldn't
work this way. Rounding down is OK, rounding up is call for trouble.
To tape over this I added some code to immediately call
snd_pcm_forward() with the difference if I noticed that the device
forwarded more than I requested. This value also got rounded up -- to
twice the period size. So with this backward+forward operation I ended
up at a frame index that is farther ahead than where I originally came
from!
So, what's the expected behaviour of snd_pcm_rewind()? Always round
up? What's the rationale behind this?
If this is not a bug but expected behaviour, could we at least add
something for passing the direction to round to?
What I am working on is the "glitch-free" playback model in PulseAudio
(http://0pointer.de/blog/projects/pulse-glitch-free.html). To do this
I am writing blocks smaller than the period size to the device via the
mmap interface all the time. Given that on HDA _rewind() is apparently
not granular to the frame size, is writing via mmap in small blocks
like that OK? If it's not, how can I learn about this in advance?
Lennart
--
Lennart Poettering Red Hat, Inc.
lennart [at] poettering [dot] net ICQ# 11060553
http://0pointer.net/lennart/ GnuPG 0x1A015CC4
next reply other threads:[~2008-04-19 23:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-19 23:37 Lennart Poettering [this message]
2008-04-21 6:58 ` snd_pcm_rewind() weirdness Jaroslav Kysela
2008-04-24 0:34 ` Lennart Poettering
2008-04-24 0:38 ` Lennart Poettering
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=20080419233738.GA18371@tango.0pointer.de \
--to=mznyfn@0pointer.de \
--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.