summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-12-07 23:07:07 +0000
committerJens Arnold <amiconn@rockbox.org>2005-12-07 23:07:07 +0000
commit2993ae69b5cfd95ddab595fcce9cc7637477d6a5 (patch)
tree1a9ba25c51db3d7313621da6dcf5bb4192cfea9d /firmware
parentec32c08a357bde454c11a41375230461509f2fe2 (diff)
downloadrockbox-2993ae69b5cfd95ddab595fcce9cc7637477d6a5.tar.gz
rockbox-2993ae69b5cfd95ddab595fcce9cc7637477d6a5.zip
Simplified and uniform volume handling: * Volume setting in dB on all targets, within the 'natural' range defined by the respective DAC (limited to -100..+12 dB for archos Recorders and Ondios in order to avoid 4 chars being displayed in the status bar). 0 dB means line level on all targets. * No more artificial volume limiting for Iriver and Player, settings always represent true values. Removed the various sound scaling options. * Bumped config version so save your settings. Also make sure to adjust the volume after loading a .cfg, then save the .cfg again, otherwise the volume will be out of range (a flaw in the .cfg loader).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8197 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/sound.h15
-rw-r--r--firmware/sound.c216
2 files changed, 54 insertions, 177 deletions
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{