summaryrefslogtreecommitdiffstats
path: root/firmware/sound.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2010-05-15 13:09:45 +0000
committerMichael Sevakis <jethead71@rockbox.org>2010-05-15 13:09:45 +0000
commit80d0d15ca9b253f8a446f50cf25d3d4b850bcfd1 (patch)
tree2598d3a019c33d6f9ea76010fd6d3a8301ef87a0 /firmware/sound.c
parent0f77db73469920f0b0006f696ddb36029338c378 (diff)
downloadrockbox-80d0d15ca9b253f8a446f50cf25d3d4b850bcfd1.tar.gz
rockbox-80d0d15ca9b253f8a446f50cf25d3d4b850bcfd1.tar.bz2
rockbox-80d0d15ca9b253f8a446f50cf25d3d4b850bcfd1.zip
Gigabeat S: Fully enable access to hardware tone controls and 3-D effect feature. Under the hood, it's designated a hardware equalizer since it is one. Implement code framework for hardware EQ in general. Menu aspect is well abstracted and so the UI and strings can be changed around if taste doesn't quite suit. So far the emphasis is distinction of the UI labelling from the software EQ so that it's clear the settings are for a different thing.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26051 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/sound.c')
-rw-r--r--firmware/sound.c347
1 files changed, 334 insertions, 13 deletions
diff --git a/firmware/sound.c b/firmware/sound.c
index b56e610034..fb2f353d71 100644
--- a/firmware/sound.c
+++ b/firmware/sound.c
@@ -48,8 +48,13 @@ extern void audiohw_set_volume(int value);
/* dummy for sim */
const struct sound_settings_info audiohw_settings[] = {
[SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25},
+/* Bass and treble tone controls */
+#ifdef AUDIOHW_HAVE_BASS
[SOUND_BASS] = {"dB", 0, 1, -24, 24, 0},
+#endif
+#ifdef AUDIOHW_HAVE_TREBLE
[SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0},
+#endif
[SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
[SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
[SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
@@ -64,6 +69,50 @@ const struct sound_settings_info audiohw_settings[] = {
#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
[SOUND_TREBLE_CUTOFF] = {"", 0, 1, 1, 4, 1},
#endif
+#if defined(AUDIOHW_HAVE_DEPTH_3D)
+ [SOUND_DEPTH_3D] = {"%", 0, 1, 0, 15, 0},
+#endif
+/* Hardware EQ tone controls */
+#if defined(AUDIOHW_HAVE_EQ_BAND1)
+ [SOUND_EQ_BAND1_GAIN] = {"dB", 0, 1, -12, 12, 0},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND2)
+ [SOUND_EQ_BAND2_GAIN] = {"dB", 0, 1, -12, 12, 0},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND3)
+ [SOUND_EQ_BAND3_GAIN] = {"dB", 0, 1, -12, 12, 0},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND4)
+ [SOUND_EQ_BAND4_GAIN] = {"dB", 0, 1, -12, 12, 0},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND5)
+ [SOUND_EQ_BAND5_GAIN] = {"dB", 0, 1, -12, 12, 0},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
+ [SOUND_EQ_BAND1_FREQUENCY] = {"", 0, 1, 1, 4, 1},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
+ [SOUND_EQ_BAND2_FREQUENCY] = {"", 0, 1, 1, 4, 1},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
+ [SOUND_EQ_BAND3_FREQUENCY] = {"", 0, 1, 1, 4, 1},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
+ [SOUND_EQ_BAND4_FREQUENCY] = {"", 0, 1, 1, 4, 1},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
+ [SOUND_EQ_BAND5_FREQUENCY] = {"", 0, 1, 1, 4, 1},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
+ [SOUND_EQ_BAND2_WIDTH] = {"", 0, 1, 0, 1, 0},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
+ [SOUND_EQ_BAND3_WIDTH] = {"", 0, 1, 0, 1, 0},
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
+ [SOUND_EQ_BAND4_WIDTH] = {"", 0, 1, 0, 1, 0},
+#endif
+
#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
[SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0},
[SOUND_AVC] = {"", 0, 1, -1, 4, 0},
@@ -111,8 +160,12 @@ static sound_set_type * const sound_set_fns[] =
{
[0 ... SOUND_LAST_SETTING-1] = NULL,
[SOUND_VOLUME] = sound_set_volume,
+#if defined(AUDIOHW_HAVE_BASS)
[SOUND_BASS] = sound_set_bass,
+#endif
+#if defined(AUDIOHW_HAVE_TREBLE)
[SOUND_TREBLE] = sound_set_treble,
+#endif
[SOUND_BALANCE] = sound_set_balance,
[SOUND_CHANNELS] = sound_set_channels,
[SOUND_STEREO_WIDTH] = sound_set_stereo_width,
@@ -132,6 +185,49 @@ static sound_set_type * const sound_set_fns[] =
#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
[SOUND_TREBLE_CUTOFF] = sound_set_treble_cutoff,
#endif
+#if defined(AUDIOHW_HAVE_DEPTH_3D)
+ [SOUND_DEPTH_3D] = sound_set_depth_3d,
+#endif
+/* Hardware EQ tone controls */
+#if defined(AUDIOHW_HAVE_EQ)
+ [SOUND_EQ_BAND1_GAIN] = sound_set_hw_eq_band1_gain,
+#if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
+ [SOUND_EQ_BAND1_FREQUENCY] = sound_set_hw_eq_band1_frequency,
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND2)
+ [SOUND_EQ_BAND2_GAIN] = sound_set_hw_eq_band2_gain,
+#if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
+ [SOUND_EQ_BAND2_FREQUENCY] = sound_set_hw_eq_band2_frequency,
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
+ [SOUND_EQ_BAND2_WIDTH] = sound_set_hw_eq_band2_width,
+#endif
+#endif /* AUDIOHW_HAVE_EQ_BAND2 */
+#if defined(AUDIOHW_HAVE_EQ_BAND3)
+ [SOUND_EQ_BAND3_GAIN] = sound_set_hw_eq_band3_gain,
+#if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
+ [SOUND_EQ_BAND3_FREQUENCY] = sound_set_hw_eq_band3_frequency,
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
+ [SOUND_EQ_BAND3_WIDTH] = sound_set_hw_eq_band3_width,
+#endif
+#endif /* AUDIOHW_HAVE_EQ_BAND3 */
+#if defined(AUDIOHW_HAVE_EQ_BAND4)
+ [SOUND_EQ_BAND4_GAIN] = sound_set_hw_eq_band4_gain,
+#if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
+ [SOUND_EQ_BAND4_FREQUENCY] = sound_set_hw_eq_band4_frequency,
+#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
+ [SOUND_EQ_BAND4_WIDTH] = sound_set_hw_eq_band4_width,
+#endif
+#endif /* AUDIOHW_HAVE_EQ_BAND4 */
+#if defined(AUDIOHW_HAVE_EQ_BAND5)
+ [SOUND_EQ_BAND5_GAIN] = sound_set_hw_eq_band5_gain,
+#if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
+ [SOUND_EQ_BAND5_FREQUENCY] = sound_set_hw_eq_band5_frequency,
+#endif
+#endif /* AUDIOHW_HAVE_EQ_BAND5 */
+#endif /* AUDIOHW_HAVE_EQ */
};
sound_set_type* sound_get_fn(int setting)
@@ -174,8 +270,15 @@ static int tenthdb2reg(int db)
/* all values in tenth of dB MAS3507D UDA1380 */
int current_volume = 0; /* -780..+180 -840.. 0 */
int current_balance = 0; /* -960..+960 -840..+840 */
+#ifdef AUDIOHW_HAVE_TREBLE
int current_treble = 0; /* -150..+150 0.. +60 */
+#endif
+#ifdef AUDIOHW_HAVE_BASS
int current_bass = 0; /* -150..+150 0..+240 */
+#endif
+#ifdef AUDIOHW_HAVE_EQ
+int current_eq_band_gain[AUDIOHW_EQ_BAND_NUM];
+#endif
static void set_prescaled_volume(void)
{
@@ -191,10 +294,18 @@ static void set_prescaled_volume(void)
|| defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
|| defined(HAVE_WM8758) || defined(HAVE_WM8985) || defined(HAVE_UDA1341))
+#if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE)
prescale = MAX(current_bass, current_treble);
+#endif
+#if defined(AUDIOHW_HAVE_EQ)
+ int i;
+ for (i = 0; i < AUDIOHW_EQ_BAND_NUM; i++)
+ prescale = MAX(current_eq_band_gain[i], prescale);
+#endif
+
if (prescale < 0)
prescale = 0; /* no need to prescale if we don't boost
- bass or treble */
+ bass, treble or eq band */
/* Gain up the analog volume to compensate the prescale gain reduction,
* but if this would push the volume over the top, reduce prescaling
@@ -289,6 +400,7 @@ void sound_set_balance(int value)
#endif
}
+#ifdef AUDIOHW_HAVE_BASS
void sound_set_bass(int value)
{
if(!audio_is_initialized)
@@ -302,17 +414,19 @@ void sound_set_bass(int value)
#endif
#endif
-#if defined(AUDIOHW_HAVE_BASS)
- audiohw_set_bass(value);
-#else
+#if defined(HAVE_SW_TONE_CONTROLS)
dsp_callback(DSP_CALLBACK_SET_BASS, current_bass);
+#else
+ audiohw_set_bass(value);
#endif
#if !defined(AUDIOHW_HAVE_CLIPPING)
set_prescaled_volume();
#endif
}
+#endif /* AUDIOHW_HAVE_BASS */
+#ifdef AUDIOHW_HAVE_TREBLE
void sound_set_treble(int value)
{
if(!audio_is_initialized)
@@ -326,16 +440,37 @@ void sound_set_treble(int value)
#endif
#endif
-#if defined(AUDIOHW_HAVE_TREBLE)
- audiohw_set_treble(value);
-#else
+#if defined(HAVE_SW_TONE_CONTROLS)
dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble);
+#else
+ audiohw_set_treble(value);
#endif
#if !defined(AUDIOHW_HAVE_CLIPPING)
set_prescaled_volume();
#endif
}
+#endif /* AUDIOHW_HAVE_TREBLE */
+
+#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
+void sound_set_bass_cutoff(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_bass_cutoff(value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
+void sound_set_treble_cutoff(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_treble_cutoff(value);
+}
+#endif
void sound_set_channels(int value)
{
@@ -361,26 +496,208 @@ void sound_set_stereo_width(int value)
#endif
}
-#if defined(AUDIOHW_HAVE_BASS_CUTOFF)
-void sound_set_bass_cutoff(int value)
+#if defined(AUDIOHW_HAVE_DEPTH_3D)
+void sound_set_depth_3d(int value)
{
if(!audio_is_initialized)
return;
- audiohw_set_bass_cutoff(value);
+ audiohw_set_depth_3d(value);
}
#endif
-#if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
-void sound_set_treble_cutoff(int value)
+#if defined(AUDIOHW_HAVE_EQ)
+int sound_enum_hw_eq_band_setting(unsigned int band,
+ unsigned int band_setting)
+{
+ static const int8_t
+ sound_hw_eq_band_setting[AUDIOHW_EQ_SETTING_NUM][AUDIOHW_EQ_BAND_NUM] =
+ {
+ [AUDIOHW_EQ_GAIN] =
+ {
+ [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
+ [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_GAIN,
+ #ifdef AUDIOHW_HAVE_EQ_BAND2
+ [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_GAIN,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND3
+ [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_GAIN,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND4
+ [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_GAIN,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND5
+ [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_GAIN,
+ #endif
+ },
+#ifdef AUDIOHW_HAVE_EQ_FREQUENCY
+ [AUDIOHW_EQ_FREQUENCY] =
+ {
+ [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
+ #ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
+ [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_FREQUENCY,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
+ [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_FREQUENCY,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
+ [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_FREQUENCY,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
+ [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_FREQUENCY,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
+ [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_FREQUENCY,
+ #endif
+ },
+#endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
+#ifdef AUDIOHW_HAVE_EQ_WIDTH
+ [AUDIOHW_EQ_WIDTH] =
+ {
+ [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
+ #ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
+ [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_WIDTH,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
+ [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_WIDTH,
+ #endif
+ #ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
+ [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_WIDTH,
+ #endif
+ },
+#endif /* AUDIOHW_HAVE_EQ_WIDTH */
+ };
+
+ if (band < AUDIOHW_EQ_BAND_NUM && band_setting < AUDIOHW_EQ_SETTING_NUM)
+ return sound_hw_eq_band_setting[band_setting][band];
+
+ return -1;
+}
+
+static void sound_set_hw_eq_band_gain(unsigned int band, int value)
{
if(!audio_is_initialized)
return;
- audiohw_set_treble_cutoff(value);
+ current_eq_band_gain[band] = value;
+ audiohw_set_eq_band_gain(band, value);
+ set_prescaled_volume();
+}
+
+void sound_set_hw_eq_band1_gain(int value)
+{
+ sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND1, value);
+}
+
+#if defined(AUDIOHW_HAVE_EQ_BAND2)
+void sound_set_hw_eq_band2_gain(int value)
+{
+ sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND2, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND3)
+void sound_set_hw_eq_band3_gain(int value)
+{
+ sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND3, value);
}
#endif
+#if defined(AUDIOHW_HAVE_EQ_BAND4)
+void sound_set_hw_eq_band4_gain(int value)
+{
+ sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND4, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND5)
+void sound_set_hw_eq_band5_gain(int value)
+{
+ sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND5, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
+void sound_set_hw_eq_band1_frequency(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
+void sound_set_hw_eq_band2_frequency(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
+void sound_set_hw_eq_band3_frequency(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
+void sound_set_hw_eq_band4_frequency(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
+void sound_set_hw_eq_band5_frequency(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
+void sound_set_hw_eq_band2_width(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
+void sound_set_hw_eq_band3_width(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value);
+}
+#endif
+
+#if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
+void sound_set_hw_eq_band4_width(int value)
+{
+ if(!audio_is_initialized)
+ return;
+
+ audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value);
+}
+#endif
+#endif /* AUDIOHW_HAVE_EQ */
+
#if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))
void sound_set_loudness(int value)
{
@@ -572,6 +889,10 @@ int sound_val2phys(int setting, int value)
break;
#endif
+ case SOUND_DEPTH_3D:
+ result = (100 * value + 8) / 15;
+ break;
+
default:
result = value;
}