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