Thorvald Natvig: Patch to query the current probability of speech
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 13 Feb 2008 10:11:57 +0000 (10:11 +0000)
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 13 Feb 2008 10:11:57 +0000 (10:11 +0000)
git-svn-id: http://svn.xiph.org/trunk/speex@14496 0101bb08-14d6-0310-b084-bc0e0c8e3800

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

index 5ec87d1..bcef7be 100644 (file)
@@ -202,6 +202,10 @@ int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr);
 /** Get noise estimate (int32[] of squared values) */
 #define SPEEX_PREPROCESS_GET_NOISE_PSD 43
 
+/* Can't set speech probability */
+/** Get speech probability in last frame (int32).  */
+#define SPEEX_PREPROCESS_GET_PROB 45
+
 #ifdef __cplusplus
 }
 #endif
index b0daf86..06fe8e0 100644 (file)
@@ -199,6 +199,8 @@ struct SpeexPreprocessState_ {
    int    echo_suppress_active;
    SpeexEchoState *echo_state;
    
+   spx_word16_t        speech_prob;  /**< Probability last frame was speech */
+
    /* DSP-related arrays */
    spx_word16_t *frame;      /**< Processing frame (2*ps_size) */
    spx_word16_t *ft;         /**< Processing frame in freq domain (2*ps_size) */
@@ -994,9 +996,10 @@ int speex_preprocess_run(SpeexPreprocessState *st, spx_int16_t *x)
       st->outbuf[i] = st->frame[st->frame_size+i];
 
    /* FIXME: This VAD is a kludge */
+   st->speech_prob = Pframe;
    if (st->vad_enabled)
    {
-      if (Pframe > st->speech_prob_start || (st->was_speech && Pframe > st->speech_prob_continue))
+      if (st->speech_prob > st->speech_prob_start || (st->was_speech && st->speech_prob > st->speech_prob_continue))
       {
          st->was_speech=1;
          return 1;
@@ -1191,6 +1194,9 @@ int speex_preprocess_ctl(SpeexPreprocessState *state, int request, void *ptr)
       for(i=0;i<st->ps_size;i++)
        ((spx_int32_t *)ptr)[i] = (spx_int32_t) PSHR32(st->noise[i], NOISE_SHIFT);
       break;
+   case SPEEX_PREPROCESS_GET_PROB:
+      (*(spx_int32_t*)ptr) = MULT16_16_Q15(st->speech_prob, 100);
+      break;
    default:
       speex_warning_int("Unknown speex_preprocess_ctl request: ", request);
       return -1;