Merged:
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Sat, 22 Oct 2005 06:12:48 +0000 (06:12 +0000)
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Sat, 22 Oct 2005 06:12:48 +0000 (06:12 +0000)
02_configurable-VAD.dpatch by A. Maitland Bottoms <bottoms@debian.org>

git-svn-id: http://svn.xiph.org/trunk/speex@10228 0101bb08-14d6-0310-b084-bc0e0c8e3800

include/speex/speex_preprocess.h
libspeex/preprocess.c

index 456e064..0d20a4d 100644 (file)
@@ -57,6 +57,8 @@ typedef struct SpeexPreprocessState {
    int    dereverb_enabled;
    float  reverb_decay;
    float  reverb_level;
+   float  speech_prob_start;
+   float  speech_prob_continue;
    
    float *frame;             /**< Processing frame (2*ps_size) */
    float *ps;                /**< Current power spectrum */
@@ -156,6 +158,12 @@ int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr);
 /** Get preprocessor dereverb decay */
 #define SPEEX_PREPROCESS_GET_DEREVERB_DECAY 13
 
+#define SPEEX_PREPROCESS_SET_PROB_START 14
+#define SPEEX_PREPROCESS_GET_PROB_START 15
+
+#define SPEEX_PREPROCESS_SET_PROB_CONTINUE 16
+#define SPEEX_PREPROCESS_GET_PROB_CONTINUE 17
+
 #ifdef __cplusplus
 }
 #endif
index 436bf19..bf402ed 100644 (file)
@@ -52,6 +52,9 @@
 
 #define NB_BANDS 8
 
+#define SPEEX_PROB_START_DEFAULT    0.35f
+#define SPEEX_PROB_CONTINUE_DEFAULT 0.20f
+
 #define ZMIN .1
 #define ZMAX .316
 #define ZMIN_1 10
@@ -157,6 +160,9 @@ SpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_r
    st->reverb_decay = .5;
    st->reverb_level = .2;
 
+   st->speech_prob_start = SPEEX_PROB_START_DEFAULT;
+   st->speech_prob_continue = SPEEX_PROB_CONTINUE_DEFAULT;
+
    st->frame = (float*)speex_alloc(2*N*sizeof(float));
    st->ps = (float*)speex_alloc(N*sizeof(float));
    st->gain2 = (float*)speex_alloc(N*sizeof(float));
@@ -451,7 +457,8 @@ static int speex_compute_vad(SpeexPreprocessState *st, float *ps, float mean_pri
       st->speech_prob = p0/(1e-25f+p1+p0);
       /*fprintf (stderr, "%f %f %f ", tot_loudness, st->loudness2, st->speech_prob);*/
 
-      if (st->speech_prob>.35 || (st->last_speech < 20 && st->speech_prob>.1))
+      if (st->speech_prob > st->speech_prob_start
+         || (st->last_speech < 20 && st->speech_prob > st->speech_prob_continue))
       {
          is_speech = 1;
          st->last_speech = 0;
@@ -993,6 +1000,24 @@ int speex_preprocess_ctl(SpeexPreprocessState *state, int request, void *ptr)
       (*(float*)ptr) = st->reverb_decay;
       break;
 
+   case SPEEX_PREPROCESS_SET_PROB_START:
+      st->speech_prob_start = (*(int*)ptr) / 100.0;
+      if ( st->speech_prob_start > 1 || st->speech_prob_start < 0 )
+         st->speech_prob_start = SPEEX_PROB_START_DEFAULT;
+      break;
+   case SPEEX_PREPROCESS_GET_PROB_START:
+      (*(int*)ptr) = st->speech_prob_start * 100;
+      break;
+
+   case SPEEX_PREPROCESS_SET_PROB_CONTINUE:
+      st->speech_prob_continue = (*(int*)ptr) / 100.0;
+      if ( st->speech_prob_continue > 1 || st->speech_prob_continue < 0 )
+         st->speech_prob_continue = SPEEX_PROB_CONTINUE_DEFAULT;
+      break;
+   case SPEEX_PREPROCESS_GET_PROB_CONTINUE:
+      (*(int*)ptr) = st->speech_prob_continue * 100;
+      break;
+
       default:
       speex_warning_int("Unknown speex_preprocess_ctl request: ", request);
       return -1;