Skip to content
Snippets Groups Projects
Commit b7286e03 authored by Julien Bonjean's avatar Julien Bonjean
Browse files

[#2402] Code indent

parent 3298edc0
No related branches found
No related tags found
No related merge requests found
Showing
with 1128 additions and 1051 deletions
......@@ -5,7 +5,7 @@
# Savoir-faire Linux Inc
# http://www.sflphone.org
style=kr # Kernighan & Ritchie style formatting/indenting uses linux bracket
style=k&r # Kernighan & Ritchie style formatting/indenting uses linux bracket
indent=spaces=4 # Use spaces instead of tabs for indentation
indent-classes # Indent 'class' and 'struct' blocks so that the blocks 'public:', 'protected:' and 'private:' are indented
indent-switches # Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block
......
......@@ -52,18 +52,22 @@ Account::~Account()
{
}
void Account::loadConfig() {
void Account::loadConfig()
{
// If IAX is not supported, do not register this account
#ifndef USE_IAX
if (_type == "IAX")
_enabled = false;
#endif
loadAudioCodecs ();
}
void Account::setRegistrationState (RegistrationState state) {
void Account::setRegistrationState (RegistrationState state)
{
if (state != _registrationState) {
_debug ("Account: set registration state");
......@@ -74,7 +78,8 @@ void Account::setRegistrationState (RegistrationState state) {
}
}
void Account::loadAudioCodecs (void) {
void Account::loadAudioCodecs (void)
{
// if the user never set the codec list, use the default configuration for this account
if (_codecStr == "") {
......@@ -90,7 +95,8 @@ void Account::loadAudioCodecs (void) {
}
}
void Account::setActiveCodecs (const std::vector <std::string> &list) {
void Account::setActiveCodecs (const std::vector <std::string> &list)
{
_codecOrder.clear();
// list contains the ordered payload of active codecs picked by the user for this account
......
......@@ -170,8 +170,7 @@ AlsaLayer::startStream (void)
pcmp = buildDeviceTopo (PCM_DMIX, _indexOut, 0);
pcmr = buildDeviceTopo (PCM_DMIX, _indexRing, 0);
pcmc = buildDeviceTopo (PCM_DSNOOP, _indexIn, 0);
}
else {
} else {
pcmp = buildDeviceTopo (_audioPlugin, _indexOut, 0);
pcmr = buildDeviceTopo (_audioPlugin, _indexRing, 0);
pcmc = buildDeviceTopo (_audioPlugin, _indexIn, 0);
......@@ -493,8 +492,7 @@ bool AlsaLayer::alsa_set_params (snd_pcm_t *pcm_handle, int type, int rate)
if ( (err = snd_pcm_hw_params_set_rate_near (pcm_handle, hwparams, &exact_ivalue, &dir) < 0)) {
_debugAlsa ("Audio: Error: Cannot set sample rate (%s)", snd_strerror (err));
return false;
}
else
} else
_debug ("Audio: Set audio rate to %d", rate);
if (dir!= 0) {
......@@ -958,8 +956,7 @@ void AlsaLayer::audioCallback(void)
free (out);
out = 0;
}
else if (file_tone && !_RingtoneHandle && (normalAvailBytes <= 0)) {
} else if (file_tone && !_RingtoneHandle && (normalAvailBytes <= 0)) {
out = (SFLDataFormat *) malloc (playbackAvailBytes);
file_tone->getNext (out, playbackAvailSmpl, spkrVolume);
......
......@@ -73,7 +73,8 @@ int AudioProcessing::processAudio(SFLDataFormat *inputData, SFLDataFormat *outpu
}
void AudioProcessing::processAudio(SFLDataFormat *micData, SFLDataFormat *spkrData, SFLDataFormat *outputData, int nbBytes) {
void AudioProcessing::processAudio (SFLDataFormat *micData, SFLDataFormat *spkrData, SFLDataFormat *outputData, int nbBytes)
{
if (_algorithm)
_algorithm->process (micData, spkrData, outputData, nbBytes);
}
......@@ -199,13 +199,11 @@ bool AudioRecord::setRecording()
if (!recordingEnabled_) {
_info ("AudioRecording: Start recording");
recordingEnabled_ = true;
}
else {
} else {
recordingEnabled_ = false;
_info ("AudioRecording: Stop recording");
}
}
else {
} else {
openFile();
recordingEnabled_ = true; // once opend file, start recording
......@@ -412,10 +410,12 @@ void AudioRecord::closeWavFile()
SINT32 bytes = byteCounter_ * channels_;
fseek (fp, 40, SEEK_SET); // jump to data length
if (ferror (fp))
_warn ("AudioRecord: Error: can't reach offset 40 while closing");
fwrite (&bytes, sizeof (SINT32), 1, fp);
if (ferror (fp))
_warn ("AudioRecord: Error: can't write bytes for data length ");
......@@ -423,10 +423,12 @@ void AudioRecord::closeWavFile()
bytes = byteCounter_ * channels_ + 44; // + 44 for the wave header
fseek (fp, 4, SEEK_SET); // jump to file size
if (ferror (fp))
_warn ("AudioRecord: Error: can't reach offset 4");
fwrite (&bytes, 4, 1, fp);
if (ferror (fp))
_warn ("AudioRecord: Error: can't reach offset 4");
......
......@@ -95,6 +95,7 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca)
ost::MutexLock m (_audioRtpThreadMutex);
_debug ("Srtp enable: %d ", _srtpEnabled);
if (_srtpEnabled) {
std::string zidFilename (Manager::instance().getConfigString (SIGNALISATION, ZRTP_ZIDFILE));
......@@ -141,9 +142,11 @@ void AudioRtpFactory::start (AudioCodec* audiocodec)
switch (_rtpSessionType) {
case Sdes:
if (static_cast<AudioSrtpSession *> (_rtpSession)->startRtpThread (audiocodec) != 0) {
throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioSRtpSession thread");
}
break;
case Symmetric:
......@@ -160,6 +163,7 @@ void AudioRtpFactory::start (AudioCodec* audiocodec)
if (static_cast<AudioZrtpSession *> (_rtpSession)->startRtpThread (audiocodec) != 0) {
throw AudioRtpFactoryException ("RTP: Error: Failed to start AudioZrtpSession thread");
}
break;
}
}
......@@ -200,6 +204,7 @@ void AudioRtpFactory::stop (void)
void AudioRtpFactory::updateDestinationIpAddress (void)
{
_info ("RTP: Updating IP address");
if (_rtpSession == NULL) {
throw AudioRtpFactoryException ("RTP: Error: _rtpSession was null when trying to update IP address");
}
......@@ -242,13 +247,13 @@ void AudioRtpFactory::setRemoteCryptoInfo(sfl::SdesNegotiator& nego)
{
if (_rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) {
static_cast<AudioSrtpSession *> (_rtpSession)->setRemoteCryptoInfo (nego);
}
else {
} else {
throw AudioRtpFactoryException ("RTP: Error: _rtpSession is NULL in setRemoteCryptoInfo");
}
}
void AudioRtpFactory::sendDtmfDigit(int digit) {
void AudioRtpFactory::sendDtmfDigit (int digit)
{
switch (_rtpSessionType) {
case Sdes:
......
......@@ -72,7 +72,8 @@ AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) :
}
std::vector<std::string> AudioSrtpSession::getLocalCryptoInfo() {
std::vector<std::string> AudioSrtpSession::getLocalCryptoInfo()
{
_debug ("Get Cryptographic info from this rtp session");
......@@ -104,7 +105,8 @@ std::vector<std::string> AudioSrtpSession::getLocalCryptoInfo() {
}
void AudioSrtpSession::setRemoteCryptoInfo(sfl::SdesNegotiator& nego) {
void AudioSrtpSession::setRemoteCryptoInfo (sfl::SdesNegotiator& nego)
{
_debug ("Set remote Cryptographic info for Srtp");
......@@ -128,6 +130,7 @@ void AudioSrtpSession::initializeLocalMasterKey(void)
// Generate ryptographically strong pseudo-random bytes
int err;
if ( (err = RAND_bytes (random_key, _localMasterKeyLength)) != 1)
_debug ("Error occured while generating cryptographically strong pseudo-random key");
......@@ -155,6 +158,7 @@ void AudioSrtpSession::initializeLocalMasterSalt(void)
// Generate ryptographically strong pseudo-random bytes
int err;
if ( (err = RAND_bytes (random_key, _localMasterSaltLength)) != 1)
_debug ("Error occured while generating cryptographically strong pseudo-random key");
......
......@@ -75,7 +75,8 @@ CodecDescriptor::init()
}
}
void CodecDescriptor::setDefaultOrder() {
void CodecDescriptor::setDefaultOrder()
{
_defaultCodecOrder.clear();
CodecsMap::iterator iter = _CodecsMap.begin();
......@@ -115,7 +116,8 @@ CodecDescriptor::getCodec (AudioCodecType payload)
return NULL;
}
double CodecDescriptor::getBitRate (AudioCodecType payload) {
double CodecDescriptor::getBitRate (AudioCodecType payload)
{
CodecsMap::iterator iter = _CodecsMap.find (payload);
......@@ -125,7 +127,8 @@ double CodecDescriptor::getBitRate (AudioCodecType payload) {
return 0.0;
}
double CodecDescriptor::getBandwidthPerCall (AudioCodecType payload) {
double CodecDescriptor::getBandwidthPerCall (AudioCodecType payload)
{
CodecsMap::iterator iter = _CodecsMap.find (payload);
......@@ -135,7 +138,8 @@ double CodecDescriptor::getBandwidthPerCall (AudioCodecType payload) {
return 0.0;
}
int CodecDescriptor::getSampleRate (AudioCodecType payload) {
int CodecDescriptor::getSampleRate (AudioCodecType payload)
{
CodecsMap::iterator iter = _CodecsMap.find (payload);
......@@ -145,7 +149,8 @@ int CodecDescriptor::getSampleRate (AudioCodecType payload) {
return 0;
}
void CodecDescriptor::saveActiveCodecs (const std::vector<std::string>& list) {
void CodecDescriptor::saveActiveCodecs (const std::vector<std::string>& list)
{
_defaultCodecOrder.clear();
// list contains the ordered payload of active codecs picked by the user
......@@ -166,7 +171,8 @@ void CodecDescriptor::saveActiveCodecs (const std::vector<std::string>& list) {
}
}
std::vector<AudioCodec*> CodecDescriptor::scanCodecDirectory (void) {
std::vector<AudioCodec*> CodecDescriptor::scanCodecDirectory (void)
{
std::vector<AudioCodec*> codecs;
std::string tmp;
......@@ -206,7 +212,8 @@ std::vector<AudioCodec*> CodecDescriptor::scanCodecDirectory (void) {
return codecs;
}
AudioCodec* CodecDescriptor::loadCodec (std::string path) {
AudioCodec* CodecDescriptor::loadCodec (std::string path)
{
CodecHandlePointer p;
using std::cerr;
......@@ -232,7 +239,8 @@ AudioCodec* CodecDescriptor::loadCodec (std::string path) {
}
void CodecDescriptor::unloadCodec (CodecHandlePointer p) {
void CodecDescriptor::unloadCodec (CodecHandlePointer p)
{
using std::cerr;
destroy_t* destroyCodec = (destroy_t*) dlsym (p.second , "destroy");
......@@ -245,7 +253,8 @@ void CodecDescriptor::unloadCodec (CodecHandlePointer p) {
dlclose (p.second);
}
AudioCodec* CodecDescriptor::instantiateCodec (AudioCodecType payload) {
AudioCodec* CodecDescriptor::instantiateCodec (AudioCodecType payload)
{
using std::cerr;
......@@ -262,6 +271,7 @@ AudioCodec* CodecDescriptor::instantiateCodec (AudioCodecType payload) {
return a;
}
iter++;
}
......@@ -270,7 +280,8 @@ AudioCodec* CodecDescriptor::instantiateCodec (AudioCodecType payload) {
AudioCodec* CodecDescriptor::getFirstCodecAvailable (void) {
AudioCodec* CodecDescriptor::getFirstCodecAvailable (void)
{
CodecsMap::iterator iter = _CodecsMap.begin();
......@@ -280,7 +291,8 @@ AudioCodec* CodecDescriptor::getFirstCodecAvailable (void) {
return NULL;
}
bool CodecDescriptor::seemsValid (std::string lib) {
bool CodecDescriptor::seemsValid (std::string lib)
{
// The name of the shared library seems valid <==> it looks like libcodec_xxx.so
// We check this
......@@ -302,6 +314,7 @@ bool CodecDescriptor::seemsValid (std::string lib) {
#ifdef HAVE_SPEEX_CODEC
// Nothing special
#else
if (lib.substr (begin.length() , lib.length() - begin.length() - end.length()) == SPEEX_STRING_DESCRIPTION)
return false;
......@@ -310,6 +323,7 @@ bool CodecDescriptor::seemsValid (std::string lib) {
#ifdef HAVE_GSM_CODEC
// Nothing special
#else
if (lib.substr (begin.length() , lib.length() - begin.length() - end.length()) == GSM_STRING_DESCRIPTION)
return false;
......@@ -318,6 +332,7 @@ bool CodecDescriptor::seemsValid (std::string lib) {
#ifdef BUILD_ILBC
// Nothing special
#else
if (lib.substr (begin.length() , lib.length() - begin.length() - end.length()) == ILBC_STRING_DESCRIPTION)
return false;
......@@ -346,7 +361,8 @@ CodecDescriptor::alreadyInCache (std::string lib)
return false;
}
bool CodecDescriptor::isCodecLoaded (int payload) {
bool CodecDescriptor::isCodecLoaded (int payload)
{
CodecsMap::iterator iter = _CodecsMap.begin();
......@@ -360,7 +376,8 @@ bool CodecDescriptor::isCodecLoaded (int payload) {
return false;
}
std::vector <std::string> CodecDescriptor::getCodecSpecifications (const int32_t& payload) {
std::vector <std::string> CodecDescriptor::getCodecSpecifications (const int32_t& payload)
{
_debug ("CodecDescriptor: Gathering codec specifications for payload %i", payload);
......
......@@ -31,8 +31,7 @@
#include "audiocodec.h"
extern "C"
{
extern "C" {
#include <gsm/gsm.h>
}
......
......@@ -44,13 +44,17 @@ void DcBlocker::reset()
void DcBlocker::putData (SFLDataFormat *inputData UNUSED, int nbBytes UNUSED) {}
int DcBlocker::getData(SFLDataFormat *outputData UNUSED) { return 0; }
int DcBlocker::getData (SFLDataFormat *outputData UNUSED)
{
return 0;
}
void DcBlocker::process (SFLDataFormat *data, int nbBytes)
{
// y(n) = x(n) - x(n-1) + R y(n-1) , R = 0.9999
int nbSamples = nbBytes / sizeof (SFLDataFormat);
for (int i = 0; i < nbSamples; i++) {
_x = data[i];
......@@ -63,9 +67,11 @@ void DcBlocker::process (SFLDataFormat *data, int nbBytes)
}
}
int DcBlocker::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int nbBytes) {
int DcBlocker::process (SFLDataFormat *inputData, SFLDataFormat *outputData, int nbBytes)
{
int nbSamples = nbBytes / sizeof (SFLDataFormat);
for (int i = 0; i < nbSamples; i++) {
_x = inputData[i];
......
......@@ -44,7 +44,8 @@ float decimationCoefs[] = {-0.09870257, 0.07473655, 0.05616626, 0.04448337, 0.03
0.06015944, 0.04065763, 0.02183252, 0.00500204, -0.00875287, -0.01869834,
-0.02437806, -0.02602213, -0.02373243, -0.01873722, -0.01120109, -0.00266367,
0.00610982, 0.01463477, 0.02244098, 0.02944626, 0.03630817, 0.04448337,
0.05616626, 0.07473655, -0.09870257};
0.05616626, 0.07473655, -0.09870257
};
std::vector<double> ird (decimationCoefs, decimationCoefs + sizeof (decimationCoefs) /sizeof (float));
......@@ -54,7 +55,8 @@ float bandpassCoefs[] = {0.06278034, -0.0758545, -0.02274943, -0.0084497, 0.0702
-0.06979052, -0.12446371, -0.05530828, 0.00947243, 0.15294699, 0.17735563,
0.15294699, 0.00947243, -0.05530828, -0.12446371, -0.06979052, -0.07236507,
-0.03214543, -0.07568665, -0.03433526, -0.02412049, 0.06436469, 0.05986113,
0.0702427, -0.0084497, -0.02274943, -0.0758545, 0.06278034};
0.0702427, -0.0084497, -0.02274943, -0.0758545, 0.06278034
};
std::vector<double> irb (bandpassCoefs, bandpassCoefs + sizeof (bandpassCoefs) /sizeof (float));
......@@ -72,12 +74,16 @@ float FirFilter::getOutputSample(float inputSample)
_taps[_count] = inputSample;
double result = 0.0;
int index = _count;
for (int i = 0; i < _length; i++) {
result = result + _impulseResponse[i] * _taps[index--];
if (index < 0)
index = _length-1;
}
_count++;
if (_count >= _length)
_count = 0;
......@@ -162,9 +168,13 @@ void DelayDetection::putData(SFLDataFormat *inputData, int nbBytes)
}
int DelayDetection::getData(SFLDataFormat *outputData UNUSED) { return 0; }
int DelayDetection::getData (SFLDataFormat *outputData UNUSED)
{
return 0;
}
void DelayDetection::process(SFLDataFormat *inputData, int nbBytes) {
void DelayDetection::process (SFLDataFormat *inputData, int nbBytes)
{
if (_internalState != WaitForMic)
return;
......@@ -202,11 +212,15 @@ void DelayDetection::process(SFLDataFormat *inputData, int nbBytes) {
_debug ("MaxIndex: %d", maxIndex);
}
int DelayDetection::process(SFLDataFormat *intputData UNUSED, SFLDataFormat *outputData UNUSED, int nbBytes UNUSED) { return 0; }
int DelayDetection::process (SFLDataFormat *intputData UNUSED, SFLDataFormat *outputData UNUSED, int nbBytes UNUSED)
{
return 0;
}
void DelayDetection::process (SFLDataFormat *micData UNUSED, SFLDataFormat *spkrData UNUSED, SFLDataFormat *outputData UNUSED, int nbBytes UNUSED) {}
void DelayDetection::crossCorrelate(float *ref, float *seg, float *res, int refSize, int segSize) {
void DelayDetection::crossCorrelate (float *ref, float *seg, float *res, int refSize, int segSize)
{
_debug ("CrossCorrelate");
......@@ -221,6 +235,7 @@ void DelayDetection::crossCorrelate(float *ref, float *seg, float *res, int refS
// perform crossrelation on signal
float acseg = 0.0;
float r;
while (--tmpsize) {
--ssize;
acseg = correlate (seg+tmpsize, seg+tmpsize, rsize);
......@@ -235,6 +250,7 @@ void DelayDetection::crossCorrelate(float *ref, float *seg, float *res, int refS
// perform crosscorrelation on zerro padded region
int i = 0;
while (rsize) {
acseg = correlate (seg, seg, rsize);
res[ssize-1] = correlate (ref+i, seg, rsize);
......@@ -251,11 +267,13 @@ void DelayDetection::crossCorrelate(float *ref, float *seg, float *res, int refS
}
}
double DelayDetection::correlate(float *sig1, float *sig2, short size) {
double DelayDetection::correlate (float *sig1, float *sig2, short size)
{
short s = size;
double ac = 0.0;
while (s--)
ac += sig1[s]*sig2[s];
......@@ -263,7 +281,8 @@ double DelayDetection::correlate(float *sig1, float *sig2, short size) {
}
void DelayDetection::convertInt16ToFloat32(SFLDataFormat *input, float *output, int nbSamples) {
void DelayDetection::convertInt16ToFloat32 (SFLDataFormat *input, float *output, int nbSamples)
{
#define S2F_FACTOR .000030517578125f;
int len = nbSamples;
......@@ -275,7 +294,8 @@ void DelayDetection::convertInt16ToFloat32(SFLDataFormat *input, float *output,
}
void DelayDetection::downsampleData(float *input, float *output, int nbSamples, int factor) {
void DelayDetection::downsampleData (float *input, float *output, int nbSamples, int factor)
{
int _src_err;
......@@ -297,7 +317,8 @@ void DelayDetection::downsampleData(float *input, float *output, int nbSamples,
}
void DelayDetection::bandpassFilter(float *input, int nbSamples) {
void DelayDetection::bandpassFilter (float *input, int nbSamples)
{
for (int i = 0; i < nbSamples; i++) {
input[i] = _bandpassFilter.getOutputSample (input[i]);
......@@ -305,7 +326,8 @@ void DelayDetection::bandpassFilter(float *input, int nbSamples) {
}
int DelayDetection::getMaxIndex(float *data, int size) {
int DelayDetection::getMaxIndex (float *data, int size)
{
float max = 0.0;
int k;
......
......@@ -291,6 +291,7 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
// Remove noise
if (_noiseActive)
speex_preprocess_run (_noiseState, _tmpMic);
#endif
// Processed echo cancellation
......@@ -308,8 +309,7 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
// increment nb of frame processed
++nbFrame;
}
else {
} else {
_micData->Get (_tmpMic, byteSize);
performEchoCancelNoSpkr (_tmpMic, _tmpOut);
......@@ -330,11 +330,13 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
return nbFrame * _smplPerFrame;
}
void EchoCancel::process(SFLDataFormat *micData UNUSED, SFLDataFormat *spkrData UNUSED, SFLDataFormat *outputData UNUSED, int nbBytes UNUSED){
void EchoCancel::process (SFLDataFormat *micData UNUSED, SFLDataFormat *spkrData UNUSED, SFLDataFormat *outputData UNUSED, int nbBytes UNUSED)
{
}
void EchoCancel::setSamplingRate(int smplRate) {
void EchoCancel::setSamplingRate (int smplRate)
{
if (smplRate != _samplingRate) {
_samplingRate = smplRate;
......@@ -344,7 +346,8 @@ void EchoCancel::setSamplingRate(int smplRate) {
}
void EchoCancel::performEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrData, SFLDataFormat *outputData) {
void EchoCancel::performEchoCancel (SFLDataFormat *micData, SFLDataFormat *spkrData, SFLDataFormat *outputData)
{
for (int k = 0; k < _nbSegmentPerFrame; k++) {
......@@ -356,12 +359,10 @@ void EchoCancel::performEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrDa
if (_spkrLevel >= MIN_SIG_LEVEL) {
if (_micLevel > _spkrLevel) {
increaseFactor (0.2);
}
else {
} else {
_amplFactor = 0.0;
}
}
else {
} else {
increaseFactor (0.01);
}
......@@ -378,13 +379,15 @@ void EchoCancel::performEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrDa
}
void EchoCancel::performEchoCancelNoSpkr(SFLDataFormat *micData, SFLDataFormat *outputData) {
void EchoCancel::performEchoCancelNoSpkr (SFLDataFormat *micData, SFLDataFormat *outputData)
{
for (int k = 0; k < _nbSegmentPerFrame; k++) {
updateMicLevel (micData);
_micLevel = getMaxAmplitude (_avgMicLevelHist, _micHistoryLength) /6;
if (_micLevel > MIN_SIG_LEVEL) {
increaseFactor (0.2);
}
......@@ -401,7 +404,8 @@ void EchoCancel::performEchoCancelNoSpkr(SFLDataFormat *micData, SFLDataFormat *
}
void EchoCancel::updateMicLevel(SFLDataFormat *micData) {
void EchoCancel::updateMicLevel (SFLDataFormat *micData)
{
int micLvl = computeAmplitudeLevel (micData, _smplPerSeg);
......@@ -418,7 +422,8 @@ void EchoCancel::updateMicLevel(SFLDataFormat *micData) {
}
void EchoCancel::updateSpkrLevel(SFLDataFormat *spkrData) {
void EchoCancel::updateSpkrLevel (SFLDataFormat *spkrData)
{
int spkrLvl = computeAmplitudeLevel (spkrData, _smplPerSeg);
......@@ -435,7 +440,8 @@ void EchoCancel::updateSpkrLevel(SFLDataFormat *spkrData) {
}
void EchoCancel::updateEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrData) {
void EchoCancel::updateEchoCancel (SFLDataFormat *micData, SFLDataFormat *spkrData)
{
// Add 1 to make sure we are not dividing by 0
updateMicLevel (micData);
......@@ -480,7 +486,8 @@ void EchoCancel::updateEchoCancel(SFLDataFormat *micData, SFLDataFormat *spkrDat
int EchoCancel::computeAmplitudeLevel(SFLDataFormat *data, int size) {
int EchoCancel::computeAmplitudeLevel (SFLDataFormat *data, int size)
{
int level = 0;
......@@ -497,7 +504,8 @@ int EchoCancel::computeAmplitudeLevel(SFLDataFormat *data, int size) {
}
SFLDataFormat EchoCancel::estimatePower(SFLDataFormat *data, SFLDataFormat *ampl, int size, SFLDataFormat mem) {
SFLDataFormat EchoCancel::estimatePower (SFLDataFormat *data, SFLDataFormat *ampl, int size, SFLDataFormat mem)
{
float memFactor = 1.0 - _alpha;
......@@ -511,7 +519,8 @@ SFLDataFormat EchoCancel::estimatePower(SFLDataFormat *data, SFLDataFormat *ampl
}
int EchoCancel::getMaxAmplitude(int *data, int size) {
int EchoCancel::getMaxAmplitude (int *data, int size)
{
SFLDataFormat level = 0.0;
......@@ -524,7 +533,8 @@ int EchoCancel::getMaxAmplitude(int *data, int size) {
}
void EchoCancel::amplifySignal(SFLDataFormat *micData, SFLDataFormat *outputData, float amplify) {
void EchoCancel::amplifySignal (SFLDataFormat *micData, SFLDataFormat *outputData, float amplify)
{
// for(int i = 0; i < _smplPerSeg; i++)
// outputData[i] = micData[i];
......@@ -536,13 +546,14 @@ void EchoCancel::amplifySignal(SFLDataFormat *micData, SFLDataFormat *outputData
for (int i = 0; i < _smplPerSeg; i++) {
outputData[i] = (SFLDataFormat) ( ( (float) micData[i]) *_delayLineAmplify[_amplDelayIndexOut]);
}
_amplDelayIndexOut++;
_delayLineAmplify[_amplDelayIndexIn++] = amplify;
}
else {
} else {
for (int i = 0; i < _smplPerSeg; i++) {
outputData[i] = micData[i];
}
return;
}
......@@ -556,7 +567,8 @@ void EchoCancel::amplifySignal(SFLDataFormat *micData, SFLDataFormat *outputData
void EchoCancel::increaseFactor(float factor) {
void EchoCancel::increaseFactor (float factor)
{
// Get 200 ms to get back to full amplitude
_amplFactor += factor;
......@@ -567,7 +579,8 @@ void EchoCancel::increaseFactor(float factor) {
}
void EchoCancel::decreaseFactor() {
void EchoCancel::decreaseFactor()
{
// Takes about 50 ms to react
_amplFactor -= 0.2;
......@@ -577,24 +590,29 @@ void EchoCancel::decreaseFactor() {
}
int EchoCancel::performCorrelation(int *data1, int *data2, int size) {
int EchoCancel::performCorrelation (int *data1, int *data2, int size)
{
int correlation = 0;
while (size) {
size--;
correlation += data1[size] * data2[size];
}
return correlation;
}
int EchoCancel::getMaximumIndex(int *data, int size) {
int EchoCancel::getMaximumIndex (int *data, int size)
{
int index = size;
int max = data[size-1];
while (size) {
size--;
if (data[size] > max) {
index = size;
max = data[size];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment