summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2012-04-30 16:27:01 -0400
committerMichael Sevakis <jethead71@rockbox.org>2012-04-30 22:47:37 +0200
commit57a20d2d638895fffe88a23cbd2960f1102b292f (patch)
treedf1943429ec040a18d854fa0a0091051e4200304
parenta32cbf33465367cd6fe36d636da8d03485e9d15d (diff)
downloadrockbox-57a20d2d638895fffe88a23cbd2960f1102b292f.tar.gz
rockbox-57a20d2d638895fffe88a23cbd2960f1102b292f.zip
Make DSP's replaygain independent of global_settings.
Moves replaygain definitions to lib/rbcodec/dsp/dsp_misc.h. Intermediate functions in misc.c handle any adjustment and calling the rbcodec APIs. Change-Id: I9f03561bca9aedd13760cf19c4e19aa3c68e7024 Reviewed-on: http://gerrit.rockbox.org/140 Reviewed-by: Michael Sevakis <jethead71@rockbox.org>
-rw-r--r--apps/gui/quickscreen.c4
-rw-r--r--apps/gui/skin_engine/skin_tokens.c13
-rw-r--r--apps/gui/skin_engine/skin_touchsupport.c4
-rw-r--r--apps/menus/playback_menu.c20
-rw-r--r--apps/misc.c39
-rw-r--r--apps/misc.h10
-rw-r--r--apps/settings.c2
-rw-r--r--apps/settings.h8
-rw-r--r--apps/settings_list.c10
-rw-r--r--lib/rbcodec/dsp/dsp_misc.c77
-rw-r--r--lib/rbcodec/dsp/dsp_misc.h20
11 files changed, 128 insertions, 79 deletions
diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c
index 6e50d61511..df295a8a95 100644
--- a/apps/gui/quickscreen.c
+++ b/apps/gui/quickscreen.c
@@ -419,9 +419,7 @@ bool quick_screen_quick(int button_enter)
419 if (oldshuffle != global_settings.playlist_shuffle 419 if (oldshuffle != global_settings.playlist_shuffle
420 && audio_status() & AUDIO_STATUS_PLAY) 420 && audio_status() & AUDIO_STATUS_PLAY)
421 { 421 {
422#if CONFIG_CODEC == SWCODEC 422 replaygain_update();
423 dsp_set_replaygain();
424#endif
425 if (global_settings.playlist_shuffle) 423 if (global_settings.playlist_shuffle)
426 playlist_randomise(NULL, current_tick, true); 424 playlist_randomise(NULL, current_tick, true);
427 else 425 else
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c
index 0f5deedcf9..578a729bb3 100644
--- a/apps/gui/skin_engine/skin_tokens.c
+++ b/apps/gui/skin_engine/skin_tokens.c
@@ -1420,25 +1420,22 @@ const char *get_token_value(struct gui_wps *gwps,
1420 1420
1421 case SKIN_TOKEN_REPLAYGAIN: 1421 case SKIN_TOKEN_REPLAYGAIN:
1422 { 1422 {
1423 int globtype = global_settings.replaygain_settings.type;
1423 int val; 1424 int val;
1424 1425
1425 if (global_settings.replaygain_type == REPLAYGAIN_OFF) 1426
1427 if (globtype == REPLAYGAIN_OFF)
1426 val = 1; /* off */ 1428 val = 1; /* off */
1427 else 1429 else
1428 { 1430 {
1429 int type; 1431 int type = id3_get_replaygain_mode(id3);
1430 if (LIKELY(id3))
1431 type = get_replaygain_mode(id3->track_gain != 0,
1432 id3->album_gain != 0);
1433 else
1434 type = -1;
1435 1432
1436 if (type < 0) 1433 if (type < 0)
1437 val = 6; /* no tag */ 1434 val = 6; /* no tag */
1438 else 1435 else
1439 val = type + 2; 1436 val = type + 2;
1440 1437
1441 if (global_settings.replaygain_type == REPLAYGAIN_SHUFFLE) 1438 if (globtype == REPLAYGAIN_SHUFFLE)
1442 val += 2; 1439 val += 2;
1443 } 1440 }
1444 1441
diff --git a/apps/gui/skin_engine/skin_touchsupport.c b/apps/gui/skin_engine/skin_touchsupport.c
index a52a88439e..34f616b9a3 100644
--- a/apps/gui/skin_engine/skin_touchsupport.c
+++ b/apps/gui/skin_engine/skin_touchsupport.c
@@ -266,9 +266,7 @@ int skin_get_touchaction(struct wps_data *data, int* edge_offset,
266 { 266 {
267 global_settings.playlist_shuffle = 267 global_settings.playlist_shuffle =
268 !global_settings.playlist_shuffle; 268 !global_settings.playlist_shuffle;
269#if CONFIG_CODEC == SWCODEC 269 replaygain_update();
270 dsp_set_replaygain();
271#endif
272 if (global_settings.playlist_shuffle) 270 if (global_settings.playlist_shuffle)
273 playlist_randomise(NULL, current_tick, true); 271 playlist_randomise(NULL, current_tick, true);
274 else 272 else
diff --git a/apps/menus/playback_menu.c b/apps/menus/playback_menu.c
index d1d999587b..6beda93991 100644
--- a/apps/menus/playback_menu.c
+++ b/apps/menus/playback_menu.c
@@ -34,6 +34,7 @@
34#include "scrobbler.h" 34#include "scrobbler.h"
35#include "audio.h" 35#include "audio.h"
36#include "cuesheet.h" 36#include "cuesheet.h"
37#include "misc.h"
37#if CONFIG_CODEC == SWCODEC 38#if CONFIG_CODEC == SWCODEC
38#include "playback.h" 39#include "playback.h"
39#endif 40#endif
@@ -116,14 +117,20 @@ static int replaygain_callback(int action,const struct menu_item_ex *this_item)
116 switch (action) 117 switch (action)
117 { 118 {
118 case ACTION_EXIT_MENUITEM: /* on exit */ 119 case ACTION_EXIT_MENUITEM: /* on exit */
119 dsp_set_replaygain(); 120 replaygain_update();
120 break; 121 break;
121 } 122 }
122 return action; 123 return action;
123} 124}
124MENUITEM_SETTING(replaygain_noclip, &global_settings.replaygain_noclip ,replaygain_callback); 125MENUITEM_SETTING(replaygain_noclip,
125MENUITEM_SETTING(replaygain_type, &global_settings.replaygain_type ,replaygain_callback); 126 &global_settings.replaygain_settings.noclip,
126MENUITEM_SETTING(replaygain_preamp, &global_settings.replaygain_preamp ,replaygain_callback); 127 replaygain_callback);
128MENUITEM_SETTING(replaygain_type,
129 &global_settings.replaygain_settings.type,
130 replaygain_callback);
131MENUITEM_SETTING(replaygain_preamp,
132 &global_settings.replaygain_settings.preamp,
133 replaygain_callback);
127MAKE_MENU(replaygain_settings_menu,ID2P(LANG_REPLAYGAIN),0, Icon_NOICON, 134MAKE_MENU(replaygain_settings_menu,ID2P(LANG_REPLAYGAIN),0, Icon_NOICON,
128 &replaygain_type, &replaygain_noclip, &replaygain_preamp); 135 &replaygain_type, &replaygain_noclip, &replaygain_preamp);
129 136
@@ -244,9 +251,8 @@ static int playback_callback(int action,const struct menu_item_ex *this_item)
244 if (old_shuffle == global_settings.playlist_shuffle) 251 if (old_shuffle == global_settings.playlist_shuffle)
245 break; 252 break;
246 253
247#if CONFIG_CODEC == SWCODEC 254 replaygain_update();
248 dsp_set_replaygain(); 255
249#endif
250 if (global_settings.playlist_shuffle) 256 if (global_settings.playlist_shuffle)
251 { 257 {
252 playlist_randomise(NULL, current_tick, true); 258 playlist_randomise(NULL, current_tick, true);
diff --git a/apps/misc.c b/apps/misc.c
index 3cb314fc51..3bee0772a6 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -953,6 +953,45 @@ void keyclick_click(bool rawbutton, int action)
953#endif 953#endif
954 } 954 }
955} 955}
956
957/* Return the ReplayGain mode adjusted by other relevant settings */
958static int replaygain_setting_mode(int type)
959{
960 switch (type)
961 {
962 case REPLAYGAIN_SHUFFLE:
963 type = global_settings.playlist_shuffle ?
964 REPLAYGAIN_TRACK : REPLAYGAIN_ALBUM;
965 case REPLAYGAIN_ALBUM:
966 case REPLAYGAIN_TRACK:
967 case REPLAYGAIN_OFF:
968 default:
969 break;
970 }
971
972 return type;
973}
974
975/* Return the ReplayGain mode adjusted for display purposes */
976int id3_get_replaygain_mode(const struct mp3entry *id3)
977{
978 if (!id3)
979 return -1;
980
981 int type = global_settings.replaygain_settings.type;
982 type = replaygain_setting_mode(type);
983
984 return (type != REPLAYGAIN_TRACK && id3->album_gain != 0) ?
985 REPLAYGAIN_ALBUM : (id3->track_gain != 0 ? REPLAYGAIN_TRACK : -1);
986}
987
988/* Update DSP's replaygain from global settings */
989void replaygain_update(void)
990{
991 struct replaygain_settings settings = global_settings.replaygain_settings;
992 settings.type = replaygain_setting_mode(settings.type);
993 dsp_replaygain_set_settings(&settings);
994}
956#endif /* CONFIG_CODEC == SWCODEC */ 995#endif /* CONFIG_CODEC == SWCODEC */
957 996
958#endif /* !defined(__PCTOOL__) */ 997#endif /* !defined(__PCTOOL__) */
diff --git a/apps/misc.h b/apps/misc.h
index 8d0953985d..7ca8d75930 100644
--- a/apps/misc.h
+++ b/apps/misc.h
@@ -149,6 +149,16 @@ typedef bool (*keyclick_callback)(int action, void* data);
149void keyclick_set_callback(keyclick_callback cb, void* data); 149void keyclick_set_callback(keyclick_callback cb, void* data);
150/* Produce keyclick based upon button and global settings */ 150/* Produce keyclick based upon button and global settings */
151void keyclick_click(bool rawbutton, int action); 151void keyclick_click(bool rawbutton, int action);
152
153/* Return current ReplayGain mode a file should have (REPLAYGAIN_TRACK or
154 * REPLAYGAIN_ALBUM) if ReplayGain processing is enabled, or -1 if no
155 * information present.
156 */
157struct mp3entry;
158int id3_get_replaygain_mode(const struct mp3entry *id3);
159void replaygain_update(void);
160#else
161static inline void replaygain_update(void) {}
152#endif /* CONFIG_CODEC == SWCODEC */ 162#endif /* CONFIG_CODEC == SWCODEC */
153 163
154void push_current_activity(enum current_activity screen); 164void push_current_activity(enum current_activity screen);
diff --git a/apps/settings.c b/apps/settings.c
index d481bc5124..e885beb302 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -978,7 +978,7 @@ void settings_apply(bool read_disk)
978#ifdef HAVE_CROSSFADE 978#ifdef HAVE_CROSSFADE
979 audio_set_crossfade(global_settings.crossfade); 979 audio_set_crossfade(global_settings.crossfade);
980#endif 980#endif
981 dsp_set_replaygain(); 981 replaygain_update();
982 dsp_crossfeed_enable(global_settings.crossfeed); 982 dsp_crossfeed_enable(global_settings.crossfeed);
983 dsp_set_crossfeed_direct_gain(global_settings.crossfeed_direct_gain); 983 dsp_set_crossfeed_direct_gain(global_settings.crossfeed_direct_gain);
984 dsp_set_crossfeed_cross_params(global_settings.crossfeed_cross_gain, 984 dsp_set_crossfeed_cross_params(global_settings.crossfeed_cross_gain,
diff --git a/apps/settings.h b/apps/settings.h
index 071346864c..34cc75b116 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -117,9 +117,6 @@ enum { SORT_INTERPRET_AS_DIGIT, SORT_INTERPRET_AS_NUMBER };
117/* recursive dir insert options */ 117/* recursive dir insert options */
118enum { RECURSE_OFF, RECURSE_ON, RECURSE_ASK }; 118enum { RECURSE_OFF, RECURSE_ON, RECURSE_ASK };
119 119
120/* replaygain types */
121enum { REPLAYGAIN_TRACK = 0, REPLAYGAIN_ALBUM, REPLAYGAIN_SHUFFLE, REPLAYGAIN_OFF };
122
123/* show path types */ 120/* show path types */
124enum { SHOW_PATH_OFF = 0, SHOW_PATH_CURRENT, SHOW_PATH_FULL }; 121enum { SHOW_PATH_OFF = 0, SHOW_PATH_CURRENT, SHOW_PATH_FULL };
125 122
@@ -325,10 +322,7 @@ struct user_settings
325#endif 322#endif
326 323
327 /* Replaygain */ 324 /* Replaygain */
328 bool replaygain_noclip; /* scale to prevent clips */ 325 struct replaygain_settings replaygain_settings;
329 int replaygain_type; /* 0=track gain, 1=album gain, 2=track gain if
330 shuffle is on, album gain otherwise, 4=off */
331 int replaygain_preamp; /* scale replaygained tracks by this */
332 326
333 /* Crossfeed */ 327 /* Crossfeed */
334 bool crossfeed; /* enable crossfeed */ 328 bool crossfeed; /* enable crossfeed */
diff --git a/apps/settings_list.c b/apps/settings_list.c
index 5f4addea2f..c332b47655 100644
--- a/apps/settings_list.c
+++ b/apps/settings_list.c
@@ -1353,13 +1353,13 @@ const struct settings_list settings[] = {
1353 1353
1354#if CONFIG_CODEC == SWCODEC 1354#if CONFIG_CODEC == SWCODEC
1355 /* replay gain */ 1355 /* replay gain */
1356 CHOICE_SETTING(F_SOUNDSETTING, replaygain_type, LANG_REPLAYGAIN_MODE, 1356 CHOICE_SETTING(F_SOUNDSETTING, replaygain_settings.type,
1357 REPLAYGAIN_SHUFFLE, "replaygain type", 1357 LANG_REPLAYGAIN_MODE, REPLAYGAIN_SHUFFLE, "replaygain type",
1358 "track,album,track shuffle,off", NULL, 4, ID2P(LANG_TRACK_GAIN), 1358 "track,album,track shuffle,off", NULL, 4, ID2P(LANG_TRACK_GAIN),
1359 ID2P(LANG_ALBUM_GAIN), ID2P(LANG_SHUFFLE_GAIN), ID2P(LANG_OFF)), 1359 ID2P(LANG_ALBUM_GAIN), ID2P(LANG_SHUFFLE_GAIN), ID2P(LANG_OFF)),
1360 OFFON_SETTING(F_SOUNDSETTING, replaygain_noclip, LANG_REPLAYGAIN_NOCLIP, 1360 OFFON_SETTING(F_SOUNDSETTING, replaygain_settings.noclip,
1361 false, "replaygain noclip", NULL), 1361 LANG_REPLAYGAIN_NOCLIP, false, "replaygain noclip", NULL),
1362 INT_SETTING_NOWRAP(F_SOUNDSETTING, replaygain_preamp, 1362 INT_SETTING_NOWRAP(F_SOUNDSETTING, replaygain_settings.preamp,
1363 LANG_REPLAYGAIN_PREAMP, 0, "replaygain preamp", 1363 LANG_REPLAYGAIN_PREAMP, 0, "replaygain preamp",
1364 UNIT_DB, -120, 120, 5, db_format, get_dec_talkid, NULL), 1364 UNIT_DB, -120, 120, 5, db_format, get_dec_talkid, NULL),
1365 1365
diff --git a/lib/rbcodec/dsp/dsp_misc.c b/lib/rbcodec/dsp/dsp_misc.c
index a98a7e429e..e8bbeb6f5e 100644
--- a/lib/rbcodec/dsp/dsp_misc.c
+++ b/lib/rbcodec/dsp/dsp_misc.c
@@ -23,12 +23,16 @@
23 ****************************************************************************/ 23 ****************************************************************************/
24#include "config.h" 24#include "config.h"
25#include "sound.h" 25#include "sound.h"
26#include "settings.h"
27#include "fixedpoint.h" 26#include "fixedpoint.h"
28#include "replaygain.h" 27#include "replaygain.h"
29#include "dsp_proc_entry.h" 28#include "dsp_proc_entry.h"
30#include "dsp_sample_io.h" 29#include "dsp_sample_io.h"
31#include "dsp_misc.h" 30#include "dsp_misc.h"
31#include "pga.h"
32#include "channel_mode.h"
33#ifdef HAVE_SW_TONE_CONTROLS
34#include "tone_controls.h"
35#endif
32#include <string.h> 36#include <string.h>
33 37
34/** Firmware callback interface **/ 38/** Firmware callback interface **/
@@ -77,43 +81,37 @@ int dsp_callback(int msg, intptr_t param)
77} 81}
78 82
79/** Replaygain settings **/ 83/** Replaygain settings **/
80static struct dsp_replay_gains current_rpgains; 84static struct replaygain_settings current_settings;
85static struct dsp_replay_gains current_gains;
81 86
82static void dsp_replaygain_update(const struct dsp_replay_gains *gains) 87static void dsp_replaygain_update(
88 const struct replaygain_settings *settings,
89 const struct dsp_replay_gains *gains)
83{ 90{
84 if (gains == NULL) 91 if (settings != &current_settings)
85 { 92 current_settings = *settings; /* Stash settings */
86 /* Use defaults */ 93
87 memset(&current_rpgains, 0, sizeof (current_rpgains)); 94 if (gains != &current_gains)
88 gains = &current_rpgains; 95 current_gains = *gains; /* Stash gains */
89 }
90 else
91 {
92 current_rpgains = *gains; /* Stash settings */
93 }
94 96
95 int32_t gain = PGA_UNITY; 97 int32_t gain = PGA_UNITY;
96 98
97 if (global_settings.replaygain_type != REPLAYGAIN_OFF || 99 if (settings->type != REPLAYGAIN_OFF || settings->noclip)
98 global_settings.replaygain_noclip)
99 { 100 {
100 bool track_mode = 101 bool track_mode = settings->type == REPLAYGAIN_TRACK &&
101 get_replaygain_mode(gains->track_gain != 0, 102 gains->track_gain != 0;
102 gains->album_gain != 0) == REPLAYGAIN_TRACK;
103 103
104 int32_t peak = (track_mode || gains->album_peak == 0) ? 104 int32_t peak = (track_mode || gains->album_peak == 0) ?
105 gains->track_peak : gains->album_peak; 105 gains->track_peak : gains->album_peak;
106 106
107 if (global_settings.replaygain_type != REPLAYGAIN_OFF) 107 if (settings->type != REPLAYGAIN_OFF)
108 { 108 {
109 gain = (track_mode || gains->album_gain == 0) ? 109 gain = (track_mode || gains->album_gain == 0) ?
110 gains->track_gain : gains->album_gain; 110 gains->track_gain : gains->album_gain;
111 111
112 if (global_settings.replaygain_preamp) 112 if (settings->preamp != 0)
113 { 113 {
114 int32_t preamp = get_replaygain_int( 114 int32_t preamp = get_replaygain_int(settings->preamp * 10);
115 global_settings.replaygain_preamp * 10);
116
117 gain = fp_mul(gain, preamp, 24); 115 gain = fp_mul(gain, preamp, 24);
118 } 116 }
119 } 117 }
@@ -124,7 +122,7 @@ static void dsp_replaygain_update(const struct dsp_replay_gains *gains)
124 gain = PGA_UNITY; 122 gain = PGA_UNITY;
125 } 123 }
126 124
127 if (global_settings.replaygain_noclip && peak != 0 && 125 if (settings->noclip && peak != 0 &&
128 fp_mul(gain, peak, 24) >= PGA_UNITY) 126 fp_mul(gain, peak, 24) >= PGA_UNITY)
129 { 127 {
130 gain = fp_div(PGA_UNITY, peak, 24); 128 gain = fp_div(PGA_UNITY, peak, 24);
@@ -135,28 +133,21 @@ static void dsp_replaygain_update(const struct dsp_replay_gains *gains)
135 pga_enable_gain(PGA_REPLAYGAIN, gain != PGA_UNITY); 133 pga_enable_gain(PGA_REPLAYGAIN, gain != PGA_UNITY);
136} 134}
137 135
138int get_replaygain_mode(bool have_track_gain, bool have_album_gain) 136void dsp_replaygain_set_settings(const struct replaygain_settings *settings)
139{ 137{
140 bool track = false; 138 dsp_replaygain_update(settings, &current_gains);
139}
141 140
142 switch (global_settings.replaygain_type) 141void dsp_replaygain_set_gains(const struct dsp_replay_gains *gains)
142{
143 if (gains == NULL)
143 { 144 {
144 case REPLAYGAIN_TRACK: 145 /* Set defaults */
145 track = true; 146 gains = &current_gains;
146 break; 147 memset((void *)gains, 0, sizeof (*gains));
147
148 case REPLAYGAIN_SHUFFLE:
149 track = global_settings.playlist_shuffle;
150 break;
151 } 148 }
152 149
153 return (!track && have_album_gain) ? 150 dsp_replaygain_update(&current_settings, gains);
154 REPLAYGAIN_ALBUM : (have_track_gain ? REPLAYGAIN_TRACK : -1);
155}
156
157void dsp_set_replaygain(void)
158{
159 dsp_replaygain_update(&current_rpgains);
160} 151}
161 152
162 153
@@ -217,7 +208,7 @@ static intptr_t misc_handler_configure(struct dsp_proc_entry *this,
217#endif 208#endif
218 value = (intptr_t)NULL; /* Default gains */ 209 value = (intptr_t)NULL; /* Default gains */
219 case REPLAYGAIN_SET_GAINS: 210 case REPLAYGAIN_SET_GAINS:
220 dsp_replaygain_update((void *)value); 211 dsp_replaygain_set_gains((void *)value);
221 break; 212 break;
222 213
223#ifdef HAVE_PITCHSCREEN 214#ifdef HAVE_PITCHSCREEN
diff --git a/lib/rbcodec/dsp/dsp_misc.h b/lib/rbcodec/dsp/dsp_misc.h
index 74587cbb0e..e0035457f5 100644
--- a/lib/rbcodec/dsp/dsp_misc.h
+++ b/lib/rbcodec/dsp/dsp_misc.h
@@ -26,6 +26,22 @@
26/* Set the tri-pdf dithered output */ 26/* Set the tri-pdf dithered output */
27void dsp_dither_enable(bool enable); /* in dsp_sample_output.c */ 27void dsp_dither_enable(bool enable); /* in dsp_sample_output.c */
28 28
29enum replaygain_types
30{
31 REPLAYGAIN_TRACK = 0,
32 REPLAYGAIN_ALBUM,
33 REPLAYGAIN_SHUFFLE,
34 REPLAYGAIN_OFF
35};
36
37struct replaygain_settings
38{
39 bool noclip; /* scale to prevent clips */
40 int type; /* 0=track gain, 1=album gain, 2=track gain if
41 shuffle is on, album gain otherwise, 4=off */
42 int preamp; /* scale replaygained tracks by this */
43};
44
29/* Structure used with REPLAYGAIN_SET_GAINS message */ 45/* Structure used with REPLAYGAIN_SET_GAINS message */
30#define REPLAYGAIN_SET_GAINS (DSP_PROC_SETTING+DSP_PROC_MISC_HANDLER) 46#define REPLAYGAIN_SET_GAINS (DSP_PROC_SETTING+DSP_PROC_MISC_HANDLER)
31struct dsp_replay_gains 47struct dsp_replay_gains
@@ -36,8 +52,8 @@ struct dsp_replay_gains
36 long album_peak; 52 long album_peak;
37}; 53};
38 54
39int get_replaygain_mode(bool have_track_gain, bool have_album_gain); 55void dsp_replaygain_set_settings(const struct replaygain_settings *settings);
40void dsp_set_replaygain(void); 56void dsp_replaygain_set_gains(const struct dsp_replay_gains *gains);
41 57
42#ifdef HAVE_PITCHSCREEN 58#ifdef HAVE_PITCHSCREEN
43void sound_set_pitch(int32_t ratio); 59void sound_set_pitch(int32_t ratio);