diff --git a/core/src/dsp/noise_reduction.h b/core/src/dsp/noise_reduction.h index 79ea4c41..a6f1905b 100644 --- a/core/src/dsp/noise_reduction.h +++ b/core/src/dsp/noise_reduction.h @@ -65,6 +65,50 @@ namespace dsp { generic_block::tempStart(); } + void setTapCount(int tapCount) { + assert(generic_block::_block_init); + std::lock_guard lck(generic_block::ctrlMtx); + generic_block::tempStop(); + generic_block::unregisterInput(_in); + + _tapCount = tapCount; + + fftwf_destroy_plan(forwardPlan); + fftwf_destroy_plan(backwardPlan); + fftwf_free(delay); + fftwf_free(fft_in); + fftwf_free(fft_window); + fftwf_free(amp_buf); + fftwf_free(fft_cout); + fftwf_free(fft_fcout); + + delay = (complex_t*)fftwf_malloc(sizeof(complex_t)*STREAM_BUFFER_SIZE); + fft_in = (complex_t*)fftwf_malloc(sizeof(complex_t)*_tapCount); + fft_window = (float*)fftwf_malloc(sizeof(float)*_tapCount); + amp_buf = (float*)fftwf_malloc(sizeof(float)*_tapCount); + fft_cout = (complex_t*)fftwf_malloc(sizeof(complex_t)*_tapCount); + fft_fcout = (complex_t*)fftwf_malloc(sizeof(complex_t)*_tapCount); + delay_start = &delay[_tapCount]; + + memset(delay, 0, sizeof(complex_t)*STREAM_BUFFER_SIZE); + memset(fft_in, 0, sizeof(complex_t)*_tapCount); + memset(amp_buf, 0, sizeof(float)*_tapCount); + memset(fft_cout, 0, sizeof(complex_t)*_tapCount); + memset(fft_fcout, 0, sizeof(complex_t)*_tapCount); + + for (int i = 0; i < _tapCount; i++) { + fft_window[i] = window_function::blackman(i, _tapCount - 1); + } + + forwardPlan = fftwf_plan_dft_1d(_tapCount, (fftwf_complex*)fft_in, (fftwf_complex*)fft_cout, FFTW_FORWARD, FFTW_ESTIMATE); + backwardPlan = fftwf_plan_dft_1d(_tapCount, (fftwf_complex*)fft_cout, (fftwf_complex*)fft_fcout, FFTW_BACKWARD, FFTW_ESTIMATE); + + spdlog::info("FM IF Noise reduction set to {0} taps", _tapCount); + + generic_block::registerInput(_in); + generic_block::tempStart(); + } + void setLevel(float level) { _level = powf(10.0f, level / 10.0f); } diff --git a/decoder_modules/radio/src/radio_module.h b/decoder_modules/radio/src/radio_module.h index c63694b2..19f6302a 100644 --- a/decoder_modules/radio/src/radio_module.h +++ b/decoder_modules/radio/src/radio_module.h @@ -384,6 +384,9 @@ private: vfo->setSampleRate(selectedDemod->getIFSampleRate(), bandwidth); } + // Configure bandwidth + setBandwidth(bandwidth); + // Configure FM IF Noise Reduction setFMIFNREnabled(FMIFNRAllowed ? FMIFNREnabled : false); @@ -395,6 +398,7 @@ private: setSquelchEnabled(squelchEnabled); // Configure noise blanker + fmnr.block.setTapCount((selectedDemod->getIFSampleRate() < 100000.0f) ? 8 : 32); nb.block.setLevel(nbLevel); setNoiseBlankerEnabled(nbEnabled);