]> sjero.net Git - linphone/blobdiff - coreapi/ec-calibrator.c
Improve echo canceller calibrator.
[linphone] / coreapi / ec-calibrator.c
index 8efbabb1b0a0758c0fde6bcef4592860361eb296..d724669a4d6037f8474b5d8ebd001e4a47c50352 100644 (file)
@@ -29,6 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 static void ecc_init_filters(EcCalibrator *ecc){
        unsigned int rate;
+       int channels = 1;
+       int ecc_channels = 1;
        MSTickerParams params={0};
        params.name="Echo calibrator";
        params.prio=MS_TICKER_PRIO_HIGH;
@@ -37,9 +39,13 @@ static void ecc_init_filters(EcCalibrator *ecc){
        ecc->sndread=ms_snd_card_create_reader(ecc->play_card);
        ms_filter_call_method(ecc->sndread,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate);
        ms_filter_call_method(ecc->sndread,MS_FILTER_GET_SAMPLE_RATE,&rate);
+       ms_filter_call_method(ecc->sndread,MS_FILTER_SET_NCHANNELS,&ecc_channels);
+       ms_filter_call_method(ecc->sndread,MS_FILTER_GET_NCHANNELS,&channels);
        ecc->read_resampler=ms_filter_new(MS_RESAMPLE_ID);
        ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_SAMPLE_RATE,&rate);
        ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&ecc->rate);
+       ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_NCHANNELS,&ecc_channels);
+       ms_filter_call_method(ecc->read_resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&channels);
        
        
        ecc->det=ms_filter_new(MS_TONE_DETECTOR_ID);
@@ -50,7 +56,7 @@ static void ecc_init_filters(EcCalibrator *ecc){
        ms_filter_link(ecc->read_resampler,0,ecc->det,0);
        ms_filter_link(ecc->det,0,ecc->rec,0);
 
-       ecc->play=ms_filter_new(MS_FILE_PLAYER_ID);
+       ecc->play=ms_filter_new(MS_VOID_SOURCE_ID);
        ecc->gen=ms_filter_new(MS_DTMF_GEN_ID);
        ms_filter_call_method(ecc->gen,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate);
        ecc->write_resampler=ms_filter_new(MS_RESAMPLE_ID);
@@ -58,8 +64,12 @@ static void ecc_init_filters(EcCalibrator *ecc){
        
        ms_filter_call_method(ecc->sndwrite,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate);
        ms_filter_call_method(ecc->sndwrite,MS_FILTER_GET_SAMPLE_RATE,&rate);
+       ms_filter_call_method(ecc->sndwrite,MS_FILTER_SET_NCHANNELS,&ecc_channels);
+       ms_filter_call_method(ecc->sndwrite,MS_FILTER_GET_NCHANNELS,&channels);
        ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate);
        ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&rate);
+       ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_NCHANNELS,&ecc_channels);
+       ms_filter_call_method(ecc->write_resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&channels);
 
        ms_filter_link(ecc->play,0,ecc->gen,0);
        ms_filter_link(ecc->gen,0,ecc->write_resampler,0);
@@ -133,6 +143,9 @@ static void on_tone_received(void *data, MSFilter *f, unsigned int event_id, voi
 static void ecc_play_tones(EcCalibrator *ecc){
        MSDtmfGenCustomTone tone;
        MSToneDetectorDef expected_tone;
+       
+       memset(&tone,0,sizeof(tone));
+       memset(&expected_tone,0,sizeof(expected_tone));
 
        ms_filter_set_notify_callback(ecc->det,on_tone_received,ecc);
 
@@ -161,7 +174,7 @@ static void ecc_play_tones(EcCalibrator *ecc){
        
        /*play an initial tone to startup the audio playback/capture*/
        
-       tone.frequency=140;
+       tone.frequencies[0]=140;
        tone.duration=1000;
        tone.amplitude=0.5;
 
@@ -172,17 +185,17 @@ static void ecc_play_tones(EcCalibrator *ecc){
        
        /* play the three tones*/
        
-       tone.frequency=2000;
+       tone.frequencies[0]=2000;
        tone.duration=100;
        ms_filter_call_method(ecc->gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone);
        ms_usleep(300000);
        
-       tone.frequency=2300;
+       tone.frequencies[0]=2300;
        tone.duration=100;
        ms_filter_call_method(ecc->gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone);
        ms_usleep(300000);
        
-       tone.frequency=2500;
+       tone.frequencies[0]=2500;
        tone.duration=100;
        ms_filter_call_method(ecc->gen,MS_DTMF_GEN_PLAY_CUSTOM,&tone);
        ms_sleep(1);