From: Daniel Mack <zonque@gmail.com>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, "[3.5+]"@mail.zonque.de, clemens@ladisch.de,
Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
linuxaudio@showlabor.de, Daniel Mack <zonque@gmail.com>,
linux@romal.de, stable@kernel.org
Subject: [PATCH 1/3] ALSA: snd-usb: restore delay information
Date: Thu, 30 Aug 2012 18:52:29 +0200 [thread overview]
Message-ID: <1346345551-8956-2-git-send-email-zonque@gmail.com> (raw)
In-Reply-To: <1346345551-8956-1-git-send-email-zonque@gmail.com>
Parts of commit 294c4fb8 ("ALSA: usb: refine delay information with USB
frame counter") were unfortunately lost during the refactoring of the
snd-usb driver in 3.5.
This patch adds them back, restoring the correct delay information
behaviour.
Signed-off-by: Daniel Mack <zonque@gmail.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: stable@kernel.org [3.5+]
---
sound/usb/pcm.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 1546577..5ceb8f1 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -1091,7 +1091,16 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
subs->hwptr_done += bytes;
if (subs->hwptr_done >= runtime->buffer_size * stride)
subs->hwptr_done -= runtime->buffer_size * stride;
+
+ /* update delay with exact number of samples queued */
+ runtime->delay = subs->last_delay;
runtime->delay += frames;
+ subs->last_delay = runtime->delay;
+
+ /* realign last_frame_number */
+ subs->last_frame_number = usb_get_current_frame_number(subs->dev);
+ subs->last_frame_number &= 0xFF; /* keep 8 LSBs */
+
spin_unlock_irqrestore(&subs->lock, flags);
urb->transfer_buffer_length = bytes;
if (period_elapsed)
@@ -1109,12 +1118,26 @@ static void retire_playback_urb(struct snd_usb_substream *subs,
struct snd_pcm_runtime *runtime = subs->pcm_substream->runtime;
int stride = runtime->frame_bits >> 3;
int processed = urb->transfer_buffer_length / stride;
+ int est_delay;
spin_lock_irqsave(&subs->lock, flags);
- if (processed > runtime->delay)
- runtime->delay = 0;
+ est_delay = snd_usb_pcm_delay(subs, runtime->rate);
+ /* update delay with exact number of samples played */
+ if (processed > subs->last_delay)
+ subs->last_delay = 0;
else
- runtime->delay -= processed;
+ subs->last_delay -= processed;
+ runtime->delay = subs->last_delay;
+
+ /*
+ * Report when delay estimate is off by more than 2ms.
+ * The error should be lower than 2ms since the estimate relies
+ * on two reads of a counter updated every ms.
+ */
+ if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
+ snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n",
+ est_delay, subs->last_delay);
+
spin_unlock_irqrestore(&subs->lock, flags);
}
--
1.7.11.4
next prev parent reply other threads:[~2012-08-30 16:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-30 16:52 [PATCH 0/3] ALSA: snd-usb: Regression fixes for 3.5 Daniel Mack
2012-08-30 16:52 ` Daniel Mack [this message]
2012-08-30 16:52 ` [PATCH 2/3] ALSA: snd-usb: fix calls to next_packet_size Daniel Mack
2012-08-30 16:52 ` [PATCH 3/3] ALSA: snd-usb: fix cross-interface streaming devices Daniel Mack
2012-08-30 16:54 ` Daniel Mack
2012-08-31 16:26 ` [PATCH 0/3] ALSA: snd-usb: Regression fixes for 3.5 Takashi Iwai
2012-08-31 16:30 ` Daniel Mack
2012-08-31 23:37 ` Felix Homann
2012-09-04 14:33 ` Takashi Iwai
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=1346345551-8956-2-git-send-email-zonque@gmail.com \
--to=zonque@gmail.com \
--cc="[3.5+]"@mail.zonque.de \
--cc=alsa-devel@alsa-project.org \
--cc=clemens@ladisch.de \
--cc=linux@romal.de \
--cc=linuxaudio@showlabor.de \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=stable@kernel.org \
--cc=tiwai@suse.de \
/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.