From patchwork Fri Feb 21 20:01:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Baert X-Patchwork-Id: 3699851 X-Patchwork-Delegate: tiwai@suse.de Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AE9599F382 for ; Fri, 21 Feb 2014 20:01:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE4412012E for ; Fri, 21 Feb 2014 20:01:27 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 5D06B2010C for ; Fri, 21 Feb 2014 20:01:26 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 42D0B261AA5; Fri, 21 Feb 2014 21:01:24 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id E4EF2261A7B; Fri, 21 Feb 2014 21:01:13 +0100 (CET) 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 E60B6261A7B; Fri, 21 Feb 2014 21:01:12 +0100 (CET) Received: from blu0-omc3-s3.blu0.hotmail.com (blu0-omc3-s3.blu0.hotmail.com [65.55.116.78]) by alsa0.perex.cz (Postfix) with ESMTP id AC35C261A3A for ; Fri, 21 Feb 2014 21:01:05 +0100 (CET) Received: from BLU0-SMTP134 ([65.55.116.73]) by blu0-omc3-s3.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 21 Feb 2014 12:01:04 -0800 X-TMN: [SMoSVNAxs8ht6Ni5ZLdrPjw2YTJYwPY3] X-Originating-Email: [maarten-baert@hotmail.com] Message-ID: Received: from [192.168.1.106] ([91.180.73.244]) by BLU0-SMTP134.phx.gbl over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Fri, 21 Feb 2014 12:01:02 -0800 Date: Fri, 21 Feb 2014 21:01:00 +0100 From: Maarten Baert User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: alsa-devel@alsa-project.org X-Enigmail-Version: 1.6 X-OriginalArrivalTime: 21 Feb 2014 20:01:02.0763 (UTC) FILETIME=[A5C4FFB0:01CF2F3F] Subject: [alsa-devel] [PATCH] Bugfix: Fix resampling when client and slave both use format float 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP I found a bug in libasound. When both the client and the slave (in my case, the JACK plugin) try to use the float format, but the sample rate or channel count does not match, libasound *should* insert linear conversion plugins to convert from float to linear, then resample/remap channels, and then convert back to float (because apparently the resamplers and channel remapper don't support floating point, only 'linear' i.e. integers). Currently this doesn't work, snd_pcm_plug_change_format doesn't know what to do and simply returns EINVAL. As a result, snd_pcm_hw_params fails even though the HW params were perfectly valid (it indicates that both the float format and any sample rate are supported). In my test, this broke audio for WINE (and any other application that tries to use float, such as aplay with the right settings) when I wanted to use the JACK plugin (which only supports the float format). This patch fixes this bug by doing a conversion to S16 and back when resampling or remapping is needed. And while I was at it, I also removed a check that had no effect because the exact same check is already being done at the start of the function. I still think it's a bit silly that libasound requires integers for resampling, because both libsamplerate and libspeex use float internally for resampling. So now ALSA is literally doing a float-to-s16-to-float-to-s16-to-float conversion. But changing that would have been a lot harder. Maarten Baert diff --git a/src/pcm/pcm_plug.c b/src/pcm/pcm_plug.c index fa84eaa..ede9c15 100644 --- a/src/pcm/pcm_plug.c +++ b/src/pcm/pcm_plug.c @@ -522,15 +522,13 @@ static int snd_pcm_plug_change_format(snd_pcm_t *pcm, snd_pcm_t **new, snd_pcm_p } #ifdef BUILD_PCM_PLUGIN_LFLOAT } else if (snd_pcm_format_float(slv->format)) { - /* Conversion is done in another plugin */ - if (clt->format == slv->format && - clt->rate == slv->rate && - clt->channels == slv->channels) - return 0; - cfmt = clt->format; - if (snd_pcm_format_linear(clt->format)) + if (snd_pcm_format_linear(clt->format)) { + cfmt = clt->format; f = snd_pcm_lfloat_open; - else + } else if (clt->rate != slv->rate || clt->channels != slv->channels) { + cfmt = SND_PCM_FORMAT_S16; + f = snd_pcm_lfloat_open; + } else return -EINVAL; #endif #ifdef BUILD_PCM_NONLINEAR