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 801B31F66E for ; Sun, 6 Sep 2020 04:17:00 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1kEm6b-0008Vw-W3; Sun, 06 Sep 2020 04:16:41 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kEm6a-0008Vp-9U for sox-devel@lists.sourceforge.net; Sun, 06 Sep 2020 04:16:40 +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=bLT4fMxntQe4Ylun5Q7m7VtK/TwVYU9ZMp462kFHKWM=; b=WnJ9pdYoa1YGH+DUIyDCT3y37f IQ1tU5RLV8BIIffB0WxPpwp4DgorK4+jEvkRKHz0CV9MfFVdeX0DOoD9Emm9MgeCUiSz8tSQvZwSv aU+daAY2XjKK+p16V8CNlhQZPYiWnxry98aJ8PIoN3gxxi+ClqolXZxtRgOqd/al/Q4Y=; 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=bLT4fMxntQe4Ylun5Q7m7VtK/TwVYU9ZMp462kFHKWM=; b=clmP6Zx+KRgtKnas1C6vujNOUe yGi6zqEwERefkP6fSZDunKkTBGrZkPprbXKkt1WLI+aUYdRJP2W7kvCX+WrkGvC5r5PAdTp78ZPUX XvzaSXxsteChWb2QH5JeHLEAIracLD/54Thn+u3US898HSuhW+hdSnYeIhZRKC8b4BoI=; Received: from gw1.zacglen.com ([202.153.210.28] helo=mail.zacglen.com) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1kEm6W-00EXA6-Ed for sox-devel@lists.sourceforge.net; Sun, 06 Sep 2020 04:16:40 +0000 Received: (from local) by mail.zacglen.com (8.14.3/8.14.3) id 0864GFf8029685 for sox-devel@lists.sourceforge.net; Sun, 6 Sep 2020 14:16:15 +1000 Date: Sun, 6 Sep 2020 14:16:15 +1000 Message-Id: <202009060416.0864GFf8029685.mail.zacglen.com@localhost> To: sox-devel@lists.sourceforge.net From: fbk-qriry@zacglen.net X-Headers-End: 1kEm6W-00EXA6-Ed Subject: silence additional 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 Further to my previous "silence" patch I have discovered that there is another error involving the rms calculations. Initially, and after a reset, the rms sample window is empty yet the rms calculation always uses the window size as the calculation denominator. This will make the rms value appear artificially low to start with. Instead, an actual count of samples should be used. Incidentally, I think that the hard-coded 1/50 for selection of a window size should also be parametized. Sometimes a size using 1/20 (100 milliseconds when stereo) can be more appropriate than the very small 40 millisecond hard-coded sample window size. The following is the updated patch: =================================================================== --- sox-downstream-sox-14.4.2.0.modified/src/silence.c.jw +++ sox-downstream-sox-14.4.2.0.modified/src/silence.c @@ -55,6 +55,7 @@ double *window_current; double *window_end; size_t window_size; + size_t window_count; double rms_sum; char leave_silence; @@ -73,6 +74,7 @@ silence->window_current = silence->window; silence->window_end = silence->window + silence->window_size; + silence->window_count = 0; silence->rms_sum = 0; } @@ -277,9 +279,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 (a sqrt irrational) */ + 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; @@ -294,12 +302,17 @@ priv_t * silence = (priv_t *) effp->priv; double new_sum; sox_sample_t rms; + size_t count; new_sum = silence->rms_sum; new_sum -= *silence->window_current; new_sum += ((double)sample * (double)sample); - rms = sqrt(new_sum / silence->window_size); + count = silence->window_count; + if (count < silence->window_size) + count++; + + rms = sqrt(new_sum / count); return (rms); } @@ -315,6 +328,9 @@ silence->window_current++; if (silence->window_current >= silence->window_end) silence->window_current = silence->window; + + if (silence->window_count < silence->window_size) + silence->window_count++; } /* Process signed long samples from ibuf to obuf. */ =================================================================== :JW _______________________________________________ SoX-devel mailing list SoX-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sox-devel