mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-11 00:59:28 +00:00
Testing external clock detection and auto-switch
Simplified audio spectrum computation and transfer ACARS RX in debug mode Disabled ABI warnings Updated binary
This commit is contained in:
@@ -66,47 +66,57 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) {
|
||||
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
|
||||
// audio_spectrum_decimator piles up 256 samples before doing FFT computation
|
||||
// This sends an AudioSpectrum every: sample rate/buffer size/refresh period = 3072000/2048/50 = 30 Hz
|
||||
// When audio_spectrum_timer expires, the audio spectrum computation is triggered
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
audio_spectrum_timer++;
|
||||
if (audio_spectrum_timer == 50) {
|
||||
audio_spectrum_timer = 0;
|
||||
audio_spectrum_state = FEED;
|
||||
}
|
||||
|
||||
if (refresh_timer == 31)
|
||||
refresh_timer = 0;
|
||||
else
|
||||
refresh_timer++;
|
||||
switch (audio_spectrum_state) {
|
||||
case FEED:
|
||||
// Convert audio to "complex" just so the FFT can be done :/
|
||||
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);
|
||||
}
|
||||
);
|
||||
break;
|
||||
case FFT:
|
||||
// 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_step < 8) {
|
||||
fft_c_preswapped(audio_spectrum, fft_step, fft_step + 1);
|
||||
fft_step++;
|
||||
} else {
|
||||
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));
|
||||
}
|
||||
AudioSpectrumMessage message { &spectrum };
|
||||
shared_memory.application_queue.push(message);
|
||||
audio_spectrum_state = IDLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* 96kHz int16_t[64]
|
||||
* -> FIR filter, <15kHz (0.156fs) pass, >19kHz (0.198fs) stop, gain of 1
|
||||
@@ -121,7 +131,8 @@ 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;
|
||||
audio_spectrum_state = FFT;
|
||||
fft_step = 0;
|
||||
}
|
||||
|
||||
void WidebandFMAudio::on_message(const Message* const message) {
|
||||
@@ -167,9 +178,6 @@ 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) {
|
||||
|
||||
Reference in New Issue
Block a user