Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 1 | /* |
wjiang | ca2685b | 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 |
| 32 | |
| 33 | #include <stdbool.h> |
| 34 | #include <cutils/log.h> |
| 35 | #include <tinyalsa/asoundlib.h> |
Subhash Chandra Bose Naripeddy | 090a2aa | 2014-01-30 14:03:12 -0800 | [diff] [blame] | 36 | #include <sound/audio_effects.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 37 | |
| 38 | #include "effect_api.h" |
| 39 | |
| 40 | #define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) |
| 41 | |
| 42 | #define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19 |
| 43 | const int map_eq_opensl_preset_2_offload_preset[] = { |
| 44 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */ |
| 45 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */ |
| 46 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */ |
| 47 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */ |
| 48 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */ |
| 49 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */ |
| 50 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */ |
| 51 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */ |
| 52 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */ |
| 53 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */ |
| 54 | OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */ |
| 55 | }; |
| 56 | |
| 57 | const int map_reverb_opensl_preset_2_offload_preset |
| 58 | [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = { |
| 59 | {1, 15}, |
| 60 | {2, 16}, |
| 61 | {3, 17}, |
| 62 | {4, 18}, |
| 63 | {5, 3}, |
| 64 | {6, 20} |
| 65 | }; |
| 66 | |
| 67 | int offload_update_mixer_and_effects_ctl(int card, int device_id, |
| 68 | struct mixer *mixer, |
| 69 | struct mixer_ctl *ctl) |
| 70 | { |
| 71 | char mixer_string[128]; |
| 72 | |
| 73 | snprintf(mixer_string, sizeof(mixer_string), |
| 74 | "%s %d", "Audio Effects Config", device_id); |
| 75 | ALOGV("%s: mixer_string: %s", __func__, mixer_string); |
| 76 | mixer = mixer_open(card); |
| 77 | if (!mixer) { |
| 78 | ALOGE("Failed to open mixer"); |
| 79 | ctl = NULL; |
| 80 | return -EINVAL; |
| 81 | } else { |
| 82 | ctl = mixer_get_ctl_by_name(mixer, mixer_string); |
| 83 | if (!ctl) { |
| 84 | ALOGE("mixer_get_ctl_by_name failed"); |
| 85 | mixer_close(mixer); |
| 86 | mixer = NULL; |
| 87 | return -EINVAL; |
| 88 | } |
| 89 | } |
| 90 | ALOGV("mixer: %p, ctl: %p", mixer, ctl); |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | void offload_close_mixer(struct mixer *mixer) |
| 95 | { |
| 96 | mixer_close(mixer); |
| 97 | } |
| 98 | |
| 99 | void offload_bassboost_set_device(struct bass_boost_params *bassboost, |
| 100 | uint32_t device) |
| 101 | { |
| 102 | ALOGV("%s", __func__); |
| 103 | bassboost->device = device; |
| 104 | } |
| 105 | |
| 106 | void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost, |
| 107 | bool enable) |
| 108 | { |
| 109 | ALOGV("%s", __func__); |
| 110 | bassboost->enable_flag = enable; |
| 111 | } |
| 112 | |
| 113 | int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost) |
| 114 | { |
| 115 | ALOGV("%s", __func__); |
| 116 | return bassboost->enable_flag; |
| 117 | } |
| 118 | |
| 119 | void offload_bassboost_set_strength(struct bass_boost_params *bassboost, |
| 120 | int strength) |
| 121 | { |
| 122 | ALOGV("%s", __func__); |
| 123 | bassboost->strength = strength; |
| 124 | } |
| 125 | |
| 126 | void offload_bassboost_set_mode(struct bass_boost_params *bassboost, |
| 127 | int mode) |
| 128 | { |
| 129 | ALOGV("%s", __func__); |
| 130 | bassboost->mode = mode; |
| 131 | } |
| 132 | |
| 133 | int offload_bassboost_send_params(struct mixer_ctl *ctl, |
| 134 | struct bass_boost_params bassboost, |
| 135 | unsigned param_send_flags) |
| 136 | { |
| 137 | int param_values[128] = {0}; |
| 138 | int *p_param_values = param_values; |
| 139 | |
| 140 | ALOGV("%s", __func__); |
| 141 | *p_param_values++ = BASS_BOOST_MODULE; |
| 142 | *p_param_values++ = bassboost.device; |
| 143 | *p_param_values++ = 0; /* num of commands*/ |
| 144 | if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) { |
| 145 | *p_param_values++ = BASS_BOOST_ENABLE; |
| 146 | *p_param_values++ = CONFIG_SET; |
| 147 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 148 | *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN; |
| 149 | *p_param_values++ = bassboost.enable_flag; |
| 150 | param_values[2] += 1; |
| 151 | } |
| 152 | if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) { |
| 153 | *p_param_values++ = BASS_BOOST_STRENGTH; |
| 154 | *p_param_values++ = CONFIG_SET; |
| 155 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 156 | *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN; |
| 157 | *p_param_values++ = bassboost.strength; |
| 158 | param_values[2] += 1; |
| 159 | } |
| 160 | if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) { |
| 161 | *p_param_values++ = BASS_BOOST_MODE; |
| 162 | *p_param_values++ = CONFIG_SET; |
| 163 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 164 | *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN; |
| 165 | *p_param_values++ = bassboost.mode; |
| 166 | param_values[2] += 1; |
| 167 | } |
| 168 | |
| 169 | if (param_values[2] && ctl) |
| 170 | mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); |
| 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | void offload_virtualizer_set_device(struct virtualizer_params *virtualizer, |
| 176 | uint32_t device) |
| 177 | { |
| 178 | ALOGV("%s", __func__); |
| 179 | virtualizer->device = device; |
| 180 | } |
| 181 | |
| 182 | void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer, |
| 183 | bool enable) |
| 184 | { |
| 185 | ALOGV("%s", __func__); |
| 186 | virtualizer->enable_flag = enable; |
| 187 | } |
| 188 | |
| 189 | int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer) |
| 190 | { |
| 191 | ALOGV("%s", __func__); |
| 192 | return virtualizer->enable_flag; |
| 193 | } |
| 194 | |
| 195 | void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer, |
| 196 | int strength) |
| 197 | { |
| 198 | ALOGV("%s", __func__); |
| 199 | virtualizer->strength = strength; |
| 200 | } |
| 201 | |
| 202 | void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer, |
| 203 | int out_type) |
| 204 | { |
| 205 | ALOGV("%s", __func__); |
| 206 | virtualizer->out_type = out_type; |
| 207 | } |
| 208 | |
| 209 | void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer, |
| 210 | int gain_adjust) |
| 211 | { |
| 212 | ALOGV("%s", __func__); |
| 213 | virtualizer->gain_adjust = gain_adjust; |
| 214 | } |
| 215 | |
| 216 | int offload_virtualizer_send_params(struct mixer_ctl *ctl, |
| 217 | struct virtualizer_params virtualizer, |
| 218 | unsigned param_send_flags) |
| 219 | { |
| 220 | int param_values[128] = {0}; |
| 221 | int *p_param_values = param_values; |
| 222 | |
| 223 | ALOGV("%s", __func__); |
| 224 | *p_param_values++ = VIRTUALIZER_MODULE; |
| 225 | *p_param_values++ = virtualizer.device; |
| 226 | *p_param_values++ = 0; /* num of commands*/ |
| 227 | if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) { |
| 228 | *p_param_values++ = VIRTUALIZER_ENABLE; |
| 229 | *p_param_values++ = CONFIG_SET; |
| 230 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 231 | *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN; |
| 232 | *p_param_values++ = virtualizer.enable_flag; |
| 233 | param_values[2] += 1; |
| 234 | } |
| 235 | if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) { |
| 236 | *p_param_values++ = VIRTUALIZER_STRENGTH; |
| 237 | *p_param_values++ = CONFIG_SET; |
| 238 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 239 | *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN; |
| 240 | *p_param_values++ = virtualizer.strength; |
| 241 | param_values[2] += 1; |
| 242 | } |
| 243 | if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) { |
| 244 | *p_param_values++ = VIRTUALIZER_OUT_TYPE; |
| 245 | *p_param_values++ = CONFIG_SET; |
| 246 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 247 | *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN; |
| 248 | *p_param_values++ = virtualizer.out_type; |
| 249 | param_values[2] += 1; |
| 250 | } |
| 251 | if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) { |
| 252 | *p_param_values++ = VIRTUALIZER_GAIN_ADJUST; |
| 253 | *p_param_values++ = CONFIG_SET; |
| 254 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 255 | *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN; |
| 256 | *p_param_values++ = virtualizer.gain_adjust; |
| 257 | param_values[2] += 1; |
| 258 | } |
| 259 | |
| 260 | if (param_values[2] && ctl) |
| 261 | mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); |
| 262 | |
| 263 | return 0; |
| 264 | } |
| 265 | |
| 266 | void offload_eq_set_device(struct eq_params *eq, uint32_t device) |
| 267 | { |
| 268 | ALOGV("%s", __func__); |
| 269 | eq->device = device; |
| 270 | } |
| 271 | |
| 272 | void offload_eq_set_enable_flag(struct eq_params *eq, bool enable) |
| 273 | { |
| 274 | ALOGV("%s", __func__); |
| 275 | eq->enable_flag = enable; |
| 276 | } |
| 277 | |
| 278 | int offload_eq_get_enable_flag(struct eq_params *eq) |
| 279 | { |
| 280 | ALOGV("%s", __func__); |
| 281 | return eq->enable_flag; |
| 282 | } |
| 283 | |
| 284 | void offload_eq_set_preset(struct eq_params *eq, int preset) |
| 285 | { |
| 286 | ALOGV("%s", __func__); |
| 287 | eq->config.preset_id = preset; |
| 288 | eq->config.eq_pregain = Q27_UNITY; |
| 289 | } |
| 290 | |
| 291 | void offload_eq_set_bands_level(struct eq_params *eq, int num_bands, |
| 292 | const uint16_t *band_freq_list, |
| 293 | int *band_gain_list) |
| 294 | { |
| 295 | int i; |
| 296 | ALOGV("%s", __func__); |
| 297 | eq->config.num_bands = num_bands; |
| 298 | for (i=0; i<num_bands; i++) { |
| 299 | eq->per_band_cfg[i].band_idx = i; |
| 300 | eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST; |
| 301 | eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000; |
| 302 | eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100; |
| 303 | eq->per_band_cfg[i].quality_factor = Q8_UNITY; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params eq, |
| 308 | unsigned param_send_flags) |
| 309 | { |
| 310 | int param_values[128] = {0}; |
| 311 | int *p_param_values = param_values; |
| 312 | uint32_t i; |
| 313 | |
| 314 | ALOGV("%s", __func__); |
| 315 | if (eq.config.preset_id < -1 ) { |
| 316 | ALOGV("No Valid preset to set"); |
| 317 | return 0; |
| 318 | } |
| 319 | *p_param_values++ = EQ_MODULE; |
| 320 | *p_param_values++ = eq.device; |
| 321 | *p_param_values++ = 0; /* num of commands*/ |
| 322 | if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) { |
| 323 | *p_param_values++ = EQ_ENABLE; |
| 324 | *p_param_values++ = CONFIG_SET; |
| 325 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 326 | *p_param_values++ = EQ_ENABLE_PARAM_LEN; |
| 327 | *p_param_values++ = eq.enable_flag; |
| 328 | param_values[2] += 1; |
| 329 | } |
| 330 | if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) { |
| 331 | *p_param_values++ = EQ_CONFIG; |
| 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_CONFIG_PARAM_LEN; |
| 335 | *p_param_values++ = eq.config.eq_pregain; |
| 336 | *p_param_values++ = |
| 337 | map_eq_opensl_preset_2_offload_preset[eq.config.preset_id]; |
| 338 | *p_param_values++ = 0; |
| 339 | param_values[2] += 1; |
| 340 | } |
| 341 | if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) { |
| 342 | *p_param_values++ = EQ_CONFIG; |
| 343 | *p_param_values++ = CONFIG_SET; |
| 344 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 345 | *p_param_values++ = EQ_CONFIG_PARAM_LEN + |
| 346 | eq.config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN; |
| 347 | *p_param_values++ = eq.config.eq_pregain; |
| 348 | *p_param_values++ = CUSTOM_OPENSL_PRESET; |
| 349 | *p_param_values++ = eq.config.num_bands; |
| 350 | for (i=0; i<eq.config.num_bands; i++) { |
| 351 | *p_param_values++ = eq.per_band_cfg[i].band_idx; |
| 352 | *p_param_values++ = eq.per_band_cfg[i].filter_type; |
| 353 | *p_param_values++ = eq.per_band_cfg[i].freq_millihertz; |
| 354 | *p_param_values++ = eq.per_band_cfg[i].gain_millibels; |
| 355 | *p_param_values++ = eq.per_band_cfg[i].quality_factor; |
| 356 | } |
| 357 | param_values[2] += 1; |
| 358 | } |
| 359 | |
| 360 | if (param_values[2] && ctl) |
| 361 | mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device) |
| 367 | { |
| 368 | ALOGV("%s", __func__); |
| 369 | reverb->device = device; |
| 370 | } |
| 371 | |
| 372 | void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable) |
| 373 | { |
| 374 | ALOGV("%s", __func__); |
| 375 | reverb->enable_flag = enable; |
| 376 | } |
| 377 | |
| 378 | int offload_reverb_get_enable_flag(struct reverb_params *reverb) |
| 379 | { |
| 380 | ALOGV("%s", __func__); |
| 381 | return reverb->enable_flag; |
| 382 | } |
| 383 | |
| 384 | void offload_reverb_set_mode(struct reverb_params *reverb, int mode) |
| 385 | { |
| 386 | ALOGV("%s", __func__); |
| 387 | reverb->mode = mode; |
| 388 | } |
| 389 | |
| 390 | void offload_reverb_set_preset(struct reverb_params *reverb, int preset) |
| 391 | { |
| 392 | ALOGV("%s", __func__); |
| 393 | if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED)) |
wjiang | ca2685b | 2014-03-18 06:43:48 +0800 | [diff] [blame^] | 394 | 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] | 395 | } |
| 396 | |
| 397 | void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix) |
| 398 | { |
| 399 | ALOGV("%s", __func__); |
| 400 | reverb->wet_mix = wet_mix; |
| 401 | } |
| 402 | |
| 403 | void offload_reverb_set_gain_adjust(struct reverb_params *reverb, |
| 404 | int gain_adjust) |
| 405 | { |
| 406 | ALOGV("%s", __func__); |
| 407 | reverb->gain_adjust = gain_adjust; |
| 408 | } |
| 409 | |
| 410 | void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level) |
| 411 | { |
| 412 | ALOGV("%s", __func__); |
| 413 | reverb->room_level = room_level; |
| 414 | } |
| 415 | |
| 416 | void offload_reverb_set_room_hf_level(struct reverb_params *reverb, |
| 417 | int room_hf_level) |
| 418 | { |
| 419 | ALOGV("%s", __func__); |
| 420 | reverb->room_hf_level = room_hf_level; |
| 421 | } |
| 422 | |
| 423 | void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time) |
| 424 | { |
| 425 | ALOGV("%s", __func__); |
| 426 | reverb->decay_time = decay_time; |
| 427 | } |
| 428 | |
| 429 | void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb, |
| 430 | int decay_hf_ratio) |
| 431 | { |
| 432 | ALOGV("%s", __func__); |
| 433 | reverb->decay_hf_ratio = decay_hf_ratio; |
| 434 | } |
| 435 | |
| 436 | void offload_reverb_set_reflections_level(struct reverb_params *reverb, |
| 437 | int reflections_level) |
| 438 | { |
| 439 | ALOGV("%s", __func__); |
| 440 | reverb->reflections_level = reflections_level; |
| 441 | } |
| 442 | |
| 443 | void offload_reverb_set_reflections_delay(struct reverb_params *reverb, |
| 444 | int reflections_delay) |
| 445 | { |
| 446 | ALOGV("%s", __func__); |
| 447 | reverb->reflections_delay = reflections_delay; |
| 448 | } |
| 449 | |
| 450 | void offload_reverb_set_reverb_level(struct reverb_params *reverb, |
| 451 | int reverb_level) |
| 452 | { |
| 453 | ALOGV("%s", __func__); |
| 454 | reverb->level = reverb_level; |
| 455 | } |
| 456 | |
| 457 | void offload_reverb_set_delay(struct reverb_params *reverb, int delay) |
| 458 | { |
| 459 | ALOGV("%s", __func__); |
| 460 | reverb->delay = delay; |
| 461 | } |
| 462 | |
| 463 | void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion) |
| 464 | { |
| 465 | ALOGV("%s", __func__); |
| 466 | reverb->diffusion = diffusion; |
| 467 | } |
| 468 | |
| 469 | void offload_reverb_set_density(struct reverb_params *reverb, int density) |
| 470 | { |
| 471 | ALOGV("%s", __func__); |
| 472 | reverb->density = density; |
| 473 | } |
| 474 | |
| 475 | int offload_reverb_send_params(struct mixer_ctl *ctl, |
| 476 | struct reverb_params reverb, |
| 477 | unsigned param_send_flags) |
| 478 | { |
| 479 | int param_values[128] = {0}; |
| 480 | int *p_param_values = param_values; |
| 481 | |
| 482 | ALOGV("%s", __func__); |
| 483 | *p_param_values++ = REVERB_MODULE; |
| 484 | *p_param_values++ = reverb.device; |
| 485 | *p_param_values++ = 0; /* num of commands*/ |
| 486 | |
| 487 | if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) { |
| 488 | *p_param_values++ = REVERB_ENABLE; |
| 489 | *p_param_values++ = CONFIG_SET; |
| 490 | *p_param_values++ = 0; /* start offset if param size if greater than 128 */ |
| 491 | *p_param_values++ = REVERB_ENABLE_PARAM_LEN; |
| 492 | *p_param_values++ = reverb.enable_flag; |
| 493 | param_values[2] += 1; |
| 494 | } |
| 495 | if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) { |
| 496 | *p_param_values++ = REVERB_MODE; |
| 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_MODE_PARAM_LEN; |
| 500 | *p_param_values++ = reverb.mode; |
| 501 | param_values[2] += 1; |
| 502 | } |
| 503 | if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) { |
| 504 | *p_param_values++ = REVERB_PRESET; |
| 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_PRESET_PARAM_LEN; |
| 508 | *p_param_values++ = reverb.preset; |
| 509 | param_values[2] += 1; |
| 510 | } |
| 511 | if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) { |
| 512 | *p_param_values++ = REVERB_WET_MIX; |
| 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_WET_MIX_PARAM_LEN; |
| 516 | *p_param_values++ = reverb.wet_mix; |
| 517 | param_values[2] += 1; |
| 518 | } |
| 519 | if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) { |
| 520 | *p_param_values++ = REVERB_GAIN_ADJUST; |
| 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_GAIN_ADJUST_PARAM_LEN; |
| 524 | *p_param_values++ = reverb.gain_adjust; |
| 525 | param_values[2] += 1; |
| 526 | } |
| 527 | if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) { |
| 528 | *p_param_values++ = REVERB_ROOM_LEVEL; |
| 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_ROOM_LEVEL_PARAM_LEN; |
| 532 | *p_param_values++ = reverb.room_level; |
| 533 | param_values[2] += 1; |
| 534 | } |
| 535 | if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) { |
| 536 | *p_param_values++ = REVERB_ROOM_HF_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_HF_LEVEL_PARAM_LEN; |
| 540 | *p_param_values++ = reverb.room_hf_level; |
| 541 | param_values[2] += 1; |
| 542 | } |
| 543 | if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) { |
| 544 | *p_param_values++ = REVERB_DECAY_TIME; |
| 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_DECAY_TIME_PARAM_LEN; |
| 548 | *p_param_values++ = reverb.decay_time; |
| 549 | param_values[2] += 1; |
| 550 | } |
| 551 | if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) { |
| 552 | *p_param_values++ = REVERB_DECAY_HF_RATIO; |
| 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_HF_RATIO_PARAM_LEN; |
| 556 | *p_param_values++ = reverb.decay_hf_ratio; |
| 557 | param_values[2] += 1; |
| 558 | } |
| 559 | if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) { |
| 560 | *p_param_values++ = REVERB_REFLECTIONS_LEVEL; |
| 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_REFLECTIONS_LEVEL_PARAM_LEN; |
| 564 | *p_param_values++ = reverb.reflections_level; |
| 565 | param_values[2] += 1; |
| 566 | } |
| 567 | if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) { |
| 568 | *p_param_values++ = REVERB_REFLECTIONS_DELAY; |
| 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_DELAY_PARAM_LEN; |
| 572 | *p_param_values++ = reverb.reflections_delay; |
| 573 | param_values[2] += 1; |
| 574 | } |
| 575 | if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) { |
| 576 | *p_param_values++ = REVERB_LEVEL; |
| 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_LEVEL_PARAM_LEN; |
| 580 | *p_param_values++ = reverb.level; |
| 581 | param_values[2] += 1; |
| 582 | } |
| 583 | if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) { |
| 584 | *p_param_values++ = REVERB_DELAY; |
| 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_DELAY_PARAM_LEN; |
| 588 | *p_param_values++ = reverb.delay; |
| 589 | param_values[2] += 1; |
| 590 | } |
| 591 | if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) { |
| 592 | *p_param_values++ = REVERB_DIFFUSION; |
| 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_DIFFUSION_PARAM_LEN; |
| 596 | *p_param_values++ = reverb.diffusion; |
| 597 | param_values[2] += 1; |
| 598 | } |
| 599 | if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) { |
| 600 | *p_param_values++ = REVERB_DENSITY; |
| 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_DENSITY_PARAM_LEN; |
| 604 | *p_param_values++ = reverb.density; |
| 605 | param_values[2] += 1; |
| 606 | } |
| 607 | |
| 608 | if (param_values[2] && ctl) |
| 609 | mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values)); |
| 610 | |
| 611 | return 0; |
| 612 | } |