All of
 help / color / mirror / Atom feed
From: Maarten Baert <>
Subject: [PATCH] Bugfix: Fix resampling when client and slave both use format float
Date: Fri, 21 Feb 2014 21:01:00 +0100	[thread overview]
Message-ID: <BLU0-SMTP134831A0E1EA4F209F321CAE2850@phx.gbl> (raw)

[-- Attachment #1: Type: text/plain, Size: 1467 bytes --]

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

[-- Attachment #2: fix-float-resampling.patch --]
[-- Type: text/x-patch, Size: 864 bytes --]

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
 	} 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;

[-- Attachment #3: Type: text/plain, Size: 0 bytes --]

             reply	other threads:[~2014-02-21 20:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-21 20:01 Maarten Baert [this message]
2014-02-24  9:17 ` [PATCH] Bugfix: Fix resampling when client and slave both use format float Takashi Iwai
2014-02-24 12:13   ` Maarten Baert
2014-02-24 12:57     ` Pavel Hofman
2014-02-24 13:38       ` Takashi Iwai
2014-02-24 13:19     ` Takashi Iwai
2014-02-24 13:37       ` Takashi Iwai
2014-02-24 20:52         ` Maarten Baert
2014-02-26  7:28           ` Takashi Iwai
2014-02-26 13:32             ` Maarten Baert
2014-02-26 13:40               ` 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:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BLU0-SMTP134831A0E1EA4F209F321CAE2850@phx.gbl \ \ \

* 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.