diff --git a/firmware/application/external/gfxeq/ui_gfxeq.cpp b/firmware/application/external/gfxeq/ui_gfxeq.cpp index 5d97a400b..b8033c31a 100644 --- a/firmware/application/external/gfxeq/ui_gfxeq.cpp +++ b/firmware/application/external/gfxeq/ui_gfxeq.cpp @@ -90,15 +90,24 @@ void gfxEQView::on_hide() { } void gfxEQView::update_audio_spectrum(const AudioSpectrum& spectrum) { - const int bins_per_bar = 128 / NUM_BARS; + const float bin_frequency_size = 48000.0f / 128; + for (int bar = 0; bar < NUM_BARS; bar++) { - int start_bin = bar * bins_per_bar; + int start_bin = FREQUENCY_BANDS[bar] / bin_frequency_size; + int end_bin = FREQUENCY_BANDS[bar + 1] / bin_frequency_size; + + if (start_bin < 0) start_bin = 0; + if (start_bin > 127) start_bin = 127; + if (end_bin < 0) end_bin = 0; + if (end_bin > 127) end_bin = 127; + uint8_t max_db = 0; - for (int bin = start_bin; bin < start_bin + bins_per_bar; bin++) { + for (int bin = start_bin; bin <= end_bin; bin++) { if (spectrum.db[bin] > max_db) { max_db = spectrum.db[bin]; } } + int height = (max_db * RENDER_HEIGHT) / 255; bar_heights[bar] = height; } diff --git a/firmware/application/external/gfxeq/ui_gfxeq.hpp b/firmware/application/external/gfxeq/ui_gfxeq.hpp index ebb431977..45ccb42df 100644 --- a/firmware/application/external/gfxeq/ui_gfxeq.hpp +++ b/firmware/application/external/gfxeq/ui_gfxeq.hpp @@ -46,6 +46,9 @@ class gfxEQView : public View { static constexpr int BAR_WIDTH = SCREEN_WIDTH / NUM_BARS; static constexpr int BAR_SPACING = 2; static constexpr int SEGMENT_HEIGHT = 10; + static constexpr std::array FREQUENCY_BANDS = { + 20, 40, 80, 160, 315, 630, 1250, 2500, 5000, 10000, + 12000, 14000, 16000, 18000, 20000, 22000, 24000}; struct ColorTheme { Color base_color;