diff options
Diffstat (limited to 'firmware/sound.c')
-rw-r--r-- | firmware/sound.c | 489 |
1 files changed, 126 insertions, 363 deletions
diff --git a/firmware/sound.c b/firmware/sound.c index 7c86b0bf05..4c390f4a5b 100644 --- a/firmware/sound.c +++ b/firmware/sound.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * | 9 | * |
10 | * Copyright (C) 2005 by Linus Nielsen Feltzing | 10 | * Copyright (C) 2005 by Linus Nielsen Feltzing |
11 | * Copyright (C) 2007 by Christian Gmeiner | 11 | * Copyright (C) 2007 by Christian Gmeiner |
12 | * Copyright (C) 2013 by Michael Sevakis | ||
12 | * | 13 | * |
13 | * This program is free software; you can redistribute it and/or | 14 | * This program is free software; you can redistribute it and/or |
14 | * modify it under the terms of the GNU General Public License | 15 | * modify it under the terms of the GNU General Public License |
@@ -19,141 +20,95 @@ | |||
19 | * KIND, either express or implied. | 20 | * KIND, either express or implied. |
20 | * | 21 | * |
21 | ****************************************************************************/ | 22 | ****************************************************************************/ |
22 | #include <stdbool.h> | 23 | /* Indicate it's the sound.c file which affects compilation of audiohw.h */ |
23 | #include <stdio.h> | 24 | #define AUDIOHW_IS_SOUND_C |
24 | #include "config.h" | 25 | #include "config.h" |
25 | #include "sound.h" | ||
26 | #include "logf.h" | ||
27 | #include "system.h" | 26 | #include "system.h" |
28 | #include "i2c.h" | 27 | #include "sound.h" |
28 | #include "fixedpoint.h" | ||
29 | #ifdef HAVE_SW_VOLUME_CONTROL | 29 | #ifdef HAVE_SW_VOLUME_CONTROL |
30 | #include "pcm_sw_volume.h" | 30 | #include "pcm_sw_volume.h" |
31 | #endif /* HAVE_SW_VOLUME_CONTROL */ | 31 | #endif /* HAVE_SW_VOLUME_CONTROL */ |
32 | 32 | ||
33 | /* TODO | 33 | /* Define sound_setting_entries table */ |
34 | * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble | 34 | #define AUDIOHW_SOUND_SETTINGS_ENTRIES |
35 | */ | 35 | #include "audiohw_settings.h" |
36 | |||
37 | /* Implements sound_val2phys */ | ||
38 | #define AUDIOHW_SOUND_SETTINGS_VAL2PHYS | ||
39 | #include "audiohw_settings.h" | ||
36 | 40 | ||
37 | extern bool audio_is_initialized; | 41 | extern bool audio_is_initialized; |
38 | 42 | ||
39 | const char *sound_unit(int setting) | 43 | static const struct sound_setting_entry * get_setting_entry(int setting) |
40 | { | 44 | { |
41 | return audiohw_settings[setting].unit; | 45 | static const struct sound_settings_info default_info = |
46 | { "", 0, 0, 0, 0, 0 }; | ||
47 | |||
48 | static const struct sound_setting_entry default_entry = | ||
49 | { &default_info, NULL }; | ||
50 | |||
51 | if ((unsigned)setting >= ARRAYLEN(sound_setting_entries)) | ||
52 | return &default_entry; | ||
53 | |||
54 | const struct sound_setting_entry *e = &sound_setting_entries[setting]; | ||
55 | return e->info ? e : &default_entry; /* setting valid but not in table? */ | ||
56 | } | ||
57 | |||
58 | static const struct sound_settings_info * get_settings_info(int setting) | ||
59 | { | ||
60 | return get_setting_entry(setting)->info; | ||
61 | } | ||
62 | |||
63 | const char * sound_unit(int setting) | ||
64 | { | ||
65 | return get_settings_info(setting)->unit; | ||
42 | } | 66 | } |
43 | 67 | ||
44 | int sound_numdecimals(int setting) | 68 | int sound_numdecimals(int setting) |
45 | { | 69 | { |
46 | return audiohw_settings[setting].numdecimals; | 70 | return get_settings_info(setting)->numdecimals; |
47 | } | 71 | } |
48 | 72 | ||
49 | int sound_steps(int setting) | 73 | int sound_steps(int setting) |
50 | { | 74 | { |
51 | return audiohw_settings[setting].steps; | 75 | return get_settings_info(setting)->steps; |
52 | } | 76 | } |
53 | 77 | ||
54 | int sound_min(int setting) | 78 | int sound_min(int setting) |
55 | { | 79 | { |
56 | return audiohw_settings[setting].minval; | 80 | return get_settings_info(setting)->minval; |
57 | } | 81 | } |
58 | 82 | ||
59 | int sound_max(int setting) | 83 | int sound_max(int setting) |
60 | { | 84 | { |
61 | return audiohw_settings[setting].maxval; | 85 | return get_settings_info(setting)->maxval; |
62 | } | 86 | } |
63 | 87 | ||
64 | int sound_default(int setting) | 88 | int sound_default(int setting) |
65 | { | 89 | { |
66 | return audiohw_settings[setting].defaultval; | 90 | return get_settings_info(setting)->defaultval; |
67 | } | 91 | } |
68 | 92 | ||
69 | static sound_set_type * const sound_set_fns[] = | 93 | sound_set_type * sound_get_fn(int setting) |
70 | { | 94 | { |
71 | [0 ... SOUND_LAST_SETTING-1] = NULL, | 95 | return get_setting_entry(setting)->function; |
72 | [SOUND_VOLUME] = sound_set_volume, | 96 | } |
73 | #if defined(AUDIOHW_HAVE_BASS) | ||
74 | [SOUND_BASS] = sound_set_bass, | ||
75 | #endif | ||
76 | #if defined(AUDIOHW_HAVE_TREBLE) | ||
77 | [SOUND_TREBLE] = sound_set_treble, | ||
78 | #endif | ||
79 | [SOUND_BALANCE] = sound_set_balance, | ||
80 | [SOUND_CHANNELS] = sound_set_channels, | ||
81 | [SOUND_STEREO_WIDTH] = sound_set_stereo_width, | ||
82 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
83 | [SOUND_LOUDNESS] = sound_set_loudness, | ||
84 | [SOUND_AVC] = sound_set_avc, | ||
85 | [SOUND_MDB_STRENGTH] = sound_set_mdb_strength, | ||
86 | [SOUND_MDB_HARMONICS] = sound_set_mdb_harmonics, | ||
87 | [SOUND_MDB_CENTER] = sound_set_mdb_center, | ||
88 | [SOUND_MDB_SHAPE] = sound_set_mdb_shape, | ||
89 | [SOUND_MDB_ENABLE] = sound_set_mdb_enable, | ||
90 | [SOUND_SUPERBASS] = sound_set_superbass, | ||
91 | #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ | ||
92 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) | ||
93 | [SOUND_BASS_CUTOFF] = sound_set_bass_cutoff, | ||
94 | #endif | ||
95 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) | ||
96 | [SOUND_TREBLE_CUTOFF] = sound_set_treble_cutoff, | ||
97 | #endif | ||
98 | #if defined(AUDIOHW_HAVE_DEPTH_3D) | ||
99 | [SOUND_DEPTH_3D] = sound_set_depth_3d, | ||
100 | #endif | ||
101 | /* Hardware EQ tone controls */ | ||
102 | #if defined(AUDIOHW_HAVE_EQ) | ||
103 | [SOUND_EQ_BAND1_GAIN] = sound_set_hw_eq_band1_gain, | ||
104 | #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY) | ||
105 | [SOUND_EQ_BAND1_FREQUENCY] = sound_set_hw_eq_band1_frequency, | ||
106 | #endif | ||
107 | #if defined(AUDIOHW_HAVE_EQ_BAND2) | ||
108 | [SOUND_EQ_BAND2_GAIN] = sound_set_hw_eq_band2_gain, | ||
109 | #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY) | ||
110 | [SOUND_EQ_BAND2_FREQUENCY] = sound_set_hw_eq_band2_frequency, | ||
111 | #endif | ||
112 | #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH) | ||
113 | [SOUND_EQ_BAND2_WIDTH] = sound_set_hw_eq_band2_width, | ||
114 | #endif | ||
115 | #endif /* AUDIOHW_HAVE_EQ_BAND2 */ | ||
116 | #if defined(AUDIOHW_HAVE_EQ_BAND3) | ||
117 | [SOUND_EQ_BAND3_GAIN] = sound_set_hw_eq_band3_gain, | ||
118 | #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY) | ||
119 | [SOUND_EQ_BAND3_FREQUENCY] = sound_set_hw_eq_band3_frequency, | ||
120 | #endif | ||
121 | #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH) | ||
122 | [SOUND_EQ_BAND3_WIDTH] = sound_set_hw_eq_band3_width, | ||
123 | #endif | ||
124 | #endif /* AUDIOHW_HAVE_EQ_BAND3 */ | ||
125 | #if defined(AUDIOHW_HAVE_EQ_BAND4) | ||
126 | [SOUND_EQ_BAND4_GAIN] = sound_set_hw_eq_band4_gain, | ||
127 | #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY) | ||
128 | [SOUND_EQ_BAND4_FREQUENCY] = sound_set_hw_eq_band4_frequency, | ||
129 | #endif | ||
130 | #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH) | ||
131 | [SOUND_EQ_BAND4_WIDTH] = sound_set_hw_eq_band4_width, | ||
132 | #endif | ||
133 | #endif /* AUDIOHW_HAVE_EQ_BAND4 */ | ||
134 | #if defined(AUDIOHW_HAVE_EQ_BAND5) | ||
135 | [SOUND_EQ_BAND5_GAIN] = sound_set_hw_eq_band5_gain, | ||
136 | #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY) | ||
137 | [SOUND_EQ_BAND5_FREQUENCY] = sound_set_hw_eq_band5_frequency, | ||
138 | #endif | ||
139 | #endif /* AUDIOHW_HAVE_EQ_BAND5 */ | ||
140 | #endif /* AUDIOHW_HAVE_EQ */ | ||
141 | }; | ||
142 | 97 | ||
143 | sound_set_type* sound_get_fn(int setting) | 98 | void sound_set(int setting, int value) |
144 | { | 99 | { |
145 | return ((unsigned)setting >= ARRAYLEN(sound_set_fns)? | 100 | sound_set_type *sound_set_val = sound_get_fn(setting); |
146 | NULL : sound_set_fns[setting]); | ||
147 | } | ||
148 | 101 | ||
149 | #if CONFIG_CODEC == SWCODEC | 102 | if (sound_set_val) |
150 | static int (*dsp_callback)(int, intptr_t) = NULL; | 103 | sound_set_val(value); |
104 | } | ||
151 | 105 | ||
152 | void sound_set_dsp_callback(int (*func)(int, intptr_t)) | 106 | /* Return the sound value scaled to centibels (tenth-decibels) */ |
107 | static int sound_value_to_cb(int setting, int value) | ||
153 | { | 108 | { |
154 | dsp_callback = func; | 109 | long e = (1 - sound_numdecimals(setting)) << 16; |
110 | return fp_mul(value, fp_exp10(e, 16), 16); | ||
155 | } | 111 | } |
156 | #endif | ||
157 | 112 | ||
158 | #if !defined(AUDIOHW_HAVE_CLIPPING) | 113 | #if !defined(AUDIOHW_HAVE_CLIPPING) |
159 | /* | 114 | /* |
@@ -165,39 +120,31 @@ void sound_set_dsp_callback(int (*func)(int, intptr_t)) | |||
165 | * by 12 dB after processing. | 120 | * by 12 dB after processing. |
166 | */ | 121 | */ |
167 | 122 | ||
168 | /* all values in tenth of dB MAS3507D UDA1380 */ | 123 | static int current_volume = 0; /* tenth dB */ |
169 | static int current_volume = 0; /* -780..+180 -840.. 0 */ | 124 | static int current_balance = 0; /* percent */ |
170 | static int current_balance = 0; /* -960..+960 -840..+840 */ | ||
171 | #ifdef AUDIOHW_HAVE_TREBLE | 125 | #ifdef AUDIOHW_HAVE_TREBLE |
172 | static int current_treble = 0; /* -150..+150 0.. +60 */ | 126 | static int current_treble = 0; /* tenth dB */ |
173 | #endif | 127 | #endif |
174 | #ifdef AUDIOHW_HAVE_BASS | 128 | #ifdef AUDIOHW_HAVE_BASS |
175 | static int current_bass = 0; /* -150..+150 0..+240 */ | 129 | static int current_bass = 0; /* tenth dB */ |
176 | #endif | 130 | #endif |
177 | #ifdef AUDIOHW_HAVE_EQ | 131 | #ifdef AUDIOHW_HAVE_EQ |
178 | static int current_eq_band_gain[AUDIOHW_EQ_BAND_NUM]; | 132 | static int current_eq_band_gain[AUDIOHW_EQ_BAND_NUM]; /* tenth dB */ |
179 | #endif | 133 | #endif |
180 | 134 | ||
181 | static void set_prescaled_volume(void) | 135 | static void set_prescaled_volume(void) |
182 | { | 136 | { |
183 | int prescale = 0; | 137 | int prescale = 0; |
184 | int l, r; | ||
185 | 138 | ||
186 | /* The codecs listed use HW tone controls but don't have suitable prescaler | 139 | #if defined(AUDIOHW_HAVE_BASS) || defined(AUDIOHW_HAVE_TREBLE) \ |
187 | * functionality, so we let the prescaler stay at 0 for these, unless | 140 | || defined(AUDIOHW_HAVE_EQ) |
188 | * SW tone controls are in use. This is to avoid needing the SW DSP just for | ||
189 | * the prescaling. | ||
190 | */ | ||
191 | #if defined(HAVE_SW_TONE_CONTROLS) || !(defined(HAVE_WM8975) \ | ||
192 | || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \ | ||
193 | || defined(HAVE_WM8758) || defined(HAVE_WM8985) || defined(HAVE_UDA1341)) | ||
194 | 141 | ||
142 | /* Note: Having Tone + EQ isn't prohibited */ | ||
195 | #if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE) | 143 | #if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE) |
196 | prescale = MAX(current_bass, current_treble); | 144 | prescale = MAX(current_bass, current_treble); |
197 | #endif | 145 | #endif |
198 | #if defined(AUDIOHW_HAVE_EQ) | 146 | #if defined(AUDIOHW_HAVE_EQ) |
199 | int i; | 147 | for (int i = 0; i < AUDIOHW_EQ_BAND_NUM; i++) |
200 | for (i = 0; i < AUDIOHW_EQ_BAND_NUM; i++) | ||
201 | prescale = MAX(current_eq_band_gain[i], prescale); | 148 | prescale = MAX(current_eq_band_gain[i], prescale); |
202 | #endif | 149 | #endif |
203 | 150 | ||
@@ -210,86 +157,65 @@ static void set_prescaled_volume(void) | |||
210 | * instead (might cause clipping). */ | 157 | * instead (might cause clipping). */ |
211 | if (current_volume + prescale > VOLUME_MAX) | 158 | if (current_volume + prescale > VOLUME_MAX) |
212 | prescale = VOLUME_MAX - current_volume; | 159 | prescale = VOLUME_MAX - current_volume; |
213 | #endif | ||
214 | 160 | ||
215 | #if defined(AUDIOHW_HAVE_PRESCALER) | ||
216 | audiohw_set_prescaler(prescale); | 161 | audiohw_set_prescaler(prescale); |
217 | #else | ||
218 | dsp_callback(DSP_CALLBACK_SET_PRESCALE, prescale); | ||
219 | #endif | ||
220 | 162 | ||
221 | if (current_volume <= VOLUME_MIN) | 163 | if (current_volume < VOLUME_MIN) |
222 | prescale = 0; /* Make sure the chip gets muted at VOLUME_MIN */ | 164 | prescale = 0; /* Make sure the audio gets muted */ |
165 | #endif /* AUDIOHW_HAVE_BASS || AUDIOHW_HAVE_TREBLE || AUDIOHW_HAVE_EQ */ | ||
223 | 166 | ||
224 | l = r = current_volume + prescale; | 167 | #if defined(AUDIOHW_HAVE_MONO_VOLUME) |
168 | audiohw_set_volume(current_volume); | ||
169 | #else /* Stereo volume */ | ||
170 | int l = current_volume + prescale, r = l; | ||
225 | 171 | ||
226 | /* Balance the channels scaled by the current volume and min volume. */ | 172 | /* Balance the channels scaled by the current volume and min volume. */ |
227 | /* Subtract a dB from VOLUME_MIN to get it to a mute level */ | 173 | /* Subtract a dB from VOLUME_MIN to get it to a mute level */ |
228 | if (current_balance > 0) | 174 | int volshift = current_balance * VOLUME_RANGE / 100; /* tenth of dB */ |
175 | |||
176 | if (volshift > 0) | ||
229 | { | 177 | { |
230 | l -= ((l - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE; | 178 | l -= ((l - (VOLUME_MIN - ONE_DB)) * volshift) / VOLUME_RANGE; |
231 | } | 179 | } |
232 | else if (current_balance < 0) | 180 | else if (volshift < 0) |
233 | { | 181 | { |
234 | r += ((r - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE; | 182 | r += ((r - (VOLUME_MIN - ONE_DB)) * volshift) / VOLUME_RANGE; |
235 | } | 183 | } |
236 | 184 | ||
237 | /* ypr0 with sdl has separate volume controls */ | 185 | audiohw_set_volume(l, r); |
238 | #if defined(HAVE_SW_VOLUME_CONTROL) | 186 | #endif /* AUDIOHW_HAVE_MONO_VOLUME */ |
239 | audiohw_set_master_vol(l, r); | ||
240 | #elif !defined(HAVE_SDL_AUDIO) || defined(SAMSUNG_YPR0) | ||
241 | #if defined(HAVE_JZ4740_CODEC) | ||
242 | audiohw_set_master_vol(l, r); | ||
243 | #elif CONFIG_CODEC == MAS3507D | ||
244 | dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); | ||
245 | #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \ | ||
246 | || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \ | ||
247 | || defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_AS3514) \ | ||
248 | || defined(HAVE_TSC2100) || defined(HAVE_AK4537) || defined(HAVE_UDA1341) \ | ||
249 | || defined(HAVE_CS42L55) || defined(HAVE_RK27XX_CODEC) | ||
250 | audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r)); | ||
251 | #if defined(HAVE_WM8975) || defined(HAVE_WM8758) \ | ||
252 | || (defined(HAVE_WM8751) && defined(TOSHIBA_GIGABEAT_F)) \ | ||
253 | || defined(HAVE_WM8985) || defined(HAVE_CS42L55) | ||
254 | audiohw_set_lineout_vol(tenthdb2master(0), tenthdb2master(0)); | ||
255 | #endif | ||
256 | 187 | ||
257 | #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) || defined(HAVE_IMX233_CODEC) || defined(HAVE_AIC3X) | 188 | #if defined(AUDIOHW_HAVE_LINEOUT) |
258 | audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r)); | 189 | /* For now, lineout stays at unity */ |
259 | #elif defined(HAVE_SDL_AUDIO) || defined(ANDROID) | 190 | audiohw_set_lineout_volume(0, 0); |
260 | audiohw_set_volume(current_volume); | 191 | #endif /* AUDIOHW_HAVE_LINEOUT */ |
261 | #endif | 192 | |
262 | #else /* HAVE_SDL_AUDIO */ | 193 | (void)prescale; /* In case of no tone controls + mono volume */ |
263 | audiohw_set_volume(current_volume); | ||
264 | #endif /* !HAVE_SDL_AUDIO */ | ||
265 | } | 194 | } |
266 | #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */ | 195 | #endif /* AUDIOIHW_HAVE_CLIPPING */ |
267 | 196 | ||
268 | void sound_set_volume(int value) | 197 | void sound_set_volume(int value) |
269 | { | 198 | { |
270 | if(!audio_is_initialized) | 199 | if (!audio_is_initialized) |
271 | return; | 200 | return; |
272 | 201 | ||
273 | #if defined(AUDIOHW_HAVE_CLIPPING) | 202 | #if defined(AUDIOHW_HAVE_CLIPPING) |
274 | audiohw_set_volume(value); | 203 | audiohw_set_volume(value); |
275 | #elif CONFIG_CPU == PNX0101 | ||
276 | int tmp = (60 - value * 4) & 0xff; | ||
277 | CODECVOL = tmp | (tmp << 8); | ||
278 | #else | 204 | #else |
279 | current_volume = value * 10; /* tenth of dB */ | 205 | current_volume = sound_value_to_cb(SOUND_VOLUME, value); |
280 | set_prescaled_volume(); | 206 | set_prescaled_volume(); |
281 | #endif | 207 | #endif |
282 | } | 208 | } |
283 | 209 | ||
284 | void sound_set_balance(int value) | 210 | void sound_set_balance(int value) |
285 | { | 211 | { |
286 | if(!audio_is_initialized) | 212 | if (!audio_is_initialized) |
287 | return; | 213 | return; |
288 | 214 | ||
289 | #ifdef AUDIOHW_HAVE_BALANCE | 215 | #if defined(AUDIOHW_HAVE_BALANCE) |
290 | audiohw_set_balance(value); | 216 | audiohw_set_balance(value); |
291 | #else | 217 | #else |
292 | current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */ | 218 | current_balance = value; |
293 | set_prescaled_volume(); | 219 | set_prescaled_volume(); |
294 | #endif | 220 | #endif |
295 | } | 221 | } |
@@ -297,24 +223,13 @@ void sound_set_balance(int value) | |||
297 | #ifdef AUDIOHW_HAVE_BASS | 223 | #ifdef AUDIOHW_HAVE_BASS |
298 | void sound_set_bass(int value) | 224 | void sound_set_bass(int value) |
299 | { | 225 | { |
300 | if(!audio_is_initialized) | 226 | if (!audio_is_initialized) |
301 | return; | 227 | return; |
302 | 228 | ||
303 | #if !defined(AUDIOHW_HAVE_CLIPPING) | ||
304 | #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55) | ||
305 | current_bass = value; | ||
306 | #else | ||
307 | current_bass = value * 10; | ||
308 | #endif | ||
309 | #endif | ||
310 | |||
311 | #if defined(HAVE_SW_TONE_CONTROLS) | ||
312 | dsp_callback(DSP_CALLBACK_SET_BASS, current_bass); | ||
313 | #else | ||
314 | audiohw_set_bass(value); | 229 | audiohw_set_bass(value); |
315 | #endif | ||
316 | 230 | ||
317 | #if !defined(AUDIOHW_HAVE_CLIPPING) | 231 | #if !defined(AUDIOHW_HAVE_CLIPPING) |
232 | current_bass = sound_value_to_cb(SOUND_BASS, value); | ||
318 | set_prescaled_volume(); | 233 | set_prescaled_volume(); |
319 | #endif | 234 | #endif |
320 | } | 235 | } |
@@ -323,24 +238,13 @@ void sound_set_bass(int value) | |||
323 | #ifdef AUDIOHW_HAVE_TREBLE | 238 | #ifdef AUDIOHW_HAVE_TREBLE |
324 | void sound_set_treble(int value) | 239 | void sound_set_treble(int value) |
325 | { | 240 | { |
326 | if(!audio_is_initialized) | 241 | if (!audio_is_initialized) |
327 | return; | 242 | return; |
328 | 243 | ||
329 | #if !defined(AUDIOHW_HAVE_CLIPPING) | ||
330 | #if defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_CS42L55) | ||
331 | current_treble = value; | ||
332 | #else | ||
333 | current_treble = value * 10; | ||
334 | #endif | ||
335 | #endif | ||
336 | |||
337 | #if defined(HAVE_SW_TONE_CONTROLS) | ||
338 | dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble); | ||
339 | #else | ||
340 | audiohw_set_treble(value); | 244 | audiohw_set_treble(value); |
341 | #endif | ||
342 | 245 | ||
343 | #if !defined(AUDIOHW_HAVE_CLIPPING) | 246 | #if !defined(AUDIOHW_HAVE_CLIPPING) |
247 | current_treble = sound_value_to_cb(SOUND_TREBLE, value); | ||
344 | set_prescaled_volume(); | 248 | set_prescaled_volume(); |
345 | #endif | 249 | #endif |
346 | } | 250 | } |
@@ -349,7 +253,7 @@ void sound_set_treble(int value) | |||
349 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) | 253 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) |
350 | void sound_set_bass_cutoff(int value) | 254 | void sound_set_bass_cutoff(int value) |
351 | { | 255 | { |
352 | if(!audio_is_initialized) | 256 | if (!audio_is_initialized) |
353 | return; | 257 | return; |
354 | 258 | ||
355 | audiohw_set_bass_cutoff(value); | 259 | audiohw_set_bass_cutoff(value); |
@@ -359,7 +263,7 @@ void sound_set_bass_cutoff(int value) | |||
359 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) | 263 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) |
360 | void sound_set_treble_cutoff(int value) | 264 | void sound_set_treble_cutoff(int value) |
361 | { | 265 | { |
362 | if(!audio_is_initialized) | 266 | if (!audio_is_initialized) |
363 | return; | 267 | return; |
364 | 268 | ||
365 | audiohw_set_treble_cutoff(value); | 269 | audiohw_set_treble_cutoff(value); |
@@ -368,32 +272,24 @@ void sound_set_treble_cutoff(int value) | |||
368 | 272 | ||
369 | void sound_set_channels(int value) | 273 | void sound_set_channels(int value) |
370 | { | 274 | { |
371 | if(!audio_is_initialized) | 275 | if (!audio_is_initialized) |
372 | return; | 276 | return; |
373 | 277 | ||
374 | #if CONFIG_CODEC == SWCODEC | ||
375 | dsp_callback(DSP_CALLBACK_SET_CHANNEL_CONFIG, value); | ||
376 | #else | ||
377 | audiohw_set_channel(value); | 278 | audiohw_set_channel(value); |
378 | #endif | ||
379 | } | 279 | } |
380 | 280 | ||
381 | void sound_set_stereo_width(int value) | 281 | void sound_set_stereo_width(int value) |
382 | { | 282 | { |
383 | if(!audio_is_initialized) | 283 | if (!audio_is_initialized) |
384 | return; | 284 | return; |
385 | 285 | ||
386 | #if CONFIG_CODEC == SWCODEC | ||
387 | dsp_callback(DSP_CALLBACK_SET_STEREO_WIDTH, value); | ||
388 | #else | ||
389 | audiohw_set_stereo_width(value); | 286 | audiohw_set_stereo_width(value); |
390 | #endif | ||
391 | } | 287 | } |
392 | 288 | ||
393 | #if defined(AUDIOHW_HAVE_DEPTH_3D) | 289 | #if defined(AUDIOHW_HAVE_DEPTH_3D) |
394 | void sound_set_depth_3d(int value) | 290 | void sound_set_depth_3d(int value) |
395 | { | 291 | { |
396 | if(!audio_is_initialized) | 292 | if (!audio_is_initialized) |
397 | return; | 293 | return; |
398 | 294 | ||
399 | audiohw_set_depth_3d(value); | 295 | audiohw_set_depth_3d(value); |
@@ -470,13 +366,11 @@ int sound_enum_hw_eq_band_setting(unsigned int band, | |||
470 | 366 | ||
471 | static void sound_set_hw_eq_band_gain(unsigned int band, int value) | 367 | static void sound_set_hw_eq_band_gain(unsigned int band, int value) |
472 | { | 368 | { |
473 | int setting; | 369 | if (!audio_is_initialized) |
474 | |||
475 | if(!audio_is_initialized) | ||
476 | return; | 370 | return; |
477 | 371 | ||
478 | setting = sound_enum_hw_eq_band_setting(band, AUDIOHW_EQ_GAIN); | 372 | int setting = sound_enum_hw_eq_band_setting(band, AUDIOHW_EQ_GAIN); |
479 | current_eq_band_gain[band] = sound_val2phys(setting + 0x10000, value); | 373 | current_eq_band_gain[band] = sound_value_to_cb(setting, value); |
480 | 374 | ||
481 | audiohw_set_eq_band_gain(band, value); | 375 | audiohw_set_eq_band_gain(band, value); |
482 | set_prescaled_volume(); | 376 | set_prescaled_volume(); |
@@ -518,7 +412,7 @@ void sound_set_hw_eq_band5_gain(int value) | |||
518 | #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY) | 412 | #if defined(AUDIOHW_HAVE_EQ_BAND1_FREQUENCY) |
519 | void sound_set_hw_eq_band1_frequency(int value) | 413 | void sound_set_hw_eq_band1_frequency(int value) |
520 | { | 414 | { |
521 | if(!audio_is_initialized) | 415 | if (!audio_is_initialized) |
522 | return; | 416 | return; |
523 | 417 | ||
524 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value); | 418 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND1, value); |
@@ -528,7 +422,7 @@ void sound_set_hw_eq_band1_frequency(int value) | |||
528 | #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY) | 422 | #if defined(AUDIOHW_HAVE_EQ_BAND2_FREQUENCY) |
529 | void sound_set_hw_eq_band2_frequency(int value) | 423 | void sound_set_hw_eq_band2_frequency(int value) |
530 | { | 424 | { |
531 | if(!audio_is_initialized) | 425 | if (!audio_is_initialized) |
532 | return; | 426 | return; |
533 | 427 | ||
534 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value); | 428 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND2, value); |
@@ -538,7 +432,7 @@ void sound_set_hw_eq_band2_frequency(int value) | |||
538 | #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY) | 432 | #if defined(AUDIOHW_HAVE_EQ_BAND3_FREQUENCY) |
539 | void sound_set_hw_eq_band3_frequency(int value) | 433 | void sound_set_hw_eq_band3_frequency(int value) |
540 | { | 434 | { |
541 | if(!audio_is_initialized) | 435 | if (!audio_is_initialized) |
542 | return; | 436 | return; |
543 | 437 | ||
544 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value); | 438 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND3, value); |
@@ -548,7 +442,7 @@ void sound_set_hw_eq_band3_frequency(int value) | |||
548 | #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY) | 442 | #if defined(AUDIOHW_HAVE_EQ_BAND4_FREQUENCY) |
549 | void sound_set_hw_eq_band4_frequency(int value) | 443 | void sound_set_hw_eq_band4_frequency(int value) |
550 | { | 444 | { |
551 | if(!audio_is_initialized) | 445 | if (!audio_is_initialized) |
552 | return; | 446 | return; |
553 | 447 | ||
554 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value); | 448 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND4, value); |
@@ -558,7 +452,7 @@ void sound_set_hw_eq_band4_frequency(int value) | |||
558 | #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY) | 452 | #if defined(AUDIOHW_HAVE_EQ_BAND5_FREQUENCY) |
559 | void sound_set_hw_eq_band5_frequency(int value) | 453 | void sound_set_hw_eq_band5_frequency(int value) |
560 | { | 454 | { |
561 | if(!audio_is_initialized) | 455 | if (!audio_is_initialized) |
562 | return; | 456 | return; |
563 | 457 | ||
564 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value); | 458 | audiohw_set_eq_band_frequency(AUDIOHW_EQ_BAND5, value); |
@@ -568,7 +462,7 @@ void sound_set_hw_eq_band5_frequency(int value) | |||
568 | #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH) | 462 | #if defined(AUDIOHW_HAVE_EQ_BAND2_WIDTH) |
569 | void sound_set_hw_eq_band2_width(int value) | 463 | void sound_set_hw_eq_band2_width(int value) |
570 | { | 464 | { |
571 | if(!audio_is_initialized) | 465 | if (!audio_is_initialized) |
572 | return; | 466 | return; |
573 | 467 | ||
574 | audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value); | 468 | audiohw_set_eq_band_width(AUDIOHW_EQ_BAND2, value); |
@@ -578,7 +472,7 @@ void sound_set_hw_eq_band2_width(int value) | |||
578 | #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH) | 472 | #if defined(AUDIOHW_HAVE_EQ_BAND3_WIDTH) |
579 | void sound_set_hw_eq_band3_width(int value) | 473 | void sound_set_hw_eq_band3_width(int value) |
580 | { | 474 | { |
581 | if(!audio_is_initialized) | 475 | if (!audio_is_initialized) |
582 | return; | 476 | return; |
583 | 477 | ||
584 | audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value); | 478 | audiohw_set_eq_band_width(AUDIOHW_EQ_BAND3, value); |
@@ -588,7 +482,7 @@ void sound_set_hw_eq_band3_width(int value) | |||
588 | #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH) | 482 | #if defined(AUDIOHW_HAVE_EQ_BAND4_WIDTH) |
589 | void sound_set_hw_eq_band4_width(int value) | 483 | void sound_set_hw_eq_band4_width(int value) |
590 | { | 484 | { |
591 | if(!audio_is_initialized) | 485 | if (!audio_is_initialized) |
592 | return; | 486 | return; |
593 | 487 | ||
594 | audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value); | 488 | audiohw_set_eq_band_width(AUDIOHW_EQ_BAND4, value); |
@@ -596,10 +490,10 @@ void sound_set_hw_eq_band4_width(int value) | |||
596 | #endif | 490 | #endif |
597 | #endif /* AUDIOHW_HAVE_EQ */ | 491 | #endif /* AUDIOHW_HAVE_EQ */ |
598 | 492 | ||
599 | #if ((CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)) | 493 | #if CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F |
600 | void sound_set_loudness(int value) | 494 | void sound_set_loudness(int value) |
601 | { | 495 | { |
602 | if(!audio_is_initialized) | 496 | if (!audio_is_initialized) |
603 | return; | 497 | return; |
604 | 498 | ||
605 | audiohw_set_loudness(value); | 499 | audiohw_set_loudness(value); |
@@ -607,7 +501,7 @@ void sound_set_loudness(int value) | |||
607 | 501 | ||
608 | void sound_set_avc(int value) | 502 | void sound_set_avc(int value) |
609 | { | 503 | { |
610 | if(!audio_is_initialized) | 504 | if (!audio_is_initialized) |
611 | return; | 505 | return; |
612 | 506 | ||
613 | audiohw_set_avc(value); | 507 | audiohw_set_avc(value); |
@@ -615,7 +509,7 @@ void sound_set_avc(int value) | |||
615 | 509 | ||
616 | void sound_set_mdb_strength(int value) | 510 | void sound_set_mdb_strength(int value) |
617 | { | 511 | { |
618 | if(!audio_is_initialized) | 512 | if (!audio_is_initialized) |
619 | return; | 513 | return; |
620 | 514 | ||
621 | audiohw_set_mdb_strength(value); | 515 | audiohw_set_mdb_strength(value); |
@@ -623,7 +517,7 @@ void sound_set_mdb_strength(int value) | |||
623 | 517 | ||
624 | void sound_set_mdb_harmonics(int value) | 518 | void sound_set_mdb_harmonics(int value) |
625 | { | 519 | { |
626 | if(!audio_is_initialized) | 520 | if (!audio_is_initialized) |
627 | return; | 521 | return; |
628 | 522 | ||
629 | audiohw_set_mdb_harmonics(value); | 523 | audiohw_set_mdb_harmonics(value); |
@@ -631,7 +525,7 @@ void sound_set_mdb_harmonics(int value) | |||
631 | 525 | ||
632 | void sound_set_mdb_center(int value) | 526 | void sound_set_mdb_center(int value) |
633 | { | 527 | { |
634 | if(!audio_is_initialized) | 528 | if (!audio_is_initialized) |
635 | return; | 529 | return; |
636 | 530 | ||
637 | audiohw_set_mdb_center(value); | 531 | audiohw_set_mdb_center(value); |
@@ -639,7 +533,7 @@ void sound_set_mdb_center(int value) | |||
639 | 533 | ||
640 | void sound_set_mdb_shape(int value) | 534 | void sound_set_mdb_shape(int value) |
641 | { | 535 | { |
642 | if(!audio_is_initialized) | 536 | if (!audio_is_initialized) |
643 | return; | 537 | return; |
644 | 538 | ||
645 | audiohw_set_mdb_shape(value); | 539 | audiohw_set_mdb_shape(value); |
@@ -647,7 +541,7 @@ void sound_set_mdb_shape(int value) | |||
647 | 541 | ||
648 | void sound_set_mdb_enable(int value) | 542 | void sound_set_mdb_enable(int value) |
649 | { | 543 | { |
650 | if(!audio_is_initialized) | 544 | if (!audio_is_initialized) |
651 | return; | 545 | return; |
652 | 546 | ||
653 | audiohw_set_mdb_enable(value); | 547 | audiohw_set_mdb_enable(value); |
@@ -655,158 +549,27 @@ void sound_set_mdb_enable(int value) | |||
655 | 549 | ||
656 | void sound_set_superbass(int value) | 550 | void sound_set_superbass(int value) |
657 | { | 551 | { |
658 | if(!audio_is_initialized) | 552 | if (!audio_is_initialized) |
659 | return; | 553 | return; |
660 | 554 | ||
661 | audiohw_set_superbass(value); | 555 | audiohw_set_superbass(value); |
662 | } | 556 | } |
663 | #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ | 557 | #endif /* CONFIG_CODEC == MAS3587F || CONFIG_CODEC == MAS3539F */ |
664 | |||
665 | void sound_set(int setting, int value) | ||
666 | { | ||
667 | sound_set_type* sound_set_val = sound_get_fn(setting); | ||
668 | if (sound_set_val) | ||
669 | sound_set_val(value); | ||
670 | } | ||
671 | |||
672 | #if (!defined(HAVE_AS3514) && !defined(HAVE_WM8975) \ | ||
673 | && !defined(HAVE_WM8758) && !defined(HAVE_TSC2100) \ | ||
674 | && !defined (HAVE_WM8711) && !defined (HAVE_WM8721) \ | ||
675 | && !defined (HAVE_WM8731) && !defined (HAVE_WM8978) \ | ||
676 | && !defined (HAVE_WM8750) && !defined (HAVE_WM8751) \ | ||
677 | && !defined(HAVE_AK4537)) || defined(SIMULATOR) | ||
678 | int sound_val2phys(int setting, int value) | ||
679 | { | ||
680 | #if CONFIG_CODEC == MAS3587F | ||
681 | int result = 0; | ||
682 | |||
683 | switch(setting) | ||
684 | { | ||
685 | case SOUND_LEFT_GAIN: | ||
686 | case SOUND_RIGHT_GAIN: | ||
687 | result = (value - 2) * 15; | ||
688 | break; | ||
689 | |||
690 | case SOUND_MIC_GAIN: | ||
691 | result = value * 15 + 210; | ||
692 | break; | ||
693 | |||
694 | default: | ||
695 | result = value; | ||
696 | break; | ||
697 | } | ||
698 | return result; | ||
699 | #elif defined(HAVE_UDA1380) | ||
700 | int result = 0; | ||
701 | |||
702 | switch(setting) | ||
703 | { | ||
704 | #ifdef HAVE_RECORDING | ||
705 | case SOUND_LEFT_GAIN: | ||
706 | case SOUND_RIGHT_GAIN: | ||
707 | case SOUND_MIC_GAIN: | ||
708 | result = value * 5; /* (1/2) * 10 */ | ||
709 | break; | ||
710 | #endif | ||
711 | default: | ||
712 | result = value; | ||
713 | break; | ||
714 | } | ||
715 | return result; | ||
716 | #elif defined(HAVE_TLV320) || defined(HAVE_WM8711) \ | ||
717 | || defined(HAVE_WM8721) || defined(HAVE_WM8731) | ||
718 | int result = 0; | ||
719 | |||
720 | switch(setting) | ||
721 | { | ||
722 | #ifdef HAVE_RECORDING | ||
723 | case SOUND_LEFT_GAIN: | ||
724 | case SOUND_RIGHT_GAIN: | ||
725 | result = (value - 23) * 15; /* (x - 23)/1.5 *10 */ | ||
726 | break; | ||
727 | |||
728 | case SOUND_MIC_GAIN: | ||
729 | result = value * 200; /* 0 or 20 dB */ | ||
730 | break; | ||
731 | #endif | ||
732 | default: | ||
733 | result = value; | ||
734 | break; | ||
735 | } | ||
736 | return result; | ||
737 | #elif defined(HAVE_AS3514) | ||
738 | /* This is here for the sim only and the audio driver has its own */ | ||
739 | int result; | ||
740 | |||
741 | switch(setting) | ||
742 | { | ||
743 | #ifdef HAVE_RECORDING | ||
744 | case SOUND_LEFT_GAIN: | ||
745 | case SOUND_RIGHT_GAIN: | ||
746 | case SOUND_MIC_GAIN: | ||
747 | result = (value - 23) * 15; | ||
748 | break; | ||
749 | #endif | ||
750 | default: | ||
751 | result = value; | ||
752 | break; | ||
753 | } | ||
754 | |||
755 | return result; | ||
756 | #elif defined(HAVE_WM8978) || defined(HAVE_WM8750) || defined(HAVE_WM8751) | ||
757 | int result; | ||
758 | |||
759 | switch (setting) | ||
760 | { | ||
761 | #ifdef HAVE_RECORDING | ||
762 | case SOUND_LEFT_GAIN: | ||
763 | case SOUND_RIGHT_GAIN: | ||
764 | case SOUND_MIC_GAIN: | ||
765 | result = value * 5; | ||
766 | break; | ||
767 | #endif | ||
768 | #ifdef AUDIOHW_HAVE_DEPTH_3D | ||
769 | case SOUND_DEPTH_3D: | ||
770 | result = (100 * value + 8) / 15; | ||
771 | break; | ||
772 | #endif | ||
773 | default: | ||
774 | result = value; | ||
775 | } | ||
776 | |||
777 | return result; | ||
778 | #else | ||
779 | (void)setting; | ||
780 | return value; | ||
781 | #endif | ||
782 | } | ||
783 | #endif /* CONFIG_CODECs || PLATFORM_HOSTED */ | ||
784 | |||
785 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) | ||
786 | /* This function works by telling the decoder that we have another | ||
787 | crystal frequency than we actually have. It will adjust its internal | ||
788 | parameters and the result is that the audio is played at another pitch. | ||
789 | */ | ||
790 | |||
791 | static int last_pitch = PITCH_SPEED_100; | ||
792 | 558 | ||
559 | #ifdef HAVE_PITCHCONTROL | ||
793 | void sound_set_pitch(int32_t pitch) | 560 | void sound_set_pitch(int32_t pitch) |
794 | { | 561 | { |
795 | unsigned long val; | 562 | if (!audio_is_initialized) |
796 | 563 | return; | |
797 | if (pitch != last_pitch) | ||
798 | { | ||
799 | /* Calculate the new (bogus) frequency */ | ||
800 | val = 18432 * PITCH_SPEED_100 / pitch; | ||
801 | |||
802 | audiohw_set_pitch(val); | ||
803 | 564 | ||
804 | last_pitch = pitch; | 565 | audiohw_set_pitch(pitch); |
805 | } | ||
806 | } | 566 | } |
807 | 567 | ||
808 | int32_t sound_get_pitch(void) | 568 | int32_t sound_get_pitch(void) |
809 | { | 569 | { |
810 | return last_pitch; | 570 | if (!audio_is_initialized) |
571 | return PITCH_SPEED_100; | ||
572 | |||
573 | return audiohw_get_pitch(); | ||
811 | } | 574 | } |
812 | #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ | 575 | #endif /* HAVE_PITCHCONTROL */ |