diff options
author | Thom Johansen <thomj@rockbox.org> | 2007-02-26 00:41:26 +0000 |
---|---|---|
committer | Thom Johansen <thomj@rockbox.org> | 2007-02-26 00:41:26 +0000 |
commit | a7fabf0741c91fb0a2c28b2d8357bcc4630300af (patch) | |
tree | e1528a67f63933aa23ebb7b5d809e1ce7e60b589 /firmware | |
parent | 1915c1099431294ca9c43bc11fb1bfa41bbd83cc (diff) | |
download | rockbox-a7fabf0741c91fb0a2c28b2d8357bcc4630300af.tar.gz rockbox-a7fabf0741c91fb0a2c28b2d8357bcc4630300af.zip |
Add software based bass/treble controls for targets which have no such functionality in hardware (currently only X5). They can also be used on any other SWCODEC target by adding #define HAVE_SW_TONE_CONTROLS in the relevant config-*.h file. Also remove some now unneeded zero checks when using get_replaygain_int(). Comments on sound quality are welcome as some parameters can still be fine-tuned.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12489 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/export/config-iaudiox5.h | 3 | ||||
-rw-r--r-- | firmware/export/sound.h | 2 | ||||
-rw-r--r-- | firmware/sound.c | 53 |
3 files changed, 43 insertions, 15 deletions
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h index 6aeaab0431..ba9e95398f 100644 --- a/firmware/export/config-iaudiox5.h +++ b/firmware/export/config-iaudiox5.h | |||
@@ -84,6 +84,9 @@ | |||
84 | 84 | ||
85 | #define HAVE_TLV320 | 85 | #define HAVE_TLV320 |
86 | 86 | ||
87 | /* TLV320 has no tone controls, so we use the software ones */ | ||
88 | #define HAVE_SW_TONE_CONTROLS | ||
89 | |||
87 | #ifndef SIMULATOR | 90 | #ifndef SIMULATOR |
88 | 91 | ||
89 | /* Define this if your LCD can set contrast */ | 92 | /* Define this if your LCD can set contrast */ |
diff --git a/firmware/export/sound.h b/firmware/export/sound.h index 2079a84f0f..192384031d 100644 --- a/firmware/export/sound.h +++ b/firmware/export/sound.h | |||
@@ -19,6 +19,7 @@ | |||
19 | #ifndef SOUND_H | 19 | #ifndef SOUND_H |
20 | #define SOUND_H | 20 | #define SOUND_H |
21 | 21 | ||
22 | #include <inttypes.h> | ||
22 | #ifdef HAVE_UDA1380 | 23 | #ifdef HAVE_UDA1380 |
23 | #include "uda1380.h" | 24 | #include "uda1380.h" |
24 | #elif defined(HAVE_WM8975) || defined(HAVE_WM8751) | 25 | #elif defined(HAVE_WM8975) || defined(HAVE_WM8751) |
@@ -76,6 +77,7 @@ int sound_max(int setting); | |||
76 | int sound_default(int setting); | 77 | int sound_default(int setting); |
77 | sound_set_type* sound_get_fn(int setting); | 78 | sound_set_type* sound_get_fn(int setting); |
78 | 79 | ||
80 | void sound_set_dsp_callback(int (*func)(int, intptr_t)); | ||
79 | void sound_set_volume(int value); | 81 | void sound_set_volume(int value); |
80 | void sound_set_balance(int value); | 82 | void sound_set_balance(int value); |
81 | void sound_set_bass(int value); | 83 | void sound_set_bass(int value); |
diff --git a/firmware/sound.c b/firmware/sound.c index c3679d41f2..a2b4e96e81 100644 --- a/firmware/sound.c +++ b/firmware/sound.c | |||
@@ -87,6 +87,11 @@ static const struct sound_settings_info sound_settings_table[] = { | |||
87 | [SOUND_BASS] = {"dB", 0, 1, -15, 15, 7, sound_set_bass}, | 87 | [SOUND_BASS] = {"dB", 0, 1, -15, 15, 7, sound_set_bass}, |
88 | [SOUND_TREBLE] = {"dB", 0, 1, -15, 15, 7, sound_set_treble}, | 88 | [SOUND_TREBLE] = {"dB", 0, 1, -15, 15, 7, sound_set_treble}, |
89 | #endif | 89 | #endif |
90 | /* Override any other potentially existing treble/bass controllers if wanted */ | ||
91 | #ifdef HAVE_SW_TONE_CONTROLS | ||
92 | [SOUND_BASS] = {"dB", 0, 1, -24, 24, 0, sound_set_bass}, | ||
93 | [SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0, sound_set_treble}, | ||
94 | #endif | ||
90 | [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0, sound_set_balance}, | 95 | [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0, sound_set_balance}, |
91 | [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0, sound_set_channels}, | 96 | [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0, sound_set_channels}, |
92 | [SOUND_STEREO_WIDTH] = {"%", 0, 1, 0, 255, 100, sound_set_stereo_width}, | 97 | [SOUND_STEREO_WIDTH] = {"%", 0, 1, 0, 255, 100, sound_set_stereo_width}, |
@@ -166,6 +171,22 @@ sound_set_type* sound_get_fn(int setting) | |||
166 | return NULL; | 171 | return NULL; |
167 | } | 172 | } |
168 | 173 | ||
174 | #ifdef HAVE_SW_TONE_CONTROLS | ||
175 | /* Copied from dsp.h, nasty nasty, but we don't want to include dsp.h */ | ||
176 | enum { | ||
177 | DSP_CALLBACK_SET_PRESCALE = 0, | ||
178 | DSP_CALLBACK_SET_BASS, | ||
179 | DSP_CALLBACK_SET_TREBLE | ||
180 | }; | ||
181 | |||
182 | static int (*dsp_callback)(int, intptr_t) = NULL; | ||
183 | |||
184 | void sound_set_dsp_callback(int (*func)(int, intptr_t)) | ||
185 | { | ||
186 | dsp_callback = func; | ||
187 | } | ||
188 | #endif | ||
189 | |||
169 | #ifndef SIMULATOR | 190 | #ifndef SIMULATOR |
170 | #if CONFIG_CODEC == MAS3507D /* volume/balance/treble/bass interdependency */ | 191 | #if CONFIG_CODEC == MAS3507D /* volume/balance/treble/bass interdependency */ |
171 | #define VOLUME_MIN -780 | 192 | #define VOLUME_MIN -780 |
@@ -293,10 +314,9 @@ int current_bass = 0; /* -150..+150 0..+240 */ | |||
293 | 314 | ||
294 | static void set_prescaled_volume(void) | 315 | static void set_prescaled_volume(void) |
295 | { | 316 | { |
296 | int prescale = 0; | 317 | int prescale; |
297 | int l, r; | 318 | int l, r; |
298 | 319 | ||
299 | #ifndef HAVE_TLV320 | ||
300 | prescale = MAX(current_bass, current_treble); | 320 | prescale = MAX(current_bass, current_treble); |
301 | if (prescale < 0) | 321 | if (prescale < 0) |
302 | prescale = 0; /* no need to prescale if we don't boost | 322 | prescale = 0; /* no need to prescale if we don't boost |
@@ -307,13 +327,12 @@ static void set_prescaled_volume(void) | |||
307 | * instead (might cause clipping). */ | 327 | * instead (might cause clipping). */ |
308 | if (current_volume + prescale > VOLUME_MAX) | 328 | if (current_volume + prescale > VOLUME_MAX) |
309 | prescale = VOLUME_MAX - current_volume; | 329 | prescale = VOLUME_MAX - current_volume; |
310 | #endif | 330 | |
311 | 331 | #if defined(HAVE_SW_TONE_CONTROLS) | |
312 | #if CONFIG_CODEC == MAS3507D | 332 | dsp_callback(DSP_CALLBACK_SET_PRESCALE, prescale); |
333 | #elif CONFIG_CODEC == MAS3507D | ||
313 | mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]); | 334 | mas_writereg(MAS_REG_KPRESCALE, prescale_table[prescale/10]); |
314 | #elif defined(HAVE_UDA1380) | 335 | #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \ |
315 | audiohw_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale)); | ||
316 | #elif defined(HAVE_WM8975) || defined(HAVE_WM8758) \ | ||
317 | || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751) | 336 | || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751) |
318 | audiohw_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale)); | 337 | audiohw_set_mixer_vol(tenthdb2mixer(-prescale), tenthdb2mixer(-prescale)); |
319 | #endif | 338 | #endif |
@@ -338,9 +357,7 @@ static void set_prescaled_volume(void) | |||
338 | 357 | ||
339 | #if CONFIG_CODEC == MAS3507D | 358 | #if CONFIG_CODEC == MAS3507D |
340 | dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); | 359 | dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); |
341 | #elif defined(HAVE_UDA1380) | 360 | #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \ |
342 | audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r)); | ||
343 | #elif defined(HAVE_WM8975) || defined(HAVE_WM8758) \ | ||
344 | || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751) | 361 | || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751) |
345 | audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r)); | 362 | audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r)); |
346 | #if defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_WM8751) | 363 | #if defined(HAVE_WM8975) || defined(HAVE_WM8758) || defined(HAVE_WM8751) |
@@ -484,12 +501,15 @@ void sound_set_balance(int value) | |||
484 | #endif | 501 | #endif |
485 | } | 502 | } |
486 | 503 | ||
487 | #ifndef HAVE_TLV320 | ||
488 | void sound_set_bass(int value) | 504 | void sound_set_bass(int value) |
489 | { | 505 | { |
490 | if(!audio_is_initialized) | 506 | if(!audio_is_initialized) |
491 | return; | 507 | return; |
492 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | 508 | #if defined(HAVE_SW_TONE_CONTROLS) |
509 | current_bass = value * 10; | ||
510 | dsp_callback(DSP_CALLBACK_SET_BASS, current_bass); | ||
511 | set_prescaled_volume(); | ||
512 | #elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
493 | unsigned tmp = ((unsigned)(value * 8) & 0xff) << 8; | 513 | unsigned tmp = ((unsigned)(value * 8) & 0xff) << 8; |
494 | mas_codec_writereg(0x14, tmp); | 514 | mas_codec_writereg(0x14, tmp); |
495 | #elif CONFIG_CODEC == MAS3507D | 515 | #elif CONFIG_CODEC == MAS3507D |
@@ -515,7 +535,11 @@ void sound_set_treble(int value) | |||
515 | { | 535 | { |
516 | if(!audio_is_initialized) | 536 | if(!audio_is_initialized) |
517 | return; | 537 | return; |
518 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | 538 | #if defined(HAVE_SW_TONE_CONTROLS) |
539 | current_treble = value * 10; | ||
540 | dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble); | ||
541 | set_prescaled_volume(); | ||
542 | #elif (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
519 | unsigned tmp = ((unsigned)(value * 8) & 0xff) << 8; | 543 | unsigned tmp = ((unsigned)(value * 8) & 0xff) << 8; |
520 | mas_codec_writereg(0x15, tmp); | 544 | mas_codec_writereg(0x15, tmp); |
521 | #elif CONFIG_CODEC == MAS3507D | 545 | #elif CONFIG_CODEC == MAS3507D |
@@ -536,7 +560,6 @@ void sound_set_treble(int value) | |||
536 | (void)value; | 560 | (void)value; |
537 | #endif | 561 | #endif |
538 | } | 562 | } |
539 | #endif /* HAVE_TLV320 */ | ||
540 | 563 | ||
541 | void sound_set_channels(int value) | 564 | void sound_set_channels(int value) |
542 | { | 565 | { |