From: <sb...@us...> - 2007-10-23 22:37:58
|
Revision: 1225 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1225&view=rev Author: sbalea Date: 2007-10-23 15:37:55 -0700 (Tue, 23 Oct 2007) Log Message: ----------- Force PA to spit out standard sized buffers Comment out bias removal code Miscellaneous tweaks => Echo cancellation works pretty well on my mac :) 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-23 22:20:37 UTC (rev 1224) +++ branches/team/mihai/echocan/lib/audio_encode.c 2007-10-23 22:37:55 UTC (rev 1225) @@ -417,7 +417,7 @@ set_speex_filters(); } -void audio_echo_cancellation(short *inputBuffer, short *outputBuffer, int samples) +int audio_echo_cancellation(short *inputBuffer, short *outputBuffer, int samples) { #ifdef SPEEX_EC int i; @@ -426,11 +426,11 @@ short cancelledBuffer[1024]; /* remove bias -- whether ec is on or not. */ - for ( i = 0; i < samples; i++ ) - { - bias += ((((long int) inputBuffer[i]) << 15) - bias) >> 14; - inputBuffer[i] -= (short int) (bias >> 15); - } +// for ( i = 0; i < samples; i++ ) +// { +// 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. */ @@ -444,7 +444,7 @@ speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_ECHO_STATE, NULL); } - return; + return 0; } /* we want echo cancellation */ @@ -462,20 +462,21 @@ } } - /* fill ecOutRing */ + // Put our data in the EC ring buffer. + // Echo canceller needs SAMPLES_PER_FRAME samples, so if we don't have enough + // at this time, we just store what we have and return. rb_WriteRingBuffer(&ecOutRing, outputBuffer, samples * 2); + if ( rb_GetRingBufferReadAvailable(&ecOutRing) < (SAMPLES_PER_FRAME * 2) ) + return -1; - // Make sure we have enough buffer. - // Currently, just one SAMPLES_PER_FRAME's worth. - if ( rb_GetRingBufferReadAvailable(&ecOutRing) < ((samples + SAMPLES_PER_FRAME) * 2) ) - return; + rb_ReadRingBuffer(&ecOutRing, delayedBuf, SAMPLES_PER_FRAME * 2); - rb_ReadRingBuffer(&ecOutRing, delayedBuf, samples * 2); - + //fprintf(stderr, "Mihai: doing echo cancellation, samples = %d\n", samples); speex_echo_cancellation(ec, inputBuffer, delayedBuf, cancelledBuffer); for ( i = 0; i < samples; i++ ) inputBuffer[i] = cancelledBuffer[i]; #endif + return 0; } Modified: branches/team/mihai/echocan/lib/audio_encode.h =================================================================== --- branches/team/mihai/echocan/lib/audio_encode.h 2007-10-23 22:20:37 UTC (rev 1224) +++ branches/team/mihai/echocan/lib/audio_encode.h 2007-10-23 22:37:55 UTC (rev 1225) @@ -51,7 +51,7 @@ int audio_decode_audio(struct iaxc_call * p, void * out, void * data, int len, int iEncodeType, int * samples); -void audio_echo_cancellation(short *inputBuffer, short *outputBuffer, int samples); +int audio_echo_cancellation(short *inputBuffer, short *outputBuffer, int samples); #endif Modified: branches/team/mihai/echocan/lib/audio_portaudio.c =================================================================== --- branches/team/mihai/echocan/lib/audio_portaudio.c 2007-10-23 22:20:37 UTC (rev 1224) +++ branches/team/mihai/echocan/lib/audio_portaudio.c 2007-10-23 22:37:55 UTC (rev 1225) @@ -351,11 +351,10 @@ PaStreamCallbackFlags statusFlags, void *userData) { + short virtualInBuffer[MAX_SAMPLES_PER_FRAME]; + short virtualOutBuffer[MAX_SAMPLES_PER_FRAME]; int totBytes = samplesPerFrame * sizeof(SAMPLE); - short virtualInBuffer[MAX_SAMPLES_PER_FRAME * 2]; - short virtualOutBuffer[MAX_SAMPLES_PER_FRAME * 2]; - #if 0 /* I think this can't happen */ if(virtualMono && samplesPerFrame > SAMPLES_PER_FRAME) { @@ -364,8 +363,10 @@ } #endif + fprintf(stderr, "Mihai: in PA callback\n"); if ( outputBuffer ) { + //fprintf(stderr, "Mihai: PA output buffer size %d samples\n", samplesPerFrame); int bWritten; /* output underflow might happen here */ if (virtualMonoOut) @@ -406,22 +407,31 @@ if ( inputBuffer ) { + int res; + + //fprintf(stderr, "Mihai: PA input buffer size %d samples\n", samplesPerFrame); /* input overflow might happen here */ if ( virtualMonoIn ) { stereo2mono(virtualInBuffer, (SAMPLE *)inputBuffer, samplesPerFrame); - audio_echo_cancellation(virtualInBuffer, - virtualOutBuffer, - samplesPerFrame); - rb_WriteRingBuffer(&inRing, virtualInBuffer, totBytes); + res = audio_echo_cancellation(virtualInBuffer, + virtualOutBuffer, + samplesPerFrame); + if ( !res ) + rb_WriteRingBuffer(&inRing, virtualInBuffer, totBytes); + //else + // fprintf(stderr, "Mihai: EC does not have enough data\n"); } else { - audio_echo_cancellation((short *)inputBuffer, - (short *)outputBuffer, - samplesPerFrame); - rb_WriteRingBuffer(&inRing, inputBuffer, totBytes); + res = audio_echo_cancellation((short *)inputBuffer, + (short *)outputBuffer, + samplesPerFrame); + if ( !res) + rb_WriteRingBuffer(&inRing, inputBuffer, totBytes); + //else + // fprintf(stderr, "Mihai: EC does not have enough data\n"); } } @@ -480,7 +490,8 @@ &in_stream_params, &out_stream_params, iaxci_sample_rate, - paFramesPerBufferUnspecified, //FEEBACK - unsure if appropriate + //paFramesPerBufferUnspecified, //FEEBACK - unsure if appropriate + SAMPLES_PER_FRAME, paNoFlag, (PaStreamCallback *)pa_callback, NULL); @@ -493,7 +504,8 @@ &in_stream_params, &no_device, iaxci_sample_rate, - paFramesPerBufferUnspecified, //FEEBACK - unsure if appropriate + //paFramesPerBufferUnspecified, //FEEBACK - unsure if appropriate + SAMPLES_PER_FRAME, paNoFlag, (PaStreamCallback *)pa_callback, NULL); @@ -503,7 +515,8 @@ &no_device, &out_stream_params, iaxci_sample_rate, - paFramesPerBufferUnspecified, //FEEBACK - unsure if appropriate + //paFramesPerBufferUnspecified, //FEEBACK - unsure if appropriate + SAMPLES_PER_FRAME, paNoFlag, (PaStreamCallback *)pa_callback, NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |