From be78ed657fc23dfdbb41c2a595af4945db0219e7 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 3 Nov 2015 12:11:32 -0800 Subject: [PATCH] Remove taps_count template arg for FIRAndDecimateBy2Complex. Use heap to allocate samples and taps buffers, so filters of different lengths can be supported. --- firmware/baseband/dsp_decimate.hpp | 42 ++++++++++++++++++++-------- firmware/baseband/proc_am_audio.hpp | 2 +- firmware/baseband/proc_fsk.hpp | 2 +- firmware/baseband/proc_nfm_audio.hpp | 2 +- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/firmware/baseband/dsp_decimate.hpp b/firmware/baseband/dsp_decimate.hpp index d34034e19..aed3dcc61 100644 --- a/firmware/baseband/dsp_decimate.hpp +++ b/firmware/baseband/dsp_decimate.hpp @@ -24,6 +24,10 @@ #include #include +#include +#include + +#include "utility.hpp" #include "dsp_types.hpp" @@ -83,32 +87,48 @@ size_t fir_and_decimate_by_2_complex_fast( const size_t taps_count ); -template class FIRAndDecimateBy2Complex { public: + using sample_t = complex16_t; + using tap_t = complex16_t; + + using taps_t = tap_t[]; + /* NOTE! Current code makes an assumption that block of samples to be * processed will be a multiple of the taps_count. */ FIRAndDecimateBy2Complex( - const std::array& real_taps - ) { - for(size_t i=0; i(taps_count) }, + taps_reversed_ { std::make_unique(taps_count * 2) }, + taps_count_ { taps_count } + { + } + + template + FIRAndDecimateBy2Complex( + const T& taps + ) : FIRAndDecimateBy2Complex(taps.size()) + { + std::reverse_copy(taps.cbegin(), taps.cend(), &taps_reversed_[0]); + std::reverse_copy(taps.cbegin(), taps.cend(), &taps_reversed_[taps.size()]); } 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, z.data(), taps.data(), taps_count); - return { dst.p, dst_count, src.sampling_rate / 2 }; + const auto dst_count = fir_and_decimate_by_2_complex_fast(src.p, src.count, dst.p, &samples_[0], &taps_reversed_[0], taps_count_); + return { dst.p, dst_count, src.sampling_rate / decimation_factor }; } private: - std::array taps; - std::array z; + 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 }; }; class DecimateBy2CIC4Real { diff --git a/firmware/baseband/proc_am_audio.hpp b/firmware/baseband/proc_am_audio.hpp index 5ba413026..1302a2eab 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<64> channel_filter { channel_filter_taps.taps }; + dsp::decimate::FIRAndDecimateBy2Complex channel_filter { channel_filter_taps.taps }; 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 c8515fac4..4af865924 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<64> channel_filter { channel_filter_taps.taps }; + dsp::decimate::FIRAndDecimateBy2Complex channel_filter { channel_filter_taps.taps }; 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 9ecd0fa70..72437adce 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<64> channel_filter { channel_filter_taps.taps }; + dsp::decimate::FIRAndDecimateBy2Complex channel_filter { channel_filter_taps.taps }; dsp::demodulate::FM demod { 48000, 7500 }; IIRBiquadFilter audio_hpf { audio_hpf_config };