summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2006-01-30 21:12:31 +0000
committerDave Chapman <dave@dchapman.com>2006-01-30 21:12:31 +0000
commit5ffa8c52df2df1096c484efe6815ea8e8b548065 (patch)
treec9add96d65013bfced444a7b77f9c09b8dc785a4
parent1a4ef4fc0aa7a6257995f5df51f686c726802e5b (diff)
downloadrockbox-5ffa8c52df2df1096c484efe6815ea8e8b548065.tar.gz
rockbox-5ffa8c52df2df1096c484efe6815ea8e8b548065.tar.bz2
rockbox-5ffa8c52df2df1096c484efe6815ea8e8b548065.zip
iPod: Initial attempt at volume/bass/treble control - more work is needed, but it seems to be working.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8495 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/wm8975.c15
-rw-r--r--firmware/sound.c74
2 files changed, 70 insertions, 19 deletions
diff --git a/firmware/drivers/wm8975.c b/firmware/drivers/wm8975.c
index 802bcfa72b..a817284406 100644
--- a/firmware/drivers/wm8975.c
+++ b/firmware/drivers/wm8975.c
@@ -196,14 +196,25 @@ int wm8975_set_mixer_vol(int channel1, int channel2)
return 0;
}
+/* We are using Linear bass control */
void wm8975_set_bass(int value)
{
- (void)value;
+ int regvalues[]={11, 10, 10, 9, 8, 8, 0xf , 6, 6, 5, 4, 4, 3, 2, 1, 0};
+
+ if ((value >= -6) && (value <= 9)) {
+ /* We use linear bass control with 130Hz cutoff */
+ ipod_i2c_send(0x1a, 0x0c << 1, regvalues[value+6]);
+ }
}
void wm8975_set_treble(int value)
{
- (void)value;
+ int regvalues[]={11, 10, 10, 9, 8, 8, 0xf , 6, 6, 5, 4, 4, 3, 2, 1, 0};
+
+ if ((value >= -6) && (value <= 9)) {
+ /* We use a 8Khz cutoff */
+ ipod_i2c_send(0x1a, 0x0d << 1, regvalues[value+6]);
+ }
}
int wm8975_mute(int mute)
diff --git a/firmware/sound.c b/firmware/sound.c
index 555280c3d5..41212e72b9 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -20,11 +20,14 @@
#include <stdio.h>
#include "config.h"
#include "sound.h"
+#include "logf.h"
#ifndef SIMULATOR
#include "i2c.h"
#include "mas.h"
#ifdef HAVE_UDA1380
#include "uda1380.h"
+#elif defined(HAVE_WM8975)
+#include "wm8975.h"
#elif HAVE_TLV320
#include "tlv320.h"
#endif
@@ -64,6 +67,10 @@ static const struct sound_settings_info sound_settings_table[] = {
[SOUND_VOLUME] = {"dB", 0, 1, -84, 0, -25, sound_set_volume},
[SOUND_BASS] = {"dB", 0, 2, 0, 24, 0, sound_set_bass},
[SOUND_TREBLE] = {"dB", 0, 2, 0, 6, 0, sound_set_treble},
+#elif defined(HAVE_WM8975)
+ [SOUND_VOLUME] = {"dB", 0, 1, -73, 6, -25, sound_set_volume},
+ [SOUND_BASS] = {"dB", 0, 1, -6, 9, 0, sound_set_bass},
+ [SOUND_TREBLE] = {"dB", 0, 1, -6, 9, 0, sound_set_treble},
#else /* MAS3507D */
[SOUND_VOLUME] = {"dB", 0, 1, -78, 18, -18, sound_set_volume},
[SOUND_BASS] = {"dB", 0, 1, -15, 15, 7, sound_set_bass},
@@ -269,9 +276,42 @@ static int tenthdb2mixer(int db)
return -db * 2 / 5;
}
+#elif defined(HAVE_WM8975) /* volume/balance/treble/bass interdependency */
+#define VOLUME_MIN -730
+#define VOLUME_MAX 60
+
+/* convert tenth of dB volume (-730..60) to master volume register value */
+static int tenthdb2master(int db)
+{
+ /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
+ /* 1111111 == +6dB (0x7f) */
+ /* 1111001 == 0dB (0x79) */
+ /* 0110000 == -73dB (0x30 */
+ /* 0101111 == mute (0x2f) */
+
+ if (db <= -730) {
+ return 0x2f;
+ } else {
+ return((db/10)+74+0x2f);
+ }
+}
+
+/* convert tenth of dB volume (-780..0) to mixer volume register value */
+static int tenthdb2mixer(int db)
+{
+ if (db < -660) /* 1.5 dB steps */
+ return (2640 - db) / 15;
+ else if (db < -600) /* 0.75 dB steps */
+ return (990 - db) * 2 / 15;
+ else if (db < -460) /* 0.5 dB steps */
+ return (460 - db) / 5;
+ else /* 0.25 dB steps */
+ return -db * 2 / 5;
+}
+
#endif
-#if (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380
+#if (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 || defined HAVE_WM8975
/* volume/balance/treble/bass interdependency main part */
#define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN)
@@ -299,8 +339,10 @@ static void set_prescaled_volume(void)
#if CONFIG_CODEC == MAS3507D
mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]);
-#else /* UDA1380 */
+#elif defined(HAVE_UDA1380)
uda1380_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale));
+#elif defined(HAVE_WM8975)
+ wm8975_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale));
#endif
if (current_volume == VOLUME_MIN)
@@ -323,8 +365,10 @@ static void set_prescaled_volume(void)
#if CONFIG_CODEC == MAS3507D
dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
-#else /* UDA1380 */
+#elif defined(HAVE_UDA1380)
uda1380_set_master_vol(tenthdb2master(l), tenthdb2master(r));
+#elif defined(HAVE_WM8975)
+ wm8975_set_master_vol(tenthdb2master(l), tenthdb2master(r));
#endif
}
#endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
@@ -424,12 +468,9 @@ void sound_set_volume(int value)
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
unsigned tmp = ((unsigned)(value + 115) & 0xff) << 8;
mas_codec_writereg(0x10, tmp);
-#elif (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380
+#elif (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 || defined HAVE_WM8975
current_volume = value * 10; /* tenth of dB */
set_prescaled_volume();
-#elif (CONFIG_CPU == PP5020)
- /* TODO: Implement sound_set_volume() */
- (void)value;
#endif
}
@@ -440,12 +481,9 @@ void sound_set_balance(int value)
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
unsigned tmp = ((unsigned)(value * 127 / 100) & 0xff) << 8;
mas_codec_writereg(0x11, tmp);
-#elif CONFIG_CODEC == MAS3507D || defined HAVE_UDA1380
+#elif CONFIG_CODEC == MAS3507D || defined HAVE_UDA1380 || defined HAVE_WM8975
current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */
set_prescaled_volume();
-#elif (CONFIG_CPU == PP5020)
- /* TODO: Implement sound_set_balance() */
- (void)value;
#endif
}
@@ -464,9 +502,10 @@ void sound_set_bass(int value)
uda1380_set_bass(value >> 1);
current_bass = value * 10;
set_prescaled_volume();
-#elif (CONFIG_CPU == PP5020)
- /* TODO: Implement sound_set_bass() */
- (void)value;
+#elif defined(HAVE_WM8975)
+ current_bass = value * 10;
+ wm8975_set_bass(value);
+ set_prescaled_volume();
#endif
}
@@ -485,9 +524,10 @@ void sound_set_treble(int value)
uda1380_set_treble(value >> 1);
current_treble = value * 10;
set_prescaled_volume();
-#elif (CONFIG_CPU == PP5020)
- /* TODO: Implement sound_set_treble() */
- (void)value;
+#elif defined(HAVE_WM8975)
+ wm8975_set_treble(value);
+ current_treble = value * 10;
+ set_prescaled_volume();
#endif
}