From nobody Mon Feb 9 07:57:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1566758996; cv=none; d=zoho.com; s=zohoarc; b=CPbX4E7J8F928Rzp51e5pZ3jmXDg7IwS1ykDNsN2vkVfvkY8OE0e8lEF3ZxEhO52Z8Z2Pyc0t/EIZ8Xyv2pO7jvilQ1mBQ7W2zp+SQ0tXKt6dajKoxYgHTfRMgq3YEs++Wujg+AafEVc7X0nvAa9CHdHTza9PCF91B/n5fE8qE0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566758996; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=cz79XjdkmViVpdk1H7R3zTMM+q7tgUGQ9sdBd1DrXRo=; b=BwCEUr9ydJ6lF+x0ExRkHAuuOnczQgjpA7izWKF1oBTq9edpBxzwATLOgRMXHn+ovutKIkNzehAPQKl81BdSmpeZAkUIqTHYlaiI8O2zuKzuHDgwvMEQOd8csR+6+zREyTcLzXOpYL7EI8NOrGsax5XuZnY3iEpy75kmgT19EXM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566758996464988.8773623446186; Sun, 25 Aug 2019 11:49:56 -0700 (PDT) Received: from localhost ([::1]:45698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1xaN-00047u-0L for importer@patchew.org; Sun, 25 Aug 2019 14:49:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57706) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1xXG-0001BK-D5 for qemu-devel@nongnu.org; Sun, 25 Aug 2019 14:46:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1xXF-0004ng-6J for qemu-devel@nongnu.org; Sun, 25 Aug 2019 14:46:42 -0400 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:42397) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i1xXF-0004nV-1z for qemu-devel@nongnu.org; Sun, 25 Aug 2019 14:46:41 -0400 Received: by mail-qk1-x743.google.com with SMTP id 201so12427582qkm.9 for ; Sun, 25 Aug 2019 11:46:41 -0700 (PDT) Received: from nullptr.home.dirty-ice.org (2a01-036c-0113-61b1-0000-0000-0000-0005.pool6.digikabel.hu. [2a01:36c:113:61b1::5]) by smtp.gmail.com with ESMTPSA id d3sm5348870qtq.32.2019.08.25.11.46.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Aug 2019 11:46:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cz79XjdkmViVpdk1H7R3zTMM+q7tgUGQ9sdBd1DrXRo=; b=QcuzilRIE/pH6kRXpxc2nxhJBJWV2PBVN7j1LjVjLeYrSlioi8R6xm3/hC0310PPeb k8uzCLp8HDok/J8k28IKGGouqKa+EcHiX7RL8CwaL8bxrMhCWW18M6Q5qOTrOssn25LJ mVH+QtoqT/c8gbtiQeYTChnhIoQ9qbu10/mpIGhENBRE/jVs0toXrMzJaKuzEYZ4jOyy 1mZ8y428PcdYrWdFQ7suZE8uJUo+Pv2VJ01IdYrDWdGnHysJUOqZieJ/vnud64ifLnHE ZF0tcHf8ZoqCfY3KwumpU1jjDzTvtdN0YCcB+vIU/o+FxLv18koOW/oH4vPtk6DRc2sS xm/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cz79XjdkmViVpdk1H7R3zTMM+q7tgUGQ9sdBd1DrXRo=; b=DM8d+FgV5NsjOxDjU49c2TWqz//giFY0pPefcUf110yBPMKYJHcdPylUhCHStDSJeS ppZ5KV+bkEnxwq3MtpUf8A5yEH9gLuFrgk4bwr46lnq/nJGYxpBdr+ikm7kH/Bv709L+ GT/7keK8QnH6pQcDUOuQHRsrRPwnYoVIKrwzENrEDj0D+lt/SG4vQN4nSCGdNYgjHO7p TMt6TtllLGWgTtlHBZzcUGi7ZFU6sWLWEzqtbURMzWEAX+P5pxKg1R7G85NYU6NrajXm YMgcnM8uKPV5cs0t3qDB5vztBZY2zsv4w8czgjxx3V2aRo5JWuIDLCqlA/JF+uHBoZJE OqCQ== X-Gm-Message-State: APjAAAVXvR2RF6dgJCVbmaUWvpCE75zMFLF97oohdupugtZAcHddN/+c IjbjyeakUX+PqS6tTRUt09ITdp/hALA= X-Google-Smtp-Source: APXvYqyF+NSlXzCQZvZZO/29FPVRg4wVW85zDGPu/mbniFJWpzh/N7BIc14l4BPeCCS3q5/2ip6LSw== X-Received: by 2002:a05:620a:68b:: with SMTP id f11mr7666240qkh.339.1566758800536; Sun, 25 Aug 2019 11:46:40 -0700 (PDT) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= To: qemu-devel@nongnu.org Date: Sun, 25 Aug 2019 20:46:10 +0200 Message-Id: X-Mailer: git-send-email 2.22.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::743 Subject: [Qemu-devel] [PATCH 08/25] sdlaudio: port to the new audio backend api X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: K=C5=91v=C3=A1g=C3=B3, Zolt=C3=A1n --- 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 @@ =20 typedef struct SDLVoiceOut { HWVoiceOut hw; - size_t live; - size_t decr; } SDLVoiceOut; =20 static struct SDLAudioState { @@ -184,62 +182,59 @@ static void sdl_callback (void *opaque, Uint8 *buf, i= nt len) SDLVoiceOut *sdl =3D opaque; SDLAudioState *s =3D &glob_sdl; HWVoiceOut *hw =3D &sdl->hw; - size_t samples =3D len >> hw->info.shift; - size_t to_mix, decr; =20 - if (s->exit || !sdl->live) { + if (s->exit) { return; } =20 /* dolog ("in callback samples=3D%zu live=3D%zu\n", samples, sdl->live= ); */ =20 - to_mix =3D MIN(samples, sdl->live); - decr =3D to_mix; - while (to_mix) { - size_t chunk =3D MIN(to_mix, hw->samples - hw->rpos); - struct st_sample *src =3D hw->mix_buf + hw->rpos; - - /* dolog ("in callback to_mix %zu, chunk %zu\n", to_mix, chunk); */ - hw->clip(buf, src, chunk); - hw->rpos =3D (hw->rpos + chunk) % hw->samples; - to_mix -=3D chunk; - buf +=3D chunk << hw->info.shift; + while (hw->pending_emul && len) { + size_t write_len; + ssize_t start =3D ((ssize_t) hw->pos_emul) - hw->pending_emul; + if (start < 0) { + start +=3D hw->size_emul; + } + assert(start >=3D 0 && start < hw->size_emul); + + write_len =3D MIN(MIN(hw->pending_emul, len), + hw->size_emul - start); + + memcpy(buf, hw->buf_emul + start, write_len); + hw->pending_emul -=3D write_len; + len -=3D write_len; + buf +=3D write_len; } - samples -=3D decr; - sdl->live -=3D decr; - sdl->decr +=3D decr; - - /* dolog ("done len=3D%zu\n", len); */ =20 - /* SDL2 does not clear the remaining buffer for us, so do it on our ow= n */ - 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); } } =20 -static size_t sdl_run_out(HWVoiceOut *hw, size_t live) -{ - size_t decr; - SDLVoiceOut *sdl =3D (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 =3D glue(audio_generic_, name)args; \ + \ + SDL_UnlockAudio(); \ + return ret; \ } =20 - decr =3D MIN (sdl->decr, live); - sdl->decr -=3D decr; +SDL_WRAPPER_FUNC(get_buffer_out, void *, (HWVoiceOut *hw, size_t *size), + (hw, size), *size =3D 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) =20 - sdl->live =3D live; - - SDL_UnlockAudio(); - - return decr; -} +#undef SDL_WRAPPER_FUNC =20 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 =3D { .init_out =3D sdl_init_out, .fini_out =3D sdl_fini_out, - .run_out =3D sdl_run_out, + .write =3D sdl_write, + .get_buffer_out =3D sdl_get_buffer_out, + .put_buffer_out =3D sdl_put_buffer_out_nowrite, .ctl_out =3D sdl_ctl_out, }; =20 --=20 2.22.0