From 7c5db55f8f4308eebcda66caa29f3894376e73d5 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 27 Aug 2015 13:14:45 -0700 Subject: [PATCH] Extract NarrowbandFMAudio into separate files. --- firmware/baseband/Makefile | 1 + firmware/baseband/main.cpp | 62 +---------------------- firmware/baseband/proc_nfm_audio.cpp | 74 ++++++++++++++++++++++++++++ firmware/baseband/proc_nfm_audio.hpp | 49 ++++++++++++++++++ 4 files changed, 125 insertions(+), 61 deletions(-) create mode 100644 firmware/baseband/proc_nfm_audio.cpp create mode 100644 firmware/baseband/proc_nfm_audio.hpp diff --git a/firmware/baseband/Makefile b/firmware/baseband/Makefile index c15e5920..4542dccf 100755 --- a/firmware/baseband/Makefile +++ b/firmware/baseband/Makefile @@ -134,6 +134,7 @@ CPPSRC = main.cpp \ dsp_decimate.cpp \ dsp_demodulate.cpp \ proc_am_audio.cpp \ + proc_nfm_audio.cpp \ dsp_squelch.cpp \ clock_recovery.cpp \ access_code_correlator.cpp \ diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index 87c81474..fdd18f3b 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -53,6 +53,7 @@ #include "channel_decimator.hpp" #include "baseband_processor.hpp" #include "proc_am_audio.hpp" +#include "proc_nfm_audio.hpp" #include "clock_recovery.hpp" #include "access_code_correlator.hpp" @@ -78,67 +79,6 @@ constexpr auto baseband_thread_priority = NORMALPRIO + 20; constexpr auto rssi_thread_priority = NORMALPRIO + 10; -class NarrowbandFMAudio : public BasebandProcessor { -public: - void execute(buffer_c8_t buffer) override { - /* Called every 2048/3072000 second -- 1500Hz. */ - - auto decimator_out = decimator.execute(buffer); - - const buffer_c16_t work_baseband_buffer { - (complex16_t*)decimator_out.p, - sizeof(*decimator_out.p) * decimator_out.count - }; - - /* 96kHz complex[64] - * -> FIR filter, <6kHz (0.063fs) pass, gain 1.0 - * -> 48kHz int16_t[32] */ - auto channel = channel_filter.execute(decimator_out, work_baseband_buffer); - - // TODO: Feed channel_stats post-decimation data? - feed_channel_stats(channel); - feed_channel_spectrum( - channel, - decimator_out.sampling_rate * channel_filter_taps.pass_frequency_normalized, - decimator_out.sampling_rate * channel_filter_taps.stop_frequency_normalized - ); - - const buffer_s16_t work_audio_buffer { - (int16_t*)decimator_out.p, - sizeof(*decimator_out.p) * decimator_out.count - }; - - /* 48kHz complex[32] - * -> FM demodulation - * -> 48kHz int16_t[32] */ - auto audio = demod.execute(channel, work_audio_buffer); - - static uint64_t audio_present_history = 0; - const auto audio_present_now = squelch.execute(audio); - audio_present_history = (audio_present_history << 1) | (audio_present_now ? 1 : 0); - const bool audio_present = (audio_present_history != 0); - - if( !audio_present ) { - // Zero audio buffer. - for(size_t i=0; i& channel_filter_taps = taps_64_lp_042_078_tfilter; - dsp::decimate::FIRAndDecimateBy2Complex<64> channel_filter { channel_filter_taps.taps }; - dsp::demodulate::FM demod { 48000, 7500 }; - - IIRBiquadFilter audio_hpf { audio_hpf_config }; - FMSquelch squelch; -}; - class WidebandFMAudio : public BasebandProcessor { public: void execute(buffer_c8_t buffer) override { diff --git a/firmware/baseband/proc_nfm_audio.cpp b/firmware/baseband/proc_nfm_audio.cpp new file mode 100644 index 00000000..e9b70cf9 --- /dev/null +++ b/firmware/baseband/proc_nfm_audio.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc. + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "proc_nfm_audio.hpp" + +#include +#include + +void NarrowbandFMAudio::execute(buffer_c8_t buffer) { + /* Called every 2048/3072000 second -- 1500Hz. */ + + auto decimator_out = decimator.execute(buffer); + + const buffer_c16_t work_baseband_buffer { + (complex16_t*)decimator_out.p, + sizeof(*decimator_out.p) * decimator_out.count + }; + + /* 96kHz complex[64] + * -> FIR filter, <6kHz (0.063fs) pass, gain 1.0 + * -> 48kHz int16_t[32] */ + auto channel = channel_filter.execute(decimator_out, work_baseband_buffer); + + // TODO: Feed channel_stats post-decimation data? + feed_channel_stats(channel); + feed_channel_spectrum( + channel, + decimator_out.sampling_rate * channel_filter_taps.pass_frequency_normalized, + decimator_out.sampling_rate * channel_filter_taps.stop_frequency_normalized + ); + + const buffer_s16_t work_audio_buffer { + (int16_t*)decimator_out.p, + sizeof(*decimator_out.p) * decimator_out.count + }; + + /* 48kHz complex[32] + * -> FM demodulation + * -> 48kHz int16_t[32] */ + auto audio = demod.execute(channel, work_audio_buffer); + + static uint64_t audio_present_history = 0; + const auto audio_present_now = squelch.execute(audio); + audio_present_history = (audio_present_history << 1) | (audio_present_now ? 1 : 0); + const bool audio_present = (audio_present_history != 0); + + if( !audio_present ) { + // Zero audio buffer. + for(size_t i=0; i& channel_filter_taps = taps_64_lp_042_078_tfilter; + dsp::decimate::FIRAndDecimateBy2Complex<64> channel_filter { channel_filter_taps.taps }; + dsp::demodulate::FM demod { 48000, 7500 }; + + IIRBiquadFilter audio_hpf { audio_hpf_config }; + FMSquelch squelch; +}; + +#endif/*__PROC_NFM_AUDIO_H__*/