Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 1 | /* |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 2 | * Copyright (c) 2013-2014, 2017-2019, 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 | |
| 20 | #define LOG_TAG "offload_effect_equalizer" |
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> |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 24 | #include <log/log.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 25 | #include <tinyalsa/asoundlib.h> |
Subhash Chandra Bose Naripeddy | 090a2aa | 2014-01-30 14:03:12 -0800 | [diff] [blame] | 26 | #include <sound/audio_effects.h> |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 27 | #include <audio_effects/effect_equalizer.h> |
| 28 | |
| 29 | #include "effect_api.h" |
| 30 | #include "equalizer.h" |
| 31 | |
Trinath Thammishetty | 765efd2 | 2018-08-20 13:23:24 +0530 | [diff] [blame] | 32 | #define EQUALIZER_MAX_LATENCY 0 |
| 33 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 34 | /* Offload equalizer UUID: a0dac280-401c-11e3-9379-0002a5d5c51b */ |
| 35 | const effect_descriptor_t equalizer_descriptor = { |
| 36 | {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type |
| 37 | {0xa0dac280, 0x401c, 0x11e3, 0x9379, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
| 38 | EFFECT_CONTROL_API_VERSION, |
Weiyin Jiang | 90ac1ea | 2017-04-13 14:18:23 +0800 | [diff] [blame] | 39 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_HW_ACC_TUNNEL | EFFECT_FLAG_VOLUME_CTRL), |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 40 | 0, /* TODO */ |
| 41 | 1, |
| 42 | "MSM offload equalizer", |
| 43 | "The Android Open Source Project", |
| 44 | }; |
| 45 | |
Vatsal Bucha | c09ae06 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 46 | #ifdef AUDIO_FEATURE_ENABLED_GCOV |
| 47 | extern void __gcov_flush(); |
| 48 | void enable_gcov() |
| 49 | { |
| 50 | __gcov_flush(); |
| 51 | } |
| 52 | #else |
| 53 | void enable_gcov() |
| 54 | { |
| 55 | } |
| 56 | #endif |
| 57 | |
| 58 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 59 | static const char *equalizer_preset_names[] = { |
| 60 | "Normal", |
| 61 | "Classical", |
| 62 | "Dance", |
| 63 | "Flat", |
| 64 | "Folk", |
| 65 | "Heavy Metal", |
| 66 | "Hip Hop", |
| 67 | "Jazz", |
| 68 | "Pop", |
| 69 | "Rock" |
wjiang | 1eae625 | 2014-07-19 21:46:46 +0800 | [diff] [blame] | 70 | }; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 71 | |
| 72 | static const uint32_t equalizer_band_freq_range[NUM_EQ_BANDS][2] = { |
| 73 | {30000, 120000}, |
| 74 | {120001, 460000}, |
| 75 | {460001, 1800000}, |
| 76 | {1800001, 7000000}, |
| 77 | {7000001, 20000000}}; |
| 78 | |
wjiang | 1eae625 | 2014-07-19 21:46:46 +0800 | [diff] [blame] | 79 | static const int16_t equalizer_band_presets_level[] = { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 80 | 3, 0, 0, 0, 3, /* Normal Preset */ |
| 81 | 5, 3, -2, 4, 4, /* Classical Preset */ |
| 82 | 6, 0, 2, 4, 1, /* Dance Preset */ |
| 83 | 0, 0, 0, 0, 0, /* Flat Preset */ |
| 84 | 3, 0, 0, 2, -1, /* Folk Preset */ |
| 85 | 4, 1, 9, 3, 0, /* Heavy Metal Preset */ |
| 86 | 5, 3, 0, 1, 3, /* Hip Hop Preset */ |
| 87 | 4, 2, -2, 2, 5, /* Jazz Preset */ |
| 88 | -1, 2, 5, 1, -2, /* Pop Preset */ |
| 89 | 5, 3, -1, 3, 5}; /* Rock Preset */ |
| 90 | |
| 91 | const uint16_t equalizer_band_presets_freq[NUM_EQ_BANDS] = { |
| 92 | 60, /* Frequencies in Hz */ |
| 93 | 230, |
| 94 | 910, |
| 95 | 3600, |
| 96 | 14000 |
| 97 | }; |
| 98 | |
| 99 | /* |
| 100 | * Equalizer operations |
| 101 | */ |
| 102 | |
| 103 | int equalizer_get_band_level(equalizer_context_t *context, int32_t band) |
| 104 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 105 | ALOGV("%s: ctxt %p, band: %d level: %d", __func__, context, band, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 106 | context->band_levels[band] * 100); |
| 107 | return context->band_levels[band] * 100; |
| 108 | } |
| 109 | |
| 110 | int equalizer_set_band_level(equalizer_context_t *context, int32_t band, |
| 111 | int32_t level) |
| 112 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 113 | ALOGV("%s: ctxt %p, band: %d, level: %d", __func__, context, band, level); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 114 | if (level > 0) { |
| 115 | level = (int)((level+50)/100); |
| 116 | } else { |
| 117 | level = (int)((level-50)/100); |
| 118 | } |
| 119 | context->band_levels[band] = level; |
| 120 | context->preset = PRESET_CUSTOM; |
| 121 | |
| 122 | offload_eq_set_preset(&(context->offload_eq), PRESET_CUSTOM); |
| 123 | offload_eq_set_bands_level(&(context->offload_eq), |
| 124 | NUM_EQ_BANDS, |
| 125 | equalizer_band_presets_freq, |
| 126 | context->band_levels); |
| 127 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 128 | offload_eq_send_params(context->ctl, &context->offload_eq, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 129 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 130 | OFFLOAD_SEND_EQ_BANDS_LEVEL); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 131 | if (context->hw_acc_fd > 0) |
| 132 | hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq, |
| 133 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 134 | OFFLOAD_SEND_EQ_BANDS_LEVEL); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | int equalizer_get_center_frequency(equalizer_context_t *context, int32_t band) |
| 139 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 140 | ALOGV("%s: ctxt %p, band: %d", __func__, context, band); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 141 | return (equalizer_band_freq_range[band][0] + |
| 142 | equalizer_band_freq_range[band][1]) / 2; |
| 143 | } |
| 144 | |
| 145 | int equalizer_get_band_freq_range(equalizer_context_t *context, int32_t band, |
| 146 | uint32_t *low, uint32_t *high) |
| 147 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 148 | ALOGV("%s: ctxt %p, band: %d", __func__, context, band); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 149 | *low = equalizer_band_freq_range[band][0]; |
| 150 | *high = equalizer_band_freq_range[band][1]; |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | int equalizer_get_band(equalizer_context_t *context, uint32_t freq) |
| 155 | { |
| 156 | int i; |
| 157 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 158 | ALOGV("%s: ctxt %p, freq: %d", __func__, context, freq); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 159 | for(i = 0; i < NUM_EQ_BANDS; i++) { |
| 160 | if (freq <= equalizer_band_freq_range[i][1]) { |
| 161 | return i; |
| 162 | } |
| 163 | } |
| 164 | return NUM_EQ_BANDS - 1; |
| 165 | } |
| 166 | |
| 167 | int equalizer_get_preset(equalizer_context_t *context) |
| 168 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 169 | ALOGV("%s: ctxt %p, preset: %d", __func__, context, context->preset); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 170 | return context->preset; |
| 171 | } |
| 172 | |
| 173 | int equalizer_set_preset(equalizer_context_t *context, int preset) |
| 174 | { |
| 175 | int i; |
| 176 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 177 | ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 178 | context->preset = preset; |
| 179 | for (i=0; i<NUM_EQ_BANDS; i++) |
| 180 | context->band_levels[i] = |
| 181 | equalizer_band_presets_level[i + preset * NUM_EQ_BANDS]; |
| 182 | |
| 183 | offload_eq_set_preset(&(context->offload_eq), preset); |
| 184 | offload_eq_set_bands_level(&(context->offload_eq), |
| 185 | NUM_EQ_BANDS, |
| 186 | equalizer_band_presets_freq, |
| 187 | context->band_levels); |
| 188 | if(context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 189 | offload_eq_send_params(context->ctl, &context->offload_eq, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 190 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 191 | OFFLOAD_SEND_EQ_PRESET); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 192 | if(context->hw_acc_fd > 0) |
| 193 | hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq, |
| 194 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 195 | OFFLOAD_SEND_EQ_PRESET); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | const char * equalizer_get_preset_name(equalizer_context_t *context, |
| 200 | int32_t preset) |
| 201 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 202 | ALOGV("%s: ctxt %p, preset: %s", __func__, context, |
| 203 | equalizer_preset_names[preset]); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 204 | if (preset == PRESET_CUSTOM) { |
| 205 | return "Custom"; |
| 206 | } else { |
| 207 | return equalizer_preset_names[preset]; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | int equalizer_get_num_presets(equalizer_context_t *context) |
| 212 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 213 | ALOGV("%s: ctxt %p, presets_num: %d", __func__, context, |
Weiyin Jiang | 90ac1ea | 2017-04-13 14:18:23 +0800 | [diff] [blame] | 214 | (int)(sizeof(equalizer_preset_names)/sizeof(char *))); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 215 | return sizeof(equalizer_preset_names)/sizeof(char *); |
| 216 | } |
| 217 | |
| 218 | int equalizer_get_parameter(effect_context_t *context, effect_param_t *p, |
| 219 | uint32_t *size) |
| 220 | { |
| 221 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 222 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 223 | int32_t *param_tmp = (int32_t *)p->data; |
| 224 | int32_t param = *param_tmp++; |
| 225 | int32_t param2; |
| 226 | char *name; |
| 227 | void *value = p->data + voffset; |
| 228 | int i; |
| 229 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 230 | ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 231 | |
| 232 | p->status = 0; |
| 233 | |
| 234 | switch (param) { |
| 235 | case EQ_PARAM_NUM_BANDS: |
| 236 | case EQ_PARAM_CUR_PRESET: |
| 237 | case EQ_PARAM_GET_NUM_OF_PRESETS: |
| 238 | case EQ_PARAM_BAND_LEVEL: |
| 239 | case EQ_PARAM_GET_BAND: |
| 240 | if (p->vsize < sizeof(int16_t)) |
| 241 | p->status = -EINVAL; |
| 242 | p->vsize = sizeof(int16_t); |
| 243 | break; |
| 244 | |
| 245 | case EQ_PARAM_LEVEL_RANGE: |
| 246 | if (p->vsize < 2 * sizeof(int16_t)) |
| 247 | p->status = -EINVAL; |
| 248 | p->vsize = 2 * sizeof(int16_t); |
| 249 | break; |
| 250 | case EQ_PARAM_BAND_FREQ_RANGE: |
| 251 | if (p->vsize < 2 * sizeof(int32_t)) |
| 252 | p->status = -EINVAL; |
| 253 | p->vsize = 2 * sizeof(int32_t); |
| 254 | break; |
| 255 | |
| 256 | case EQ_PARAM_CENTER_FREQ: |
| 257 | if (p->vsize < sizeof(int32_t)) |
| 258 | p->status = -EINVAL; |
| 259 | p->vsize = sizeof(int32_t); |
| 260 | break; |
| 261 | |
| 262 | case EQ_PARAM_GET_PRESET_NAME: |
| 263 | break; |
| 264 | |
| 265 | case EQ_PARAM_PROPERTIES: |
| 266 | if (p->vsize < (2 + NUM_EQ_BANDS) * sizeof(uint16_t)) |
| 267 | p->status = -EINVAL; |
| 268 | p->vsize = (2 + NUM_EQ_BANDS) * sizeof(uint16_t); |
| 269 | break; |
| 270 | |
Trinath Thammishetty | 765efd2 | 2018-08-20 13:23:24 +0530 | [diff] [blame] | 271 | case EQ_PARAM_LATENCY: |
| 272 | if (p->vsize < sizeof(uint32_t)) |
| 273 | p->status = -EINVAL; |
| 274 | p->vsize = sizeof(uint32_t); |
| 275 | break; |
| 276 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 277 | default: |
| 278 | p->status = -EINVAL; |
| 279 | } |
| 280 | |
| 281 | *size = sizeof(effect_param_t) + voffset + p->vsize; |
| 282 | |
| 283 | if (p->status != 0) |
| 284 | return 0; |
| 285 | |
| 286 | switch (param) { |
| 287 | case EQ_PARAM_NUM_BANDS: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 288 | *(uint16_t *)value = (uint16_t)NUM_EQ_BANDS; |
| 289 | break; |
| 290 | |
| 291 | case EQ_PARAM_LEVEL_RANGE: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 292 | *(int16_t *)value = -1500; |
| 293 | *((int16_t *)value + 1) = 1500; |
| 294 | break; |
| 295 | |
| 296 | case EQ_PARAM_BAND_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 297 | param2 = *param_tmp; |
rago | 3ef61e2 | 2016-10-31 12:42:15 -0700 | [diff] [blame] | 298 | if (param2 < 0 || param2 >= NUM_EQ_BANDS) { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 299 | p->status = -EINVAL; |
rago | 3ef61e2 | 2016-10-31 12:42:15 -0700 | [diff] [blame] | 300 | if (param2 < 0) { |
| 301 | android_errorWriteLog(0x534e4554, "32438598"); |
| 302 | ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", param2); |
| 303 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 304 | break; |
| 305 | } |
| 306 | *(int16_t *)value = (int16_t)equalizer_get_band_level(eq_ctxt, param2); |
| 307 | break; |
| 308 | |
| 309 | case EQ_PARAM_CENTER_FREQ: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 310 | param2 = *param_tmp; |
rago | 3ef61e2 | 2016-10-31 12:42:15 -0700 | [diff] [blame] | 311 | if (param2 < 0 || param2 >= NUM_EQ_BANDS) { |
| 312 | p->status = -EINVAL; |
| 313 | if (param2 < 0) { |
| 314 | android_errorWriteLog(0x534e4554, "32436341"); |
| 315 | ALOGW("\tERROR EQ_PARAM_CENTER_FREQ band %d", param2); |
| 316 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | *(int32_t *)value = equalizer_get_center_frequency(eq_ctxt, param2); |
| 320 | break; |
| 321 | |
| 322 | case EQ_PARAM_BAND_FREQ_RANGE: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 323 | param2 = *param_tmp; |
rago | 3ef61e2 | 2016-10-31 12:42:15 -0700 | [diff] [blame] | 324 | if (param2 < 0 || param2 >= NUM_EQ_BANDS) { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 325 | p->status = -EINVAL; |
rago | 3ef61e2 | 2016-10-31 12:42:15 -0700 | [diff] [blame] | 326 | if (param2 < 0) { |
| 327 | android_errorWriteLog(0x534e4554, "32247948"); |
| 328 | ALOGW("\tERROR EQ_PARAM_BAND_FREQ_RANGE band %d", param2); |
| 329 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 330 | break; |
| 331 | } |
| 332 | equalizer_get_band_freq_range(eq_ctxt, param2, (uint32_t *)value, |
| 333 | ((uint32_t *)value + 1)); |
| 334 | break; |
| 335 | |
| 336 | case EQ_PARAM_GET_BAND: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 337 | param2 = *param_tmp; |
| 338 | *(uint16_t *)value = (uint16_t)equalizer_get_band(eq_ctxt, param2); |
| 339 | break; |
| 340 | |
| 341 | case EQ_PARAM_CUR_PRESET: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 342 | *(uint16_t *)value = (uint16_t)equalizer_get_preset(eq_ctxt); |
| 343 | break; |
| 344 | |
| 345 | case EQ_PARAM_GET_NUM_OF_PRESETS: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 346 | *(uint16_t *)value = (uint16_t)equalizer_get_num_presets(eq_ctxt); |
| 347 | break; |
| 348 | |
| 349 | case EQ_PARAM_GET_PRESET_NAME: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 350 | param2 = *param_tmp; |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 351 | ALOGV("%s: EQ_PARAM_GET_PRESET_NAME: param2: %d", __func__, param2); |
rago | 0b38640 | 2016-11-15 13:00:50 -0800 | [diff] [blame] | 352 | if ((param2 < 0 && param2 != PRESET_CUSTOM) || |
| 353 | param2 >= equalizer_get_num_presets(eq_ctxt)) { |
| 354 | p->status = -EINVAL; |
| 355 | if (param2 < 0) { |
| 356 | android_errorWriteLog(0x534e4554, "32588016"); |
| 357 | ALOGW("\tERROR EQ_PARAM_GET_PRESET_NAME preset %d", param2); |
| 358 | } |
| 359 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 360 | } |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 361 | |
| 362 | if (p->vsize < 1) { |
| 363 | p->status = -EINVAL; |
| 364 | android_errorWriteLog(0x534e4554, "37536407"); |
| 365 | break; |
| 366 | } |
| 367 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 368 | name = (char *)value; |
| 369 | strlcpy(name, equalizer_get_preset_name(eq_ctxt, param2), p->vsize - 1); |
| 370 | name[p->vsize - 1] = 0; |
| 371 | p->vsize = strlen(name) + 1; |
| 372 | break; |
| 373 | |
| 374 | case EQ_PARAM_PROPERTIES: { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 375 | int16_t *prop = (int16_t *)value; |
| 376 | prop[0] = (int16_t)equalizer_get_preset(eq_ctxt); |
| 377 | prop[1] = (int16_t)NUM_EQ_BANDS; |
| 378 | for (i = 0; i < NUM_EQ_BANDS; i++) { |
| 379 | prop[2 + i] = (int16_t)equalizer_get_band_level(eq_ctxt, i); |
| 380 | } |
| 381 | } break; |
| 382 | |
Trinath Thammishetty | 765efd2 | 2018-08-20 13:23:24 +0530 | [diff] [blame] | 383 | case EQ_PARAM_LATENCY: |
| 384 | *(uint32_t *)value = EQUALIZER_MAX_LATENCY; |
| 385 | break; |
| 386 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 387 | default: |
| 388 | p->status = -EINVAL; |
| 389 | break; |
| 390 | } |
| 391 | |
| 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | int equalizer_set_parameter(effect_context_t *context, effect_param_t *p, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 396 | uint32_t size __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 397 | { |
| 398 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 399 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 400 | void *value = p->data + voffset; |
rago | d8912a6 | 2017-06-06 15:02:43 -0700 | [diff] [blame] | 401 | int32_t vsize = (int32_t) p->vsize; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 402 | int32_t *param_tmp = (int32_t *)p->data; |
| 403 | int32_t param = *param_tmp++; |
| 404 | int32_t preset; |
| 405 | int32_t band; |
| 406 | int32_t level; |
| 407 | int i; |
| 408 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 409 | ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 410 | |
| 411 | p->status = 0; |
| 412 | |
| 413 | switch (param) { |
| 414 | case EQ_PARAM_CUR_PRESET: |
rago | d8912a6 | 2017-06-06 15:02:43 -0700 | [diff] [blame] | 415 | if (vsize < sizeof(int16_t)) { |
| 416 | p->status = -EINVAL; |
| 417 | break; |
| 418 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 419 | preset = (int32_t)(*(uint16_t *)value); |
| 420 | |
| 421 | if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) { |
| 422 | p->status = -EINVAL; |
| 423 | break; |
| 424 | } |
| 425 | equalizer_set_preset(eq_ctxt, preset); |
| 426 | break; |
| 427 | case EQ_PARAM_BAND_LEVEL: |
rago | d8912a6 | 2017-06-06 15:02:43 -0700 | [diff] [blame] | 428 | if (vsize < sizeof(int16_t)) { |
| 429 | p->status = -EINVAL; |
| 430 | break; |
| 431 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 432 | band = *param_tmp; |
| 433 | level = (int32_t)(*(int16_t *)value); |
rago | 0b38640 | 2016-11-15 13:00:50 -0800 | [diff] [blame] | 434 | if (band < 0 || band >= NUM_EQ_BANDS) { |
| 435 | p->status = -EINVAL; |
| 436 | if (band < 0) { |
| 437 | android_errorWriteLog(0x534e4554, "32585400"); |
| 438 | ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", band); |
| 439 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 440 | break; |
| 441 | } |
| 442 | equalizer_set_band_level(eq_ctxt, band, level); |
| 443 | break; |
| 444 | case EQ_PARAM_PROPERTIES: { |
rago | d8912a6 | 2017-06-06 15:02:43 -0700 | [diff] [blame] | 445 | if (vsize < sizeof(int16_t)) { |
| 446 | p->status = -EINVAL; |
| 447 | break; |
| 448 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 449 | int16_t *prop = (int16_t *)value; |
| 450 | if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) { |
| 451 | p->status = -EINVAL; |
| 452 | break; |
| 453 | } |
| 454 | if (prop[0] >= 0) { |
| 455 | equalizer_set_preset(eq_ctxt, (int)prop[0]); |
| 456 | } else { |
rago | d8912a6 | 2017-06-06 15:02:43 -0700 | [diff] [blame] | 457 | if (vsize < (2 + NUM_EQ_BANDS) * sizeof(int16_t)) { |
| 458 | android_errorWriteLog(0x534e4554, "37563371"); |
| 459 | ALOGE("\tERROR EQ_PARAM_PROPERTIES valueSize %d < %d", |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 460 | vsize, (int) ((2 + NUM_EQ_BANDS) * sizeof(int16_t))); |
rago | d8912a6 | 2017-06-06 15:02:43 -0700 | [diff] [blame] | 461 | p->status = -EINVAL; |
| 462 | break; |
| 463 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 464 | if ((int)prop[1] != NUM_EQ_BANDS) { |
| 465 | p->status = -EINVAL; |
| 466 | break; |
| 467 | } |
| 468 | for (i = 0; i < NUM_EQ_BANDS; i++) { |
| 469 | equalizer_set_band_level(eq_ctxt, i, (int)prop[2 + i]); |
| 470 | } |
| 471 | } |
| 472 | } break; |
| 473 | default: |
| 474 | p->status = -EINVAL; |
| 475 | break; |
| 476 | } |
| 477 | |
| 478 | return 0; |
| 479 | } |
| 480 | |
| 481 | int equalizer_set_device(effect_context_t *context, uint32_t device) |
| 482 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 483 | ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 484 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 485 | eq_ctxt->device = device; |
| 486 | offload_eq_set_device(&(eq_ctxt->offload_eq), device); |
| 487 | return 0; |
| 488 | } |
| 489 | |
Aalique Grahame | 22e4910 | 2018-12-18 14:23:57 -0800 | [diff] [blame^] | 490 | int equalizer_reset(effect_context_t *context __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 491 | { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | int equalizer_init(effect_context_t *context) |
| 496 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 497 | ALOGV("%s: ctxt %p", __func__, context); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 498 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 499 | |
| 500 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
| 501 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 502 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 503 | context->config.inputCfg.samplingRate = 44100; |
| 504 | context->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 505 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 506 | context->config.inputCfg.bufferProvider.cookie = NULL; |
| 507 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 508 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
| 509 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 510 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 511 | context->config.outputCfg.samplingRate = 44100; |
| 512 | context->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 513 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 514 | context->config.outputCfg.bufferProvider.cookie = NULL; |
| 515 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 516 | |
| 517 | set_config(context, &context->config); |
| 518 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 519 | eq_ctxt->hw_acc_fd = -1; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 520 | memset(&(eq_ctxt->offload_eq), 0, sizeof(struct eq_params)); |
| 521 | offload_eq_set_preset(&(eq_ctxt->offload_eq), INVALID_PRESET); |
Vatsal Bucha | c09ae06 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 522 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | int equalizer_enable(effect_context_t *context) |
| 527 | { |
| 528 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 529 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 530 | ALOGV("%s: ctxt %p", __func__, context); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 531 | |
| 532 | if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) { |
| 533 | offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true); |
| 534 | if (eq_ctxt->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 535 | offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 536 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 537 | OFFLOAD_SEND_EQ_BANDS_LEVEL); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 538 | if (eq_ctxt->hw_acc_fd > 0) |
| 539 | hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq, |
| 540 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 541 | OFFLOAD_SEND_EQ_BANDS_LEVEL); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 542 | } |
Vatsal Bucha | c09ae06 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 543 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | int equalizer_disable(effect_context_t *context) |
| 548 | { |
| 549 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 550 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 551 | ALOGV("%s:ctxt %p", __func__, eq_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 552 | if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) { |
| 553 | offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false); |
| 554 | if (eq_ctxt->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 555 | offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 556 | OFFLOAD_SEND_EQ_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 557 | if (eq_ctxt->hw_acc_fd > 0) |
| 558 | hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq, |
| 559 | OFFLOAD_SEND_EQ_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 560 | } |
Vatsal Bucha | c09ae06 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 561 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 562 | return 0; |
| 563 | } |
| 564 | |
| 565 | int equalizer_start(effect_context_t *context, output_context_t *output) |
| 566 | { |
| 567 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 568 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 569 | ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 570 | eq_ctxt->ctl = output->ctl; |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 571 | if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) { |
Amit Shekhar | d02f2cd | 2014-01-16 16:51:43 -0800 | [diff] [blame] | 572 | if (eq_ctxt->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 573 | offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq, |
Amit Shekhar | d02f2cd | 2014-01-16 16:51:43 -0800 | [diff] [blame] | 574 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 575 | OFFLOAD_SEND_EQ_BANDS_LEVEL); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 576 | if (eq_ctxt->hw_acc_fd > 0) |
| 577 | hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq, |
| 578 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 579 | OFFLOAD_SEND_EQ_BANDS_LEVEL); |
| 580 | } |
Vatsal Bucha | c09ae06 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 581 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 582 | return 0; |
| 583 | } |
| 584 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 585 | int equalizer_stop(effect_context_t *context, output_context_t *output __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 586 | { |
| 587 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 588 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 589 | ALOGV("%s: ctxt %p", __func__, eq_ctxt); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 590 | if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)) && |
| 591 | eq_ctxt->ctl) { |
| 592 | struct eq_params eq; |
| 593 | eq.enable_flag = false; |
| 594 | offload_eq_send_params(eq_ctxt->ctl, &eq, OFFLOAD_SEND_EQ_ENABLE_FLAG); |
| 595 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 596 | eq_ctxt->ctl = NULL; |
Vatsal Bucha | c09ae06 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 597 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 598 | return 0; |
| 599 | } |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 600 | |
| 601 | int equalizer_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 602 | { |
| 603 | equalizer_context_t *eq_ctxt = (equalizer_context_t *)context; |
| 604 | |
| 605 | ALOGV("%s: ctxt %p", __func__, eq_ctxt); |
| 606 | eq_ctxt->hw_acc_fd = hw_acc_fd; |
| 607 | if ((eq_ctxt->hw_acc_fd > 0) && |
| 608 | (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)))) |
| 609 | hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq, |
| 610 | OFFLOAD_SEND_EQ_ENABLE_FLAG | |
| 611 | OFFLOAD_SEND_EQ_BANDS_LEVEL); |
| 612 | return 0; |
| 613 | } |