[xiph-commits] r11948 - in trunk/speex: include/speex libspeex

jm at svn.xiph.org jm at svn.xiph.org
Wed Oct 25 17:13:21 PDT 2006


Author: jm
Date: 2006-10-25 17:13:14 -0700 (Wed, 25 Oct 2006)
New Revision: 11948

Modified:
   trunk/speex/include/speex/speex_preprocess.h
   trunk/speex/libspeex/mdf.c
   trunk/speex/libspeex/preprocess.c
   trunk/speex/libspeex/testdenoise.c
   trunk/speex/libspeex/testecho.c
Log:
The World Institute for Mental Health recommends switching to the new 
echo/preprocess API.


Modified: trunk/speex/include/speex/speex_preprocess.h
===================================================================
--- trunk/speex/include/speex/speex_preprocess.h	2006-10-25 16:08:15 UTC (rev 11947)
+++ trunk/speex/include/speex/speex_preprocess.h	2006-10-26 00:13:14 UTC (rev 11948)
@@ -53,6 +53,9 @@
 void speex_preprocess_state_destroy(SpeexPreprocessState *st);
 
 /** Preprocess a frame */
+int speex_preprocess_run(SpeexPreprocessState *st, spx_int16_t *x);
+
+/** Preprocess a frame (deprecated) */
 int speex_preprocess(SpeexPreprocessState *st, spx_int16_t *x, spx_int32_t *echo);
 
 /** Preprocess a frame */
@@ -113,6 +116,9 @@
 #define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE 22
 #define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE 23
 
+#define SPEEX_PREPROCESS_SET_ECHO_STATE 24
+#define SPEEX_PREPROCESS_GET_ECHO_STATE 25
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/speex/libspeex/mdf.c
===================================================================
--- trunk/speex/libspeex/mdf.c	2006-10-25 16:08:15 UTC (rev 11947)
+++ trunk/speex/libspeex/mdf.c	2006-10-26 00:13:14 UTC (rev 11948)
@@ -102,7 +102,7 @@
 #define TOP16(x) (x)
 #endif
 
-void speex_echo_get_residual(SpeexEchoState *st, spx_int32_t *Yout, int len);
+void speex_echo_get_residual(SpeexEchoState *st, spx_word32_t *Yout, int len);
 
 
 /** Speex echo cancellation state. */
@@ -126,7 +126,6 @@
    spx_word16_t *d;
    spx_word16_t *y;
    spx_word16_t *last_y;
-   spx_word32_t *Yps;
    spx_word16_t *Y;
    spx_word16_t *E;
    spx_word32_t *PHI;
@@ -303,7 +302,6 @@
    st->x = (spx_word16_t*)speex_alloc(N*sizeof(spx_word16_t));
    st->d = (spx_word16_t*)speex_alloc(N*sizeof(spx_word16_t));
    st->y = (spx_word16_t*)speex_alloc(N*sizeof(spx_word16_t));
-   st->Yps = (spx_word32_t*)speex_alloc(N*sizeof(spx_word32_t));
    st->last_y = (spx_word16_t*)speex_alloc(N*sizeof(spx_word16_t));
    st->Yf = (spx_word32_t*)speex_alloc((st->frame_size+1)*sizeof(spx_word32_t));
    st->Rf = (spx_word32_t*)speex_alloc((st->frame_size+1)*sizeof(spx_word32_t));
@@ -409,7 +407,6 @@
    speex_free(st->d);
    speex_free(st->y);
    speex_free(st->last_y);
-   speex_free(st->Yps);
    speex_free(st->Yf);
    speex_free(st->Rf);
    speex_free(st->Xf);
@@ -471,7 +468,6 @@
 void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *in, const spx_int16_t *far_end, spx_int16_t *out, spx_int32_t *Yout)
 {
    speex_echo_cancellation(st, in, far_end, out);
-   speex_echo_get_residual(st, Yout, 0);
 }
 
 /** Performs echo cancellation on a frame (deprecated, last arg now ignored) */
@@ -815,7 +811,7 @@
 }
 
 /* Compute spectrum of estimated echo for use in an echo post-filter */
-void speex_echo_get_residual(SpeexEchoState *st, spx_int32_t *Yout, int len)
+void speex_echo_get_residual(SpeexEchoState *st, spx_word32_t *residual_echo, int len)
 {
    int i;
    spx_word16_t leak2;
@@ -829,7 +825,7 @@
       
    /* Compute power spectrum of the echo */
    spx_fft(st->fft_table, st->y, st->Y);
-   power_spectrum(st->Y, st->Yps, N);
+   power_spectrum(st->Y, residual_echo, N);
       
 #ifdef FIXED_POINT
    if (st->leak_estimate > 16383)
@@ -844,7 +840,7 @@
 #endif
    /* Estimate residual echo */
    for (i=0;i<=st->frame_size;i++)
-      Yout[i] = (spx_int32_t)MULT16_32_Q15(leak2,st->Yps[i]);
+      residual_echo[i] = (spx_int32_t)MULT16_32_Q15(leak2,residual_echo[i]);
    
 }
 

Modified: trunk/speex/libspeex/preprocess.c
===================================================================
--- trunk/speex/libspeex/preprocess.c	2006-10-25 16:08:15 UTC (rev 11947)
+++ trunk/speex/libspeex/preprocess.c	2006-10-26 00:13:14 UTC (rev 11948)
@@ -61,6 +61,7 @@
 
 #include <math.h>
 #include "speex/speex_preprocess.h"
+#include "speex/speex_echo.h"
 #include "misc.h"
 #include "fftwrap.h"
 #include "filterbank.h"
@@ -82,6 +83,10 @@
 #define ECHO_SUPPRESS_DEFAULT        -45
 #define ECHO_SUPPRESS_ACTIVE_DEFAULT -15
 
+#ifndef NULL
+#define NULL 0
+#endif
+
 /** Speex pre-processor state. */
 struct SpeexPreprocessState_ {
    /* Basic info */
@@ -104,6 +109,7 @@
    int    noise_suppress;
    int    echo_suppress;
    int    echo_suppress_active;
+   SpeexEchoState *echo_state;
    
    /* DSP-related arrays */
    float *frame;             /**< Processing frame (2*ps_size) */
@@ -129,6 +135,7 @@
    float *loudness_weight;   /**< Perceptual loudness curve */
 
    float *echo_noise;
+   spx_word32_t *residual_echo;
 
    /* Misc */
    float *inbuf;             /**< Input buffer (overlapped analysis) */
@@ -251,6 +258,8 @@
    st->speech_prob_start = SPEEX_PROB_START_DEFAULT;
    st->speech_prob_continue = SPEEX_PROB_CONTINUE_DEFAULT;
 
+   st->echo_state = NULL;
+   
    st->nbands = NB_BANDS;
    M = st->nbands;
    st->bank = filterbank_new(M, sampling_rate, N, 1);
@@ -262,6 +271,7 @@
    st->ps = (float*)speex_alloc((N+M)*sizeof(float));
    st->noise = (float*)speex_alloc((N+M)*sizeof(float));
    st->echo_noise = (float*)speex_alloc((N+M)*sizeof(float));
+   st->residual_echo = (spx_word32_t*)speex_alloc((N+M)*sizeof(float));
    st->reverb_estimate = (float*)speex_alloc((N+M)*sizeof(float));
    st->old_ps = (float*)speex_alloc((N+M)*sizeof(float));
    st->prior = (float*)speex_alloc((N+M)*sizeof(float));
@@ -347,6 +357,7 @@
    speex_free(st->post);
    speex_free(st->loudness_weight);
    speex_free(st->echo_noise);
+   speex_free(st->residual_echo);
 
    speex_free(st->S);
    speex_free(st->Smin);
@@ -507,8 +518,15 @@
 
 #define NOISE_OVERCOMPENS 1.
 
+void speex_echo_get_residual(SpeexEchoState *st, spx_word32_t *Yout, int len);
+
 int speex_preprocess(SpeexPreprocessState *st, spx_int16_t *x, spx_int32_t *echo)
 {
+   return speex_preprocess_run(st, x);
+}
+
+int speex_preprocess_run(SpeexPreprocessState *st, spx_int16_t *x)
+{
    int i;
    int M;
    int N = st->ps_size;
@@ -529,10 +547,11 @@
    beta_1 = 1.0f-beta;
    M = st->nbands;
    /* Deal with residual echo if provided */
-   if (echo)
+   if (st->echo_state)
    {
+      speex_echo_get_residual(st->echo_state, st->residual_echo, N);
       for (i=0;i<N;i++)
-         st->echo_noise[i] = MAX32(.6f*st->echo_noise[i], echo[i]);
+         st->echo_noise[i] = MAX32(.6f*st->echo_noise[i], st->residual_echo[i]);
       filterbank_compute_bank(st->bank, st->echo_noise, st->echo_noise+N);
    } else {
       for (i=0;i<N+M;i++)
@@ -891,6 +910,12 @@
    case SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE:
       (*(spx_int32_t*)ptr) = st->echo_suppress_active;
       break;
+   case SPEEX_PREPROCESS_SET_ECHO_STATE:
+      st->echo_state = (SpeexEchoState*)ptr;
+      break;
+   case SPEEX_PREPROCESS_GET_ECHO_STATE:
+      ptr = (void*)st->echo_state;
+      break;
 
    default:
       speex_warning_int("Unknown speex_preprocess_ctl request: ", request);

Modified: trunk/speex/libspeex/testdenoise.c
===================================================================
--- trunk/speex/libspeex/testdenoise.c	2006-10-25 16:08:15 UTC (rev 11947)
+++ trunk/speex/libspeex/testdenoise.c	2006-10-26 00:13:14 UTC (rev 11948)
@@ -24,9 +24,9 @@
    speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &f);
    i=0;
    speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB, &i);
-   f=.4;
+   f=.0;
    speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f);
-   f=.3;
+   f=.0;
    speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
    while (1)
    {
@@ -34,7 +34,7 @@
       fread(in, sizeof(short), NN, stdin);
       if (feof(stdin))
          break;
-      vad = speex_preprocess(st, in, NULL);
+      vad = speex_preprocess_run(st, in);
       /*fprintf (stderr, "%d\n", vad);*/
       fwrite(in, sizeof(short), NN, stdout);
       count++;

Modified: trunk/speex/libspeex/testecho.c
===================================================================
--- trunk/speex/libspeex/testecho.c	2006-10-25 16:08:15 UTC (rev 11947)
+++ trunk/speex/libspeex/testecho.c	2006-10-26 00:13:14 UTC (rev 11948)
@@ -18,7 +18,6 @@
 int main(int argc, char **argv)
 {
    int echo_fd, ref_fd, e_fd;
-   spx_int32_t noise[NN+1];
    short echo_buf[NN], ref_buf[NN], e_buf[NN];
    SpeexEchoState *st;
    SpeexPreprocessState *den;
@@ -36,12 +35,13 @@
    den = speex_preprocess_state_init(NN, 8000);
    int tmp = 8000;
    speex_echo_ctl(st, SPEEX_ECHO_SET_SAMPLING_RATE, &tmp);
+   speex_preprocess_ctl(den, SPEEX_PREPROCESS_SET_ECHO_STATE, st);
 
    while (read(ref_fd, ref_buf, NN*2))
    {
       read(echo_fd, echo_buf, NN*2);
-      speex_echo_cancel(st, ref_buf, echo_buf, e_buf, noise);
-      /*speex_preprocess(den, e_buf, noise);*/
+      speex_echo_cancellation(st, ref_buf, echo_buf, e_buf);
+      speex_preprocess_run(den, e_buf);
       write(e_fd, e_buf, NN*2);
    }
    speex_echo_state_destroy(st);



More information about the commits mailing list