Added an audio FFT view in Wideband FM receive

Tried speeding up fill_rectangle for clearing the waveform widget
This commit is contained in:
furrtek
2018-05-21 18:46:48 +01:00
parent b11c3c94b6
commit b813b32593
19 changed files with 259 additions and 38 deletions

View File

@@ -22,8 +22,9 @@
#include "proc_wfm_audio.hpp"
#include "portapack_shared_memory.hpp"
#include "audio_output.hpp"
#include "dsp_fft.hpp"
#include "event_m4.hpp"
#include <cstdint>
@@ -63,7 +64,50 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) {
* -> 4th order CIC decimation by 2, gain of 1
* -> 96kHz int16_t[64] */
auto audio_2fs = audio_dec_2.execute(audio_4fs, work_audio_buffer);
// Input: 96kHz int16_t[64]
// audio_spectrum_decimator piles up 256 bytes before doing FFT computation
// This should send an AudioSpectrum every sample rate/buffer size/(256/64)/refresh scaler = 3072000/2048/4/8 = ~47 Hz
// 0~3: feed continuous audio
// 4~31: ignore, wrap at 31
if (!(refresh_timer & 0xF8)) {
for (size_t i = 0; i < 64; i++) {
complex_audio[i] = { (int16_t)(work_audio_buffer.p[i] / 32), (int16_t)0 };
}
audio_spectrum_decimator.feed(
complex_audio_buffer,
[this](const buffer_c16_t& data) {
this->post_message(data);
}
);
} else {
// Spread the FFT workload in time to avoid making the audio skip
// "8" comes from the log2() of the size of audio_spectrum: log2(256) = 8
if (fft_stage && (fft_stage <= 8)) {
fft_c_preswapped(audio_spectrum, fft_stage - 1, fft_stage);
fft_stage++;
} else if (fft_stage > 8) {
AudioSpectrum spectrum;
const size_t spectrum_end = spectrum.db.size();
for(size_t i=0; i<spectrum_end; i++) {
//const auto corrected_sample = spectrum_window_hamming_3(audio_spectrum, i);
const auto corrected_sample = audio_spectrum[i];
const auto mag2 = magnitude_squared(corrected_sample * (1.0f / 32768.0f));
const float db = mag2_to_dbv_norm(mag2);
constexpr float mag_scale = 5.0f;
const unsigned int v = (db * mag_scale) + 255.0f;
spectrum.db[i] = std::max(0U, std::min(255U, v));
}
fifo.in(spectrum);
fft_stage = 0;
}
}
if (refresh_timer == 31)
refresh_timer = 0;
else
refresh_timer++;
/* 96kHz int16_t[64]
* -> FIR filter, <15kHz (0.156fs) pass, >19kHz (0.198fs) stop, gain of 1
* -> 48kHz int16_t[32] */
@@ -74,6 +118,12 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) {
}
void WidebandFMAudio::post_message(const buffer_c16_t& data) {
// This is called when audio_spectrum_decimator is filled up to 256 samples
fft_swap(data, audio_spectrum);
fft_stage = 1;
}
void WidebandFMAudio::on_message(const Message* const message) {
switch(message->id) {
case Message::ID::UpdateSpectrum:
@@ -117,6 +167,9 @@ void WidebandFMAudio::configure(const WFMConfigureMessage& message) {
channel_spectrum.set_decimation_factor(1);
configured = true;
AudioSpectrumConfigMessage config_message { &fifo };
shared_memory.application_queue.push(config_message);
}
void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) {

View File

@@ -27,8 +27,10 @@
#include "baseband_thread.hpp"
#include "rssi_thread.hpp"
#include "dsp_types.hpp"
#include "dsp_decimate.hpp"
#include "dsp_demodulate.hpp"
#include "block_decimator.hpp"
#include "audio_output.hpp"
#include "spectrum_collector.hpp"
@@ -56,6 +58,12 @@ private:
sizeof(dst) / sizeof(int16_t)
};
std::array<complex16_t, 64> complex_audio { };
const buffer_c16_t complex_audio_buffer {
complex_audio.data(),
complex_audio.size()
};
dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0 { };
dsp::decimate::FIRC16xR16x16Decim2 decim_1 { };
uint32_t channel_filter_pass_f = 0;
@@ -67,6 +75,14 @@ private:
dsp::decimate::FIR64AndDecimateBy2Real audio_filter { };
AudioOutput audio_output { };
// For fs=96kHz FFT streaming
BlockDecimator<complex16_t, 256> audio_spectrum_decimator { 1 };
AudioSpectrum fifo_data[1 << AudioSpectrumConfigMessage::fifo_k] { };
AudioSpectrumFIFO fifo { fifo_data, AudioSpectrumConfigMessage::fifo_k };
std::array<std::complex<float>, 256> audio_spectrum { };
uint32_t refresh_timer { 0 };
uint32_t fft_stage { 0 };
SpectrumCollector channel_spectrum { };
size_t spectrum_interval_samples = 0;
@@ -75,6 +91,7 @@ private:
bool configured { false };
void configure(const WFMConfigureMessage& message);
void capture_config(const CaptureConfigMessage& message);
void post_message(const buffer_c16_t& data);
};
#endif/*__PROC_WFM_AUDIO_H__*/

View File

@@ -132,7 +132,7 @@ void SpectrumCollector::update() {
// Called from idle thread (after EVT_MASK_SPECTRUM is flagged)
if( streaming && channel_spectrum_request_update ) {
/* Decimated buffer is full. Compute spectrum. */
fft_c_preswapped(channel_spectrum);
fft_c_preswapped(channel_spectrum, 0, 8);
ChannelSpectrum spectrum;
spectrum.sampling_rate = channel_spectrum_sampling_rate;