Remove taps_count template arg for FIRAndDecimateBy2Complex.

Use heap to allocate samples and taps buffers, so filters of different lengths can be supported.
This commit is contained in:
Jared Boone 2015-11-03 12:11:32 -08:00
parent 0f73d6061a
commit be78ed657f
4 changed files with 34 additions and 14 deletions

View File

@ -24,6 +24,10 @@
#include <cstdint> #include <cstdint>
#include <array> #include <array>
#include <memory>
#include <algorithm>
#include "utility.hpp"
#include "dsp_types.hpp" #include "dsp_types.hpp"
@ -83,32 +87,48 @@ size_t fir_and_decimate_by_2_complex_fast(
const size_t taps_count const size_t taps_count
); );
template<size_t taps_count>
class FIRAndDecimateBy2Complex { class FIRAndDecimateBy2Complex {
public: 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 /* NOTE! Current code makes an assumption that block of samples to be
* processed will be a multiple of the taps_count. * processed will be a multiple of the taps_count.
*/ */
FIRAndDecimateBy2Complex( FIRAndDecimateBy2Complex(
const std::array<int16_t, taps_count>& real_taps const size_t taps_count
) { ) : samples_ { std::make_unique<samples_t>(taps_count) },
for(size_t i=0; i<taps_count; i++) { taps_reversed_ { std::make_unique<taps_t>(taps_count * 2) },
taps[ i] = real_taps[i]; taps_count_ { taps_count }
taps[taps_count + i] = real_taps[i]; {
} }
template<typename T>
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 execute(
buffer_c16_t src, buffer_c16_t src,
buffer_c16_t dst 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); 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 / 2 }; return { dst.p, dst_count, src.sampling_rate / decimation_factor };
} }
private: private:
std::array<complex16_t, taps_count * 2> taps; using samples_t = sample_t[];
std::array<complex16_t, taps_count> z;
const std::unique_ptr<samples_t> samples_;
const std::unique_ptr<taps_t> taps_reversed_;
const size_t taps_count_;
const size_t decimation_factor { 2 };
}; };
class DecimateBy2CIC4Real { class DecimateBy2CIC4Real {

View File

@ -38,7 +38,7 @@ public:
private: private:
ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By32 }; ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By32 };
const fir_taps_real<64>& channel_filter_taps = taps_64_lp_031_070_tfilter; 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; dsp::demodulate::AM demod;
IIRBiquadFilter audio_hpf { audio_hpf_config }; IIRBiquadFilter audio_hpf { audio_hpf_config };
}; };

View File

@ -55,7 +55,7 @@ private:
ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By16 }; ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By16 };
const fir_taps_real<64>& channel_filter_taps = taps_64_lp_031_070_tfilter; 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 }; dsp::matched_filter::MatchedFilter mf { baseband::ais::rrc_taps_128_decim_4_p, 1 };

View File

@ -39,7 +39,7 @@ public:
private: private:
ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By32 }; ChannelDecimator decimator { ChannelDecimator::DecimationFactor::By32 };
const fir_taps_real<64>& channel_filter_taps = taps_64_lp_042_078_tfilter; 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 }; dsp::demodulate::FM demod { 48000, 7500 };
IIRBiquadFilter audio_hpf { audio_hpf_config }; IIRBiquadFilter audio_hpf { audio_hpf_config };