summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/gui/gwps-common.c7
-rw-r--r--apps/gui/statusbar.c39
-rw-r--r--apps/gui/statusbar.h2
-rw-r--r--apps/lang/english.lang30
-rw-r--r--apps/settings.c17
-rw-r--r--apps/settings.h3
-rw-r--r--apps/sound_menu.c18
-rw-r--r--firmware/export/sound.h15
-rw-r--r--firmware/sound.c216
9 files changed, 87 insertions, 260 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 7590f493e8..307036eda4 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -569,7 +569,10 @@ static char* get_tag(struct wps_data* wps_data,
569 case 'v': /* volume */ 569 case 'v': /* volume */
570 *flags |= WPS_REFRESH_DYNAMIC; 570 *flags |= WPS_REFRESH_DYNAMIC;
571 snprintf(buf, buf_size, "%d", global_settings.volume); 571 snprintf(buf, buf_size, "%d", global_settings.volume);
572 *intval = global_settings.volume / 10 + 1; 572 *intval = 10 * (global_settings.volume
573 - sound_min(SOUND_VOLUME))
574 / (sound_max(SOUND_VOLUME)
575 - sound_min(SOUND_VOLUME)) + 1;
573 return buf; 576 return buf;
574 577
575 } 578 }
@@ -1892,7 +1895,7 @@ bool update_onvol_change(struct gui_wps * gwps)
1892 gui_wps_refresh(gwps, 0, WPS_REFRESH_NON_STATIC); 1895 gui_wps_refresh(gwps, 0, WPS_REFRESH_NON_STATIC);
1893 1896
1894#ifdef HAVE_LCD_CHARCELLS 1897#ifdef HAVE_LCD_CHARCELLS
1895 gui_splash(gwps->display,0, false, "Vol: %d %% ", 1898 gui_splash(gwps->display,0, false, "Vol: %d dB ",
1896 sound_val2phys(SOUND_VOLUME, global_settings.volume)); 1899 sound_val2phys(SOUND_VOLUME, global_settings.volume));
1897 return true; 1900 return true;
1898#endif 1901#endif
diff --git a/apps/gui/statusbar.c b/apps/gui/statusbar.c
index fda54a610e..56d1647d9b 100644
--- a/apps/gui/statusbar.c
+++ b/apps/gui/statusbar.c
@@ -102,7 +102,7 @@ struct gui_syncstatusbar statusbars;
102 102
103void gui_statusbar_init(struct gui_statusbar * bar) 103void gui_statusbar_init(struct gui_statusbar * bar)
104{ 104{
105 bar->last_volume = -1; /* -1 means "first update ever" */ 105 bar->last_volume = -1000; /* -1000 means "first update ever" */
106 bar->battery_icon_switch_tick = 0; 106 bar->battery_icon_switch_tick = 0;
107#ifdef HAVE_CHARGING 107#ifdef HAVE_CHARGING
108 bar->battery_charge_step = 0; 108 bar->battery_charge_step = 0;
@@ -117,6 +117,7 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
117#endif /* CONFIG_RTC */ 117#endif /* CONFIG_RTC */
118 118
119#ifdef HAVE_LCD_CHARCELLS 119#ifdef HAVE_LCD_CHARCELLS
120 int vol;
120 (void)force_redraw; /* players always "redraw" */ 121 (void)force_redraw; /* players always "redraw" */
121#endif /* HAVE_LCD_CHARCELLS */ 122#endif /* HAVE_LCD_CHARCELLS */
122 123
@@ -277,12 +278,14 @@ void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
277 display->icon(ICON_BATTERY_2, bar->info.battlevel > 50); 278 display->icon(ICON_BATTERY_2, bar->info.battlevel > 50);
278 display->icon(ICON_BATTERY_3, bar->info.battlevel > 75); 279 display->icon(ICON_BATTERY_3, bar->info.battlevel > 75);
279 280
281 vol = 100 * (bar->info.volume - sound_min(SOUND_VOLUME))
282 / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME));
280 display->icon(ICON_VOLUME, true); 283 display->icon(ICON_VOLUME, true);
281 display->icon(ICON_VOLUME_1, bar->info.volume > 10); 284 display->icon(ICON_VOLUME_1, vol > 10);
282 display->icon(ICON_VOLUME_2, bar->info.volume > 30); 285 display->icon(ICON_VOLUME_2, vol > 30);
283 display->icon(ICON_VOLUME_3, bar->info.volume > 50); 286 display->icon(ICON_VOLUME_3, vol > 50);
284 display->icon(ICON_VOLUME_4, bar->info.volume > 70); 287 display->icon(ICON_VOLUME_4, vol > 70);
285 display->icon(ICON_VOLUME_5, bar->info.volume > 90); 288 display->icon(ICON_VOLUME_5, vol > 90);
286 289
287 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY); 290 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
288 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE); 291 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
@@ -356,31 +359,31 @@ void gui_statusbar_icon_battery(struct screen * display, int percent)
356/* 359/*
357 * Print volume gauge to status bar 360 * Print volume gauge to status bar
358 */ 361 */
359bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int percent) 362bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume)
360{ 363{
361 int i; 364 int i;
362 int volume;
363 int vol; 365 int vol;
364 char buffer[4]; 366 char buffer[4];
365 unsigned int width, height; 367 unsigned int width, height;
366 bool needs_redraw = false; 368 bool needs_redraw = false;
367 int type = global_settings.volume_type; 369 int type = global_settings.volume_type;
368 struct screen * display=bar->display; 370 struct screen * display=bar->display;
371 int minvol = sound_min(SOUND_VOLUME);
372 int maxvol = sound_max(SOUND_VOLUME);
369 373
370 volume = percent; 374 if (volume < minvol)
371 if (volume < 0) 375 volume = minvol;
372 volume = 0; 376 if (volume > maxvol)
373 if (volume > 100) 377 volume = maxvol;
374 volume = 100;
375 378
376 if (volume == 0) { 379 if (volume == minvol) {
377 display->mono_bitmap(bitmap_icons_7x8[Icon_Mute], 380 display->mono_bitmap(bitmap_icons_7x8[Icon_Mute],
378 STATUSBAR_VOLUME_X_POS + STATUSBAR_VOLUME_WIDTH / 2 - 4, 381 STATUSBAR_VOLUME_X_POS + STATUSBAR_VOLUME_WIDTH / 2 - 4,
379 STATUSBAR_Y_POS, 7, STATUSBAR_HEIGHT); 382 STATUSBAR_Y_POS, 7, STATUSBAR_HEIGHT);
380 } 383 }
381 else { 384 else {
382 /* We want to redraw the icon later on */ 385 /* We want to redraw the icon later on */
383 if (bar->last_volume != volume && bar->last_volume >= 0) { 386 if (bar->last_volume != volume && bar->last_volume >= minvol) {
384 bar->volume_icon_switch_tick = current_tick + HZ; 387 bar->volume_icon_switch_tick = current_tick + HZ;
385 } 388 }
386 389
@@ -395,7 +398,7 @@ bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int percent)
395 if (type) 398 if (type)
396 { 399 {
397 display->setfont(FONT_SYSFIXED); 400 display->setfont(FONT_SYSFIXED);
398 snprintf(buffer, sizeof(buffer), "%2d", percent); 401 snprintf(buffer, sizeof(buffer), "%2d", volume);
399 display->getstringsize(buffer, &width, &height); 402 display->getstringsize(buffer, &width, &height);
400 if (height <= STATUSBAR_HEIGHT) 403 if (height <= STATUSBAR_HEIGHT)
401 { 404 {
@@ -406,7 +409,7 @@ bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int percent)
406 display->setfont(FONT_UI); 409 display->setfont(FONT_UI);
407 } else { 410 } else {
408 /* display volume bar */ 411 /* display volume bar */
409 vol = volume * 14 / 100; 412 vol = (volume - minvol) * 14 / (maxvol - minvol);
410 for(i=0; i < vol; i++) { 413 for(i=0; i < vol; i++) {
411 display->vline(STATUSBAR_VOLUME_X_POS + i, 414 display->vline(STATUSBAR_VOLUME_X_POS + i,
412 STATUSBAR_Y_POS + 6 - i / 2, 415 STATUSBAR_Y_POS + 6 - i / 2,
diff --git a/apps/gui/statusbar.h b/apps/gui/statusbar.h
index 6b8e49a838..650b49d63b 100644
--- a/apps/gui/statusbar.h
+++ b/apps/gui/statusbar.h
@@ -102,7 +102,7 @@ extern void gui_statusbar_init(struct gui_statusbar * bar);
102extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw); 102extern void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw);
103 103
104void gui_statusbar_icon_battery(struct screen * display, int percent); 104void gui_statusbar_icon_battery(struct screen * display, int percent);
105bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int percent); 105bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume);
106void gui_statusbar_icon_play_state(struct screen * display, int state); 106void gui_statusbar_icon_play_state(struct screen * display, int state);
107void gui_statusbar_icon_play_mode(struct screen * display, int mode); 107void gui_statusbar_icon_play_mode(struct screen * display, int mode);
108void gui_statusbar_icon_shuffle(struct screen * display); 108void gui_statusbar_icon_shuffle(struct screen * display);
diff --git a/apps/lang/english.lang b/apps/lang/english.lang
index 3595281209..1f0ef87ca4 100644
--- a/apps/lang/english.lang
+++ b/apps/lang/english.lang
@@ -3550,33 +3550,3 @@ desc: in radio screen / menu
3550eng: "Mode:" 3550eng: "Mode:"
3551voice: "" 3551voice: ""
3552new: 3552new:
3553
3554id: LANG_SCALING_MODE
3555desc: in sound_settings. How to scale volume/bass to prevent clipping
3556eng: "Prevent clipping"
3557voice: "Prevent clipping"
3558new:
3559
3560id: LANG_SCALE_OFF
3561desc: in sound_settings. Do not reduce volume/bass
3562eng: "Off"
3563voice: "Off"
3564new:
3565
3566id: LANG_SCALE_VOLUME
3567desc: in sound_settings. Reduce volume
3568eng: "Adjust volume"
3569voice: "Adjust volume"
3570new:
3571
3572id: LANG_SCALE_BASS
3573desc: in sound_settings. Reduce bass
3574eng: "Adjust bass"
3575voice: "Adjust bass"
3576new:
3577
3578id: LANG_SCALE_CURRENT
3579desc: in sound_settings. Reduce other metric than currently modified
3580eng: "Adjust current"
3581voice: "Adjust current"
3582new:
diff --git a/apps/settings.c b/apps/settings.c
index d3441630fd..bd6076dc93 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -85,7 +85,7 @@ const char rec_base_directory[] = REC_BASE_DIR;
85#include "dsp.h" 85#include "dsp.h"
86#endif 86#endif
87 87
88#define CONFIG_BLOCK_VERSION 35 88#define CONFIG_BLOCK_VERSION 36
89#define CONFIG_BLOCK_SIZE 512 89#define CONFIG_BLOCK_SIZE 512
90#define RTC_BLOCK_SIZE 44 90#define RTC_BLOCK_SIZE 44
91 91
@@ -193,7 +193,11 @@ static const struct bit_entry rtc_bits[] =
193 193
194 /* # of bits, offset+size, default, .cfg name, .cfg values */ 194 /* # of bits, offset+size, default, .cfg name, .cfg values */
195 /* sound */ 195 /* sound */
196 {7, S_O(volume), 70, "volume", NULL }, /* 0...100 */ 196#if CONFIG_CODEC == MAS3507D
197 {8 | SIGNED, S_O(volume), -18, "volume", NULL }, /* -78...+18 */
198#else
199 {8 | SIGNED, S_O(volume), -25, "volume", NULL }, /* -100...+12 / -84...0 */
200#endif
197 {8 | SIGNED, S_O(balance), 0, "balance", NULL }, /* -100...100 */ 201 {8 | SIGNED, S_O(balance), 0, "balance", NULL }, /* -100...100 */
198#if CONFIG_CODEC != SWCODEC /* any MAS */ 202#if CONFIG_CODEC != SWCODEC /* any MAS */
199 {5 | SIGNED, S_O(bass), 0, "bass", NULL }, /* -15..+15 / -12..+12 */ 203 {5 | SIGNED, S_O(bass), 0, "bass", NULL }, /* -15..+15 / -12..+12 */
@@ -210,9 +214,6 @@ static const struct bit_entry rtc_bits[] =
210 {3, S_O(channel_config), 0, "channels", 214 {3, S_O(channel_config), 0, "channels",
211 "stereo,mono,custom,mono left,mono right,karaoke" }, 215 "stereo,mono,custom,mono left,mono right,karaoke" },
212 {8, S_O(stereo_width), 100, "stereo width", NULL}, 216 {8, S_O(stereo_width), 100, "stereo width", NULL},
213#ifdef HAVE_UDA1380
214 {2, S_O(sound_scaling), SOUND_SCALE_VOLUME, "prevent clipping", "adjust volume,adjust bass,adjust current,off"},
215#endif
216 /* playback */ 217 /* playback */
217 {1, S_O(resume), false, "resume", off_on }, 218 {1, S_O(resume), false, "resume", off_on },
218 {1, S_O(playlist_shuffle), false, "shuffle", off_on }, 219 {1, S_O(playlist_shuffle), false, "shuffle", off_on },
@@ -842,9 +843,6 @@ void sound_settings_apply(void)
842 sound_set(SOUND_VOLUME, global_settings.volume); 843 sound_set(SOUND_VOLUME, global_settings.volume);
843 sound_set(SOUND_CHANNELS, global_settings.channel_config); 844 sound_set(SOUND_CHANNELS, global_settings.channel_config);
844 sound_set(SOUND_STEREO_WIDTH, global_settings.stereo_width); 845 sound_set(SOUND_STEREO_WIDTH, global_settings.stereo_width);
845#ifdef HAVE_UDA1380
846 sound_set(SOUND_SCALING, global_settings.sound_scaling);
847#endif
848#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 846#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
849 sound_set(SOUND_LOUDNESS, global_settings.loudness); 847 sound_set(SOUND_LOUDNESS, global_settings.loudness);
850 sound_set(SOUND_AVC, global_settings.avc); 848 sound_set(SOUND_AVC, global_settings.avc);
@@ -1429,9 +1427,6 @@ void settings_reset(void) {
1429 global_settings.treble = sound_default(SOUND_TREBLE); 1427 global_settings.treble = sound_default(SOUND_TREBLE);
1430 global_settings.channel_config = sound_default(SOUND_CHANNELS); 1428 global_settings.channel_config = sound_default(SOUND_CHANNELS);
1431 global_settings.stereo_width = sound_default(SOUND_STEREO_WIDTH); 1429 global_settings.stereo_width = sound_default(SOUND_STEREO_WIDTH);
1432#ifdef HAVE_UDA1380
1433 global_settings.sound_scaling = sound_default(SOUND_SCALING);
1434#endif
1435#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 1430#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
1436 global_settings.loudness = sound_default(SOUND_LOUDNESS); 1431 global_settings.loudness = sound_default(SOUND_LOUDNESS);
1437 global_settings.avc = sound_default(SOUND_AVC); 1432 global_settings.avc = sound_default(SOUND_AVC);
diff --git a/apps/settings.h b/apps/settings.h
index 6b34543c27..b1e8c9e2e8 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -157,9 +157,6 @@ struct user_settings
157 int avc; /* auto volume correct: 0=off, 1=20ms, 2=2s 3=4s 4=8s */ 157 int avc; /* auto volume correct: 0=off, 1=20ms, 2=2s 3=4s 4=8s */
158 int channel_config; /* Stereo, Mono, Custom, Mono left, Mono right, Karaoke */ 158 int channel_config; /* Stereo, Mono, Custom, Mono left, Mono right, Karaoke */
159 int stereo_width; /* 0-255% */ 159 int stereo_width; /* 0-255% */
160#ifdef HAVE_UDA1380
161 int sound_scaling; /* Off, Volume, Bass, Current metric */
162#endif
163 int mdb_strength; /* 0-127dB */ 160 int mdb_strength; /* 0-127dB */
164 int mdb_harmonics; /* 0-100% */ 161 int mdb_harmonics; /* 0-100% */
165 int mdb_center; /* 20-300Hz */ 162 int mdb_center; /* 20-300Hz */
diff --git a/apps/sound_menu.c b/apps/sound_menu.c
index f97cdde2ab..e44aa68231 100644
--- a/apps/sound_menu.c
+++ b/apps/sound_menu.c
@@ -366,21 +366,6 @@ static bool stereo_width(void)
366 SOUND_STEREO_WIDTH); 366 SOUND_STEREO_WIDTH);
367} 367}
368 368
369#ifdef HAVE_UDA1380
370static bool sound_scaling(void)
371{
372 static const struct opt_items names[] = {
373 { STR(LANG_SCALE_VOLUME) },
374 { STR(LANG_SCALE_BASS) },
375 { STR(LANG_SCALE_CURRENT)},
376 { STR(LANG_SCALE_OFF) }
377 };
378
379 return set_option(str(LANG_SCALING_MODE), &global_settings.sound_scaling, INT,
380 names, 4, sound_set_scaling);
381}
382#endif
383
384bool sound_menu(void) 369bool sound_menu(void)
385{ 370{
386 int m; 371 int m;
@@ -395,9 +380,6 @@ bool sound_menu(void)
395#if CONFIG_CODEC == SWCODEC 380#if CONFIG_CODEC == SWCODEC
396 { ID2P(LANG_CROSSFEED), crossfeed }, 381 { ID2P(LANG_CROSSFEED), crossfeed },
397#endif 382#endif
398#ifdef HAVE_UDA1380
399 { ID2P(LANG_SCALING_MODE), sound_scaling },
400#endif
401#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 383#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
402 { ID2P(LANG_LOUDNESS), loudness }, 384 { ID2P(LANG_LOUDNESS), loudness },
403 { ID2P(LANG_AUTOVOL), avc }, 385 { ID2P(LANG_AUTOVOL), avc },
diff --git a/firmware/export/sound.h b/firmware/export/sound.h
index 3c7dec62b0..2c002063db 100644
--- a/firmware/export/sound.h
+++ b/firmware/export/sound.h
@@ -26,9 +26,6 @@ enum {
26 SOUND_BALANCE, 26 SOUND_BALANCE,
27 SOUND_CHANNELS, 27 SOUND_CHANNELS,
28 SOUND_STEREO_WIDTH, 28 SOUND_STEREO_WIDTH,
29#ifdef HAVE_UDA1380
30 SOUND_SCALING,
31#endif
32#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 29#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
33 SOUND_LOUDNESS, 30 SOUND_LOUDNESS,
34 SOUND_AVC, 31 SOUND_AVC,
@@ -59,15 +56,6 @@ enum {
59 SOUND_CHAN_KARAOKE, 56 SOUND_CHAN_KARAOKE,
60}; 57};
61 58
62#ifdef HAVE_UDA1380
63enum {
64 SOUND_SCALE_VOLUME = 0,
65 SOUND_SCALE_BASS,
66 SOUND_SCALE_CURRENT,
67 SOUND_SCALE_OFF
68};
69#endif
70
71typedef void sound_set_type(int value); 59typedef void sound_set_type(int value);
72 60
73const char *sound_unit(int setting); 61const char *sound_unit(int setting);
@@ -84,9 +72,6 @@ void sound_set_bass(int value);
84void sound_set_treble(int value); 72void sound_set_treble(int value);
85void sound_set_channels(int value); 73void sound_set_channels(int value);
86void sound_set_stereo_width(int value); 74void sound_set_stereo_width(int value);
87#ifdef HAVE_UDA1380
88void sound_set_scaling(int value);
89#endif
90#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 75#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
91void sound_set_loudness(int value); 76void sound_set_loudness(int value);
92void sound_set_avc(int value); 77void sound_set_avc(int value);
diff --git a/firmware/sound.c b/firmware/sound.c
index 20c796b674..555280c3d5 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -56,15 +56,16 @@ struct sound_settings_info {
56}; 56};
57 57
58static const struct sound_settings_info sound_settings_table[] = { 58static const struct sound_settings_info sound_settings_table[] = {
59 [SOUND_VOLUME] = {"%", 0, 1, 0, 100, 70, sound_set_volume},
60#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 59#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
60 [SOUND_VOLUME] = {"dB", 0, 1,-100, 12, -25, sound_set_volume},
61 [SOUND_BASS] = {"dB", 0, 1, -12, 12, 6, sound_set_bass}, 61 [SOUND_BASS] = {"dB", 0, 1, -12, 12, 6, sound_set_bass},
62 [SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 6, sound_set_treble}, 62 [SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 6, sound_set_treble},
63#elif defined(HAVE_UDA1380) 63#elif defined(HAVE_UDA1380)
64 [SOUND_VOLUME] = {"dB", 0, 1, -84, 0, -25, sound_set_volume},
64 [SOUND_BASS] = {"dB", 0, 2, 0, 24, 0, sound_set_bass}, 65 [SOUND_BASS] = {"dB", 0, 2, 0, 24, 0, sound_set_bass},
65 [SOUND_TREBLE] = {"dB", 0, 2, 0, 6, 0, sound_set_treble}, 66 [SOUND_TREBLE] = {"dB", 0, 2, 0, 6, 0, sound_set_treble},
66 [SOUND_SCALING] = {"", 0, 1, 0, 1, SOUND_SCALE_VOLUME, sound_set_scaling},
67#else /* MAS3507D */ 67#else /* MAS3507D */
68 [SOUND_VOLUME] = {"dB", 0, 1, -78, 18, -18, sound_set_volume},
68 [SOUND_BASS] = {"dB", 0, 1, -15, 15, 7, sound_set_bass}, 69 [SOUND_BASS] = {"dB", 0, 1, -15, 15, 7, sound_set_bass},
69 [SOUND_TREBLE] = {"dB", 0, 1, -15, 15, 7, sound_set_treble}, 70 [SOUND_TREBLE] = {"dB", 0, 1, -15, 15, 7, sound_set_treble},
70#endif 71#endif
@@ -228,11 +229,12 @@ static const unsigned int prescale_table[] =
228 0xe9400 /* 15dB */ 229 0xe9400 /* 15dB */
229}; 230};
230 231
231/* convert tenth of dB volume to dac3550 register value */ 232/* convert tenth of dB volume (-780..+180) to dac3550 register value */
232static int tenthdb2reg(int db) { 233static int tenthdb2reg(int db)
233 if (db < -540) 234{
235 if (db < -540) /* 3 dB steps */
234 return (db + 780) / 30; 236 return (db + 780) / 30;
235 else 237 else /* 1.5 dB steps */
236 return (db + 660) / 15; 238 return (db + 660) / 15;
237} 239}
238#endif 240#endif
@@ -241,8 +243,9 @@ static int tenthdb2reg(int db) {
241#define VOLUME_MIN -840 243#define VOLUME_MIN -840
242#define VOLUME_MAX 0 244#define VOLUME_MAX 0
243 245
244/* convert tenth of dB volume to master volume register value */ 246/* convert tenth of dB volume (-840..0) to master volume register value */
245static int tenthdb2master(int db) { 247static int tenthdb2master(int db)
248{
246 if (db < -720) /* 1.5 dB steps */ 249 if (db < -720) /* 1.5 dB steps */
247 return (2940 - db) / 15; 250 return (2940 - db) / 15;
248 else if (db < -660) /* 0.75 dB steps */ 251 else if (db < -660) /* 0.75 dB steps */
@@ -253,16 +256,16 @@ static int tenthdb2master(int db) {
253 return -db * 2 / 5; 256 return -db * 2 / 5;
254} 257}
255 258
256static int tenthdb2mixer(int db) { 259/* convert tenth of dB volume (-780..0) to mixer volume register value */
257 if (db < -720) 260static int tenthdb2mixer(int db)
258 return 228; 261{
259 else if (db < -660) 262 if (db < -660) /* 1.5 dB steps */
260 return 224; 263 return (2640 - db) / 15;
261 else if (db < -600) 264 else if (db < -600) /* 0.75 dB steps */
262 return 216; 265 return (990 - db) * 2 / 15;
263 else if (db < -470) 266 else if (db < -460) /* 0.5 dB steps */
264 return (460 - db) / 5; 267 return (460 - db) / 5;
265 else 268 else /* 0.25 dB steps */
266 return -db * 2 / 5; 269 return -db * 2 / 5;
267} 270}
268 271
@@ -278,89 +281,6 @@ int current_balance = 0; /* -960..+960 -840..+840 */
278int current_treble = 0; /* -150..+150 0.. +60 */ 281int current_treble = 0; /* -150..+150 0.. +60 */
279int current_bass = 0; /* -150..+150 0..+240 */ 282int current_bass = 0; /* -150..+150 0..+240 */
280 283
281#ifdef HAVE_UDA1380
282
283#define MODIFYING_VOLUME 0
284#define MODIFYING_BASS 1
285#define MODIFYING_BALANCE 2
286#define MODIFYING_NONE 3
287
288int current_scaling_mode = SOUND_SCALE_VOLUME;
289int current_start_l_r = VOLUME_MAX;
290
291static void set_prescaled_volume_and_bass(int scaling_mode, bool just_balance)
292{
293 int l = VOLUME_MAX, r = VOLUME_MAX, prescale;
294 int new_bass = 0, new_volume = 0;
295
296 if(scaling_mode == SOUND_SCALE_OFF)
297 {
298 if (current_volume > VOLUME_MAX)
299 current_volume = VOLUME_MAX;
300 new_bass = (current_bass/10) >> 1;
301 new_volume = tenthdb2mixer(current_volume);
302
303 }
304 else if(scaling_mode == SOUND_SCALE_BASS)
305 {
306 if (current_volume > VOLUME_MAX)
307 current_volume = VOLUME_MAX;
308
309 prescale = ((VOLUME_MAX - current_volume) / 20);
310
311 if ((current_bass + current_volume) <= VOLUME_MAX)
312 new_bass = current_bass / 20;
313 else
314 new_bass = prescale; /* limit bass with volume */
315
316 new_volume = tenthdb2mixer(current_volume);
317
318 }
319 else if(scaling_mode == SOUND_SCALE_VOLUME)
320 {
321 prescale = current_bass;
322 if (prescale < 0)
323 prescale = 0;
324
325 new_bass = (current_bass/10) >> 1;
326 new_volume = prescale*2/5;
327
328 if (current_volume + prescale > VOLUME_MAX)
329 prescale = VOLUME_MAX - current_volume;
330
331 l = r = current_volume + prescale;
332 }
333 else if(scaling_mode == SOUND_SCALE_CURRENT)
334 {
335 l = r = current_start_l_r;
336
337 }
338
339 if(!just_balance)
340 {
341 uda1380_set_bass(new_bass);
342 uda1380_set_mixer_vol(new_volume, new_volume);
343 }
344
345 current_start_l_r = l;
346
347 if (current_balance > 0) {
348 l -= current_balance;
349 if (l < VOLUME_MIN)
350 l = VOLUME_MIN;
351 }
352 if (current_balance < 0) {
353 r += current_balance;
354 if (r < VOLUME_MIN)
355 r = VOLUME_MIN;
356 }
357
358 uda1380_set_master_vol(tenthdb2master(l), tenthdb2master(r));
359}
360
361#endif
362
363#if CONFIG_CODEC == MAS3507D
364static void set_prescaled_volume(void) 284static void set_prescaled_volume(void)
365{ 285{
366 int prescale; 286 int prescale;
@@ -371,12 +291,21 @@ static void set_prescaled_volume(void)
371 prescale = 0; /* no need to prescale if we don't boost 291 prescale = 0; /* no need to prescale if we don't boost
372 bass or treble */ 292 bass or treble */
373 293
374 mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]); 294 /* Gain up the analog volume to compensate the prescale gain reduction,
375 295 * but if this would push the volume over the top, reduce prescaling
376 /* gain up the analog volume to compensate the prescale gain reduction, 296 * instead (might cause clipping). */
377 * but limit to the possible maximum */
378 if (current_volume + prescale > VOLUME_MAX) 297 if (current_volume + prescale > VOLUME_MAX)
379 prescale = VOLUME_MAX - current_volume; 298 prescale = VOLUME_MAX - current_volume;
299
300#if CONFIG_CODEC == MAS3507D
301 mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]);
302#else /* UDA1380 */
303 uda1380_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale));
304#endif
305
306 if (current_volume == VOLUME_MIN)
307 prescale = 0; /* Make sure the chip gets muted at VOLUME_MIN */
308
380 l = r = current_volume + prescale; 309 l = r = current_volume + prescale;
381 310
382 if (current_balance > 0) 311 if (current_balance > 0)
@@ -392,28 +321,12 @@ static void set_prescaled_volume(void)
392 r = VOLUME_MIN; 321 r = VOLUME_MIN;
393 } 322 }
394 323
324#if CONFIG_CODEC == MAS3507D
395 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); 325 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
396} 326#else /* UDA1380 */
327 uda1380_set_master_vol(tenthdb2master(l), tenthdb2master(r));
397#endif 328#endif
398
399#ifdef HAVE_UDA1380
400static void set_prescaled_volume(int modifying)
401{
402 if (modifying == MODIFYING_BALANCE)
403 set_prescaled_volume_and_bass(current_scaling_mode,true);
404 else if (current_scaling_mode == SOUND_SCALE_OFF)
405 set_prescaled_volume_and_bass(current_scaling_mode,false);
406 else if(( (modifying == MODIFYING_BASS)
407 && (current_scaling_mode == SOUND_SCALE_CURRENT)) ||
408 (current_scaling_mode == SOUND_SCALE_VOLUME))
409 set_prescaled_volume_and_bass(SOUND_SCALE_VOLUME,false);
410 else if(( (modifying == MODIFYING_VOLUME)
411 && (current_scaling_mode == SOUND_SCALE_CURRENT)) ||
412 (current_scaling_mode == SOUND_SCALE_BASS))
413 set_prescaled_volume_and_bass(SOUND_SCALE_BASS,false);
414} 329}
415#endif
416
417#endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */ 330#endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
418#endif /* !SIMULATOR */ 331#endif /* !SIMULATOR */
419 332
@@ -509,18 +422,15 @@ void sound_set_volume(int value)
509 if(!audio_is_initialized) 422 if(!audio_is_initialized)
510 return; 423 return;
511#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 424#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
512 int tmp = 0x7f00 * value / 100; 425 unsigned tmp = ((unsigned)(value + 115) & 0xff) << 8;
513 mas_codec_writereg(0x10, tmp & 0xff00); 426 mas_codec_writereg(0x10, tmp);
514#elif (CONFIG_CODEC == MAS3507D) 427#elif (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380
515 current_volume = VOLUME_MIN + (value * VOLUME_RANGE / 100); 428 current_volume = value * 10; /* tenth of dB */
516 set_prescaled_volume(); /* tenth of dB */ 429 set_prescaled_volume();
517#elif defined HAVE_UDA1380
518 current_volume = VOLUME_MIN + (value * VOLUME_RANGE / 100);
519 set_prescaled_volume(MODIFYING_VOLUME); /* tenth of dB */
520#elif (CONFIG_CPU == PP5020) 430#elif (CONFIG_CPU == PP5020)
521 /* TODO: Implement sound_set_volume() */ 431 /* TODO: Implement sound_set_volume() */
522 (void)value; 432 (void)value;
523#endif 433#endif
524} 434}
525 435
526void sound_set_balance(int value) 436void sound_set_balance(int value)
@@ -528,18 +438,15 @@ void sound_set_balance(int value)
528 if(!audio_is_initialized) 438 if(!audio_is_initialized)
529 return; 439 return;
530#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 440#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
531 int tmp = ((value * 127 / 100) & 0xff) << 8; 441 unsigned tmp = ((unsigned)(value * 127 / 100) & 0xff) << 8;
532 mas_codec_writereg(0x11, tmp & 0xff00); 442 mas_codec_writereg(0x11, tmp);
533#elif CONFIG_CODEC == MAS3507D 443#elif CONFIG_CODEC == MAS3507D || defined HAVE_UDA1380
534 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */ 444 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */
535 set_prescaled_volume(); 445 set_prescaled_volume();
536#elif defined HAVE_UDA1380
537 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */
538 set_prescaled_volume(MODIFYING_BALANCE);
539#elif (CONFIG_CPU == PP5020) 446#elif (CONFIG_CPU == PP5020)
540 /* TODO: Implement sound_set_balance() */ 447 /* TODO: Implement sound_set_balance() */
541 (void)value; 448 (void)value;
542#endif 449#endif
543} 450}
544 451
545void sound_set_bass(int value) 452void sound_set_bass(int value)
@@ -547,15 +454,16 @@ void sound_set_bass(int value)
547 if(!audio_is_initialized) 454 if(!audio_is_initialized)
548 return; 455 return;
549#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 456#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
550 int tmp = ((value * 8) & 0xff) << 8; 457 unsigned tmp = ((unsigned)(value * 8) & 0xff) << 8;
551 mas_codec_writereg(0x14, tmp & 0xff00); 458 mas_codec_writereg(0x14, tmp);
552#elif CONFIG_CODEC == MAS3507D 459#elif CONFIG_CODEC == MAS3507D
553 mas_writereg(MAS_REG_KBASS, bass_table[value+15]); 460 mas_writereg(MAS_REG_KBASS, bass_table[value+15]);
554 current_bass = value * 10; 461 current_bass = value * 10;
555 set_prescaled_volume(); 462 set_prescaled_volume();
556#elif defined(HAVE_UDA1380) 463#elif defined(HAVE_UDA1380)
464 uda1380_set_bass(value >> 1);
557 current_bass = value * 10; 465 current_bass = value * 10;
558 set_prescaled_volume(MODIFYING_BASS); 466 set_prescaled_volume();
559#elif (CONFIG_CPU == PP5020) 467#elif (CONFIG_CPU == PP5020)
560 /* TODO: Implement sound_set_bass() */ 468 /* TODO: Implement sound_set_bass() */
561 (void)value; 469 (void)value;
@@ -567,8 +475,8 @@ void sound_set_treble(int value)
567 if(!audio_is_initialized) 475 if(!audio_is_initialized)
568 return; 476 return;
569#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 477#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
570 int tmp = ((value * 8) & 0xff) << 8; 478 unsigned tmp = ((unsigned)(value * 8) & 0xff) << 8;
571 mas_codec_writereg(0x15, tmp & 0xff00); 479 mas_codec_writereg(0x15, tmp);
572#elif CONFIG_CODEC == MAS3507D 480#elif CONFIG_CODEC == MAS3507D
573 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]); 481 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]);
574 current_treble = value * 10; 482 current_treble = value * 10;
@@ -576,6 +484,7 @@ void sound_set_treble(int value)
576#elif defined(HAVE_UDA1380) 484#elif defined(HAVE_UDA1380)
577 uda1380_set_treble(value >> 1); 485 uda1380_set_treble(value >> 1);
578 current_treble = value * 10; 486 current_treble = value * 10;
487 set_prescaled_volume();
579#elif (CONFIG_CPU == PP5020) 488#elif (CONFIG_CPU == PP5020)
580 /* TODO: Implement sound_set_treble() */ 489 /* TODO: Implement sound_set_treble() */
581 (void)value; 490 (void)value;
@@ -599,16 +508,6 @@ void sound_set_stereo_width(int value)
599 set_channel_config(); 508 set_channel_config();
600} 509}
601 510
602#ifdef HAVE_UDA1380
603void sound_set_scaling(int value)
604{
605 current_scaling_mode = value;
606 if(!audio_is_initialized)
607 return;
608 set_prescaled_volume(MODIFYING_NONE);
609}
610#endif
611
612#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 511#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
613void sound_set_loudness(int value) 512void sound_set_loudness(int value)
614{ 513{
@@ -726,13 +625,6 @@ void sound_set_stereo_width(int value)
726 (void)value; 625 (void)value;
727} 626}
728 627
729#ifdef HAVE_UDA1380
730void sound_set_scaling(int value)
731{
732 (void)value;
733}
734#endif
735
736#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) 628#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
737void sound_set_loudness(int value) 629void sound_set_loudness(int value)
738{ 630{