echo-cancel: Fix echo suppression, add some knobs
authorBart Cerneels <bart.cerneels@kde.org>
Sat, 28 May 2011 02:27:22 +0000 (07:57 +0530)
committerArun Raghavan <arun.raghavan@collabora.co.uk>
Sat, 28 May 2011 02:29:07 +0000 (07:59 +0530)
The echo suppress attenuation value was being incorrectly modified.
Fixed and added 2 arguments to change the attenuation of the residual
echo filter. Default values of the speex preprocessor will be used when
omitted.

src/modules/echo-cancel/echo-cancel.h
src/modules/echo-cancel/module-echo-cancel.c

index 5f18053..aa40adc 100644 (file)
@@ -68,6 +68,8 @@ struct pa_echo_canceller {
     pa_bool_t agc;
     pa_bool_t denoise;
     pa_bool_t echo_suppress;
+    int32_t echo_suppress_attenuation;
+    int32_t echo_suppress_attenuation_active;
     SpeexPreprocessState *pp_state;
 };
 
index 90577d4..cb30832 100644 (file)
@@ -79,7 +79,9 @@ PA_MODULE_USAGE(
           "aec_args=<parameters for the AEC engine> "
           "agc=<perform automagic gain control?> "
           "denoise=<apply denoising?> "
-          "echo_suppress=<perform echo suppression? (only with the speex canceller)> "
+          "echo_suppress=<perform residual echo suppression? (only with the speex canceller)> "
+          "echo_suppress_attenuation=<dB value of residual echo attenuation> "
+          "echo_suppress_attenuation_active=<dB value of residual echo attenuation when near end is active> "
           "save_aec=<save AEC data in /tmp> "
           "autoloaded=<set if this module is being loaded automatically> "
         ));
@@ -112,6 +114,7 @@ static const pa_echo_canceller ec_table[] = {
 #define DEFAULT_AGC_ENABLED FALSE
 #define DEFAULT_DENOISE_ENABLED FALSE
 #define DEFAULT_ECHO_SUPPRESS_ENABLED FALSE
+#define DEFAULT_ECHO_SUPPRESS_ATTENUATION 0
 #define DEFAULT_SAVE_AEC 0
 #define DEFAULT_AUTOLOADED FALSE
 
@@ -221,6 +224,8 @@ static const char* const valid_modargs[] = {
     "agc",
     "denoise",
     "echo_suppress",
+    "echo_suppress_attenuation",
+    "echo_suppress_attenuation_active",
     "save_aec",
     "autoloaded",
     NULL
@@ -1429,6 +1434,26 @@ int pa__init(pa_module*m) {
         goto fail;
     }
 
+    u->ec->echo_suppress_attenuation = DEFAULT_ECHO_SUPPRESS_ATTENUATION;
+    if (pa_modargs_get_value_s32(ma, "echo_suppress_attenuation", &u->ec->echo_suppress_attenuation) < 0) {
+        pa_log("Failed to parse echo_suppress_attenuation value");
+        goto fail;
+    }
+    if (u->ec->echo_suppress_attenuation > 0) {
+        pa_log("echo_suppress_attenuation should be a negative dB value");
+        goto fail;
+    }
+
+    u->ec->echo_suppress_attenuation_active = DEFAULT_ECHO_SUPPRESS_ATTENUATION;
+    if (pa_modargs_get_value_s32(ma, "echo_suppress_attenuation_active", &u->ec->echo_suppress_attenuation_active) < 0) {
+        pa_log("Failed to parse echo_supress_attenuation_active value");
+        goto fail;
+    }
+    if (u->ec->echo_suppress_attenuation_active > 0) {
+        pa_log("echo_suppress_attenuation_active should be a negative dB value");
+        goto fail;
+    }
+
     u->save_aec = DEFAULT_SAVE_AEC;
     if (pa_modargs_get_value_u32(ma, "save_aec", &u->save_aec) < 0) {
         pa_log("Failed to parse save_aec value");
@@ -1460,9 +1485,15 @@ int pa__init(pa_module*m) {
 
         speex_preprocess_ctl(u->ec->pp_state, SPEEX_PREPROCESS_SET_AGC, &u->ec->agc);
         speex_preprocess_ctl(u->ec->pp_state, SPEEX_PREPROCESS_SET_DENOISE, &u->ec->denoise);
-        speex_preprocess_ctl(u->ec->pp_state, SPEEX_PREPROCESS_SET_ECHO_SUPPRESS, &u->ec->echo_suppress);
-        if (u->ec->echo_suppress)
+        if (u->ec->echo_suppress) {
+            if (u->ec->echo_suppress_attenuation)
+                speex_preprocess_ctl(u->ec->pp_state, SPEEX_PREPROCESS_SET_ECHO_SUPPRESS, &u->ec->echo_suppress_attenuation);
+            if (u->ec->echo_suppress_attenuation_active) {
+                speex_preprocess_ctl(u->ec->pp_state, SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE,
+                                     &u->ec->echo_suppress_attenuation_active);
+            }
             speex_preprocess_ctl(u->ec->pp_state, SPEEX_PREPROCESS_SET_ECHO_STATE, u->ec->params.priv.speex.state);
+        }
     }
 
     /* Create source */