From nobody Tue Feb 10 23:13:24 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696746400227433.4020240798077; Sat, 7 Oct 2023 23:26:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qpNCr-00085J-4h; Sun, 08 Oct 2023 02:24:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qpNCq-000842-50 for qemu-devel@nongnu.org; Sun, 08 Oct 2023 02:24:00 -0400 Received: from mout.kundenserver.de ([212.227.17.10]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qpNCo-0007lQ-Eh for qemu-devel@nongnu.org; Sun, 08 Oct 2023 02:23:59 -0400 Received: from quad ([82.142.8.70]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MfqCF-1rValx1dKj-00gIVt; Sun, 08 Oct 2023 08:23:57 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Cc: Mark Cave-Ayland , Laurent Vivier Subject: [PULL 08/20] asc: generate silence if FIFO empty but engine still running Date: Sun, 8 Oct 2023 08:23:37 +0200 Message-ID: <20231008062349.2733552-9-laurent@vivier.eu> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231008062349.2733552-1-laurent@vivier.eu> References: <20231008062349.2733552-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Nod/Hl+yXfnuP8JYoN5qjxrm6MUc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jsQjLBIE0nOOpr/hTDEoI7TL6ym/bzbOkGh1vQWQgO7QXuhAePk3fFO7RmC vyR/ki5Ls2ZjkOg== Received-SPF: pass (zohomail.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; Received-SPF: none client-ip=212.227.17.10; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.376, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1696746401032100001 Content-Type: text/plain; charset="utf-8" From: Mark Cave-Ayland MacOS (un)helpfully leaves the FIFO engine running even when all the sample= s have been written to the hardware, and expects the FIFO status flags and IRQ to = be updated continuously. There is an additional problem in that not all audio backends guarantee an all-zero output when there is no FIFO data available, in particular the Win= dows dsound backend which re-uses its internal circular buffer causing the last = played sound to loop indefinitely. Whilst this is effectively a bug in the Windows dsound backend, work around= it for now using a simple heuristic: if the FIFO remains empty for half a cycle (~23ms) then continuously fill the generated buffer with empty silence. Signed-off-by: Mark Cave-Ayland Reviewed-by: Laurent Vivier Message-ID: <20231004083806.757242-9-mark.cave-ayland@ilande.co.uk> Signed-off-by: Laurent Vivier --- include/hw/audio/asc.h | 2 ++ hw/audio/asc.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/hw/audio/asc.h b/include/hw/audio/asc.h index d9412815c324..4741f92c4613 100644 --- a/include/hw/audio/asc.h +++ b/include/hw/audio/asc.h @@ -68,6 +68,8 @@ struct ASCState { int samples; int shift; =20 + uint8_t *silentbuf; + /* Time when we were last able to generate samples */ int64_t fifo_empty_ns; =20 diff --git a/hw/audio/asc.c b/hw/audio/asc.c index 9084708eafab..0f36b4ce9b6f 100644 --- a/hw/audio/asc.c +++ b/hw/audio/asc.c @@ -341,6 +341,21 @@ static void asc_out_cb(void *opaque, int free_b) } =20 if (!generated) { + /* Workaround for audio underflow bug on Windows dsound backend */ + int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + int silent_samples =3D muldiv64(now - s->fifo_empty_ns, + NANOSECONDS_PER_SECOND, ASC_FREQ); + + if (silent_samples > ASC_FIFO_CYCLE_TIME / 2) { + /* + * No new FIFO data within half a cycle time (~23ms) so fill t= he + * entire available buffer with silence. This prevents an issue + * with the Windows dsound backend whereby the sound appears to + * loop because the FIFO has run out of data, and the driver + * reuses the stale content in its circular audio buffer. + */ + AUD_write(s->voice, s->silentbuf, samples << s->shift); + } return; } =20 @@ -618,6 +633,7 @@ static void asc_unrealize(DeviceState *dev) ASCState *s =3D ASC(dev); =20 g_free(s->mixbuf); + g_free(s->silentbuf); =20 AUD_remove_card(&s->card); } @@ -642,6 +658,9 @@ static void asc_realize(DeviceState *dev, Error **errp) s->samples =3D AUD_get_buffer_size_out(s->voice) >> s->shift; s->mixbuf =3D g_malloc0(s->samples << s->shift); =20 + s->silentbuf =3D g_malloc0(s->samples << s->shift); + memset(s->silentbuf, 0x80, s->samples << s->shift); + /* Add easc registers if required */ if (s->type =3D=3D ASC_TYPE_EASC) { memory_region_add_subregion(&s->asc, ASC_EXTREG_OFFSET, --=20 2.41.0