Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 1 | /* |
wjiang | 120b9ea | 2014-03-18 06:43:48 +0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 3 | |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #define LOG_TAG "offload_effect_api" |
| 31 | #define LOG_NDEBUG 0 |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 32 | //#define VERY_VERY_VERBOSE_LOGGING |
| 33 | #ifdef VERY_VERY_VERBOSE_LOGGING |
| 34 | #define ALOGVV ALOGV |
| 35 | #else |
| 36 | #define ALOGVV(a...) do { } while(0) |
| 37 | #endif |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 38 | |
| 39 | #include <stdbool.h> |
| 40 | #include <cutils/log.h> |
| 41 | #include <tinyalsa/asoundlib.h> |
Steve Kondik | b1b0360 | 2013-12-27 18:17:52 -0800 | [diff] [blame] | 42 | #include <sound/audio_effects.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 43 | |
| 44 | #include "effect_api.h" |
Ramjee Singh | 7f718d5 | 2015-08-13 18:41:11 +0530 | [diff] [blame] | 45 | #include <errno.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 46 | |
| 47 | #define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) |
| 48 | |
| 49 | #define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19 |
| 50 | const int map_eq_opensl_preset_2_offload_preset[] = { |
| 51 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */ |
| 52 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */ |
| 53 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */ |
| 54 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */ |
| 55 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */ |
| 56 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */ |
| 57 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */ |
| 58 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */ |
| 59 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */ |
| 60 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */ |
| 61 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */ |
| 62 | }; |
| 63 | |
| 64 | const int map_reverb_opensl_preset_2_offload_preset |
| 65 | [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = { |
| 66 | {1, 15}, |
| 67 | {2, 16}, |
| 68 | {3, 17}, |
| 69 | {4, 18}, |
| 70 | {5, 3}, |
| 71 | {6, 20} |
| 72 | }; |
| 73 | |
| 74 | int offload_update_mixer_and_effects_ctl(int card, int device_id, |
| 75 | struct mixer *mixer, |
| 76 | struct mixer_ctl *ctl) |
| 77 | { |
| 78 | char mixer_string[128]; |
| 79 | |
| 80 | snprintf(mixer_string, sizeof(mixer_string), |
| 81 | "%s %d", "Audio Effects Config", device_id); |
| 82 | ALOGV("%s: mixer_string: %s", __func__, mixer_string); |
| 83 | mixer = mixer_open(card); |
| 84 | if (!mixer) { |
| 85 | ALOGE("Failed to open mixer"); |
| 86 | ctl = NULL; |
| 87 | return -EINVAL; |
| 88 | } else { |
| 89 | ctl = mixer_get_ctl_by_name(mixer, mixer_string); |
| 90 | if (!ctl) { |
| 91 | ALOGE("mixer_get_ctl_by_name failed"); |
| 92 | mixer_close(mixer); |
| 93 | mixer = NULL; |
| 94 | return -EINVAL; |
| 95 | } |
| 96 | } |
| 97 | ALOGV("mixer: %p, ctl: %p", mixer, ctl); |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | void offload_close_mixer(struct mixer *mixer) |
| 102 | { |
| 103 | mixer_close(mixer); |
| 104 | } |
| 105 | |
| 106 | void offload_bassboost_set_device(struct bass_boost_params *bassboost, |
| 107 | uint32_t device) |
| 108 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 109 | ALOGVV("%s: device 0x%x", __func__, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 110 | bassboost->device = device; |
| 111 | } |
| 112 | |
| 113 | void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost, |
| 114 | bool enable) |
| 115 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 116 | ALOGVV("%s: enable=%d", __func__, (int)enable); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 117 | bassboost->enable_flag = enable; |
| 118 | } |
| 119 | |
| 120 | int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost) |
| 121 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 122 | ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 123 | return bassboost->enable_flag; |
| 124 | } |
| 125 | |
| 126 | void offload_bassboost_set_strength(struct bass_boost_params *bassboost, |
| 127 | int strength) |
| 128 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 129 | ALOGVV("%s: strength %d", __func__, strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 130 | bassboost->strength = strength; |
| 131 | } |
| 132 | |
| 133 | void offload_bassboost_set_mode(struct bass_boost_params *bassboost, |
| 134 | int mode) |
| 135 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 136 | ALOGVV("%s: mode %d", __func__, mode); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 137 | bassboost->mode = mode; |
| 138 | } |
| 139 | |
| 140 | int offload_bassboost_send_params(struct mixer_ctl *ctl, |
| 141 | struct bass_boost_params bassboost, |
| 142 | unsigned param_send_flags) |
| 143 | { |
| 144 | int param_values[128] = {0}; |
| 145 | int *p_param_values = param_values; |
| 146 | |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 147 | ALOGV("%s: flags 0x%x", __func__, param_send_flags); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 148 | *p_param_values++ = BASS_BOOST_MODULE; |
| 149 | *p_param_values++ = bassboost.device; |
| 150 | *p_param_values++ = 0; /* num of commands*/ |
| 151 | if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) { |
| 152 | *p_param_values++ = BASS_BOOST_ENABLE; |
| 153 | *p_param_values++ = CONFIG_SET; |
| 154 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 155 | *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN; |
| 156 | *p_param_values++ = bassboost.enable_flag; |
| 157 | param_values[2] += 1; |
| 158 | } |
| 159 | if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) { |
| 160 | *p_param_values++ = BASS_BOOST_STRENGTH; |
| 161 | *p_param_values++ = CONFIG_SET; |
| 162 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 163 | *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN; |
| 164 | *p_param_values++ = bassboost.strength; |
| 165 | param_values[2] += 1; |
| 166 | } |
| 167 | if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) { |
| 168 | *p_param_values++ = BASS_BOOST_MODE; |
| 169 | *p_param_values++ = CONFIG_SET; |
| 170 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 171 | *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN; |
| 172 | *p_param_values++ = bassboost.mode; |
| 173 | param_values[2] += 1; |
| 174 | } |
| 175 | |
| 176 | if (param_values[2] && ctl) |
| 177 | mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); |
| 178 | |
| 179 | return 0; |
| 180 | } |
| 181 | |
| 182 | void offload_virtualizer_set_device(struct virtualizer_params *virtualizer, |
| 183 | uint32_t device) |
| 184 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 185 | ALOGVV("%s: device=0x%x", __func__, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 186 | virtualizer->device = device; |
| 187 | } |
| 188 | |
| 189 | void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer, |
| 190 | bool enable) |
| 191 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 192 | ALOGVV("%s: enable=%d", __func__, (int)enable); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 193 | virtualizer->enable_flag = enable; |
| 194 | } |
| 195 | |
| 196 | int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer) |
| 197 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 198 | ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 199 | return virtualizer->enable_flag; |
| 200 | } |
| 201 | |
| 202 | void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer, |
| 203 | int strength) |
| 204 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 205 | ALOGVV("%s: strength %d", __func__, strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 206 | virtualizer->strength = strength; |
| 207 | } |
| 208 | |
| 209 | void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer, |
| 210 | int out_type) |
| 211 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 212 | ALOGVV("%s: out_type %d", __func__, out_type); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 213 | virtualizer->out_type = out_type; |
| 214 | } |
| 215 | |
| 216 | void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer, |
| 217 | int gain_adjust) |
| 218 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 219 | ALOGVV("%s: gain %d", __func__, gain_adjust); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 220 | virtualizer->gain_adjust = gain_adjust; |
| 221 | } |
| 222 | |
| 223 | int offload_virtualizer_send_params(struct mixer_ctl *ctl, |
| 224 | struct virtualizer_params virtualizer, |
| 225 | unsigned param_send_flags) |
| 226 | { |
| 227 | int param_values[128] = {0}; |
| 228 | int *p_param_values = param_values; |
| 229 | |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 230 | ALOGV("%s: flags 0x%x", __func__, param_send_flags); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 231 | *p_param_values++ = VIRTUALIZER_MODULE; |
| 232 | *p_param_values++ = virtualizer.device; |
| 233 | *p_param_values++ = 0; /* num of commands*/ |
| 234 | if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) { |
| 235 | *p_param_values++ = VIRTUALIZER_ENABLE; |
| 236 | *p_param_values++ = CONFIG_SET; |
| 237 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 238 | *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN; |
| 239 | *p_param_values++ = virtualizer.enable_flag; |
| 240 | param_values[2] += 1; |
| 241 | } |
| 242 | if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) { |
| 243 | *p_param_values++ = VIRTUALIZER_STRENGTH; |
| 244 | *p_param_values++ = CONFIG_SET; |
| 245 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 246 | *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN; |
| 247 | *p_param_values++ = virtualizer.strength; |
| 248 | param_values[2] += 1; |
| 249 | } |
| 250 | if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) { |
| 251 | *p_param_values++ = VIRTUALIZER_OUT_TYPE; |
| 252 | *p_param_values++ = CONFIG_SET; |
| 253 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 254 | *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN; |
| 255 | *p_param_values++ = virtualizer.out_type; |
| 256 | param_values[2] += 1; |
| 257 | } |
| 258 | if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) { |
| 259 | *p_param_values++ = VIRTUALIZER_GAIN_ADJUST; |
| 260 | *p_param_values++ = CONFIG_SET; |
| 261 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 262 | *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN; |
| 263 | *p_param_values++ = virtualizer.gain_adjust; |
| 264 | param_values[2] += 1; |
| 265 | } |
| 266 | |
| 267 | if (param_values[2] && ctl) |
| 268 | mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | void offload_eq_set_device(struct eq_params *eq, uint32_t device) |
| 274 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 275 | ALOGVV("%s: device 0x%x", __func__, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 276 | eq->device = device; |
| 277 | } |
| 278 | |
| 279 | void offload_eq_set_enable_flag(struct eq_params *eq, bool enable) |
| 280 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 281 | ALOGVV("%s: enable=%d", __func__, (int)enable); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 282 | eq->enable_flag = enable; |
| 283 | } |
| 284 | |
| 285 | int offload_eq_get_enable_flag(struct eq_params *eq) |
| 286 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 287 | ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 288 | return eq->enable_flag; |
| 289 | } |
| 290 | |
| 291 | void offload_eq_set_preset(struct eq_params *eq, int preset) |
| 292 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 293 | ALOGVV("%s: preset %d", __func__, preset); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 294 | eq->config.preset_id = preset; |
| 295 | eq->config.eq_pregain = Q27_UNITY; |
| 296 | } |
| 297 | |
| 298 | void offload_eq_set_bands_level(struct eq_params *eq, int num_bands, |
| 299 | const uint16_t *band_freq_list, |
| 300 | int *band_gain_list) |
| 301 | { |
| 302 | int i; |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 303 | ALOGVV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 304 | eq->config.num_bands = num_bands; |
| 305 | for (i=0; i<num_bands; i++) { |
| 306 | eq->per_band_cfg[i].band_idx = i; |
| 307 | eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST; |
| 308 | eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000; |
| 309 | eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100; |
| 310 | eq->per_band_cfg[i].quality_factor = Q8_UNITY; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params eq, |
| 315 | unsigned param_send_flags) |
| 316 | { |
| 317 | int param_values[128] = {0}; |
| 318 | int *p_param_values = param_values; |
| 319 | uint32_t i; |
| 320 | |
wjiang | 74ff595 | 2014-05-15 19:38:26 +0800 | [diff] [blame] | 321 | ALOGV("%s: flags 0x%x", __func__, param_send_flags); |
| 322 | if ((eq.config.preset_id < -1) || |
| 323 | ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq.config.preset_id == -1))) { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 324 | ALOGV("No Valid preset to set"); |
| 325 | return 0; |
| 326 | } |
| 327 | *p_param_values++ = EQ_MODULE; |
| 328 | *p_param_values++ = eq.device; |
| 329 | *p_param_values++ = 0; /* num of commands*/ |
| 330 | if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) { |
| 331 | *p_param_values++ = EQ_ENABLE; |
| 332 | *p_param_values++ = CONFIG_SET; |
| 333 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 334 | *p_param_values++ = EQ_ENABLE_PARAM_LEN; |
| 335 | *p_param_values++ = eq.enable_flag; |
| 336 | param_values[2] += 1; |
| 337 | } |
| 338 | if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) { |
| 339 | *p_param_values++ = EQ_CONFIG; |
| 340 | *p_param_values++ = CONFIG_SET; |
| 341 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 342 | *p_param_values++ = EQ_CONFIG_PARAM_LEN; |
| 343 | *p_param_values++ = eq.config.eq_pregain; |
| 344 | *p_param_values++ = |
| 345 | map_eq_opensl_preset_2_offload_preset[eq.config.preset_id]; |
| 346 | *p_param_values++ = 0; |
| 347 | param_values[2] += 1; |
| 348 | } |
| 349 | if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) { |
| 350 | *p_param_values++ = EQ_CONFIG; |
| 351 | *p_param_values++ = CONFIG_SET; |
| 352 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 353 | *p_param_values++ = EQ_CONFIG_PARAM_LEN + |
| 354 | eq.config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN; |
| 355 | *p_param_values++ = eq.config.eq_pregain; |
| 356 | *p_param_values++ = CUSTOM_OPENSL_PRESET; |
| 357 | *p_param_values++ = eq.config.num_bands; |
| 358 | for (i=0; i<eq.config.num_bands; i++) { |
| 359 | *p_param_values++ = eq.per_band_cfg[i].band_idx; |
| 360 | *p_param_values++ = eq.per_band_cfg[i].filter_type; |
| 361 | *p_param_values++ = eq.per_band_cfg[i].freq_millihertz; |
| 362 | *p_param_values++ = eq.per_band_cfg[i].gain_millibels; |
| 363 | *p_param_values++ = eq.per_band_cfg[i].quality_factor; |
| 364 | } |
| 365 | param_values[2] += 1; |
| 366 | } |
| 367 | |
| 368 | if (param_values[2] && ctl) |
| 369 | mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device) |
| 375 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 376 | ALOGVV("%s: device 0x%x", __func__, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 377 | reverb->device = device; |
| 378 | } |
| 379 | |
| 380 | void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable) |
| 381 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 382 | ALOGVV("%s: enable=%d", __func__, (int)enable); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 383 | reverb->enable_flag = enable; |
| 384 | } |
| 385 | |
| 386 | int offload_reverb_get_enable_flag(struct reverb_params *reverb) |
| 387 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 388 | ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 389 | return reverb->enable_flag; |
| 390 | } |
| 391 | |
| 392 | void offload_reverb_set_mode(struct reverb_params *reverb, int mode) |
| 393 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 394 | ALOGVV("%s", __func__); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 395 | reverb->mode = mode; |
| 396 | } |
| 397 | |
| 398 | void offload_reverb_set_preset(struct reverb_params *reverb, int preset) |
| 399 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 400 | ALOGVV("%s: preset %d", __func__, preset); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 401 | if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED)) |
wjiang | 120b9ea | 2014-03-18 06:43:48 +0800 | [diff] [blame] | 402 | reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1]; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix) |
| 406 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 407 | ALOGVV("%s: wet_mix %d", __func__, wet_mix); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 408 | reverb->wet_mix = wet_mix; |
| 409 | } |
| 410 | |
| 411 | void offload_reverb_set_gain_adjust(struct reverb_params *reverb, |
| 412 | int gain_adjust) |
| 413 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 414 | ALOGVV("%s: gain %d", __func__, gain_adjust); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 415 | reverb->gain_adjust = gain_adjust; |
| 416 | } |
| 417 | |
| 418 | void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level) |
| 419 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 420 | ALOGVV("%s: level %d", __func__, room_level); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 421 | reverb->room_level = room_level; |
| 422 | } |
| 423 | |
| 424 | void offload_reverb_set_room_hf_level(struct reverb_params *reverb, |
| 425 | int room_hf_level) |
| 426 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 427 | ALOGVV("%s: level %d", __func__, room_hf_level); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 428 | reverb->room_hf_level = room_hf_level; |
| 429 | } |
| 430 | |
| 431 | void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time) |
| 432 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 433 | ALOGVV("%s: decay time %d", __func__, decay_time); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 434 | reverb->decay_time = decay_time; |
| 435 | } |
| 436 | |
| 437 | void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb, |
| 438 | int decay_hf_ratio) |
| 439 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 440 | ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 441 | reverb->decay_hf_ratio = decay_hf_ratio; |
| 442 | } |
| 443 | |
| 444 | void offload_reverb_set_reflections_level(struct reverb_params *reverb, |
| 445 | int reflections_level) |
| 446 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 447 | ALOGVV("%s: ref level %d", __func__, reflections_level); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 448 | reverb->reflections_level = reflections_level; |
| 449 | } |
| 450 | |
| 451 | void offload_reverb_set_reflections_delay(struct reverb_params *reverb, |
| 452 | int reflections_delay) |
| 453 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 454 | ALOGVV("%s: ref delay", __func__, reflections_delay); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 455 | reverb->reflections_delay = reflections_delay; |
| 456 | } |
| 457 | |
| 458 | void offload_reverb_set_reverb_level(struct reverb_params *reverb, |
| 459 | int reverb_level) |
| 460 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 461 | ALOGD("%s: reverb level %d", __func__, reverb_level); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 462 | reverb->level = reverb_level; |
| 463 | } |
| 464 | |
| 465 | void offload_reverb_set_delay(struct reverb_params *reverb, int delay) |
| 466 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 467 | ALOGVV("%s: delay %d", __func__, delay); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 468 | reverb->delay = delay; |
| 469 | } |
| 470 | |
| 471 | void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion) |
| 472 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 473 | ALOGVV("%s: diffusion %d", __func__, diffusion); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 474 | reverb->diffusion = diffusion; |
| 475 | } |
| 476 | |
| 477 | void offload_reverb_set_density(struct reverb_params *reverb, int density) |
| 478 | { |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 479 | ALOGVV("%s: density %d", __func__, density); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 480 | reverb->density = density; |
| 481 | } |
| 482 | |
| 483 | int offload_reverb_send_params(struct mixer_ctl *ctl, |
| 484 | struct reverb_params reverb, |
| 485 | unsigned param_send_flags) |
| 486 | { |
| 487 | int param_values[128] = {0}; |
| 488 | int *p_param_values = param_values; |
| 489 | |
Dhananjay Kumar | b2c7ac1 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 490 | ALOGV("%s: flags 0x%x", __func__, param_send_flags); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 491 | *p_param_values++ = REVERB_MODULE; |
| 492 | *p_param_values++ = reverb.device; |
| 493 | *p_param_values++ = 0; /* num of commands*/ |
| 494 | |
| 495 | if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) { |
| 496 | *p_param_values++ = REVERB_ENABLE; |
| 497 | *p_param_values++ = CONFIG_SET; |
| 498 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 499 | *p_param_values++ = REVERB_ENABLE_PARAM_LEN; |
| 500 | *p_param_values++ = reverb.enable_flag; |
| 501 | param_values[2] += 1; |
| 502 | } |
| 503 | if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) { |
| 504 | *p_param_values++ = REVERB_MODE; |
| 505 | *p_param_values++ = CONFIG_SET; |
| 506 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 507 | *p_param_values++ = REVERB_MODE_PARAM_LEN; |
| 508 | *p_param_values++ = reverb.mode; |
| 509 | param_values[2] += 1; |
| 510 | } |
| 511 | if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) { |
| 512 | *p_param_values++ = REVERB_PRESET; |
| 513 | *p_param_values++ = CONFIG_SET; |
| 514 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 515 | *p_param_values++ = REVERB_PRESET_PARAM_LEN; |
| 516 | *p_param_values++ = reverb.preset; |
| 517 | param_values[2] += 1; |
| 518 | } |
| 519 | if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) { |
| 520 | *p_param_values++ = REVERB_WET_MIX; |
| 521 | *p_param_values++ = CONFIG_SET; |
| 522 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 523 | *p_param_values++ = REVERB_WET_MIX_PARAM_LEN; |
| 524 | *p_param_values++ = reverb.wet_mix; |
| 525 | param_values[2] += 1; |
| 526 | } |
| 527 | if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) { |
| 528 | *p_param_values++ = REVERB_GAIN_ADJUST; |
| 529 | *p_param_values++ = CONFIG_SET; |
| 530 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 531 | *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN; |
| 532 | *p_param_values++ = reverb.gain_adjust; |
| 533 | param_values[2] += 1; |
| 534 | } |
| 535 | if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) { |
| 536 | *p_param_values++ = REVERB_ROOM_LEVEL; |
| 537 | *p_param_values++ = CONFIG_SET; |
| 538 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 539 | *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN; |
| 540 | *p_param_values++ = reverb.room_level; |
| 541 | param_values[2] += 1; |
| 542 | } |
| 543 | if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) { |
| 544 | *p_param_values++ = REVERB_ROOM_HF_LEVEL; |
| 545 | *p_param_values++ = CONFIG_SET; |
| 546 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 547 | *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN; |
| 548 | *p_param_values++ = reverb.room_hf_level; |
| 549 | param_values[2] += 1; |
| 550 | } |
| 551 | if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) { |
| 552 | *p_param_values++ = REVERB_DECAY_TIME; |
| 553 | *p_param_values++ = CONFIG_SET; |
| 554 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 555 | *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN; |
| 556 | *p_param_values++ = reverb.decay_time; |
| 557 | param_values[2] += 1; |
| 558 | } |
| 559 | if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) { |
| 560 | *p_param_values++ = REVERB_DECAY_HF_RATIO; |
| 561 | *p_param_values++ = CONFIG_SET; |
| 562 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 563 | *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN; |
| 564 | *p_param_values++ = reverb.decay_hf_ratio; |
| 565 | param_values[2] += 1; |
| 566 | } |
| 567 | if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) { |
| 568 | *p_param_values++ = REVERB_REFLECTIONS_LEVEL; |
| 569 | *p_param_values++ = CONFIG_SET; |
| 570 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 571 | *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN; |
| 572 | *p_param_values++ = reverb.reflections_level; |
| 573 | param_values[2] += 1; |
| 574 | } |
| 575 | if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) { |
| 576 | *p_param_values++ = REVERB_REFLECTIONS_DELAY; |
| 577 | *p_param_values++ = CONFIG_SET; |
| 578 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 579 | *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN; |
| 580 | *p_param_values++ = reverb.reflections_delay; |
| 581 | param_values[2] += 1; |
| 582 | } |
| 583 | if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) { |
| 584 | *p_param_values++ = REVERB_LEVEL; |
| 585 | *p_param_values++ = CONFIG_SET; |
| 586 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 587 | *p_param_values++ = REVERB_LEVEL_PARAM_LEN; |
| 588 | *p_param_values++ = reverb.level; |
| 589 | param_values[2] += 1; |
| 590 | } |
| 591 | if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) { |
| 592 | *p_param_values++ = REVERB_DELAY; |
| 593 | *p_param_values++ = CONFIG_SET; |
| 594 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 595 | *p_param_values++ = REVERB_DELAY_PARAM_LEN; |
| 596 | *p_param_values++ = reverb.delay; |
| 597 | param_values[2] += 1; |
| 598 | } |
| 599 | if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) { |
| 600 | *p_param_values++ = REVERB_DIFFUSION; |
| 601 | *p_param_values++ = CONFIG_SET; |
| 602 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 603 | *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN; |
| 604 | *p_param_values++ = reverb.diffusion; |
| 605 | param_values[2] += 1; |
| 606 | } |
| 607 | if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) { |
| 608 | *p_param_values++ = REVERB_DENSITY; |
| 609 | *p_param_values++ = CONFIG_SET; |
| 610 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 611 | *p_param_values++ = REVERB_DENSITY_PARAM_LEN; |
| 612 | *p_param_values++ = reverb.density; |
| 613 | param_values[2] += 1; |
| 614 | } |
| 615 | |
| 616 | if (param_values[2] && ctl) |
| 617 | mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); |
| 618 | |
| 619 | return 0; |
| 620 | } |