aboutsummaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2019-02-05 04:08:21 +0100
committerGerd Hoffmann <kraxel@redhat.com>2019-02-28 10:30:08 +0100
commit9399ef168377d9e7f2e33b1c2eb61751aa1b72fa (patch)
treecc16bfd8cc27b220f73b5ac5b0af145d04c59294 /audio
parent8a7816c4ac13e6ba61de2be1e4e93ed71bc26266 (diff)
audio/sdlaudio: Simplify the sdl_callback function
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>
Diffstat (limited to 'audio')
-rw-r--r--audio/sdlaudio.c45
1 files changed, 19 insertions, 26 deletions
diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c
index 53bfdbf724..f7ee70b153 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 */