summaryrefslogtreecommitdiff
path: root/firmware/sound.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/sound.c')
-rw-r--r--firmware/sound.c53
1 files changed, 38 insertions, 15 deletions
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 */
176enum {
177 DSP_CALLBACK_SET_PRESCALE = 0,
178 DSP_CALLBACK_SET_BASS,
179 DSP_CALLBACK_SET_TREBLE
180};
181
182static int (*dsp_callback)(int, intptr_t) = NULL;
183
184void 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
294static void set_prescaled_volume(void) 315static 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
488void sound_set_bass(int value) 504void 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
541void sound_set_channels(int value) 564void sound_set_channels(int value)
542{ 565{