From b5aa2b205fa71a6e8b25ea95b00260e14525b8be Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 3 Jan 2016 14:31:39 -0800 Subject: [PATCH] Implement AMConfigureMessage from M0 to M4. --- firmware/application/analog_audio_app.cpp | 13 +++++ firmware/application/analog_audio_app.hpp | 1 + firmware/baseband/proc_am_audio.cpp | 64 ++++++++++++++--------- firmware/baseband/proc_am_audio.hpp | 5 +- firmware/common/message.hpp | 19 +++++++ 5 files changed, 75 insertions(+), 27 deletions(-) diff --git a/firmware/application/analog_audio_app.cpp b/firmware/application/analog_audio_app.cpp index 0b048acf..ec50f4d5 100644 --- a/firmware/application/analog_audio_app.cpp +++ b/firmware/application/analog_audio_app.cpp @@ -44,6 +44,10 @@ AnalogAudioModel::AnalogAudioModel(ReceiverModel::Mode mode) { configure_wfm(); break; + case ReceiverModel::Mode::AMAudio: + configure_am(); + break; + default: break; } @@ -69,3 +73,12 @@ void AnalogAudioModel::configure_wfm() { }; shared_memory.baseband_queue.push(message); } + +void AnalogAudioModel::configure_am() { + const AMConfigureMessage message { + taps_6k0_decim_0, + taps_6k0_decim_1, + taps_6k0_channel, + }; + shared_memory.baseband_queue.push(message); +} diff --git a/firmware/application/analog_audio_app.hpp b/firmware/application/analog_audio_app.hpp index 80047fa2..7c840ced 100644 --- a/firmware/application/analog_audio_app.hpp +++ b/firmware/application/analog_audio_app.hpp @@ -32,6 +32,7 @@ public: private: void configure_nbfm(); void configure_wfm(); + void configure_am(); }; namespace ui { diff --git a/firmware/baseband/proc_am_audio.cpp b/firmware/baseband/proc_am_audio.cpp index c2da853b..c6fc3212 100644 --- a/firmware/baseband/proc_am_audio.cpp +++ b/firmware/baseband/proc_am_audio.cpp @@ -21,31 +21,11 @@ #include "proc_am_audio.hpp" -NarrowbandAMAudio::NarrowbandAMAudio() { - constexpr size_t baseband_fs = 3072000; - - constexpr size_t decim_0_input_fs = baseband_fs; - constexpr size_t decim_0_decimation_factor = 8; - constexpr size_t decim_0_output_fs = decim_0_input_fs / decim_0_decimation_factor; - - constexpr size_t decim_1_input_fs = decim_0_output_fs; - constexpr size_t decim_1_decimation_factor = 8; - constexpr size_t decim_1_output_fs = decim_1_input_fs / decim_1_decimation_factor; - - constexpr size_t channel_filter_input_fs = decim_1_output_fs; - constexpr size_t channel_filter_decimation_factor = 1; - constexpr size_t channel_filter_output_fs = channel_filter_input_fs / channel_filter_decimation_factor; - - decim_0.configure(taps_6k0_decim_0.taps, 33554432); - decim_1.configure(taps_6k0_decim_1.taps, 131072); - channel_filter.configure(taps_6k0_channel.taps, channel_filter_decimation_factor); - channel_filter_pass_f = taps_6k0_channel.pass_frequency_normalized * channel_filter_input_fs; - channel_filter_stop_f = taps_6k0_channel.stop_frequency_normalized * channel_filter_input_fs; - - channel_spectrum.set_decimation_factor(std::floor((channel_filter_output_fs / 2) / ((channel_filter_pass_f + channel_filter_stop_f) / 2))); -} - void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) { + if( !configured ) { + return; + } + std::array dst; const buffer_c16_t dst_buffer { dst.data(), @@ -73,7 +53,41 @@ void NarrowbandAMAudio::execute(const buffer_c8_t& buffer) { } void NarrowbandAMAudio::on_message(const Message* const message) { - if( message->id == Message::ID::UpdateSpectrum ) { + switch(message->id) { + case Message::ID::UpdateSpectrum: channel_spectrum.update(); + break; + + case Message::ID::AMConfigure: + configure(*reinterpret_cast(message)); + break; + + default: + break; } } + +void NarrowbandAMAudio::configure(const AMConfigureMessage& message) { + constexpr size_t baseband_fs = 3072000; + + constexpr size_t decim_0_input_fs = baseband_fs; + constexpr size_t decim_0_decimation_factor = 8; + constexpr size_t decim_0_output_fs = decim_0_input_fs / decim_0_decimation_factor; + + constexpr size_t decim_1_input_fs = decim_0_output_fs; + constexpr size_t decim_1_decimation_factor = 8; + constexpr size_t decim_1_output_fs = decim_1_input_fs / decim_1_decimation_factor; + + constexpr size_t channel_filter_input_fs = decim_1_output_fs; + constexpr size_t channel_filter_decimation_factor = 1; + constexpr size_t channel_filter_output_fs = channel_filter_input_fs / channel_filter_decimation_factor; + + decim_0.configure(message.decim_0_filter.taps, 33554432); + decim_1.configure(message.decim_1_filter.taps, 131072); + channel_filter.configure(message.channel_filter.taps, channel_filter_decimation_factor); + channel_filter_pass_f = message.channel_filter.pass_frequency_normalized * channel_filter_input_fs; + channel_filter_stop_f = message.channel_filter.stop_frequency_normalized * channel_filter_input_fs; + channel_spectrum.set_decimation_factor(std::floor((channel_filter_output_fs / 2) / ((channel_filter_pass_f + channel_filter_stop_f) / 2))); + + configured = true; +} diff --git a/firmware/baseband/proc_am_audio.hpp b/firmware/baseband/proc_am_audio.hpp index e664b0af..f7088513 100644 --- a/firmware/baseband/proc_am_audio.hpp +++ b/firmware/baseband/proc_am_audio.hpp @@ -38,8 +38,6 @@ class NarrowbandAMAudio : public BasebandProcessor { public: - NarrowbandAMAudio(); - void execute(const buffer_c8_t& buffer) override; void on_message(const Message* const message) override; @@ -56,6 +54,9 @@ private: IIRBiquadFilter audio_hpf { audio_hpf_300hz_config }; SpectrumCollector channel_spectrum; + + bool configured { false }; + void configure(const AMConfigureMessage& message); }; #endif/*__PROC_AM_AUDIO_H__*/ diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index fdb67bbd..6e0e8fee 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -54,6 +54,7 @@ public: UpdateSpectrum = 10, NBFMConfigure = 11, WFMConfigure = 12, + AMConfigure = 13, MAX }; @@ -314,6 +315,24 @@ public: const size_t deviation; }; +class AMConfigureMessage : public Message { +public: + constexpr AMConfigureMessage( + const fir_taps_real<24>& decim_0_filter, + const fir_taps_real<32>& decim_1_filter, + const fir_taps_real<32>& channel_filter + ) : Message { ID::AMConfigure }, + decim_0_filter { decim_0_filter }, + decim_1_filter { decim_1_filter }, + channel_filter { channel_filter } + { + } + + const fir_taps_real<24> decim_0_filter; + const fir_taps_real<32> decim_1_filter; + const fir_taps_real<32> channel_filter; +}; + class MessageHandlerMap { public: using MessageHandler = std::function;