From: mikebrady@eircom.net (Mike Brady)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] staging: bcm2835-audio: interpolate audio delay
Date: Mon, 22 Oct 2018 20:08:05 +0100 [thread overview]
Message-ID: <20181022190805.GA4551@ubuntu> (raw)
In-Reply-To: <22867d63-12f1-31f7-acb6-ce9a58fcbe71@gmail.com>
Hi Kirill.
The problem that this patch seeks to resolve is that when userland asks for the
delay -- the time to hear -- the driver responds with a figure that is only updated
when a GPU interrupt occurs, now approximately every 10 milliseconds.
As far as I am aware, there is no way to get a more up-to-date delay number on request,
hence the present patch to interpolate based on the time of the last update, the time of
the request and the nominal frame rate.
It does have the drawback of relying on the accuracy of the CPU clock and on the
nominal rate but on reasonable assumptions, it will not be in error over
the approximately 10 ms interval.
As you'll probably know, this is the built-in DAC in the full-sized Raspberry Pi devices and
is widely used. As a developer of Shairport Sync, I have noticed that the "slop" in
delay on the Pi's built-in DAC is very large by comparison with other DACs. FYI, there is
a discussion of the effects of a downstream equivalent of this suggested patch at:
https://github.com/raspberrypi/firmware/issues/1026#issuecomment-415746016.
Best wishes
Mike
On Thu, Oct 18, 2018 at 09:48:36PM +0200, Kirill Marinushkin wrote:
> Hello Mike,
>
> On 10/18/18 12:57, Mike Brady wrote:
> > + ktime_t now = ktime_get();
> > +
> > + /* Give userspace better delay reporting by interpolating between GPU
> > + * notifications, assuming audio speed is close enough to the clock
> > + * used for ktime
> > + */
> > +
> > + if ((ktime_to_ns(alsa_stream->interpolate_start)) &&
> > + (ktime_compare(alsa_stream->interpolate_start, now) < 0)) {
> > + u64 interval =
> > + (ktime_to_ns(ktime_sub(now,
> > + alsa_stream->interpolate_start)));
> > + u64 frames_output_in_interval =
> > + div_u64((interval * runtime->rate), 1000000000);
> > + snd_pcm_sframes_t frames_output_in_interval_sized =
> > + -frames_output_in_interval;
> > + runtime->delay = frames_output_in_interval_sized;
> > + }
>
> This doesn't look like a good solution for me. More like a workaround. What is
> the root cause of the delay?
>
> Best Regards,
> Kirill
next prev parent reply other threads:[~2018-10-22 19:08 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-18 10:57 [PATCH] staging: bcm2835-audio: interpolate audio delay Mike Brady
2018-10-18 11:02 ` Takashi Iwai
2018-10-18 19:48 ` Kirill Marinushkin
2018-10-22 19:08 ` Mike Brady [this message]
2018-10-22 19:17 ` [PATCH v2] " Mike Brady
2018-10-22 22:25 ` Kirill Marinushkin
2018-10-24 8:20 ` [alsa-devel] " Mike Brady
2018-10-24 18:06 ` Kirill Marinushkin
2018-10-24 19:54 ` Mike Brady
2018-10-24 22:02 ` Kirill Marinushkin
2018-10-25 7:37 ` Takashi Iwai
2018-10-25 17:20 ` Kirill Marinushkin
2018-10-28 14:24 ` Mike Brady
2018-10-28 14:26 ` Mike Brady
2018-11-05 15:57 ` Mike Brady
2018-11-05 16:11 ` Takashi Iwai
2018-11-06 21:05 ` Mike Brady
2018-11-06 21:31 ` Takashi Iwai
2018-11-11 18:08 ` Mike Brady
2018-11-11 20:18 ` [PATCH v2] ARM: " Stefan Wahren
2018-11-13 16:50 ` Takashi Iwai
2019-01-01 10:02 ` Mike Brady
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=20181022190805.GA4551@ubuntu \
--to=mikebrady@eircom.net \
--cc=linux-arm-kernel@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).