]> sjero.net Git - linphone/commitdiff
Custom sample rate for echo calibration.
authorGuillaume Beraudo <guillaume.beraudo@belledonne-communications.com>
Mon, 23 May 2011 14:32:28 +0000 (16:32 +0200)
committerGuillaume Beraudo <guillaume.beraudo@belledonne-communications.com>
Mon, 23 May 2011 14:32:28 +0000 (16:32 +0200)
New "echo_cancellation_rate" config file key.

coreapi/ec-calibrator.c
coreapi/private.h
coreapi/test_ecc.c
mediastreamer2

index 4c8a37586ebf538f580915bdd39424a3321d4dab..38b83f0d6065abd1c3257599df7594d438d27a71 100644 (file)
@@ -23,15 +23,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "mediastreamer2/mstonedetector.h"
 #include "mediastreamer2/dtmfgen.h"
 
-
+#include "lpconfig.h"
 
 
 
 static void ecc_init_filters(EcCalibrator *ecc){
+       unsigned int rate;
        ecc->ticker=ms_ticker_new();
 
        ecc->sndread=ms_snd_card_create_reader(ecc->play_card);
+       ms_filter_call_method(ecc->sndread,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate);
        ecc->det=ms_filter_new(MS_TONE_DETECTOR_ID);
+       ms_filter_call_method(ecc->det,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate);
        ecc->rec=ms_filter_new(MS_FILE_REC_ID);
 
        ms_filter_link(ecc->sndread,0,ecc->det,0);
@@ -39,14 +42,17 @@ static void ecc_init_filters(EcCalibrator *ecc){
 
        ecc->play=ms_filter_new(MS_FILE_PLAYER_ID);
        ecc->gen=ms_filter_new(MS_DTMF_GEN_ID);
+       ms_filter_call_method(ecc->gen,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate);
        ecc->resampler=ms_filter_new(MS_RESAMPLE_ID);
        ecc->sndwrite=ms_snd_card_create_writer(ecc->capt_card);
 
        ms_filter_link(ecc->play,0,ecc->gen,0);
        ms_filter_link(ecc->gen,0,ecc->resampler,0);
        ms_filter_link(ecc->resampler,0,ecc->sndwrite,0);
-       unsigned int rate;
+
+       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->resampler,MS_FILTER_SET_SAMPLE_RATE,&ecc->rate);
        ms_filter_call_method(ecc->resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&rate);
 
        ms_ticker_attach(ecc->ticker,ecc->play);
@@ -149,9 +155,10 @@ static void  * ecc_thread(void *p){
        return NULL;
 }
 
-EcCalibrator * ec_calibrator_new(MSSndCard *play_card, MSSndCard *capt_card, LinphoneEcCalibrationCallback cb, void *cb_data ){
+EcCalibrator * ec_calibrator_new(MSSndCard *play_card, MSSndCard *capt_card, unsigned int rate, LinphoneEcCalibrationCallback cb, void *cb_data ){
        EcCalibrator *ecc=ms_new0(EcCalibrator,1);
 
+       ecc->rate=rate;
        ecc->cb=cb;
        ecc->cb_data=cb_data;
        ecc->capt_card=capt_card;
@@ -174,6 +181,7 @@ int linphone_core_start_echo_calibration(LinphoneCore *lc, LinphoneEcCalibration
                ms_error("Echo calibration is still on going !");
                return -1;
        }
-       lc->ecc=ec_calibrator_new(lc->sound_conf.play_sndcard,lc->sound_conf.capt_sndcard,cb,cb_data);
+       unsigned int rate = lp_config_get_int(lc->config,"sound","echo_cancellation_rate",8000);
+       lc->ecc=ec_calibrator_new(lc->sound_conf.play_sndcard,lc->sound_conf.capt_sndcard,rate,cb,cb_data);
        return 0;
 }
index aea7e2e4253f250dfcb07199cd9f879d12a9b846..b9d79776e2b5da31c5659e897a6dbb01999bf500 100644 (file)
@@ -472,6 +472,7 @@ struct _EcCalibrator{
        int sent_count;
        int64_t acc;
        int delay;
+       unsigned int rate;
        LinphoneEcCalibratorStatus status;
 };
 
index 7553c20189ad021056aaea880d0821176b11d68b..43ae0dcb2bf4c3e7485be432c2628f80dbfc72c5 100644 (file)
@@ -27,10 +27,21 @@ static void calibration_finished(LinphoneCore *lc, LinphoneEcCalibratorStatus st
        if (status==LinphoneEcCalibratorDone) ms_message("Measured delay is %i",delay);
 }
 
+
+static char config_file[1024];
+void parse_args(int argc, char *argv[]){
+       if (argc != 3 || strncmp("-c",argv[1], 2) || access(argv[2],F_OK)!=0) {
+               printf("Usage: test_ecc [-c config_file] where config_file will be written with the detected value\n");
+               exit(-1);
+       }
+       strncpy(config_file,argv[2],1024);
+}
+
 int main(int argc, char *argv[]){
+       if (argc>1) parse_args(argc,argv);
        int count=0;
        LinphoneCoreVTable vtable={0};
-       LinphoneCore *lc=linphone_core_new(&vtable,NULL,NULL,NULL);
+       LinphoneCore *lc=linphone_core_new(&vtable,config_file,NULL,NULL);
        
        linphone_core_enable_logs(NULL);
 
index 0781bd574fc09a43bcadcb55d8f1563d6493629c..45a3e458669ae7d3f5537665d7549d82469cf96f 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 0781bd574fc09a43bcadcb55d8f1563d6493629c
+Subproject commit 45a3e458669ae7d3f5537665d7549d82469cf96f