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

[#3458] Make libspeexdsp optional in echo canceller

parent cf40250f
......@@ -90,6 +90,7 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
_spkrHistoryLength = SPKR_LENGTH / SEGMENT_LENGTH;
_nbSegmentPerFrame = _frameLength / SEGMENT_LENGTH;
#ifdef HAVE_SPEEXDSP_LIB
_noiseState = speex_preprocess_state_init(_smplPerFrame, _samplingRate);
int i=1;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DENOISE, &i);
......@@ -105,6 +106,7 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f);
f=0.0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
#endif
memset(_avgSpkrLevelHist, 0, BUFF_SIZE*sizeof(int));
memset(_avgMicLevelHist, 0, BUFF_SIZE*sizeof(int));
......@@ -128,8 +130,9 @@ EchoCancel::~EchoCancel()
delete _spkrData;
_spkrData = NULL;
#ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_state_destroy(_noiseState);
#endif
micFile->close();
spkrFile->close();
......@@ -183,6 +186,7 @@ void EchoCancel::reset()
_spkrData->flushAll();
_spkrDataOut->flushAll();
#ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_state_destroy(_noiseState);
_noiseState = speex_preprocess_state_init(_smplPerFrame, _samplingRate);
......@@ -200,6 +204,7 @@ void EchoCancel::reset()
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f);
f=0.0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f);
#endif
_spkrStoped = true;
......@@ -271,9 +276,11 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
micFile->write((const char *)_tmpMic, byteSize);
spkrFile->write((const char *)_tmpSpkr, byteSize);
#ifdef HAVE_SPEEXDSP_LIB
// Remove noise
if(_noiseActive)
speex_preprocess_run(_noiseState, _tmpMic);
#endif
// Processed echo cancellation
performEchoCancel(_tmpMic, _tmpSpkr, _tmpOut);
......
......@@ -324,10 +324,12 @@ class EchoCancel : public Algorithm {
ofstream *micLevelData;
ofstream *spkrLevelData;
#ifdef HAVE_SPEEXDSP_LIB
/**
* Noise reduction processing state
*/
SpeexPreprocessState *_noiseState;
#endif
/**
* true if noise suppressor is active, false elsewhere
......
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