diff --git a/firmware/application/external/gfxeq/ui_gfxeq.cpp b/firmware/application/external/gfxeq/ui_gfxeq.cpp index b8033c31a..d2a39ce6f 100644 --- a/firmware/application/external/gfxeq/ui_gfxeq.cpp +++ b/firmware/application/external/gfxeq/ui_gfxeq.cpp @@ -93,23 +93,30 @@ void gfxEQView::update_audio_spectrum(const AudioSpectrum& spectrum) { const float bin_frequency_size = 48000.0f / 128; for (int bar = 0; bar < NUM_BARS; bar++) { - int start_bin = FREQUENCY_BANDS[bar] / bin_frequency_size; - int end_bin = FREQUENCY_BANDS[bar + 1] / bin_frequency_size; + float start_freq = FREQUENCY_BANDS[bar]; + float end_freq = FREQUENCY_BANDS[bar + 1]; + + int start_bin = std::round(start_freq / bin_frequency_size); + int end_bin = std::round(end_freq / 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; + float total_energy = 0; + int bin_count = 0; + for (int bin = start_bin; bin <= end_bin; bin++) { - if (spectrum.db[bin] > max_db) { - max_db = spectrum.db[bin]; - } + total_energy += spectrum.db[bin]; + bin_count++; } - int height = (max_db * RENDER_HEIGHT) / 255; - bar_heights[bar] = height; + uint8_t avg_db = bin_count > 0 ? total_energy / bin_count : 0; + + const float response_speed = 0.7f; + int target_height = (avg_db * RENDER_HEIGHT) / 255; + bar_heights[bar] = bar_heights[bar] * (1.0f - response_speed) + target_height * response_speed; } } diff --git a/firmware/application/external/gfxeq/ui_gfxeq.hpp b/firmware/application/external/gfxeq/ui_gfxeq.hpp index 45ccb42df..080bde379 100644 --- a/firmware/application/external/gfxeq/ui_gfxeq.hpp +++ b/firmware/application/external/gfxeq/ui_gfxeq.hpp @@ -47,8 +47,8 @@ class gfxEQView : public View { 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}; + 20, 50, 100, 200, 400, 630, 1000, 1600, 2500, 4000, + 6300, 8000, 10000, 12500, 16000, 20000, 24000}; struct ColorTheme { Color base_color;