mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-04-14 05:03:08 -04:00
Enhance Graphic Equalizer Visualization with Improved Frequency Bands and Response (#2614)
This commit is contained in:
parent
319ed3e7b4
commit
eff214cc79
51
firmware/application/external/gfxeq/ui_gfxeq.cpp
vendored
51
firmware/application/external/gfxeq/ui_gfxeq.cpp
vendored
@ -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;
|
||||
}
|
||||
}
|
||||
|
17
firmware/application/external/gfxeq/ui_gfxeq.hpp
vendored
17
firmware/application/external/gfxeq/ui_gfxeq.hpp
vendored
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user