From nobody Tue Feb 10 11:33:44 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 1677265577109409.2657896822411; Fri, 24 Feb 2023 11:06:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVdOR-0001tg-Th; Fri, 24 Feb 2023 14:06:07 -0500 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 1pVdOQ-0001sJ-Q4 for qemu-devel@nongnu.org; Fri, 24 Feb 2023 14:06:06 -0500 Received: from mailout05.t-online.de ([194.25.134.82]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVdOP-0003mf-5v for qemu-devel@nongnu.org; Fri, 24 Feb 2023 14:06:06 -0500 Received: from fwd79.dcpf.telekom.de (fwd79.aul.t-online.de [10.223.144.105]) by mailout05.t-online.de (Postfix) with SMTP id 8DAD65C8C; Fri, 24 Feb 2023 20:06:03 +0100 (CET) Received: from linpower.localnet ([84.175.228.75]) by fwd79.t-online.de with (TLSv1.3:TLS_AES_256_GCM_SHA384 encrypted) esmtp id 1pVdOK-2mPfE10; Fri, 24 Feb 2023 20:06:00 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 9111A335521; Fri, 24 Feb 2023 20:05:55 +0100 (CET) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Cc: Christian Schoenebeck , Mark Cave-Ayland , qemu-devel@nongnu.org Subject: [PATCH v3 03/15] audio: make the resampling code greedy Date: Fri, 24 Feb 2023 20:05:43 +0100 Message-Id: <20230224190555.7409-3-vr_qemu@t-online.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-TOI-EXPURGATEID: 150726::1677265560-D5BB19DF-638E9B95/0/0 CLEAN NORMAL X-TOI-MSGID: 2898f854-dfa2-4616-b22c-c5893ba3f450 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=194.25.134.82; envelope-from=volker.ruemelin@t-online.de; helo=mailout05.t-online.de X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: 1677265578592100007 Read the maximum possible number of audio frames instead of the minimum necessary number of frames when the audio stream is downsampled and the output buffer is limited. This makes the function symmetrical to upsampling when the input buffer is limited. The maximum possible number of frames is written here. With this change it's easier to calculate the exact number of audio frames the resample function will read or write. These two functions will be introduced later. Acked-by: Mark Cave-Ayland Acked-by: Marc-Andr=C3=A9 Lureau Signed-off-by: Volker R=C3=BCmelin --- audio/rate_template.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/audio/rate_template.h b/audio/rate_template.h index b432719ebb..6648f0d2e5 100644 --- a/audio/rate_template.h +++ b/audio/rate_template.h @@ -40,8 +40,6 @@ void NAME (void *opaque, struct st_sample *ibuf, struct s= t_sample *obuf, int64_t t; #endif =20 - ilast =3D rate->ilast; - istart =3D ibuf; iend =3D ibuf + *isamp; =20 @@ -59,15 +57,17 @@ void NAME (void *opaque, struct st_sample *ibuf, struct= st_sample *obuf, return; } =20 - while (obuf < oend) { + /* without input samples, there's nothing to do */ + if (ibuf >=3D iend) { + *osamp =3D 0; + return; + } =20 - /* Safety catch to make sure we have input samples. */ - if (ibuf >=3D iend) { - break; - } + ilast =3D rate->ilast; =20 - /* read as many input samples so that ipos > opos */ + while (true) { =20 + /* read as many input samples so that ipos > opos */ while (rate->ipos <=3D (rate->opos >> 32)) { ilast =3D *ibuf++; rate->ipos++; @@ -78,6 +78,11 @@ void NAME (void *opaque, struct st_sample *ibuf, struct = st_sample *obuf, } } =20 + /* make sure that the next output sample can be written */ + if (obuf >=3D oend) { + break; + } + icur =3D *ibuf; =20 /* wrap ipos and opos around long before they overflow */ --=20 2.35.3