From patchwork Thu May 1 10:20:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 4098751 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3EA42BFF02 for ; Thu, 1 May 2014 10:20:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 43C8220340 for ; Thu, 1 May 2014 10:20:50 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 2046C20263 for ; Thu, 1 May 2014 10:20:48 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id F13B9265335; Thu, 1 May 2014 12:20:45 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 83ADE26531B; Thu, 1 May 2014 12:20:40 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1B74626531F; Thu, 1 May 2014 12:20:39 +0200 (CEST) Received: from mail-ee0-f54.google.com (mail-ee0-f54.google.com [74.125.83.54]) by alsa0.perex.cz (Postfix) with ESMTP id D528D265319 for ; Thu, 1 May 2014 12:20:29 +0200 (CEST) Received: by mail-ee0-f54.google.com with SMTP id b57so217078eek.27 for ; Thu, 01 May 2014 03:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=r1m4pOj20droRppwTLL/Vc+YCoDAiiWAbeex6x16FxY=; b=BYgGwpwquBvsBJzFp5VYrUPN+O12Mevol39tfu0Cx57E8DHH73lMNak6HQDA7OADpX svtcpD8uumhr2RV03HAJH/SF749UxoWQn5kqwYI+F1gvUGQvkncANX3WSgWjgD0ZVVzW a3uMFXfBWuCksLq0QDbucYsqfc7kCUt/c1eRcO2ibX4LGsR6I6YWYNpcPBWlH7ENHXHL 9A/Fd8myEB5k8xI9CCqWgcIe39RHjVTsRw7jlK1xs7bdRZiEQg/J7hWWZQbczbWtwhJW 2rVGbqHOIUyMVGkX+p2u0S5zZAV8nf2gfeX55EBvMUNHAGxacIwzXDB7/PVc/Yn9CcOf eCmQ== X-Received: by 10.15.81.135 with SMTP id x7mr9019686eey.61.1398939629506; Thu, 01 May 2014 03:20:29 -0700 (PDT) Received: from tamtam.fritz.box ([2001:4dd0:ff00:9394:224:d7ff:fec6:a0ec]) by mx.google.com with ESMTPSA id t4sm75205913eeb.29.2014.05.01.03.20.28 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 May 2014 03:20:28 -0700 (PDT) From: Daniel Mack To: alsa-devel@alsa-project.org Date: Thu, 1 May 2014 12:20:22 +0200 Message-Id: <1398939622-29451-1-git-send-email-zonque@gmail.com> X-Mailer: git-send-email 1.9.0 Cc: tiwai@suse.de, mick37@gmx.de, clemens@ladisch.de, stable@vger.kernel.org, andr.messa@tiscali.it Subject: [alsa-devel] [PATCH v2] ALSA: usb-audio: work around corrupted TEAC UD-H01 feedback data X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Clemens Ladisch The TEAC UD-H01 firmware sends wrong feedback frequency values, thus causing the PC to send the samples at a wrong rate, which results in clicks and crackles in the output. Add a workaround to detect and fix the corruption. Signed-off-by: Clemens Ladisch [mick37@gmx.de: use sender->udh01_fb_quirk rather than ep->udh01_fb_quirk in snd_usb_handle_sync_urb()] Reported-and-tested-by: Mick Reported-and-tested-by: Andrea Messa Cc: --- Clemens, I hope you're ok that I resend this patch. With Mick's minor amendment (use sender->udh01_fb_quirk rather than ep->udh01_fb_quirk), Andrea Messa also reported success with the same hardware model. Thanks, Daniel sound/usb/card.h | 1 + sound/usb/endpoint.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/sound/usb/card.h b/sound/usb/card.h index 9867ab8..97acb90 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -92,6 +92,7 @@ struct snd_usb_endpoint { unsigned int curframesize; /* current packet size in frames (for capture) */ unsigned int syncmaxsize; /* sync endpoint packet size */ unsigned int fill_max:1; /* fill max packet size always */ + unsigned int udh01_fb_quirk:1; /* corrupted feedback data */ unsigned int datainterval; /* log_2 of data packet interval */ unsigned int syncinterval; /* P for adaptive mode, 0 otherwise */ unsigned char silence_value; diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index e70a87e..289f582 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -471,6 +471,10 @@ struct snd_usb_endpoint *snd_usb_add_endpoint(struct snd_usb_audio *chip, ep->syncinterval = 3; ep->syncmaxsize = le16_to_cpu(get_endpoint(alts, 1)->wMaxPacketSize); + + if (chip->usb_id == USB_ID(0x0644, 0x8038) /* TEAC UD-H01 */ && + ep->syncmaxsize == 4) + ep->udh01_fb_quirk = 1; } list_add_tail(&ep->list, &chip->ep_list); @@ -1105,7 +1109,16 @@ void snd_usb_handle_sync_urb(struct snd_usb_endpoint *ep, if (f == 0) return; - if (unlikely(ep->freqshift == INT_MIN)) { + if (unlikely(sender->udh01_fb_quirk)) { + /* + * The TEAC UD-H01 firmware sometimes changes the feedback value + * by +/- 0x1.0000. + */ + if (f < ep->freqn - 0x8000) + f += 0x10000; + else if (f > ep->freqn + 0x8000) + f -= 0x10000; + } else if (unlikely(ep->freqshift == INT_MIN)) { /* * The first time we see a feedback value, determine its format * by shifting it left or right until it matches the nominal