avfilter/af_silenceremove: add standard deviation detector

Useful in cases audio samples DC offset is not ~0.0, where
other detectors will fail to detect silence.
pull/389/head
Paul B Mahol 1 year ago
parent aa4acc111e
commit f02964aee1
  1. 2
      doc/filters.texi
  2. 9
      libavfilter/af_silenceremove.c
  3. 17
      libavfilter/silenceremove_template.c

@ -6474,6 +6474,8 @@ Maximum of absolute values of samples in moving window.
Median of absolute values of samples in moving window.
@item ptp
Absolute of max peak to min peak difference of samples in moving window.
@item dev
Standard deviation of values of samples in moving window.
@end table
Default value is @code{rms}.

@ -38,6 +38,7 @@ enum SilenceDetect {
D_PEAK,
D_MEDIAN,
D_PTP,
D_DEV,
D_NB
};
@ -146,6 +147,7 @@ static const AVOption silenceremove_options[] = {
{ "peak", "use max absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" },
{ "median", "use median of absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_MEDIAN},0, 0, AF, "detection" },
{ "ptp", "use absolute of max peak to min peak difference", 0, AV_OPT_TYPE_CONST, {.i64=D_PTP}, 0, 0, AF, "detection" },
{ "dev", "use standard deviation from values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_DEV}, 0, 0, AF, "detection" },
{ "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF },
{ "timestamp", "set how every output frame timestamp is processed", OFFSET(timestamp_mode), AV_OPT_TYPE_INT, {.i64=TS_WRITE}, 0, TS_NB-1, AF, "timestamp" },
{ "write", "full timestamps rewrite, keep only the start time", 0, AV_OPT_TYPE_CONST, {.i64=TS_WRITE}, 0, 0, AF, "timestamp" },
@ -230,6 +232,9 @@ static int config_output(AVFilterLink *outlink)
case D_RMS:
s->cache_size = 1;
break;
case D_DEV:
s->cache_size = 2;
break;
case D_MEDIAN:
case D_PEAK:
case D_PTP:
@ -263,6 +268,10 @@ static int config_output(AVFilterLink *outlink)
s->compute_flt = compute_avg_flt;
s->compute_dbl = compute_avg_dbl;
break;
case D_DEV:
s->compute_flt = compute_dev_flt;
s->compute_dbl = compute_dev_dbl;
break;
case D_PTP:
s->compute_flt = compute_ptp_flt;
s->compute_dbl = compute_ptp_dbl;

@ -307,6 +307,23 @@ static ftype fn(compute_rms)(ftype *cache, ftype sample, ftype wsample,
return SQRT(r / window_size);
}
static ftype fn(compute_dev)(ftype *ss, ftype x, ftype px,
int n, int *unused, int *unused2)
{
ftype r;
ss[0] += x;
ss[0] -= px;
ss[1] += x * x;
ss[1] -= px * px;
ss[1] = FMAX(ss[1], ZERO);
r = FMAX(ss[1] - ss[0] * ss[0] / n, ZERO) / n;
return SQRT(r);
}
static void fn(filter_start)(AVFilterContext *ctx,
const ftype *src, ftype *dst,
int *nb_out_samples,

Loading…
Cancel
Save