mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-04-18 06:56:03 -04:00
Made calculations for 14 bars to fit screen and little adjustments
This commit is contained in:
parent
5f2056a9b0
commit
01911c85a3
18
firmware/application/external/gfxeq/ui_gfxeq.cpp
vendored
18
firmware/application/external/gfxeq/ui_gfxeq.cpp
vendored
@ -113,26 +113,32 @@ void gfxEQView::update_audio_spectrum(const AudioSpectrum& spectrum) {
|
||||
float total_energy = 0;
|
||||
int bin_count = 0;
|
||||
|
||||
// Improved energy calculation with weighted frequency response
|
||||
for (int bin = start_bin; bin <= end_bin; bin++) {
|
||||
total_energy += spectrum.db[bin];
|
||||
// Apply slight emphasis to mid-range frequencies (human ear is more sensitive)
|
||||
float weight = 1.0f;
|
||||
if (bin > 20 && bin < 80) { // Roughly corresponds to 375-1500Hz
|
||||
weight = 1.2f;
|
||||
}
|
||||
total_energy += spectrum.db[bin] * weight;
|
||||
bin_count++;
|
||||
}
|
||||
|
||||
uint8_t avg_db = bin_count > 0 ? total_energy / bin_count : 0;
|
||||
|
||||
const float response_speed = 0.7f;
|
||||
// Slightly faster response for low frequencies, slower for high frequencies
|
||||
float response_speed = bar < 5 ? 0.75f : (bar > 10 ? 0.65f : 0.7f);
|
||||
int target_height = (avg_db * RENDER_HEIGHT) / 255;
|
||||
bar_heights[bar] = bar_heights[bar] * (1.0f - response_speed) + target_height * response_speed;
|
||||
}
|
||||
}
|
||||
|
||||
void gfxEQView::render_equalizer(Painter& painter) {
|
||||
const int num_bars = SCREEN_WIDTH / (BAR_WIDTH + BAR_SPACING);
|
||||
const int num_segments = RENDER_HEIGHT / SEGMENT_HEIGHT;
|
||||
const ColorTheme& theme = themes[current_theme];
|
||||
|
||||
for (int bar = 0; bar < num_bars; bar++) {
|
||||
int x = bar * (BAR_WIDTH + BAR_SPACING);
|
||||
for (int bar = 0; bar < NUM_BARS; bar++) {
|
||||
int x = HORIZONTAL_OFFSET + bar * (BAR_WIDTH + BAR_SPACING);
|
||||
int active_segments = (bar_heights[bar] * num_segments) / RENDER_HEIGHT;
|
||||
|
||||
if (prev_bar_heights[bar] > active_segments) {
|
||||
@ -165,4 +171,4 @@ void gfxEQView::cycle_theme() {
|
||||
current_theme = (current_theme + 1) % themes.size();
|
||||
}
|
||||
|
||||
} // namespace ui::external_app::gfxeq
|
||||
} // namespace ui::external_app::gfxeq
|
13
firmware/application/external/gfxeq/ui_gfxeq.hpp
vendored
13
firmware/application/external/gfxeq/ui_gfxeq.hpp
vendored
@ -43,13 +43,16 @@ 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 = 16;
|
||||
static constexpr int BAR_WIDTH = SCREEN_WIDTH / NUM_BARS;
|
||||
static constexpr int NUM_BARS = 14;
|
||||
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; // Adjust for centering
|
||||
static constexpr int SEGMENT_HEIGHT = 10;
|
||||
|
||||
// Improved frequency bands with better low-frequency separation
|
||||
static constexpr std::array<int, NUM_BARS + 1> FREQUENCY_BANDS = {
|
||||
20, 50, 100, 200, 400, 630, 1000, 1600, 2500, 4000,
|
||||
6300, 8000, 10000, 12500, 16000, 20000, 24000};
|
||||
20, 50, 100, 200, 400, 800, 1200, 1800, 2600, 4000,
|
||||
6000, 9000, 12000, 16000, 24000};
|
||||
|
||||
struct ColorTheme {
|
||||
Color base_color;
|
||||
@ -122,4 +125,4 @@ class gfxEQView : public View {
|
||||
|
||||
} // namespace ui::external_app::gfxeq
|
||||
|
||||
#endif
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user