summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/sound_menu.c7
-rw-r--r--firmware/mp3_playback.c69
2 files changed, 31 insertions, 45 deletions
diff --git a/apps/sound_menu.c b/apps/sound_menu.c
index 33bb80faa1..f08ee35525 100644
--- a/apps/sound_menu.c
+++ b/apps/sound_menu.c
@@ -135,13 +135,8 @@ bool set_sound(const char* string,
135 return true; 135 return true;
136 break; 136 break;
137 } 137 }
138 if (changed) { 138 if (changed)
139 mpeg_sound_set(setting, *variable); 139 mpeg_sound_set(setting, *variable);
140#if CONFIG_HWCODEC == MAS3507D
141 if(setting == SOUND_BALANCE)
142 mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
143#endif
144 }
145 } 140 }
146 lcd_stop_scroll(); 141 lcd_stop_scroll();
147 return false; 142 return false;
diff --git a/firmware/mp3_playback.c b/firmware/mp3_playback.c
index 6c59ee2327..16fe544c7a 100644
--- a/firmware/mp3_playback.c
+++ b/firmware/mp3_playback.c
@@ -591,11 +591,11 @@ static void init_playback(void)
591 591
592#ifndef SIMULATOR 592#ifndef SIMULATOR
593#if CONFIG_HWCODEC == MAS3507D 593#if CONFIG_HWCODEC == MAS3507D
594int current_left_volume = 0; /* all values in tenth of dB */ 594/* all values in tenth of dB */
595int current_right_volume = 0; /* all values in tenth of dB */ 595int current_volume = 0; /* -780..+180 */
596int current_treble = 0; 596int current_balance = 0; /* -960..+960 */
597int current_bass = 0; 597int current_treble = 0; /* -150..+150 */
598int current_balance = 0; 598int current_bass = 0; /* -150..+150 */
599 599
600/* convert tenth of dB volume to register value */ 600/* convert tenth of dB volume to register value */
601static int tenthdb2reg(int db) { 601static int tenthdb2reg(int db) {
@@ -616,10 +616,25 @@ void set_prescaled_volume(void)
616 bass or treble */ 616 bass or treble */
617 617
618 mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]); 618 mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]);
619 619
620 /* gain up the analog volume to compensate the prescale reduction gain */ 620 /* gain up the analog volume to compensate the prescale reduction gain,
621 l = current_left_volume + prescale; 621 * but limit to +18 dB (the maximum the DAC can do */
622 r = current_right_volume + prescale; 622 if (current_volume + prescale > 180)
623 prescale = 180 - current_volume;
624 l = r = current_volume + prescale;
625
626 if (current_balance > 0)
627 {
628 l -= current_balance;
629 if (l < -780)
630 l = -780;
631 }
632 if (current_balance < 0)
633 {
634 r += current_balance;
635 if (r < -780)
636 r = -780;
637 }
623 638
624 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); 639 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
625} 640}
@@ -719,9 +734,7 @@ void mpeg_sound_set(int setting, int value)
719#ifdef SIMULATOR 734#ifdef SIMULATOR
720 setting = value; 735 setting = value;
721#else 736#else
722#if CONFIG_HWCODEC == MAS3507D 737#if (CONFIG_HWCODEC == MAS3587F) || (CONFIG_HWCODEC == MAS3539F)
723 int l, r;
724#else
725 int tmp; 738 int tmp;
726#endif 739#endif
727 740
@@ -735,30 +748,7 @@ void mpeg_sound_set(int setting, int value)
735 tmp = 0x7f00 * value / 100; 748 tmp = 0x7f00 * value / 100;
736 mas_codec_writereg(0x10, tmp & 0xff00); 749 mas_codec_writereg(0x10, tmp & 0xff00);
737#else 750#else
738 l = value; 751 current_volume = -780 + (value * 960 / 100); /* tenth of dB */
739 r = value;
740
741 if(current_balance > 0)
742 {
743 l -= current_balance;
744 if(l < 0)
745 l = 0;
746 }
747
748 if(current_balance < 0)
749 {
750 r += current_balance;
751 if(r < 0)
752 r = 0;
753 }
754
755 l = 0x38 * l / 100;
756 r = 0x38 * r / 100;
757
758 /* store volume in tenth of dB */
759 current_left_volume = ( l < 0x08 ? l*30 - 780 : l*15 - 660 );
760 current_right_volume = ( r < 0x08 ? r*30 - 780 : r*15 - 660 );
761
762 set_prescaled_volume(); 752 set_prescaled_volume();
763#endif 753#endif
764 break; 754 break;
@@ -768,7 +758,8 @@ void mpeg_sound_set(int setting, int value)
768 tmp = ((value * 127 / 100) & 0xff) << 8; 758 tmp = ((value * 127 / 100) & 0xff) << 8;
769 mas_codec_writereg(0x11, tmp & 0xff00); 759 mas_codec_writereg(0x11, tmp & 0xff00);
770#else 760#else
771 current_balance = value; 761 current_balance = value * 960 / 100; /* tenth of dB */
762 set_prescaled_volume();
772#endif 763#endif
773 break; 764 break;
774 765
@@ -778,7 +769,7 @@ void mpeg_sound_set(int setting, int value)
778 mas_codec_writereg(0x14, tmp & 0xff00); 769 mas_codec_writereg(0x14, tmp & 0xff00);
779#else 770#else
780 mas_writereg(MAS_REG_KBASS, bass_table[value+15]); 771 mas_writereg(MAS_REG_KBASS, bass_table[value+15]);
781 current_bass = (value) * 10; 772 current_bass = value * 10;
782 set_prescaled_volume(); 773 set_prescaled_volume();
783#endif 774#endif
784 break; 775 break;
@@ -789,7 +780,7 @@ void mpeg_sound_set(int setting, int value)
789 mas_codec_writereg(0x15, tmp & 0xff00); 780 mas_codec_writereg(0x15, tmp & 0xff00);
790#else 781#else
791 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]); 782 mas_writereg(MAS_REG_KTREBLE, treble_table[value+15]);
792 current_treble = (value) * 10; 783 current_treble = value * 10;
793 set_prescaled_volume(); 784 set_prescaled_volume();
794#endif 785#endif
795 break; 786 break;