diff --git a/sflphone-common/src/audio/Makefile.am b/sflphone-common/src/audio/Makefile.am index cfbbf30f31c7eeb284814347fd5956bbd7862fbf..19e5f45793c140ae16fc8936023ad03821990b64 100644 --- a/sflphone-common/src/audio/Makefile.am +++ b/sflphone-common/src/audio/Makefile.am @@ -19,6 +19,7 @@ libaudio_la_SOURCES = \ audiolayer.cpp \ audiodevice.cpp \ samplerateconverter.cpp \ + dcblocker.cpp \ $(SPEEX_SOURCES_CPP) noinst_HEADERS = \ @@ -29,6 +30,7 @@ noinst_HEADERS = \ audiodevice.h \ mainbuffer.h \ recordable.h \ + dcblocker.h \ samplerateconverter.h diff --git a/sflphone-common/src/audio/alsa/alsalayer.cpp b/sflphone-common/src/audio/alsa/alsalayer.cpp index 054f0426eafbc85623172e89fcaab3519062b482..92f2fba69ae38af047b3890326e25b938f1b28a6 100644 --- a/sflphone-common/src/audio/alsa/alsalayer.cpp +++ b/sflphone-common/src/audio/alsa/alsalayer.cpp @@ -46,6 +46,8 @@ AlsaLayer::AlsaLayer (ManagerImpl* manager) _audioThread = new AudioThread (this); _urgentRingBuffer.createReadPointer(); + + dcblocker = new DcBlocker(); } // Destructor @@ -57,6 +59,8 @@ AlsaLayer::~AlsaLayer (void) if(_converter) { delete _converter; _converter = NULL; } + + delete dcblocker; dcblocker = NULL; } bool @@ -884,6 +888,8 @@ void AlsaLayer::audioCallback (void) nbSample = _converter->downsampleData ((SFLDataFormat*)in, rsmpl_out, _mainBufferSampleRate, _audioSampleRate, nb_sample_up); + dcblocker->filter_signal(rsmpl_out, nbSample); + _mainBuffer.putData(rsmpl_out, nbSample * sizeof (SFLDataFormat), 100); free(rsmpl_out); diff --git a/sflphone-common/src/audio/alsa/alsalayer.h b/sflphone-common/src/audio/alsa/alsalayer.h index aa827afe262a108ef2d2d8b76360d80a731a0d31..e1d4b189b78d3b79c7ae5194a3751e04fc4e7044 100644 --- a/sflphone-common/src/audio/alsa/alsalayer.h +++ b/sflphone-common/src/audio/alsa/alsalayer.h @@ -22,6 +22,7 @@ #include "audio/audiolayer.h" #include "audio/samplerateconverter.h" +#include "audio/dcblocker.h" #include "eventthread.h" #include <alsa/asoundlib.h> @@ -271,6 +272,8 @@ class AlsaLayer : public AudioLayer { int _converterSamplingRate; + DcBlocker* dcblocker; + }; #endif // _ALSA_LAYER_H_ diff --git a/sflphone-common/src/audio/audiolayer.h b/sflphone-common/src/audio/audiolayer.h index 44fc3036f2fe9930f0c5fb3100295b5bbb795b57..75921da755bb7f9ceb34489f5f2a10be3d85566d 100644 --- a/sflphone-common/src/audio/audiolayer.h +++ b/sflphone-common/src/audio/audiolayer.h @@ -299,6 +299,7 @@ class AudioLayer { int _errorMessage; ost::Mutex _mutex; + }; #endif // _AUDIO_LAYER_H_ diff --git a/sflphone-common/src/audio/dcblocker.cpp b/sflphone-common/src/audio/dcblocker.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c19b3ccc7c1a8db095475b4dffc188594bc3be63 --- /dev/null +++ b/sflphone-common/src/audio/dcblocker.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + + +#include "dcblocker.h" + +DcBlocker::DcBlocker(){ + + y = 0; + x = 0; + xm1 = 0; + ym1 = 0; + +} + +DcBlocker::~DcBlocker(){ + + +} + +void DcBlocker::filter_signal(SFLDataFormat* audio_data, int length) +{ + // y(n) = x(n) - x(n-1) + R y(n-1) , R = 0.9999 + + for(int i = 0; i < length; i++) { + + x = audio_data[i]; + + y = (SFLDataFormat)((float)x - (float)xm1 + 0.9999 * (float)ym1); + xm1 = x; + ym1 = y; + + audio_data[i] = y; + + } + +} diff --git a/sflphone-common/src/audio/dcblocker.h b/sflphone-common/src/audio/dcblocker.h new file mode 100644 index 0000000000000000000000000000000000000000..0fab73167840d6922ff9cadd20d9152156a08983 --- /dev/null +++ b/sflphone-common/src/audio/dcblocker.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2009 Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#ifndef DCBLOCKER_H +#define DCBLOCKER_H + +#include "global.h" + +class DcBlocker { + +public: + + DcBlocker(); + + ~DcBlocker(); + + void filter_signal(SFLDataFormat* audio_data, int length); + +private: + + SFLDataFormat y, x, xm1, ym1; +}; + +#endif diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp index 47e0090d637d509d04da10f6c9ab0ece979d111e..e8ae5f0521954c7c8859508507f8d36e3f29dc13 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp @@ -41,6 +41,7 @@ PulseLayer::PulseLayer (ManagerImpl* manager) _debug ("PulseLayer::Pulse audio constructor: Create context\n"); _urgentRingBuffer.createReadPointer(); + dcblocker = new DcBlocker(); } // Destructor @@ -51,6 +52,8 @@ PulseLayer::~PulseLayer (void) if (_converter) { delete _converter; _converter = NULL; } + + delete dcblocker; dcblocker = NULL; } bool @@ -486,6 +489,8 @@ void PulseLayer::readFromMic (void) nbSample = _converter->downsampleData ((SFLDataFormat*)data, rsmpl_out, _mainBufferSampleRate, _audioSampleRate, nb_sample_up); + // remove dc offset + dcblocker->filter_signal( rsmpl_out, nbSample ); _mainBuffer.putData ( (void*) rsmpl_out, nbSample*sizeof(SFLDataFormat), 100); diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.h b/sflphone-common/src/audio/pulseaudio/pulselayer.h index 3fd54cec7d2719a5a714f3d8512c2fe5355807cf..efe0e7f3fd5527e1a6881c2b1b93fe0a0c99fbf1 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.h +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.h @@ -22,6 +22,7 @@ #include "audio/audiolayer.h" #include "audio/samplerateconverter.h" +#include "audio/dcblocker.h" #include "audiostream.h" #include <pulse/pulseaudio.h> @@ -198,6 +199,8 @@ class PulseLayer : public AudioLayer { int spkrVolume; int micVolume; + DcBlocker* dcblocker; + // private: public: diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index 26108d4999e3dbeba6004f732cf076d9a74365b4..095185b41e44612acef385ff99ec4a2d00ea1c4c 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -594,8 +594,8 @@ int SIPVoIPLink::sendRegister (AccountID id) pjsip_tpselector *tp; - init_transport_selector (account->getAccountTransport (), &tp); - status = pjsip_regc_set_transport (regc, tp); + // init_transport_selector (account->getAccountTransport (), &tp); + // status = pjsip_regc_set_transport (regc, tp); if (status != PJ_SUCCESS) { _debug ("UserAgent: Unable to set transport.\n"); @@ -1322,9 +1322,9 @@ SIPVoIPLink::SIPStartCall (SIPCall* call, const std::string& subject UNUSED) call->setInvSession (inv); // Set the appropriate transport - pjsip_tpselector *tp; - init_transport_selector (account->getAccountTransport (), &tp); - status = pjsip_dlg_set_transport (dialog, tp); + // pjsip_tpselector *tp; + // init_transport_selector (account->getAccountTransport (), &tp); + // status = pjsip_dlg_set_transport (dialog, tp); status = pjsip_inv_send_msg (inv, tdata);