From a55856588619d71626fc65df1301387b45547448 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Fri, 29 Jan 2016 19:25:08 -0800 Subject: [PATCH] Further template BlockDecimator by element type, use for audio buffer. Appropriating for use as a buffer accumulator that will save up enough audio samples to put into an audio DMA buffer. --- firmware/baseband/audio_output.cpp | 11 +++++++++++ firmware/baseband/audio_output.hpp | 4 ++++ firmware/baseband/block_decimator.hpp | 6 +++--- firmware/baseband/proc_am_audio.cpp | 8 ++------ firmware/baseband/proc_am_audio.hpp | 2 -- firmware/baseband/proc_nfm_audio.cpp | 8 ++------ firmware/baseband/proc_nfm_audio.hpp | 2 -- firmware/baseband/spectrum_collector.hpp | 2 +- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/firmware/baseband/audio_output.cpp b/firmware/baseband/audio_output.cpp index 6e29fa161..fa67eab26 100644 --- a/firmware/baseband/audio_output.cpp +++ b/firmware/baseband/audio_output.cpp @@ -57,6 +57,17 @@ void AudioOutput::write( void AudioOutput::write( const buffer_f32_t& audio +) { + block_buffer.feed( + audio, + [this](const buffer_f32_t& buffer) { + this->on_block(buffer); + } + ); +} + +void AudioOutput::on_block( + const buffer_f32_t& audio ) { const auto audio_present_now = squelch.execute(audio); diff --git a/firmware/baseband/audio_output.hpp b/firmware/baseband/audio_output.hpp index df490d3c8..0ebaa8cdd 100644 --- a/firmware/baseband/audio_output.hpp +++ b/firmware/baseband/audio_output.hpp @@ -27,6 +27,7 @@ #include "dsp_iir.hpp" #include "dsp_squelch.hpp" +#include "block_decimator.hpp" #include "audio_stats_collector.hpp" #include @@ -43,6 +44,8 @@ public: void write(const buffer_f32_t& audio); private: + BlockDecimator block_buffer { 1 }; + IIRBiquadFilter hpf; IIRBiquadFilter deemph; FMSquelch squelch; @@ -51,6 +54,7 @@ private: uint64_t audio_present_history = 0; + void on_block(const buffer_f32_t& audio); void fill_audio_buffer(const buffer_f32_t& audio); void feed_audio_stats(const buffer_f32_t& audio); }; diff --git a/firmware/baseband/block_decimator.hpp b/firmware/baseband/block_decimator.hpp index 1f7710efc..7782dc371 100644 --- a/firmware/baseband/block_decimator.hpp +++ b/firmware/baseband/block_decimator.hpp @@ -29,7 +29,7 @@ #include "dsp_types.hpp" #include "complex.hpp" -template +template class BlockDecimator { public: constexpr BlockDecimator( @@ -65,7 +65,7 @@ public: } template - void feed(const buffer_c16_t& src, BlockCallback callback) { + void feed(const buffer_t& src, BlockCallback callback) { /* NOTE: Input block size must be >= factor */ set_input_sampling_rate(src.sampling_rate); @@ -85,7 +85,7 @@ public: } private: - std::array buffer; + std::array buffer; uint32_t input_sampling_rate_ { 0 }; size_t factor_ { 1 }; size_t src_i { 0 }; diff --git a/firmware/baseband/proc_am_audio.cpp b/firmware/baseband/proc_am_audio.cpp index 65ad8e9e0..c522eb6df 100644 --- a/firmware/baseband/proc_am_audio.cpp +++ b/firmware/baseband/proc_am_audio.cpp @@ -38,12 +38,8 @@ 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); - channel_block_buffer.feed( - channel_out, [this](const buffer_c16_t buffer) { - auto audio = this->demod.execute(buffer, this->audio_buffer); - this->audio_output.write(audio); - } - ); + auto audio = demod.execute(channel_out, audio_buffer); + audio_output.write(audio); } void NarrowbandAMAudio::on_message(const Message* const message) { diff --git a/firmware/baseband/proc_am_audio.hpp b/firmware/baseband/proc_am_audio.hpp index e2e76e95d..43ec8c971 100644 --- a/firmware/baseband/proc_am_audio.hpp +++ b/firmware/baseband/proc_am_audio.hpp @@ -58,8 +58,6 @@ private: uint32_t channel_filter_pass_f = 0; uint32_t channel_filter_stop_f = 0; - BlockDecimator<32> channel_block_buffer { post_channel_decimation_factor }; - dsp::demodulate::AM demod; AudioOutput audio_output; diff --git a/firmware/baseband/proc_nfm_audio.cpp b/firmware/baseband/proc_nfm_audio.cpp index 3fd9f5e38..3bc880434 100644 --- a/firmware/baseband/proc_nfm_audio.cpp +++ b/firmware/baseband/proc_nfm_audio.cpp @@ -38,12 +38,8 @@ 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); - channel_block_buffer.feed( - channel_out, [this](const buffer_c16_t buffer) { - auto audio = this->demod.execute(buffer, this->audio_buffer); - this->audio_output.write(audio); - } - ); + auto audio = demod.execute(channel_out, audio_buffer); + audio_output.write(audio); } void NarrowbandFMAudio::on_message(const Message* const message) { diff --git a/firmware/baseband/proc_nfm_audio.hpp b/firmware/baseband/proc_nfm_audio.hpp index 6f0866946..dbae4f5fd 100644 --- a/firmware/baseband/proc_nfm_audio.hpp +++ b/firmware/baseband/proc_nfm_audio.hpp @@ -58,8 +58,6 @@ private: uint32_t channel_filter_pass_f = 0; uint32_t channel_filter_stop_f = 0; - BlockDecimator<32> channel_block_buffer { post_channel_decimation_factor }; - dsp::demodulate::FM demod; AudioOutput audio_output; diff --git a/firmware/baseband/spectrum_collector.hpp b/firmware/baseband/spectrum_collector.hpp index 4c2cd5420..6c50120be 100644 --- a/firmware/baseband/spectrum_collector.hpp +++ b/firmware/baseband/spectrum_collector.hpp @@ -50,7 +50,7 @@ public: ); private: - BlockDecimator<256> channel_spectrum_decimator; + BlockDecimator channel_spectrum_decimator; ChannelSpectrumFIFO fifo; volatile bool channel_spectrum_request_update { false };