Mapped bars to audio spectrum

Still needs fine tuning.
This commit is contained in:
RocketGod 2025-04-03 14:11:58 -07:00
parent c43bfed0af
commit 6967915a60
2 changed files with 15 additions and 3 deletions

View File

@ -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;
}

View File

@ -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<int, NUM_BARS + 1> FREQUENCY_BANDS = {
20, 40, 80, 160, 315, 630, 1250, 2500, 5000, 10000,
12000, 14000, 16000, 18000, 20000, 22000, 24000};
struct ColorTheme {
Color base_color;