summaryrefslogtreecommitdiff
path: root/firmware/sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/sound.c')
-rw-r--r--firmware/sound.c58
1 files changed, 50 insertions, 8 deletions
diff --git a/firmware/sound.c b/firmware/sound.c
index 7dd1fbf98e..cd6448c754 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -334,7 +334,7 @@ static int tenthdb2reg(int db) {
334 return (db + 660) / 15; 334 return (db + 660) / 15;
335} 335}
336 336
337void set_prescaled_volume(void) 337static void set_prescaled_volume(void)
338{ 338{
339 int prescale; 339 int prescale;
340 int l, r; 340 int l, r;
@@ -367,7 +367,47 @@ void set_prescaled_volume(void)
367 367
368 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); 368 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
369} 369}
370#endif /* MAS3507D */ 370#elif CONFIG_HWCODEC == MASNONE
371#ifdef HAVE_UDA1380 /* iriver H1x0 + H3x0 */
372/* all values in tenth of dB */
373int current_volume = 0; /* -840..0 */
374int current_balance = 0; /* -840..+840 */
375
376/* convert tenth of dB volume to register value */
377static int tenthdb2reg(int db) {
378 if (db < -720) /* 1.5 dB steps */
379 return (2940 - db) / 15;
380 else if (db < -660) /* 0.75 dB steps */
381 return (1110 - db) * 2 / 15;
382 else if (db < -520) /* 0.5 dB steps */
383 return (520 - db) / 5;
384 else /* 0.25 dB steps */
385 return -db * 2 / 5;
386}
387
388static void set_volume(void)
389{
390 int l, r;
391
392 l = r = current_volume;
393
394 if (current_balance > 0)
395 {
396 l -= current_balance;
397 if (l < -840)
398 l = -840;
399 }
400 if (current_balance < 0)
401 {
402 r += current_balance;
403 if (r < -840)
404 r = -840;
405 }
406
407 uda1380_setvol(tenthdb2reg(l), tenthdb2reg(r));
408}
409#endif
410#endif /* MASNONE */
371#endif /* !SIMULATOR */ 411#endif /* !SIMULATOR */
372 412
373int channel_configuration = SOUND_CHAN_STEREO; 413int channel_configuration = SOUND_CHAN_STEREO;
@@ -480,7 +520,8 @@ void sound_set(int setting, int value)
480 current_volume = -780 + (value * 960 / 100); /* tenth of dB */ 520 current_volume = -780 + (value * 960 / 100); /* tenth of dB */
481 set_prescaled_volume(); 521 set_prescaled_volume();
482#elif CONFIG_HWCODEC == MASNONE 522#elif CONFIG_HWCODEC == MASNONE
483 pcm_set_volume((value*167117) >> 16); 523 current_volume = -840 + (value * 840 / 100); /* tenth of dB */
524 set_volume();
484#endif 525#endif
485 break; 526 break;
486 527
@@ -492,7 +533,8 @@ void sound_set(int setting, int value)
492 current_balance = value * 960 / 100; /* tenth of dB */ 533 current_balance = value * 960 / 100; /* tenth of dB */
493 set_prescaled_volume(); 534 set_prescaled_volume();
494#elif defined(HAVE_UDA1380) 535#elif defined(HAVE_UDA1380)
495 uda1380_set_balance(value); 536 current_balance = value * 840 / 100; /* tenth of dB */
537 set_volume();
496#endif 538#endif
497 break; 539 break;
498 540
@@ -500,12 +542,12 @@ void sound_set(int setting, int value)
500#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 542#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
501 tmp = ((value * 8) & 0xff) << 8; 543 tmp = ((value * 8) & 0xff) << 8;
502 mas_codec_writereg(0x14, tmp & 0xff00); 544 mas_codec_writereg(0x14, tmp & 0xff00);
503#elif defined(HAVE_UDA1380)
504 uda1380_set_bass(value >> 1);
505#elif CONFIG_HWCODEC == MAS3507D 545#elif CONFIG_HWCODEC == MAS3507D
506 mas_writereg(MAS_REG_KBASS, bass_table[value+15]); 546 mas_writereg(MAS_REG_KBASS, bass_table[value+15]);
507 current_bass = value * 10; 547 current_bass = value * 10;
508 set_prescaled_volume(); 548 set_prescaled_volume();
549#elif defined(HAVE_UDA1380)
550 uda1380_set_bass(value >> 1);
509#endif 551#endif
510 break; 552 break;
511 553
@@ -513,12 +555,12 @@ void sound_set(int setting, int value)
513#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F) 555#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
514 tmp = ((value * 8) & 0xff) << 8; 556 tmp = ((value * 8) & 0xff) << 8;
515 mas_codec_writereg(0x15, tmp & 0xff00); 557 mas_codec_writereg(0x15, tmp & 0xff00);
516#elif defined(HAVE_UDA1380)
517 uda1380_set_treble(value >> 1);
518#elif CONFIG_HWCODEC == MAS3507D 558#elif CONFIG_HWCODEC == MAS3507D
519 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]); 559 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]);
520 current_treble = value * 10; 560 current_treble = value * 10;
521 set_prescaled_volume(); 561 set_prescaled_volume();
562#elif defined(HAVE_UDA1380)
563 uda1380_set_treble(value >> 1);
522#endif 564#endif
523 break; 565 break;
524 566