aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/silenceremove_template.c
diff options
context:
space:
mode:
authorPaul B Mahol <onemda@gmail.com>2023-05-28 17:37:55 +0200
committerPaul B Mahol <onemda@gmail.com>2023-05-29 11:47:10 +0200
commitf02964aee1ed06ac4a67103904d5fae2862fa45e (patch)
tree9b8287adb5aa73acdaec4fadee3b1b618292c728 /libavfilter/silenceremove_template.c
parentaa4acc111e6ea1117dfec230435fdb26ec7631d9 (diff)
downloadffmpeg-f02964aee1ed06ac4a67103904d5fae2862fa45e.tar.gz
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.
Diffstat (limited to 'libavfilter/silenceremove_template.c')
-rw-r--r--libavfilter/silenceremove_template.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/libavfilter/silenceremove_template.c b/libavfilter/silenceremove_template.c
index 8536d5e723..009ed52f89 100644
--- a/libavfilter/silenceremove_template.c
+++ b/libavfilter/silenceremove_template.c
@@ -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,