sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
From: "Måns Rullgård" <mans@mansr.com>
To: fbk-qriry@zacglen.net
Cc: sox-devel@lists.sourceforge.net
Subject: Re: silence patch
Date: Sat, 05 Sep 2020 12:16:07 +0100	[thread overview]
Message-ID: <yw1xft7wiidk.fsf@mansr.com> (raw)
In-Reply-To: <202009050159.0851xmCt004755.mail.zacglen.com@localhost> (fbk-qriry@zacglen.net's message of "Sat, 5 Sep 2020 11:59:48 +1000")

fbk-qriry@zacglen.net writes:

> 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 only serious flaw I see here is your condescending tone.

> 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
>

-- 
Måns Rullgård


_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

      reply	other threads:[~2020-09-05 11:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-05  1:59 silence patch fbk-qriry
2020-09-05 11:16 ` Måns Rullgård [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.sourceforge.net/lists/listinfo/sox-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yw1xft7wiidk.fsf@mansr.com \
    --to=sox-devel@lists.sourceforge.net \
    --cc=fbk-qriry@zacglen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).