summaryrefslogtreecommitdiff
path: root/apps/settings_list.c
diff options
context:
space:
mode:
authorPurlingNayuki <cyq.yzfl@gmail.com>2013-12-21 21:33:54 +0800
committerJonathan Gordon <rockbox@jdgordon.info>2014-01-13 11:32:03 +0100
commitf0bec023d9ff45cede09274dff12f015f0830a38 (patch)
tree88af20d2941735f441491762daa4139d1bbbbed0 /apps/settings_list.c
parent31dfabfa254235516dde148f16fa2ac4d522944d (diff)
Implement volume limiter feature
Add a "volume limit" parameter to the configuration file. The maximum value of volume setting in sound menu will be limited to the same as volume limit. Also each time when setvol() is excuted, Rockbox will check if the global_settings.volume value larger than global_settings.volume_limit. If larger, take the value of volume_limit instead. The volume_limit argument shares the same maximum and minimum values with volume argument, while taking the maximum volume as its default value. Change-Id: I8ca9bc6ea6e617b48fc346aae5f2a0a1d259ae36 Reviewed-on: http://gerrit.rockbox.org/697 Reviewed-by: Jonathan Gordon <rockbox@jdgordon.info>
Diffstat (limited to 'apps/settings_list.c')
-rw-r--r--apps/settings_list.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/apps/settings_list.c b/apps/settings_list.c
index bd2bfce36f..01bc5c53f4 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -661,9 +661,39 @@ static int32_t hotkey_getlang(int value, int unit)
return get_hotkey_lang_id(value);
}
#endif /* HAVE_HOTKEY */
+
+/* volume limiter */
+static void volume_limit_load_from_cfg(void* var, char*value)
+{
+ *(int*)var = atoi(value);
+}
+static char* volume_limit_write_to_cfg(void* setting, char*buf, int buf_len)
+{
+ int current = *(int*)setting;
+ snprintf(buf, buf_len, "%d", current);
+ return buf;
+}
+static bool volume_limit_is_changed(void* setting, void* defaultval)
+{
+ int current = *(int*)setting;
+
+ if ((int*)defaultval == NULL)
+ *(int*)defaultval = sound_max(SOUND_VOLUME);
+ return (current != sound_max(SOUND_VOLUME));
+}
+static void volume_limit_set_default(void* setting, void* defaultval)
+{
+ (void)defaultval;
+ *(int*)setting = sound_max(SOUND_VOLUME);
+}
+
const struct settings_list settings[] = {
/* sound settings */
- SOUND_SETTING(F_NO_WRAP,volume, LANG_VOLUME, "volume", SOUND_VOLUME),
+ SOUND_SETTING(F_NO_WRAP, volume, LANG_VOLUME, "volume", SOUND_VOLUME),
+ CUSTOM_SETTING(F_NO_WRAP, volume_limit, LANG_VOLUME_LIMIT,
+ NULL, "volume limit",
+ volume_limit_load_from_cfg, volume_limit_write_to_cfg,
+ volume_limit_is_changed, volume_limit_set_default),
SOUND_SETTING(0, balance, LANG_BALANCE, "balance", SOUND_BALANCE),
/* Tone controls */
#ifdef AUDIOHW_HAVE_BASS