From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 1A3A71F66E for ; Sat, 5 Sep 2020 02:12:45 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kENgz-0006qZ-RQ; Sat, 05 Sep 2020 02:12:37 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kENgy-0006qK-Jn for sox-devel@lists.sourceforge.net; Sat, 05 Sep 2020 02:12:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=From:Subject:To:Message-Id:Date:Sender:Reply-To:Cc: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=ZRe65WjgXVNA/alj0K/3XCRPR/4T5r0ZeQBIrdJMq34=; b=QzmuLX25NHTEC4rC8k+44Dk907 UH2yqKO3cAgH9BXWn2/BRILsFLuzgNBWSJO5/MHv5UVWIn3EUUJwxeJFrydbu2Zoj/rIdZP2iACMf XxmdnTETiuBiVXhXU3sP0UUk9khjz9GHw7Dc9uEAyVSYF3a9p5Ey0Ysi+yzf7/ZMx5bw=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=From:Subject:To:Message-Id:Date:Sender:Reply-To:Cc:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=ZRe65WjgXVNA/alj0K/3XCRPR/4T5r0ZeQBIrdJMq34=; b=j5bkBr/sL1lqM6Oyn9lkSiRMzb 2rcB3QoETzplrVaLp7JPTM6heuClpqTfmGqLdXTpVUaePgeFfk+J0hTA7oKNmf46aVB2IFMH4kfRy 4+D++kEQSK9diFK/izETNG39CrUSu7UFGE3Uws1G67fC6xaAUx2D/7cnUQRSX/mpNOTg=; Received: from gw1.zacglen.com ([202.153.210.28] helo=mail.zacglen.com) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kENgs-00CqrF-OD for sox-devel@lists.sourceforge.net; Sat, 05 Sep 2020 02:12:36 +0000 Received: (from local) by mail.zacglen.com (8.14.3/8.14.3) id 0851xmCt004755 for sox-devel@lists.sourceforge.net; Sat, 5 Sep 2020 11:59:48 +1000 Date: Sat, 5 Sep 2020 11:59:48 +1000 Message-Id: <202009050159.0851xmCt004755.mail.zacglen.com@localhost> To: sox-devel@lists.sourceforge.net From: fbk-qriry@zacglen.net X-Headers-End: 1kENgs-00CqrF-OD Subject: silence patch X-BeenThere: sox-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sox-devel@lists.sourceforge.net MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: sox-devel-bounces@lists.sourceforge.net There is a bug in the "silence" effect that appears to have been introduced in 2009 with commit bbb403. In function aboveThreshold() the value being scaled is effectively the result of a sqrt but when it gets scaled the value is not rounded but coarsely truncated instead. Truncation is wrong. Rounding is right. Prior to this commit the value was effectively rounded to the nearest whole value (according to the precision). Without the following patch the "silence" results are considerably different to earlier versions. For example: value old masked current ----- ---------- ------- 0x009bd6ae 0x0000009c 0x009b0000 0x00a170b8 0x000000a1 0x00a10000 The 0x009bd6ae used to be correctly rounded to 0x9c whereas the current version effectively truncates the value to 0x9b. That is a serious flaw that should have been picked up during testing. But better discovered 11 years later by a random member of the public than never. The patch: ====================================================================== --- sox-downstream-sox-14.4.2.0.modified/src/silence.c.jw +++ sox-downstream-sox-14.4.2.0.modified/src/silence.c @@ -277,9 +277,15 @@ { /* When scaling low bit data, noise values got scaled way up */ /* Only consider the original bits when looking for silence */ - sox_sample_t masked_value = value & (-1 << (32 - effp->in_signal.precision)); + double scaled_value; + sox_sample_t rounded_value = value; - double scaled_value = (double)masked_value / SOX_SAMPLE_MAX; + /* before we mask we should round the value */ + if (effp->in_signal.precision < 32) + rounded_value += (1 << (32 - effp->in_signal.precision - 1)); + rounded_value &= (-1 << (32 - effp->in_signal.precision)); + + scaled_value = (double)rounded_value / SOX_SAMPLE_MAX; if (unit == '%') scaled_value *= 100; ====================================================================== :JW _______________________________________________ SoX-devel mailing list SoX-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sox-devel