Commit a9f25b14 authored by Alexandre Savard's avatar Alexandre Savard

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

parent 2e3d4ca3
......@@ -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
......@@ -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);
......
......@@ -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_
......@@ -299,6 +299,7 @@ class AudioLayer {
int _errorMessage;
ost::Mutex _mutex;
};
#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)
_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);
......
......@@ -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:
......
......@@ -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);
......
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