Commit 4870710a authored by Alexandre Savard's avatar Alexandre Savard

#5814: Add parameters for echo cancel

parent cb35f874
......@@ -798,6 +798,24 @@ active_echo_cancel(void)
dbus_set_echo_cancel_state(newstate);
}
void
echo_tail_length_changed(GtkRange *range, gpointer user_data)
{
gint value;
value = (gint)gtk_range_get_value(range);
dbus_set_echo_cancel_tail_length(value);
}
void
echo_delay_changed(GtkRange *range, gpointer user_data)
{
gint value;
value = (gint)gtk_range_get_value(range);
dbus_set_echo_cancel_delay(value);
}
void
active_is_always_recording (void)
{
......@@ -945,6 +963,8 @@ GtkWidget* create_audio_configuration()
GtkWidget *frame;
GtkWidget *enableNoiseReduction;
GtkWidget *enableEchoCancel;
GtkWidget *echoTailLength;
GtkWidget *echoDelay;
gboolean noisesuppressActive;
gboolean echoCancelActive;
gchar *state;
......@@ -955,7 +975,7 @@ GtkWidget* create_audio_configuration()
GtkWidget *alsa;
GtkWidget *table;
gnome_main_section_new_with_table (_ ("Sound Manager"), &frame, &table, 1, 2);
gnome_main_section_new_with_table (_ ("Sound Manager"), &frame, &table, 1, 4);
gtk_box_pack_start (GTK_BOX (ret), frame, FALSE, FALSE, 0);
int audio_manager = dbus_get_audio_manager();
......@@ -1047,6 +1067,18 @@ GtkWidget* create_audio_configuration()
g_signal_connect(G_OBJECT(enableEchoCancel), "clicked", active_echo_cancel, NULL);
gtk_table_attach(GTK_TABLE(table), enableEchoCancel, 0, 1, 2, 3, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gint value = dbus_get_echo_cancel_tail_length();
echoTailLength = gtk_hscale_new_with_range(100, 500, 5);
gtk_range_set_value(GTK_RANGE(echoTailLength), (gdouble)value);
gtk_table_attach(GTK_TABLE(table), echoTailLength, 0, 1, 3, 4, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
g_signal_connect(G_OBJECT(echoTailLength), "value-changed", G_CALLBACK(echo_tail_length_changed), NULL);
value = dbus_get_echo_cancel_delay();
echoDelay = gtk_hscale_new_with_range(0, 500, 5);
gtk_range_set_value(GTK_RANGE(echoDelay), (gdouble)value);
gtk_table_attach(GTK_TABLE(table), echoDelay, 0, 1, 4, 5, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
g_signal_connect(G_OBJECT(echoDelay), "value-changed", G_CALLBACK(echo_delay_changed), NULL);
gtk_widget_show_all (ret);
if (!pulse_audio) {
......
......@@ -227,7 +227,7 @@ class AudioRtpRecordHandler
SIPCall *_ca;
SpeexEchoCancel echoCanceller;
SpeexEchoCancel echoCanceller;
};
}
......
......@@ -20,6 +20,7 @@
#include <fstream>
#include "speexechocancel.h"
#include "manager.h"
// number of samples (20 ms)
#define EC_FRAME_SIZE 160
......@@ -31,12 +32,19 @@ SpeexEchoCancel::SpeexEchoCancel()
{
int samplingRate = 8000;
_debug("EchoCancel: Initializing echo canceller with framesize: %d, filter length: %d, and samplerate %d",
EC_FRAME_SIZE, EC_FILTER_LENGTH, samplingRate);
_echoState = speex_echo_state_init (EC_FRAME_SIZE, EC_FILTER_LENGTH);
int echoDelayMs = Manager::instance().getEchoCancelDelay();
int echoTailLengthMs = Manager::instance().getEchoCancelTailLength();
_echoDelay = echoDelayMs * samplingRate / 1000;
_echoTailLength = echoTailLengthMs * samplingRate / 1000;
// _echoState = speex_echo_state_init (EC_FRAME_SIZE, EC_FILTER_LENGTH);
_echoState = speex_echo_state_init (EC_FRAME_SIZE, _echoTailLength);
_preState = speex_preprocess_state_init (EC_FRAME_SIZE, samplingRate);
_debug("EchoCancel: Initializing echo canceller with delay: %d, filter length: %d, frame size: %d and samplerate %d",
_echoDelay, _echoTailLength, EC_FRAME_SIZE, samplingRate);
speex_echo_ctl (_echoState, SPEEX_ECHO_SET_SAMPLING_RATE, &samplingRate);
speex_preprocess_ctl (_preState, SPEEX_PREPROCESS_SET_ECHO_STATE, _echoState);
......@@ -128,7 +136,8 @@ int SpeexEchoCancel::process (SFLDataFormat *inputData, SFLDataFormat *outputDat
int nbFrame = 0;
// Get data from mic and speaker
if ((spkrAvail >= (byteSize * 6)) && (micAvail >= byteSize)) {
// if ((spkrAvail >= (byteSize * 6)) && (micAvail >= byteSize)) {
if ((spkrAvail >= (_echoDelay+byteSize)) && (micAvail >= byteSize)) {
// get synchronized data
_spkrData->Get (_tmpSpkr, byteSize);
......
......@@ -76,6 +76,9 @@ class SpeexEchoCancel : public Algorithm
RingBuffer *_micData;
RingBuffer *_spkrData;
int _echoDelay;
int _echoTailLength;
bool _spkrStopped;
SFLDataFormat _tmpSpkr[5000];
......
......@@ -3092,6 +3092,7 @@ std::string ManagerImpl::getEchoCancelState(void)
void ManagerImpl::setEchoCancelState(std::string state)
{
bool isEnabled = (state == "enabled");
audioPreference.setEchoCancel(isEnabled);
......@@ -3099,21 +3100,25 @@ void ManagerImpl::setEchoCancelState(std::string state)
int ManagerImpl::getEchoCancelTailLength(void)
{
_debug("-------------------------------------- getEchoTailLength %d", audioPreference.getEchoCancelTailLength());
return audioPreference.getEchoCancelTailLength();
}
void ManagerImpl::setEchoCancelTailLength(int length)
{
_debug("------------------------------------- setEchoTailLength %d", length);
audioPreference.setEchoCancelTailLength(length);
}
int ManagerImpl::getEchoCancelDelay(void)
{
_debug("------------------------------------- getEchoCancelDelay %d", audioPreference.getEchoCancelDelay());
return audioPreference.getEchoCancelDelay();
}
void ManagerImpl::setEchoCancelDelay(int delay)
{
_debug("------------------------------------- setEchoCancelDelay %d", delay);
audioPreference.setEchoCancelDelay(delay);
}
......
......@@ -542,9 +542,11 @@ void AudioPreference::serialize (Conf::YamlEmitter *emitter)
Conf::ScalarNode noise (_noisereduce ? "true":"false");
Conf::ScalarNode echo(_echocancel ? "true" : "false");
std::stringstream tailstr;
_debug("************************************************** serialize echotail %d", _echoCancelTailLength);
tailstr << _echoCancelTailLength;
Conf::ScalarNode echotail(tailstr.str());
std::stringstream delaystr;
_debug("************************************************** serialize echodelay %d", _echoCancelTailLength);
delaystr << _echoCancelDelay;
Conf::ScalarNode echodelay(delaystr.str());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment