Merge branch 'v3.10' into pandora-port
[maemo-rb.git] / firmware / sound.c
blobec577d6a10cbbf028771f29c4388e51edb425005
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include <stdbool.h>
23 #include <stdio.h>
24 #include "config.h"
25 #include "sound.h"
26 #include "logf.h"
27 #include "system.h"
28 #include "i2c.h"
30 /* TODO
31 * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble
34 extern bool audio_is_initialized;
36 const char *sound_unit(int setting)
38 return audiohw_settings[setting].unit;
41 int sound_numdecimals(int setting)
43 return audiohw_settings[setting].numdecimals;
46 int sound_steps(int setting)
48 return audiohw_settings[setting].steps;
51 int sound_min(int setting)
53 return audiohw_settings[setting].minval;
56 int sound_max(int setting)
58 return audiohw_settings[setting].maxval;
61 int sound_default(int setting)
63 return audiohw_settings[setting].defaultval;
66 static sound_set_type * const sound_set_fns[] =
68 [0 ... SOUND_LAST_SETTING-1] = NULL,
69 [SOUND_VOLUME] = sound_set_volume,
70 #if defined(AUDIOHW_HAVE_BASS)
71 [SOUND_BASS] = sound_set_bass,
72 #endif
73 #if defined(AUDIOHW_HAVE_TREBLE)
74 [SOUND_TREBLE] = sound_set_treble,
75 #endif
76 [SOUND_BALANCE] = sound_set_balance,
77 [SOUND_CHANNELS] = sound_set_channels,
78 [SOUND_STEREO_WIDTH] = sound_set_stereo_width,
79 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
80 [SOUND_LOUDNESS] = sound_set_loudness,
81 [SOUND_AVC] = sound_set_avc,
82 [SOUND_MDB_STRENGTH] = sound_set_mdb_strength,
83 [SOUND_MDB_HARMONICS] = sound_set_mdb_harmonics,
84 [SOUND_MDB_CENTER] = sound_set_mdb_center,
85 [SOUND_MDB_SHAPE] = sound_set_mdb_shape,
86 [SOUND_MDB_ENABLE] = sound_set_mdb_enable,
87 [SOUND_SUPERBASS] = sound_set_superbass,
88 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
89 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
90 [SOUND_BASS_CUTOFF] = sound_set_bass_cutoff,
91 #endif
92 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
93 [SOUND_TREBLE_CUTOFF] = sound_set_treble_cutoff,
94 #endif
95 #if defined(AUDIOHW_HAVE_DEPTH_3D)
96 [SOUND_DEPTH_3D] = sound_set_depth_3d,
97 #endif
98 /* Hardware EQ tone controls */
99 #if defined(AUDIOHW_HAVE_EQ)
100 [SOUND_EQ_BAND1_GAIN] = sound_set_hw_eq_band1_gain,
101 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
102 [SOUND_EQ_BAND1_FREQUENCY] = sound_set_hw_eq_band1_frequency,
103 #endif
104 #if defined(AUDIOHW_HAVE_EQ_BAND2)
105 [SOUND_EQ_BAND2_GAIN] = sound_set_hw_eq_band2_gain,
106 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
107 [SOUND_EQ_BAND2_FREQUENCY] = sound_set_hw_eq_band2_frequency,
108 #endif
109 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
110 [SOUND_EQ_BAND2_WIDTH] = sound_set_hw_eq_band2_width,
111 #endif
112 #endif /* AUDIOHW_HAVE_EQ_BAND2 */
113 #if defined(AUDIOHW_HAVE_EQ_BAND3)
114 [SOUND_EQ_BAND3_GAIN] = sound_set_hw_eq_band3_gain,
115 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
116 [SOUND_EQ_BAND3_FREQUENCY] = sound_set_hw_eq_band3_frequency,
117 #endif
118 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
119 [SOUND_EQ_BAND3_WIDTH] = sound_set_hw_eq_band3_width,
120 #endif
121 #endif /* AUDIOHW_HAVE_EQ_BAND3 */
122 #if defined(AUDIOHW_HAVE_EQ_BAND4)
123 [SOUND_EQ_BAND4_GAIN] = sound_set_hw_eq_band4_gain,
124 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
125 [SOUND_EQ_BAND4_FREQUENCY] = sound_set_hw_eq_band4_frequency,
126 #endif
127 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
128 [SOUND_EQ_BAND4_WIDTH] = sound_set_hw_eq_band4_width,
129 #endif
130 #endif /* AUDIOHW_HAVE_EQ_BAND4 */
131 #if defined(AUDIOHW_HAVE_EQ_BAND5)
132 [SOUND_EQ_BAND5_GAIN] = sound_set_hw_eq_band5_gain,
133 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
134 [SOUND_EQ_BAND5_FREQUENCY] = sound_set_hw_eq_band5_frequency,
135 #endif
136 #endif /* AUDIOHW_HAVE_EQ_BAND5 */
137 #endif /* AUDIOHW_HAVE_EQ */
140 sound_set_type* sound_get_fn(int setting)
142 return ((unsigned)setting >= ARRAYLEN(sound_set_fns)?
143 NULL : sound_set_fns[setting]);
146 #if CONFIG_CODEC == SWCODEC
147 static int (*dsp_callback)(int, intptr_t) = NULL;
149 void sound_set_dsp_callback(int (*func)(int, intptr_t))
151 dsp_callback = func;
153 #endif
155 #if !defined(AUDIOHW_HAVE_CLIPPING)
157 * The prescaler compensates for any kind of boosts, to prevent clipping.
159 * It's basically just a measure to make sure that audio does not clip during
160 * tone controls processing, like if i want to boost bass 12 dB, i can decrease
161 * the audio amplitude by -12 dB before processing, then increase master gain
162 * by 12 dB after processing.
165 /* all values in tenth of dB MAS3507D UDA1380 */
166 static int current_volume = 0; /* -780..+180 -840.. 0 */
167 static int current_balance = 0; /* -960..+960 -840..+840 */
168 #ifdef AUDIOHW_HAVE_TREBLE
169 static int current_treble = 0; /* -150..+150 0.. +60 */
170 #endif
171 #ifdef AUDIOHW_HAVE_BASS
172 static int current_bass = 0; /* -150..+150 0..+240 */
173 #endif
174 #ifdef AUDIOHW_HAVE_EQ
175 static int current_eq_band_gain[AUDIOHW_EQ_BAND_NUM];
176 #endif
178 static void set_prescaled_volume(void)
180 int prescale = 0;
181 int l, r;
183 /* The codecs listed use HW tone controls but don't have suitable prescaler
184 * functionality, so we let the prescaler stay at 0 for these, unless
185 * SW tone controls are in use. This is to avoid needing the SW DSP just for
186 * the prescaling.
188 #if defined(HAVE_SW_TONE_CONTROLS) || !(defined(HAVE_WM8975) \
189 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
190 || defined(HAVE_WM8758) || defined(HAVE_WM8985) || defined(HAVE_UDA1341))
192 #if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE)
193 prescale = MAX(current_bass, current_treble);
194 #endif
195 #if defined(AUDIOHW_HAVE_EQ)
196 int i;
197 for (i = 0; i < AUDIOHW_EQ_BAND_NUM; i++)
198 prescale = MAX(current_eq_band_gain[i], prescale);
199 #endif
201 if (prescale < 0)
202 prescale = 0; /* no need to prescale if we don't boost
203 bass, treble or eq band */
205 /* Gain up the analog volume to compensate the prescale gain reduction,
206 * but if this would push the volume over the top, reduce prescaling
207 * instead (might cause clipping). */
208 if (current_volume + prescale > VOLUME_MAX)
209 prescale = VOLUME_MAX - current_volume;
210 #endif
212 #if defined(AUDIOHW_HAVE_PRESCALER)
213 audiohw_set_prescaler(prescale);
214 #else
215 dsp_callback(DSP_CALLBACK_SET_PRESCALE, prescale);
216 #endif
218 if (current_volume == VOLUME_MIN)
219 prescale = 0; /* Make sure the chip gets muted at VOLUME_MIN */
221 l = r = current_volume + prescale;
223 /* Balance the channels scaled by the current volume and min volume. */
224 /* Subtract a dB from VOLUME_MIN to get it to a mute level */
225 if (current_balance > 0)
227 l -= ((l - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE;
229 else if (current_balance < 0)
231 r += ((r - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE;
234 #ifdef HAVE_SW_VOLUME_CONTROL
235 dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0);
236 #endif
238 #ifndef HAVE_SDL_AUDIO
239 #if CONFIG_CODEC == MAS3507D
240 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
241 #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
242 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
243 || defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_AS3514) \
244 || defined(HAVE_TSC2100) || defined(HAVE_AK4537) || defined(HAVE_UDA1341) \
245 || defined(HAVE_CS42L55) || defined(HAVE_RK27XX_CODEC)
246 audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r));
247 #if defined(HAVE_WM8975) || defined(HAVE_WM8758) \
248 || (defined(HAVE_WM8751) && defined(TOSHIBA_GIGABEAT_F)) \
249 || defined(HAVE_WM8985) || defined(HAVE_CS42L55)
250 audiohw_set_lineout_vol(tenthdb2master(0), tenthdb2master(0));
251 #endif
253 #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) || defined(HAVE_IMX233_CODEC)
254 audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r));
255 #elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
256 audiohw_set_volume(current_volume);
257 #endif
258 #else /* HAVE_SDL_AUDIO */
259 audiohw_set_volume(current_volume);
260 #endif /* !HAVE_SDL_AUDIO */
262 #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
264 void sound_set_volume(int value)
266 if(!audio_is_initialized)
267 return;
269 #if defined(AUDIOHW_HAVE_CLIPPING)
270 audiohw_set_volume(value);
271 #elif CONFIG_CPU == PNX0101
272 int tmp = (60 - value * 4) & 0xff;
273 CODECVOL = tmp | (tmp << 8);
274 #else
275 current_volume = value * 10; /* tenth of dB */
276 set_prescaled_volume();
277 #endif
280 void sound_set_balance(int value)
282 if(!audio_is_initialized)
283 return;
285 #ifdef AUDIOHW_HAVE_BALANCE
286 audiohw_set_balance(value);
287 #else
288 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */
289 set_prescaled_volume();
290 #endif
293 #ifdef AUDIOHW_HAVE_BASS
294 void sound_set_bass(int value)
296 if(!audio_is_initialized)
297 return;
299 #if !defined(AUDIOHW_HAVE_CLIPPING)
300 #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55)
301 current_bass = value;
302 #else
303 current_bass = value * 10;
304 #endif
305 #endif
307 #if defined(HAVE_SW_TONE_CONTROLS)
308 dsp_callback(DSP_CALLBACK_SET_BASS, current_bass);
309 #else
310 audiohw_set_bass(value);
311 #endif
313 #if !defined(AUDIOHW_HAVE_CLIPPING)
314 set_prescaled_volume();
315 #endif
317 #endif /* AUDIOHW_HAVE_BASS */
319 #ifdef AUDIOHW_HAVE_TREBLE
320 void sound_set_treble(int value)
322 if(!audio_is_initialized)
323 return;
325 #if !defined(AUDIOHW_HAVE_CLIPPING)
326 #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55)
327 current_treble = value;
328 #else
329 current_treble = value * 10;
330 #endif
331 #endif
333 #if defined(HAVE_SW_TONE_CONTROLS)
334 dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble);
335 #else
336 audiohw_set_treble(value);
337 #endif
339 #if !defined(AUDIOHW_HAVE_CLIPPING)
340 set_prescaled_volume();
341 #endif
343 #endif /* AUDIOHW_HAVE_TREBLE */
345 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
346 void sound_set_bass_cutoff(int value)
348 if(!audio_is_initialized)
349 return;
351 audiohw_set_bass_cutoff(value);
353 #endif
355 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
356 void sound_set_treble_cutoff(int value)
358 if(!audio_is_initialized)
359 return;
361 audiohw_set_treble_cutoff(value);
363 #endif
365 void sound_set_channels(int value)
367 if(!audio_is_initialized)
368 return;
370 #if CONFIG_CODEC == SWCODEC
371 dsp_callback(DSP_CALLBACK_SET_CHANNEL_CONFIG, value);
372 #else
373 audiohw_set_channel(value);
374 #endif
377 void sound_set_stereo_width(int value)
379 if(!audio_is_initialized)
380 return;
382 #if CONFIG_CODEC == SWCODEC
383 dsp_callback(DSP_CALLBACK_SET_STEREO_WIDTH, value);
384 #else
385 audiohw_set_stereo_width(value);
386 #endif
389 #if defined(AUDIOHW_HAVE_DEPTH_3D)
390 void sound_set_depth_3d(int value)
392 if(!audio_is_initialized)
393 return;
395 audiohw_set_depth_3d(value);
397 #endif
399 #if defined(AUDIOHW_HAVE_EQ)
400 int sound_enum_hw_eq_band_setting(unsigned int band,
401 unsigned int band_setting)
403 static const int8_t
404 sound_hw_eq_band_setting[AUDIOHW_EQ_SETTING_NUM][AUDIOHW_EQ_BAND_NUM] =
406 [AUDIOHW_EQ_GAIN] =
408 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
409 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_GAIN,
410 #ifdef AUDIOHW_HAVE_EQ_BAND2
411 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_GAIN,
412 #endif
413 #ifdef AUDIOHW_HAVE_EQ_BAND3
414 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_GAIN,
415 #endif
416 #ifdef AUDIOHW_HAVE_EQ_BAND4
417 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_GAIN,
418 #endif
419 #ifdef AUDIOHW_HAVE_EQ_BAND5
420 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_GAIN,
421 #endif
423 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
424 [AUDIOHW_EQ_FREQUENCY] =
426 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
427 #ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
428 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_FREQUENCY,
429 #endif
430 #ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
431 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_FREQUENCY,
432 #endif
433 #ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
434 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_FREQUENCY,
435 #endif
436 #ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
437 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_FREQUENCY,
438 #endif
439 #ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
440 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_FREQUENCY,
441 #endif
443 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
444 #ifdef AUDIOHW_HAVE_EQ_WIDTH
445 [AUDIOHW_EQ_WIDTH] =
447 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
448 #ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
449 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_WIDTH,
450 #endif
451 #ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
452 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_WIDTH,
453 #endif
454 #ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
455 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_WIDTH,
456 #endif
458 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
461 if (band < AUDIOHW_EQ_BAND_NUM && band_setting < AUDIOHW_EQ_SETTING_NUM)
462 return sound_hw_eq_band_setting[band_setting][band];
464 return -1;
467 static void sound_set_hw_eq_band_gain(unsigned int band, int value)
469 int setting;
471 if(!audio_is_initialized)
472 return;
474 setting = sound_enum_hw_eq_band_setting(band, AUDIOHW_EQ_GAIN);
475 current_eq_band_gain[band] = sound_val2phys(setting + 0x10000, value);
477 audiohw_set_eq_band_gain(band, value);
478 set_prescaled_volume();
481 void sound_set_hw_eq_band1_gain(int value)
483 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND1, value);
486 #if defined(AUDIOHW_HAVE_EQ_BAND2)
487 void sound_set_hw_eq_band2_gain(int value)
489 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND2, value);
491 #endif
493 #if defined(AUDIOHW_HAVE_EQ_BAND3)
494 void sound_set_hw_eq_band3_gain(int value)
496 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND3, value);
498 #endif
500 #if defined(AUDIOHW_HAVE_EQ_BAND4)
501 void sound_set_hw_eq_band4_gain(int value)
503 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND4, value);
505 #endif
507 #if defined(AUDIOHW_HAVE_EQ_BAND5)
508 void sound_set_hw_eq_band5_gain(int value)
510 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND5, value);
512 #endif
514 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
515 void sound_set_hw_eq_band1_frequency(int value)
517 if(!audio_is_initialized)
518 return;
520 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value);
522 #endif
524 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
525 void sound_set_hw_eq_band2_frequency(int value)
527 if(!audio_is_initialized)
528 return;
530 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value);
532 #endif
534 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
535 void sound_set_hw_eq_band3_frequency(int value)
537 if(!audio_is_initialized)
538 return;
540 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value);
542 #endif
544 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
545 void sound_set_hw_eq_band4_frequency(int value)
547 if(!audio_is_initialized)
548 return;
550 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value);
552 #endif
554 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
555 void sound_set_hw_eq_band5_frequency(int value)
557 if(!audio_is_initialized)
558 return;
560 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value);
562 #endif
564 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
565 void sound_set_hw_eq_band2_width(int value)
567 if(!audio_is_initialized)
568 return;
570 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value);
572 #endif
574 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
575 void sound_set_hw_eq_band3_width(int value)
577 if(!audio_is_initialized)
578 return;
580 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value);
582 #endif
584 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
585 void sound_set_hw_eq_band4_width(int value)
587 if(!audio_is_initialized)
588 return;
590 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value);
592 #endif
593 #endif /* AUDIOHW_HAVE_EQ */
595 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))
596 void sound_set_loudness(int value)
598 if(!audio_is_initialized)
599 return;
601 audiohw_set_loudness(value);
604 void sound_set_avc(int value)
606 if(!audio_is_initialized)
607 return;
609 audiohw_set_avc(value);
612 void sound_set_mdb_strength(int value)
614 if(!audio_is_initialized)
615 return;
617 audiohw_set_mdb_strength(value);
620 void sound_set_mdb_harmonics(int value)
622 if(!audio_is_initialized)
623 return;
625 audiohw_set_mdb_harmonics(value);
628 void sound_set_mdb_center(int value)
630 if(!audio_is_initialized)
631 return;
633 audiohw_set_mdb_center(value);
636 void sound_set_mdb_shape(int value)
638 if(!audio_is_initialized)
639 return;
641 audiohw_set_mdb_shape(value);
644 void sound_set_mdb_enable(int value)
646 if(!audio_is_initialized)
647 return;
649 audiohw_set_mdb_enable(value);
652 void sound_set_superbass(int value)
654 if(!audio_is_initialized)
655 return;
657 audiohw_set_superbass(value);
659 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
661 void sound_set(int setting, int value)
663 sound_set_type* sound_set_val = sound_get_fn(setting);
664 if (sound_set_val)
665 sound_set_val(value);
668 #if (!defined(HAVE_AS3514) && !defined(HAVE_WM8975) \
669 && !defined(HAVE_WM8758) && !defined(HAVE_TSC2100) \
670 && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \
671 && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \
672 && !defined (HAVE_WM8750) && !defined (HAVE_WM8751) \
673 && !defined(HAVE_AK4537)) || (CONFIG_PLATFORM & PLATFORM_HOSTED)
674 int sound_val2phys(int setting, int value)
676 #if CONFIG_CODEC == MAS3587F
677 int result = 0;
679 switch(setting)
681 case SOUND_LEFT_GAIN:
682 case SOUND_RIGHT_GAIN:
683 result = (value - 2) * 15;
684 break;
686 case SOUND_MIC_GAIN:
687 result = value * 15 + 210;
688 break;
690 default:
691 result = value;
692 break;
694 return result;
695 #elif defined(HAVE_UDA1380)
696 int result = 0;
698 switch(setting)
700 #ifdef HAVE_RECORDING
701 case SOUND_LEFT_GAIN:
702 case SOUND_RIGHT_GAIN:
703 case SOUND_MIC_GAIN:
704 result = value * 5; /* (1/2) * 10 */
705 break;
706 #endif
707 default:
708 result = value;
709 break;
711 return result;
712 #elif defined(HAVE_TLV320) || defined(HAVE_WM8711) \
713 || defined(HAVE_WM8721) || defined(HAVE_WM8731)
714 int result = 0;
716 switch(setting)
718 #ifdef HAVE_RECORDING
719 case SOUND_LEFT_GAIN:
720 case SOUND_RIGHT_GAIN:
721 result = (value - 23) * 15; /* (x - 23)/1.5 *10 */
722 break;
724 case SOUND_MIC_GAIN:
725 result = value * 200; /* 0 or 20 dB */
726 break;
727 #endif
728 default:
729 result = value;
730 break;
732 return result;
733 #elif defined(HAVE_AS3514)
734 /* This is here for the sim only and the audio driver has its own */
735 int result;
737 switch(setting)
739 #ifdef HAVE_RECORDING
740 case SOUND_LEFT_GAIN:
741 case SOUND_RIGHT_GAIN:
742 case SOUND_MIC_GAIN:
743 result = (value - 23) * 15;
744 break;
745 #endif
746 default:
747 result = value;
748 break;
751 return result;
752 #elif defined(HAVE_WM8978) || defined(HAVE_WM8750) || defined(HAVE_WM8751)
753 int result;
755 switch (setting)
757 #ifdef HAVE_RECORDING
758 case SOUND_LEFT_GAIN:
759 case SOUND_RIGHT_GAIN:
760 case SOUND_MIC_GAIN:
761 result = value * 5;
762 break;
763 #endif
764 #ifdef AUDIOHW_HAVE_DEPTH_3D
765 case SOUND_DEPTH_3D:
766 result = (100 * value + 8) / 15;
767 break;
768 #endif
769 default:
770 result = value;
773 return result;
774 #else
775 (void)setting;
776 return value;
777 #endif
779 #endif /* CONFIG_CODECs || PLATFORM_HOSTED */
781 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
782 /* This function works by telling the decoder that we have another
783 crystal frequency than we actually have. It will adjust its internal
784 parameters and the result is that the audio is played at another pitch.
786 The pitch value precision is based on PITCH_SPEED_PRECISION (in dsp.h)
789 static int last_pitch = PITCH_SPEED_100;
791 void sound_set_pitch(int32_t pitch)
793 unsigned long val;
795 if (pitch != last_pitch)
797 /* Calculate the new (bogus) frequency */
798 val = 18432 * PITCH_SPEED_100 / pitch;
800 audiohw_set_pitch(val);
802 last_pitch = pitch;
806 int32_t sound_get_pitch(void)
808 return last_pitch;
810 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */