mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-24 16:07:47 +00:00
Added PWM RSSI output for NBFM and WFM
This commit is contained in:
@@ -32,7 +32,7 @@ void NarrowbandFMAudio::execute(const buffer_c8_t& buffer) {
|
||||
if( !configured ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
|
||||
const auto decim_1_out = decim_1.execute(decim_0_out, dst_buffer);
|
||||
const auto channel_out = channel_filter.execute(decim_1_out, dst_buffer);
|
||||
@@ -40,8 +40,23 @@ void NarrowbandFMAudio::execute(const buffer_c8_t& buffer) {
|
||||
feed_channel_stats(channel_out);
|
||||
channel_spectrum.feed(channel_out, channel_filter_pass_f, channel_filter_stop_f);
|
||||
|
||||
auto audio = demod.execute(channel_out, audio_buffer);
|
||||
audio_output.write(audio);
|
||||
if ( !pwmrssi_enabled ) {
|
||||
auto audio = demod.execute(channel_out, audio_buffer);
|
||||
audio_output.write(audio);
|
||||
} else {
|
||||
for (c = 0; c < 32; c++) {
|
||||
if (synth_acc < pwmrssi_avg)
|
||||
pwmrssi_audio_buffer.p[c] = 32767;
|
||||
else
|
||||
pwmrssi_audio_buffer.p[c] = -32768;
|
||||
if (synth_acc < 30) // 24kHz / 30 = 800Hz (TODO: use pwmrssi_freq !)
|
||||
synth_acc++;
|
||||
else
|
||||
synth_acc = 0;
|
||||
}
|
||||
|
||||
audio_output.write(pwmrssi_audio_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
void NarrowbandFMAudio::on_message(const Message* const message) {
|
||||
@@ -58,6 +73,10 @@ void NarrowbandFMAudio::on_message(const Message* const message) {
|
||||
case Message::ID::CaptureConfig:
|
||||
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
||||
break;
|
||||
|
||||
case Message::ID::PWMRSSIConfigure:
|
||||
pwmrssi_config(*reinterpret_cast<const PWMRSSIConfigureMessage*>(message));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -83,11 +102,19 @@ void NarrowbandFMAudio::configure(const NBFMConfigureMessage& message) {
|
||||
channel_filter_pass_f = message.channel_filter.pass_frequency_normalized * channel_filter_input_fs;
|
||||
channel_filter_stop_f = message.channel_filter.stop_frequency_normalized * channel_filter_input_fs;
|
||||
channel_spectrum.set_decimation_factor(std::floor(channel_filter_output_fs / (channel_filter_pass_f + channel_filter_stop_f)));
|
||||
audio_output.configure(message.audio_hpf_config, message.audio_deemph_config, 0.8f);
|
||||
audio_output.configure(message.audio_hpf_config, message.audio_deemph_config); // , 0.8f
|
||||
|
||||
synth_acc = 0;
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
||||
void NarrowbandFMAudio::pwmrssi_config(const PWMRSSIConfigureMessage& message) {
|
||||
pwmrssi_enabled = message.enabled;
|
||||
pwmrssi_freq = message.freq;
|
||||
pwmrssi_avg = message.avg / 3;
|
||||
}
|
||||
|
||||
void NarrowbandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
||||
if( message.config ) {
|
||||
audio_output.set_stream(std::make_unique<StreamInput>(message.config));
|
||||
|
@@ -56,6 +56,12 @@ private:
|
||||
audio.data(),
|
||||
audio.size()
|
||||
};
|
||||
|
||||
std::array<int16_t, 32> pwm;
|
||||
const buffer_s16_t pwmrssi_audio_buffer {
|
||||
(int16_t*)pwm.data(),
|
||||
sizeof(pwm) / sizeof(int16_t)
|
||||
};
|
||||
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim8 decim_0;
|
||||
dsp::decimate::FIRC16xR16x32Decim8 decim_1;
|
||||
@@ -68,8 +74,14 @@ private:
|
||||
AudioOutput audio_output;
|
||||
|
||||
SpectrumCollector channel_spectrum;
|
||||
|
||||
unsigned int c, synth_acc = 0;
|
||||
bool pwmrssi_enabled = false;
|
||||
uint32_t pwmrssi_freq;
|
||||
uint32_t pwmrssi_avg;
|
||||
|
||||
bool configured { false };
|
||||
void pwmrssi_config(const PWMRSSIConfigureMessage& message);
|
||||
void configure(const NBFMConfigureMessage& message);
|
||||
void capture_config(const CaptureConfigMessage& message);
|
||||
};
|
||||
|
@@ -31,7 +31,7 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) {
|
||||
if( !configured ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const auto decim_0_out = decim_0.execute(buffer, dst_buffer);
|
||||
const auto channel = decim_1.execute(decim_0_out, dst_buffer);
|
||||
|
||||
@@ -44,32 +44,49 @@ void WidebandFMAudio::execute(const buffer_c8_t& buffer) {
|
||||
channel_spectrum.feed(channel, channel_filter_pass_f, channel_filter_stop_f);
|
||||
}
|
||||
|
||||
/* 384kHz complex<int16_t>[256]
|
||||
* -> FM demodulation
|
||||
* -> 384kHz int16_t[256] */
|
||||
/* TODO: To improve adjacent channel rejection, implement complex channel filter:
|
||||
* pass < +/- 100kHz, stop > +/- 200kHz
|
||||
*/
|
||||
if ( !pwmrssi_enabled ) {
|
||||
/* 384kHz complex<int16_t>[256]
|
||||
* -> FM demodulation
|
||||
* -> 384kHz int16_t[256] */
|
||||
/* TODO: To improve adjacent channel rejection, implement complex channel filter:
|
||||
* pass < +/- 100kHz, stop > +/- 200kHz
|
||||
*/
|
||||
|
||||
auto audio_oversampled = demod.execute(channel, work_audio_buffer);
|
||||
auto audio_oversampled = demod.execute(channel, work_audio_buffer);
|
||||
|
||||
/* 384kHz int16_t[256]
|
||||
* -> 4th order CIC decimation by 2, gain of 1
|
||||
* -> 192kHz int16_t[128] */
|
||||
auto audio_4fs = audio_dec_1.execute(audio_oversampled, work_audio_buffer);
|
||||
/* 384kHz int16_t[256]
|
||||
* -> 4th order CIC decimation by 2, gain of 1
|
||||
* -> 192kHz int16_t[128] */
|
||||
auto audio_4fs = audio_dec_1.execute(audio_oversampled, work_audio_buffer);
|
||||
|
||||
/* 192kHz int16_t[128]
|
||||
* -> 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);
|
||||
/* 192kHz int16_t[128]
|
||||
* -> 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);
|
||||
|
||||
/* 96kHz int16_t[64]
|
||||
* -> FIR filter, <15kHz (0.156fs) pass, >19kHz (0.198fs) stop, gain of 1
|
||||
* -> 48kHz int16_t[32] */
|
||||
auto audio = audio_filter.execute(audio_2fs, work_audio_buffer);
|
||||
/* 96kHz int16_t[64]
|
||||
* -> FIR filter, <15kHz (0.156fs) pass, >19kHz (0.198fs) stop, gain of 1
|
||||
* -> 48kHz int16_t[32] */
|
||||
auto audio = audio_filter.execute(audio_2fs, work_audio_buffer);
|
||||
|
||||
/* -> 48kHz int16_t[32] */
|
||||
audio_output.write(audio);
|
||||
} else {
|
||||
for (c = 0; c < 32; c++) {
|
||||
if (synth_acc < pwmrssi_avg)
|
||||
pwmrssi_audio_buffer.p[c] = 32767;
|
||||
else
|
||||
pwmrssi_audio_buffer.p[c] = -32768;
|
||||
if (synth_acc < 96) // 48kHz / 96 = 500Hz (TODO: use pwmrssi_freq !)
|
||||
synth_acc++;
|
||||
else
|
||||
synth_acc = 0;
|
||||
}
|
||||
|
||||
/* -> 48kHz int16_t[32] */
|
||||
audio_output.write(audio);
|
||||
/* -> 48kHz int16_t[32] */
|
||||
audio_output.write(pwmrssi_audio_buffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void WidebandFMAudio::on_message(const Message* const message) {
|
||||
@@ -86,6 +103,10 @@ void WidebandFMAudio::on_message(const Message* const message) {
|
||||
case Message::ID::CaptureConfig:
|
||||
capture_config(*reinterpret_cast<const CaptureConfigMessage*>(message));
|
||||
break;
|
||||
|
||||
case Message::ID::PWMRSSIConfigure:
|
||||
pwmrssi_config(*reinterpret_cast<const PWMRSSIConfigureMessage*>(message));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -114,9 +135,18 @@ void WidebandFMAudio::configure(const WFMConfigureMessage& message) {
|
||||
|
||||
channel_spectrum.set_decimation_factor(1);
|
||||
|
||||
pwmrssi_enabled = false;
|
||||
synth_acc = 0;
|
||||
|
||||
configured = true;
|
||||
}
|
||||
|
||||
void WidebandFMAudio::pwmrssi_config(const PWMRSSIConfigureMessage& message) {
|
||||
pwmrssi_enabled = message.enabled;
|
||||
pwmrssi_freq = message.freq;
|
||||
pwmrssi_avg = message.avg;
|
||||
}
|
||||
|
||||
void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) {
|
||||
if( message.config ) {
|
||||
audio_output.set_stream(std::make_unique<StreamInput>(message.config));
|
||||
|
@@ -54,6 +54,12 @@ private:
|
||||
(int16_t*)dst.data(),
|
||||
sizeof(dst) / sizeof(int16_t)
|
||||
};
|
||||
|
||||
std::array<int16_t, 32> pwm;
|
||||
const buffer_s16_t pwmrssi_audio_buffer {
|
||||
(int16_t*)pwm.data(),
|
||||
sizeof(pwm) / sizeof(int16_t)
|
||||
};
|
||||
|
||||
dsp::decimate::FIRC8xR16x24FS4Decim4 decim_0;
|
||||
dsp::decimate::FIRC16xR16x16Decim2 decim_1;
|
||||
@@ -70,8 +76,14 @@ private:
|
||||
SpectrumCollector channel_spectrum;
|
||||
size_t spectrum_interval_samples = 0;
|
||||
size_t spectrum_samples = 0;
|
||||
|
||||
unsigned int c, synth_acc = 0;
|
||||
bool pwmrssi_enabled = false;
|
||||
uint32_t pwmrssi_freq;
|
||||
uint32_t pwmrssi_avg;
|
||||
|
||||
bool configured { false };
|
||||
void pwmrssi_config(const PWMRSSIConfigureMessage& message);
|
||||
void configure(const WFMConfigureMessage& message);
|
||||
void capture_config(const CaptureConfigMessage& message);
|
||||
};
|
||||
|
@@ -21,10 +21,6 @@
|
||||
*/
|
||||
|
||||
#include "proc_xylos.hpp"
|
||||
|
||||
#include "dsp_iir_config.hpp"
|
||||
#include "audio_output.hpp"
|
||||
|
||||
#include "portapack_shared_memory.hpp"
|
||||
#include "sine_table_int8.hpp"
|
||||
#include "event_m4.hpp"
|
||||
|
Reference in New Issue
Block a user