[Speex-dev] Patch to get impulse response from echo canceller

Thorvald Natvig speex at natvig.com
Tue Feb 12 15:10:13 PST 2008


Hi,

Here's the second attempt of a patch to get the impulse response from the 
echo canceller :)

-------------- next part --------------
diff -ubBwr clean/include/speex/speex_echo.h get_impulse/include/speex/speex_echo.h
--- clean/include/speex/speex_echo.h	2007-10-09 13:08:15.000000000 +0200
+++ get_impulse/include/speex/speex_echo.h	2008-02-12 23:58:11.000000000 +0100
@@ -51,6 +51,14 @@
 /** Get sampling rate */
 #define SPEEX_ECHO_GET_SAMPLING_RATE 25
 
+/* Can't set window sizes */
+/** Get size of impulse response (int32) */
+#define SPEEX_ECHO_GET_IMPULSE_RESPONSE_SIZE 27
+
+/* Can't set window content */
+/** Get impulse response (int32[]) */
+#define SPEEX_ECHO_GET_IMPULSE_RESPONSE 29
+
 /** Internal echo canceller state. Should never be accessed directly. */
 struct SpeexEchoState_;
 
diff -ubBwr clean/libspeex/mdf.c get_impulse/libspeex/mdf.c
--- clean/libspeex/mdf.c	2007-11-19 13:54:38.000000000 +0100
+++ get_impulse/libspeex/mdf.c	2008-02-12 23:58:22.000000000 +0100
@@ -1169,6 +1169,27 @@
       case SPEEX_ECHO_GET_SAMPLING_RATE:
          (*(int*)ptr) = st->sampling_rate;
          break;
+      case SPEEX_ECHO_GET_IMPULSE_RESPONSE_SIZE:
+      	 *((spx_int32_t *)ptr) = st->M * st->frame_size;
+      	 break;
+      case SPEEX_ECHO_GET_IMPULSE_RESPONSE:
+	{
+		int M = st->M, N = st->window_size, n = st->frame_size, i, j;
+		spx_int32_t *filt = (spx_int32_t *) ptr;
+		for(j=0;j<M;j++)
+		{
+#ifdef FIXED_POINT
+			for (i=0;i<N;i++)
+				st->wtmp2[i] = EXTRACT16(PSHR32(st->W[j*N+i],16));
+			spx_ifft(st->fft_table, st->wtmp2, st->wtmp);
+#else
+			spx_ifft(st->fft_table, &st->W[j*N], st->wtmp);
+#endif
+			for(i=0;i<n;i++)
+				filt[j*n+i] = PSHR32(MULT16_16(32767,st->wtmp[i]), WEIGHT_SHIFT);
+		}
+	}
+	break;
       default:
          speex_warning_int("Unknown speex_echo_ctl request: ", request);
          return -1;


More information about the Speex-dev mailing list