From patchwork Fri May 5 15:52:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13232814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C30C7C77B75 for ; Fri, 5 May 2023 15:55:03 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 8A6EF2D69; Fri, 5 May 2023 17:54:11 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8A6EF2D69 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1683302101; bh=c3REkVFlo9Bl3OSMGTPE0qe+gE7XqT0DcsHqllG2GmA=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=LWebTMZlYtRhiWt9yV3t64CH8xm/UrxLt1Wgh5ogxZlEvk8gfiLmxYjQxz70lcWPo SI5DLHEFrajcgpFe3I20w76zyPKMTyiS7wkojsxBz8xPsZ6Ejga9XaSpVHY+he1Dkb xcTYK5G/iYkFa+c45KvGPtS3T6u5h7tflzgqa/u8= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id C26D2F80578; Fri, 5 May 2023 17:53:05 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 88501F80558; Fri, 5 May 2023 17:52:57 +0200 (CEST) Received: from bluemchen.kde.org (bluemchen.kde.org [209.51.188.41]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id B7CF5F8052E for ; Fri, 5 May 2023 17:52:46 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B7CF5F8052E Received: from ugly.fritz.box (localhost [127.0.0.1]) by bluemchen.kde.org (Postfix) with ESMTP id 452E523E9C; Fri, 5 May 2023 11:52:45 -0400 (EDT) Received: by ugly.fritz.box (masqmail 0.3.4, from userid 1000) id 1puxjh-hVy-00; Fri, 05 May 2023 17:52:45 +0200 From: Oswald Buddenhagen To: alsa-devel@alsa-project.org Subject: [PATCH v2 3/7] ALSA: pcm: fix playback silence - correct incremental silencing Date: Fri, 5 May 2023 17:52:40 +0200 Message-Id: <20230505155244.2312199-3-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.40.0.152.g15d061e6df In-Reply-To: <20230505155244.2312199-1-oswald.buddenhagen@gmx.de> References: <20230505155244.2312199-1-oswald.buddenhagen@gmx.de> MIME-Version: 1.0 Message-ID-Hash: SEZYZOS52U3HWM6JO2RBHKYGCSUPARZV X-Message-ID-Hash: SEZYZOS52U3HWM6JO2RBHKYGCSUPARZV X-MailFrom: ossi@kde.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Takashi Iwai X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Jaroslav Kysela Commit 9a826ddba6e ("[ALSA] pcm core: fix silence_start calculations") came with exactly the right commit message, but the patch just made things broken in a different way: We'd fill at a too low address if the area was already partially zeroed, so we'd under-fill. This affected both thresholded mode (where it was somewhat less likely) and top-up mode (where it would be the case consistently). Co-developed-by: Oswald Buddenhagen Signed-off-by: Oswald Buddenhagen Signed-off-by: Jaroslav Kysela --- v2: - rewrote commit message - postponed the addition of comments to a subsequent patch where it makes more sense - dropped the part which the subsequent refactoring obsoletes. this reduces the patch to its essentials, making it easier to understand, and reducing churn. --- sound/core/pcm_lib.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 6ad67e7e740c..5ddb74a12030 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -87,29 +87,25 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram if (avail > runtime->buffer_size) avail = runtime->buffer_size; runtime->silence_filled = avail > 0 ? avail : 0; - runtime->silence_start = (runtime->status->hw_ptr + - runtime->silence_filled) % - runtime->boundary; + runtime->silence_start = runtime->status->hw_ptr; } else { ofs = runtime->status->hw_ptr; frames = new_hw_ptr - ofs; if ((snd_pcm_sframes_t)frames < 0) frames += runtime->boundary; runtime->silence_filled -= frames; if ((snd_pcm_sframes_t)runtime->silence_filled < 0) { runtime->silence_filled = 0; - runtime->silence_start = new_hw_ptr; - } else { - runtime->silence_start = ofs; } + runtime->silence_start = new_hw_ptr; } frames = runtime->buffer_size - runtime->silence_filled; } if (snd_BUG_ON(frames > runtime->buffer_size)) return; if (frames == 0) return; - ofs = runtime->silence_start % runtime->buffer_size; + ofs = (runtime->silence_start + runtime->silence_filled) % runtime->buffer_size; while (frames > 0) { transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames; err = fill_silence_frames(substream, ofs, transfer);