Bootloader USB mode for PP502x. Enable only on GoGear SA9200 for the time being....
[kugel-rb.git] / firmware / sound.c
blobde963601983709ff7dc1a2ed1e6d96db727c9f95
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"
29 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
30 #if CONFIG_CPU == PNX0101
31 #include "pnx0101.h"
32 #endif /* CONFIG_CPU == PNX101 */
33 #if CONFIG_CODEC == SWCODEC
34 #include "pcm.h"
35 #else /* !CONFIG_CODEC == HWCODEC */
36 #include "mas35xx.h"
37 #include "dac3550a.h"
38 #endif
39 #endif /* !SIMULATOR */
41 /* TODO
42 * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble
45 extern bool audio_is_initialized;
47 const char *sound_unit(int setting)
49 return audiohw_settings[setting].unit;
52 int sound_numdecimals(int setting)
54 return audiohw_settings[setting].numdecimals;
57 int sound_steps(int setting)
59 return audiohw_settings[setting].steps;
62 int sound_min(int setting)
64 return audiohw_settings[setting].minval;
67 int sound_max(int setting)
69 return audiohw_settings[setting].maxval;
72 int sound_default(int setting)
74 return audiohw_settings[setting].defaultval;
77 static sound_set_type * const sound_set_fns[] =
79 [0 ... SOUND_LAST_SETTING-1] = NULL,
80 [SOUND_VOLUME] = sound_set_volume,
81 #if defined(AUDIOHW_HAVE_BASS)
82 [SOUND_BASS] = sound_set_bass,
83 #endif
84 #if defined(AUDIOHW_HAVE_TREBLE)
85 [SOUND_TREBLE] = sound_set_treble,
86 #endif
87 [SOUND_BALANCE] = sound_set_balance,
88 [SOUND_CHANNELS] = sound_set_channels,
89 [SOUND_STEREO_WIDTH] = sound_set_stereo_width,
90 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
91 [SOUND_LOUDNESS] = sound_set_loudness,
92 [SOUND_AVC] = sound_set_avc,
93 [SOUND_MDB_STRENGTH] = sound_set_mdb_strength,
94 [SOUND_MDB_HARMONICS] = sound_set_mdb_harmonics,
95 [SOUND_MDB_CENTER] = sound_set_mdb_center,
96 [SOUND_MDB_SHAPE] = sound_set_mdb_shape,
97 [SOUND_MDB_ENABLE] = sound_set_mdb_enable,
98 [SOUND_SUPERBASS] = sound_set_superbass,
99 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
100 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
101 [SOUND_BASS_CUTOFF] = sound_set_bass_cutoff,
102 #endif
103 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
104 [SOUND_TREBLE_CUTOFF] = sound_set_treble_cutoff,
105 #endif
106 #if defined(AUDIOHW_HAVE_DEPTH_3D)
107 [SOUND_DEPTH_3D] = sound_set_depth_3d,
108 #endif
109 /* Hardware EQ tone controls */
110 #if defined(AUDIOHW_HAVE_EQ)
111 [SOUND_EQ_BAND1_GAIN] = sound_set_hw_eq_band1_gain,
112 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
113 [SOUND_EQ_BAND1_FREQUENCY] = sound_set_hw_eq_band1_frequency,
114 #endif
115 #if defined(AUDIOHW_HAVE_EQ_BAND2)
116 [SOUND_EQ_BAND2_GAIN] = sound_set_hw_eq_band2_gain,
117 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
118 [SOUND_EQ_BAND2_FREQUENCY] = sound_set_hw_eq_band2_frequency,
119 #endif
120 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
121 [SOUND_EQ_BAND2_WIDTH] = sound_set_hw_eq_band2_width,
122 #endif
123 #endif /* AUDIOHW_HAVE_EQ_BAND2 */
124 #if defined(AUDIOHW_HAVE_EQ_BAND3)
125 [SOUND_EQ_BAND3_GAIN] = sound_set_hw_eq_band3_gain,
126 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
127 [SOUND_EQ_BAND3_FREQUENCY] = sound_set_hw_eq_band3_frequency,
128 #endif
129 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
130 [SOUND_EQ_BAND3_WIDTH] = sound_set_hw_eq_band3_width,
131 #endif
132 #endif /* AUDIOHW_HAVE_EQ_BAND3 */
133 #if defined(AUDIOHW_HAVE_EQ_BAND4)
134 [SOUND_EQ_BAND4_GAIN] = sound_set_hw_eq_band4_gain,
135 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
136 [SOUND_EQ_BAND4_FREQUENCY] = sound_set_hw_eq_band4_frequency,
137 #endif
138 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
139 [SOUND_EQ_BAND4_WIDTH] = sound_set_hw_eq_band4_width,
140 #endif
141 #endif /* AUDIOHW_HAVE_EQ_BAND4 */
142 #if defined(AUDIOHW_HAVE_EQ_BAND5)
143 [SOUND_EQ_BAND5_GAIN] = sound_set_hw_eq_band5_gain,
144 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
145 [SOUND_EQ_BAND5_FREQUENCY] = sound_set_hw_eq_band5_frequency,
146 #endif
147 #endif /* AUDIOHW_HAVE_EQ_BAND5 */
148 #endif /* AUDIOHW_HAVE_EQ */
151 sound_set_type* sound_get_fn(int setting)
153 return ((unsigned)setting >= ARRAYLEN(sound_set_fns)?
154 NULL : sound_set_fns[setting]);
157 #if CONFIG_CODEC == SWCODEC
158 static int (*dsp_callback)(int, intptr_t) = NULL;
160 void sound_set_dsp_callback(int (*func)(int, intptr_t))
162 dsp_callback = func;
164 #endif
166 #if !defined(AUDIOHW_HAVE_CLIPPING)
168 * The prescaler compensates for any kind of boosts, to prevent clipping.
170 * It's basically just a measure to make sure that audio does not clip during
171 * tone controls processing, like if i want to boost bass 12 dB, i can decrease
172 * the audio amplitude by -12 dB before processing, then increase master gain
173 * by 12 dB after processing.
176 /* all values in tenth of dB MAS3507D UDA1380 */
177 static int current_volume = 0; /* -780..+180 -840.. 0 */
178 static int current_balance = 0; /* -960..+960 -840..+840 */
179 #ifdef AUDIOHW_HAVE_TREBLE
180 static int current_treble = 0; /* -150..+150 0.. +60 */
181 #endif
182 #ifdef AUDIOHW_HAVE_BASS
183 static int current_bass = 0; /* -150..+150 0..+240 */
184 #endif
185 #ifdef AUDIOHW_HAVE_EQ
186 static int current_eq_band_gain[AUDIOHW_EQ_BAND_NUM];
187 #endif
189 static void set_prescaled_volume(void)
191 int prescale = 0;
192 int l, r;
194 /* The codecs listed use HW tone controls but don't have suitable prescaler
195 * functionality, so we let the prescaler stay at 0 for these, unless
196 * SW tone controls are in use. This is to avoid needing the SW DSP just for
197 * the prescaling.
199 #if defined(HAVE_SW_TONE_CONTROLS) || !(defined(HAVE_WM8975) \
200 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
201 || defined(HAVE_WM8758) || defined(HAVE_WM8985) || defined(HAVE_UDA1341))
203 #if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE)
204 prescale = MAX(current_bass, current_treble);
205 #endif
206 #if defined(AUDIOHW_HAVE_EQ)
207 int i;
208 for (i = 0; i < AUDIOHW_EQ_BAND_NUM; i++)
209 prescale = MAX(current_eq_band_gain[i], prescale);
210 #endif
212 if (prescale < 0)
213 prescale = 0; /* no need to prescale if we don't boost
214 bass, treble or eq band */
216 /* Gain up the analog volume to compensate the prescale gain reduction,
217 * but if this would push the volume over the top, reduce prescaling
218 * instead (might cause clipping). */
219 if (current_volume + prescale > VOLUME_MAX)
220 prescale = VOLUME_MAX - current_volume;
221 #endif
223 #if defined(AUDIOHW_HAVE_PRESCALER)
224 audiohw_set_prescaler(prescale);
225 #else
226 dsp_callback(DSP_CALLBACK_SET_PRESCALE, prescale);
227 #endif
229 if (current_volume == VOLUME_MIN)
230 prescale = 0; /* Make sure the chip gets muted at VOLUME_MIN */
232 l = r = current_volume + prescale;
234 /* Balance the channels scaled by the current volume and min volume. */
235 /* Subtract a dB from VOLUME_MIN to get it to a mute level */
236 if (current_balance > 0)
238 l -= ((l - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE;
240 else if (current_balance < 0)
242 r += ((r - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE;
245 #ifdef HAVE_SW_VOLUME_CONTROL
246 dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0);
247 #endif
249 #ifndef HAVE_SDL_AUDIO
250 #if CONFIG_CODEC == MAS3507D
251 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
252 #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
253 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
254 || defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_AS3514) \
255 || defined(HAVE_TSC2100) || defined(HAVE_AK4537) || defined(HAVE_UDA1341) \
256 || defined(HAVE_CS42L55)
257 audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r));
258 #if defined(HAVE_WM8975) || defined(HAVE_WM8758) \
259 || defined(HAVE_WM8750) || (defined(HAVE_WM8751) && !defined(MROBE_100)) \
260 || defined(HAVE_WM8985) || defined(HAVE_CS42L55)
261 audiohw_set_lineout_vol(tenthdb2master(0), tenthdb2master(0));
262 #endif
264 #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985)
265 audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r));
266 #elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
267 audiohw_set_volume(current_volume);
268 #endif
269 #else /* HAVE_SDL_AUDIO */
270 audiohw_set_volume(current_volume);
271 #endif /* !HAVE_SDL_AUDIO */
273 #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
275 void sound_set_volume(int value)
277 if(!audio_is_initialized)
278 return;
280 #if defined(AUDIOHW_HAVE_CLIPPING)
281 audiohw_set_volume(value);
282 #elif CONFIG_CPU == PNX0101
283 int tmp = (60 - value * 4) & 0xff;
284 CODECVOL = tmp | (tmp << 8);
285 #else
286 current_volume = value * 10; /* tenth of dB */
287 set_prescaled_volume();
288 #endif
291 void sound_set_balance(int value)
293 if(!audio_is_initialized)
294 return;
296 #ifdef AUDIOHW_HAVE_BALANCE
297 audiohw_set_balance(value);
298 #else
299 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */
300 set_prescaled_volume();
301 #endif
304 #ifdef AUDIOHW_HAVE_BASS
305 void sound_set_bass(int value)
307 if(!audio_is_initialized)
308 return;
310 #if !defined(AUDIOHW_HAVE_CLIPPING)
311 #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55)
312 current_bass = value;
313 #else
314 current_bass = value * 10;
315 #endif
316 #endif
318 #if defined(HAVE_SW_TONE_CONTROLS)
319 dsp_callback(DSP_CALLBACK_SET_BASS, current_bass);
320 #else
321 audiohw_set_bass(value);
322 #endif
324 #if !defined(AUDIOHW_HAVE_CLIPPING)
325 set_prescaled_volume();
326 #endif
328 #endif /* AUDIOHW_HAVE_BASS */
330 #ifdef AUDIOHW_HAVE_TREBLE
331 void sound_set_treble(int value)
333 if(!audio_is_initialized)
334 return;
336 #if !defined(AUDIOHW_HAVE_CLIPPING)
337 #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55)
338 current_treble = value;
339 #else
340 current_treble = value * 10;
341 #endif
342 #endif
344 #if defined(HAVE_SW_TONE_CONTROLS)
345 dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble);
346 #else
347 audiohw_set_treble(value);
348 #endif
350 #if !defined(AUDIOHW_HAVE_CLIPPING)
351 set_prescaled_volume();
352 #endif
354 #endif /* AUDIOHW_HAVE_TREBLE */
356 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
357 void sound_set_bass_cutoff(int value)
359 if(!audio_is_initialized)
360 return;
362 audiohw_set_bass_cutoff(value);
364 #endif
366 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
367 void sound_set_treble_cutoff(int value)
369 if(!audio_is_initialized)
370 return;
372 audiohw_set_treble_cutoff(value);
374 #endif
376 void sound_set_channels(int value)
378 if(!audio_is_initialized)
379 return;
381 #if CONFIG_CODEC == SWCODEC
382 dsp_callback(DSP_CALLBACK_SET_CHANNEL_CONFIG, value);
383 #else
384 audiohw_set_channel(value);
385 #endif
388 void sound_set_stereo_width(int value)
390 if(!audio_is_initialized)
391 return;
393 #if CONFIG_CODEC == SWCODEC
394 dsp_callback(DSP_CALLBACK_SET_STEREO_WIDTH, value);
395 #else
396 audiohw_set_stereo_width(value);
397 #endif
400 #if defined(AUDIOHW_HAVE_DEPTH_3D)
401 void sound_set_depth_3d(int value)
403 if(!audio_is_initialized)
404 return;
406 audiohw_set_depth_3d(value);
408 #endif
410 #if defined(AUDIOHW_HAVE_EQ)
411 int sound_enum_hw_eq_band_setting(unsigned int band,
412 unsigned int band_setting)
414 static const int8_t
415 sound_hw_eq_band_setting[AUDIOHW_EQ_SETTING_NUM][AUDIOHW_EQ_BAND_NUM] =
417 [AUDIOHW_EQ_GAIN] =
419 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
420 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_GAIN,
421 #ifdef AUDIOHW_HAVE_EQ_BAND2
422 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_GAIN,
423 #endif
424 #ifdef AUDIOHW_HAVE_EQ_BAND3
425 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_GAIN,
426 #endif
427 #ifdef AUDIOHW_HAVE_EQ_BAND4
428 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_GAIN,
429 #endif
430 #ifdef AUDIOHW_HAVE_EQ_BAND5
431 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_GAIN,
432 #endif
434 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
435 [AUDIOHW_EQ_FREQUENCY] =
437 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
438 #ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
439 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_FREQUENCY,
440 #endif
441 #ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
442 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_FREQUENCY,
443 #endif
444 #ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
445 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_FREQUENCY,
446 #endif
447 #ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
448 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_FREQUENCY,
449 #endif
450 #ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
451 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_FREQUENCY,
452 #endif
454 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
455 #ifdef AUDIOHW_HAVE_EQ_WIDTH
456 [AUDIOHW_EQ_WIDTH] =
458 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
459 #ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
460 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_WIDTH,
461 #endif
462 #ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
463 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_WIDTH,
464 #endif
465 #ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
466 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_WIDTH,
467 #endif
469 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
472 if (band < AUDIOHW_EQ_BAND_NUM && band_setting < AUDIOHW_EQ_SETTING_NUM)
473 return sound_hw_eq_band_setting[band_setting][band];
475 return -1;
478 static void sound_set_hw_eq_band_gain(unsigned int band, int value)
480 if(!audio_is_initialized)
481 return;
483 current_eq_band_gain[band] = value;
484 audiohw_set_eq_band_gain(band, value);
485 set_prescaled_volume();
488 void sound_set_hw_eq_band1_gain(int value)
490 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND1, value);
493 #if defined(AUDIOHW_HAVE_EQ_BAND2)
494 void sound_set_hw_eq_band2_gain(int value)
496 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND2, value);
498 #endif
500 #if defined(AUDIOHW_HAVE_EQ_BAND3)
501 void sound_set_hw_eq_band3_gain(int value)
503 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND3, value);
505 #endif
507 #if defined(AUDIOHW_HAVE_EQ_BAND4)
508 void sound_set_hw_eq_band4_gain(int value)
510 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND4, value);
512 #endif
514 #if defined(AUDIOHW_HAVE_EQ_BAND5)
515 void sound_set_hw_eq_band5_gain(int value)
517 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND5, value);
519 #endif
521 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
522 void sound_set_hw_eq_band1_frequency(int value)
524 if(!audio_is_initialized)
525 return;
527 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value);
529 #endif
531 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
532 void sound_set_hw_eq_band2_frequency(int value)
534 if(!audio_is_initialized)
535 return;
537 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value);
539 #endif
541 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
542 void sound_set_hw_eq_band3_frequency(int value)
544 if(!audio_is_initialized)
545 return;
547 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value);
549 #endif
551 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
552 void sound_set_hw_eq_band4_frequency(int value)
554 if(!audio_is_initialized)
555 return;
557 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value);
559 #endif
561 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
562 void sound_set_hw_eq_band5_frequency(int value)
564 if(!audio_is_initialized)
565 return;
567 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value);
569 #endif
571 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
572 void sound_set_hw_eq_band2_width(int value)
574 if(!audio_is_initialized)
575 return;
577 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value);
579 #endif
581 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
582 void sound_set_hw_eq_band3_width(int value)
584 if(!audio_is_initialized)
585 return;
587 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value);
589 #endif
591 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
592 void sound_set_hw_eq_band4_width(int value)
594 if(!audio_is_initialized)
595 return;
597 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value);
599 #endif
600 #endif /* AUDIOHW_HAVE_EQ */
602 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))
603 void sound_set_loudness(int value)
605 if(!audio_is_initialized)
606 return;
608 audiohw_set_loudness(value);
611 void sound_set_avc(int value)
613 if(!audio_is_initialized)
614 return;
616 audiohw_set_avc(value);
619 void sound_set_mdb_strength(int value)
621 if(!audio_is_initialized)
622 return;
624 audiohw_set_mdb_strength(value);
627 void sound_set_mdb_harmonics(int value)
629 if(!audio_is_initialized)
630 return;
632 audiohw_set_mdb_harmonics(value);
635 void sound_set_mdb_center(int value)
637 if(!audio_is_initialized)
638 return;
640 audiohw_set_mdb_center(value);
643 void sound_set_mdb_shape(int value)
645 if(!audio_is_initialized)
646 return;
648 audiohw_set_mdb_shape(value);
651 void sound_set_mdb_enable(int value)
653 if(!audio_is_initialized)
654 return;
656 audiohw_set_mdb_enable(value);
659 void sound_set_superbass(int value)
661 if(!audio_is_initialized)
662 return;
664 audiohw_set_superbass(value);
666 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
668 void sound_set(int setting, int value)
670 sound_set_type* sound_set_val = sound_get_fn(setting);
671 if (sound_set_val)
672 sound_set_val(value);
675 #if (!defined(HAVE_AS3514) && !defined(HAVE_WM8975) \
676 && !defined(HAVE_WM8758) && !defined(HAVE_TSC2100) \
677 && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \
678 && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \
679 && !defined(HAVE_AK4537)) || (CONFIG_PLATFORM & PLATFORM_HOSTED)
680 int sound_val2phys(int setting, int value)
682 #if CONFIG_CODEC == MAS3587F
683 int result = 0;
685 switch(setting)
687 case SOUND_LEFT_GAIN:
688 case SOUND_RIGHT_GAIN:
689 result = (value - 2) * 15;
690 break;
692 case SOUND_MIC_GAIN:
693 result = value * 15 + 210;
694 break;
696 default:
697 result = value;
698 break;
700 return result;
701 #elif defined(HAVE_UDA1380)
702 int result = 0;
704 switch(setting)
706 #ifdef HAVE_RECORDING
707 case SOUND_LEFT_GAIN:
708 case SOUND_RIGHT_GAIN:
709 case SOUND_MIC_GAIN:
710 result = value * 5; /* (1/2) * 10 */
711 break;
712 #endif
713 default:
714 result = value;
715 break;
717 return result;
718 #elif defined(HAVE_TLV320) || defined(HAVE_WM8711) \
719 || defined(HAVE_WM8721) || defined(HAVE_WM8731)
720 int result = 0;
722 switch(setting)
724 #ifdef HAVE_RECORDING
725 case SOUND_LEFT_GAIN:
726 case SOUND_RIGHT_GAIN:
727 result = (value - 23) * 15; /* (x - 23)/1.5 *10 */
728 break;
730 case SOUND_MIC_GAIN:
731 result = value * 200; /* 0 or 20 dB */
732 break;
733 #endif
734 default:
735 result = value;
736 break;
738 return result;
739 #elif defined(HAVE_AS3514)
740 /* This is here for the sim only and the audio driver has its own */
741 int result;
743 switch(setting)
745 #ifdef HAVE_RECORDING
746 case SOUND_LEFT_GAIN:
747 case SOUND_RIGHT_GAIN:
748 case SOUND_MIC_GAIN:
749 result = (value - 23) * 15;
750 break;
751 #endif
752 default:
753 result = value;
754 break;
757 return result;
758 #elif defined(HAVE_WM8978)
759 int result;
761 switch (setting)
763 #ifdef HAVE_RECORDING
764 case SOUND_LEFT_GAIN:
765 case SOUND_RIGHT_GAIN:
766 case SOUND_MIC_GAIN:
767 result = value * 5;
768 break;
769 #endif
771 case SOUND_DEPTH_3D:
772 result = (100 * value + 8) / 15;
773 break;
775 default:
776 result = value;
779 return result;
780 #else
781 (void)setting;
782 return value;
783 #endif
785 #endif /* CONFIG_CODECs || PLATFORM_HOSTED */
787 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
788 /* This function works by telling the decoder that we have another
789 crystal frequency than we actually have. It will adjust its internal
790 parameters and the result is that the audio is played at another pitch.
792 The pitch value precision is based on PITCH_SPEED_PRECISION (in dsp.h)
795 static int last_pitch = PITCH_SPEED_100;
797 void sound_set_pitch(int32_t pitch)
799 unsigned long val;
801 if (pitch != last_pitch)
803 /* Calculate the new (bogus) frequency */
804 val = 18432 * PITCH_SPEED_100 / pitch;
806 audiohw_set_pitch(val);
808 last_pitch = pitch;
812 int32_t sound_get_pitch(void)
814 return last_pitch;
816 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */