Enhance Graphic Equalizer Visualization with Improved Frequency Bands and Response (#2614)

This commit is contained in:
RocketGod 2025-04-10 13:16:18 -07:00 committed by GitHub
parent 319ed3e7b4
commit eff214cc79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 31 deletions

View File

@ -112,49 +112,44 @@ void gfxEQView::update_audio_spectrum(const AudioSpectrum& spectrum) {
float total_energy = 0;
int bin_count = 0;
// Apply standard EQ frequency response curve (inverted V shape)
for (int bin = start_bin; bin <= end_bin; bin++) {
float weight = 1.0f;
float normalized_bin = bin / 127.0f; // 0.0 to 1.0
// Boosting mid frequencies per standard graphic EQ curve
if (normalized_bin >= 0.2f && normalized_bin <= 0.7f) {
// Create an inverted V shape with peak at 0.45 (middle frequencies)
float distance_from_mid = fabs(normalized_bin - 0.45f);
weight = 2.2f - (distance_from_mid * 2.0f); // Max 2.2x boost at center
}
// Add extra low-frequency sensitivity
if (bar < 5) {
weight *= (1.8f - (bar * 0.15f));
}
total_energy += spectrum.db[bin] * weight;
total_energy += spectrum.db[bin];
bin_count++;
}
uint8_t avg_db = bin_count > 0 ? (total_energy / bin_count) : 0;
float avg_db = bin_count > 0 ? (total_energy / bin_count) : 0;
// Scale all bands to reasonable levels
float band_scale = 0.85f;
// Manually boost highs for better visual balance
float treble_boost = 1.0f;
if (bar == 10)
treble_boost = 1.7f;
else if (bar >= 9)
treble_boost = 1.3f;
else if (bar >= 7)
treble_boost = 1.3f;
// Get the height in display units
int target_height = (avg_db * RENDER_HEIGHT * band_scale) / 255;
// Mid emphasis for a V-shape effect
float mid_boost = 1.0f;
if (bar == 4 || bar == 5 || bar == 6) mid_boost = 1.2f;
float amplified_db = avg_db * treble_boost * mid_boost;
if (amplified_db > 255) amplified_db = 255;
float band_scale = 1.0f;
int target_height = (amplified_db * RENDER_HEIGHT * band_scale) / 255;
// Cap maximum height to prevent overshoot
if (target_height > RENDER_HEIGHT) {
target_height = RENDER_HEIGHT;
}
// Apply different speeds for rise and fall
float rise_speed = 0.7f;
float fall_speed = 0.12f;
// Adjusted to look nice to my eyes
float rise_speed = 0.8f;
float fall_speed = 1.0f;
if (target_height > bar_heights[bar]) {
// Fast rise response
bar_heights[bar] = bar_heights[bar] * (1.0f - rise_speed) + target_height * rise_speed;
} else {
// Slow fall response
bar_heights[bar] = bar_heights[bar] * (1.0f - fall_speed) + target_height * fall_speed;
}
}

View File

@ -43,15 +43,26 @@ class gfxEQView : public View {
static constexpr int SCREEN_WIDTH = 240;
static constexpr int SCREEN_HEIGHT = 320;
static constexpr int RENDER_HEIGHT = 288;
static constexpr int NUM_BARS = 14;
static constexpr int NUM_BARS = 11;
static constexpr int BAR_SPACING = 2;
static constexpr int BAR_WIDTH = (SCREEN_WIDTH - (BAR_SPACING * (NUM_BARS - 1))) / NUM_BARS;
static constexpr int HORIZONTAL_OFFSET = 2;
static constexpr int SEGMENT_HEIGHT = 10;
static constexpr std::array<int, NUM_BARS + 1> FREQUENCY_BANDS = {
20, 40, 80, 160, 320, 640, 1000, 1600, 2500, 4000,
6000, 9000, 12000, 16000, 24000};
375, // Bass warmth and low rumble (e.g., deep basslines, kick drum body)
750, // Upper bass punch (e.g., bass guitar punch, kick drum attack)
1500, // Lower midrange fullness (e.g., warmth in vocals, guitar body)
2250, // Midrange clarity (e.g., vocal presence, snare crack)
3375, // Upper midrange bite (e.g., instrument definition, vocal articulation)
4875, // Presence and edge (e.g., guitar bite, vocal sibilance start)
6750, // Lower brilliance (e.g., cymbal shimmer, vocal clarity)
9375, // Brilliance and air (e.g., hi-hat crispness, breathy vocals)
13125, // High treble sparkle (e.g., subtle overtones, synth shimmer)
16875, // Upper treble airiness (e.g., faint harmonics, room ambiance)
20625, // Top-end sheen (e.g., ultra-high harmonics, noise floor)
24375 // Extreme treble limit (e.g., inaudible overtones, signal cutoff, static)
};
struct ColorTheme {
Color base_color;