diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index c3d9f3f7..96101082 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -80,18 +80,39 @@ constexpr auto baseband_thread_priority = NORMALPRIO + 20; constexpr auto rssi_thread_priority = NORMALPRIO + 10; -static volatile bool channel_spectrum_request_update { false }; -static std::array channel_spectrum; -static uint32_t channel_spectrum_sampling_rate { 0 }; -static uint32_t channel_filter_pass_frequency { 0 }; -static uint32_t channel_filter_stop_frequency { 0 }; - class BasebandProcessor { public: virtual ~BasebandProcessor() = default; virtual void execute(buffer_c8_t buffer) = 0; + void update_spectrum() { + // Called from idle thread (after EVT_MASK_SPECTRUM is flagged) + if( channel_spectrum_request_update ) { + /* Decimated buffer is full. Compute spectrum. */ + std::array, 256> samples_swapped; + fft_swap(channel_spectrum, samples_swapped); + channel_spectrum_request_update = false; + fft_c_preswapped(samples_swapped); + + ChannelSpectrumMessage spectrum_message; + for(size_t i=0; i .magnitude, or something more (less!) accurate. */ + spectrum_message.spectrum.db_count = spectrum_message.spectrum.db.size(); + spectrum_message.spectrum.sampling_rate = channel_spectrum_sampling_rate; + spectrum_message.spectrum.channel_filter_pass_frequency = channel_filter_pass_frequency; + spectrum_message.spectrum.channel_filter_stop_frequency = channel_filter_stop_frequency; + shared_memory.application_queue.push(spectrum_message); + } + } + protected: void feed_channel_stats(const buffer_c16_t channel) { channel_stats.feed( @@ -136,6 +157,12 @@ private: AudioStatsCollector audio_stats; AudioStatisticsMessage audio_stats_message; + volatile bool channel_spectrum_request_update { false }; + std::array channel_spectrum; + uint32_t channel_spectrum_sampling_rate { 0 }; + uint32_t channel_filter_pass_frequency { 0 }; + uint32_t channel_filter_stop_frequency { 0 }; + void post_channel_stats_message(const ChannelStatistics statistics) { channel_stats_message.statistics = statistics; shared_memory.application_queue.push(channel_stats_message); @@ -623,28 +650,8 @@ private: } void handle_spectrum() { - if( channel_spectrum_request_update ) { - /* Decimated buffer is full. Compute spectrum. */ - std::array, channel_spectrum.size()> samples_swapped; - fft_swap(channel_spectrum, samples_swapped); - channel_spectrum_request_update = false; - fft_c_preswapped(samples_swapped); - - ChannelSpectrumMessage spectrum_message; - for(size_t i=0; i .magnitude, or something more (less!) accurate. */ - spectrum_message.spectrum.db_count = spectrum_message.spectrum.db.size(); - spectrum_message.spectrum.sampling_rate = channel_spectrum_sampling_rate; - spectrum_message.spectrum.channel_filter_pass_frequency = channel_filter_pass_frequency; - spectrum_message.spectrum.channel_filter_stop_frequency = channel_filter_stop_frequency; - shared_memory.application_queue.push(spectrum_message); + if( baseband_processor ) { + baseband_processor->update_spectrum(); } } };