summaryrefslogtreecommitdiff
path: root/gst/removesilence/vad_private.c
diff options
context:
space:
mode:
authorNicola Murino <nicola.murino@gmail.com>2018-11-26 16:40:01 +0100
committerNicola Murino <nicola.murino@gmail.com>2018-12-14 18:43:49 +0100
commit8978f558868b92b0294e59680d1381a1e7c585fe (patch)
tree5e26081d300b8be8e2c5face6fbb67acec115563 /gst/removesilence/vad_private.c
parente5495669697a23508f5906de052d1ae0600fb7b5 (diff)
downloadgstreamer-plugins-bad-8978f558868b92b0294e59680d1381a1e7c585fe.tar.gz
removesilence: add threshold property
silence thresold was hardcoded to -60 dB, now it is configurable using this new property Closes #63
Diffstat (limited to 'gst/removesilence/vad_private.c')
-rw-r--r--gst/removesilence/vad_private.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/gst/removesilence/vad_private.c b/gst/removesilence/vad_private.c
index 2c495967e..369e18e6f 100644
--- a/gst/removesilence/vad_private.c
+++ b/gst/removesilence/vad_private.c
@@ -22,11 +22,11 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <math.h>
#include <glib.h>
#include "vad_private.h"
#define VAD_POWER_ALPHA 0x0800 /* Q16 */
-#define VAD_POWER_THRESHOLD 0x000010C7 /* -60 dB (square wave) */
#define VAD_ZCR_THRESHOLD 0
#define VAD_BUFFER_SIZE 256
@@ -59,15 +59,17 @@ struct _vad_s
guint64 hysteresis;
guint64 vad_samples;
guint64 vad_power;
+ guint64 threshold;
long vad_zcr;
};
VADFilter *
-vad_new (guint64 hysteresis)
+vad_new (guint64 hysteresis, gint threshold)
{
VADFilter *vad = malloc (sizeof (VADFilter));
vad_reset (vad);
vad->hysteresis = hysteresis;
+ vad_set_threshold (vad, threshold);
return vad;
}
@@ -99,6 +101,19 @@ vad_get_hysteresis (struct _vad_s *p)
return p->hysteresis;
}
+void
+vad_set_threshold (struct _vad_s *p, gint threshold_db)
+{
+ gint power = (gint) (threshold_db / 10.0);
+ p->threshold = (guint64) (pow (10, (power)) * 4294967295);
+}
+
+gint
+vad_get_threshold_as_db (struct _vad_s *p)
+{
+ return (gint) (10 * log10 (p->threshold / 4294967295.0));
+}
+
gint
vad_update (struct _vad_s * p, gint16 * data, gint len)
{
@@ -129,7 +144,7 @@ vad_update (struct _vad_s * p, gint16 * data, gint len)
((sample & 0x8000) != (p->cqueue.base.s[tail] & 0x8000)) ? 1 : -1;
}
- frame_type = (p->vad_power > VAD_POWER_THRESHOLD
+ frame_type = (p->vad_power > p->threshold
&& p->vad_zcr < VAD_ZCR_THRESHOLD) ? VAD_VOICE : VAD_SILENCE;
if (p->vad_state != frame_type) {