History

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.

Paul B Mahol committed 3 years ago

Commit f02964a1 parent aa4acc13 files · +28 −0Browse files

Showing the changes to libavfilter (2 of 3 files). Show all

Unified · Split

2 files
  1. libavfilter/af_silenceremove.c +9 −0
  2. libavfilter/silenceremove_template.c +17 −0
libavfilter/af_silenceremove.c+9−0
@@ -38,6 +38,7 @@ enum SilenceDetect { · 37 unmodified lines
3838 D_PEAK,
3939 D_MEDIAN,
4040 D_PTP,
41+ D_DEV,
4142 D_NB
4243 };
4344
@@ -146,6 +147,7 @@ static const AVOption silenceremove_options[] = { · 102 unmodified lines
146147 { "peak", "use max absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_PEAK},0, 0, AF, "detection" },
147148 { "median", "use median of absolute values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_MEDIAN},0, 0, AF, "detection" },
148149 { "ptp", "use absolute of max peak to min peak difference", 0, AV_OPT_TYPE_CONST, {.i64=D_PTP}, 0, 0, AF, "detection" },
150+ { "dev", "use standard deviation from values of samples", 0, AV_OPT_TYPE_CONST, {.i64=D_DEV}, 0, 0, AF, "detection" },
149151 { "window", "set duration of window for silence detection", OFFSET(window_duration_opt), AV_OPT_TYPE_DURATION, {.i64=20000}, 0, 100000000, AF },
150152 { "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" },
151153 { "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) · 78 unmodified lines
230232 case D_RMS:
231233 s->cache_size = 1;
232234 break;
235+ case D_DEV:
236+ s->cache_size = 2;
237+ break;
233238 case D_MEDIAN:
234239 case D_PEAK:
235240 case D_PTP:
@@ -263,6 +268,10 @@ static int config_output(AVFilterLink *outlink) · 27 unmodified lines
263268 s->compute_flt = compute_avg_flt;
264269 s->compute_dbl = compute_avg_dbl;
265270 break;
271+ case D_DEV:
272+ s->compute_flt = compute_dev_flt;
273+ s->compute_dbl = compute_dev_dbl;
274+ break;
266275 case D_PTP:
267276 s->compute_flt = compute_ptp_flt;
268277 s->compute_dbl = compute_ptp_dbl;
libavfilter/silenceremove_template.c+17−0
@@ -307,6 +307,23 @@ static ftype fn(compute_rms)(ftype *cache, ftype sample, ftype wsample, · 306 unmodified lines
307307 return SQRT(r / window_size);
308308 }
309309
310+static ftype fn(compute_dev)(ftype *ss, ftype x, ftype px,
311+ int n, int *unused, int *unused2)
312+{
313+ ftype r;
314+
315+ ss[0] += x;
316+ ss[0] -= px;
317+
318+ ss[1] += x * x;
319+ ss[1] -= px * px;
320+ ss[1] = FMAX(ss[1], ZERO);
321+
322+ r = FMAX(ss[1] - ss[0] * ss[0] / n, ZERO) / n;
323+
324+ return SQRT(r);
325+}
326+
310327 static void fn(filter_start)(AVFilterContext *ctx,
311328 const ftype *src, ftype *dst,
312329 int *nb_out_samples,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t