qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Kővágó, Zoltán" <dirty.ice.hu@gmail.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 08/25] sdlaudio: port to the new audio backend api
Date: Sun, 25 Aug 2019 20:46:10 +0200	[thread overview]
Message-ID: <dcff895661435b76f4159d3547b60e6c08cb777c.1566755452.git.DirtY.iCE.hu@gmail.com> (raw)
In-Reply-To: <cover.1566755452.git.DirtY.iCE.hu@gmail.com>

Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
---
 audio/sdlaudio.c | 87 +++++++++++++++++++++++-------------------------
 1 file changed, 42 insertions(+), 45 deletions(-)

diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c
index 14b11f0335..f7ac8cd101 100644
--- a/audio/sdlaudio.c
+++ b/audio/sdlaudio.c
@@ -41,8 +41,6 @@
 
 typedef struct SDLVoiceOut {
     HWVoiceOut hw;
-    size_t live;
-    size_t decr;
 } SDLVoiceOut;
 
 static struct SDLAudioState {
@@ -184,62 +182,59 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
     SDLVoiceOut *sdl = opaque;
     SDLAudioState *s = &glob_sdl;
     HWVoiceOut *hw = &sdl->hw;
-    size_t samples = len >> hw->info.shift;
-    size_t to_mix, decr;
 
-    if (s->exit || !sdl->live) {
+    if (s->exit) {
         return;
     }
 
     /* dolog ("in callback samples=%zu live=%zu\n", samples, sdl->live); */
 
-    to_mix = MIN(samples, sdl->live);
-    decr = to_mix;
-    while (to_mix) {
-        size_t chunk = MIN(to_mix, hw->samples - hw->rpos);
-        struct st_sample *src = hw->mix_buf + hw->rpos;
-
-        /* dolog ("in callback to_mix %zu, chunk %zu\n", to_mix, chunk); */
-        hw->clip(buf, src, chunk);
-        hw->rpos = (hw->rpos + chunk) % hw->samples;
-        to_mix -= chunk;
-        buf += chunk << hw->info.shift;
+    while (hw->pending_emul && len) {
+        size_t write_len;
+        ssize_t start = ((ssize_t) hw->pos_emul) - hw->pending_emul;
+        if (start < 0) {
+            start += hw->size_emul;
+        }
+        assert(start >= 0 && start < hw->size_emul);
+
+        write_len = MIN(MIN(hw->pending_emul, len),
+                        hw->size_emul - start);
+
+        memcpy(buf, hw->buf_emul + start, write_len);
+        hw->pending_emul -= write_len;
+        len -= write_len;
+        buf += write_len;
     }
-    samples -= decr;
-    sdl->live -= decr;
-    sdl->decr += decr;
-
-    /* dolog ("done len=%zu\n", len); */
 
-    /* SDL2 does not clear the remaining buffer for us, so do it on our own */
-    if (samples) {
-        memset(buf, 0, samples << hw->info.shift);
+    /* clear remaining buffer that we couldn't fill with data */
+    if (len) {
+        memset(buf, 0, len);
     }
 }
 
-static size_t sdl_run_out(HWVoiceOut *hw, size_t live)
-{
-    size_t decr;
-    SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
-
-    SDL_LockAudio();
-
-    if (sdl->decr > live) {
-        ldebug ("sdl->decr %d live %d sdl->live %d\n",
-                sdl->decr,
-                live,
-                sdl->live);
+#define SDL_WRAPPER_FUNC(name, ret_type, args_decl, args, fail, unlock) \
+    static ret_type glue(sdl_, name)args_decl                           \
+    {                                                                   \
+        ret_type ret;                                                   \
+                                                                        \
+        SDL_LockAudio();                                                \
+                                                                        \
+        ret = glue(audio_generic_, name)args;                           \
+                                                                        \
+        SDL_UnlockAudio();                                              \
+        return ret;                                                     \
     }
 
-    decr = MIN (sdl->decr, live);
-    sdl->decr -= decr;
+SDL_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size),
+                 (hw, size), *size = 0, sdl_unlock)
+SDL_WRAPPER_FUNC(put_buffer_out_nowrite, size_t,
+                 (HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size),
+                 /*nothing*/, sdl_unlock_and_post)
+SDL_WRAPPER_FUNC(write, size_t,
+                 (HWVoiceOut *hw, void *buf, size_t size), (hw, buf, size),
+                 /*nothing*/, sdl_unlock_and_post)
 
-    sdl->live = live;
-
-    SDL_UnlockAudio();
-
-    return decr;
-}
+#undef SDL_WRAPPER_FUNC
 
 static void sdl_fini_out (HWVoiceOut *hw)
 {
@@ -336,7 +331,9 @@ static void sdl_audio_fini (void *opaque)
 static struct audio_pcm_ops sdl_pcm_ops = {
     .init_out = sdl_init_out,
     .fini_out = sdl_fini_out,
-    .run_out  = sdl_run_out,
+    .write    = sdl_write,
+    .get_buffer_out = sdl_get_buffer_out,
+    .put_buffer_out = sdl_put_buffer_out_nowrite,
     .ctl_out  = sdl_ctl_out,
 };
 
-- 
2.22.0



  parent reply	other threads:[~2019-08-25 18:49 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-25 18:46 [Qemu-devel] [PATCH 00/25] Audio: Mixeng-free 5.1/7.1 audio support Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 01/25] audio: api for mixeng code free backends Kővágó, Zoltán
2019-08-27  5:43   ` Gerd Hoffmann
2019-08-25 18:46 ` [Qemu-devel] [PATCH 02/25] alsaaudio: port to the new audio backend api Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 03/25] coreaudio: " Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 04/25] dsoundaudio: " Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 05/25] noaudio: " Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 06/25] ossaudio: " Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 07/25] paaudio: " Kővágó, Zoltán
2019-08-25 18:46 ` Kővágó, Zoltán [this message]
2019-08-25 18:46 ` [Qemu-devel] [PATCH 10/25] wavaudio: " Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 11/25] audio: remove remains of the old " Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 12/25] audio: unify input and output mixeng buffer management Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 13/25] audio: remove hw->samples, buffer_size_in/out pcm_ops Kővágó, Zoltán
2019-08-27  5:48   ` Gerd Hoffmann
2019-08-25 18:46 ` [Qemu-devel] [PATCH 14/25] audio: common rate control code for timer based outputs Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 15/25] audio: split ctl_* functions into enable_* and volume_* Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 16/25] audio: add mixeng option (documentation) Kővágó, Zoltán
2019-08-26 13:35   ` Eric Blake
2019-08-26 20:04     ` Zoltán Kővágó
2019-08-25 18:46 ` [Qemu-devel] [PATCH 17/25] audio: make mixeng optional Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 19/25] audio: support more than two channels in volume setting Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 20/25] audio: replace shift in audio_pcm_info with bytes_per_frame Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 21/25] audio: basic support for multichannel audio Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 22/25] paaudio: channel-map option Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 23/25] usb-audio: do not count on avail bytes actually available Kővágó, Zoltán
2019-08-25 18:46 ` [Qemu-devel] [PATCH 25/25] usbaudio: change playback counters to 64 bit Kővágó, Zoltán

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=dcff895661435b76f4159d3547b60e6c08cb777c.1566755452.git.DirtY.iCE.hu@gmail.com \
    --to=dirty.ice.hu@gmail.com \
    --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).