1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
29 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
30 #if CONFIG_CPU == PNX0101
32 #endif /* CONFIG_CPU == PNX101 */
33 #if CONFIG_CODEC == SWCODEC
35 #else /* !CONFIG_CODEC == HWCODEC */
39 #endif /* !SIMULATOR */
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
,
84 #if defined(AUDIOHW_HAVE_TREBLE)
85 [SOUND_TREBLE
] = sound_set_treble
,
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
,
103 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
104 [SOUND_TREBLE_CUTOFF
] = sound_set_treble_cutoff
,
106 #if defined(AUDIOHW_HAVE_DEPTH_3D)
107 [SOUND_DEPTH_3D
] = sound_set_depth_3d
,
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
,
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
,
120 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
121 [SOUND_EQ_BAND2_WIDTH
] = sound_set_hw_eq_band2_width
,
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
,
129 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
130 [SOUND_EQ_BAND3_WIDTH
] = sound_set_hw_eq_band3_width
,
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
,
138 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
139 [SOUND_EQ_BAND4_WIDTH
] = sound_set_hw_eq_band4_width
,
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
,
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))
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 */
182 #ifdef AUDIOHW_HAVE_BASS
183 static int current_bass
= 0; /* -150..+150 0..+240 */
185 #ifdef AUDIOHW_HAVE_EQ
186 static int current_eq_band_gain
[AUDIOHW_EQ_BAND_NUM
];
189 static void set_prescaled_volume(void)
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
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
);
206 #if defined(AUDIOHW_HAVE_EQ)
208 for (i
= 0; i
< AUDIOHW_EQ_BAND_NUM
; i
++)
209 prescale
= MAX(current_eq_band_gain
[i
], prescale
);
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
;
223 #if defined(AUDIOHW_HAVE_PRESCALER)
224 audiohw_set_prescaler(prescale
);
226 dsp_callback(DSP_CALLBACK_SET_PRESCALE
, prescale
);
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);
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));
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
);
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
)
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);
286 current_volume
= value
* 10; /* tenth of dB */
287 set_prescaled_volume();
291 void sound_set_balance(int value
)
293 if(!audio_is_initialized
)
296 #ifdef AUDIOHW_HAVE_BALANCE
297 audiohw_set_balance(value
);
299 current_balance
= value
* VOLUME_RANGE
/ 100; /* tenth of dB */
300 set_prescaled_volume();
304 #ifdef AUDIOHW_HAVE_BASS
305 void sound_set_bass(int value
)
307 if(!audio_is_initialized
)
310 #if !defined(AUDIOHW_HAVE_CLIPPING)
311 #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55)
312 current_bass
= value
;
314 current_bass
= value
* 10;
318 #if defined(HAVE_SW_TONE_CONTROLS)
319 dsp_callback(DSP_CALLBACK_SET_BASS
, current_bass
);
321 audiohw_set_bass(value
);
324 #if !defined(AUDIOHW_HAVE_CLIPPING)
325 set_prescaled_volume();
328 #endif /* AUDIOHW_HAVE_BASS */
330 #ifdef AUDIOHW_HAVE_TREBLE
331 void sound_set_treble(int value
)
333 if(!audio_is_initialized
)
336 #if !defined(AUDIOHW_HAVE_CLIPPING)
337 #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55)
338 current_treble
= value
;
340 current_treble
= value
* 10;
344 #if defined(HAVE_SW_TONE_CONTROLS)
345 dsp_callback(DSP_CALLBACK_SET_TREBLE
, current_treble
);
347 audiohw_set_treble(value
);
350 #if !defined(AUDIOHW_HAVE_CLIPPING)
351 set_prescaled_volume();
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
)
362 audiohw_set_bass_cutoff(value
);
366 #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF)
367 void sound_set_treble_cutoff(int value
)
369 if(!audio_is_initialized
)
372 audiohw_set_treble_cutoff(value
);
376 void sound_set_channels(int value
)
378 if(!audio_is_initialized
)
381 #if CONFIG_CODEC == SWCODEC
382 dsp_callback(DSP_CALLBACK_SET_CHANNEL_CONFIG
, value
);
384 audiohw_set_channel(value
);
388 void sound_set_stereo_width(int value
)
390 if(!audio_is_initialized
)
393 #if CONFIG_CODEC == SWCODEC
394 dsp_callback(DSP_CALLBACK_SET_STEREO_WIDTH
, value
);
396 audiohw_set_stereo_width(value
);
400 #if defined(AUDIOHW_HAVE_DEPTH_3D)
401 void sound_set_depth_3d(int value
)
403 if(!audio_is_initialized
)
406 audiohw_set_depth_3d(value
);
410 #if defined(AUDIOHW_HAVE_EQ)
411 int sound_enum_hw_eq_band_setting(unsigned int band
,
412 unsigned int band_setting
)
415 sound_hw_eq_band_setting
[AUDIOHW_EQ_SETTING_NUM
][AUDIOHW_EQ_BAND_NUM
] =
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
,
424 #ifdef AUDIOHW_HAVE_EQ_BAND3
425 [AUDIOHW_EQ_BAND3
] = SOUND_EQ_BAND3_GAIN
,
427 #ifdef AUDIOHW_HAVE_EQ_BAND4
428 [AUDIOHW_EQ_BAND4
] = SOUND_EQ_BAND4_GAIN
,
430 #ifdef AUDIOHW_HAVE_EQ_BAND5
431 [AUDIOHW_EQ_BAND5
] = SOUND_EQ_BAND5_GAIN
,
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
,
441 #ifdef AUDIOHW_HAVE_EQ_BAND2_FREQUENCY
442 [AUDIOHW_EQ_BAND2
] = SOUND_EQ_BAND2_FREQUENCY
,
444 #ifdef AUDIOHW_HAVE_EQ_BAND3_FREQUENCY
445 [AUDIOHW_EQ_BAND3
] = SOUND_EQ_BAND3_FREQUENCY
,
447 #ifdef AUDIOHW_HAVE_EQ_BAND4_FREQUENCY
448 [AUDIOHW_EQ_BAND4
] = SOUND_EQ_BAND4_FREQUENCY
,
450 #ifdef AUDIOHW_HAVE_EQ_BAND5_FREQUENCY
451 [AUDIOHW_EQ_BAND5
] = SOUND_EQ_BAND5_FREQUENCY
,
454 #endif /* AUDIOHW_HAVE_EQ_FREQUENCY */
455 #ifdef AUDIOHW_HAVE_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
,
462 #ifdef AUDIOHW_HAVE_EQ_BAND3_WIDTH
463 [AUDIOHW_EQ_BAND3
] = SOUND_EQ_BAND3_WIDTH
,
465 #ifdef AUDIOHW_HAVE_EQ_BAND4_WIDTH
466 [AUDIOHW_EQ_BAND4
] = SOUND_EQ_BAND4_WIDTH
,
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
];
478 static void sound_set_hw_eq_band_gain(unsigned int band
, int value
)
482 if(!audio_is_initialized
)
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
);
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
);
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
);
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
);
525 #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY)
526 void sound_set_hw_eq_band1_frequency(int value
)
528 if(!audio_is_initialized
)
531 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1
, value
);
535 #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY)
536 void sound_set_hw_eq_band2_frequency(int value
)
538 if(!audio_is_initialized
)
541 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2
, value
);
545 #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY)
546 void sound_set_hw_eq_band3_frequency(int value
)
548 if(!audio_is_initialized
)
551 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3
, value
);
555 #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY)
556 void sound_set_hw_eq_band4_frequency(int value
)
558 if(!audio_is_initialized
)
561 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4
, value
);
565 #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY)
566 void sound_set_hw_eq_band5_frequency(int value
)
568 if(!audio_is_initialized
)
571 audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5
, value
);
575 #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH)
576 void sound_set_hw_eq_band2_width(int value
)
578 if(!audio_is_initialized
)
581 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2
, value
);
585 #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH)
586 void sound_set_hw_eq_band3_width(int value
)
588 if(!audio_is_initialized
)
591 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3
, value
);
595 #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH)
596 void sound_set_hw_eq_band4_width(int value
)
598 if(!audio_is_initialized
)
601 audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4
, value
);
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
)
612 audiohw_set_loudness(value
);
615 void sound_set_avc(int value
)
617 if(!audio_is_initialized
)
620 audiohw_set_avc(value
);
623 void sound_set_mdb_strength(int value
)
625 if(!audio_is_initialized
)
628 audiohw_set_mdb_strength(value
);
631 void sound_set_mdb_harmonics(int value
)
633 if(!audio_is_initialized
)
636 audiohw_set_mdb_harmonics(value
);
639 void sound_set_mdb_center(int value
)
641 if(!audio_is_initialized
)
644 audiohw_set_mdb_center(value
);
647 void sound_set_mdb_shape(int value
)
649 if(!audio_is_initialized
)
652 audiohw_set_mdb_shape(value
);
655 void sound_set_mdb_enable(int value
)
657 if(!audio_is_initialized
)
660 audiohw_set_mdb_enable(value
);
663 void sound_set_superbass(int value
)
665 if(!audio_is_initialized
)
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
);
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
691 case SOUND_LEFT_GAIN
:
692 case SOUND_RIGHT_GAIN
:
693 result
= (value
- 2) * 15;
697 result
= value
* 15 + 210;
705 #elif defined(HAVE_UDA1380)
710 #ifdef HAVE_RECORDING
711 case SOUND_LEFT_GAIN
:
712 case SOUND_RIGHT_GAIN
:
714 result
= value
* 5; /* (1/2) * 10 */
722 #elif defined(HAVE_TLV320) || defined(HAVE_WM8711) \
723 || defined(HAVE_WM8721) || defined(HAVE_WM8731)
728 #ifdef HAVE_RECORDING
729 case SOUND_LEFT_GAIN
:
730 case SOUND_RIGHT_GAIN
:
731 result
= (value
- 23) * 15; /* (x - 23)/1.5 *10 */
735 result
= value
* 200; /* 0 or 20 dB */
743 #elif defined(HAVE_AS3514)
744 /* This is here for the sim only and the audio driver has its own */
749 #ifdef HAVE_RECORDING
750 case SOUND_LEFT_GAIN
:
751 case SOUND_RIGHT_GAIN
:
753 result
= (value
- 23) * 15;
762 #elif defined(HAVE_WM8978)
767 #ifdef HAVE_RECORDING
768 case SOUND_LEFT_GAIN
:
769 case SOUND_RIGHT_GAIN
:
776 result
= (100 * value
+ 8) / 15;
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
)
805 if (pitch
!= last_pitch
)
807 /* Calculate the new (bogus) frequency */
808 val
= 18432 * PITCH_SPEED_100
/ pitch
;
810 audiohw_set_pitch(val
);
816 int32_t sound_get_pitch(void)
820 #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */