From f2f7032615b497d10ca2c7e810fdd05d1b9af839 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 3 Jan 2016 13:38:55 -0800 Subject: [PATCH] Wideband FM configuration messages from M0. --- firmware/application/analog_audio_app.cpp | 40 +++++++++++++---- firmware/application/analog_audio_app.hpp | 4 ++ firmware/baseband/proc_wfm_audio.cpp | 55 +++++++++++++++-------- firmware/baseband/proc_wfm_audio.hpp | 7 ++- firmware/common/message.hpp | 22 +++++++++ 5 files changed, 99 insertions(+), 29 deletions(-) diff --git a/firmware/application/analog_audio_app.cpp b/firmware/application/analog_audio_app.cpp index 7ef3102a..0b048acf 100644 --- a/firmware/application/analog_audio_app.cpp +++ b/firmware/application/analog_audio_app.cpp @@ -35,13 +35,37 @@ AnalogAudioModel::AnalogAudioModel(ReceiverModel::Mode mode) { }); receiver_model.set_baseband_bandwidth(1750000); - if( mode == ReceiverModel::Mode::NarrowbandFMAudio ) { - const NBFMConfigureMessage message { - taps_4k25_decim_0, - taps_4k25_decim_1, - taps_4k25_channel, - 2500, - }; - shared_memory.baseband_queue.push(message); + switch(mode) { + case ReceiverModel::Mode::NarrowbandFMAudio: + configure_nbfm(); + break; + + case ReceiverModel::Mode::WidebandFMAudio: + configure_wfm(); + break; + + default: + break; } + +} + +void AnalogAudioModel::configure_nbfm() { + const NBFMConfigureMessage message { + taps_4k25_decim_0, + taps_4k25_decim_1, + taps_4k25_channel, + 2500, + }; + shared_memory.baseband_queue.push(message); +} + +void AnalogAudioModel::configure_wfm() { + const WFMConfigureMessage message { + taps_200k_wfm_decim_0, + taps_200k_wfm_decim_1, + taps_64_lp_156_198, + 75000, + }; + shared_memory.baseband_queue.push(message); } diff --git a/firmware/application/analog_audio_app.hpp b/firmware/application/analog_audio_app.hpp index 20703094..80047fa2 100644 --- a/firmware/application/analog_audio_app.hpp +++ b/firmware/application/analog_audio_app.hpp @@ -28,6 +28,10 @@ class AnalogAudioModel { public: AnalogAudioModel(ReceiverModel::Mode mode); + +private: + void configure_nbfm(); + void configure_wfm(); }; namespace ui { diff --git a/firmware/baseband/proc_wfm_audio.cpp b/firmware/baseband/proc_wfm_audio.cpp index 65923ddd..485fa620 100644 --- a/firmware/baseband/proc_wfm_audio.cpp +++ b/firmware/baseband/proc_wfm_audio.cpp @@ -23,26 +23,11 @@ #include -WidebandFMAudio::WidebandFMAudio() { - constexpr size_t baseband_fs = 3072000; - - constexpr size_t decim_0_input_fs = baseband_fs; - constexpr size_t decim_0_decimation_factor = 4; - 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 = 2; - constexpr size_t decim_1_output_fs = decim_1_input_fs / decim_1_decimation_factor; - - constexpr size_t demod_input_fs = decim_1_output_fs; - - decim_0.configure(taps_200k_wfm_decim_0.taps, 33554432); - decim_1.configure(taps_200k_wfm_decim_1.taps, 131072); - demod.configure(demod_input_fs, 75000); - audio_filter.configure(taps_64_lp_156_198.taps); -} - void WidebandFMAudio::execute(const buffer_c8_t& buffer) { + if( !configured ) { + return; + } + std::array dst; const buffer_c16_t dst_buffer { dst.data(), @@ -94,3 +79,35 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) { fill_audio_buffer(audio); } + +void WidebandFMAudio::on_message(const Message* const message) { + switch(message->id) { + case Message::ID::WFMConfigure: + configure(*reinterpret_cast(message)); + break; + + default: + break; + } +} + +void WidebandFMAudio::configure(const WFMConfigureMessage& message) { + constexpr size_t baseband_fs = 3072000; + + constexpr size_t decim_0_input_fs = baseband_fs; + constexpr size_t decim_0_decimation_factor = 4; + 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 = 2; + constexpr size_t decim_1_output_fs = decim_1_input_fs / decim_1_decimation_factor; + + constexpr size_t demod_input_fs = decim_1_output_fs; + + decim_0.configure(message.decim_0_filter.taps, 33554432); + decim_1.configure(message.decim_1_filter.taps, 131072); + demod.configure(demod_input_fs, message.deviation); + audio_filter.configure(message.audio_filter.taps); + + configured = true; +} diff --git a/firmware/baseband/proc_wfm_audio.hpp b/firmware/baseband/proc_wfm_audio.hpp index 6d6a6d0c..79b7969d 100644 --- a/firmware/baseband/proc_wfm_audio.hpp +++ b/firmware/baseband/proc_wfm_audio.hpp @@ -33,10 +33,10 @@ class WidebandFMAudio : public BasebandProcessor { public: - WidebandFMAudio(); - void execute(const buffer_c8_t& buffer) override; + void on_message(const Message* const message) override; + private: dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0; dsp::decimate::FIRC16xR16x16Decim2 decim_1; @@ -48,6 +48,9 @@ private: IIRBiquadFilter audio_hpf { audio_hpf_30hz_config }; IIRBiquadFilter audio_deemph { audio_deemph_2122_6_config }; + + bool configured { false }; + void configure(const WFMConfigureMessage& message); }; #endif/*__PROC_WFM_AUDIO_H__*/ diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index d332a091..fdb67bbd 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -53,6 +53,7 @@ public: ERTPacket = 9, UpdateSpectrum = 10, NBFMConfigure = 11, + WFMConfigure = 12, MAX }; @@ -292,6 +293,27 @@ public: const size_t deviation; }; +class WFMConfigureMessage : public Message { +public: + constexpr WFMConfigureMessage( + const fir_taps_real<24>& decim_0_filter, + const fir_taps_real<16>& decim_1_filter, + const fir_taps_real<64>& audio_filter, + const size_t deviation + ) : Message { ID::WFMConfigure }, + decim_0_filter { decim_0_filter }, + decim_1_filter { decim_1_filter }, + audio_filter { audio_filter }, + deviation { deviation } + { + } + + const fir_taps_real<24> decim_0_filter; + const fir_taps_real<16> decim_1_filter; + const fir_taps_real<64> audio_filter; + const size_t deviation; +}; + class MessageHandlerMap { public: using MessageHandler = std::function;