Skip to content
Snippets Groups Projects
Commit 158543bc authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#958] Tuning AGC and noise reduction engines

parent f99d9f30
Branches
Tags
No related merge requests found
......@@ -78,7 +78,7 @@ class Speex : public AudioCodec
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_frame_size);
/*
#ifdef HAVE_SPEEXDSP_LIB
int enable = 1;
......@@ -101,6 +101,7 @@ class Speex : public AudioCodec
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_VAD, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_AGC, &enable);
#endif
*/
}
......@@ -136,11 +137,12 @@ class Speex : public AudioCodec
virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) {
speex_bits_reset (&_speex_enc_bits);
/*
#ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_run (_preprocess_state, src);
#endif
*/
speex_encode_int (_speex_enc_state, src, &_speex_enc_bits);
int nbBytes = speex_bits_write (&_speex_enc_bits, (char*) dst, size);
......
......@@ -79,6 +79,7 @@ class Speex : public AudioCodec
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_frame_size);
/*
#ifdef HAVE_SPEEXDSP_LIB
int enable = 1;
......@@ -100,7 +101,7 @@ class Speex : public AudioCodec
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_VAD, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_AGC, &enable);
#endif
*/
}
~Speex() {
......@@ -135,11 +136,12 @@ class Speex : public AudioCodec
virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) {
speex_bits_reset (&_speex_enc_bits);
/*
#ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_run (_preprocess_state, src);
#endif
*/
speex_encode_int (_speex_enc_state, src, &_speex_enc_bits);
speex_bits_nbytes (&_speex_enc_bits);
......
......@@ -77,6 +77,7 @@ class Speex : public AudioCodec
speex_decoder_ctl (_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_frame_size);
/*
#ifdef HAVE_SPEEXDSP_LIB
int enable = 1;
......@@ -99,6 +100,7 @@ class Speex : public AudioCodec
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_VAD, &enable);
speex_preprocess_ctl (_preprocess_state, SPEEX_PREPROCESS_SET_AGC, &enable);
#endif
*/
}
......@@ -135,10 +137,12 @@ class Speex : public AudioCodec
virtual int codecEncode (unsigned char *dst, short *src, unsigned int size) {
speex_bits_reset (&_speex_enc_bits);
/*
#ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_run (_preprocess_state, src);
#endif
*/
//printf ("Codec::codecEncode() size %i\n", size);
speex_encode_int (_speex_enc_state, src, &_speex_enc_bits);
......
......@@ -223,7 +223,7 @@ void DelayDetection::process(SFLDataFormat *inputData, int nbBytes) {
_debug("MaxIndex: %d", maxIndex);
reset();
// reset();
}
int DelayDetection::process(SFLDataFormat *intputData, SFLDataFormat *outputData, int nbBytes) { return 0; }
......
......@@ -90,15 +90,17 @@ EchoCancel::EchoCancel(int smplRate, int frameLength) : _samplingRate(smplRate),
_spkrHistoryLength = SPKR_LENGTH / SEGMENT_LENGTH;
_nbSegmentPerFrame = _frameLength / SEGMENT_LENGTH;
#ifdef HAVE_SPEEXDSP_LIB
// #ifdef HAVE_SPEEXDSP_LIB
_noiseState = speex_preprocess_state_init(_smplPerFrame, _samplingRate);
int i=1;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DENOISE, &i);
i=-30;
i=-10;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &i);
i=0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC, &i);
i=8000;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC_TARGET, &i);
i=16000;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC_LEVEL, &i);
i=0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB, &i);
......@@ -106,7 +108,9 @@ 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
i = 0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_VAD, &i);
// #endif
memset(_avgSpkrLevelHist, 0, BUFF_SIZE*sizeof(int));
memset(_avgMicLevelHist, 0, BUFF_SIZE*sizeof(int));
......@@ -131,9 +135,9 @@ EchoCancel::~EchoCancel()
delete _spkrData;
_spkrData = NULL;
#ifdef HAVE_SPEEXDSP_LIB
// #ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_state_destroy(_noiseState);
#endif
// #endif
// micFile->close();
// spkrFile->close();
......@@ -185,17 +189,19 @@ void EchoCancel::reset()
_spkrData->flushAll();
_spkrDataOut->flushAll();
#ifdef HAVE_SPEEXDSP_LIB
// #ifdef HAVE_SPEEXDSP_LIB
speex_preprocess_state_destroy(_noiseState);
_noiseState = speex_preprocess_state_init(_smplPerFrame, _samplingRate);
int i=1;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DENOISE, &i);
i=-30;
i=-10;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS, &i);
i=0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC, &i);
i=8000;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC_TARGET, &i);
i=16000;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_AGC_LEVEL, &i);
i=0;
speex_preprocess_ctl(_noiseState, SPEEX_PREPROCESS_SET_DEREVERB, &i);
......@@ -203,7 +209,8 @@ 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
// #endif
_spkrStoped = true;
......@@ -283,11 +290,12 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
// micFile->write((const char *)_tmpMic, byteSize);
// spkrFile->write((const char *)_tmpSpkr, byteSize);
#ifdef HAVE_SPEEXDSP_LIB
// #ifdef HAVE_SPEEXDSP_LIB
// Remove noise
if(_noiseActive)
speex_preprocess_run(_noiseState, _tmpMic);
#endif
// #endif
// Processed echo cancellation
performEchoCancel(_tmpMic, _tmpSpkr, _tmpOut);
......@@ -320,7 +328,6 @@ int EchoCancel::process(SFLDataFormat *inputData, SFLDataFormat *outputData, int
// if spkrAvail is twice the size of a frame discard it, this data is late and won't be used
if(spkrAvail > (2*byteSize)) {
_debug("EchoCancel: Discard echo cancel");
_spkrData->Discard(spkrAvail-(2*byteSize));
}
......
......@@ -364,12 +364,12 @@ class EchoCancel : public Algorithm {
ofstream *micLevelData;
ofstream *spkrLevelData;
#ifdef HAVE_SPEEXDSP_LIB
// #ifdef HAVE_SPEEXDSP_LIB
/**
* Noise reduction processing state
*/
SpeexPreprocessState *_noiseState;
#endif
// #endif
/**
* true if noise suppressor is active, false elsewhere
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment