From d9017530c638622964f183f681c9cc25e1a75e7b Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 3 Jan 2016 22:31:44 -0800 Subject: [PATCH] Moved baseband temporary buffers back into class member variables. Significant performance hit when declaring on stack. C++ wants to initialize std::array or even raw array with element constructors, was resulting in ~7% CPU utilization, for a buffer that was immediately written over anyway. --- firmware/baseband/proc_ais.cpp | 6 ------ firmware/baseband/proc_ais.hpp | 6 ++++++ firmware/baseband/proc_am_audio.cpp | 11 ----------- firmware/baseband/proc_am_audio.hpp | 10 ++++++++++ firmware/baseband/proc_nfm_audio.cpp | 11 ----------- firmware/baseband/proc_nfm_audio.hpp | 10 ++++++++++ firmware/baseband/proc_tpms.cpp | 6 ------ firmware/baseband/proc_tpms.hpp | 6 ++++++ firmware/baseband/proc_wfm_audio.cpp | 11 ----------- firmware/baseband/proc_wfm_audio.hpp | 10 ++++++++++ 10 files changed, 42 insertions(+), 45 deletions(-) diff --git a/firmware/baseband/proc_ais.cpp b/firmware/baseband/proc_ais.cpp index 41108ff7..b12e8ba8 100644 --- a/firmware/baseband/proc_ais.cpp +++ b/firmware/baseband/proc_ais.cpp @@ -36,12 +36,6 @@ AISProcessor::AISProcessor() { void AISProcessor::execute(const buffer_c8_t& buffer) { /* 2.4576MHz, 2048 samples */ - std::array dst; - const buffer_c16_t dst_buffer { - dst.data(), - dst.size() - }; - const auto decim_0_out = decim_0.execute(buffer, dst_buffer); const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); const auto decimator_out = decim_1_out; diff --git a/firmware/baseband/proc_ais.hpp b/firmware/baseband/proc_ais.hpp index 6f8be94d..966d739a 100644 --- a/firmware/baseband/proc_ais.hpp +++ b/firmware/baseband/proc_ais.hpp @@ -47,6 +47,12 @@ public: void execute(const buffer_c8_t& buffer) override; private: + std::array dst; + const buffer_c16_t dst_buffer { + dst.data(), + dst.size() + }; + dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0; dsp::decimate::FIRC16xR16x32Decim8 decim_1; dsp::matched_filter::MatchedFilter mf { baseband::ais::rrc_taps_38k4_4t_p, 2 }; diff --git a/firmware/baseband/proc_am_audio.cpp b/firmware/baseband/proc_am_audio.cpp index ce11aaf1..dd51c746 100644 --- a/firmware/baseband/proc_am_audio.cpp +++ b/firmware/baseband/proc_am_audio.cpp @@ -28,12 +28,6 @@ void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) { return; } - std::array dst; - const buffer_c16_t dst_buffer { - dst.data(), - dst.size() - }; - const auto decim_0_out = decim_0.execute(buffer, dst_buffer); const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer); @@ -42,11 +36,6 @@ void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) { feed_channel_stats(channel_out); channel_spectrum.feed(channel_out, channel_filter_pass_f, channel_filter_stop_f); - const buffer_s16_t work_audio_buffer { - (int16_t*)dst.data(), - sizeof(*dst.data()) * dst.size() - }; - auto audio = demod.execute(channel_out, work_audio_buffer); audio_hpf.execute_in_place(audio); diff --git a/firmware/baseband/proc_am_audio.hpp b/firmware/baseband/proc_am_audio.hpp index 172fab61..1ab7890f 100644 --- a/firmware/baseband/proc_am_audio.hpp +++ b/firmware/baseband/proc_am_audio.hpp @@ -40,6 +40,16 @@ public: void on_message(const Message* const message) override; private: + std::array dst; + const buffer_c16_t dst_buffer { + dst.data(), + dst.size() + }; + const buffer_s16_t work_audio_buffer { + (int16_t*)dst.data(), + sizeof(*dst.data()) * dst.size() + }; + dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0; dsp::decimate::FIRC16xR16x32Decim8 decim_1; dsp::decimate::FIRAndDecimateComplex channel_filter; diff --git a/firmware/baseband/proc_nfm_audio.cpp b/firmware/baseband/proc_nfm_audio.cpp index 4468af00..8424f0d8 100644 --- a/firmware/baseband/proc_nfm_audio.cpp +++ b/firmware/baseband/proc_nfm_audio.cpp @@ -29,12 +29,6 @@ void NarrowbandFMAudio::execute(const buffer_c8_t& buffer) { return; } - std::array dst; - const buffer_c16_t dst_buffer { - dst.data(), - dst.size() - }; - const auto decim_0_out = decim_0.execute(buffer, dst_buffer); const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer); @@ -42,11 +36,6 @@ void NarrowbandFMAudio::execute(const buffer_c8_t& buffer) { feed_channel_stats(channel_out); channel_spectrum.feed(channel_out, channel_filter_pass_f, channel_filter_stop_f); - const buffer_s16_t work_audio_buffer { - (int16_t*)dst.data(), - sizeof(*dst.data()) * dst.size() - }; - auto audio = demod.execute(channel_out, work_audio_buffer); static uint64_t audio_present_history = 0; diff --git a/firmware/baseband/proc_nfm_audio.hpp b/firmware/baseband/proc_nfm_audio.hpp index 87e05693..aa444c20 100644 --- a/firmware/baseband/proc_nfm_audio.hpp +++ b/firmware/baseband/proc_nfm_audio.hpp @@ -39,6 +39,16 @@ public: void on_message(const Message* const message) override; private: + std::array dst; + const buffer_c16_t dst_buffer { + dst.data(), + dst.size() + }; + const buffer_s16_t work_audio_buffer { + (int16_t*)dst.data(), + sizeof(*dst.data()) * dst.size() + }; + dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0; dsp::decimate::FIRC16xR16x32Decim8 decim_1; diff --git a/firmware/baseband/proc_tpms.cpp b/firmware/baseband/proc_tpms.cpp index 99b58b57..6ae7da99 100644 --- a/firmware/baseband/proc_tpms.cpp +++ b/firmware/baseband/proc_tpms.cpp @@ -57,12 +57,6 @@ TPMSProcessor::TPMSProcessor() { void TPMSProcessor::execute(const buffer_c8_t& buffer) { /* 2.4576MHz, 2048 samples */ - std::array dst; - const buffer_c16_t dst_buffer { - dst.data(), - dst.size() - }; - const auto decim_0_out = decim_0.execute(buffer, dst_buffer); const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); const auto decimator_out = decim_1_out; diff --git a/firmware/baseband/proc_tpms.hpp b/firmware/baseband/proc_tpms.hpp index 0164a28c..0c42beb7 100644 --- a/firmware/baseband/proc_tpms.hpp +++ b/firmware/baseband/proc_tpms.hpp @@ -59,6 +59,12 @@ public: void execute(const buffer_c8_t& buffer) override; private: + std::array dst; + const buffer_c16_t dst_buffer { + dst.data(), + dst.size() + }; + dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0; dsp::decimate::FIRC16xR16x16Decim2 decim_1; diff --git a/firmware/baseband/proc_wfm_audio.cpp b/firmware/baseband/proc_wfm_audio.cpp index 485fa620..61710299 100644 --- a/firmware/baseband/proc_wfm_audio.cpp +++ b/firmware/baseband/proc_wfm_audio.cpp @@ -28,21 +28,10 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) { return; } - std::array dst; - const buffer_c16_t dst_buffer { - dst.data(), - dst.size() - }; - const auto decim_0_out = decim_0.execute(buffer, dst_buffer); const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer); const auto decimator_out = decim_1_out; - const buffer_s16_t work_audio_buffer { - (int16_t*)decimator_out.p, - sizeof(*decimator_out.p) * decimator_out.count - }; - auto channel = decimator_out; // TODO: Feed channel_stats post-decimation data? diff --git a/firmware/baseband/proc_wfm_audio.hpp b/firmware/baseband/proc_wfm_audio.hpp index 9ef62fc8..6c149328 100644 --- a/firmware/baseband/proc_wfm_audio.hpp +++ b/firmware/baseband/proc_wfm_audio.hpp @@ -36,6 +36,16 @@ public: void on_message(const Message* const message) override; private: + std::array dst; + const buffer_c16_t dst_buffer { + dst.data(), + dst.size() + }; + const buffer_s16_t work_audio_buffer { + (int16_t*)dst.data(), + sizeof(dst) / sizeof(int16_t) + }; + dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0; dsp::decimate::FIRC16xR16x16Decim2 decim_1;