qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Marc-André Lureau" <marcandre.lureau@gmail.com>
To: "Volker Rümelin" <vr_qemu@t-online.de>
Cc: Gerd Hoffmann <kraxel@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [PATCH 11/12] audio: fix sw->buf size for audio recording
Date: Tue, 27 Sep 2022 15:54:05 +0400	[thread overview]
Message-ID: <CAJ+F1CLnjL80zO7_FHDQp-w2_rkXa2-U1pgVOTmAsJLP23DT1A@mail.gmail.com> (raw)
In-Reply-To: <20220923183640.8314-11-vr_qemu@t-online.de>

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

On Fri, Sep 23, 2022 at 10:48 PM Volker Rümelin <vr_qemu@t-online.de> 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 = frontend sample rate / backend sample rate.
>
> From this follows
>
> frontend samples = frontend sample rate / backend sample rate
>  * backend samples
> frontend samples = 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ümelin <vr_qemu@t-online.de>
>

Would you mind adding the test to qtest?

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



> ---
>  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 = ((int64_t) sw->HWBUF->size << 32) / sw->ratio;
> +#else
> +    samples = (int64_t)sw->HWBUF->size * sw->ratio >> 32;
> +#endif
>
>      sw->buf = audio_calloc(__func__, samples, sizeof(struct st_sample));
>      if (!sw->buf) {
> --
> 2.35.3
>
>
>

-- 
Marc-André Lureau

[-- Attachment #2: Type: text/html, Size: 3183 bytes --]

  reply	other threads:[~2022-09-27 13:43 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 18:34 [PATCH 00/12] audio: misc. improvements and bug fixes Volker Rümelin
2022-09-23 18:36 ` [PATCH 01/12] audio: refactor code in audio_run_out() Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 02/12] audio: fix GUS audio playback with out.mixing-engine=off Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 03/12] audio: run downstream playback queue unconditionally Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 04/12] alsaaudio: reduce playback latency Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 05/12] audio: add more audio rate control functions Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 06/12] spiceaudio: add a pcm_ops buffer_get_free function Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 07/12] spiceaudio: update comment Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 08/12] audio: swap audio_rate_get_bytes() function parameters Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 09/12] audio: rename audio_sw_bytes_free() Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 10/12] audio: refactor audio_get_avail() Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau
2022-09-23 18:36 ` [PATCH 11/12] audio: fix sw->buf size for audio recording Volker Rümelin
2022-09-27 11:54   ` Marc-André Lureau [this message]
2022-10-01 12:08     ` Volker Rümelin
2022-09-23 18:36 ` [PATCH 12/12] audio: prevent an integer overflow in resampling code Volker Rümelin
2022-10-11 13:31 ` [PATCH 00/12] audio: misc. improvements and bug fixes Gerd Hoffmann

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=CAJ+F1CLnjL80zO7_FHDQp-w2_rkXa2-U1pgVOTmAsJLP23DT1A@mail.gmail.com \
    --to=marcandre.lureau@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vr_qemu@t-online.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).