summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2008-04-22 13:43:01 +0000
committerChristian Gmeiner <christian.gmeiner@gmail.com>2008-04-22 13:43:01 +0000
commitb1806b2b20e59c7c6c2c9dcb301bbb5698caaca6 (patch)
tree16f2ab838b9855765e32f337ca390f37e6f8e40d /firmware/drivers
parent3ad6ca0da3aff74a76c26b487909549256d35773 (diff)
move mas35xx specific code for set_channels and set_stereo_width to mas35xx.c audio codec driver. If you ask why I
am doing this... cleaning up sound.c and move target specific code into target tree or into audio codec drivers. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17217 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/audio/mas35xx.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/firmware/drivers/audio/mas35xx.c b/firmware/drivers/audio/mas35xx.c
index 813b02e1ca..dac890ddc8 100644
--- a/firmware/drivers/audio/mas35xx.c
+++ b/firmware/drivers/audio/mas35xx.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "audiohw.h"
+#include "mas.h"
const struct sound_settings_info audiohw_settings[] = {
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
@@ -52,3 +53,100 @@ const struct sound_settings_info audiohw_settings[] = {
[SOUND_MIC_GAIN] = {"dB", 1, 1, 0, 15, 2},
#endif
};
+
+
+int channel_configuration = SOUND_CHAN_STEREO;
+int stereo_width = 100;
+
+
+static void set_channel_config(void)
+{
+ /* default values: stereo */
+ unsigned long val_ll = 0x80000;
+ unsigned long val_lr = 0;
+ unsigned long val_rl = 0;
+ unsigned long val_rr = 0x80000;
+
+ switch(channel_configuration)
+ {
+ /* case SOUND_CHAN_STEREO unnecessary */
+
+ case SOUND_CHAN_MONO:
+ val_ll = 0xc0000;
+ val_lr = 0xc0000;
+ val_rl = 0xc0000;
+ val_rr = 0xc0000;
+ break;
+
+ case SOUND_CHAN_CUSTOM:
+ {
+ /* fixed point variables (matching MAS internal format)
+ integer part: upper 13 bits (inlcuding sign)
+ fractional part: lower 19 bits */
+ long fp_width, fp_straight, fp_cross;
+
+ fp_width = (stereo_width << 19) / 100;
+ if (stereo_width <= 100)
+ {
+ fp_straight = - ((1<<19) + fp_width) / 2;
+ fp_cross = fp_straight + fp_width;
+ }
+ else
+ {
+ /* straight = - (1 + width) / (2 * width) */
+ fp_straight = - ((((1<<19) + fp_width) / (fp_width >> 9)) << 9);
+ fp_cross = (1<<19) + fp_straight;
+ }
+ val_ll = val_rr = fp_straight & 0xfffff;
+ val_lr = val_rl = fp_cross & 0xfffff;
+ }
+ break;
+
+ case SOUND_CHAN_MONO_LEFT:
+ val_ll = 0x80000;
+ val_lr = 0x80000;
+ val_rl = 0;
+ val_rr = 0;
+ break;
+
+ case SOUND_CHAN_MONO_RIGHT:
+ val_ll = 0;
+ val_lr = 0;
+ val_rl = 0x80000;
+ val_rr = 0x80000;
+ break;
+
+ case SOUND_CHAN_KARAOKE:
+ val_ll = 0xc0000;
+ val_lr = 0x40000;
+ val_rl = 0x40000;
+ val_rr = 0xc0000;
+ break;
+ }
+
+#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
+ mas_writemem(MAS_BANK_D0, MAS_D0_OUT_LL, &val_ll, 1); /* LL */
+ mas_writemem(MAS_BANK_D0, MAS_D0_OUT_LR, &val_lr, 1); /* LR */
+ mas_writemem(MAS_BANK_D0, MAS_D0_OUT_RL, &val_rl, 1); /* RL */
+ mas_writemem(MAS_BANK_D0, MAS_D0_OUT_RR, &val_rr, 1); /* RR */
+#elif CONFIG_CODEC == MAS3507D
+ mas_writemem(MAS_BANK_D1, 0x7f8, &val_ll, 1); /* LL */
+ mas_writemem(MAS_BANK_D1, 0x7f9, &val_lr, 1); /* LR */
+ mas_writemem(MAS_BANK_D1, 0x7fa, &val_rl, 1); /* RL */
+ mas_writemem(MAS_BANK_D1, 0x7fb, &val_rr, 1); /* RR */
+#endif
+}
+
+void audiohw_set_channel(int val)
+{
+ channel_configuration = val;
+ set_channel_config();
+}
+
+void audiohw_set_stereo_width(int val)
+{
+ stereo_width = val;
+ if (channel_configuration == SOUND_CHAN_CUSTOM) {
+ set_channel_config();
+ }
+}