From 26be8d09f17b575c96de7b496bead3123f3a30df Mon Sep 17 00:00:00 2001 From: Sean Bartell Date: Sun, 21 Aug 2011 17:18:09 -0400 Subject: [PATCH 1/6] rbcodec refactoring: dsp_set_eq_coefs --- apps/menus/eq_menu.c | 65 +++++++++++++++++++++++++------------------------ apps/settings.c | 4 ++- apps/settings.h | 31 ++--------------------- apps/settings_list.c | 30 +++++++++++----------- lib/rbcodec/dsp/dsp.c | 14 ++-------- lib/rbcodec/dsp/dsp.h | 3 +- 6 files changed, 59 insertions(+), 88 deletions(-) diff --git a/apps/menus/eq_menu.c b/apps/menus/eq_menu.c index be1dd42..2da3219 100644 --- a/apps/menus/eq_menu.c +++ b/apps/menus/eq_menu.c @@ -75,7 +75,9 @@ static void eq_apply(void) dsp_set_eq_precut(global_settings.eq_precut); /* Update all bands */ for(i = 0; i < 5; i++) { - dsp_set_eq_coefs(i); + dsp_set_eq_coefs(i, global_settings.eq_band_cutoff[i], + global_settings.eq_band_q[i], + global_settings.eq_band_gain[i]); } } @@ -97,23 +99,23 @@ static int eq_setting_callback(int action, const struct menu_item_ex *this_item) MENUITEM_SETTING(eq_enable, &global_settings.eq_enabled, eq_setting_callback); MENUITEM_SETTING(eq_precut, &global_settings.eq_precut, eq_setting_callback); -MENUITEM_SETTING(cutoff_0, &global_settings.eq_band0_cutoff, eq_setting_callback); -MENUITEM_SETTING(cutoff_1, &global_settings.eq_band1_cutoff, eq_setting_callback); -MENUITEM_SETTING(cutoff_2, &global_settings.eq_band2_cutoff, eq_setting_callback); -MENUITEM_SETTING(cutoff_3, &global_settings.eq_band3_cutoff, eq_setting_callback); -MENUITEM_SETTING(cutoff_4, &global_settings.eq_band4_cutoff, eq_setting_callback); +MENUITEM_SETTING(cutoff_0, &global_settings.eq_band_cutoff[0], eq_setting_callback); +MENUITEM_SETTING(cutoff_1, &global_settings.eq_band_cutoff[1], eq_setting_callback); +MENUITEM_SETTING(cutoff_2, &global_settings.eq_band_cutoff[2], eq_setting_callback); +MENUITEM_SETTING(cutoff_3, &global_settings.eq_band_cutoff[3], eq_setting_callback); +MENUITEM_SETTING(cutoff_4, &global_settings.eq_band_cutoff[4], eq_setting_callback); -MENUITEM_SETTING(q_0, &global_settings.eq_band0_q, eq_setting_callback); -MENUITEM_SETTING(q_1, &global_settings.eq_band1_q, eq_setting_callback); -MENUITEM_SETTING(q_2, &global_settings.eq_band2_q, eq_setting_callback); -MENUITEM_SETTING(q_3, &global_settings.eq_band3_q, eq_setting_callback); -MENUITEM_SETTING(q_4, &global_settings.eq_band4_q, eq_setting_callback); +MENUITEM_SETTING(q_0, &global_settings.eq_band_q[0], eq_setting_callback); +MENUITEM_SETTING(q_1, &global_settings.eq_band_q[1], eq_setting_callback); +MENUITEM_SETTING(q_2, &global_settings.eq_band_q[2], eq_setting_callback); +MENUITEM_SETTING(q_3, &global_settings.eq_band_q[3], eq_setting_callback); +MENUITEM_SETTING(q_4, &global_settings.eq_band_q[4], eq_setting_callback); -MENUITEM_SETTING(gain_0, &global_settings.eq_band0_gain, eq_setting_callback); -MENUITEM_SETTING(gain_1, &global_settings.eq_band1_gain, eq_setting_callback); -MENUITEM_SETTING(gain_2, &global_settings.eq_band2_gain, eq_setting_callback); -MENUITEM_SETTING(gain_3, &global_settings.eq_band3_gain, eq_setting_callback); -MENUITEM_SETTING(gain_4, &global_settings.eq_band4_gain, eq_setting_callback); +MENUITEM_SETTING(gain_0, &global_settings.eq_band_gain[0], eq_setting_callback); +MENUITEM_SETTING(gain_1, &global_settings.eq_band_gain[1], eq_setting_callback); +MENUITEM_SETTING(gain_2, &global_settings.eq_band_gain[2], eq_setting_callback); +MENUITEM_SETTING(gain_3, &global_settings.eq_band_gain[3], eq_setting_callback); +MENUITEM_SETTING(gain_4, &global_settings.eq_band_gain[4], eq_setting_callback); static char* gainitem_get_name(int selected_item, void * data, char *buffer) { @@ -145,23 +147,23 @@ static int do_option(void * param) MENUITEM_FUNCTION_DYNTEXT(gain_item_0, MENU_FUNC_USEPARAM, do_option, (void*)&gain_0, gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band0_cutoff, NULL, Icon_NOICON); + &global_settings.eq_band_cutoff[0], NULL, Icon_NOICON); MENUITEM_FUNCTION_DYNTEXT(gain_item_1, MENU_FUNC_USEPARAM, do_option, (void*)&gain_1, gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band1_cutoff, NULL, Icon_NOICON); + &global_settings.eq_band_cutoff[1], NULL, Icon_NOICON); MENUITEM_FUNCTION_DYNTEXT(gain_item_2, MENU_FUNC_USEPARAM, do_option, (void*)&gain_2, gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band2_cutoff, NULL, Icon_NOICON); + &global_settings.eq_band_cutoff[2], NULL, Icon_NOICON); MENUITEM_FUNCTION_DYNTEXT(gain_item_3, MENU_FUNC_USEPARAM, do_option, (void*)&gain_3, gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band3_cutoff, NULL, Icon_NOICON); + &global_settings.eq_band_cutoff[3], NULL, Icon_NOICON); MENUITEM_FUNCTION_DYNTEXT(gain_item_4, MENU_FUNC_USEPARAM, do_option, (void*)&gain_4, gainitem_get_name, gainitem_speak_item, - &global_settings.eq_band4_cutoff, NULL, Icon_NOICON); + &global_settings.eq_band_cutoff[4], NULL, Icon_NOICON); MAKE_MENU(gain_menu, ID2P(LANG_EQUALIZER_GAIN), NULL, Icon_NOICON, &gain_item_0, &gain_item_1, &gain_item_2, &gain_item_3, &gain_item_4); @@ -351,13 +353,12 @@ static void draw_eq_sliders(struct screen * screen, int x, int y, { int i, gain, q, cutoff; int height = y; - int *setting = &global_settings.eq_band0_cutoff; start_item = MIN(start_item, 5-nb_eq_sliders); for (i=0; i<5; i++) { - cutoff = *setting++; - q = *setting++; - gain = *setting++; + cutoff = global_settings.eq_band_cutoff[i]; + q = global_settings.eq_band_q[i]; + gain = global_settings.eq_band_gain[i]; if (i == start_item + nb_eq_sliders) break; @@ -429,8 +430,7 @@ bool eq_menu_graphical(void) /* Set pointer to the band data currently editable */ if (mode == GAIN) { /* gain */ - setting = &global_settings.eq_band0_gain; - setting += current_band * 3; + setting = &global_settings.eq_band_gain[current_band]; step = EQ_GAIN_STEP; fast_step = EQ_GAIN_FAST_STEP; @@ -443,8 +443,7 @@ bool eq_menu_graphical(void) screens[i].putsxy(0, 0, buf); } else if (mode == CUTOFF) { /* cutoff */ - setting = &global_settings.eq_band0_cutoff; - setting += current_band * 3; + setting = &global_settings.eq_band_cutoff[current_band]; step = EQ_CUTOFF_STEP; fast_step = EQ_CUTOFF_FAST_STEP; @@ -457,8 +456,7 @@ bool eq_menu_graphical(void) screens[i].putsxy(0, 0, buf); } else { /* Q */ - setting = &global_settings.eq_band0_q; - setting += current_band * 3; + setting = &global_settings.eq_band_q[current_band]; step = EQ_Q_STEP; fast_step = EQ_Q_FAST_STEP; @@ -560,7 +558,10 @@ bool eq_menu_graphical(void) /* Update the filter if the user changed something */ if (has_changed) { - dsp_set_eq_coefs(current_band); + dsp_set_eq_coefs(current_band, + global_settings.eq_band_cutoff[current_band], + global_settings.eq_band_q[current_band], + global_settings.eq_band_gain[current_band]); has_changed = false; } } diff --git a/apps/settings.c b/apps/settings.c index 623bc5b..9071648 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -974,7 +974,9 @@ void settings_apply(bool read_disk) dsp_set_eq(global_settings.eq_enabled); dsp_set_eq_precut(global_settings.eq_precut); for(i = 0; i < 5; i++) { - dsp_set_eq_coefs(i); + dsp_set_eq_coefs(i, global_settings.eq_band_cutoff[i], + global_settings.eq_band_q[i], + global_settings.eq_band_gain[i]); } dsp_dither_enable(global_settings.dithering_enabled); diff --git a/apps/settings.h b/apps/settings.h index 05965b3..6819d27 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -336,34 +336,9 @@ struct user_settings /* EQ */ bool eq_enabled; /* Enable equalizer */ unsigned int eq_precut; /* dB */ - - /* Order is important here, must be cutoff, q, then gain for each band. - See dsp_set_eq_coefs in dsp.c for why. */ - - /* Band 0 settings */ - int eq_band0_cutoff; /* Hz */ - int eq_band0_q; - int eq_band0_gain; /* +/- dB */ - - /* Band 1 settings */ - int eq_band1_cutoff; /* Hz */ - int eq_band1_q; - int eq_band1_gain; /* +/- dB */ - - /* Band 2 settings */ - int eq_band2_cutoff; /* Hz */ - int eq_band2_q; - int eq_band2_gain; /* +/- dB */ - - /* Band 3 settings */ - int eq_band3_cutoff; /* Hz */ - int eq_band3_q; - int eq_band3_gain; /* +/- dB */ - - /* Band 4 settings */ - int eq_band4_cutoff; /* Hz */ - int eq_band4_q; - int eq_band4_gain; /* +/- dB */ + int eq_band_cutoff[5]; /* Hz */ + int eq_band_q[5]; + int eq_band_gain[5]; /* +/- dB */ /* Misc. swcodec */ int beep; /* system beep volume when changing tracks etc. */ diff --git a/apps/settings_list.c b/apps/settings_list.c index 292749b..901c0e9 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -1359,51 +1359,51 @@ const struct settings_list settings[] = { "eq precut", UNIT_DB, 0, 240, 5, eq_precut_format, get_precut_talkid, dsp_set_eq_precut), /* 0..32768 Hz */ - INT_SETTING_NOWRAP(F_EQSETTING, eq_band0_cutoff, LANG_EQUALIZER_BAND_CUTOFF, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_cutoff[0], LANG_EQUALIZER_BAND_CUTOFF, 60, "eq band 0 cutoff", UNIT_HERTZ, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, EQ_CUTOFF_STEP, NULL, NULL, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band1_cutoff, LANG_EQUALIZER_BAND_CENTER, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_cutoff[1], LANG_EQUALIZER_BAND_CENTER, 200, "eq band 1 cutoff", UNIT_HERTZ, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, EQ_CUTOFF_STEP, NULL, NULL, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band2_cutoff, LANG_EQUALIZER_BAND_CENTER, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_cutoff[2], LANG_EQUALIZER_BAND_CENTER, 800, "eq band 2 cutoff", UNIT_HERTZ, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, EQ_CUTOFF_STEP, NULL, NULL, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band3_cutoff, LANG_EQUALIZER_BAND_CENTER, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_cutoff[3], LANG_EQUALIZER_BAND_CENTER, 4000, "eq band 3 cutoff", UNIT_HERTZ, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, EQ_CUTOFF_STEP, NULL, NULL, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band4_cutoff, LANG_EQUALIZER_BAND_CUTOFF, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_cutoff[4], LANG_EQUALIZER_BAND_CUTOFF, 12000, "eq band 4 cutoff", UNIT_HERTZ, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, EQ_CUTOFF_STEP, NULL, NULL, NULL), /* 0..64 (or 0.0 to 6.4) */ - INT_SETTING_NOWRAP(F_EQSETTING, eq_band0_q, LANG_EQUALIZER_BAND_Q, 7, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_q[0], LANG_EQUALIZER_BAND_Q, 7, "eq band 0 q", UNIT_INT, EQ_Q_MIN, EQ_Q_MAX, EQ_Q_STEP, eq_q_format, get_dec_talkid, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band1_q, LANG_EQUALIZER_BAND_Q, 10, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_q[1], LANG_EQUALIZER_BAND_Q, 10, "eq band 1 q", UNIT_INT, EQ_Q_MIN, EQ_Q_MAX, EQ_Q_STEP, eq_q_format, get_dec_talkid, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band2_q, LANG_EQUALIZER_BAND_Q, 10, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_q[2], LANG_EQUALIZER_BAND_Q, 10, "eq band 2 q", UNIT_INT, EQ_Q_MIN, EQ_Q_MAX, EQ_Q_STEP, eq_q_format, get_dec_talkid, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band3_q, LANG_EQUALIZER_BAND_Q, 10, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_q[3], LANG_EQUALIZER_BAND_Q, 10, "eq band 3 q", UNIT_INT, EQ_Q_MIN, EQ_Q_MAX, EQ_Q_STEP, eq_q_format, get_dec_talkid, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band4_q, LANG_EQUALIZER_BAND_Q, 7, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_q[4], LANG_EQUALIZER_BAND_Q, 7, "eq band 4 q", UNIT_INT, EQ_Q_MIN, EQ_Q_MAX, EQ_Q_STEP, eq_q_format, get_dec_talkid, NULL), /* -240..240 (or -24db to +24db) */ - INT_SETTING_NOWRAP(F_EQSETTING, eq_band0_gain, LANG_GAIN, 0, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_gain[0], LANG_GAIN, 0, "eq band 0 gain", UNIT_DB, EQ_GAIN_MIN, EQ_GAIN_MAX, EQ_GAIN_STEP, db_format, get_dec_talkid, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band1_gain, LANG_GAIN, 0, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_gain[1], LANG_GAIN, 0, "eq band 1 gain", UNIT_DB, EQ_GAIN_MIN, EQ_GAIN_MAX, EQ_GAIN_STEP, db_format, get_dec_talkid, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band2_gain, LANG_GAIN, 0, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_gain[2], LANG_GAIN, 0, "eq band 2 gain", UNIT_DB, EQ_GAIN_MIN, EQ_GAIN_MAX, EQ_GAIN_STEP, db_format, get_dec_talkid, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band3_gain, LANG_GAIN, 0, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_gain[3], LANG_GAIN, 0, "eq band 3 gain", UNIT_DB, EQ_GAIN_MIN, EQ_GAIN_MAX, EQ_GAIN_STEP, db_format, get_dec_talkid, NULL), - INT_SETTING_NOWRAP(F_EQSETTING, eq_band4_gain, LANG_GAIN, 0, + INT_SETTING_NOWRAP(F_EQSETTING, eq_band_gain[4], LANG_GAIN, 0, "eq band 4 gain", UNIT_DB, EQ_GAIN_MIN, EQ_GAIN_MAX, EQ_GAIN_STEP, db_format, get_dec_talkid, NULL), diff --git a/lib/rbcodec/dsp/dsp.c b/lib/rbcodec/dsp/dsp.c index 3cff191..dc64648 100644 --- a/lib/rbcodec/dsp/dsp.c +++ b/lib/rbcodec/dsp/dsp.c @@ -948,19 +948,11 @@ void dsp_set_eq_precut(int precut) * * @param band the equalizer band to synchronize */ -void dsp_set_eq_coefs(int band) +void dsp_set_eq_coefs(int band, unsigned long cutoff, unsigned long q, + long gain) { - const int *setting; - long gain; - unsigned long cutoff, q; - - /* Adjust setting pointer to the band we actually want to change */ - setting = &global_settings.eq_band0_cutoff + (band * 3); - /* Convert user settings to format required by coef generator functions */ - cutoff = 0xffffffff / NATIVE_FREQUENCY * (*setting++); - q = *setting++; - gain = *setting++; + cutoff = 0xffffffff / NATIVE_FREQUENCY * cutoff; if (q == 0) q = 1; diff --git a/lib/rbcodec/dsp/dsp.h b/lib/rbcodec/dsp/dsp.h index 092a99f..60a8b06 100644 --- a/lib/rbcodec/dsp/dsp.h +++ b/lib/rbcodec/dsp/dsp.h @@ -73,7 +73,8 @@ void dsp_set_crossfeed_cross_params(long lf_gain, long hf_gain, long cutoff); void dsp_set_eq(bool enable); void dsp_set_eq_precut(int precut); -void dsp_set_eq_coefs(int band); +void dsp_set_eq_coefs(int band, unsigned long cutoff, unsigned long q, + long gain); void dsp_dither_enable(bool enable); void dsp_timestretch_enable(bool enable); bool dsp_timestretch_available(void); -- 1.7.6