mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-08-02 11:36:38 -04:00
Added an audio FFT view in Wideband FM receive
Tried speeding up fill_rectangle for clearing the waveform widget
This commit is contained in:
parent
b11c3c94b6
commit
b813b32593
19 changed files with 259 additions and 38 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue