bugfix + improved NFM IF noise reduction (less distortion)

This commit is contained in:
AlexandreRouma 2021-12-12 20:06:21 +01:00
parent 15010cff01
commit cee0f75870
2 changed files with 48 additions and 0 deletions

View File

@ -65,6 +65,50 @@ namespace dsp {
generic_block<FMIFNoiseReduction>::tempStart(); generic_block<FMIFNoiseReduction>::tempStart();
} }
void setTapCount(int tapCount) {
assert(generic_block<FMIFNoiseReduction>::_block_init);
std::lock_guard<std::mutex> lck(generic_block<FMIFNoiseReduction>::ctrlMtx);
generic_block<FMIFNoiseReduction>::tempStop();
generic_block<FMIFNoiseReduction>::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<FMIFNoiseReduction>::registerInput(_in);
generic_block<FMIFNoiseReduction>::tempStart();
}
void setLevel(float level) { void setLevel(float level) {
_level = powf(10.0f, level / 10.0f); _level = powf(10.0f, level / 10.0f);
} }

View File

@ -384,6 +384,9 @@ private:
vfo->setSampleRate(selectedDemod->getIFSampleRate(), bandwidth); vfo->setSampleRate(selectedDemod->getIFSampleRate(), bandwidth);
} }
// Configure bandwidth
setBandwidth(bandwidth);
// Configure FM IF Noise Reduction // Configure FM IF Noise Reduction
setFMIFNREnabled(FMIFNRAllowed ? FMIFNREnabled : false); setFMIFNREnabled(FMIFNRAllowed ? FMIFNREnabled : false);
@ -395,6 +398,7 @@ private:
setSquelchEnabled(squelchEnabled); setSquelchEnabled(squelchEnabled);
// Configure noise blanker // Configure noise blanker
fmnr.block.setTapCount((selectedDemod->getIFSampleRate() < 100000.0f) ? 8 : 32);
nb.block.setLevel(nbLevel); nb.block.setLevel(nbLevel);
setNoiseBlankerEnabled(nbEnabled); setNoiseBlankerEnabled(nbEnabled);