From nobody Tue Feb 10 01:32:30 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 1675709841232633.923662774983; Mon, 6 Feb 2023 10:57:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pP6cD-0005aC-MO; Mon, 06 Feb 2023 13:53:22 -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 1pP6cB-0005WP-IN for qemu-devel@nongnu.org; Mon, 06 Feb 2023 13:53:19 -0500 Received: from mailout01.t-online.de ([194.25.134.80]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pP6c9-0005XR-Ok for qemu-devel@nongnu.org; Mon, 06 Feb 2023 13:53:19 -0500 Received: from fwd72.dcpf.telekom.de (fwd72.aul.t-online.de [10.223.144.98]) by mailout01.t-online.de (Postfix) with SMTP id 395ADBEB6; Mon, 6 Feb 2023 19:53:16 +0100 (CET) Received: from linpower.localnet ([79.208.25.151]) by fwd72.t-online.de with (TLSv1.3:TLS_AES_256_GCM_SHA384 encrypted) esmtp id 1pP6c7-3AMqNF0; Mon, 6 Feb 2023 19:53:15 +0100 Received: by linpower.localnet (Postfix, from userid 1000) id 9D00C2006CF; Mon, 6 Feb 2023 19:52:37 +0100 (CET) From: =?UTF-8?q?Volker=20R=C3=BCmelin?= To: Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Cc: qemu-devel@nongnu.org, Christian Schoenebeck , Mark Cave-Ayland Subject: [PATCH v2 17/17] audio: remove sw->ratio Date: Mon, 6 Feb 2023 19:52:37 +0100 Message-Id: <20230206185237.8358-17-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::1675709595-81AEBD99-64F0BB90/2/50744550798 SUSPECT URL-COUNT X-TOI-MSGID: 7057a69a-cd9a-4033-b082-81c90fcb8e0c 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.80; envelope-from=volker.ruemelin@t-online.de; helo=mailout01.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_H2=-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: 1675709842296100001 Simplify the resample buffer size calculation. For audio playback we have sw->ratio =3D ((int64_t)sw->hw->info.freq << 32) / sw->info.freq; samples =3D ((int64_t)sw->HWBUF.size << 32) / sw->ratio; This can be simplified to samples =3D muldiv64(sw->HWBUF.size, sw->info.freq, sw->hw->info.freq); For audio recording we have sw->ratio =3D ((int64_t)sw->info.freq << 32) / sw->hw->info.freq; samples =3D (int64_t)sw->HWBUF.size * sw->ratio >> 32; This can be simplified to samples =3D muldiv64(sw->HWBUF.size, sw->info.freq, sw->hw->info.freq); With hw =3D sw->hw this becomes in both cases samples =3D muldiv64(HWBUF.size, sw->info.freq, hw->info.freq); Now that sw->ratio is no longer needed, remove sw->ratio. Acked-by: Mark Cave-Ayland Signed-off-by: Volker R=C3=BCmelin --- audio/audio.c | 1 - audio/audio_int.h | 2 -- audio/audio_template.h | 30 +++++++++--------------------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/audio/audio.c b/audio/audio.c index 4836ab8ca8..70b096713c 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -478,7 +478,6 @@ static int audio_attach_capture (HWVoiceOut *hw) sw->info =3D hw->info; sw->empty =3D 1; sw->active =3D hw->enabled; - sw->ratio =3D ((int64_t) hw_cap->info.freq << 32) / sw->info.freq; sw->vol =3D nominal_volume; sw->rate =3D st_rate_start (sw->info.freq, hw_cap->info.freq); QLIST_INSERT_HEAD (&hw_cap->sw_head, sw, entries); diff --git a/audio/audio_int.h b/audio/audio_int.h index 8b163e1759..d51d63f08d 100644 --- a/audio/audio_int.h +++ b/audio/audio_int.h @@ -108,7 +108,6 @@ struct SWVoiceOut { AudioState *s; struct audio_pcm_info info; t_sample *conv; - int64_t ratio; STSampleBuffer resample_buf; void *rate; size_t total_hw_samples_mixed; @@ -126,7 +125,6 @@ struct SWVoiceIn { AudioState *s; int active; struct audio_pcm_info info; - int64_t ratio; void *rate; size_t total_hw_samples_acquired; STSampleBuffer resample_buf; diff --git a/audio/audio_template.h b/audio/audio_template.h index 7e116426c7..e42326c20d 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -108,32 +108,23 @@ static void glue (audio_pcm_sw_free_resources_, TYPE)= (SW *sw) static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw) { HW *hw =3D sw->hw; - int samples; + uint64_t samples; =20 if (!glue(audio_get_pdo_, TYPE)(sw->s->dev)->mixing_engine) { return 0; } =20 -#ifdef DAC - samples =3D ((int64_t)sw->HWBUF.size << 32) / sw->ratio; -#else - samples =3D (int64_t)sw->HWBUF.size * sw->ratio >> 32; -#endif - if (audio_bug(__func__, samples < 0)) { - dolog("Can not allocate buffer for `%s' (%d samples)\n", - SW_NAME(sw), samples); - return -1; - } - + samples =3D muldiv64(HWBUF.size, sw->info.freq, hw->info.freq); if (samples =3D=3D 0) { - size_t f_fe_min; + uint64_t f_fe_min; + uint64_t f_be =3D (uint32_t)hw->info.freq; =20 /* f_fe_min =3D ceil(1 [frames] * f_be [Hz] / size_be [frames]) */ - f_fe_min =3D (hw->info.freq + HWBUF.size - 1) / HWBUF.size; + f_fe_min =3D (f_be + HWBUF.size - 1) / HWBUF.size; qemu_log_mask(LOG_UNIMP, AUDIO_CAP ": The guest selected a " NAME " sample ra= te" - " of %d Hz for %s. Only sample rates >=3D %zu Hz are" - " supported.\n", + " of %d Hz for %s. Only sample rates >=3D %" PRIu64 = " Hz" + " are supported.\n", sw->info.freq, sw->name, f_fe_min); return -1; } @@ -141,9 +132,9 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (= SW *sw) /* * Allocate one additional audio frame that is needed for upsampling * if the resample buffer size is small. For large buffer sizes take - * care of overflows. + * care of overflows and truncation. */ - samples =3D samples < INT_MAX ? samples + 1 : INT_MAX; + samples =3D samples < SIZE_MAX ? samples + 1 : SIZE_MAX; sw->resample_buf.buffer =3D g_new0(st_sample, samples); sw->resample_buf.size =3D samples; sw->resample_buf.pos =3D 0; @@ -170,11 +161,8 @@ static int glue (audio_pcm_sw_init_, TYPE) ( sw->hw =3D hw; sw->active =3D 0; #ifdef DAC - sw->ratio =3D ((int64_t) sw->hw->info.freq << 32) / sw->info.freq; sw->total_hw_samples_mixed =3D 0; sw->empty =3D 1; -#else - sw->ratio =3D ((int64_t) sw->info.freq << 32) / sw->hw->info.freq; #endif =20 if (sw->info.is_float) { --=20 2.35.3