From nobody Mon Feb 9 06:01:55 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; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154933673438020.472832939434852; Mon, 4 Feb 2019 19:18:54 -0800 (PST) Received: from localhost ([127.0.0.1]:53231 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrG6-0008Ux-UJ for importer@patchew.org; Mon, 04 Feb 2019 22:18:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gqrEM-0007aV-Nv for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:17:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gqr6L-0002c9-GJ for qemu-devel@nongnu.org; Mon, 04 Feb 2019 22:08:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38250) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gqr6L-0002b5-8t; Mon, 04 Feb 2019 22:08:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A3C378666F; Tue, 5 Feb 2019 03:08:36 +0000 (UTC) Received: from thuth.com (ovpn-116-65.phx2.redhat.com [10.3.116.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D64B60CCE; Tue, 5 Feb 2019 03:08:35 +0000 (UTC) From: Thomas Huth To: Gerd Hoffmann , qemu-devel@nongnu.org Date: Tue, 5 Feb 2019 04:08:21 +0100 Message-Id: <1549336101-17623-3-git-send-email-thuth@redhat.com> In-Reply-To: <1549336101-17623-1-git-send-email-thuth@redhat.com> References: <1549336101-17623-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 05 Feb 2019 03:08:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/2] audio/sdlaudio: Simplify the sdl_callback function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=20Zolt=C3=A1n?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- audio/sdlaudio.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/audio/sdlaudio.c b/audio/sdlaudio.c index 53bfdbf..f7ee70b 100644 --- a/audio/sdlaudio.c +++ b/audio/sdlaudio.c @@ -189,37 +189,30 @@ static void sdl_callback (void *opaque, Uint8 *buf, i= nt len) SDLAudioState *s =3D &glob_sdl; HWVoiceOut *hw =3D &sdl->hw; int samples =3D len >> hw->info.shift; + int to_mix, decr; =20 - if (s->exit) { + if (s->exit || !sdl->live) { return; } =20 - while (samples) { - int to_mix, decr; - - /* dolog ("in callback samples=3D%d\n", samples); */ - - if (s->exit || !sdl->live) { - break; - } - - /* dolog ("in callback live=3D%d\n", live); */ - to_mix =3D audio_MIN (samples, sdl->live); - decr =3D to_mix; - while (to_mix) { - int chunk =3D audio_MIN (to_mix, hw->samples - hw->rpos); - struct st_sample *src =3D hw->mix_buf + hw->rpos; - - /* dolog ("in callback to_mix %d, chunk %d\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; - } - samples -=3D decr; - sdl->live -=3D decr; - sdl->decr +=3D decr; + /* dolog ("in callback samples=3D%d live=3D%d\n", samples, sdl->live);= */ + + to_mix =3D audio_MIN(samples, sdl->live); + decr =3D to_mix; + while (to_mix) { + int chunk =3D audio_MIN(to_mix, hw->samples - hw->rpos); + struct st_sample *src =3D hw->mix_buf + hw->rpos; + + /* dolog ("in callback to_mix %d, chunk %d\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; } + samples -=3D decr; + sdl->live -=3D decr; + sdl->decr +=3D decr; + /* dolog ("done len=3D%d\n", len); */ =20 /* SDL2 does not clear the remaining buffer for us, so do it on our ow= n */ --=20 1.8.3.1