Commit a9f25b14 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#2253] Add DcBlocker class to remove capture's dc offset

parent 2e3d4ca3
...@@ -19,6 +19,7 @@ libaudio_la_SOURCES = \ ...@@ -19,6 +19,7 @@ libaudio_la_SOURCES = \
audiolayer.cpp \ audiolayer.cpp \
audiodevice.cpp \ audiodevice.cpp \
samplerateconverter.cpp \ samplerateconverter.cpp \
dcblocker.cpp \
$(SPEEX_SOURCES_CPP) $(SPEEX_SOURCES_CPP)
noinst_HEADERS = \ noinst_HEADERS = \
...@@ -29,6 +30,7 @@ noinst_HEADERS = \ ...@@ -29,6 +30,7 @@ noinst_HEADERS = \
audiodevice.h \ audiodevice.h \
mainbuffer.h \ mainbuffer.h \
recordable.h \ recordable.h \
dcblocker.h \
samplerateconverter.h samplerateconverter.h
...@@ -46,6 +46,8 @@ AlsaLayer::AlsaLayer (ManagerImpl* manager) ...@@ -46,6 +46,8 @@ AlsaLayer::AlsaLayer (ManagerImpl* manager)
_audioThread = new AudioThread (this); _audioThread = new AudioThread (this);
_urgentRingBuffer.createReadPointer(); _urgentRingBuffer.createReadPointer();
dcblocker = new DcBlocker();
} }
// Destructor // Destructor
...@@ -57,6 +59,8 @@ AlsaLayer::~AlsaLayer (void) ...@@ -57,6 +59,8 @@ AlsaLayer::~AlsaLayer (void)
if(_converter) { if(_converter) {
delete _converter; _converter = NULL; delete _converter; _converter = NULL;
} }
delete dcblocker; dcblocker = NULL;
} }
bool bool
...@@ -884,6 +888,8 @@ void AlsaLayer::audioCallback (void) ...@@ -884,6 +888,8 @@ void AlsaLayer::audioCallback (void)
nbSample = _converter->downsampleData ((SFLDataFormat*)in, rsmpl_out, _mainBufferSampleRate, _audioSampleRate, nb_sample_up); 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); _mainBuffer.putData(rsmpl_out, nbSample * sizeof (SFLDataFormat), 100);
free(rsmpl_out); free(rsmpl_out);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "audio/audiolayer.h" #include "audio/audiolayer.h"
#include "audio/samplerateconverter.h" #include "audio/samplerateconverter.h"
#include "audio/dcblocker.h"
#include "eventthread.h" #include "eventthread.h"
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
...@@ -271,6 +272,8 @@ class AlsaLayer : public AudioLayer { ...@@ -271,6 +272,8 @@ class AlsaLayer : public AudioLayer {
int _converterSamplingRate; int _converterSamplingRate;
DcBlocker* dcblocker;
}; };
#endif // _ALSA_LAYER_H_ #endif // _ALSA_LAYER_H_
...@@ -299,6 +299,7 @@ class AudioLayer { ...@@ -299,6 +299,7 @@ class AudioLayer {
int _errorMessage; int _errorMessage;
ost::Mutex _mutex; ost::Mutex _mutex;
}; };
#endif // _AUDIO_LAYER_H_ #endif // _AUDIO_LAYER_H_
/*
* 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;
}
}
/*
* 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
...@@ -41,6 +41,7 @@ PulseLayer::PulseLayer (ManagerImpl* manager) ...@@ -41,6 +41,7 @@ PulseLayer::PulseLayer (ManagerImpl* manager)
_debug ("PulseLayer::Pulse audio constructor: Create context\n"); _debug ("PulseLayer::Pulse audio constructor: Create context\n");
_urgentRingBuffer.createReadPointer(); _urgentRingBuffer.createReadPointer();
dcblocker = new DcBlocker();
} }
// Destructor // Destructor
...@@ -51,6 +52,8 @@ PulseLayer::~PulseLayer (void) ...@@ -51,6 +52,8 @@ PulseLayer::~PulseLayer (void)
if (_converter) { if (_converter) {
delete _converter; _converter = NULL; delete _converter; _converter = NULL;
} }
delete dcblocker; dcblocker = NULL;
} }
bool bool
...@@ -486,6 +489,8 @@ void PulseLayer::readFromMic (void) ...@@ -486,6 +489,8 @@ void PulseLayer::readFromMic (void)
nbSample = _converter->downsampleData ((SFLDataFormat*)data, rsmpl_out, _mainBufferSampleRate, _audioSampleRate, nb_sample_up); 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); _mainBuffer.putData ( (void*) rsmpl_out, nbSample*sizeof(SFLDataFormat), 100);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "audio/audiolayer.h" #include "audio/audiolayer.h"
#include "audio/samplerateconverter.h" #include "audio/samplerateconverter.h"
#include "audio/dcblocker.h"
#include "audiostream.h" #include "audiostream.h"
#include <pulse/pulseaudio.h> #include <pulse/pulseaudio.h>
...@@ -198,6 +199,8 @@ class PulseLayer : public AudioLayer { ...@@ -198,6 +199,8 @@ class PulseLayer : public AudioLayer {
int spkrVolume; int spkrVolume;
int micVolume; int micVolume;
DcBlocker* dcblocker;
// private: // private:
public: public:
......
...@@ -594,8 +594,8 @@ int SIPVoIPLink::sendRegister (AccountID id) ...@@ -594,8 +594,8 @@ int SIPVoIPLink::sendRegister (AccountID id)
pjsip_tpselector *tp; pjsip_tpselector *tp;
init_transport_selector (account->getAccountTransport (), &tp); // init_transport_selector (account->getAccountTransport (), &tp);
status = pjsip_regc_set_transport (regc, tp); // status = pjsip_regc_set_transport (regc, tp);
if (status != PJ_SUCCESS) { if (status != PJ_SUCCESS) {
_debug ("UserAgent: Unable to set transport.\n"); _debug ("UserAgent: Unable to set transport.\n");
...@@ -1322,9 +1322,9 @@ SIPVoIPLink::SIPStartCall (SIPCall* call, const std::string& subject UNUSED) ...@@ -1322,9 +1322,9 @@ SIPVoIPLink::SIPStartCall (SIPCall* call, const std::string& subject UNUSED)
call->setInvSession (inv); call->setInvSession (inv);
// Set the appropriate transport // Set the appropriate transport
pjsip_tpselector *tp; // pjsip_tpselector *tp;
init_transport_selector (account->getAccountTransport (), &tp); // init_transport_selector (account->getAccountTransport (), &tp);
status = pjsip_dlg_set_transport (dialog, tp); // status = pjsip_dlg_set_transport (dialog, tp);
status = pjsip_inv_send_msg (inv, tdata); status = pjsip_inv_send_msg (inv, tdata);
......
Supports Markdown
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