1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
11 * Copyright (C) 2007 by Christian Gmeiner
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
30 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
31 #if CONFIG_CPU == PNX0101
35 #if CONFIG_CODEC == SWCODEC
41 * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble
44 extern bool audio_is_initialized
;
46 const char *sound_unit(int setting
)
48 return audiohw_settings
[setting
].unit
;
51 int sound_numdecimals(int setting
)
53 return audiohw_settings
[setting
].numdecimals
;
56 int sound_steps(int setting
)
58 return audiohw_settings
[setting
].steps
;
61 int sound_min(int setting
)
63 return audiohw_settings
[setting
].minval
;
66 int sound_max(int setting
)
68 return audiohw_settings
[setting
].maxval
;
71 int sound_default(int setting
)
73 return audiohw_settings
[setting
].defaultval
;
76 static sound_set_type
* const sound_set_fns
[] =
78 [0 ... SOUND_LAST_SETTING
-1] = NULL
,
79 [SOUND_VOLUME
] = sound_set_volume
,
80 #if defined(AUDIOHW_HAVE_BASS)
81 [SOUND_BASS
] = sound_set_bass
,
83 #if defined(AUDIOHW_HAVE_TREBLE)
84 [SOUND_TREBLE
] = sound_set_treble
,
86 [SOUND_BALANCE
] = sound_set_balance
,
87 [SOUND_CHANNELS
] = sound_set_channels
,
88 [SOUND_STEREO_WIDTH
] = sound_set_stereo_width
,
89 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
90 [SOUND_LOUDNESS
] = sound_set_loudness
,
91 [SOUND_AVC
] = sound_set_avc
,
92 [SOUND_MDB_STRENGTH
] = sound_set_mdb_strength
,
93 [SOUND_MDB_HARMONICS
] = sound_set_mdb_harmonics
,
94 [SOUND_MDB_CENTER
] = sound_set_mdb_center
,
95 [SOUND_MDB_SHAPE
] = sound_set_mdb_shape
,
96 [SOUND_MDB_ENABLE
] = sound_set_mdb_enable
,
97 [SOUND_SUPERBASS
] = sound_set_superbass
,
98 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
99 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
100 [SOUND_BASS_CUTOFF
] = sound_set_bass_cutoff
,
102 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
103 [SOUND_TREBLE_CUTOFF
] = sound_set_treble_cutoff
,
105 #if defined(AUDIOHW_HAVE_DEPTH_3D)
106 [SOUND_DEPTH_3D
] = sound_set_depth_3d
,
108 /* Hardware EQ tone controls */
109 #if defined(AUDIOHW_HAVE_EQ)
110 [SOUND_EQ_BAND1_GAIN
] = sound_set_hw_eq_band1_gain
,
111 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
112 [SOUND_EQ_BAND1_FREQUENCY
] = sound_set_hw_eq_band1_frequency
,
114 #if defined(AUDIOHW_HAVE_EQ_BAND2)
115 [SOUND_EQ_BAND2_GAIN
] = sound_set_hw_eq_band2_gain
,
116 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
117 [SOUND_EQ_BAND2_FREQUENCY
] = sound_set_hw_eq_band2_frequency
,
119 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
120 [SOUND_EQ_BAND2_WIDTH
] = sound_set_hw_eq_band2_width
,
122 #endif /* AUDIOHW_HAVE_EQ_BAND2 */
123 #if defined(AUDIOHW_HAVE_EQ_BAND3)
124 [SOUND_EQ_BAND3_GAIN
] = sound_set_hw_eq_band3_gain
,
125 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
126 [SOUND_EQ_BAND3_FREQUENCY
] = sound_set_hw_eq_band3_frequency
,
128 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
129 [SOUND_EQ_BAND3_WIDTH
] = sound_set_hw_eq_band3_width
,
131 #endif /* AUDIOHW_HAVE_EQ_BAND3 */
132 #if defined(AUDIOHW_HAVE_EQ_BAND4)
133 [SOUND_EQ_BAND4_GAIN
] = sound_set_hw_eq_band4_gain
,
134 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
135 [SOUND_EQ_BAND4_FREQUENCY
] = sound_set_hw_eq_band4_frequency
,
137 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
138 [SOUND_EQ_BAND4_WIDTH
] = sound_set_hw_eq_band4_width
,
140 #endif /* AUDIOHW_HAVE_EQ_BAND4 */
141 #if defined(AUDIOHW_HAVE_EQ_BAND5)
142 [SOUND_EQ_BAND5_GAIN
] = sound_set_hw_eq_band5_gain
,
143 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
144 [SOUND_EQ_BAND5_FREQUENCY
] = sound_set_hw_eq_band5_frequency
,
146 #endif /* AUDIOHW_HAVE_EQ_BAND5 */
147 #endif /* AUDIOHW_HAVE_EQ */
150 sound_set_type
* sound_get_fn(int setting
)
152 return ((unsigned)setting
>= ARRAYLEN(sound_set_fns
)?
153 NULL
: sound_set_fns
[setting
]);
156 #if CONFIG_CODEC == SWCODEC
157 static int (*dsp_callback
)(int, intptr_t) = NULL
;
159 void sound_set_dsp_callback(int (*func
)(int, intptr_t))
165 #if (CONFIG_CODEC == MAS3507D) && !defined(SIMULATOR)
166 /* convert tenth of dB volume (-780..+180) to dac3550 register value */
167 static int tenthdb2reg(int db
)
169 if (db
< -540) /* 3 dB steps */
170 return (db
+ 780) / 30;
171 else /* 1.5 dB steps */
172 return (db
+ 660) / 15;
177 #if !defined(AUDIOHW_HAVE_CLIPPING)
179 * The prescaler compensates for any kind of boosts, to prevent clipping.
181 * It's basically just a measure to make sure that audio does not clip during
182 * tone controls processing, like if i want to boost bass 12 dB, i can decrease
183 * the audio amplitude by -12 dB before processing, then increase master gain
184 * by 12 dB after processing.
187 /* all values in tenth of dB MAS3507D UDA1380 */
188 static int current_volume
= 0; /* -780..+180 -840.. 0 */
189 static int current_balance
= 0; /* -960..+960 -840..+840 */
190 #ifdef AUDIOHW_HAVE_TREBLE
191 static int current_treble
= 0; /* -150..+150 0.. +60 */
193 #ifdef AUDIOHW_HAVE_BASS
194 static int current_bass
= 0; /* -150..+150 0..+240 */
196 #ifdef AUDIOHW_HAVE_EQ
197 static int current_eq_band_gain
[AUDIOHW_EQ_BAND_NUM
];
200 static void set_prescaled_volume(void)
205 /* The codecs listed use HW tone controls but don't have suitable prescaler
206 * functionality, so we let the prescaler stay at 0 for these, unless
207 * SW tone controls are in use. This is to avoid needing the SW DSP just for
210 #if defined(HAVE_SW_TONE_CONTROLS) || !(defined(HAVE_WM8975) \
211 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
212 || defined(HAVE_WM8758) || defined(HAVE_WM8985) || defined(HAVE_UDA1341))
214 #if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE)
215 prescale
= MAX(current_bass
, current_treble
);
217 #if defined(AUDIOHW_HAVE_EQ)
219 for (i
= 0; i
< AUDIOHW_EQ_BAND_NUM
; i
++)
220 prescale
= MAX(current_eq_band_gain
[i
], prescale
);
224 prescale
= 0; /* no need to prescale if we don't boost
225 bass, treble or eq band */
227 /* Gain up the analog volume to compensate the prescale gain reduction,
228 * but if this would push the volume over the top, reduce prescaling
229 * instead (might cause clipping). */
230 if (current_volume
+ prescale
> VOLUME_MAX
)
231 prescale
= VOLUME_MAX
- current_volume
;
234 #if defined(AUDIOHW_HAVE_PRESCALER)
235 audiohw_set_prescaler(prescale
);
237 dsp_callback(DSP_CALLBACK_SET_PRESCALE
, prescale
);
240 if (current_volume
== VOLUME_MIN
)
241 prescale
= 0; /* Make sure the chip gets muted at VOLUME_MIN */
243 l
= r
= current_volume
+ prescale
;
245 /* Balance the channels scaled by the current volume and min volume. */
246 /* Subtract a dB from VOLUME_MIN to get it to a mute level */
247 if (current_balance
> 0)
249 l
-= ((l
- (VOLUME_MIN
- ONE_DB
)) * current_balance
) / VOLUME_RANGE
;
251 else if (current_balance
< 0)
253 r
+= ((r
- (VOLUME_MIN
- ONE_DB
)) * current_balance
) / VOLUME_RANGE
;
256 #ifdef HAVE_SW_VOLUME_CONTROL
257 dsp_callback(DSP_CALLBACK_SET_SW_VOLUME
, 0);
260 #ifndef HAVE_SDL_AUDIO
261 #if CONFIG_CODEC == MAS3507D
262 dac_volume(tenthdb2reg(l
), tenthdb2reg(r
), false);
263 #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
264 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
265 || defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_AS3514) \
266 || defined(HAVE_TSC2100) || defined(HAVE_AK4537) || defined(HAVE_UDA1341)
267 audiohw_set_master_vol(tenthdb2master(l
), tenthdb2master(r
));
268 #if defined(HAVE_WM8975) || defined(HAVE_WM8758) \
269 || defined(HAVE_WM8750) || (defined(HAVE_WM8751) && !defined(MROBE_100)) \
270 || defined(HAVE_WM8985)
271 audiohw_set_lineout_vol(tenthdb2master(0), tenthdb2master(0));
274 #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985)
275 audiohw_set_headphone_vol(tenthdb2master(l
), tenthdb2master(r
));
276 #elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
277 audiohw_set_volume(current_volume
);
279 #else /* HAVE_SDL_AUDIO */
280 audiohw_set_volume(current_volume
);
281 #endif /* !HAVE_SDL_AUDIO */
283 #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
286 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
287 static unsigned long mdb_shape_shadow
= 0;
288 static unsigned long loudness_shadow
= 0;
291 void sound_set_volume(int value
)
293 if(!audio_is_initialized
)
296 #if defined(AUDIOHW_HAVE_CLIPPING)
297 audiohw_set_volume(value
);
298 #elif CONFIG_CPU == PNX0101
299 int tmp
= (60 - value
* 4) & 0xff;
300 CODECVOL
= tmp
| (tmp
<< 8);
302 current_volume
= value
* 10; /* tenth of dB */
303 set_prescaled_volume();
307 void sound_set_balance(int value
)
309 if(!audio_is_initialized
)
312 #ifdef AUDIOHW_HAVE_BALANCE
313 audiohw_set_balance(value
);
315 current_balance
= value
* VOLUME_RANGE
/ 100; /* tenth of dB */
316 set_prescaled_volume();
320 #ifdef AUDIOHW_HAVE_BASS
321 void sound_set_bass(int value
)
323 if(!audio_is_initialized
)
326 #if !defined(AUDIOHW_HAVE_CLIPPING)
327 #if defined(HAVE_WM8750) || defined(HAVE_WM8751)
328 current_bass
= value
;
330 current_bass
= value
* 10;
334 #if defined(HAVE_SW_TONE_CONTROLS)
335 dsp_callback(DSP_CALLBACK_SET_BASS
, current_bass
);
337 audiohw_set_bass(value
);
340 #if !defined(AUDIOHW_HAVE_CLIPPING)
341 set_prescaled_volume();
344 #endif /* AUDIOHW_HAVE_BASS */
346 #ifdef AUDIOHW_HAVE_TREBLE
347 void sound_set_treble(int value
)
349 if(!audio_is_initialized
)
352 #if !defined(AUDIOHW_HAVE_CLIPPING)
353 #if defined(HAVE_WM8750) || defined(HAVE_WM8751)
354 current_treble
= value
;
356 current_treble
= value
* 10;
360 #if defined(HAVE_SW_TONE_CONTROLS)
361 dsp_callback(DSP_CALLBACK_SET_TREBLE
, current_treble
);
363 audiohw_set_treble(value
);
366 #if !defined(AUDIOHW_HAVE_CLIPPING)
367 set_prescaled_volume();
370 #endif /* AUDIOHW_HAVE_TREBLE */
372 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
373 void sound_set_bass_cutoff(int value
)
375 if(!audio_is_initialized
)
378 audiohw_set_bass_cutoff(value
);
382 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
383 void sound_set_treble_cutoff(int value
)
385 if(!audio_is_initialized
)
388 audiohw_set_treble_cutoff(value
);
392 void sound_set_channels(int value
)
394 if(!audio_is_initialized
)
397 #if CONFIG_CODEC == SWCODEC
398 dsp_callback(DSP_CALLBACK_SET_CHANNEL_CONFIG
, value
);
400 audiohw_set_channel(value
);
404 void sound_set_stereo_width(int value
)
406 if(!audio_is_initialized
)
409 #if CONFIG_CODEC == SWCODEC
410 dsp_callback(DSP_CALLBACK_SET_STEREO_WIDTH
, value
);
412 audiohw_set_stereo_width(value
);
416 #if defined(AUDIOHW_HAVE_DEPTH_3D)
417 void sound_set_depth_3d(int value
)
419 if(!audio_is_initialized
)
422 audiohw_set_depth_3d(value
);
426 #if defined(AUDIOHW_HAVE_EQ)
427 int sound_enum_hw_eq_band_setting(unsigned int band
,
428 unsigned int band_setting
)
431 sound_hw_eq_band_setting
[AUDIOHW_EQ_SETTING_NUM
][AUDIOHW_EQ_BAND_NUM
] =
435 [0 ... AUDIOHW_EQ_BAND_NUM
-1] = -1,
436 [AUDIOHW_EQ_BAND1
] = SOUND_EQ_BAND1_GAIN
,
437 #ifdef AUDIOHW_HAVE_EQ_BAND2
438 [AUDIOHW_EQ_BAND2
] = SOUND_EQ_BAND2_GAIN
,
440 #ifdef AUDIOHW_HAVE_EQ_BAND3
441 [AUDIOHW_EQ_BAND3
] = SOUND_EQ_BAND3_GAIN
,
443 #ifdef AUDIOHW_HAVE_EQ_BAND4
444 [AUDIOHW_EQ_BAND4
] = SOUND_EQ_BAND4_GAIN
,
446 #ifdef AUDIOHW_HAVE_EQ_BAND5
447 [AUDIOHW_EQ_BAND5
] = SOUND_EQ_BAND5_GAIN
,
450 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
451 [AUDIOHW_EQ_FREQUENCY
] =
453 [0 ... AUDIOHW_EQ_BAND_NUM
-1] = -1,
454 #ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
455 [AUDIOHW_EQ_BAND1
] = SOUND_EQ_BAND1_FREQUENCY
,
457 #ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
458 [AUDIOHW_EQ_BAND2
] = SOUND_EQ_BAND2_FREQUENCY
,
460 #ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
461 [AUDIOHW_EQ_BAND3
] = SOUND_EQ_BAND3_FREQUENCY
,
463 #ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
464 [AUDIOHW_EQ_BAND4
] = SOUND_EQ_BAND4_FREQUENCY
,
466 #ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
467 [AUDIOHW_EQ_BAND5
] = SOUND_EQ_BAND5_FREQUENCY
,
470 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
471 #ifdef AUDIOHW_HAVE_EQ_WIDTH
474 [0 ... AUDIOHW_EQ_BAND_NUM
-1] = -1,
475 #ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
476 [AUDIOHW_EQ_BAND2
] = SOUND_EQ_BAND2_WIDTH
,
478 #ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
479 [AUDIOHW_EQ_BAND3
] = SOUND_EQ_BAND3_WIDTH
,
481 #ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
482 [AUDIOHW_EQ_BAND4
] = SOUND_EQ_BAND4_WIDTH
,
485 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
488 if (band
< AUDIOHW_EQ_BAND_NUM
&& band_setting
< AUDIOHW_EQ_SETTING_NUM
)
489 return sound_hw_eq_band_setting
[band_setting
][band
];
494 static void sound_set_hw_eq_band_gain(unsigned int band
, int value
)
496 if(!audio_is_initialized
)
499 current_eq_band_gain
[band
] = value
;
500 audiohw_set_eq_band_gain(band
, value
);
501 set_prescaled_volume();
504 void sound_set_hw_eq_band1_gain(int value
)
506 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND1
, value
);
509 #if defined(AUDIOHW_HAVE_EQ_BAND2)
510 void sound_set_hw_eq_band2_gain(int value
)
512 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND2
, value
);
516 #if defined(AUDIOHW_HAVE_EQ_BAND3)
517 void sound_set_hw_eq_band3_gain(int value
)
519 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND3
, value
);
523 #if defined(AUDIOHW_HAVE_EQ_BAND4)
524 void sound_set_hw_eq_band4_gain(int value
)
526 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND4
, value
);
530 #if defined(AUDIOHW_HAVE_EQ_BAND5)
531 void sound_set_hw_eq_band5_gain(int value
)
533 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND5
, value
);
537 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
538 void sound_set_hw_eq_band1_frequency(int value
)
540 if(!audio_is_initialized
)
543 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1
, value
);
547 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
548 void sound_set_hw_eq_band2_frequency(int value
)
550 if(!audio_is_initialized
)
553 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2
, value
);
557 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
558 void sound_set_hw_eq_band3_frequency(int value
)
560 if(!audio_is_initialized
)
563 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3
, value
);
567 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
568 void sound_set_hw_eq_band4_frequency(int value
)
570 if(!audio_is_initialized
)
573 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4
, value
);
577 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
578 void sound_set_hw_eq_band5_frequency(int value
)
580 if(!audio_is_initialized
)
583 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5
, value
);
587 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
588 void sound_set_hw_eq_band2_width(int value
)
590 if(!audio_is_initialized
)
593 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2
, value
);
597 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
598 void sound_set_hw_eq_band3_width(int value
)
600 if(!audio_is_initialized
)
603 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3
, value
);
607 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
608 void sound_set_hw_eq_band4_width(int value
)
610 if(!audio_is_initialized
)
613 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4
, value
);
616 #endif /* AUDIOHW_HAVE_EQ */
618 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))
619 void sound_set_loudness(int value
)
621 if(!audio_is_initialized
)
623 loudness_shadow
= (loudness_shadow
& 0x04) |
624 (MAX(MIN(value
* 4, 0x44), 0) << 8);
625 mas_codec_writereg(MAS_REG_KLOUDNESS
, loudness_shadow
);
628 void sound_set_avc(int value
)
630 if(!audio_is_initialized
)
634 static const uint16_t avc_vals
[] =
636 (0x1 << 8) | (0x8 << 12), /* 20ms */
637 (0x2 << 8) | (0x8 << 12), /* 2s */
638 (0x4 << 8) | (0x8 << 12), /* 4s */
639 (0x8 << 8) | (0x8 << 12), /* 8s */
646 tmp
= avc_vals
[value
-1];
648 case -1: /* turn off and then turn on again to decay quickly */
649 tmp
= mas_codec_readreg(MAS_REG_KAVC
);
650 mas_codec_writereg(MAS_REG_KAVC
, 0);
656 mas_codec_writereg(MAS_REG_KAVC
, tmp
);
659 void sound_set_mdb_strength(int value
)
661 if(!audio_is_initialized
)
663 mas_codec_writereg(MAS_REG_KMDB_STR
, (value
& 0x7f) << 8);
666 void sound_set_mdb_harmonics(int value
)
668 if(!audio_is_initialized
)
670 int tmp
= value
* 127 / 100;
671 mas_codec_writereg(MAS_REG_KMDB_HAR
, (tmp
& 0x7f) << 8);
674 void sound_set_mdb_center(int value
)
676 if(!audio_is_initialized
)
678 mas_codec_writereg(MAS_REG_KMDB_FC
, (value
/10) << 8);
681 void sound_set_mdb_shape(int value
)
683 if(!audio_is_initialized
)
685 mdb_shape_shadow
= (mdb_shape_shadow
& 0x02) | ((value
/10) << 8);
686 mas_codec_writereg(MAS_REG_KMDB_SWITCH
, mdb_shape_shadow
);
689 void sound_set_mdb_enable(int value
)
691 if(!audio_is_initialized
)
693 mdb_shape_shadow
= (mdb_shape_shadow
& ~0x02) | (value
?2:0);
694 mas_codec_writereg(MAS_REG_KMDB_SWITCH
, mdb_shape_shadow
);
697 void sound_set_superbass(int value
)
699 if(!audio_is_initialized
)
701 loudness_shadow
= (loudness_shadow
& ~0x04) | (value
?4:0);
702 mas_codec_writereg(MAS_REG_KLOUDNESS
, loudness_shadow
);
704 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
706 void sound_set(int setting
, int value
)
708 sound_set_type
* sound_set_val
= sound_get_fn(setting
);
710 sound_set_val(value
);
713 #if (!defined(HAVE_AS3514) && !defined(HAVE_WM8975) \
714 && !defined(HAVE_WM8758) && !defined(HAVE_TSC2100) \
715 && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \
716 && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \
717 && !defined(HAVE_AK4537)) || (CONFIG_PLATFORM & PLATFORM_HOSTED)
718 int sound_val2phys(int setting
, int value
)
720 #if CONFIG_CODEC == MAS3587F
725 case SOUND_LEFT_GAIN
:
726 case SOUND_RIGHT_GAIN
:
727 result
= (value
- 2) * 15;
731 result
= value
* 15 + 210;
739 #elif defined(HAVE_UDA1380)
744 #ifdef HAVE_RECORDING
745 case SOUND_LEFT_GAIN
:
746 case SOUND_RIGHT_GAIN
:
748 result
= value
* 5; /* (1/2) * 10 */
756 #elif defined(HAVE_TLV320) || defined(HAVE_WM8711) \
757 || defined(HAVE_WM8721) || defined(HAVE_WM8731)
762 #ifdef HAVE_RECORDING
763 case SOUND_LEFT_GAIN
:
764 case SOUND_RIGHT_GAIN
:
765 result
= (value
- 23) * 15; /* (x - 23)/1.5 *10 */
769 result
= value
* 200; /* 0 or 20 dB */
777 #elif defined(HAVE_AS3514)
778 /* This is here for the sim only and the audio driver has its own */
783 #ifdef HAVE_RECORDING
784 case SOUND_LEFT_GAIN
:
785 case SOUND_RIGHT_GAIN
:
787 result
= (value
- 23) * 15;
796 #elif defined(HAVE_WM8978)
801 #ifdef HAVE_RECORDING
802 case SOUND_LEFT_GAIN
:
803 case SOUND_RIGHT_GAIN
:
810 result
= (100 * value
+ 8) / 15;
823 #endif /* CONFIG_CODECs || PLATFORM_HOSTED */
825 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
826 /* This function works by telling the decoder that we have another
827 crystal frequency than we actually have. It will adjust its internal
828 parameters and the result is that the audio is played at another pitch.
830 The pitch value precision is based on PITCH_SPEED_PRECISION (in dsp.h)
838 unsigned long shadow_io_control_main
;
839 static int last_pitch
= PITCH_SPEED_100
;
841 void sound_set_pitch(int32_t pitch
)
845 if (pitch
!= last_pitch
)
847 /* Calculate the new (bogus) frequency */
848 val
= 18432 * PITCH_SPEED_100
/ pitch
;
850 mas_writemem(MAS_BANK_D0
, MAS_D0_OFREQ_CONTROL
, &val
, 1);
852 /* We must tell the MAS that the frequency has changed.
853 * This will unfortunately cause a short silence. */
854 mas_writemem(MAS_BANK_D0
, MAS_D0_IO_CONTROL_MAIN
, &shadow_io_control_main
, 1);
860 int32_t sound_get_pitch(void)
864 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */