summaryrefslogtreecommitdiff
path: root/apps/eq_menu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/eq_menu.c')
-rw-r--r--apps/eq_menu.c71
1 files changed, 50 insertions, 21 deletions
diff --git a/apps/eq_menu.c b/apps/eq_menu.c
index 82639a54da..61d38f473c 100644
--- a/apps/eq_menu.c
+++ b/apps/eq_menu.c
@@ -97,14 +97,14 @@
97 97
98#endif 98#endif
99 99
100 100/* Various user interface limits and sizes */
101#define EQ_CUTOFF_MIN 20 101#define EQ_CUTOFF_MIN 20
102#define EQ_CUTOFF_MAX 22040 102#define EQ_CUTOFF_MAX 22040
103#define EQ_CUTOFF_STEP 10 103#define EQ_CUTOFF_STEP 10
104#define EQ_CUTOFF_FAST_STEP 100 104#define EQ_CUTOFF_FAST_STEP 100
105#define EQ_GAIN_MIN (-240) 105#define EQ_GAIN_MIN (-240)
106#define EQ_GAIN_MAX 240 106#define EQ_GAIN_MAX 240
107#define EQ_GAIN_STEP 1 107#define EQ_GAIN_STEP 5
108#define EQ_GAIN_FAST_STEP 10 108#define EQ_GAIN_FAST_STEP 10
109#define EQ_Q_MIN 5 109#define EQ_Q_MIN 5
110#define EQ_Q_MAX 64 110#define EQ_Q_MAX 64
@@ -113,32 +113,59 @@
113 113
114#define EQ_USER_DIVISOR 10 114#define EQ_USER_DIVISOR 10
115 115
116/*
117 * Utility functions
118 */
119
120static void eq_gain_format(char* buffer, int buffer_size, int value, const char* unit)
121{
122 int v = abs(value);
123
124 snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "",
125 v / EQ_USER_DIVISOR, v % EQ_USER_DIVISOR, unit);
126}
127
128static void eq_q_format(char* buffer, int buffer_size, int value, const char* unit)
129{
130 snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
131}
132
133static void eq_precut_format(char* buffer, int buffer_size, int value, const char* unit)
134{
135 snprintf(buffer, buffer_size, "%s%d.%d %s", value == 0 ? " " : "-",
136 value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
137}
138
139/*
140 * Settings functions
141 */
142
116static bool eq_enabled(void) 143static bool eq_enabled(void)
117{ 144{
118 int i; 145 int i;
119 146
120 bool result = set_bool(str(LANG_EQUALIZER_ENABLED), 147 bool result = set_bool(str(LANG_EQUALIZER_ENABLED),
121 &global_settings.eq_enabled); 148 &global_settings.eq_enabled);
122 149
150 dsp_eq_set(global_settings.eq_enabled, global_settings.eq_precut);
151
123 /* Update all bands */ 152 /* Update all bands */
124 for(i = 0; i < 5; i++) { 153 for(i = 0; i < 5; i++) {
125 dsp_eq_update_data(global_settings.eq_enabled, i); 154 dsp_eq_update_filter_coefs(i);
126 } 155 }
127 156
128 return result; 157 return result;
129} 158}
130 159
131static void eq_gain_format(char* buffer, int buffer_size, int value, const char* unit) 160static bool eq_precut(void)
132{ 161{
133 int v = abs(value); 162 bool result = set_int(str(LANG_EQUALIZER_PRECUT), str(LANG_UNIT_DB),
163 UNIT_DB, &global_settings.eq_precut, NULL, 5, 0, 240,
164 eq_precut_format);
134 165
135 snprintf(buffer, buffer_size, "%s%d.%d %s", value < 0 ? "-" : "", 166 dsp_eq_set(global_settings.eq_enabled, global_settings.eq_precut);
136 v / EQ_USER_DIVISOR, v % EQ_USER_DIVISOR, unit);
137}
138 167
139static void eq_q_format(char* buffer, int buffer_size, int value, const char* unit) 168 return result;
140{
141 snprintf(buffer, buffer_size, "%d.%d %s", value / EQ_USER_DIVISOR, value % EQ_USER_DIVISOR, unit);
142} 169}
143 170
144/* Possibly dodgy way of simplifying the code a bit. */ 171/* Possibly dodgy way of simplifying the code a bit. */
@@ -148,20 +175,20 @@ static void eq_q_format(char* buffer, int buffer_size, int value, const char* un
148#define eq_set_center(band) \ 175#define eq_set_center(band) \
149static bool eq_set_band ## band ## _center(void) \ 176static bool eq_set_band ## band ## _center(void) \
150{ \ 177{ \
151 bool result = set_int(str(LANG_EQUALIZER_BAND_CENTER), "Hertz", UNIT_HERTZ, \ 178 bool result = set_int(str(LANG_EQUALIZER_BAND_CENTER), "Hertz", \
152 &global_settings.eq_band ## band ## _cutoff, NULL, \ 179 UNIT_HERTZ, &global_settings.eq_band ## band ## _cutoff, NULL, \
153 EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \ 180 EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \
154 dsp_eq_update_data(global_settings.eq_enabled, band); \ 181 dsp_eq_update_filter_coefs(band); \
155 return result; \ 182 return result; \
156} 183}
157 184
158#define eq_set_cutoff(band) \ 185#define eq_set_cutoff(band) \
159static bool eq_set_band ## band ## _cutoff(void) \ 186static bool eq_set_band ## band ## _cutoff(void) \
160{ \ 187{ \
161 bool result = set_int(str(LANG_EQUALIZER_BAND_CUTOFF), "Hertz", UNIT_HERTZ, \ 188 bool result = set_int(str(LANG_EQUALIZER_BAND_CUTOFF), "Hertz", \
162 &global_settings.eq_band ## band ## _cutoff, NULL, \ 189 UNIT_HERTZ, &global_settings.eq_band ## band ## _cutoff, NULL, \
163 EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \ 190 EQ_CUTOFF_STEP, EQ_CUTOFF_MIN, EQ_CUTOFF_MAX, NULL); \
164 dsp_eq_update_data(global_settings.eq_enabled, band); \ 191 dsp_eq_update_filter_coefs(band); \
165 return result; \ 192 return result; \
166} 193}
167 194
@@ -171,7 +198,7 @@ static bool eq_set_band ## band ## _q(void) \
171 bool result = set_int(str(LANG_EQUALIZER_BAND_Q), "Q", UNIT_INT, \ 198 bool result = set_int(str(LANG_EQUALIZER_BAND_Q), "Q", UNIT_INT, \
172 &global_settings.eq_band ## band ## _q, NULL, \ 199 &global_settings.eq_band ## band ## _q, NULL, \
173 EQ_Q_STEP, EQ_Q_MIN, EQ_Q_MAX, eq_q_format); \ 200 EQ_Q_STEP, EQ_Q_MIN, EQ_Q_MAX, eq_q_format); \
174 dsp_eq_update_data(global_settings.eq_enabled, band); \ 201 dsp_eq_update_filter_coefs(band); \
175 return result; \ 202 return result; \
176} 203}
177 204
@@ -181,7 +208,7 @@ static bool eq_set_band ## band ## _gain(void) \
181 bool result = set_int("Band " #band, str(LANG_UNIT_DB), UNIT_DB, \ 208 bool result = set_int("Band " #band, str(LANG_UNIT_DB), UNIT_DB, \
182 &global_settings.eq_band ## band ## _gain, NULL, \ 209 &global_settings.eq_band ## band ## _gain, NULL, \
183 EQ_GAIN_STEP, EQ_GAIN_MIN, EQ_GAIN_MAX, eq_gain_format); \ 210 EQ_GAIN_STEP, EQ_GAIN_MIN, EQ_GAIN_MAX, eq_gain_format); \
184 dsp_eq_update_data(global_settings.eq_enabled, band); \ 211 dsp_eq_update_filter_coefs(band); \
185 return result; \ 212 return result; \
186} 213}
187 214
@@ -666,7 +693,7 @@ bool eq_menu_graphical(void)
666 693
667 /* Update the filter if the user changed something */ 694 /* Update the filter if the user changed something */
668 if (has_changed) { 695 if (has_changed) {
669 dsp_eq_update_data(global_settings.eq_enabled, current_band); 696 dsp_eq_update_filter_coefs(current_band);
670 has_changed = false; 697 has_changed = false;
671 } 698 }
672 } 699 }
@@ -706,6 +733,7 @@ static bool eq_save_preset(void)
706 733
707 /* TODO: Should we really do this? */ 734 /* TODO: Should we really do this? */
708 fdprintf(fd, "eq enabled: on\r\n"); 735 fdprintf(fd, "eq enabled: on\r\n");
736 fdprintf(fd, "eq precut: %d\r\n", global_settings.eq_precut);
709 737
710 setting = &global_settings.eq_band0_cutoff; 738 setting = &global_settings.eq_band0_cutoff;
711 739
@@ -737,6 +765,7 @@ bool eq_menu(void)
737 static const struct menu_item items[] = { 765 static const struct menu_item items[] = {
738 { ID2P(LANG_EQUALIZER_ENABLED), eq_enabled }, 766 { ID2P(LANG_EQUALIZER_ENABLED), eq_enabled },
739 { ID2P(LANG_EQUALIZER_GRAPHICAL), eq_menu_graphical }, 767 { ID2P(LANG_EQUALIZER_GRAPHICAL), eq_menu_graphical },
768 { ID2P(LANG_EQUALIZER_PRECUT), eq_precut },
740 { ID2P(LANG_EQUALIZER_GAIN), eq_gain_menu }, 769 { ID2P(LANG_EQUALIZER_GAIN), eq_gain_menu },
741 { ID2P(LANG_EQUALIZER_ADVANCED), eq_advanced_menu }, 770 { ID2P(LANG_EQUALIZER_ADVANCED), eq_advanced_menu },
742 { ID2P(LANG_EQUALIZER_SAVE), eq_save_preset }, 771 { ID2P(LANG_EQUALIZER_SAVE), eq_save_preset },