From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Thomas Huth <thuth@redhat.com>
Subject: [Qemu-devel] [PULL 5/5] audio/sdlaudio: Simplify the sdl_callback function
Date: Thu, 28 Feb 2019 11:08:58 +0100 [thread overview]
Message-ID: <20190228100858.28397-6-kraxel@redhat.com> (raw)
In-Reply-To: <20190228100858.28397-1-kraxel@redhat.com>
From: Thomas Huth <thuth@redhat.com>
At the end of the while-loop, either "samples" or "sdl->live" is zero, so
now that we've removed the semaphore code, the content of the while-loop
is always only executed once. Thus we can remove the while-loop now to
get rid of one indentation level here.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-id: 1549336101-17623-3-git-send-email-thuth@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
audio/sdlaudio.c | 45 +++++++++++++++++++--------------------------
1 file changed, 19 insertions(+), 26 deletions(-)
diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c
index 53bfdbf72439..f7ee70b15347 100644
--- a/audio/sdlaudio.c
+++ b/audio/sdlaudio.c
@@ -189,37 +189,30 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
SDLAudioState *s = &glob_sdl;
HWVoiceOut *hw = &sdl->hw;
int samples = len >> hw->info.shift;
+ int to_mix, decr;
- if (s->exit) {
+ if (s->exit || !sdl->live) {
return;
}
- while (samples) {
- int to_mix, decr;
-
- /* dolog ("in callback samples=%d\n", samples); */
-
- if (s->exit || !sdl->live) {
- break;
- }
-
- /* dolog ("in callback live=%d\n", live); */
- to_mix = audio_MIN (samples, sdl->live);
- decr = to_mix;
- while (to_mix) {
- int chunk = audio_MIN (to_mix, hw->samples - hw->rpos);
- struct st_sample *src = hw->mix_buf + hw->rpos;
-
- /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
- hw->clip (buf, src, chunk);
- hw->rpos = (hw->rpos + chunk) % hw->samples;
- to_mix -= chunk;
- buf += chunk << hw->info.shift;
- }
- samples -= decr;
- sdl->live -= decr;
- sdl->decr += decr;
+ /* dolog ("in callback samples=%d live=%d\n", samples, sdl->live); */
+
+ to_mix = audio_MIN(samples, sdl->live);
+ decr = to_mix;
+ while (to_mix) {
+ int chunk = audio_MIN(to_mix, hw->samples - hw->rpos);
+ struct st_sample *src = hw->mix_buf + hw->rpos;
+
+ /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
+ hw->clip(buf, src, chunk);
+ hw->rpos = (hw->rpos + chunk) % hw->samples;
+ to_mix -= chunk;
+ buf += chunk << hw->info.shift;
}
+ samples -= decr;
+ sdl->live -= decr;
+ sdl->decr += decr;
+
/* dolog ("done len=%d\n", len); */
/* SDL2 does not clear the remaining buffer for us, so do it on our own */
--
2.9.3
next prev parent reply other threads:[~2019-02-28 10:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 10:08 [Qemu-devel] [PULL 0/5] Audio 20190228 patches Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 1/5] audio: Use g_strdup_printf instead of manual building a string Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 2/5] audio: Do not check for audio_calloc failure Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 3/5] audio: don't build alsa and sdl by default on linux Gerd Hoffmann
2019-02-28 10:08 ` [Qemu-devel] [PULL 4/5] audio/sdlaudio: Remove the semaphore code Gerd Hoffmann
2019-02-28 10:08 ` Gerd Hoffmann [this message]
2019-02-28 17:35 ` [Qemu-devel] [PULL 0/5] Audio 20190228 patches Peter Maydell
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=20190228100858.28397-6-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/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).