Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2005 by Linus Nielsen Feltzing |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 11 | * Copyright (C) 2007 by Christian Gmeiner |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 12 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 17 | * |
| 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | * KIND, either express or implied. |
| 20 | * |
| 21 | ****************************************************************************/ |
| 22 | #include <stdbool.h> |
Linus Nielsen Feltzing | d6f297e | 2005-06-05 23:46:09 +0000 | [diff] [blame] | 23 | #include <stdio.h> |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 24 | #include "config.h" |
| 25 | #include "sound.h" |
Dave Chapman | 5ffa8c5 | 2006-01-30 21:12:31 +0000 | [diff] [blame] | 26 | #include "logf.h" |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 27 | #ifndef SIMULATOR |
| 28 | #include "i2c.h" |
| 29 | #include "mas.h" |
Marcoen Hirschberg | 1b967f4 | 2006-12-06 13:34:15 +0000 | [diff] [blame] | 30 | #if CONFIG_CPU == PNX0101 |
Tomasz Malesinski | 4e5f4ee | 2006-08-12 21:03:23 +0000 | [diff] [blame] | 31 | #include "pnx0101.h" |
Thom Johansen | 38c9d75 | 2005-06-15 19:56:44 +0000 | [diff] [blame] | 32 | #endif |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 33 | #include "dac.h" |
| 34 | #include "system.h" |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 35 | #if CONFIG_CODEC == SWCODEC |
Michael Sevakis | 6077e5b | 2007-10-06 22:27:27 +0000 | [diff] [blame] | 36 | #include "pcm.h" |
Linus Nielsen Feltzing | d6f297e | 2005-06-05 23:46:09 +0000 | [diff] [blame] | 37 | #endif |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
Christian Gmeiner | a6100fb | 2008-04-28 22:15:52 +0000 | [diff] [blame] | 40 | /* TODO |
| 41 | * find a nice way to handle 1.5db steps -> see wm8751 ifdef in sound_set_bass/treble |
| 42 | */ |
| 43 | |
Christian Gmeiner | 365c3b9 | 2008-04-22 09:42:02 +0000 | [diff] [blame] | 44 | #if !defined(VOLUME_MIN) && !defined(VOLUME_MAX) |
Dave Chapman | 5e97323 | 2008-05-24 08:03:15 +0000 | [diff] [blame] | 45 | #warning define for VOLUME_MIN and VOLUME_MAX is missing |
| 46 | #define VOLUME_MIN -700 |
| 47 | #define VOLUME_MAX 0 |
Dan Everton | a537114 | 2007-10-13 23:18:30 +0000 | [diff] [blame] | 48 | #endif |
| 49 | |
| 50 | /* volume/balance/treble/bass interdependency main part */ |
| 51 | #define VOLUME_RANGE (VOLUME_MAX - VOLUME_MIN) |
| 52 | |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 53 | #ifndef SIMULATOR |
| 54 | extern bool audio_is_initialized; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 55 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 56 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 57 | extern unsigned long shadow_io_control_main; |
| 58 | extern unsigned shadow_codec_reg0; |
| 59 | #endif |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 60 | #endif /* SIMULATOR */ |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 61 | |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 62 | #ifdef SIMULATOR |
| 63 | /* dummy for sim */ |
| 64 | const struct sound_settings_info audiohw_settings[] = { |
Dan Everton | 003a4a1 | 2007-10-13 23:01:10 +0000 | [diff] [blame] | 65 | [SOUND_VOLUME] = {"dB", 0, 1, VOLUME_MIN / 10, VOLUME_MAX / 10, -25}, |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 66 | [SOUND_BASS] = {"dB", 0, 1, -24, 24, 0}, |
| 67 | [SOUND_TREBLE] = {"dB", 0, 1, -24, 24, 0}, |
Marcoen Hirschberg | df31f5f | 2007-12-10 11:14:28 +0000 | [diff] [blame] | 68 | [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0}, |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 69 | [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0}, |
Thom Johansen | 8f72192 | 2007-10-09 21:29:20 +0000 | [diff] [blame] | 70 | [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100}, |
Christian Gmeiner | 48f3eed | 2008-05-16 19:53:01 +0000 | [diff] [blame] | 71 | #if defined(HAVE_RECORDING) |
Jonathan Gordon | 43c299e | 2007-05-27 04:00:56 +0000 | [diff] [blame] | 72 | [SOUND_LEFT_GAIN] = {"dB", 1, 1,-128, 96, 0}, |
| 73 | [SOUND_RIGHT_GAIN] = {"dB", 1, 1,-128, 96, 0}, |
| 74 | [SOUND_MIC_GAIN] = {"dB", 1, 1,-128, 108, 16}, |
| 75 | #endif |
Christian Gmeiner | 59357d4 | 2008-05-16 19:28:45 +0000 | [diff] [blame] | 76 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 77 | [SOUND_BASS_CUTOFF] = {"", 0, 1, 1, 4, 1}, |
Christian Gmeiner | 59357d4 | 2008-05-16 19:28:45 +0000 | [diff] [blame] | 78 | #endif |
| 79 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 80 | [SOUND_TREBLE_CUTOFF] = {"", 0, 1, 1, 4, 1}, |
| 81 | #endif |
Dan Everton | f666a7e | 2007-11-27 10:52:03 +0000 | [diff] [blame] | 82 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 83 | [SOUND_LOUDNESS] = {"dB", 0, 1, 0, 17, 0}, |
| 84 | [SOUND_AVC] = {"", 0, 1, -1, 4, 0}, |
| 85 | [SOUND_MDB_STRENGTH] = {"dB", 0, 1, 0, 127, 48}, |
| 86 | [SOUND_MDB_HARMONICS] = {"%", 0, 1, 0, 100, 50}, |
| 87 | [SOUND_MDB_CENTER] = {"Hz", 0, 10, 20, 300, 60}, |
| 88 | [SOUND_MDB_SHAPE] = {"Hz", 0, 10, 50, 300, 90}, |
| 89 | [SOUND_MDB_ENABLE] = {"", 0, 1, 0, 1, 0}, |
| 90 | [SOUND_SUPERBASS] = {"", 0, 1, 0, 1, 0}, |
| 91 | #endif |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 92 | }; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 93 | #endif |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 94 | |
| 95 | const char *sound_unit(int setting) |
| 96 | { |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 97 | return audiohw_settings[setting].unit; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | int sound_numdecimals(int setting) |
| 101 | { |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 102 | return audiohw_settings[setting].numdecimals; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | int sound_steps(int setting) |
| 106 | { |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 107 | return audiohw_settings[setting].steps; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | int sound_min(int setting) |
| 111 | { |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 112 | return audiohw_settings[setting].minval; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | int sound_max(int setting) |
| 116 | { |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 117 | return audiohw_settings[setting].maxval; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | int sound_default(int setting) |
| 121 | { |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 122 | return audiohw_settings[setting].defaultval; |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | sound_set_type* sound_get_fn(int setting) |
| 126 | { |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 127 | sound_set_type* result = NULL; |
| 128 | |
| 129 | switch (setting) { |
| 130 | case SOUND_VOLUME: |
| 131 | result = sound_set_volume; |
| 132 | break; |
| 133 | |
| 134 | case SOUND_BASS: |
| 135 | result = sound_set_bass; |
| 136 | break; |
| 137 | |
| 138 | case SOUND_TREBLE: |
| 139 | result = sound_set_treble; |
| 140 | break; |
| 141 | |
| 142 | case SOUND_BALANCE: |
| 143 | result = sound_set_balance; |
| 144 | break; |
| 145 | |
| 146 | case SOUND_CHANNELS: |
| 147 | result = sound_set_channels; |
| 148 | break; |
| 149 | |
| 150 | case SOUND_STEREO_WIDTH: |
| 151 | result = sound_set_stereo_width; |
| 152 | break; |
| 153 | |
Christian Gmeiner | 59357d4 | 2008-05-16 19:28:45 +0000 | [diff] [blame] | 154 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 155 | case SOUND_BASS_CUTOFF: |
| 156 | result = sound_set_bass_cutoff; |
| 157 | break; |
Christian Gmeiner | 59357d4 | 2008-05-16 19:28:45 +0000 | [diff] [blame] | 158 | #endif |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 159 | |
Christian Gmeiner | 59357d4 | 2008-05-16 19:28:45 +0000 | [diff] [blame] | 160 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 161 | case SOUND_TREBLE_CUTOFF: |
| 162 | result = sound_set_treble_cutoff; |
| 163 | break; |
| 164 | #endif |
| 165 | |
Christian Gmeiner | cdbf33a | 2007-05-22 15:56:05 +0000 | [diff] [blame] | 166 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 167 | case SOUND_LOUDNESS: |
| 168 | result = sound_set_loudness; |
| 169 | break; |
| 170 | |
| 171 | case SOUND_AVC: |
| 172 | result = sound_set_avc; |
| 173 | break; |
| 174 | |
| 175 | case SOUND_MDB_STRENGTH: |
| 176 | result = sound_set_mdb_strength; |
| 177 | break; |
| 178 | |
| 179 | case SOUND_MDB_HARMONICS: |
| 180 | result = sound_set_mdb_harmonics; |
| 181 | break; |
| 182 | |
| 183 | case SOUND_MDB_CENTER: |
| 184 | result = sound_set_mdb_center; |
| 185 | break; |
| 186 | |
| 187 | case SOUND_MDB_SHAPE: |
| 188 | result = sound_set_mdb_shape; |
| 189 | break; |
| 190 | |
| 191 | case SOUND_MDB_ENABLE: |
| 192 | result = sound_set_mdb_enable; |
| 193 | break; |
| 194 | |
| 195 | case SOUND_SUPERBASS: |
| 196 | result = sound_set_superbass; |
| 197 | break; |
| 198 | #endif |
| 199 | } |
| 200 | |
| 201 | return result; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Thom Johansen | 99b2742 | 2007-03-07 19:11:16 +0000 | [diff] [blame] | 204 | #if CONFIG_CODEC == SWCODEC |
Thom Johansen | a7fabf0 | 2007-02-26 00:41:26 +0000 | [diff] [blame] | 205 | /* Copied from dsp.h, nasty nasty, but we don't want to include dsp.h */ |
| 206 | enum { |
| 207 | DSP_CALLBACK_SET_PRESCALE = 0, |
| 208 | DSP_CALLBACK_SET_BASS, |
Thom Johansen | 99b2742 | 2007-03-07 19:11:16 +0000 | [diff] [blame] | 209 | DSP_CALLBACK_SET_TREBLE, |
| 210 | DSP_CALLBACK_SET_CHANNEL_CONFIG, |
| 211 | DSP_CALLBACK_SET_STEREO_WIDTH |
Thom Johansen | a7fabf0 | 2007-02-26 00:41:26 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | static int (*dsp_callback)(int, intptr_t) = NULL; |
| 215 | |
| 216 | void sound_set_dsp_callback(int (*func)(int, intptr_t)) |
| 217 | { |
| 218 | dsp_callback = func; |
| 219 | } |
| 220 | #endif |
| 221 | |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 222 | #ifndef SIMULATOR |
Christian Gmeiner | 7197d9d | 2007-11-15 23:32:56 +0000 | [diff] [blame] | 223 | #if CONFIG_CODEC == MAS3507D |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 224 | /* convert tenth of dB volume (-780..+180) to dac3550 register value */ |
Jens Arnold | 8636e69 | 2007-04-11 23:51:00 +0000 | [diff] [blame] | 225 | static int tenthdb2reg(int db) |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 226 | { |
| 227 | if (db < -540) /* 3 dB steps */ |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 228 | return (db + 780) / 30; |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 229 | else /* 1.5 dB steps */ |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 230 | return (db + 660) / 15; |
| 231 | } |
Jens Arnold | 12a0e22 | 2005-06-19 23:33:23 +0000 | [diff] [blame] | 232 | #endif |
| 233 | |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 234 | |
Christian Gmeiner | 785e776 | 2008-05-13 06:19:16 +0000 | [diff] [blame] | 235 | #if !defined(AUDIOHW_HAVE_CLIPPING) |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 236 | /* |
| 237 | * The prescaler compensates for any kind of boosts, to prevent clipping. |
| 238 | * |
| 239 | * It's basically just a measure to make sure that audio does not clip during |
| 240 | * tone controls processing, like if i want to boost bass 12 dB, i can decrease |
| 241 | * the audio amplitude by -12 dB before processing, then increase master gain |
| 242 | * by 12 dB after processing. |
| 243 | */ |
Jens Arnold | 12a0e22 | 2005-06-19 23:33:23 +0000 | [diff] [blame] | 244 | |
| 245 | /* all values in tenth of dB MAS3507D UDA1380 */ |
| 246 | int current_volume = 0; /* -780..+180 -840.. 0 */ |
| 247 | int current_balance = 0; /* -960..+960 -840..+840 */ |
| 248 | int current_treble = 0; /* -150..+150 0.. +60 */ |
| 249 | int current_bass = 0; /* -150..+150 0..+240 */ |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 250 | |
Jens Arnold | 4c7da88 | 2005-06-18 01:25:47 +0000 | [diff] [blame] | 251 | static void set_prescaled_volume(void) |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 252 | { |
Thom Johansen | 2d7bb99c | 2007-03-07 15:00:29 +0000 | [diff] [blame] | 253 | int prescale = 0; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 254 | int l, r; |
| 255 | |
Thom Johansen | 2d7bb99c | 2007-03-07 15:00:29 +0000 | [diff] [blame] | 256 | /* The WM codecs listed don't have suitable prescaler functionality, so we let |
| 257 | * the prescaler stay at 0 for these unless SW tone controls are in use */ |
| 258 | #if defined(HAVE_SW_TONE_CONTROLS) || !(defined(HAVE_WM8975) \ |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 259 | || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751) \ |
Jonathan Gordon | 6b9b508 | 2008-04-27 14:07:57 +0000 | [diff] [blame] | 260 | || defined(HAVE_WM8758) || defined(HAVE_WM8985)) || defined(HAVE_TSC2100) |
Thom Johansen | 2d7bb99c | 2007-03-07 15:00:29 +0000 | [diff] [blame] | 261 | |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 262 | prescale = MAX(current_bass, current_treble); |
| 263 | if (prescale < 0) |
| 264 | prescale = 0; /* no need to prescale if we don't boost |
| 265 | bass or treble */ |
| 266 | |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 267 | /* Gain up the analog volume to compensate the prescale gain reduction, |
| 268 | * but if this would push the volume over the top, reduce prescaling |
| 269 | * instead (might cause clipping). */ |
Jens Arnold | 12a0e22 | 2005-06-19 23:33:23 +0000 | [diff] [blame] | 270 | if (current_volume + prescale > VOLUME_MAX) |
| 271 | prescale = VOLUME_MAX - current_volume; |
Thom Johansen | 2d7bb99c | 2007-03-07 15:00:29 +0000 | [diff] [blame] | 272 | #endif |
| 273 | |
Christian Gmeiner | 05e8488 | 2008-05-14 21:35:19 +0000 | [diff] [blame] | 274 | #if defined(AUDIOHW_HAVE_PRESCALER) |
| 275 | audiohw_set_prescaler(prescale); |
| 276 | #else |
Thom Johansen | a7fabf0 | 2007-02-26 00:41:26 +0000 | [diff] [blame] | 277 | dsp_callback(DSP_CALLBACK_SET_PRESCALE, prescale); |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 278 | #endif |
| 279 | |
| 280 | if (current_volume == VOLUME_MIN) |
| 281 | prescale = 0; /* Make sure the chip gets muted at VOLUME_MIN */ |
| 282 | |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 283 | l = r = current_volume + prescale; |
| 284 | |
| 285 | if (current_balance > 0) |
| 286 | { |
| 287 | l -= current_balance; |
Jens Arnold | 12a0e22 | 2005-06-19 23:33:23 +0000 | [diff] [blame] | 288 | if (l < VOLUME_MIN) |
| 289 | l = VOLUME_MIN; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 290 | } |
| 291 | if (current_balance < 0) |
| 292 | { |
| 293 | r += current_balance; |
Jens Arnold | 12a0e22 | 2005-06-19 23:33:23 +0000 | [diff] [blame] | 294 | if (r < VOLUME_MIN) |
| 295 | r = VOLUME_MIN; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 298 | #if CONFIG_CODEC == MAS3507D |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 299 | dac_volume(tenthdb2reg(l), tenthdb2reg(r), false); |
Thom Johansen | a7fabf0 | 2007-02-26 00:41:26 +0000 | [diff] [blame] | 300 | #elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \ |
Daniel Ankers | dfad406 | 2007-03-11 17:38:08 +0000 | [diff] [blame] | 301 | || defined(HAVE_WM8731) || defined(HAVE_WM8721) || defined(HAVE_WM8751) \ |
Jonathan Gordon | 6b9b508 | 2008-04-27 14:07:57 +0000 | [diff] [blame] | 302 | || defined(HAVE_AS3514) || defined(HAVE_TSC2100) |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 303 | audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r)); |
Mark Arigo | 8a7e626 | 2008-02-06 05:15:06 +0000 | [diff] [blame] | 304 | #if defined(HAVE_WM8975) || defined(HAVE_WM8758) \ |
Jonathan Gordon | 6b9b508 | 2008-04-27 14:07:57 +0000 | [diff] [blame] | 305 | || (defined(HAVE_WM8751) && !defined(MROBE_100)) \ |
Rob Purchase | d6159ea | 2008-06-22 18:48:22 +0000 | [diff] [blame] | 306 | || defined(HAVE_TSC2100) || defined(HAVE_WM8985) |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 307 | audiohw_set_lineout_vol(tenthdb2master(0), tenthdb2master(0)); |
Thom Johansen | 473fc2b | 2006-03-22 13:04:49 +0000 | [diff] [blame] | 308 | #endif |
| 309 | |
Rob Purchase | d6159ea | 2008-06-22 18:48:22 +0000 | [diff] [blame] | 310 | #elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985) |
Marcoen Hirschberg | 77d039b | 2006-12-06 10:24:59 +0000 | [diff] [blame] | 311 | audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r)); |
Anton Oleynikov | 2654d91 | 2005-12-04 14:33:10 +0000 | [diff] [blame] | 312 | #endif |
Anton Oleynikov | 2654d91 | 2005-12-04 14:33:10 +0000 | [diff] [blame] | 313 | } |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 314 | #endif /* (CONFIG_CODEC == MAS3507D) || defined HAVE_UDA1380 */ |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 315 | #endif /* !SIMULATOR */ |
| 316 | |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 317 | |
| 318 | #ifndef SIMULATOR |
Thom Johansen | b0960ae | 2006-03-21 23:20:17 +0000 | [diff] [blame] | 319 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 320 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 321 | unsigned long mdb_shape_shadow = 0; |
| 322 | unsigned long loudness_shadow = 0; |
| 323 | #endif |
| 324 | |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 325 | void sound_set_volume(int value) |
| 326 | { |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 327 | if(!audio_is_initialized) |
| 328 | return; |
Christian Gmeiner | 785e776 | 2008-05-13 06:19:16 +0000 | [diff] [blame] | 329 | |
| 330 | #if defined(AUDIOHW_HAVE_CLIPPING) |
| 331 | audiohw_set_volume(value); |
Tomasz Malesinski | c31d2f8 | 2006-02-03 23:14:42 +0000 | [diff] [blame] | 332 | #elif CONFIG_CPU == PNX0101 |
Tomasz Malesinski | 4e5f4ee | 2006-08-12 21:03:23 +0000 | [diff] [blame] | 333 | int tmp = (60 - value * 4) & 0xff; |
| 334 | CODECVOL = tmp | (tmp << 8); |
Christian Gmeiner | 785e776 | 2008-05-13 06:19:16 +0000 | [diff] [blame] | 335 | #else |
| 336 | current_volume = value * 10; /* tenth of dB */ |
| 337 | set_prescaled_volume(); |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 338 | #endif |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | void sound_set_balance(int value) |
| 342 | { |
| 343 | if(!audio_is_initialized) |
| 344 | return; |
Christian Gmeiner | 785e776 | 2008-05-13 06:19:16 +0000 | [diff] [blame] | 345 | |
| 346 | #ifdef AUDIOHW_HAVE_BALANCE |
| 347 | audiohw_set_balance(value); |
| 348 | #else |
Marcoen Hirschberg | df31f5f | 2007-12-10 11:14:28 +0000 | [diff] [blame] | 349 | current_balance = value * VOLUME_RANGE / 100; /* tenth of dB */ |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 350 | set_prescaled_volume(); |
Jens Arnold | 2993ae6 | 2005-12-07 23:07:07 +0000 | [diff] [blame] | 351 | #endif |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | void sound_set_bass(int value) |
| 355 | { |
| 356 | if(!audio_is_initialized) |
| 357 | return; |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 358 | |
Christian Gmeiner | dfa28e6 | 2008-05-16 20:06:50 +0000 | [diff] [blame] | 359 | #if !defined(AUDIOHW_HAVE_CLIPPING) |
| 360 | #if defined(HAVE_WM8751) |
| 361 | current_bass = value; |
| 362 | #else |
| 363 | current_bass = value * 10; |
| 364 | #endif |
| 365 | #endif |
| 366 | |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 367 | #if defined(AUDIOHW_HAVE_BASS) |
| 368 | audiohw_set_bass(value); |
| 369 | #else |
Thom Johansen | a7fabf0 | 2007-02-26 00:41:26 +0000 | [diff] [blame] | 370 | dsp_callback(DSP_CALLBACK_SET_BASS, current_bass); |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 371 | #endif |
| 372 | |
Christian Gmeiner | 785e776 | 2008-05-13 06:19:16 +0000 | [diff] [blame] | 373 | #if !defined(AUDIOHW_HAVE_CLIPPING) |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 374 | set_prescaled_volume(); |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 375 | #endif |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | void sound_set_treble(int value) |
| 379 | { |
| 380 | if(!audio_is_initialized) |
| 381 | return; |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 382 | |
Christian Gmeiner | dfa28e6 | 2008-05-16 20:06:50 +0000 | [diff] [blame] | 383 | #if !defined(AUDIOHW_HAVE_CLIPPING) |
| 384 | #if defined(HAVE_WM8751) |
| 385 | current_treble = value; |
| 386 | #else |
| 387 | current_treble = value * 10; |
| 388 | #endif |
| 389 | #endif |
| 390 | |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 391 | #if defined(AUDIOHW_HAVE_TREBLE) |
| 392 | audiohw_set_treble(value); |
| 393 | #else |
Thom Johansen | a7fabf0 | 2007-02-26 00:41:26 +0000 | [diff] [blame] | 394 | dsp_callback(DSP_CALLBACK_SET_TREBLE, current_treble); |
Michael Sevakis | 040b6cc | 2008-04-15 14:44:32 +0000 | [diff] [blame] | 395 | #endif |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 396 | |
Christian Gmeiner | 785e776 | 2008-05-13 06:19:16 +0000 | [diff] [blame] | 397 | #if !defined(AUDIOHW_HAVE_CLIPPING) |
Christian Gmeiner | 8391526 | 2008-04-28 08:37:18 +0000 | [diff] [blame] | 398 | set_prescaled_volume(); |
| 399 | #endif |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | void sound_set_channels(int value) |
| 403 | { |
Christian Gmeiner | b1806b2 | 2008-04-22 13:43:01 +0000 | [diff] [blame] | 404 | if(!audio_is_initialized) |
| 405 | return; |
| 406 | |
Thom Johansen | b0960ae | 2006-03-21 23:20:17 +0000 | [diff] [blame] | 407 | #if CONFIG_CODEC == SWCODEC |
Thom Johansen | 99b2742 | 2007-03-07 19:11:16 +0000 | [diff] [blame] | 408 | dsp_callback(DSP_CALLBACK_SET_CHANNEL_CONFIG, value); |
Thom Johansen | b0960ae | 2006-03-21 23:20:17 +0000 | [diff] [blame] | 409 | #else |
Christian Gmeiner | b1806b2 | 2008-04-22 13:43:01 +0000 | [diff] [blame] | 410 | audiohw_set_channel(value); |
Thom Johansen | b0960ae | 2006-03-21 23:20:17 +0000 | [diff] [blame] | 411 | #endif |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void sound_set_stereo_width(int value) |
| 415 | { |
Christian Gmeiner | b1806b2 | 2008-04-22 13:43:01 +0000 | [diff] [blame] | 416 | if(!audio_is_initialized) |
| 417 | return; |
| 418 | |
Thom Johansen | b0960ae | 2006-03-21 23:20:17 +0000 | [diff] [blame] | 419 | #if CONFIG_CODEC == SWCODEC |
Thom Johansen | 99b2742 | 2007-03-07 19:11:16 +0000 | [diff] [blame] | 420 | dsp_callback(DSP_CALLBACK_SET_STEREO_WIDTH, value); |
Thom Johansen | b0960ae | 2006-03-21 23:20:17 +0000 | [diff] [blame] | 421 | #else |
Christian Gmeiner | b1806b2 | 2008-04-22 13:43:01 +0000 | [diff] [blame] | 422 | audiohw_set_stereo_width(value); |
Thom Johansen | b0960ae | 2006-03-21 23:20:17 +0000 | [diff] [blame] | 423 | #endif |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Christian Gmeiner | 59357d4 | 2008-05-16 19:28:45 +0000 | [diff] [blame] | 426 | #if defined(AUDIOHW_HAVE_BASS_CUTOFF) |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 427 | void sound_set_bass_cutoff(int value) |
| 428 | { |
| 429 | if(!audio_is_initialized) |
| 430 | return; |
| 431 | |
| 432 | audiohw_set_bass_cutoff(value); |
| 433 | } |
Christian Gmeiner | 59357d4 | 2008-05-16 19:28:45 +0000 | [diff] [blame] | 434 | #endif |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 435 | |
Christian Gmeiner | 59357d4 | 2008-05-16 19:28:45 +0000 | [diff] [blame] | 436 | #if defined(AUDIOHW_HAVE_TREBLE_CUTOFF) |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 437 | void sound_set_treble_cutoff(int value) |
| 438 | { |
| 439 | if(!audio_is_initialized) |
| 440 | return; |
| 441 | |
| 442 | audiohw_set_treble_cutoff(value); |
| 443 | } |
| 444 | #endif |
| 445 | |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 446 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
| 447 | void sound_set_loudness(int value) |
| 448 | { |
| 449 | if(!audio_is_initialized) |
| 450 | return; |
| 451 | loudness_shadow = (loudness_shadow & 0x04) | |
| 452 | (MAX(MIN(value * 4, 0x44), 0) << 8); |
| 453 | mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow); |
| 454 | } |
| 455 | |
| 456 | void sound_set_avc(int value) |
| 457 | { |
| 458 | if(!audio_is_initialized) |
| 459 | return; |
| 460 | int tmp; |
| 461 | switch (value) { |
| 462 | case 1: /* 20ms */ |
| 463 | tmp = (0x1 << 8) | (0x8 << 12); |
| 464 | break; |
| 465 | case 2: /* 2s */ |
| 466 | tmp = (0x2 << 8) | (0x8 << 12); |
| 467 | break; |
| 468 | case 3: /* 4s */ |
| 469 | tmp = (0x4 << 8) | (0x8 << 12); |
| 470 | break; |
| 471 | case 4: /* 8s */ |
| 472 | tmp = (0x8 << 8) | (0x8 << 12); |
| 473 | break; |
| 474 | case -1: /* turn off and then turn on again to decay quickly */ |
| 475 | tmp = mas_codec_readreg(MAS_REG_KAVC); |
| 476 | mas_codec_writereg(MAS_REG_KAVC, 0); |
| 477 | break; |
| 478 | default: /* off */ |
| 479 | tmp = 0; |
| 480 | break; |
| 481 | } |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 482 | mas_codec_writereg(MAS_REG_KAVC, tmp); |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | void sound_set_mdb_strength(int value) |
| 486 | { |
| 487 | if(!audio_is_initialized) |
| 488 | return; |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 489 | mas_codec_writereg(MAS_REG_KMDB_STR, (value & 0x7f) << 8); |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | void sound_set_mdb_harmonics(int value) |
| 493 | { |
| 494 | if(!audio_is_initialized) |
| 495 | return; |
| 496 | int tmp = value * 127 / 100; |
| 497 | mas_codec_writereg(MAS_REG_KMDB_HAR, (tmp & 0x7f) << 8); |
| 498 | } |
| 499 | |
| 500 | void sound_set_mdb_center(int value) |
| 501 | { |
| 502 | if(!audio_is_initialized) |
| 503 | return; |
| 504 | mas_codec_writereg(MAS_REG_KMDB_FC, (value/10) << 8); |
| 505 | } |
| 506 | |
| 507 | void sound_set_mdb_shape(int value) |
| 508 | { |
| 509 | if(!audio_is_initialized) |
| 510 | return; |
| 511 | mdb_shape_shadow = (mdb_shape_shadow & 0x02) | ((value/10) << 8); |
| 512 | mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow); |
| 513 | } |
| 514 | |
| 515 | void sound_set_mdb_enable(int value) |
| 516 | { |
| 517 | if(!audio_is_initialized) |
| 518 | return; |
| 519 | mdb_shape_shadow = (mdb_shape_shadow & ~0x02) | (value?2:0); |
| 520 | mas_codec_writereg(MAS_REG_KMDB_SWITCH, mdb_shape_shadow); |
| 521 | } |
| 522 | |
| 523 | void sound_set_superbass(int value) |
| 524 | { |
| 525 | if(!audio_is_initialized) |
| 526 | return; |
| 527 | loudness_shadow = (loudness_shadow & ~0x04) | (value?4:0); |
| 528 | mas_codec_writereg(MAS_REG_KLOUDNESS, loudness_shadow); |
| 529 | } |
| 530 | #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ |
| 531 | |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 532 | #else /* SIMULATOR */ |
Jonathan Gordon | 42e4222 | 2007-07-31 11:41:42 +0000 | [diff] [blame] | 533 | int sim_volume; |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 534 | void sound_set_volume(int value) |
| 535 | { |
Dan Everton | 003a4a1 | 2007-10-13 23:01:10 +0000 | [diff] [blame] | 536 | /* 128 is SDL_MIX_MAXVOLUME */ |
Dan Everton | a537114 | 2007-10-13 23:18:30 +0000 | [diff] [blame] | 537 | sim_volume = 128 * (value - VOLUME_MIN / 10) / (VOLUME_RANGE / 10); |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | void sound_set_balance(int value) |
| 541 | { |
| 542 | (void)value; |
| 543 | } |
| 544 | |
| 545 | void sound_set_bass(int value) |
| 546 | { |
| 547 | (void)value; |
| 548 | } |
| 549 | |
| 550 | void sound_set_treble(int value) |
| 551 | { |
| 552 | (void)value; |
| 553 | } |
| 554 | |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 555 | void sound_set_channels(int value) |
| 556 | { |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 557 | (void)value; |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | void sound_set_stereo_width(int value) |
| 561 | { |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 562 | (void)value; |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 563 | } |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 564 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 565 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 566 | void sound_set_loudness(int value) |
| 567 | { |
| 568 | (void)value; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 571 | void sound_set_avc(int value) |
| 572 | { |
| 573 | (void)value; |
| 574 | } |
| 575 | |
| 576 | void sound_set_mdb_strength(int value) |
| 577 | { |
| 578 | (void)value; |
| 579 | } |
| 580 | |
| 581 | void sound_set_mdb_harmonics(int value) |
| 582 | { |
| 583 | (void)value; |
| 584 | } |
| 585 | |
| 586 | void sound_set_mdb_center(int value) |
| 587 | { |
| 588 | (void)value; |
| 589 | } |
| 590 | |
| 591 | void sound_set_mdb_shape(int value) |
| 592 | { |
| 593 | (void)value; |
| 594 | } |
| 595 | |
| 596 | void sound_set_mdb_enable(int value) |
| 597 | { |
| 598 | (void)value; |
| 599 | } |
| 600 | |
| 601 | void sound_set_superbass(int value) |
| 602 | { |
| 603 | (void)value; |
| 604 | } |
| 605 | #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 606 | |
Rob Purchase | 159f8ee | 2008-04-09 22:20:04 +0000 | [diff] [blame] | 607 | #if defined(HAVE_WM8758) || defined(HAVE_WM8985) |
Dan Everton | d7e1f77 | 2007-11-24 07:51:00 +0000 | [diff] [blame] | 608 | void sound_set_bass_cutoff(int value) |
| 609 | { |
| 610 | (void) value; |
| 611 | } |
| 612 | |
| 613 | void sound_set_treble_cutoff(int value) |
| 614 | { |
| 615 | (void) value; |
| 616 | } |
| 617 | #endif /* HAVE_WM8758 */ |
| 618 | |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 619 | #endif /* SIMULATOR */ |
| 620 | |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 621 | void sound_set(int setting, int value) |
| 622 | { |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 623 | sound_set_type* sound_set_val = sound_get_fn(setting); |
| 624 | if (sound_set_val) |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 625 | sound_set_val(value); |
| 626 | } |
| 627 | |
Jonathan Gordon | 6b9b508 | 2008-04-27 14:07:57 +0000 | [diff] [blame] | 628 | #if (!defined(HAVE_AS3514) && !defined (HAVE_WM8731) && !defined(HAVE_TSC2100)) \ |
| 629 | || defined(SIMULATOR) |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 630 | int sound_val2phys(int setting, int value) |
| 631 | { |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 632 | #if CONFIG_CODEC == MAS3587F |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 633 | int result = 0; |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 634 | |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 635 | switch(setting) |
| 636 | { |
| 637 | case SOUND_LEFT_GAIN: |
| 638 | case SOUND_RIGHT_GAIN: |
| 639 | result = (value - 2) * 15; |
| 640 | break; |
| 641 | |
| 642 | case SOUND_MIC_GAIN: |
| 643 | result = value * 15 + 210; |
| 644 | break; |
| 645 | |
| 646 | default: |
| 647 | result = value; |
| 648 | break; |
| 649 | } |
| 650 | return result; |
Andy | e6e5496 | 2005-11-12 04:00:56 +0000 | [diff] [blame] | 651 | #elif defined(HAVE_UDA1380) |
| 652 | int result = 0; |
| 653 | |
| 654 | switch(setting) |
| 655 | { |
| 656 | case SOUND_LEFT_GAIN: |
| 657 | case SOUND_RIGHT_GAIN: |
Andy | e6e5496 | 2005-11-12 04:00:56 +0000 | [diff] [blame] | 658 | case SOUND_MIC_GAIN: |
Jens Arnold | a238ab9 | 2006-05-14 23:34:24 +0000 | [diff] [blame] | 659 | result = value * 5; /* (1/2) * 10 */ |
Andy | e6e5496 | 2005-11-12 04:00:56 +0000 | [diff] [blame] | 660 | break; |
| 661 | |
Jens Arnold | a238ab9 | 2006-05-14 23:34:24 +0000 | [diff] [blame] | 662 | default: |
Andy | e6e5496 | 2005-11-12 04:00:56 +0000 | [diff] [blame] | 663 | result = value; |
| 664 | break; |
| 665 | } |
| 666 | return result; |
Michael Sevakis | c9f6994 | 2007-10-02 08:15:47 +0000 | [diff] [blame] | 667 | #elif defined(HAVE_TLV320) || defined(HAVE_WM8731) |
Linus Nielsen Feltzing | ed4d7a3 | 2006-07-21 08:42:28 +0000 | [diff] [blame] | 668 | int result = 0; |
| 669 | |
| 670 | switch(setting) |
| 671 | { |
Christian Gmeiner | 2ea6da1 | 2008-05-16 20:51:56 +0000 | [diff] [blame] | 672 | #ifdef HAVE_RECORDING |
Linus Nielsen Feltzing | ed4d7a3 | 2006-07-21 08:42:28 +0000 | [diff] [blame] | 673 | case SOUND_LEFT_GAIN: |
| 674 | case SOUND_RIGHT_GAIN: |
| 675 | result = (value - 23) * 15; /* (x - 23)/1.5 *10 */ |
| 676 | break; |
| 677 | |
| 678 | case SOUND_MIC_GAIN: |
| 679 | result = value * 200; /* 0 or 20 dB */ |
| 680 | break; |
Christian Gmeiner | 2ea6da1 | 2008-05-16 20:51:56 +0000 | [diff] [blame] | 681 | #endif |
Linus Nielsen Feltzing | ed4d7a3 | 2006-07-21 08:42:28 +0000 | [diff] [blame] | 682 | default: |
| 683 | result = value; |
| 684 | break; |
| 685 | } |
| 686 | return result; |
Michael Sevakis | 619d222 | 2007-06-05 07:22:26 +0000 | [diff] [blame] | 687 | #elif defined(HAVE_AS3514) |
| 688 | /* This is here for the sim only and the audio driver has its own */ |
| 689 | int result; |
| 690 | |
| 691 | switch(setting) |
| 692 | { |
| 693 | case SOUND_LEFT_GAIN: |
| 694 | case SOUND_RIGHT_GAIN: |
| 695 | case SOUND_MIC_GAIN: |
| 696 | result = (value - 23) * 15; |
| 697 | break; |
| 698 | |
| 699 | default: |
| 700 | result = value; |
| 701 | break; |
| 702 | } |
| 703 | |
| 704 | return result; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 705 | #else |
| 706 | (void)setting; |
| 707 | return value; |
| 708 | #endif |
| 709 | } |
Michael Sevakis | 619d222 | 2007-06-05 07:22:26 +0000 | [diff] [blame] | 710 | #endif /* !defined(HAVE_AS3514) || defined(SIMULATOR) */ |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 711 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 712 | #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 713 | #ifndef SIMULATOR |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 714 | /* This function works by telling the decoder that we have another |
| 715 | crystal frequency than we actually have. It will adjust its internal |
| 716 | parameters and the result is that the audio is played at another pitch. |
| 717 | |
| 718 | The pitch value is in tenths of percent. |
| 719 | */ |
Jens Arnold | b9ebe6a | 2005-05-22 12:45:35 +0000 | [diff] [blame] | 720 | static int last_pitch = 1000; |
| 721 | |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 722 | void sound_set_pitch(int pitch) |
| 723 | { |
| 724 | unsigned long val; |
| 725 | |
Jens Arnold | b9ebe6a | 2005-05-22 12:45:35 +0000 | [diff] [blame] | 726 | if (pitch != last_pitch) |
| 727 | { |
| 728 | /* Calculate the new (bogus) frequency */ |
| 729 | val = 18432 * 1000 / pitch; |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 730 | |
Jens Arnold | b9ebe6a | 2005-05-22 12:45:35 +0000 | [diff] [blame] | 731 | mas_writemem(MAS_BANK_D0, MAS_D0_OFREQ_CONTROL, &val, 1); |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 732 | |
Jens Arnold | b9ebe6a | 2005-05-22 12:45:35 +0000 | [diff] [blame] | 733 | /* We must tell the MAS that the frequency has changed. |
| 734 | * This will unfortunately cause a short silence. */ |
| 735 | mas_writemem(MAS_BANK_D0, MAS_D0_IO_CONTROL_MAIN, &shadow_io_control_main, 1); |
Kevin Ferrare | 9b5264d | 2005-11-06 03:18:34 +0000 | [diff] [blame] | 736 | |
Jens Arnold | b9ebe6a | 2005-05-22 12:45:35 +0000 | [diff] [blame] | 737 | last_pitch = pitch; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | int sound_get_pitch(void) |
| 742 | { |
| 743 | return last_pitch; |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 744 | } |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 745 | #else /* SIMULATOR */ |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 746 | void sound_set_pitch(int pitch) |
| 747 | { |
| 748 | (void)pitch; |
| 749 | } |
Jens Arnold | b9ebe6a | 2005-05-22 12:45:35 +0000 | [diff] [blame] | 750 | |
| 751 | int sound_get_pitch(void) |
| 752 | { |
| 753 | return 1000; |
| 754 | } |
Jens Arnold | 8051a0b | 2005-11-06 23:12:11 +0000 | [diff] [blame] | 755 | #endif /* SIMULATOR */ |
| 756 | #endif /* (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ |