From: <sb...@us...> - 2007-10-24 18:56:04
|
Revision: 1230 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1230&view=rev Author: sbalea Date: 2007-10-24 11:56:07 -0700 (Wed, 24 Oct 2007) Log Message: ----------- Make sure that we link the echo canceller to the preprocessor in all situations. Reduce tail to 512 frames. Miscellaneous code cleanups. Modified Paths: -------------- branches/team/mihai/echocan/lib/audio_encode.c branches/team/mihai/echocan/lib/audio_encode.h branches/team/mihai/echocan/lib/audio_portaudio.c Modified: branches/team/mihai/echocan/lib/audio_encode.c =================================================================== --- branches/team/mihai/echocan/lib/audio_encode.c 2007-10-24 15:31:46 UTC (rev 1229) +++ branches/team/mihai/echocan/lib/audio_encode.c 2007-10-24 18:56:07 UTC (rev 1230) @@ -154,6 +154,16 @@ if (st) speex_preprocess_state_destroy(st); st = speex_preprocess_state_init(len,rate); + if ( ec ) + { + int i; + + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_STATE, ec); + i = ECHO_SUPPRESS; + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_SUPPRESS, &i); + i = ECHO_SUPPRESS_ACTIVE; + speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE, &i); + } speex_state_size = len; speex_state_rate = rate; set_speex_filters(); @@ -431,7 +441,7 @@ // bias += ((((long int) inputBuffer[i]) << 15) - bias) >> 14; // inputBuffer[i] -= (short int) (bias >> 15); // } - + /* if ec is off, clear ec state -- this way, we start fresh if/when * it's turned back on. */ if ( !(iaxci_filters & IAXC_FILTER_ECHO) ) @@ -441,7 +451,9 @@ speex_echo_state_destroy(ec); ec = NULL; if ( st ) + { speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_STATE, NULL); + } } return 0; @@ -452,6 +464,10 @@ { rb_InitializeRingBuffer(&ecOutRing, EC_RING_SIZE, &outRingBuf); ec = speex_echo_state_init(SAMPLES_PER_FRAME, ECHO_TAIL); + + // st and ec can be created and destroyed from two separate threads + // and thus we have possible race conditions here. + // TODO: verify that this is the case and add synchronization code. if ( st ) { speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_STATE, ec); @@ -471,7 +487,6 @@ rb_ReadRingBuffer(&ecOutRing, delayedBuf, SAMPLES_PER_FRAME * 2); - //fprintf(stderr, "Mihai: doing echo cancellation, samples = %d\n", samples); speex_echo_cancellation(ec, inputBuffer, delayedBuf, cancelledBuffer); for ( i = 0; i < samples; i++ ) Modified: branches/team/mihai/echocan/lib/audio_encode.h =================================================================== --- branches/team/mihai/echocan/lib/audio_encode.h 2007-10-24 15:31:46 UTC (rev 1229) +++ branches/team/mihai/echocan/lib/audio_encode.h 2007-10-24 18:56:07 UTC (rev 1230) @@ -27,7 +27,7 @@ #define MAX_SAMPLES_PER_FRAME (MS_PER_FRAME * MAX_SAMPLE_RATE / 1000) /* echo_tail length, in samples */ -#define ECHO_TAIL 1024 +#define ECHO_TAIL 512 /* Maximum attenuation of residual echo in dB (negative number) */ #define ECHO_SUPPRESS -60 Modified: branches/team/mihai/echocan/lib/audio_portaudio.c =================================================================== --- branches/team/mihai/echocan/lib/audio_portaudio.c 2007-10-24 15:31:46 UTC (rev 1229) +++ branches/team/mihai/echocan/lib/audio_portaudio.c 2007-10-24 18:56:07 UTC (rev 1230) @@ -365,7 +365,6 @@ if ( outputBuffer ) { - //fprintf(stderr, "Mihai: PA output buffer size %d samples\n", samplesPerFrame); int bWritten; /* output underflow might happen here */ if (virtualMonoOut) @@ -408,7 +407,6 @@ { int res; - //fprintf(stderr, "Mihai: PA input buffer size %d samples\n", samplesPerFrame); /* input overflow might happen here */ if ( virtualMonoIn ) { @@ -419,8 +417,6 @@ samplesPerFrame); if ( !res ) rb_WriteRingBuffer(&inRing, virtualInBuffer, totBytes); - //else - // fprintf(stderr, "Mihai: EC does not have enough data\n"); } else { @@ -429,8 +425,6 @@ samplesPerFrame); if ( !res) rb_WriteRingBuffer(&inRing, inputBuffer, totBytes); - //else - // fprintf(stderr, "Mihai: EC does not have enough data\n"); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |