mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-10 08:39:29 +00: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:
@@ -255,7 +255,7 @@ WaterfallWidget::WaterfallWidget(const bool cursor) {
|
||||
|
||||
add_children({
|
||||
&waterfall_view,
|
||||
&frequency_scale,
|
||||
&frequency_scale
|
||||
});
|
||||
}
|
||||
|
||||
@@ -311,16 +311,51 @@ bool WaterfallWidget::on_key(const KeyEvent key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void WaterfallWidget::on_audio_spectrum(const AudioSpectrum& spectrum) {
|
||||
if (fft_widget) {
|
||||
for (size_t i = 0; i < spectrum.db.size(); i++)
|
||||
audio_spectrum[i] = ((int16_t)spectrum.db[i] - 127) * 256;
|
||||
fft_widget->set_dirty();
|
||||
}
|
||||
}
|
||||
|
||||
void WaterfallWidget::set_fft_widget(const bool show) {
|
||||
if (fft_widget) {
|
||||
audio_fifo = nullptr;
|
||||
remove_child(fft_widget.get());
|
||||
fft_widget.reset();
|
||||
}
|
||||
|
||||
if (show) {
|
||||
waterfall_view.set_parent_rect(waterfall_reduced_rect);
|
||||
waterfall_view.on_show();
|
||||
fft_widget = std::make_unique<Waveform>(
|
||||
fft_widget_rect,
|
||||
audio_spectrum,
|
||||
128,
|
||||
0,
|
||||
false,
|
||||
Color::white());
|
||||
add_child(fft_widget.get());
|
||||
} else {
|
||||
waterfall_view.set_parent_rect(waterfall_normal_rect);
|
||||
waterfall_view.on_show();
|
||||
}
|
||||
}
|
||||
|
||||
void WaterfallWidget::set_parent_rect(const Rect new_parent_rect) {
|
||||
constexpr Dim scale_height = 20;
|
||||
|
||||
View::set_parent_rect(new_parent_rect);
|
||||
|
||||
waterfall_normal_rect = { 0, scale_height, new_parent_rect.width(), new_parent_rect.height() - scale_height};
|
||||
waterfall_reduced_rect = { 0, scale_height, new_parent_rect.width(), new_parent_rect.height() - scale_height - audio_spectrum_height };
|
||||
|
||||
frequency_scale.set_parent_rect({ 0, 0, new_parent_rect.width(), scale_height });
|
||||
waterfall_view.set_parent_rect({
|
||||
0, scale_height,
|
||||
new_parent_rect.width(),
|
||||
new_parent_rect.height() - scale_height
|
||||
});
|
||||
waterfall_view.set_parent_rect(waterfall_normal_rect);
|
||||
waterfall_view.on_show();
|
||||
|
||||
fft_widget_rect = { 0, new_parent_rect.height() - audio_spectrum_height, new_parent_rect.width(), audio_spectrum_height };
|
||||
}
|
||||
|
||||
void WaterfallWidget::paint(Painter& painter) {
|
||||
|
||||
@@ -97,41 +97,67 @@ public:
|
||||
bool on_key(const KeyEvent key) override;
|
||||
|
||||
void set_parent_rect(const Rect new_parent_rect) override;
|
||||
|
||||
void set_fft_widget(const bool show);
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
private:
|
||||
void on_tick_second();
|
||||
|
||||
static constexpr ui::Dim audio_spectrum_height = 2 * 16;
|
||||
|
||||
WaterfallView waterfall_view { };
|
||||
FrequencyScale frequency_scale { };
|
||||
ChannelSpectrumFIFO* fifo { nullptr };
|
||||
|
||||
ChannelSpectrumFIFO* channel_fifo { nullptr };
|
||||
AudioSpectrumFIFO* audio_fifo { nullptr };
|
||||
|
||||
std::unique_ptr<Widget> fft_widget { };
|
||||
bool _blink { false };
|
||||
int sampling_rate { 0 };
|
||||
int32_t cursor_position { 0 };
|
||||
SignalToken signal_token_tick_second { };
|
||||
int16_t audio_spectrum[128] { 0 };
|
||||
ui::Rect waterfall_normal_rect { };
|
||||
ui::Rect waterfall_reduced_rect { };
|
||||
ui::Rect fft_widget_rect { };
|
||||
|
||||
MessageHandlerRegistration message_handler_spectrum_config {
|
||||
MessageHandlerRegistration message_handler_channel_spectrum_config {
|
||||
Message::ID::ChannelSpectrumConfig,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const ChannelSpectrumConfigMessage*>(p);
|
||||
this->fifo = message.fifo;
|
||||
this->channel_fifo = message.fifo;
|
||||
}
|
||||
};
|
||||
MessageHandlerRegistration message_handler_audio_spectrum_config {
|
||||
Message::ID::AudioSpectrumConfig,
|
||||
[this](const Message* const p) {
|
||||
const auto message = *reinterpret_cast<const AudioSpectrumConfigMessage*>(p);
|
||||
this->audio_fifo = message.fifo;
|
||||
}
|
||||
};
|
||||
MessageHandlerRegistration message_handler_frame_sync {
|
||||
Message::ID::DisplayFrameSync,
|
||||
[this](const Message* const) {
|
||||
if( this->fifo ) {
|
||||
if( this->channel_fifo ) {
|
||||
ChannelSpectrum channel_spectrum;
|
||||
while( fifo->out(channel_spectrum) ) {
|
||||
while( channel_fifo->out(channel_spectrum) ) {
|
||||
this->on_channel_spectrum(channel_spectrum);
|
||||
}
|
||||
}
|
||||
if( this->audio_fifo ) {
|
||||
AudioSpectrum audio_spectrum;
|
||||
while( audio_fifo->out(audio_spectrum) ) {
|
||||
// Unstack everything until and only use last buffer (should only be one max. ready per frame)
|
||||
}
|
||||
this->on_audio_spectrum(audio_spectrum);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void on_channel_spectrum(const ChannelSpectrum& spectrum);
|
||||
void on_audio_spectrum(const AudioSpectrum& spectrum);
|
||||
};
|
||||
|
||||
} /* namespace spectrum */
|
||||
|
||||
Reference in New Issue
Block a user