[Speex-dev] Second part of data export patch

Thorvald Natvig speex at natvig.com
Tue Feb 12 08:27:06 PST 2008


Hi,

Here are the next two patches for the data export.

speex_get_psd should be applied after speex_get_agc_gain (sent in previous 
mail). It allows applications to get the power spectrum for the signal and 
the noise estimate.

speex_get_prob should be applied last. It allows fetching the speech 
probability of the current frame (the value that the _PROB_START and 
_PROB_CONTINUE parameters are compared to in the current VAD).


I've verified that they give the same results in fixed and floating point 
mode.
-------------- next part --------------
diff -ubBwr get_agc_gain/include/speex/speex_preprocess.h get_psd/include/speex/speex_preprocess.h
--- get_agc_gain/include/speex/speex_preprocess.h	2008-02-12 17:13:04.000000000 +0100
+++ get_psd/include/speex/speex_preprocess.h	2008-02-12 17:15:10.000000000 +0100
@@ -186,6 +186,22 @@
 /** Get current gain (int32 percent) */
 #define SPEEX_PREPROCESS_GET_AGC_GAIN 35
 
+/*  Can't set spectrum size */
+/** Get spectrum size for power spectrum (int32) */
+#define SPEEX_PREPROCESS_GET_PSD_SIZE 37
+
+/*  Can't set power spectrum */
+/** Get power spectrum (int32[] of squared values) */
+#define SPEEX_PREPROCESS_GET_PSD 39
+
+/*  Can't set noise size */
+/** Get spectrum size for noise estimate (int32)  */
+#define SPEEX_PREPROCESS_GET_NOISE_PSD_SIZE 41
+
+/*  Can't set noise estimate */
+/** Get noise estimate (int32[] of squared values) */
+#define SPEEX_PREPROCESS_GET_NOISE_PSD 43
+
 #ifdef __cplusplus
 }
 #endif
diff -ubBwr get_agc_gain/libspeex/preprocess.c get_psd/libspeex/preprocess.c
--- get_agc_gain/libspeex/preprocess.c	2008-02-12 17:13:04.000000000 +0100
+++ get_psd/libspeex/preprocess.c	2008-02-12 17:16:10.000000000 +0100
@@ -1179,7 +1179,18 @@
       (*(spx_int32_t*)ptr) = (spx_int32_t) (st->agc_gain * 100.f);
       break;
 #endif
-
+   case SPEEX_PREPROCESS_GET_PSD_SIZE:
+   case SPEEX_PREPROCESS_GET_NOISE_PSD_SIZE:
+      (*(spx_int32_t*)ptr) = st->ps_size;
+      break;
+   case SPEEX_PREPROCESS_GET_PSD:
+      for(i=0;i<st->ps_size;i++)
+      	((spx_int32_t *)ptr)[i] = (spx_int32_t) st->ps[i];
+      break;
+   case SPEEX_PREPROCESS_GET_NOISE_PSD:
+      for(i=0;i<st->ps_size;i++)
+      	((spx_int32_t *)ptr)[i] = (spx_int32_t) PSHR32(st->noise[i], NOISE_SHIFT);
+      break;
    default:
       speex_warning_int("Unknown speex_preprocess_ctl request: ", request);
       return -1;
-------------- next part --------------
diff -ubBwr get_psd/include/speex/speex_preprocess.h get_prob/include/speex/speex_preprocess.h
--- get_psd/include/speex/speex_preprocess.h	2008-02-12 17:15:10.000000000 +0100
+++ get_prob/include/speex/speex_preprocess.h	2008-02-12 17:13:21.000000000 +0100
@@ -202,6 +202,10 @@
 /** 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
diff -ubBwr get_psd/libspeex/preprocess.c get_prob/libspeex/preprocess.c
--- get_psd/libspeex/preprocess.c	2008-02-12 17:16:10.000000000 +0100
+++ get_prob/libspeex/preprocess.c	2008-02-12 17:13:28.000000000 +0100
@@ -199,6 +199,8 @@
    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 @@
       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 @@
       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;


More information about the Speex-dev mailing list