1
0
Fork 0
forked from len0rd/rockbox

Add precut setting for the equalizer and add some more comments to the eq menu code.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9298 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dan Everton 2006-03-27 21:20:35 +00:00
parent 7eb4d6c3b8
commit 91db368845
6 changed files with 154 additions and 82 deletions

View file

@ -192,6 +192,7 @@ struct dsp_config
bool new_gain; bool new_gain;
bool crossfeed_enabled; bool crossfeed_enabled;
bool eq_enabled; bool eq_enabled;
long eq_precut; /* Note that this is in S8.23 format. */
}; };
struct resample_data struct resample_data
@ -589,15 +590,31 @@ static void apply_crossfeed(int32_t* src[], int count)
} }
#endif #endif
/* Synchronize the EQ filters with the global settings */ /**
void dsp_eq_update_data(bool enabled, int band) * Use to enable the equalizer and set any pregain.
*
* @param enable true to enable the equalizer
* @param precut to apply in decibels (multiplied by 10)
*/
void dsp_eq_set(bool enable, unsigned int precut)
{
dsp->eq_enabled = enable;
/* Needs to be in s8.23 format amplitude for apply_gain() */
dsp->eq_precut = get_replaygain_int(precut * -10) >> 1;
}
/**
* Synchronize the equalizer filter coefficients with the global settings.
*
* @param band the equalizer band to synchronize
*/
void dsp_eq_update_filter_coefs(int band)
{ {
const int *setting; const int *setting;
long gain; long gain;
unsigned long cutoff, q; unsigned long cutoff, q;
dsp->eq_enabled = enabled;
/* Adjust setting pointer to the band we actually want to change */ /* Adjust setting pointer to the band we actually want to change */
setting = &global_settings.eq_band0_cutoff + (band * 3); setting = &global_settings.eq_band0_cutoff + (band * 3);
@ -661,19 +678,32 @@ static void eq_process(int32_t **x, unsigned num)
* Note that this must be called before the resampler. * Note that this must be called before the resampler.
*/ */
static void apply_gain(int32_t* _src[], int _count) static void apply_gain(int32_t* _src[], int _count)
{
struct dsp_config *my_dsp = dsp;
if (my_dsp->replaygain)
{ {
int32_t** src = _src; int32_t** src = _src;
int count = _count; int count = _count;
int32_t* s0 = src[0]; int32_t* s0 = src[0];
int32_t* s1 = src[1]; int32_t* s1 = src[1];
long gain = my_dsp->replaygain; long gain = 0;
int32_t s; int32_t s;
int i; int i;
int32_t *d; int32_t *d;
if (dsp->replaygain)
{
gain = dsp->replaygain;
}
if (dsp->eq_enabled)
{
gain += dsp->eq_precut; /* FIXME: This isn't that easy right? */
}
/* Don't bother if the gain is zero */
if (gain == 0)
{
return;
}
if (s0 != s1) if (s0 != s1)
{ {
d = &sample_buf[SAMPLE_BUF_SIZE / 2]; d = &sample_buf[SAMPLE_BUF_SIZE / 2];
@ -695,7 +725,6 @@ static void apply_gain(int32_t* _src[], int _count)
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
FRACMUL_8_LOOP(s, gain, s0, d); FRACMUL_8_LOOP(s, gain, s0, d);
} }
}
void channels_set(int value) void channels_set(int value)
{ {

View file

@ -54,7 +54,8 @@ int dsp_stereo_mode(void);
bool dsp_configure(int setting, void *value); bool dsp_configure(int setting, void *value);
void dsp_set_replaygain(bool always); void dsp_set_replaygain(bool always);
void dsp_set_crossfeed(bool enable); void dsp_set_crossfeed(bool enable);
void dsp_eq_update_data(bool enabled, int band); void dsp_eq_set(bool enable, unsigned int precut);
void dsp_eq_update_filter_coefs(int band);
void sound_set_pitch(int r); void sound_set_pitch(int r);
int sound_get_pitch(void); int sound_get_pitch(void);
void channels_set(int value); void channels_set(int value);

View file

@ -97,14 +97,14 @@
#endif #endif
/* Various user interface limits and sizes */
#define EQ_CUTOFF_MIN 20 #define EQ_CUTOFF_MIN 20
#define EQ_CUTOFF_MAX 22040 #define EQ_CUTOFF_MAX 22040
#define EQ_CUTOFF_STEP 10 #define EQ_CUTOFF_STEP 10
#define EQ_CUTOFF_FAST_STEP 100 #define EQ_CUTOFF_FAST_STEP 100
#define EQ_GAIN_MIN (-240) #define EQ_GAIN_MIN (-240)
#define EQ_GAIN_MAX 240 #define EQ_GAIN_MAX 240
#define EQ_GAIN_STEP 1 #define EQ_GAIN_STEP 5
#define EQ_GAIN_FAST_STEP 10 #define EQ_GAIN_FAST_STEP 10
#define EQ_Q_MIN 5 #define EQ_Q_MIN 5
#define EQ_Q_MAX 64 #define EQ_Q_MAX 64
@ -113,20 +113,9 @@
#define EQ_USER_DIVISOR 10 #define EQ_USER_DIVISOR 10
static bool eq_enabled(void) /*
{ * Utility functions
int i; */
bool result = set_bool(str(LANG_EQUALIZER_ENABLED),
&global_settings.eq_enabled);
/* Update all bands */
for(i = 0; i < 5; i++) {
dsp_eq_update_data(global_settings.eq_enabled, i);
}
return result;
}
static void eq_gain_format(char* buffer, int buffer_size, int value, const char* unit) static void eq_gain_format(char* buffer, int buffer_size, int value, const char* unit)
{ {
@ -141,6 +130,44 @@ static void eq_q_format(char* buffer, int buffer_size, int value, const char* un
snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit); snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
} }
static void eq_precut_format(char* buffer, int buffer_size, int value, const char* unit)
{
snprintf(buffer, buffer_size, "%s%d.%d %s", value == 0 ? " " : "-",
value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
}
/*
* Settings functions
*/
static bool eq_enabled(void)
{
int i;
bool result = set_bool(str(LANG_EQUALIZER_ENABLED),
&global_settings.eq_enabled);
dsp_eq_set(global_settings.eq_enabled, global_settings.eq_precut);
/* Update all bands */
for(i = 0; i < 5; i++) {
dsp_eq_update_filter_coefs(i);
}
return result;
}
static bool eq_precut(void)
{
bool result = set_int(str(LANG_EQUALIZER_PRECUT), str(LANG_UNIT_DB),
UNIT_DB, &global_settings.eq_precut, NULL, 5, 0, 240,
eq_precut_format);
dsp_eq_set(global_settings.eq_enabled, global_settings.eq_precut);
return result;
}
/* Possibly dodgy way of simplifying the code a bit. */ /* Possibly dodgy way of simplifying the code a bit. */
#define eq_make_gain_label(buf, bufsize, frequency) snprintf((buf), \ #define eq_make_gain_label(buf, bufsize, frequency) snprintf((buf), \
(bufsize), str(LANG_EQUALIZER_GAIN_ITEM), (frequency)) (bufsize), str(LANG_EQUALIZER_GAIN_ITEM), (frequency))
@ -148,20 +175,20 @@ static void eq_q_format(char* buffer, int buffer_size, int value, const char* un
#define eq_set_center(band) \ #define eq_set_center(band) \
static bool eq_set_band ## band ## _center(void) \ static bool eq_set_band ## band ## _center(void) \
{ \ { \
bool result = set_int(str(LANG_EQUALIZER_BAND_CENTER), "Hertz", UNIT_HERTZ, \ bool result = set_int(str(LANG_EQUALIZER_BAND_CENTER), "Hertz", \
&global_settings.eq_band ## band ## _cutoff, NULL, \ UNIT_HERTZ, &global_settings.eq_band ## band ## _cutoff, NULL, \
EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \ EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \
dsp_eq_update_data(global_settings.eq_enabled, band); \ dsp_eq_update_filter_coefs(band); \
return result; \ return result; \
} }
#define eq_set_cutoff(band) \ #define eq_set_cutoff(band) \
static bool eq_set_band ## band ## _cutoff(void) \ static bool eq_set_band ## band ## _cutoff(void) \
{ \ { \
bool result = set_int(str(LANG_EQUALIZER_BAND_CUTOFF), "Hertz", UNIT_HERTZ, \ bool result = set_int(str(LANG_EQUALIZER_BAND_CUTOFF), "Hertz", \
&global_settings.eq_band ## band ## _cutoff, NULL, \ UNIT_HERTZ, &global_settings.eq_band ## band ## _cutoff, NULL, \
EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \ EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \
dsp_eq_update_data(global_settings.eq_enabled, band); \ dsp_eq_update_filter_coefs(band); \
return result; \ return result; \
} }
@ -171,7 +198,7 @@ static bool eq_set_band ## band ## _q(void) \
bool result = set_int(str(LANG_EQUALIZER_BAND_Q), "Q", UNIT_INT, \ bool result = set_int(str(LANG_EQUALIZER_BAND_Q), "Q", UNIT_INT, \
&global_settings.eq_band ## band ## _q, NULL, \ &global_settings.eq_band ## band ## _q, NULL, \
EQ_Q_STEP, EQ_Q_MIN, EQ_Q_MAX, eq_q_format); \ EQ_Q_STEP, EQ_Q_MIN, EQ_Q_MAX, eq_q_format); \
dsp_eq_update_data(global_settings.eq_enabled, band); \ dsp_eq_update_filter_coefs(band); \
return result; \ return result; \
} }
@ -181,7 +208,7 @@ static bool eq_set_band ## band ## _gain(void) \
bool result = set_int("Band " #band, str(LANG_UNIT_DB), UNIT_DB, \ bool result = set_int("Band " #band, str(LANG_UNIT_DB), UNIT_DB, \
&global_settings.eq_band ## band ## _gain, NULL, \ &global_settings.eq_band ## band ## _gain, NULL, \
EQ_GAIN_STEP, EQ_GAIN_MIN, EQ_GAIN_MAX, eq_gain_format); \ EQ_GAIN_STEP, EQ_GAIN_MIN, EQ_GAIN_MAX, eq_gain_format); \
dsp_eq_update_data(global_settings.eq_enabled, band); \ dsp_eq_update_filter_coefs(band); \
return result; \ return result; \
} }
@ -666,7 +693,7 @@ bool eq_menu_graphical(void)
/* Update the filter if the user changed something */ /* Update the filter if the user changed something */
if (has_changed) { if (has_changed) {
dsp_eq_update_data(global_settings.eq_enabled, current_band); dsp_eq_update_filter_coefs(current_band);
has_changed = false; has_changed = false;
} }
} }
@ -706,6 +733,7 @@ static bool eq_save_preset(void)
/* TODO: Should we really do this? */ /* TODO: Should we really do this? */
fdprintf(fd, "eq enabled: on\r\n"); fdprintf(fd, "eq enabled: on\r\n");
fdprintf(fd, "eq precut: %d\r\n", global_settings.eq_precut);
setting = &global_settings.eq_band0_cutoff; setting = &global_settings.eq_band0_cutoff;
@ -737,6 +765,7 @@ bool eq_menu(void)
static const struct menu_item items[] = { static const struct menu_item items[] = {
{ ID2P(LANG_EQUALIZER_ENABLED), eq_enabled }, { ID2P(LANG_EQUALIZER_ENABLED), eq_enabled },
{ ID2P(LANG_EQUALIZER_GRAPHICAL), eq_menu_graphical }, { ID2P(LANG_EQUALIZER_GRAPHICAL), eq_menu_graphical },
{ ID2P(LANG_EQUALIZER_PRECUT), eq_precut },
{ ID2P(LANG_EQUALIZER_GAIN), eq_gain_menu }, { ID2P(LANG_EQUALIZER_GAIN), eq_gain_menu },
{ ID2P(LANG_EQUALIZER_ADVANCED), eq_advanced_menu }, { ID2P(LANG_EQUALIZER_ADVANCED), eq_advanced_menu },
{ ID2P(LANG_EQUALIZER_SAVE), eq_save_preset }, { ID2P(LANG_EQUALIZER_SAVE), eq_save_preset },

View file

@ -3880,3 +3880,10 @@ desc: in tag cache settings
eng: "Updating in background" eng: "Updating in background"
voice: "Updating in background" voice: "Updating in background"
new: new:
id: LANG_EQUALIZER_PRECUT
desc: in eq settings
eng: "Precut"
voice: "Pre-cut"
new:

View file

@ -570,6 +570,10 @@ static const struct bit_entry hd_bits[] =
{1, S_O(tagcache_ram), 0, "tagcache_ram", off_on }, {1, S_O(tagcache_ram), 0, "tagcache_ram", off_on },
#endif #endif
#if (CONFIG_CODEC == SWCODEC)
{8, S_O(eq_precut), 0, "eq precut", NULL },
#endif
/* If values are just added to the end, no need to bump the version. */ /* If values are just added to the end, no need to bump the version. */
/* new stuff to be added at the end */ /* new stuff to be added at the end */
@ -1126,9 +1130,10 @@ void settings_apply(void)
dsp_set_replaygain(true); dsp_set_replaygain(true);
dsp_set_crossfeed(global_settings.crossfeed); dsp_set_crossfeed(global_settings.crossfeed);
dsp_eq_set(global_settings.eq_enabled, global_settings.eq_precut);
/* Update all EQ bands */ /* Update all EQ bands */
for(i = 0; i < 5; i++) { for(i = 0; i < 5; i++) {
dsp_eq_update_data(global_settings.eq_enabled, i); dsp_eq_update_filter_coefs(i);
} }
#endif #endif

View file

@ -432,6 +432,7 @@ struct user_settings
#if CONFIG_CODEC == SWCODEC #if CONFIG_CODEC == SWCODEC
bool eq_enabled; /* Enable equalizer */ bool eq_enabled; /* Enable equalizer */
unsigned int eq_precut; /* dB */
/* Order is important here, must be cutoff, q, then gain for each band. /* Order is important here, must be cutoff, q, then gain for each band.
See dsp_eq_update_data in dsp.c for why. */ See dsp_eq_update_data in dsp.c for why. */