From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB244C6FA82 for ; Tue, 27 Sep 2022 13:43:58 +0000 (UTC) Received: from localhost ([::1]:46426 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1odAsP-00064E-R5 for qemu-devel@archiver.kernel.org; Tue, 27 Sep 2022 09:43:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1od9AL-0002b2-Kn for qemu-devel@nongnu.org; Tue, 27 Sep 2022 07:54:33 -0400 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]:39843) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1od9AJ-0006Yb-Op for qemu-devel@nongnu.org; Tue, 27 Sep 2022 07:54:21 -0400 Received: by mail-lj1-x235.google.com with SMTP id b24so10615533ljk.6 for ; Tue, 27 Sep 2022 04:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=BdSaBqL7fuI/PStfMOb9OT43dBauY0V6RP0J/6i4BPY=; b=VEKp+Kp0YgR2m23TfBOMN0SE1Rdx7qbUZfoKfwjy6tLKnmUUW2mzHS7n7gh+MYiRt5 U+QPFrqZJcR7vixO6ugbTpX9eFBC+ZnQ918VcZjqN4o2yqLI7pLZrD1S6zdhQNnQx/SC Qtl87Dyn5wxOuwJFvEfYNLOovaqDe3cGw2bUxeOLxwRRvf42mK7XQ19FlVkt25VXNVEa 33qyeG+Bc4H65uZC9/tbHyza2XvOTq0Bz08860NqNn4B0OGXNwzy1Htf4Q+Y5VTP2/19 eJnbHk59ATp/c7Sl8/FEiKCl0jKUSEFOXF2Ir3jjKXmOjHyjDL4wG6BaPAkarYt9Ht7W uHfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=BdSaBqL7fuI/PStfMOb9OT43dBauY0V6RP0J/6i4BPY=; b=kzLdGYIR784LXoPTYf0C/JE4yHARSml9dp5/xL9LeUWqDJ5gT1L1Lt6LcSJh+iRONQ Rgn8rhQ8lmF111W+S450q+TW4MHV2q6u0yVHErV16NnfLlPc+SUaNxis1GYHUUkyhRs2 8r4K1uwY7JJG2kOAdSt8MmY8oRnEbzx9rxyrwvursh5kvpjoK1S71pSBOOg8QEcuqnuN 6GtXRI5sqg3H5zobKG7q0NpoRp5VkdXd3uKIORtZtwedO2CFfOYdWOirheFhVm4NxLhS KfyJAqsk5nXZccpVey3GEUX77NdqcZ+IzHjl4FpX8wiNCbblAoDpvccxSDMoEpqZ/e4l JEIQ== X-Gm-Message-State: ACrzQf3+P9O0wZKATJlyc8hepRuXdnj7I9iMbYN8D00r/JV5u5S5vJLB 7TMdYYjlXbbFkVsn2NwFisSYHbWx7y9A1XI2XDk= X-Google-Smtp-Source: AMsMyM7FafYCPr2OX/g4eFMuTURwvutVfBg8K9NhKKelPQ3m4NlduuSgq02SnbxuY1c2KgQSDPsGthxNCb+ktOpDAUE= X-Received: by 2002:a2e:a607:0:b0:26c:42c8:13af with SMTP id v7-20020a2ea607000000b0026c42c813afmr9080091ljp.267.1664279657768; Tue, 27 Sep 2022 04:54:17 -0700 (PDT) MIME-Version: 1.0 References: <38d7417a-fc26-be39-6a63-99c79ee15fc9@t-online.de> <20220923183640.8314-11-vr_qemu@t-online.de> In-Reply-To: <20220923183640.8314-11-vr_qemu@t-online.de> From: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= Date: Tue, 27 Sep 2022 15:54:05 +0400 Message-ID: Subject: Re: [PATCH 11/12] audio: fix sw->buf size for audio recording To: =?UTF-8?Q?Volker_R=C3=BCmelin?= Cc: Gerd Hoffmann , qemu-devel@nongnu.org Content-Type: multipart/alternative; boundary="000000000000ceeb1f05e9a74dd3" Received-SPF: pass client-ip=2a00:1450:4864:20::235; envelope-from=marcandre.lureau@gmail.com; helo=mail-lj1-x235.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000ceeb1f05e9a74dd3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Sep 23, 2022 at 10:48 PM Volker R=C3=BCmelin = wrote: > The calculation of the buffer size needed to store audio samples > after resampling is wrong for audio recording. For audio recording > sw->ratio is calculated as > > sw->ratio =3D frontend sample rate / backend sample rate. > > From this follows > > frontend samples =3D frontend sample rate / backend sample rate > * backend samples > frontend samples =3D sw->ratio * backend samples > > In 2 of 3 places in the audio recording code where sw->ratio > is used in a calculation to get the number of frontend frames, > the calculation is wrong. Fix this. The 3rd formula in > audio_pcm_sw_read() is correct. > > Resolves: https://gitlab.com/qemu-project/qemu/-/issues/71 > Signed-off-by: Volker R=C3=BCmelin > Would you mind adding the test to qtest? lgtm Acked-by: Marc-Andr=C3=A9 Lureau > --- > audio/audio.c | 2 +- > audio/audio_template.h | 4 ++++ > 2 files changed, 5 insertions(+), 1 deletion(-) > > diff --git a/audio/audio.c b/audio/audio.c > index ba0c62b120..60c7472d37 100644 > --- a/audio/audio.c > +++ b/audio/audio.c > @@ -995,7 +995,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on) > */ > static size_t audio_frontend_frames_in(SWVoiceIn *sw, size_t frames_in) > { > - return ((int64_t)frames_in << 32) / sw->ratio; > + return (int64_t)frames_in * sw->ratio >> 32; > } > > static size_t audio_get_avail (SWVoiceIn *sw) > diff --git a/audio/audio_template.h b/audio/audio_template.h > index 7192b19e73..6a0337ac6b 100644 > --- a/audio/audio_template.h > +++ b/audio/audio_template.h > @@ -112,7 +112,11 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE= ) > (SW *sw) > return 0; > } > > +#ifdef DAC > samples =3D ((int64_t) sw->HWBUF->size << 32) / sw->ratio; > +#else > + samples =3D (int64_t)sw->HWBUF->size * sw->ratio >> 32; > +#endif > > sw->buf =3D audio_calloc(__func__, samples, sizeof(struct st_sample)= ); > if (!sw->buf) { > -- > 2.35.3 > > > --=20 Marc-Andr=C3=A9 Lureau --000000000000ceeb1f05e9a74dd3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Sep 23, 2022 at 10:48 PM Volk= er R=C3=BCmelin <vr_qemu@t-online.de> wrote:
The calculation of the buffer size needed to store aud= io samples
after resampling is wrong for audio recording. For audio recording
sw->ratio is calculated as

sw->ratio =3D frontend sample rate / backend sample rate.

>From this follows

frontend samples =3D frontend sample rate / backend sample rate
=C2=A0* backend samples
frontend samples =3D sw->ratio * backend samples

In 2 of 3 places in the audio recording code where sw->ratio
is used in a calculation to get the number of frontend frames,
the calculation is wrong. Fix this. The 3rd formula in
audio_pcm_sw_read() is correct.

Resolves: https://gitlab.com/qemu-project/qemu/-/is= sues/71
Signed-off-by: Volker R=C3=BCmelin <vr_qemu@t-online.de>

<= /div>
Would you mind adding the test to qtest?

lgtm
Acked-by: Marc-Andr=C3= =A9 Lureau <marcandre.lureau@redhat.com>

=C2=A0
---
=C2=A0audio/audio.c=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | 2 +-
=C2=A0audio/audio_template.h | 4 ++++
=C2=A02 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/audio/audio.c b/audio/audio.c
index ba0c62b120..60c7472d37 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -995,7 +995,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
=C2=A0 */
=C2=A0static size_t audio_frontend_frames_in(SWVoiceIn *sw, size_t frames_i= n)
=C2=A0{
-=C2=A0 =C2=A0 return ((int64_t)frames_in << 32) / sw->ratio;
+=C2=A0 =C2=A0 return (int64_t)frames_in * sw->ratio >> 32;
=C2=A0}

=C2=A0static size_t audio_get_avail (SWVoiceIn *sw)
diff --git a/audio/audio_template.h b/audio/audio_template.h
index 7192b19e73..6a0337ac6b 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -112,7 +112,11 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) = (SW *sw)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return 0;
=C2=A0 =C2=A0 =C2=A0}

+#ifdef DAC
=C2=A0 =C2=A0 =C2=A0samples =3D ((int64_t) sw->HWBUF->size << 3= 2) / sw->ratio;
+#else
+=C2=A0 =C2=A0 samples =3D (int64_t)sw->HWBUF->size * sw->ratio &g= t;> 32;
+#endif

=C2=A0 =C2=A0 =C2=A0sw->buf =3D audio_calloc(__func__, samples, sizeof(s= truct st_sample));
=C2=A0 =C2=A0 =C2=A0if (!sw->buf) {
--
2.35.3




--
Marc-Andr= =C3=A9 Lureau
--000000000000ceeb1f05e9a74dd3--