Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 1 | /* |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved. |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 3 | * Not a Contribution. |
| 4 | * |
| 5 | * Copyright (C) 2013 The Android Open Source Project |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 20 | #define LOG_TAG "offload_effect_bass" |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 21 | //#define LOG_NDEBUG 0 |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 22 | |
| 23 | #include <cutils/list.h> |
| 24 | #include <cutils/log.h> |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 25 | #include <cutils/properties.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 26 | #include <tinyalsa/asoundlib.h> |
Subhash Chandra Bose Naripeddy | 090a2aa | 2014-01-30 14:03:12 -0800 | [diff] [blame] | 27 | #include <sound/audio_effects.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 28 | #include <audio_effects/effect_bassboost.h> |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | #include <dlfcn.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 31 | |
| 32 | #include "effect_api.h" |
| 33 | #include "bass_boost.h" |
| 34 | |
| 35 | /* Offload bassboost UUID: 2c4a8c24-1581-487f-94f6-0002a5d5c51b */ |
| 36 | const effect_descriptor_t bassboost_descriptor = { |
| 37 | {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, |
| 38 | {0x2c4a8c24, 0x1581, 0x487f, 0x94f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
| 39 | EFFECT_CONTROL_API_VERSION, |
| 40 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL), |
| 41 | 0, /* TODO */ |
| 42 | 1, |
| 43 | "MSM offload bassboost", |
| 44 | "The Android Open Source Project", |
| 45 | }; |
| 46 | |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 47 | #define LIB_ACDB_LOADER "libacdbloader.so" |
| 48 | #define PBE_CONF_APP_ID 0x00011134 |
| 49 | |
| 50 | enum { |
| 51 | AUDIO_DEVICE_CAL_TYPE = 0, |
| 52 | AUDIO_STREAM_CAL_TYPE, |
| 53 | }; |
| 54 | |
| 55 | typedef struct acdb_audio_cal_cfg { |
| 56 | uint32_t persist; |
| 57 | uint32_t snd_dev_id; |
| 58 | uint32_t dev_id; |
| 59 | int32_t acdb_dev_id; |
| 60 | uint32_t app_type; |
| 61 | uint32_t topo_id; |
| 62 | uint32_t sampling_rate; |
| 63 | uint32_t cal_type; |
| 64 | uint32_t module_id; |
| 65 | uint32_t param_id; |
| 66 | } acdb_audio_cal_cfg_t; |
| 67 | |
| 68 | typedef int (*acdb_get_audio_cal_t) (void *, void *, uint32_t*); |
| 69 | static int pbe_load_config(struct pbe_params *params); |
| 70 | |
| 71 | /* |
| 72 | * Bass operations |
| 73 | */ |
| 74 | int bass_get_parameter(effect_context_t *context, effect_param_t *p, |
| 75 | uint32_t *size) |
| 76 | { |
| 77 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 78 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 79 | int32_t *param_tmp = (int32_t *)p->data; |
| 80 | int32_t param = *param_tmp++; |
| 81 | void *value = p->data + voffset; |
| 82 | int i; |
| 83 | |
| 84 | ALOGV("%s", __func__); |
| 85 | |
| 86 | p->status = 0; |
| 87 | |
| 88 | switch (param) { |
| 89 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: |
| 90 | if (p->vsize < sizeof(uint32_t)) |
| 91 | p->status = -EINVAL; |
| 92 | p->vsize = sizeof(uint32_t); |
| 93 | break; |
| 94 | case BASSBOOST_PARAM_STRENGTH: |
| 95 | if (p->vsize < sizeof(int16_t)) |
| 96 | p->status = -EINVAL; |
| 97 | p->vsize = sizeof(int16_t); |
| 98 | break; |
| 99 | default: |
| 100 | p->status = -EINVAL; |
| 101 | } |
| 102 | |
| 103 | *size = sizeof(effect_param_t) + voffset + p->vsize; |
| 104 | |
| 105 | if (p->status != 0) |
| 106 | return 0; |
| 107 | |
| 108 | switch (param) { |
| 109 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: |
| 110 | ALOGV("%s: BASSBOOST_PARAM_STRENGTH_SUPPORTED", __func__); |
| 111 | if (bass_ctxt->active_index == BASS_BOOST) |
| 112 | *(uint32_t *)value = 1; |
| 113 | else |
| 114 | *(uint32_t *)value = 0; |
| 115 | break; |
| 116 | |
| 117 | case BASSBOOST_PARAM_STRENGTH: |
| 118 | ALOGV("%s: BASSBOOST_PARAM_STRENGTH", __func__); |
| 119 | if (bass_ctxt->active_index == BASS_BOOST) |
| 120 | *(int16_t *)value = bassboost_get_strength(&(bass_ctxt->bassboost_ctxt)); |
| 121 | else |
| 122 | *(int16_t *)value = 0; |
| 123 | break; |
| 124 | |
| 125 | default: |
| 126 | p->status = -EINVAL; |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | int bass_set_parameter(effect_context_t *context, effect_param_t *p, |
| 134 | uint32_t size __unused) |
| 135 | { |
| 136 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 137 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 138 | void *value = p->data + voffset; |
| 139 | int32_t *param_tmp = (int32_t *)p->data; |
| 140 | int32_t param = *param_tmp++; |
| 141 | uint32_t strength; |
| 142 | |
| 143 | ALOGV("%s", __func__); |
| 144 | |
| 145 | p->status = 0; |
| 146 | |
| 147 | switch (param) { |
| 148 | case BASSBOOST_PARAM_STRENGTH: |
| 149 | ALOGV("%s BASSBOOST_PARAM_STRENGTH", __func__); |
| 150 | if (bass_ctxt->active_index == BASS_BOOST) { |
| 151 | strength = (uint32_t)(*(int16_t *)value); |
| 152 | bassboost_set_strength(&(bass_ctxt->bassboost_ctxt), strength); |
| 153 | } else { |
| 154 | /* stength supported only for BB and not for PBE, but do not |
| 155 | * return error for unsupported case, as it fails cts test |
| 156 | */ |
| 157 | ALOGD("%s ignore set strength, index %d", |
| 158 | __func__, bass_ctxt->active_index); |
| 159 | break; |
| 160 | } |
| 161 | break; |
| 162 | default: |
| 163 | p->status = -EINVAL; |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | int bass_set_device(effect_context_t *context, uint32_t device) |
| 171 | { |
| 172 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 173 | |
| 174 | if (device == AUDIO_DEVICE_OUT_SPEAKER) { |
| 175 | bass_ctxt->active_index = BASS_PBE; |
| 176 | ALOGV("%s: set PBE mode, device: %x", __func__, device); |
| 177 | } else if (device == AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 178 | device == AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Dhananjay Kumar | 8413788 | 2015-06-05 20:34:50 +0530 | [diff] [blame^] | 179 | device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP || |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 180 | device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) { |
| 181 | ALOGV("%s: set BB mode, device: %x", __func__, device); |
| 182 | bass_ctxt->active_index = BASS_BOOST; |
| 183 | } else { |
| 184 | ALOGI("%s: disabled by device: %x", __func__, device); |
| 185 | bass_ctxt->active_index = BASS_INVALID; |
| 186 | } |
| 187 | |
| 188 | bassboost_set_device((effect_context_t *)&(bass_ctxt->bassboost_ctxt), device); |
| 189 | pbe_set_device((effect_context_t *)&(bass_ctxt->pbe_ctxt), device); |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | int bass_reset(effect_context_t *context) |
| 195 | { |
| 196 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 197 | |
| 198 | bassboost_reset((effect_context_t *)&(bass_ctxt->bassboost_ctxt)); |
| 199 | pbe_reset((effect_context_t *)&(bass_ctxt->pbe_ctxt)); |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | int bass_init(effect_context_t *context) |
| 205 | { |
| 206 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 207 | |
| 208 | // convery i/o channel config to sub effects |
| 209 | bass_ctxt->bassboost_ctxt.common.config = context->config; |
| 210 | bass_ctxt->pbe_ctxt.common.config = context->config; |
| 211 | |
| 212 | ALOGV("%s", __func__); |
| 213 | |
| 214 | bass_ctxt->active_index = BASS_BOOST; |
| 215 | |
| 216 | |
| 217 | bassboost_init((effect_context_t *)&(bass_ctxt->bassboost_ctxt)); |
| 218 | pbe_init((effect_context_t *)&(bass_ctxt->pbe_ctxt)); |
| 219 | |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | int bass_enable(effect_context_t *context) |
| 224 | { |
| 225 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 226 | |
| 227 | ALOGV("%s", __func__); |
| 228 | |
| 229 | bassboost_enable((effect_context_t *)&(bass_ctxt->bassboost_ctxt)); |
| 230 | pbe_enable((effect_context_t *)&(bass_ctxt->pbe_ctxt)); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | int bass_disable(effect_context_t *context) |
| 236 | { |
| 237 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 238 | |
| 239 | ALOGV("%s", __func__); |
| 240 | |
| 241 | bassboost_disable((effect_context_t *)&(bass_ctxt->bassboost_ctxt)); |
| 242 | pbe_disable((effect_context_t *)&(bass_ctxt->pbe_ctxt)); |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
| 247 | int bass_start(effect_context_t *context, output_context_t *output) |
| 248 | { |
| 249 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 250 | |
| 251 | ALOGV("%s", __func__); |
| 252 | |
| 253 | bassboost_start((effect_context_t *)&(bass_ctxt->bassboost_ctxt), output); |
| 254 | pbe_start((effect_context_t *)&(bass_ctxt->pbe_ctxt), output); |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | int bass_stop(effect_context_t *context, output_context_t *output) |
| 260 | { |
| 261 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 262 | |
| 263 | ALOGV("%s", __func__); |
| 264 | |
| 265 | bassboost_stop((effect_context_t *)&(bass_ctxt->bassboost_ctxt), output); |
| 266 | pbe_stop((effect_context_t *)&(bass_ctxt->pbe_ctxt), output); |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
| 271 | int bass_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 272 | { |
| 273 | bass_context_t *bass_ctxt = (bass_context_t *)context; |
| 274 | |
| 275 | ALOGV("%s", __func__); |
| 276 | |
| 277 | bassboost_set_mode((effect_context_t *)&(bass_ctxt->bassboost_ctxt), hw_acc_fd); |
| 278 | pbe_set_mode((effect_context_t *)&(bass_ctxt->pbe_ctxt), hw_acc_fd); |
| 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | #undef LOG_TAG |
| 284 | #define LOG_TAG "offload_effect_bb" |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 285 | /* |
| 286 | * Bassboost operations |
| 287 | */ |
| 288 | |
| 289 | int bassboost_get_strength(bassboost_context_t *context) |
| 290 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 291 | ALOGV("%s: ctxt %p, strength: %d", __func__, |
| 292 | context, context->strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 293 | return context->strength; |
| 294 | } |
| 295 | |
| 296 | int bassboost_set_strength(bassboost_context_t *context, uint32_t strength) |
| 297 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 298 | ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 299 | context->strength = strength; |
| 300 | |
| 301 | offload_bassboost_set_strength(&(context->offload_bass), strength); |
| 302 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 303 | offload_bassboost_send_params(context->ctl, &context->offload_bass, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 304 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 305 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 306 | if (context->hw_acc_fd > 0) |
| 307 | hw_acc_bassboost_send_params(context->hw_acc_fd, |
| 308 | &context->offload_bass, |
| 309 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 310 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 314 | int bassboost_set_device(effect_context_t *context, uint32_t device) |
| 315 | { |
| 316 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 317 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 318 | ALOGV("%s: ctxt %p, device 0x%x", __func__, bass_ctxt, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 319 | bass_ctxt->device = device; |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 320 | if (device == AUDIO_DEVICE_OUT_WIRED_HEADSET || |
| 321 | device == AUDIO_DEVICE_OUT_WIRED_HEADPHONE || |
Dhananjay Kumar | 8413788 | 2015-06-05 20:34:50 +0530 | [diff] [blame^] | 322 | device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP || |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 323 | device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES) { |
| 324 | if (bass_ctxt->temp_disabled) { |
| 325 | if (effect_is_active(&bass_ctxt->common)) { |
| 326 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true); |
| 327 | if (bass_ctxt->ctl) |
| 328 | offload_bassboost_send_params(bass_ctxt->ctl, |
| 329 | &bass_ctxt->offload_bass, |
| 330 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
| 331 | if (bass_ctxt->hw_acc_fd > 0) |
| 332 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 333 | &bass_ctxt->offload_bass, |
| 334 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
| 335 | } |
| 336 | bass_ctxt->temp_disabled = false; |
| 337 | } |
| 338 | } else { |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 339 | if (!bass_ctxt->temp_disabled) { |
| 340 | if (effect_is_active(&bass_ctxt->common)) { |
| 341 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false); |
| 342 | if (bass_ctxt->ctl) |
| 343 | offload_bassboost_send_params(bass_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 344 | &bass_ctxt->offload_bass, |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 345 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 346 | if (bass_ctxt->hw_acc_fd > 0) |
| 347 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 348 | &bass_ctxt->offload_bass, |
| 349 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 350 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 351 | bass_ctxt->temp_disabled = true; |
| 352 | } |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 353 | ALOGI("%s: ctxt %p, disabled based on device", __func__, bass_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 354 | } |
| 355 | offload_bassboost_set_device(&(bass_ctxt->offload_bass), device); |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | int bassboost_reset(effect_context_t *context) |
| 360 | { |
| 361 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | int bassboost_init(effect_context_t *context) |
| 367 | { |
| 368 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 369 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 370 | ALOGV("%s: ctxt %p", __func__, bass_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 371 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
| 372 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 373 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 374 | context->config.inputCfg.samplingRate = 44100; |
| 375 | context->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 376 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 377 | context->config.inputCfg.bufferProvider.cookie = NULL; |
| 378 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 379 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
| 380 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 381 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 382 | context->config.outputCfg.samplingRate = 44100; |
| 383 | context->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 384 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 385 | context->config.outputCfg.bufferProvider.cookie = NULL; |
| 386 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 387 | |
| 388 | set_config(context, &context->config); |
| 389 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 390 | bass_ctxt->hw_acc_fd = -1; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 391 | bass_ctxt->temp_disabled = false; |
| 392 | memset(&(bass_ctxt->offload_bass), 0, sizeof(struct bass_boost_params)); |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | int bassboost_enable(effect_context_t *context) |
| 398 | { |
| 399 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 400 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 401 | ALOGV("%s: ctxt %p, strength %d", __func__, bass_ctxt, bass_ctxt->strength); |
wjiang | 95d74c2 | 2014-03-28 12:29:58 +0800 | [diff] [blame] | 402 | |
| 403 | if (!offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) && |
| 404 | !(bass_ctxt->temp_disabled)) { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 405 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true); |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 406 | if (bass_ctxt->ctl && bass_ctxt->strength) |
| 407 | offload_bassboost_send_params(bass_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 408 | &bass_ctxt->offload_bass, |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 409 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 410 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 411 | if ((bass_ctxt->hw_acc_fd > 0) && (bass_ctxt->strength)) |
| 412 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 413 | &bass_ctxt->offload_bass, |
| 414 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 415 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
wjiang | d45948e | 2014-02-24 22:19:43 +0800 | [diff] [blame] | 416 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | int bassboost_disable(effect_context_t *context) |
| 421 | { |
| 422 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 423 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 424 | ALOGV("%s: ctxt %p", __func__, bass_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 425 | if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) { |
| 426 | offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false); |
| 427 | if (bass_ctxt->ctl) |
| 428 | offload_bassboost_send_params(bass_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 429 | &bass_ctxt->offload_bass, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 430 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 431 | if (bass_ctxt->hw_acc_fd > 0) |
| 432 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 433 | &bass_ctxt->offload_bass, |
| 434 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 435 | } |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | int bassboost_start(effect_context_t *context, output_context_t *output) |
| 440 | { |
| 441 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 442 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 443 | ALOGV("%s: ctxt %p, ctl %p, strength %d", __func__, bass_ctxt, |
| 444 | output->ctl, bass_ctxt->strength); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 445 | bass_ctxt->ctl = output->ctl; |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 446 | if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) { |
Amit Shekhar | d02f2cd | 2014-01-16 16:51:43 -0800 | [diff] [blame] | 447 | if (bass_ctxt->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 448 | offload_bassboost_send_params(bass_ctxt->ctl, &bass_ctxt->offload_bass, |
Amit Shekhar | d02f2cd | 2014-01-16 16:51:43 -0800 | [diff] [blame] | 449 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 450 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 451 | if (bass_ctxt->hw_acc_fd > 0) |
| 452 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 453 | &bass_ctxt->offload_bass, |
| 454 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 455 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
| 456 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 457 | return 0; |
| 458 | } |
| 459 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 460 | int bassboost_stop(effect_context_t *context, output_context_t *output __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 461 | { |
| 462 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 463 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 464 | ALOGV("%s: ctxt %p", __func__, bass_ctxt); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 465 | if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) && |
| 466 | bass_ctxt->ctl) { |
| 467 | struct bass_boost_params bassboost; |
| 468 | bassboost.enable_flag = false; |
| 469 | offload_bassboost_send_params(bass_ctxt->ctl, &bassboost, |
| 470 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG); |
| 471 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 472 | bass_ctxt->ctl = NULL; |
| 473 | return 0; |
| 474 | } |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 475 | |
| 476 | int bassboost_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 477 | { |
| 478 | bassboost_context_t *bass_ctxt = (bassboost_context_t *)context; |
| 479 | |
| 480 | ALOGV("%s: ctxt %p", __func__, bass_ctxt); |
| 481 | bass_ctxt->hw_acc_fd = hw_acc_fd; |
| 482 | if ((bass_ctxt->hw_acc_fd > 0) && |
| 483 | (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)))) |
| 484 | hw_acc_bassboost_send_params(bass_ctxt->hw_acc_fd, |
| 485 | &bass_ctxt->offload_bass, |
| 486 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 487 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
| 488 | return 0; |
| 489 | } |
Dhananjay Kumar | 5f15ff9 | 2014-05-19 16:45:08 +0800 | [diff] [blame] | 490 | |
| 491 | #undef LOG_TAG |
| 492 | #define LOG_TAG "offload_effect_pbe" |
| 493 | /* |
| 494 | * PBE operations |
| 495 | */ |
| 496 | |
| 497 | int pbe_set_device(effect_context_t *context, uint32_t device) |
| 498 | { |
| 499 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 500 | char propValue[PROPERTY_VALUE_MAX]; |
| 501 | bool pbe_enabled_by_prop = false; |
| 502 | |
| 503 | ALOGV("%s: device: %d", __func__, device); |
| 504 | pbe_ctxt->device = device; |
| 505 | |
| 506 | if (property_get("audio.safx.pbe.enabled", propValue, NULL)) { |
| 507 | pbe_enabled_by_prop = atoi(propValue) || |
| 508 | !strncmp("true", propValue, 4); |
| 509 | } |
| 510 | |
| 511 | if (device == AUDIO_DEVICE_OUT_SPEAKER && pbe_enabled_by_prop == true) { |
| 512 | if (pbe_ctxt->temp_disabled) { |
| 513 | if (effect_is_active(&pbe_ctxt->common)) { |
| 514 | offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), true); |
| 515 | if (pbe_ctxt->ctl) |
| 516 | offload_pbe_send_params(pbe_ctxt->ctl, |
| 517 | &pbe_ctxt->offload_pbe, |
| 518 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 519 | OFFLOAD_SEND_PBE_CONFIG); |
| 520 | if (pbe_ctxt->hw_acc_fd > 0) |
| 521 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 522 | &pbe_ctxt->offload_pbe, |
| 523 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 524 | OFFLOAD_SEND_PBE_CONFIG); |
| 525 | } |
| 526 | pbe_ctxt->temp_disabled = false; |
| 527 | } |
| 528 | } else { |
| 529 | if (!pbe_ctxt->temp_disabled) { |
| 530 | if (effect_is_active(&pbe_ctxt->common)) { |
| 531 | offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), false); |
| 532 | if (pbe_ctxt->ctl) |
| 533 | offload_pbe_send_params(pbe_ctxt->ctl, |
| 534 | &pbe_ctxt->offload_pbe, |
| 535 | OFFLOAD_SEND_PBE_ENABLE_FLAG); |
| 536 | if (pbe_ctxt->hw_acc_fd > 0) |
| 537 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 538 | &pbe_ctxt->offload_pbe, |
| 539 | OFFLOAD_SEND_PBE_ENABLE_FLAG); |
| 540 | } |
| 541 | pbe_ctxt->temp_disabled = true; |
| 542 | } |
| 543 | } |
| 544 | offload_pbe_set_device(&(pbe_ctxt->offload_pbe), device); |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | int pbe_reset(effect_context_t *context) |
| 549 | { |
| 550 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | int pbe_init(effect_context_t *context) |
| 556 | { |
| 557 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 558 | |
| 559 | ALOGV("%s", __func__); |
| 560 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
| 561 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 562 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 563 | context->config.inputCfg.samplingRate = 44100; |
| 564 | context->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 565 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 566 | context->config.inputCfg.bufferProvider.cookie = NULL; |
| 567 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 568 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
| 569 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 570 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 571 | context->config.outputCfg.samplingRate = 44100; |
| 572 | context->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 573 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 574 | context->config.outputCfg.bufferProvider.cookie = NULL; |
| 575 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 576 | |
| 577 | set_config(context, &context->config); |
| 578 | |
| 579 | pbe_ctxt->hw_acc_fd = -1; |
| 580 | pbe_ctxt->temp_disabled = false; |
| 581 | memset(&(pbe_ctxt->offload_pbe), 0, sizeof(struct pbe_params)); |
| 582 | pbe_load_config(&(pbe_ctxt->offload_pbe)); |
| 583 | |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | int pbe_enable(effect_context_t *context) |
| 588 | { |
| 589 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 590 | |
| 591 | ALOGV("%s", __func__); |
| 592 | |
| 593 | if (!offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe)) && |
| 594 | !(pbe_ctxt->temp_disabled)) { |
| 595 | offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), true); |
| 596 | if (pbe_ctxt->ctl) |
| 597 | offload_pbe_send_params(pbe_ctxt->ctl, |
| 598 | &pbe_ctxt->offload_pbe, |
| 599 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 600 | OFFLOAD_SEND_PBE_CONFIG); |
| 601 | if (pbe_ctxt->hw_acc_fd > 0) |
| 602 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 603 | &pbe_ctxt->offload_pbe, |
| 604 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 605 | OFFLOAD_SEND_PBE_CONFIG); |
| 606 | } |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | int pbe_disable(effect_context_t *context) |
| 611 | { |
| 612 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 613 | |
| 614 | ALOGV("%s", __func__); |
| 615 | if (offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe))) { |
| 616 | offload_pbe_set_enable_flag(&(pbe_ctxt->offload_pbe), false); |
| 617 | if (pbe_ctxt->ctl) |
| 618 | offload_pbe_send_params(pbe_ctxt->ctl, |
| 619 | &pbe_ctxt->offload_pbe, |
| 620 | OFFLOAD_SEND_PBE_ENABLE_FLAG); |
| 621 | if (pbe_ctxt->hw_acc_fd > 0) |
| 622 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 623 | &pbe_ctxt->offload_pbe, |
| 624 | OFFLOAD_SEND_PBE_ENABLE_FLAG); |
| 625 | } |
| 626 | return 0; |
| 627 | } |
| 628 | |
| 629 | int pbe_start(effect_context_t *context, output_context_t *output) |
| 630 | { |
| 631 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 632 | |
| 633 | ALOGV("%s", __func__); |
| 634 | pbe_ctxt->ctl = output->ctl; |
| 635 | ALOGV("output->ctl: %p", output->ctl); |
| 636 | if (offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe))) { |
| 637 | if (pbe_ctxt->ctl) |
| 638 | offload_pbe_send_params(pbe_ctxt->ctl, &pbe_ctxt->offload_pbe, |
| 639 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 640 | OFFLOAD_SEND_PBE_CONFIG); |
| 641 | if (pbe_ctxt->hw_acc_fd > 0) |
| 642 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 643 | &pbe_ctxt->offload_pbe, |
| 644 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 645 | OFFLOAD_SEND_PBE_CONFIG); |
| 646 | } |
| 647 | return 0; |
| 648 | } |
| 649 | |
| 650 | int pbe_stop(effect_context_t *context, output_context_t *output __unused) |
| 651 | { |
| 652 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 653 | |
| 654 | ALOGV("%s", __func__); |
| 655 | pbe_ctxt->ctl = NULL; |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | int pbe_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 660 | { |
| 661 | pbe_context_t *pbe_ctxt = (pbe_context_t *)context; |
| 662 | |
| 663 | ALOGV("%s: ctxt %p", __func__, pbe_ctxt); |
| 664 | pbe_ctxt->hw_acc_fd = hw_acc_fd; |
| 665 | if ((pbe_ctxt->hw_acc_fd > 0) && |
| 666 | (offload_pbe_get_enable_flag(&(pbe_ctxt->offload_pbe)))) |
| 667 | hw_acc_pbe_send_params(pbe_ctxt->hw_acc_fd, |
| 668 | &pbe_ctxt->offload_pbe, |
| 669 | OFFLOAD_SEND_PBE_ENABLE_FLAG | |
| 670 | OFFLOAD_SEND_PBE_CONFIG); |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | static int pbe_load_config(struct pbe_params *params) |
| 675 | { |
| 676 | int ret = 0; |
| 677 | uint32_t len = 0; |
| 678 | uint32_t propValue = 0; |
| 679 | uint32_t pbe_app_type = PBE_CONF_APP_ID; |
| 680 | char propValueStr[PROPERTY_VALUE_MAX]; |
| 681 | void *acdb_handle = NULL; |
| 682 | acdb_get_audio_cal_t acdb_get_audio_cal = NULL; |
| 683 | acdb_audio_cal_cfg_t cal_cfg = {0}; |
| 684 | |
| 685 | acdb_handle = dlopen(LIB_ACDB_LOADER, RTLD_NOW); |
| 686 | if (acdb_handle == NULL) { |
| 687 | ALOGE("%s error opening library %s", __func__, LIB_ACDB_LOADER); |
| 688 | return -EFAULT; |
| 689 | } |
| 690 | |
| 691 | acdb_get_audio_cal = (acdb_get_audio_cal_t)dlsym(acdb_handle, |
| 692 | "acdb_loader_get_audio_cal_v2"); |
| 693 | if (acdb_get_audio_cal == NULL) { |
| 694 | dlclose(acdb_handle); |
| 695 | ALOGE("%s error resolving acdb func symbols", __func__); |
| 696 | return -EFAULT; |
| 697 | } |
| 698 | if (property_get("audio.safx.pbe.app.type", propValueStr, "0")) { |
| 699 | propValue = atoll(propValueStr); |
| 700 | if (propValue != 0) { |
| 701 | pbe_app_type = propValue; |
| 702 | } |
| 703 | } |
| 704 | ALOGD("%s pbe_app_type = 0x%.8x", __func__, pbe_app_type); |
| 705 | |
| 706 | cal_cfg.persist = 1; |
| 707 | cal_cfg.cal_type = AUDIO_STREAM_CAL_TYPE; |
| 708 | cal_cfg.app_type = pbe_app_type; |
| 709 | cal_cfg.module_id = PBE_CONF_MODULE_ID; |
| 710 | cal_cfg.param_id = PBE_CONF_PARAM_ID; |
| 711 | |
| 712 | len = sizeof(params->config); |
| 713 | ret = acdb_get_audio_cal((void *)&cal_cfg, (void*)&(params->config), &len); |
| 714 | ALOGD("%s ret = %d, len = %u", __func__, ret, len); |
| 715 | if (ret == 0) |
| 716 | params->cfg_len = len; |
| 717 | |
| 718 | dlclose(acdb_handle); |
| 719 | return ret; |
| 720 | } |