From 5a1d77de83b7a6ba20e70d107ed1b5d6d0e3ce15 Mon Sep 17 00:00:00 2001 From: Dan Everton Date: Fri, 17 Feb 2006 19:56:22 +0000 Subject: Reduce CPU usage while changing EQ by only updating the coefficients of the band being modified. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8718 a1c6a512-1295-4272-9138-f99709370657 --- apps/dsp.c | 57 ++++++++++++++++++++++++++------------------------------- apps/dsp.h | 2 +- apps/eq_menu.c | 21 ++++++++++++++------- apps/settings.c | 7 ++++++- 4 files changed, 47 insertions(+), 40 deletions(-) diff --git a/apps/dsp.c b/apps/dsp.c index 7ea9ecfafd..daecd5c69e 100644 --- a/apps/dsp.c +++ b/apps/dsp.c @@ -624,48 +624,43 @@ static void apply_crossfeed(long* src[], int count) #define EQ_GAIN_USER2REAL(x) (((x) << 16) / 10) /* Synchronize the EQ filters with the global settings */ -void dsp_eq_update_data(bool enabled) +void dsp_eq_update_data(bool enabled, int band) { - int i; int *setting; - int gain, cutoff, q, maxgain; - + int gain, cutoff, q; + dsp->eq_enabled = enabled; - setting = &global_settings.eq_band0_cutoff; - maxgain = 0; + /* Adjust setting pointer to the band we actually want to change */ + setting = &global_settings.eq_band0_cutoff + (band * 3); + + cutoff = *setting++; + q = *setting++; + gain = *setting++; + + DEBUGF("cutoff %d, q %d, gain %d\n", cutoff, q, gain); + #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) /* set emac unit for dsp processing, and save old macsr, we're running in codec thread context at this point, so can't clobber it */ unsigned long old_macsr = coldfire_get_macsr(); coldfire_set_macsr(EMAC_FRACTIONAL | EMAC_SATURATE | EMAC_ROUND); #endif - - /* Iterate over each band and update the appropriate filter */ - for(i = 0; i < 5; i++) { - cutoff = *setting++; - q = *setting++; - gain = *setting++; - - /* Keep track of maxgain for the pre-amp */ - if (gain > maxgain) - maxgain = gain; - - if (gain == 0) { - eq_data.enabled[i] = 0; - } else { - if (i == 0) - eq_ls_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), - EQ_GAIN_USER2REAL(gain), eq_data.filters[0].coefs); - else if (i == 4) - eq_hs_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), - EQ_GAIN_USER2REAL(gain), eq_data.filters[4].coefs); - else - eq_pk_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), - EQ_GAIN_USER2REAL(gain), eq_data.filters[i].coefs); - eq_data.enabled[i] = 1; - } + if (gain == 0) { + eq_data.enabled[band] = 0; + } else { + if (band == 0) + eq_ls_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), + EQ_GAIN_USER2REAL(gain), eq_data.filters[band].coefs); + else if (band == 4) + eq_hs_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), + EQ_GAIN_USER2REAL(gain), eq_data.filters[band].coefs); + else + eq_pk_coefs(EQ_CUTOFF_USER2REAL(cutoff), EQ_Q_USER2REAL(q), + EQ_GAIN_USER2REAL(gain), eq_data.filters[band].coefs); + + eq_data.enabled[band] = 1; } #if defined(CPU_COLDFIRE) && !defined(SIMULATOR) diff --git a/apps/dsp.h b/apps/dsp.h index 7e3acacc32..c20def03b7 100644 --- a/apps/dsp.h +++ b/apps/dsp.h @@ -54,7 +54,7 @@ int dsp_stereo_mode(void); bool dsp_configure(int setting, void *value); void dsp_set_replaygain(bool always); void dsp_set_crossfeed(bool enable); -void dsp_eq_update_data(bool enabled); +void dsp_eq_update_data(bool enabled, int band); void sound_set_pitch(int r); int sound_get_pitch(void); #endif diff --git a/apps/eq_menu.c b/apps/eq_menu.c index 73c066705c..96935ca669 100644 --- a/apps/eq_menu.c +++ b/apps/eq_menu.c @@ -105,10 +105,15 @@ static bool eq_enabled(void) { + int i; + bool result = set_bool(str(LANG_EQUALIZER_ENABLED), &global_settings.eq_enabled); - dsp_eq_update_data(global_settings.eq_enabled); + /* Update all bands */ + for(i = 0; i < 5; i++) { + dsp_eq_update_data(global_settings.eq_enabled, i); + } return result; } @@ -136,7 +141,7 @@ static bool eq_set_band ## band ## _center(void) \ bool result = set_int(str(LANG_EQUALIZER_BAND_CENTER), "Hertz", UNIT_HERTZ, \ &global_settings.eq_band ## band ## _cutoff, NULL, \ EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \ - dsp_eq_update_data(global_settings.eq_enabled); \ + dsp_eq_update_data(global_settings.eq_enabled, band); \ return result; \ } @@ -146,7 +151,7 @@ static bool eq_set_band ## band ## _cutoff(void) \ bool result = set_int(str(LANG_EQUALIZER_BAND_CUTOFF), "Hertz", UNIT_HERTZ, \ &global_settings.eq_band ## band ## _cutoff, NULL, \ EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \ - dsp_eq_update_data(global_settings.eq_enabled); \ + dsp_eq_update_data(global_settings.eq_enabled, band); \ return result; \ } @@ -156,7 +161,7 @@ static bool eq_set_band ## band ## _q(void) \ bool result = set_int(str(LANG_EQUALIZER_BAND_Q), "Q", UNIT_INT, \ &global_settings.eq_band ## band ## _q, NULL, \ EQ_Q_STEP, EQ_Q_MIN, EQ_Q_MAX, eq_q_format); \ - dsp_eq_update_data(global_settings.eq_enabled); \ + dsp_eq_update_data(global_settings.eq_enabled, band); \ return result; \ } @@ -166,7 +171,7 @@ static bool eq_set_band ## band ## _gain(void) \ bool result = set_int("Band " #band, str(LANG_UNIT_DB), UNIT_DB, \ &global_settings.eq_band ## band ## _gain, NULL, \ EQ_GAIN_STEP, EQ_GAIN_MIN, EQ_GAIN_MAX, eq_gain_format); \ - dsp_eq_update_data(global_settings.eq_enabled); \ + dsp_eq_update_data(global_settings.eq_enabled, band); \ return result; \ } @@ -648,8 +653,10 @@ bool eq_menu_graphical(void) } /* Update the filter if the user changed something */ - if (has_changed) - dsp_eq_update_data(global_settings.eq_enabled); + if (has_changed) { + dsp_eq_update_data(global_settings.eq_enabled, current_band); + has_changed = false; + } } /* Reset screen settings */ diff --git a/apps/settings.c b/apps/settings.c index 0c62fd2201..4e25bebd95 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -924,6 +924,7 @@ void sound_settings_apply(void) void settings_apply(void) { char buf[64]; + int i; sound_settings_apply(); @@ -1052,7 +1053,11 @@ void settings_apply(void) audio_set_crossfade(global_settings.crossfade); dsp_set_replaygain(true); dsp_set_crossfeed(global_settings.crossfeed); - dsp_eq_update_data(global_settings.eq_enabled); + + /* Update all EQ bands */ + for(i = 0; i < 5; i++) { + dsp_eq_update_data(global_settings.eq_enabled, i); + } #endif #ifdef HAVE_SPDIF_POWER -- cgit v1.2.3