Small improvements for the on screen popup on 320x480 cabbiev2 wps.
[maemo-rb.git] / firmware / sound.c
blobf5adff6562bb9826ae0688b0547e8b9b5a9a60cc
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 audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r));
257 #if defined(HAVE_WM8975) || defined(HAVE_WM8758) \
258 || defined(HAVE_WM8750) || (defined(HAVE_WM8751) && !defined(MROBE_100)) \
259 || defined(HAVE_WM8985)
260 audiohw_set_lineout_vol(tenthdb2master(0), tenthdb2master(0));
261 #endif
263 #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985)
264 audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r));
265 #elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
266 audiohw_set_volume(current_volume);
267 #endif
268 #else /* HAVE_SDL_AUDIO */
269 audiohw_set_volume(current_volume);
270 #endif /* !HAVE_SDL_AUDIO */
272 #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */
274 void sound_set_volume(int value)
276 if(!audio_is_initialized)
277 return;
279 #if defined(AUDIOHW_HAVE_CLIPPING)
280 audiohw_set_volume(value);
281 #elif CONFIG_CPU == PNX0101
282 int tmp = (60 - value * 4) & 0xff;
283 CODECVOL = tmp | (tmp << 8);
284 #else
285 current_volume = value * 10; /* tenth of dB */
286 set_prescaled_volume();
287 #endif
290 void sound_set_balance(int value)
292 if(!audio_is_initialized)
293 return;
295 #ifdef AUDIOHW_HAVE_BALANCE
296 audiohw_set_balance(value);
297 #else
298 current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */
299 set_prescaled_volume();
300 #endif
303 #ifdef AUDIOHW_HAVE_BASS
304 void sound_set_bass(int value)
306 if(!audio_is_initialized)
307 return;
309 #if !defined(AUDIOHW_HAVE_CLIPPING)
310 #if defined(HAVE_WM8750) || defined(HAVE_WM8751)
311 current_bass = value;
312 #else
313 current_bass = value * 10;
314 #endif
315 #endif
317 #if defined(HAVE_SW_TONE_CONTROLS)
318 dsp_callback(DSP_CALLBACK_SET_BASS, current_bass);
319 #else
320 audiohw_set_bass(value);
321 #endif
323 #if !defined(AUDIOHW_HAVE_CLIPPING)
324 set_prescaled_volume();
325 #endif
327 #endif /* AUDIOHW_HAVE_BASS */
329 #ifdef AUDIOHW_HAVE_TREBLE
330 void sound_set_treble(int value)
332 if(!audio_is_initialized)
333 return;
335 #if !defined(AUDIOHW_HAVE_CLIPPING)
336 #if defined(HAVE_WM8750) || defined(HAVE_WM8751)
337 current_treble = value;
338 #else
339 current_treble = value * 10;
340 #endif
341 #endif
343 #if defined(HAVE_SW_TONE_CONTROLS)
344 dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble);
345 #else
346 audiohw_set_treble(value);
347 #endif
349 #if !defined(AUDIOHW_HAVE_CLIPPING)
350 set_prescaled_volume();
351 #endif
353 #endif /* AUDIOHW_HAVE_TREBLE */
355 #if defined(AUDIOHW_HAVE_BASS_CUTOFF)
356 void sound_set_bass_cutoff(int value)
358 if(!audio_is_initialized)
359 return;
361 audiohw_set_bass_cutoff(value);
363 #endif
365 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
366 void sound_set_treble_cutoff(int value)
368 if(!audio_is_initialized)
369 return;
371 audiohw_set_treble_cutoff(value);
373 #endif
375 void sound_set_channels(int value)
377 if(!audio_is_initialized)
378 return;
380 #if CONFIG_CODEC == SWCODEC
381 dsp_callback(DSP_CALLBACK_SET_CHANNEL_CONFIG, value);
382 #else
383 audiohw_set_channel(value);
384 #endif
387 void sound_set_stereo_width(int value)
389 if(!audio_is_initialized)
390 return;
392 #if CONFIG_CODEC == SWCODEC
393 dsp_callback(DSP_CALLBACK_SET_STEREO_WIDTH, value);
394 #else
395 audiohw_set_stereo_width(value);
396 #endif
399 #if defined(AUDIOHW_HAVE_DEPTH_3D)
400 void sound_set_depth_3d(int value)
402 if(!audio_is_initialized)
403 return;
405 audiohw_set_depth_3d(value);
407 #endif
409 #if defined(AUDIOHW_HAVE_EQ)
410 int sound_enum_hw_eq_band_setting(unsigned int band,
411 unsigned int band_setting)
413 static const int8_t
414 sound_hw_eq_band_setting[AUDIOHW_EQ_SETTING_NUM][AUDIOHW_EQ_BAND_NUM] =
416 [AUDIOHW_EQ_GAIN] =
418 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
419 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_GAIN,
420 #ifdef AUDIOHW_HAVE_EQ_BAND2
421 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_GAIN,
422 #endif
423 #ifdef AUDIOHW_HAVE_EQ_BAND3
424 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_GAIN,
425 #endif
426 #ifdef AUDIOHW_HAVE_EQ_BAND4
427 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_GAIN,
428 #endif
429 #ifdef AUDIOHW_HAVE_EQ_BAND5
430 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_GAIN,
431 #endif
433 #ifdef AUDIOHW_HAVE_EQ_FREQUENCY
434 [AUDIOHW_EQ_FREQUENCY] =
436 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
437 #ifdef AUDIOHW_HAVE_EQ_BAND1_FREQUENCY
438 [AUDIOHW_EQ_BAND1] = SOUND_EQ_BAND1_FREQUENCY,
439 #endif
440 #ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
441 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_FREQUENCY,
442 #endif
443 #ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
444 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_FREQUENCY,
445 #endif
446 #ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
447 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_FREQUENCY,
448 #endif
449 #ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
450 [AUDIOHW_EQ_BAND5] = SOUND_EQ_BAND5_FREQUENCY,
451 #endif
453 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
454 #ifdef AUDIOHW_HAVE_EQ_WIDTH
455 [AUDIOHW_EQ_WIDTH] =
457 [0 ... AUDIOHW_EQ_BAND_NUM-1] = -1,
458 #ifdef AUDIOHW_HAVE_EQ_BAND2_WIDTH
459 [AUDIOHW_EQ_BAND2] = SOUND_EQ_BAND2_WIDTH,
460 #endif
461 #ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
462 [AUDIOHW_EQ_BAND3] = SOUND_EQ_BAND3_WIDTH,
463 #endif
464 #ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
465 [AUDIOHW_EQ_BAND4] = SOUND_EQ_BAND4_WIDTH,
466 #endif
468 #endif /* AUDIOHW_HAVE_EQ_WIDTH */
471 if (band < AUDIOHW_EQ_BAND_NUM && band_setting < AUDIOHW_EQ_SETTING_NUM)
472 return sound_hw_eq_band_setting[band_setting][band];
474 return -1;
477 static void sound_set_hw_eq_band_gain(unsigned int band, int value)
479 if(!audio_is_initialized)
480 return;
482 current_eq_band_gain[band] = value;
483 audiohw_set_eq_band_gain(band, value);
484 set_prescaled_volume();
487 void sound_set_hw_eq_band1_gain(int value)
489 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND1, value);
492 #if defined(AUDIOHW_HAVE_EQ_BAND2)
493 void sound_set_hw_eq_band2_gain(int value)
495 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND2, value);
497 #endif
499 #if defined(AUDIOHW_HAVE_EQ_BAND3)
500 void sound_set_hw_eq_band3_gain(int value)
502 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND3, value);
504 #endif
506 #if defined(AUDIOHW_HAVE_EQ_BAND4)
507 void sound_set_hw_eq_band4_gain(int value)
509 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND4, value);
511 #endif
513 #if defined(AUDIOHW_HAVE_EQ_BAND5)
514 void sound_set_hw_eq_band5_gain(int value)
516 sound_set_hw_eq_band_gain(AUDIOHW_EQ_BAND5, value);
518 #endif
520 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
521 void sound_set_hw_eq_band1_frequency(int value)
523 if(!audio_is_initialized)
524 return;
526 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value);
528 #endif
530 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
531 void sound_set_hw_eq_band2_frequency(int value)
533 if(!audio_is_initialized)
534 return;
536 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value);
538 #endif
540 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
541 void sound_set_hw_eq_band3_frequency(int value)
543 if(!audio_is_initialized)
544 return;
546 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value);
548 #endif
550 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
551 void sound_set_hw_eq_band4_frequency(int value)
553 if(!audio_is_initialized)
554 return;
556 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value);
558 #endif
560 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
561 void sound_set_hw_eq_band5_frequency(int value)
563 if(!audio_is_initialized)
564 return;
566 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value);
568 #endif
570 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
571 void sound_set_hw_eq_band2_width(int value)
573 if(!audio_is_initialized)
574 return;
576 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value);
578 #endif
580 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
581 void sound_set_hw_eq_band3_width(int value)
583 if(!audio_is_initialized)
584 return;
586 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value);
588 #endif
590 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
591 void sound_set_hw_eq_band4_width(int value)
593 if(!audio_is_initialized)
594 return;
596 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value);
598 #endif
599 #endif /* AUDIOHW_HAVE_EQ */
601 #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F))
602 void sound_set_loudness(int value)
604 if(!audio_is_initialized)
605 return;
607 audiohw_set_loudness(value);
610 void sound_set_avc(int value)
612 if(!audio_is_initialized)
613 return;
615 audiohw_set_avc(value);
618 void sound_set_mdb_strength(int value)
620 if(!audio_is_initialized)
621 return;
623 audiohw_set_mdb_strength(value);
626 void sound_set_mdb_harmonics(int value)
628 if(!audio_is_initialized)
629 return;
631 audiohw_set_mdb_harmonics(value);
634 void sound_set_mdb_center(int value)
636 if(!audio_is_initialized)
637 return;
639 audiohw_set_mdb_center(value);
642 void sound_set_mdb_shape(int value)
644 if(!audio_is_initialized)
645 return;
647 audiohw_set_mdb_shape(value);
650 void sound_set_mdb_enable(int value)
652 if(!audio_is_initialized)
653 return;
655 audiohw_set_mdb_enable(value);
658 void sound_set_superbass(int value)
660 if(!audio_is_initialized)
661 return;
663 audiohw_set_superbass(value);
665 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */
667 void sound_set(int setting, int value)
669 sound_set_type* sound_set_val = sound_get_fn(setting);
670 if (sound_set_val)
671 sound_set_val(value);
674 #if (!defined(HAVE_AS3514) && !defined(HAVE_WM8975) \
675 && !defined(HAVE_WM8758) && !defined(HAVE_TSC2100) \
676 && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \
677 && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \
678 && !defined(HAVE_AK4537)) || (CONFIG_PLATFORM & PLATFORM_HOSTED)
679 int sound_val2phys(int setting, int value)
681 #if CONFIG_CODEC == MAS3587F
682 int result = 0;
684 switch(setting)
686 case SOUND_LEFT_GAIN:
687 case SOUND_RIGHT_GAIN:
688 result = (value - 2) * 15;
689 break;
691 case SOUND_MIC_GAIN:
692 result = value * 15 + 210;
693 break;
695 default:
696 result = value;
697 break;
699 return result;
700 #elif defined(HAVE_UDA1380)
701 int result = 0;
703 switch(setting)
705 #ifdef HAVE_RECORDING
706 case SOUND_LEFT_GAIN:
707 case SOUND_RIGHT_GAIN:
708 case SOUND_MIC_GAIN:
709 result = value * 5; /* (1/2) * 10 */
710 break;
711 #endif
712 default:
713 result = value;
714 break;
716 return result;
717 #elif defined(HAVE_TLV320) || defined(HAVE_WM8711) \
718 || defined(HAVE_WM8721) || defined(HAVE_WM8731)
719 int result = 0;
721 switch(setting)
723 #ifdef HAVE_RECORDING
724 case SOUND_LEFT_GAIN:
725 case SOUND_RIGHT_GAIN:
726 result = (value - 23) * 15; /* (x - 23)/1.5 *10 */
727 break;
729 case SOUND_MIC_GAIN:
730 result = value * 200; /* 0 or 20 dB */
731 break;
732 #endif
733 default:
734 result = value;
735 break;
737 return result;
738 #elif defined(HAVE_AS3514)
739 /* This is here for the sim only and the audio driver has its own */
740 int result;
742 switch(setting)
744 #ifdef HAVE_RECORDING
745 case SOUND_LEFT_GAIN:
746 case SOUND_RIGHT_GAIN:
747 case SOUND_MIC_GAIN:
748 result = (value - 23) * 15;
749 break;
750 #endif
751 default:
752 result = value;
753 break;
756 return result;
757 #elif defined(HAVE_WM8978)
758 int result;
760 switch (setting)
762 #ifdef HAVE_RECORDING
763 case SOUND_LEFT_GAIN:
764 case SOUND_RIGHT_GAIN:
765 case SOUND_MIC_GAIN:
766 result = value * 5;
767 break;
768 #endif
770 case SOUND_DEPTH_3D:
771 result = (100 * value + 8) / 15;
772 break;
774 default:
775 result = value;
778 return result;
779 #else
780 (void)setting;
781 return value;
782 #endif
784 #endif /* CONFIG_CODECs || PLATFORM_HOSTED */
786 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
787 /* This function works by telling the decoder that we have another
788 crystal frequency than we actually have. It will adjust its internal
789 parameters and the result is that the audio is played at another pitch.
791 The pitch value precision is based on PITCH_SPEED_PRECISION (in dsp.h)
794 static int last_pitch = PITCH_SPEED_100;
796 void sound_set_pitch(int32_t pitch)
798 unsigned long val;
800 if (pitch != last_pitch)
802 /* Calculate the new (bogus) frequency */
803 val = 18432 * PITCH_SPEED_100 / pitch;
805 audiohw_set_pitch(val);
807 last_pitch = pitch;
811 int32_t sound_get_pitch(void)
813 return last_pitch;
815 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */