summaryrefslogtreecommitdiff
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
parent31dfabfa254235516dde148f16fa2ac4d522944d (diff)
downloadrockbox-f0bec023d9ff45cede09274dff12f015f0830a38.tar.gz
rockbox-f0bec023d9ff45cede09274dff12f015f0830a38.zip
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>
-rw-r--r--apps/gui/option_select.c6
-rw-r--r--apps/lang/chinese-simp.lang14
-rw-r--r--apps/lang/chinese-trad.lang14
-rw-r--r--apps/lang/english.lang14
-rw-r--r--apps/menus/sound_menu.c41
-rw-r--r--apps/misc.c3
-rw-r--r--apps/settings.h1
-rw-r--r--apps/settings_list.c32
-rw-r--r--manual/configure_rockbox/sound_settings.tex6
9 files changed, 128 insertions, 3 deletions
diff --git a/apps/gui/option_select.c b/apps/gui/option_select.c
index d42d08188a..0452467994 100644
--- a/apps/gui/option_select.c
+++ b/apps/gui/option_select.c
@@ -345,7 +345,8 @@ static int selection_to_val(const struct settings_list *setting, int selection)
345 int setting_id = setting->sound_setting->setting; 345 int setting_id = setting->sound_setting->setting;
346#ifndef ASCENDING_INT_SETTINGS 346#ifndef ASCENDING_INT_SETTINGS
347 step = sound_steps(setting_id); 347 step = sound_steps(setting_id);
348 max = sound_max(setting_id); 348 max = (setting_id == SOUND_VOLUME) ?
349 global_settings.volume_limit : sound_max(setting_id);
349 /* min = sound_min(setting_id); */ 350 /* min = sound_min(setting_id); */
350#else 351#else
351 step = -sound_steps(setting_id); 352 step = -sound_steps(setting_id);
@@ -429,7 +430,8 @@ static void val_to_selection(const struct settings_list *setting, int oldvalue,
429 int setting_id = setting->sound_setting->setting; 430 int setting_id = setting->sound_setting->setting;
430 int steps = sound_steps(setting_id); 431 int steps = sound_steps(setting_id);
431 int min = sound_min(setting_id); 432 int min = sound_min(setting_id);
432 int max = sound_max(setting_id); 433 int max = (setting_id == SOUND_VOLUME) ?
434 global_settings.volume_limit : sound_max(setting_id);
433 *nb_items = (max-min)/steps + 1; 435 *nb_items = (max-min)/steps + 1;
434#ifndef ASCENDING_INT_SETTINGS 436#ifndef ASCENDING_INT_SETTINGS
435 *selected = (max - oldvalue) / steps; 437 *selected = (max - oldvalue) / steps;
diff --git a/apps/lang/chinese-simp.lang b/apps/lang/chinese-simp.lang
index 4c3dd3c18f..e90ec510d2 100644
--- a/apps/lang/chinese-simp.lang
+++ b/apps/lang/chinese-simp.lang
@@ -13039,3 +13039,17 @@
13039 *: "扫描媒体时扫描指定文件夹" 13039 *: "扫描媒体时扫描指定文件夹"
13040 </voice> 13040 </voice>
13041</phrase> 13041</phrase>
13042<phrase>
13043 id: LANG_VOLUME_LIMIT
13044 desc: in sound_settings
13045 user: core
13046 <source>
13047 *: "Maximum Volume Limit"
13048 </source>
13049 <dest>
13050 *: "音量限制"
13051 </dest>
13052 <voice>
13053 *: "音量限制"
13054 </voice>
13055</phrase>
diff --git a/apps/lang/chinese-trad.lang b/apps/lang/chinese-trad.lang
index f8dc5c38d6..0d0b68d1e5 100644
--- a/apps/lang/chinese-trad.lang
+++ b/apps/lang/chinese-trad.lang
@@ -11240,3 +11240,17 @@
11240 *: "檔案大小" 11240 *: "檔案大小"
11241 </voice> 11241 </voice>
11242</phrase> 11242</phrase>
11243<phrase>
11244 id: LANG_VOLUME_LIMIT
11245 desc: in sound_settings
11246 user: core
11247 <source>
11248 *: "Maximum Volume Limit"
11249 </source>
11250 <dest>
11251 *: "音量限制"
11252 </dest>
11253 <voice>
11254 *: "音量限制"
11255 </voice>
11256</phrase>
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index dcad532f7a..d7f4476be6 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -13178,3 +13178,17 @@
13178 *: "Slow" 13178 *: "Slow"
13179 </voice> 13179 </voice>
13180</phrase> 13180</phrase>
13181<phrase>
13182 id: LANG_VOLUME_LIMIT
13183 desc: in sound_settings
13184 user: core
13185 <source>
13186 *: "Maximum Volume Limit"
13187 </source>
13188 <dest>
13189 *: "Maximum Volume Limit"
13190 </dest>
13191 <voice>
13192 *: "Maximum Volume Limit"
13193 </voice>
13194</phrase>
diff --git a/apps/menus/sound_menu.c b/apps/menus/sound_menu.c
index 28cc257193..8913266a5f 100644
--- a/apps/menus/sound_menu.c
+++ b/apps/menus/sound_menu.c
@@ -34,10 +34,50 @@
34#include "menu_common.h" 34#include "menu_common.h"
35#include "splash.h" 35#include "splash.h"
36#include "kernel.h" 36#include "kernel.h"
37#include "talk.h"
38#include "option_select.h"
39#include "misc.h"
40
41static int32_t get_dec_talkid(int value, int unit)
42{
43 return TALK_ID_DECIMAL(value, 1, unit);
44}
45
46static int volume_limit_callback(int action,const struct menu_item_ex *this_item)
47{
48 (void)this_item;
49
50 static struct int_setting volume_limit_int_setting;
51 volume_limit_int_setting.option_callback = NULL;
52 volume_limit_int_setting.unit = UNIT_DB;
53 volume_limit_int_setting.min = sound_min(SOUND_VOLUME);
54 volume_limit_int_setting.max = sound_max(SOUND_VOLUME);
55 volume_limit_int_setting.step = sound_steps(SOUND_VOLUME);
56 volume_limit_int_setting.formatter = NULL;
57 volume_limit_int_setting.get_talk_id = get_dec_talkid;
58
59 struct settings_list setting;
60 setting.flags = F_BANFROMQS|F_INT_SETTING|F_T_INT|F_NO_WRAP;
61 setting.lang_id = LANG_VOLUME_LIMIT;
62 setting.default_val.int_ = sound_max(SOUND_VOLUME);
63 setting.int_setting = &volume_limit_int_setting;
64
65 switch (action)
66 {
67 case ACTION_ENTER_MENUITEM:
68 setting.setting = &global_settings.volume_limit;
69 option_screen(&setting, NULL, false, ID2P(LANG_VOLUME_LIMIT));
70 case ACTION_EXIT_MENUITEM: /* on exit */
71 setvol();
72 break;
73 }
74 return action;
75}
37 76
38/***********************************/ 77/***********************************/
39/* SOUND MENU */ 78/* SOUND MENU */
40MENUITEM_SETTING(volume, &global_settings.volume, NULL); 79MENUITEM_SETTING(volume, &global_settings.volume, NULL);
80MENUITEM_SETTING(volume_limit, &global_settings.volume_limit, volume_limit_callback);
41#ifdef AUDIOHW_HAVE_BASS 81#ifdef AUDIOHW_HAVE_BASS
42MENUITEM_SETTING(bass, &global_settings.bass, 82MENUITEM_SETTING(bass, &global_settings.bass,
43#ifdef HAVE_SW_TONE_CONTROLS 83#ifdef HAVE_SW_TONE_CONTROLS
@@ -171,6 +211,7 @@ static int timestretch_callback(int action,const struct menu_item_ex *this_item)
171 211
172MAKE_MENU(sound_settings, ID2P(LANG_SOUND_SETTINGS), NULL, Icon_Audio, 212MAKE_MENU(sound_settings, ID2P(LANG_SOUND_SETTINGS), NULL, Icon_Audio,
173 &volume 213 &volume
214 ,&volume_limit
174#ifdef AUDIOHW_HAVE_BASS 215#ifdef AUDIOHW_HAVE_BASS
175 ,&bass 216 ,&bass
176#endif 217#endif
diff --git a/apps/misc.c b/apps/misc.c
index e746c432e6..fa33bb5c4f 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -793,6 +793,9 @@ void setvol(void)
793 global_settings.volume = min_vol; 793 global_settings.volume = min_vol;
794 if (global_settings.volume > max_vol) 794 if (global_settings.volume > max_vol)
795 global_settings.volume = max_vol; 795 global_settings.volume = max_vol;
796 if (global_settings.volume > global_settings.volume_limit)
797 global_settings.volume = global_settings.volume_limit;
798
796 sound_set_volume(global_settings.volume); 799 sound_set_volume(global_settings.volume);
797 global_status.last_volume_change = current_tick; 800 global_status.last_volume_change = current_tick;
798 settings_save(); 801 settings_save();
diff --git a/apps/settings.h b/apps/settings.h
index 087ff0cb45..62ae038385 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -828,6 +828,7 @@ struct user_settings
828#ifdef HAVE_PLAY_FREQ 828#ifdef HAVE_PLAY_FREQ
829 int play_frequency; /* core audio output frequency selection */ 829 int play_frequency; /* core audio output frequency selection */
830#endif 830#endif
831 int volume_limit; /* maximum volume limit */
831}; 832};
832 833
833/** global variables **/ 834/** global variables **/
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)
661 return get_hotkey_lang_id(value); 661 return get_hotkey_lang_id(value);
662} 662}
663#endif /* HAVE_HOTKEY */ 663#endif /* HAVE_HOTKEY */
664
665/* volume limiter */
666static void volume_limit_load_from_cfg(void* var, char*value)
667{
668 *(int*)var = atoi(value);
669}
670static char* volume_limit_write_to_cfg(void* setting, char*buf, int buf_len)
671{
672 int current = *(int*)setting;
673 snprintf(buf, buf_len, "%d", current);
674 return buf;
675}
676static bool volume_limit_is_changed(void* setting, void* defaultval)
677{
678 int current = *(int*)setting;
679
680 if ((int*)defaultval == NULL)
681 *(int*)defaultval = sound_max(SOUND_VOLUME);
682 return (current != sound_max(SOUND_VOLUME));
683}
684static void volume_limit_set_default(void* setting, void* defaultval)
685{
686 (void)defaultval;
687 *(int*)setting = sound_max(SOUND_VOLUME);
688}
689
664const struct settings_list settings[] = { 690const struct settings_list settings[] = {
665 /* sound settings */ 691 /* sound settings */
666 SOUND_SETTING(F_NO_WRAP,volume, LANG_VOLUME, "volume", SOUND_VOLUME), 692 SOUND_SETTING(F_NO_WRAP, volume, LANG_VOLUME, "volume", SOUND_VOLUME),
693 CUSTOM_SETTING(F_NO_WRAP, volume_limit, LANG_VOLUME_LIMIT,
694 NULL, "volume limit",
695 volume_limit_load_from_cfg, volume_limit_write_to_cfg,
696 volume_limit_is_changed, volume_limit_set_default),
667 SOUND_SETTING(0, balance, LANG_BALANCE, "balance", SOUND_BALANCE), 697 SOUND_SETTING(0, balance, LANG_BALANCE, "balance", SOUND_BALANCE),
668/* Tone controls */ 698/* Tone controls */
669#ifdef AUDIOHW_HAVE_BASS 699#ifdef AUDIOHW_HAVE_BASS
diff --git a/manual/configure_rockbox/sound_settings.tex b/manual/configure_rockbox/sound_settings.tex
index d2da07b983..7022315c83 100644
--- a/manual/configure_rockbox/sound_settings.tex
+++ b/manual/configure_rockbox/sound_settings.tex
@@ -48,6 +48,12 @@ change to customise your listening experience.
48 \opt{iaudiom3,iaudiom5,iaudiox5,sansa,sansaAMS,iriverh10,iriverh10_5gb,vibe500,fuzeplus}{% 48 \opt{iaudiom3,iaudiom5,iaudiox5,sansa,sansaAMS,iriverh10,iriverh10_5gb,vibe500,fuzeplus}{%
49 The minimum setting is -24~dB and the maximum is 24~dB.} 49 The minimum setting is -24~dB and the maximum is 24~dB.}
50 50
51\section{\label{ref:volume_limit}Volume Limit}
52 This setting adjusts the maximum volume of your music. The setting is by
53 default set to the maximum volume which equals to no limit. To set a volume
54 limit, select a volume from the list and the maximum volume will be limited to
55 the selected value all over the system.
56
51\opt{ipodvideo}{ 57\opt{ipodvideo}{
52\section{Bass Cutoff} 58\section{Bass Cutoff}
53 This setting controls the frequency below which the bass adjustment applies. 59 This setting controls the frequency below which the bass adjustment applies.