Android:
[kugel-rb.git] / firmware / sound.c
blob4dea2b8a840251883cc5e4c16d397c006af7fa11
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 int setting;
482 if(!audio_is_initialized)
483 return;
485 setting = sound_enum_hw_eq_band_setting(band, AUDIOHW_EQ_GAIN);
486 current_eq_band_gain[band] = sound_val2phys(setting + 0x10000, value);
488 audiohw_set_eq_band_gain(band, value);
489 set_prescaled_volume();
492 void sound_set_hw_eq_band1_gain(int value)
494 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND1, value);
497 #if defined(AUDIOHW_HAVE_EQ_BAND2)
498 void sound_set_hw_eq_band2_gain(int value)
500 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND2, value);
502 #endif
504 #if defined(AUDIOHW_HAVE_EQ_BAND3)
505 void sound_set_hw_eq_band3_gain(int value)
507 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND3, value);
509 #endif
511 #if defined(AUDIOHW_HAVE_EQ_BAND4)
512 void sound_set_hw_eq_band4_gain(int value)
514 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND4, value);
516 #endif
518 #if defined(AUDIOHW_HAVE_EQ_BAND5)
519 void sound_set_hw_eq_band5_gain(int value)
521 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND5, value);
523 #endif
525 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
526 void sound_set_hw_eq_band1_frequency(int value)
528 if(!audio_is_initialized)
529 return;
531 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value);
533 #endif
535 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
536 void sound_set_hw_eq_band2_frequency(int value)
538 if(!audio_is_initialized)
539 return;
541 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value);
543 #endif
545 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
546 void sound_set_hw_eq_band3_frequency(int value)
548 if(!audio_is_initialized)
549 return;
551 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value);
553 #endif
555 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
556 void sound_set_hw_eq_band4_frequency(int value)
558 if(!audio_is_initialized)
559 return;
561 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value);
563 #endif
565 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
566 void sound_set_hw_eq_band5_frequency(int value)
568 if(!audio_is_initialized)
569 return;
571 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value);
573 #endif
575 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
576 void sound_set_hw_eq_band2_width(int value)
578 if(!audio_is_initialized)
579 return;
581 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value);
583 #endif
585 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
586 void sound_set_hw_eq_band3_width(int value)
588 if(!audio_is_initialized)
589 return;
591 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value);
593 #endif
595 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
596 void sound_set_hw_eq_band4_width(int value)
598 if(!audio_is_initialized)
599 return;
601 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value);
603 #endif
604 #endif /* AUDIOHW_HAVE_EQ */
606 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))
607 void sound_set_loudness(int value)
609 if(!audio_is_initialized)
610 return;
612 audiohw_set_loudness(value);
615 void sound_set_avc(int value)
617 if(!audio_is_initialized)
618 return;
620 audiohw_set_avc(value);
623 void sound_set_mdb_strength(int value)
625 if(!audio_is_initialized)
626 return;
628 audiohw_set_mdb_strength(value);
631 void sound_set_mdb_harmonics(int value)
633 if(!audio_is_initialized)
634 return;
636 audiohw_set_mdb_harmonics(value);
639 void sound_set_mdb_center(int value)
641 if(!audio_is_initialized)
642 return;
644 audiohw_set_mdb_center(value);
647 void sound_set_mdb_shape(int value)
649 if(!audio_is_initialized)
650 return;
652 audiohw_set_mdb_shape(value);
655 void sound_set_mdb_enable(int value)
657 if(!audio_is_initialized)
658 return;
660 audiohw_set_mdb_enable(value);
663 void sound_set_superbass(int value)
665 if(!audio_is_initialized)
666 return;
668 audiohw_set_superbass(value);
670 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
672 void sound_set(int setting, int value)
674 sound_set_type* sound_set_val = sound_get_fn(setting);
675 if (sound_set_val)
676 sound_set_val(value);
679 #if (!defined(HAVE_AS3514) && !defined(HAVE_WM8975) \
680 && !defined(HAVE_WM8758) && !defined(HAVE_TSC2100) \
681 && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \
682 && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \
683 && !defined(HAVE_AK4537)) || (CONFIG_PLATFORM & PLATFORM_HOSTED)
684 int sound_val2phys(int setting, int value)
686 #if CONFIG_CODEC == MAS3587F
687 int result = 0;
689 switch(setting)
691 case SOUND_LEFT_GAIN:
692 case SOUND_RIGHT_GAIN:
693 result = (value - 2) * 15;
694 break;
696 case SOUND_MIC_GAIN:
697 result = value * 15 + 210;
698 break;
700 default:
701 result = value;
702 break;
704 return result;
705 #elif defined(HAVE_UDA1380)
706 int result = 0;
708 switch(setting)
710 #ifdef HAVE_RECORDING
711 case SOUND_LEFT_GAIN:
712 case SOUND_RIGHT_GAIN:
713 case SOUND_MIC_GAIN:
714 result = value * 5; /* (1/2) * 10 */
715 break;
716 #endif
717 default:
718 result = value;
719 break;
721 return result;
722 #elif defined(HAVE_TLV320) || defined(HAVE_WM8711) \
723 || defined(HAVE_WM8721) || defined(HAVE_WM8731)
724 int result = 0;
726 switch(setting)
728 #ifdef HAVE_RECORDING
729 case SOUND_LEFT_GAIN:
730 case SOUND_RIGHT_GAIN:
731 result = (value - 23) * 15; /* (x - 23)/1.5 *10 */
732 break;
734 case SOUND_MIC_GAIN:
735 result = value * 200; /* 0 or 20 dB */
736 break;
737 #endif
738 default:
739 result = value;
740 break;
742 return result;
743 #elif defined(HAVE_AS3514)
744 /* This is here for the sim only and the audio driver has its own */
745 int result;
747 switch(setting)
749 #ifdef HAVE_RECORDING
750 case SOUND_LEFT_GAIN:
751 case SOUND_RIGHT_GAIN:
752 case SOUND_MIC_GAIN:
753 result = (value - 23) * 15;
754 break;
755 #endif
756 default:
757 result = value;
758 break;
761 return result;
762 #elif defined(HAVE_WM8978)
763 int result;
765 switch (setting)
767 #ifdef HAVE_RECORDING
768 case SOUND_LEFT_GAIN:
769 case SOUND_RIGHT_GAIN:
770 case SOUND_MIC_GAIN:
771 result = value * 5;
772 break;
773 #endif
775 case SOUND_DEPTH_3D:
776 result = (100 * value + 8) / 15;
777 break;
779 default:
780 result = value;
783 return result;
784 #else
785 (void)setting;
786 return value;
787 #endif
789 #endif /* CONFIG_CODECs || PLATFORM_HOSTED */
791 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
792 /* This function works by telling the decoder that we have another
793 crystal frequency than we actually have. It will adjust its internal
794 parameters and the result is that the audio is played at another pitch.
796 The pitch value precision is based on PITCH_SPEED_PRECISION (in dsp.h)
799 static int last_pitch = PITCH_SPEED_100;
801 void sound_set_pitch(int32_t pitch)
803 unsigned long val;
805 if (pitch != last_pitch)
807 /* Calculate the new (bogus) frequency */
808 val = 18432 * PITCH_SPEED_100 / pitch;
810 audiohw_set_pitch(val);
812 last_pitch = pitch;
816 int32_t sound_get_pitch(void)
818 return last_pitch;
820 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */