Move bin2c handling to libtools.make
[maemo-rb.git] / firmware / sound.c
blob99db7896ab94fa4cf7aea13c6a30b9908cab70b6
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 /* ypr0 with sdl has separate volume controls */
239 #if !defined(HAVE_SDL_AUDIO) || defined(SAMSUNG_YPR0)
240 #if CONFIG_CODEC == MAS3507D
241 dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
242 #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
243 || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
244 || defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_AS3514) \
245 || defined(HAVE_TSC2100) || defined(HAVE_AK4537) || defined(HAVE_UDA1341) \
246 || defined(HAVE_CS42L55) || defined(HAVE_RK27XX_CODEC)
247 audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r));
248 #if defined(HAVE_WM8975) || defined(HAVE_WM8758) \
249 || (defined(HAVE_WM8751) && defined(TOSHIBA_GIGABEAT_F)) \
250 || defined(HAVE_WM8985) || defined(HAVE_CS42L55)
251 audiohw_set_lineout_vol(tenthdb2master(0), tenthdb2master(0));
252 #endif
254 #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) || defined(HAVE_IMX233_CODEC) || defined(HAVE_AIC3X)
255 audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r));
256 #elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
257 audiohw_set_volume(current_volume);
258 #endif
259 #else /* HAVE_SDL_AUDIO */
260 audiohw_set_volume(current_volume);
261 #endif /* !HAVE_SDL_AUDIO */
263 #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
265 void sound_set_volume(int value)
267 if(!audio_is_initialized)
268 return;
270 #if defined(AUDIOHW_HAVE_CLIPPING)
271 audiohw_set_volume(value);
272 #elif CONFIG_CPU == PNX0101
273 int tmp = (60 - value * 4) & 0xff;
274 CODECVOL = tmp | (tmp << 8);
275 #else
276 current_volume = value * 10; /* tenth of dB */
277 set_prescaled_volume();
278 #endif
281 void sound_set_balance(int value)
283 if(!audio_is_initialized)
284 return;
286 #ifdef AUDIOHW_HAVE_BALANCE
287 audiohw_set_balance(value);
288 #else
289 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */
290 set_prescaled_volume();
291 #endif
294 #ifdef AUDIOHW_HAVE_BASS
295 void sound_set_bass(int value)
297 if(!audio_is_initialized)
298 return;
300 #if !defined(AUDIOHW_HAVE_CLIPPING)
301 #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55)
302 current_bass = value;
303 #else
304 current_bass = value * 10;
305 #endif
306 #endif
308 #if defined(HAVE_SW_TONE_CONTROLS)
309 dsp_callback(DSP_CALLBACK_SET_BASS, current_bass);
310 #else
311 audiohw_set_bass(value);
312 #endif
314 #if !defined(AUDIOHW_HAVE_CLIPPING)
315 set_prescaled_volume();
316 #endif
318 #endif /* AUDIOHW_HAVE_BASS */
320 #ifdef AUDIOHW_HAVE_TREBLE
321 void sound_set_treble(int value)
323 if(!audio_is_initialized)
324 return;
326 #if !defined(AUDIOHW_HAVE_CLIPPING)
327 #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55)
328 current_treble = value;
329 #else
330 current_treble = value * 10;
331 #endif
332 #endif
334 #if defined(HAVE_SW_TONE_CONTROLS)
335 dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble);
336 #else
337 audiohw_set_treble(value);
338 #endif
340 #if !defined(AUDIOHW_HAVE_CLIPPING)
341 set_prescaled_volume();
342 #endif
344 #endif /* AUDIOHW_HAVE_TREBLE */
346 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
347 void sound_set_bass_cutoff(int value)
349 if(!audio_is_initialized)
350 return;
352 audiohw_set_bass_cutoff(value);
354 #endif
356 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
357 void sound_set_treble_cutoff(int value)
359 if(!audio_is_initialized)
360 return;
362 audiohw_set_treble_cutoff(value);
364 #endif
366 void sound_set_channels(int value)
368 if(!audio_is_initialized)
369 return;
371 #if CONFIG_CODEC == SWCODEC
372 dsp_callback(DSP_CALLBACK_SET_CHANNEL_CONFIG, value);
373 #else
374 audiohw_set_channel(value);
375 #endif
378 void sound_set_stereo_width(int value)
380 if(!audio_is_initialized)
381 return;
383 #if CONFIG_CODEC == SWCODEC
384 dsp_callback(DSP_CALLBACK_SET_STEREO_WIDTH, value);
385 #else
386 audiohw_set_stereo_width(value);
387 #endif
390 #if defined(AUDIOHW_HAVE_DEPTH_3D)
391 void sound_set_depth_3d(int value)
393 if(!audio_is_initialized)
394 return;
396 audiohw_set_depth_3d(value);
398 #endif
400 #if defined(AUDIOHW_HAVE_EQ)
401 int sound_enum_hw_eq_band_setting(unsigned int band,
402 unsigned int band_setting)
404 static const int8_t
405 sound_hw_eq_band_setting[AUDIOHW_EQ_SETTING_NUM][AUDIOHW_EQ_BAND_NUM] =
407 [AUDIOHW_EQ_GAIN] =
409 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
410 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_GAIN,
411 #ifdef AUDIOHW_HAVE_EQ_BAND2
412 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_GAIN,
413 #endif
414 #ifdef AUDIOHW_HAVE_EQ_BAND3
415 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_GAIN,
416 #endif
417 #ifdef AUDIOHW_HAVE_EQ_BAND4
418 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_GAIN,
419 #endif
420 #ifdef AUDIOHW_HAVE_EQ_BAND5
421 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_GAIN,
422 #endif
424 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
425 [AUDIOHW_EQ_FREQUENCY] =
427 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
428 #ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
429 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_FREQUENCY,
430 #endif
431 #ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
432 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_FREQUENCY,
433 #endif
434 #ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
435 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_FREQUENCY,
436 #endif
437 #ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
438 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_FREQUENCY,
439 #endif
440 #ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
441 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_FREQUENCY,
442 #endif
444 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
445 #ifdef AUDIOHW_HAVE_EQ_WIDTH
446 [AUDIOHW_EQ_WIDTH] =
448 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
449 #ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
450 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_WIDTH,
451 #endif
452 #ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
453 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_WIDTH,
454 #endif
455 #ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
456 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_WIDTH,
457 #endif
459 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
462 if (band < AUDIOHW_EQ_BAND_NUM && band_setting < AUDIOHW_EQ_SETTING_NUM)
463 return sound_hw_eq_band_setting[band_setting][band];
465 return -1;
468 static void sound_set_hw_eq_band_gain(unsigned int band, int value)
470 int setting;
472 if(!audio_is_initialized)
473 return;
475 setting = sound_enum_hw_eq_band_setting(band, AUDIOHW_EQ_GAIN);
476 current_eq_band_gain[band] = sound_val2phys(setting + 0x10000, value);
478 audiohw_set_eq_band_gain(band, value);
479 set_prescaled_volume();
482 void sound_set_hw_eq_band1_gain(int value)
484 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND1, value);
487 #if defined(AUDIOHW_HAVE_EQ_BAND2)
488 void sound_set_hw_eq_band2_gain(int value)
490 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND2, value);
492 #endif
494 #if defined(AUDIOHW_HAVE_EQ_BAND3)
495 void sound_set_hw_eq_band3_gain(int value)
497 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND3, value);
499 #endif
501 #if defined(AUDIOHW_HAVE_EQ_BAND4)
502 void sound_set_hw_eq_band4_gain(int value)
504 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND4, value);
506 #endif
508 #if defined(AUDIOHW_HAVE_EQ_BAND5)
509 void sound_set_hw_eq_band5_gain(int value)
511 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND5, value);
513 #endif
515 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
516 void sound_set_hw_eq_band1_frequency(int value)
518 if(!audio_is_initialized)
519 return;
521 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value);
523 #endif
525 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
526 void sound_set_hw_eq_band2_frequency(int value)
528 if(!audio_is_initialized)
529 return;
531 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value);
533 #endif
535 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
536 void sound_set_hw_eq_band3_frequency(int value)
538 if(!audio_is_initialized)
539 return;
541 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value);
543 #endif
545 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
546 void sound_set_hw_eq_band4_frequency(int value)
548 if(!audio_is_initialized)
549 return;
551 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value);
553 #endif
555 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
556 void sound_set_hw_eq_band5_frequency(int value)
558 if(!audio_is_initialized)
559 return;
561 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value);
563 #endif
565 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
566 void sound_set_hw_eq_band2_width(int value)
568 if(!audio_is_initialized)
569 return;
571 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value);
573 #endif
575 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
576 void sound_set_hw_eq_band3_width(int value)
578 if(!audio_is_initialized)
579 return;
581 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value);
583 #endif
585 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
586 void sound_set_hw_eq_band4_width(int value)
588 if(!audio_is_initialized)
589 return;
591 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value);
593 #endif
594 #endif /* AUDIOHW_HAVE_EQ */
596 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))
597 void sound_set_loudness(int value)
599 if(!audio_is_initialized)
600 return;
602 audiohw_set_loudness(value);
605 void sound_set_avc(int value)
607 if(!audio_is_initialized)
608 return;
610 audiohw_set_avc(value);
613 void sound_set_mdb_strength(int value)
615 if(!audio_is_initialized)
616 return;
618 audiohw_set_mdb_strength(value);
621 void sound_set_mdb_harmonics(int value)
623 if(!audio_is_initialized)
624 return;
626 audiohw_set_mdb_harmonics(value);
629 void sound_set_mdb_center(int value)
631 if(!audio_is_initialized)
632 return;
634 audiohw_set_mdb_center(value);
637 void sound_set_mdb_shape(int value)
639 if(!audio_is_initialized)
640 return;
642 audiohw_set_mdb_shape(value);
645 void sound_set_mdb_enable(int value)
647 if(!audio_is_initialized)
648 return;
650 audiohw_set_mdb_enable(value);
653 void sound_set_superbass(int value)
655 if(!audio_is_initialized)
656 return;
658 audiohw_set_superbass(value);
660 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
662 void sound_set(int setting, int value)
664 sound_set_type* sound_set_val = sound_get_fn(setting);
665 if (sound_set_val)
666 sound_set_val(value);
669 #if (!defined(HAVE_AS3514) && !defined(HAVE_WM8975) \
670 && !defined(HAVE_WM8758) && !defined(HAVE_TSC2100) \
671 && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \
672 && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \
673 && !defined (HAVE_WM8750) && !defined (HAVE_WM8751) \
674 && !defined(HAVE_AK4537)) || defined(SIMULATOR)
675 int sound_val2phys(int setting, int value)
677 #if CONFIG_CODEC == MAS3587F
678 int result = 0;
680 switch(setting)
682 case SOUND_LEFT_GAIN:
683 case SOUND_RIGHT_GAIN:
684 result = (value - 2) * 15;
685 break;
687 case SOUND_MIC_GAIN:
688 result = value * 15 + 210;
689 break;
691 default:
692 result = value;
693 break;
695 return result;
696 #elif defined(HAVE_UDA1380)
697 int result = 0;
699 switch(setting)
701 #ifdef HAVE_RECORDING
702 case SOUND_LEFT_GAIN:
703 case SOUND_RIGHT_GAIN:
704 case SOUND_MIC_GAIN:
705 result = value * 5; /* (1/2) * 10 */
706 break;
707 #endif
708 default:
709 result = value;
710 break;
712 return result;
713 #elif defined(HAVE_TLV320) || defined(HAVE_WM8711) \
714 || defined(HAVE_WM8721) || defined(HAVE_WM8731)
715 int result = 0;
717 switch(setting)
719 #ifdef HAVE_RECORDING
720 case SOUND_LEFT_GAIN:
721 case SOUND_RIGHT_GAIN:
722 result = (value - 23) * 15; /* (x - 23)/1.5 *10 */
723 break;
725 case SOUND_MIC_GAIN:
726 result = value * 200; /* 0 or 20 dB */
727 break;
728 #endif
729 default:
730 result = value;
731 break;
733 return result;
734 #elif defined(HAVE_AS3514)
735 /* This is here for the sim only and the audio driver has its own */
736 int result;
738 switch(setting)
740 #ifdef HAVE_RECORDING
741 case SOUND_LEFT_GAIN:
742 case SOUND_RIGHT_GAIN:
743 case SOUND_MIC_GAIN:
744 result = (value - 23) * 15;
745 break;
746 #endif
747 default:
748 result = value;
749 break;
752 return result;
753 #elif defined(HAVE_WM8978) || defined(HAVE_WM8750) || defined(HAVE_WM8751)
754 int result;
756 switch (setting)
758 #ifdef HAVE_RECORDING
759 case SOUND_LEFT_GAIN:
760 case SOUND_RIGHT_GAIN:
761 case SOUND_MIC_GAIN:
762 result = value * 5;
763 break;
764 #endif
765 #ifdef AUDIOHW_HAVE_DEPTH_3D
766 case SOUND_DEPTH_3D:
767 result = (100 * value + 8) / 15;
768 break;
769 #endif
770 default:
771 result = value;
774 return result;
775 #else
776 (void)setting;
777 return value;
778 #endif
780 #endif /* CONFIG_CODECs || PLATFORM_HOSTED */
782 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
783 /* This function works by telling the decoder that we have another
784 crystal frequency than we actually have. It will adjust its internal
785 parameters and the result is that the audio is played at another pitch.
787 The pitch value precision is based on PITCH_SPEED_PRECISION (in dsp.h)
790 static int last_pitch = PITCH_SPEED_100;
792 void sound_set_pitch(int32_t pitch)
794 unsigned long val;
796 if (pitch != last_pitch)
798 /* Calculate the new (bogus) frequency */
799 val = 18432 * PITCH_SPEED_100 / pitch;
801 audiohw_set_pitch(val);
803 last_pitch = pitch;
807 int32_t sound_get_pitch(void)
809 return last_pitch;
811 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */