shithub: sox

Download patch

ref: fc724b42fe0d335f2124f49bcfc1c38e887072bc
parent: 199dd44080fcdf260be46b56669670b04fbd3248
author: robs <robs>
date: Mon Jun 8 18:13:39 EDT 2009

improve SNR robustness and cut-off logic

--- a/src/vad.c
+++ b/src/vad.c
@@ -45,7 +45,7 @@
   priv_t * p = (priv_t *)effp->priv;
   int c;
 
-  p->hp_freq          = 300;
+  p->hp_freq          = 120;
   p->lp_freq          = 12500;
   p->measure_duration = .2;
   p->measure_freq     = 10;
@@ -153,7 +153,7 @@
   priv_t * p = (priv_t *)effp->priv;
   double * buf = p->dft_buf;
   double mult, result = 0;
-  size_t i;
+  size_t i, n;
 
   for (i = 0; i < p->measure_len; ++i) {
     buf[i] = p->buffer[x] * p->window1[i];
@@ -168,9 +168,10 @@
   memset(buf + i, 0, ((p->dft_len >> 1) - i) * sizeof(*buf));
   lsx_safe_rdft((int)p->dft_len >> 1, 1, buf);
 
-  i = max(1, (size_t)(.01 * p->dft_len + .5));
-  mult = (p->dft_len / 4 + 1.) / (p->dft_len / 4 - i);
-  for (; i < p->dft_len >> 2; ++i)
+  i = max(1, (size_t)(.006 * p->dft_len + .5));
+  n = (size_t)(.014 * p->dft_len + .5);
+  mult = (p->dft_len / 4 + 1.) / (n - i);
+  for (; i < n; ++i)
     result += sqr(buf[2*i]) + sqr(buf[2*i+1]);
   result = log(mult * result);
   result = max(result + 50, 0);
@@ -227,7 +228,7 @@
               started = sox_true;
             }
           } while (flush < p->search_len && (
-                (meas > meas0 - 12 && (c->slope1 > 4 || c->slope2 > 2)) ||
+                (meas > p->trigger_level - 12 && (c->slope1 > 4 || c->slope2 > 2)) ||
                 meas > p->trigger_level));
           to_flush = range_limit(flush, to_flush, p->search_len);
         }