From: "Volker Rümelin" <vr_qemu@t-online.de>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [PATCH 10/12] audio: refactor audio_get_avail()
Date: Fri, 23 Sep 2022 20:36:38 +0200 [thread overview]
Message-ID: <20220923183640.8314-10-vr_qemu@t-online.de> (raw)
In-Reply-To: <38d7417a-fc26-be39-6a63-99c79ee15fc9@t-online.de>
Split out the code in audio_get_avail() that calculates the
buffer size that the audio frontend can read. This is similar
to the code changes in audio_get_free().
Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
---
audio/audio.c | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/audio/audio.c b/audio/audio.c
index dd66b745e5..ba0c62b120 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -986,6 +986,18 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
}
}
+/**
+ * audio_frontend_frames_in() - returns the number of frames the resampling
+ * code generates from frames_in frames
+ *
+ * @sw: audio recording frontend
+ * @frames_in: number of frames
+ */
+static size_t audio_frontend_frames_in(SWVoiceIn *sw, size_t frames_in)
+{
+ return ((int64_t)frames_in << 32) / sw->ratio;
+}
+
static size_t audio_get_avail (SWVoiceIn *sw)
{
size_t live;
@@ -1002,12 +1014,12 @@ static size_t audio_get_avail (SWVoiceIn *sw)
}
ldebug (
- "%s: get_avail live %zu ret %" PRId64 "\n",
+ "%s: get_avail live %zu frontend frames %zu\n",
SW_NAME (sw),
- live, (((int64_t) live << 32) / sw->ratio) * sw->info.bytes_per_frame
+ live, audio_frontend_frames_in(sw, live)
);
- return (((int64_t) live << 32) / sw->ratio) * sw->info.bytes_per_frame;
+ return live;
}
/**
@@ -1309,11 +1321,13 @@ static void audio_run_in (AudioState *s)
sw->total_hw_samples_acquired -= min;
if (sw->active) {
+ size_t sw_avail = audio_get_avail(sw);
size_t avail;
- avail = audio_get_avail (sw);
+ avail = audio_frontend_frames_in(sw, sw_avail);
if (avail > 0) {
- sw->callback.fn (sw->callback.opaque, avail);
+ sw->callback.fn(sw->callback.opaque,
+ avail * sw->info.bytes_per_frame);
}
}
}
--
2.35.3
next prev parent reply other threads:[~2022-09-23 18:53 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 ` Volker Rümelin [this message]
2022-09-27 11:54 ` [PATCH 10/12] audio: refactor audio_get_avail() 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
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=20220923183640.8314-10-vr_qemu@t-online.de \
--to=vr_qemu@t-online.de \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).