diff --git a/firmware/baseband/dsp_decimate.cpp b/firmware/baseband/dsp_decimate.cpp index 165fbcfb..930a2fb3 100644 --- a/firmware/baseband/dsp_decimate.cpp +++ b/firmware/baseband/dsp_decimate.cpp @@ -197,32 +197,27 @@ buffer_s16_t FIR64AndDecimateBy2Real::execute( return { dst.p, src.count / 2, src.sampling_rate / 2 }; } -size_t fir_and_decimate_by_2_complex_fast( - const complex16_t* const src_start, - const size_t src_count, - complex16_t* const dst_start, - complex16_t* const z, - const complex16_t* const taps, - const size_t taps_count, - const size_t decimation_factor +buffer_c16_t FIRAndDecimateComplex::execute( + buffer_c16_t src, + buffer_c16_t dst ) { /* int16_t input (sample count "n" must be multiple of decimation_factor) * -> int16_t output, decimated by decimation_factor. * taps are normalized to 1 << 16 == 1.0. */ - const auto src_p = src_start; - auto dst_p = dst_start; + const sample_t* src_p = src.p; + sample_t* dst_p = dst.p; - while(src_p < &src_start[src_count]) { + while(src_p < &src.p[src.count]) { /* Put two new samples into delay buffer */ - auto z_new_p = &z[taps_count - decimation_factor]; - for(size_t i=0; i 0) { *__SIMD32(t)++ = *__SIMD32(s)++; @@ -295,14 +290,14 @@ size_t fir_and_decimate_by_2_complex_fast( shift_count--; } - shift_count = (taps_count - 1) % unroll_factor; + shift_count = (taps_count_ - decimation_factor_) % unroll_factor; while(shift_count > 0) { *(t++) = *(s++); shift_count--; } } - return src_count / decimation_factor; + return { dst.p, src.count / decimation_factor_, src.sampling_rate / decimation_factor_ }; } buffer_s16_t DecimateBy2CIC4Real::execute( diff --git a/firmware/baseband/dsp_decimate.hpp b/firmware/baseband/dsp_decimate.hpp index e24207c6..cbb6204b 100644 --- a/firmware/baseband/dsp_decimate.hpp +++ b/firmware/baseband/dsp_decimate.hpp @@ -78,17 +78,7 @@ private: const std::array& taps; }; -size_t fir_and_decimate_by_2_complex_fast( - const complex16_t* const src_start, - const size_t src_count, - complex16_t* const dst_start, - complex16_t* const z, - const complex16_t* const taps, - const size_t taps_count, - const size_t decimation_factor -); - -class FIRAndDecimateBy2Complex { +class FIRAndDecimateComplex { public: using sample_t = complex16_t; using tap_t = complex16_t; @@ -98,18 +88,21 @@ public: /* NOTE! Current code makes an assumption that block of samples to be * processed will be a multiple of the taps_count. */ - FIRAndDecimateBy2Complex( - const size_t taps_count + FIRAndDecimateComplex( + const size_t taps_count, + const size_t decimation_factor ) : samples_ { std::make_unique(taps_count) }, taps_reversed_ { std::make_unique(taps_count) }, - taps_count_ { taps_count } + taps_count_ { taps_count }, + decimation_factor_ { decimation_factor } { } template - FIRAndDecimateBy2Complex( - const T& taps - ) : FIRAndDecimateBy2Complex(taps.size()) + FIRAndDecimateComplex( + const T& taps, + const size_t decimation_factor + ) : FIRAndDecimateComplex(taps.size(), decimation_factor) { std::reverse_copy(taps.cbegin(), taps.cend(), &taps_reversed_[0]); } @@ -117,18 +110,15 @@ public: buffer_c16_t execute( buffer_c16_t src, buffer_c16_t dst - ) { - const auto dst_count = fir_and_decimate_by_2_complex_fast(src.p, src.count, dst.p, &samples_[0], &taps_reversed_[0], taps_count_, decimation_factor); - return { dst.p, dst_count, src.sampling_rate / decimation_factor }; - } - + ); + private: using samples_t = sample_t[]; const std::unique_ptr samples_; const std::unique_ptr taps_reversed_; const size_t taps_count_; - const size_t decimation_factor { 2 }; + const size_t decimation_factor_; }; class DecimateBy2CIC4Real { diff --git a/firmware/baseband/proc_am_audio.hpp b/firmware/baseband/proc_am_audio.hpp index 1302a2ea..994ff74d 100644 --- a/firmware/baseband/proc_am_audio.hpp +++ b/firmware/baseband/proc_am_audio.hpp @@ -38,7 +38,7 @@ public: private: ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By32 }; const fir_taps_real<64>& channel_filter_taps = taps_64_lp_031_070_tfilter; - dsp::decimate::FIRAndDecimateBy2Complex channel_filter { channel_filter_taps.taps }; + dsp::decimate::FIRAndDecimateComplex channel_filter { channel_filter_taps.taps, 2 }; dsp::demodulate::AM demod; IIRBiquadFilter audio_hpf { audio_hpf_config }; }; diff --git a/firmware/baseband/proc_fsk.hpp b/firmware/baseband/proc_fsk.hpp index 4af86592..d2324dc9 100644 --- a/firmware/baseband/proc_fsk.hpp +++ b/firmware/baseband/proc_fsk.hpp @@ -55,7 +55,7 @@ private: ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By16 }; const fir_taps_real<64>& channel_filter_taps = taps_64_lp_031_070_tfilter; - dsp::decimate::FIRAndDecimateBy2Complex channel_filter { channel_filter_taps.taps }; + dsp::decimate::FIRAndDecimateComplex channel_filter { channel_filter_taps.taps, 2 }; dsp::matched_filter::MatchedFilter mf { baseband::ais::rrc_taps_128_decim_4_p, 1 }; diff --git a/firmware/baseband/proc_nfm_audio.hpp b/firmware/baseband/proc_nfm_audio.hpp index 72437adc..42922ede 100644 --- a/firmware/baseband/proc_nfm_audio.hpp +++ b/firmware/baseband/proc_nfm_audio.hpp @@ -39,7 +39,7 @@ public: private: ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By32 }; const fir_taps_real<64>& channel_filter_taps = taps_64_lp_042_078_tfilter; - dsp::decimate::FIRAndDecimateBy2Complex channel_filter { channel_filter_taps.taps }; + dsp::decimate::FIRAndDecimateComplex channel_filter { channel_filter_taps.taps, 2 }; dsp::demodulate::FM demod { 48000, 7500 }; IIRBiquadFilter audio_hpf { audio_hpf_config };