Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 1 | /* |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [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 | * 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_reverb" |
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> |
| 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_environmentalreverb.h> |
| 28 | #include <audio_effects/effect_presetreverb.h> |
| 29 | |
| 30 | #include "effect_api.h" |
| 31 | #include "reverb.h" |
| 32 | |
| 33 | /* Offload auxiliary environmental reverb UUID: 79a18026-18fd-4185-8233-0002a5d5c51b */ |
| 34 | const effect_descriptor_t aux_env_reverb_descriptor = { |
| 35 | { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e } }, |
| 36 | { 0x79a18026, 0x18fd, 0x4185, 0x8233, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, |
| 37 | EFFECT_CONTROL_API_VERSION, |
| 38 | (EFFECT_FLAG_TYPE_AUXILIARY | EFFECT_FLAG_HW_ACC_TUNNEL), |
| 39 | 0, /* TODO */ |
| 40 | 1, |
| 41 | "MSM offload Auxiliary Environmental Reverb", |
| 42 | "The Android Open Source Project", |
| 43 | }; |
| 44 | |
| 45 | /* Offload insert environmental reverb UUID: eb64ea04-973b-43d2-8f5e-0002a5d5c51b */ |
| 46 | const effect_descriptor_t ins_env_reverb_descriptor = { |
| 47 | {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}}, |
| 48 | {0xeb64ea04, 0x973b, 0x43d2, 0x8f5e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 49 | EFFECT_CONTROL_API_VERSION, |
| 50 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_HW_ACC_TUNNEL), |
| 51 | 0, /* TODO */ |
| 52 | 1, |
| 53 | "MSM offload Insert Environmental Reverb", |
| 54 | "The Android Open Source Project", |
| 55 | }; |
| 56 | |
| 57 | // Offload auxiliary preset reverb UUID: 6987be09-b142-4b41-9056-0002a5d5c51b */ |
| 58 | const effect_descriptor_t aux_preset_reverb_descriptor = { |
| 59 | {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 60 | {0x6987be09, 0xb142, 0x4b41, 0x9056, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 61 | EFFECT_CONTROL_API_VERSION, |
| 62 | (EFFECT_FLAG_TYPE_AUXILIARY | EFFECT_FLAG_HW_ACC_TUNNEL), |
| 63 | 0, /* TODO */ |
| 64 | 1, |
| 65 | "MSM offload Auxiliary Preset Reverb", |
| 66 | "The Android Open Source Project", |
| 67 | }; |
| 68 | |
| 69 | // Offload insert preset reverb UUID: aa2bebf6-47cf-4613-9bca-0002a5d5c51b */ |
| 70 | const effect_descriptor_t ins_preset_reverb_descriptor = { |
| 71 | {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 72 | {0xaa2bebf6, 0x47cf, 0x4613, 0x9bca, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 73 | EFFECT_CONTROL_API_VERSION, |
| 74 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_HW_ACC_TUNNEL), |
| 75 | 0, /* TODO */ |
| 76 | 1, |
| 77 | "MSM offload Insert Preset Reverb", |
| 78 | "The Android Open Source Project", |
| 79 | }; |
| 80 | |
| 81 | static const reverb_settings_t reverb_presets[] = { |
| 82 | // REVERB_PRESET_NONE: values are unused |
| 83 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
| 84 | // REVERB_PRESET_SMALLROOM |
| 85 | {-400, -600, 1100, 830, -400, 5, 500, 10, 1000, 1000}, |
| 86 | // REVERB_PRESET_MEDIUMROOM |
| 87 | {-400, -600, 1300, 830, -1000, 20, -200, 20, 1000, 1000}, |
| 88 | // REVERB_PRESET_LARGEROOM |
| 89 | {-400, -600, 1500, 830, -1600, 5, -1000, 40, 1000, 1000}, |
| 90 | // REVERB_PRESET_MEDIUMHALL |
| 91 | {-400, -600, 1800, 700, -1300, 15, -800, 30, 1000, 1000}, |
| 92 | // REVERB_PRESET_LARGEHALL |
| 93 | {-400, -600, 1800, 700, -2000, 30, -1400, 60, 1000, 1000}, |
| 94 | // REVERB_PRESET_PLATE |
| 95 | {-400, -200, 1300, 900, 0, 2, 0, 10, 1000, 750}, |
| 96 | }; |
| 97 | |
| 98 | |
| 99 | void reverb_auxiliary_init(reverb_context_t *context) |
| 100 | { |
| 101 | context->auxiliary = true; |
| 102 | context->preset = false; |
| 103 | } |
| 104 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 105 | void reverb_insert_init(reverb_context_t *context) |
| 106 | { |
| 107 | context->auxiliary = false; |
| 108 | context->preset = true; |
| 109 | context->cur_preset = REVERB_PRESET_LAST + 1; |
| 110 | context->next_preset = REVERB_DEFAULT_PRESET; |
| 111 | } |
| 112 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 113 | void reverb_preset_init(reverb_context_t *context) |
| 114 | { |
| 115 | context->auxiliary = false; |
| 116 | context->preset = true; |
| 117 | context->cur_preset = REVERB_PRESET_LAST + 1; |
| 118 | context->next_preset = REVERB_DEFAULT_PRESET; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * Reverb operations |
| 123 | */ |
| 124 | int16_t reverb_get_room_level(reverb_context_t *context) |
| 125 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 126 | ALOGV("%s: ctxt %p, room level: %d", __func__, context, context->reverb_settings.roomLevel); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 127 | return context->reverb_settings.roomLevel; |
| 128 | } |
| 129 | |
| 130 | void reverb_set_room_level(reverb_context_t *context, int16_t room_level) |
| 131 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 132 | ALOGV("%s: ctxt %p, room level: %d", __func__, context, room_level); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 133 | context->reverb_settings.roomLevel = room_level; |
| 134 | offload_reverb_set_room_level(&(context->offload_reverb), room_level); |
| 135 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 136 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 137 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 138 | OFFLOAD_SEND_REVERB_ROOM_LEVEL); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 139 | if (context->hw_acc_fd > 0) |
| 140 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 141 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 142 | OFFLOAD_SEND_REVERB_ROOM_LEVEL); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | int16_t reverb_get_room_hf_level(reverb_context_t *context) |
| 146 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 147 | ALOGV("%s: ctxt %p, room hf level: %d", __func__, context, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 148 | context->reverb_settings.roomHFLevel); |
| 149 | return context->reverb_settings.roomHFLevel; |
| 150 | } |
| 151 | |
| 152 | void reverb_set_room_hf_level(reverb_context_t *context, int16_t room_hf_level) |
| 153 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 154 | ALOGV("%s: ctxt %p, room hf level: %d", __func__, context, room_hf_level); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 155 | context->reverb_settings.roomHFLevel = room_hf_level; |
| 156 | offload_reverb_set_room_hf_level(&(context->offload_reverb), room_hf_level); |
| 157 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 158 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 159 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 160 | OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 161 | if (context->hw_acc_fd > 0) |
| 162 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 163 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 164 | OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | uint32_t reverb_get_decay_time(reverb_context_t *context) |
| 168 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 169 | ALOGV("%s: ctxt %p, decay time: %d", __func__, context, |
| 170 | context->reverb_settings.decayTime); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 171 | return context->reverb_settings.decayTime; |
| 172 | } |
| 173 | |
| 174 | void reverb_set_decay_time(reverb_context_t *context, uint32_t decay_time) |
| 175 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 176 | ALOGV("%s: ctxt %p, decay_time: %d", __func__, context, decay_time); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 177 | context->reverb_settings.decayTime = decay_time; |
| 178 | offload_reverb_set_decay_time(&(context->offload_reverb), decay_time); |
| 179 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 180 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 181 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 182 | OFFLOAD_SEND_REVERB_DECAY_TIME); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 183 | if (context->hw_acc_fd > 0) |
| 184 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 185 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 186 | OFFLOAD_SEND_REVERB_DECAY_TIME); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | int16_t reverb_get_decay_hf_ratio(reverb_context_t *context) |
| 190 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 191 | ALOGV("%s: ctxt %p, decay hf ratio: %d", __func__, context, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 192 | context->reverb_settings.decayHFRatio); |
| 193 | return context->reverb_settings.decayHFRatio; |
| 194 | } |
| 195 | |
| 196 | void reverb_set_decay_hf_ratio(reverb_context_t *context, int16_t decay_hf_ratio) |
| 197 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 198 | ALOGV("%s: ctxt %p, decay_hf_ratio: %d", __func__, context, decay_hf_ratio); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 199 | context->reverb_settings.decayHFRatio = decay_hf_ratio; |
| 200 | offload_reverb_set_decay_hf_ratio(&(context->offload_reverb), decay_hf_ratio); |
| 201 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 202 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 203 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 204 | OFFLOAD_SEND_REVERB_DECAY_HF_RATIO); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 205 | if (context->hw_acc_fd > 0) |
| 206 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 207 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 208 | OFFLOAD_SEND_REVERB_DECAY_HF_RATIO); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | int16_t reverb_get_reverb_level(reverb_context_t *context) |
| 212 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 213 | ALOGV("%s: ctxt %p, reverb level: %d", __func__, context, |
| 214 | context->reverb_settings.reverbLevel); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 215 | return context->reverb_settings.reverbLevel; |
| 216 | } |
| 217 | |
| 218 | void reverb_set_reverb_level(reverb_context_t *context, int16_t reverb_level) |
| 219 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 220 | ALOGV("%s: ctxt %p, reverb level: %d", __func__, context, reverb_level); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 221 | context->reverb_settings.reverbLevel = reverb_level; |
| 222 | offload_reverb_set_reverb_level(&(context->offload_reverb), reverb_level); |
| 223 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 224 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 225 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 226 | OFFLOAD_SEND_REVERB_LEVEL); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 227 | if (context->hw_acc_fd > 0) |
| 228 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 229 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 230 | OFFLOAD_SEND_REVERB_LEVEL); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 231 | } |
| 232 | |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 233 | uint32_t reverb_get_reverb_delay(reverb_context_t *context) |
| 234 | { |
| 235 | ALOGV("%s: ctxt %p, reverb delay: %d", __func__, context, |
| 236 | context->reverb_settings.reverbDelay); |
| 237 | return context->reverb_settings.reverbDelay; |
| 238 | } |
| 239 | |
| 240 | void reverb_set_reverb_delay(reverb_context_t *context, uint32_t delay) |
| 241 | { |
| 242 | ALOGV("%s: ctxt %p, reverb delay: %d", __func__, context, delay); |
| 243 | context->reverb_settings.reverbDelay = delay; |
| 244 | offload_reverb_set_delay(&(context->offload_reverb), delay); |
| 245 | if (context->ctl) |
| 246 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
| 247 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 248 | OFFLOAD_SEND_REVERB_DELAY); |
| 249 | if (context->hw_acc_fd > 0) |
| 250 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 251 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 252 | OFFLOAD_SEND_REVERB_DELAY); |
| 253 | } |
| 254 | |
| 255 | int16_t reverb_get_reflections_level(reverb_context_t *context) |
| 256 | { |
| 257 | ALOGV("%s: ctxt %p, reflection level: %d", __func__, context, |
| 258 | context->reverb_settings.reflectionsLevel); |
| 259 | return context->reverb_settings.reflectionsLevel; |
| 260 | } |
| 261 | |
| 262 | void reverb_set_reflections_level(reverb_context_t *context, int16_t level) |
| 263 | { |
| 264 | ALOGV("%s: ctxt %p, reflection level: %d", __func__, context, level); |
| 265 | context->reverb_settings.reflectionsLevel = level; |
| 266 | offload_reverb_set_reflections_level(&(context->offload_reverb), level); |
| 267 | if (context->ctl) |
| 268 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
| 269 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 270 | OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL); |
| 271 | if (context->hw_acc_fd > 0) |
| 272 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 273 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 274 | OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL); |
| 275 | } |
| 276 | |
| 277 | uint32_t reverb_get_reflections_delay(reverb_context_t *context) |
| 278 | { |
| 279 | ALOGV("%s: ctxt %p, reflection delay: %d", __func__, context, |
| 280 | context->reverb_settings.reflectionsDelay); |
| 281 | return context->reverb_settings.reflectionsDelay; |
| 282 | } |
| 283 | |
| 284 | void reverb_set_reflections_delay(reverb_context_t *context, uint32_t delay) |
| 285 | { |
| 286 | ALOGV("%s: ctxt %p, reflection delay: %d", __func__, context, delay); |
| 287 | context->reverb_settings.reflectionsDelay = delay; |
| 288 | offload_reverb_set_reflections_delay(&(context->offload_reverb), delay); |
| 289 | if (context->ctl) |
| 290 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
| 291 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 292 | OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY); |
| 293 | if (context->hw_acc_fd > 0) |
| 294 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 295 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 296 | OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY); |
| 297 | } |
| 298 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 299 | int16_t reverb_get_diffusion(reverb_context_t *context) |
| 300 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 301 | ALOGV("%s: ctxt %p, diffusion: %d", __func__, context, |
| 302 | context->reverb_settings.diffusion); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 303 | return context->reverb_settings.diffusion; |
| 304 | } |
| 305 | |
| 306 | void reverb_set_diffusion(reverb_context_t *context, int16_t diffusion) |
| 307 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 308 | ALOGV("%s: ctxt %p, diffusion: %d", __func__, context, diffusion); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 309 | context->reverb_settings.diffusion = diffusion; |
| 310 | offload_reverb_set_diffusion(&(context->offload_reverb), diffusion); |
| 311 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 312 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 313 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 314 | OFFLOAD_SEND_REVERB_DIFFUSION); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 315 | if (context->hw_acc_fd > 0) |
| 316 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 317 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 318 | OFFLOAD_SEND_REVERB_DIFFUSION); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | int16_t reverb_get_density(reverb_context_t *context) |
| 322 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 323 | ALOGV("%s: ctxt %p, density: %d", __func__, context, |
| 324 | context->reverb_settings.density); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 325 | return context->reverb_settings.density; |
| 326 | } |
| 327 | |
| 328 | void reverb_set_density(reverb_context_t *context, int16_t density) |
| 329 | { |
wjiang | 50b81f4 | 2014-08-06 08:03:14 +0800 | [diff] [blame] | 330 | ALOGV("%s: ctxt %p, density: %d", __func__, context, density); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 331 | context->reverb_settings.density = density; |
| 332 | offload_reverb_set_density(&(context->offload_reverb), density); |
| 333 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 334 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 335 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 336 | OFFLOAD_SEND_REVERB_DENSITY); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 337 | if (context->hw_acc_fd > 0) |
| 338 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 339 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 340 | OFFLOAD_SEND_REVERB_DENSITY); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | void reverb_set_preset(reverb_context_t *context, int16_t preset) |
| 344 | { |
wjiang | b27e25f | 2014-01-22 13:24:26 +0800 | [diff] [blame] | 345 | bool enable; |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 346 | ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 347 | context->next_preset = preset; |
| 348 | offload_reverb_set_preset(&(context->offload_reverb), preset); |
wjiang | b27e25f | 2014-01-22 13:24:26 +0800 | [diff] [blame] | 349 | |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 350 | if (context->enabled_by_client) { |
| 351 | enable = (preset == REVERB_PRESET_NONE) ? false: true; |
| 352 | offload_reverb_set_enable_flag(&(context->offload_reverb), enable); |
wjiang | b27e25f | 2014-01-22 13:24:26 +0800 | [diff] [blame] | 353 | |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 354 | if (context->ctl) |
| 355 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 356 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 357 | OFFLOAD_SEND_REVERB_PRESET); |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 358 | if (context->hw_acc_fd > 0) |
| 359 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 360 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 361 | OFFLOAD_SEND_REVERB_PRESET); |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 362 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void reverb_set_all_properties(reverb_context_t *context, |
| 366 | reverb_settings_t *reverb_settings) |
| 367 | { |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 368 | ALOGV("%s: ctxt %p", __func__, context); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 369 | context->reverb_settings.roomLevel = reverb_settings->roomLevel; |
| 370 | context->reverb_settings.roomHFLevel = reverb_settings->roomHFLevel; |
| 371 | context->reverb_settings.decayTime = reverb_settings->decayTime; |
| 372 | context->reverb_settings.decayHFRatio = reverb_settings->decayHFRatio; |
| 373 | context->reverb_settings.reverbLevel = reverb_settings->reverbLevel; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 374 | context->reverb_settings.reverbDelay = reverb_settings->reverbDelay; |
| 375 | context->reverb_settings.reflectionsLevel = reverb_settings->reflectionsLevel; |
| 376 | context->reverb_settings.reflectionsDelay = reverb_settings->reflectionsDelay; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 377 | context->reverb_settings.diffusion = reverb_settings->diffusion; |
| 378 | context->reverb_settings.density = reverb_settings->density; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 379 | |
| 380 | offload_reverb_set_room_level(&(context->offload_reverb), |
| 381 | reverb_settings->roomLevel); |
| 382 | offload_reverb_set_room_hf_level(&(context->offload_reverb), |
| 383 | reverb_settings->roomHFLevel); |
| 384 | offload_reverb_set_decay_time(&(context->offload_reverb), |
| 385 | reverb_settings->decayTime); |
| 386 | offload_reverb_set_decay_hf_ratio(&(context->offload_reverb), |
| 387 | reverb_settings->decayHFRatio); |
| 388 | offload_reverb_set_reverb_level(&(context->offload_reverb), |
| 389 | reverb_settings->reverbLevel); |
| 390 | offload_reverb_set_delay(&(context->offload_reverb), |
| 391 | reverb_settings->reverbDelay); |
| 392 | offload_reverb_set_reflections_level(&(context->offload_reverb), |
| 393 | reverb_settings->reflectionsLevel); |
| 394 | offload_reverb_set_reflections_delay(&(context->offload_reverb), |
| 395 | reverb_settings->reflectionsDelay); |
| 396 | offload_reverb_set_diffusion(&(context->offload_reverb), |
| 397 | reverb_settings->diffusion); |
| 398 | offload_reverb_set_density(&(context->offload_reverb), |
| 399 | reverb_settings->density); |
| 400 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 401 | if (context->ctl) |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 402 | offload_reverb_send_params(context->ctl, &context->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 403 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 404 | OFFLOAD_SEND_REVERB_ROOM_LEVEL | |
| 405 | OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL | |
| 406 | OFFLOAD_SEND_REVERB_DECAY_TIME | |
| 407 | OFFLOAD_SEND_REVERB_DECAY_HF_RATIO | |
| 408 | OFFLOAD_SEND_REVERB_LEVEL | |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 409 | OFFLOAD_SEND_REVERB_DELAY | |
| 410 | OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL | |
| 411 | OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 412 | OFFLOAD_SEND_REVERB_DIFFUSION | |
| 413 | OFFLOAD_SEND_REVERB_DENSITY); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 414 | if (context->hw_acc_fd > 0) |
| 415 | hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb, |
| 416 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 417 | OFFLOAD_SEND_REVERB_ROOM_LEVEL | |
| 418 | OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL | |
| 419 | OFFLOAD_SEND_REVERB_DECAY_TIME | |
| 420 | OFFLOAD_SEND_REVERB_DECAY_HF_RATIO | |
| 421 | OFFLOAD_SEND_REVERB_LEVEL | |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 422 | OFFLOAD_SEND_REVERB_DELAY | |
| 423 | OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL | |
| 424 | OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 425 | OFFLOAD_SEND_REVERB_DIFFUSION | |
| 426 | OFFLOAD_SEND_REVERB_DENSITY); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | void reverb_load_preset(reverb_context_t *context) |
| 430 | { |
| 431 | context->cur_preset = context->next_preset; |
| 432 | |
| 433 | if (context->cur_preset != REVERB_PRESET_NONE) { |
| 434 | const reverb_settings_t *preset = &reverb_presets[context->cur_preset]; |
| 435 | reverb_set_room_level(context, preset->roomLevel); |
| 436 | reverb_set_room_hf_level(context, preset->roomHFLevel); |
| 437 | reverb_set_decay_time(context, preset->decayTime); |
| 438 | reverb_set_decay_hf_ratio(context, preset->decayHFRatio); |
| 439 | reverb_set_reverb_level(context, preset->reverbLevel); |
| 440 | reverb_set_diffusion(context, preset->diffusion); |
| 441 | reverb_set_density(context, preset->density); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | int reverb_get_parameter(effect_context_t *context, effect_param_t *p, |
| 446 | uint32_t *size) |
| 447 | { |
| 448 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 449 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 450 | int32_t *param_tmp = (int32_t *)p->data; |
| 451 | int32_t param = *param_tmp++; |
| 452 | void *value = p->data + voffset; |
| 453 | reverb_settings_t *reverb_settings; |
| 454 | int i; |
| 455 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 456 | ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 457 | |
| 458 | p->status = 0; |
| 459 | |
| 460 | if (reverb_ctxt->preset) { |
| 461 | if (param != REVERB_PARAM_PRESET || p->vsize < sizeof(uint16_t)) |
| 462 | return -EINVAL; |
| 463 | *(uint16_t *)value = reverb_ctxt->next_preset; |
| 464 | ALOGV("get REVERB_PARAM_PRESET, preset %d", reverb_ctxt->next_preset); |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 465 | return 0; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 466 | } |
| 467 | switch (param) { |
| 468 | case REVERB_PARAM_ROOM_LEVEL: |
| 469 | if (p->vsize < sizeof(uint16_t)) |
| 470 | p->status = -EINVAL; |
| 471 | p->vsize = sizeof(uint16_t); |
| 472 | break; |
| 473 | case REVERB_PARAM_ROOM_HF_LEVEL: |
| 474 | if (p->vsize < sizeof(uint16_t)) |
| 475 | p->status = -EINVAL; |
| 476 | p->vsize = sizeof(uint16_t); |
| 477 | break; |
| 478 | case REVERB_PARAM_DECAY_TIME: |
| 479 | if (p->vsize < sizeof(uint32_t)) |
| 480 | p->status = -EINVAL; |
| 481 | p->vsize = sizeof(uint32_t); |
| 482 | break; |
| 483 | case REVERB_PARAM_DECAY_HF_RATIO: |
| 484 | if (p->vsize < sizeof(uint16_t)) |
| 485 | p->status = -EINVAL; |
| 486 | p->vsize = sizeof(uint16_t); |
| 487 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 488 | case REVERB_PARAM_REVERB_LEVEL: |
| 489 | if (p->vsize < sizeof(uint16_t)) |
| 490 | p->status = -EINVAL; |
| 491 | p->vsize = sizeof(uint16_t); |
| 492 | break; |
| 493 | case REVERB_PARAM_REVERB_DELAY: |
| 494 | if (p->vsize < sizeof(uint32_t)) |
| 495 | p->status = -EINVAL; |
| 496 | p->vsize = sizeof(uint32_t); |
| 497 | break; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 498 | case REVERB_PARAM_REFLECTIONS_LEVEL: |
| 499 | if (p->vsize < sizeof(uint16_t)) |
| 500 | p->status = -EINVAL; |
| 501 | p->vsize = sizeof(uint16_t); |
| 502 | break; |
| 503 | case REVERB_PARAM_REFLECTIONS_DELAY: |
| 504 | if (p->vsize < sizeof(uint32_t)) |
| 505 | p->status = -EINVAL; |
| 506 | p->vsize = sizeof(uint32_t); |
| 507 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 508 | case REVERB_PARAM_DIFFUSION: |
| 509 | if (p->vsize < sizeof(uint16_t)) |
| 510 | p->status = -EINVAL; |
| 511 | p->vsize = sizeof(uint16_t); |
| 512 | break; |
| 513 | case REVERB_PARAM_DENSITY: |
| 514 | if (p->vsize < sizeof(uint16_t)) |
| 515 | p->status = -EINVAL; |
| 516 | p->vsize = sizeof(uint16_t); |
| 517 | break; |
| 518 | case REVERB_PARAM_PROPERTIES: |
| 519 | if (p->vsize < sizeof(reverb_settings_t)) |
| 520 | p->status = -EINVAL; |
| 521 | p->vsize = sizeof(reverb_settings_t); |
| 522 | break; |
| 523 | default: |
| 524 | p->status = -EINVAL; |
| 525 | } |
| 526 | |
| 527 | *size = sizeof(effect_param_t) + voffset + p->vsize; |
| 528 | |
| 529 | if (p->status != 0) |
| 530 | return 0; |
| 531 | |
| 532 | switch (param) { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 533 | case REVERB_PARAM_ROOM_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 534 | *(int16_t *)value = reverb_get_room_level(reverb_ctxt); |
| 535 | break; |
| 536 | case REVERB_PARAM_ROOM_HF_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 537 | *(int16_t *)value = reverb_get_room_hf_level(reverb_ctxt); |
| 538 | break; |
| 539 | case REVERB_PARAM_DECAY_TIME: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 540 | *(uint32_t *)value = reverb_get_decay_time(reverb_ctxt); |
| 541 | break; |
| 542 | case REVERB_PARAM_DECAY_HF_RATIO: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 543 | *(int16_t *)value = reverb_get_decay_hf_ratio(reverb_ctxt); |
| 544 | break; |
| 545 | case REVERB_PARAM_REVERB_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 546 | *(int16_t *)value = reverb_get_reverb_level(reverb_ctxt); |
| 547 | break; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 548 | case REVERB_PARAM_REVERB_DELAY: |
| 549 | *(uint32_t *)value = reverb_get_reverb_delay(reverb_ctxt); |
| 550 | break; |
| 551 | case REVERB_PARAM_REFLECTIONS_LEVEL: |
| 552 | *(int16_t *)value = reverb_get_reflections_level(reverb_ctxt); |
| 553 | break; |
| 554 | case REVERB_PARAM_REFLECTIONS_DELAY: |
| 555 | *(uint32_t *)value = reverb_get_reflections_delay(reverb_ctxt); |
| 556 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 557 | case REVERB_PARAM_DIFFUSION: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 558 | *(int16_t *)value = reverb_get_diffusion(reverb_ctxt); |
| 559 | break; |
| 560 | case REVERB_PARAM_DENSITY: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 561 | *(int16_t *)value = reverb_get_density(reverb_ctxt); |
| 562 | break; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 563 | case REVERB_PARAM_PROPERTIES: |
| 564 | reverb_settings = (reverb_settings_t *)value; |
| 565 | reverb_settings->roomLevel = reverb_get_room_level(reverb_ctxt); |
| 566 | reverb_settings->roomHFLevel = reverb_get_room_hf_level(reverb_ctxt); |
| 567 | reverb_settings->decayTime = reverb_get_decay_time(reverb_ctxt); |
| 568 | reverb_settings->decayHFRatio = reverb_get_decay_hf_ratio(reverb_ctxt); |
| 569 | reverb_settings->reverbLevel = reverb_get_reverb_level(reverb_ctxt); |
| 570 | reverb_settings->reverbDelay = reverb_get_reverb_delay(reverb_ctxt); |
| 571 | reverb_settings->reflectionsLevel = reverb_get_reflections_level(reverb_ctxt); |
| 572 | reverb_settings->reflectionsDelay = reverb_get_reflections_delay(reverb_ctxt); |
| 573 | reverb_settings->diffusion = reverb_get_diffusion(reverb_ctxt); |
| 574 | reverb_settings->density = reverb_get_density(reverb_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 575 | break; |
| 576 | default: |
| 577 | p->status = -EINVAL; |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | int reverb_set_parameter(effect_context_t *context, effect_param_t *p, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 585 | uint32_t size __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 586 | { |
| 587 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 588 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 589 | void *value = p->data + voffset; |
| 590 | int32_t *param_tmp = (int32_t *)p->data; |
| 591 | int32_t param = *param_tmp++; |
| 592 | reverb_settings_t *reverb_settings; |
| 593 | int16_t level; |
| 594 | int16_t ratio; |
| 595 | uint32_t time; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 596 | uint32_t delay; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 597 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 598 | ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 599 | |
| 600 | p->status = 0; |
| 601 | |
| 602 | if (reverb_ctxt->preset) { |
| 603 | if (param != REVERB_PARAM_PRESET) |
| 604 | return -EINVAL; |
| 605 | uint16_t preset = *(uint16_t *)value; |
| 606 | ALOGV("set REVERB_PARAM_PRESET, preset %d", preset); |
| 607 | if (preset > REVERB_PRESET_LAST) { |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | reverb_set_preset(reverb_ctxt, preset); |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 611 | return 0; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 612 | } |
| 613 | switch (param) { |
| 614 | case REVERB_PARAM_PROPERTIES: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 615 | reverb_settings = (reverb_settings_t *)value; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 616 | reverb_set_all_properties(reverb_ctxt, reverb_settings); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 617 | break; |
| 618 | case REVERB_PARAM_ROOM_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 619 | level = *(int16_t *)value; |
| 620 | reverb_set_room_level(reverb_ctxt, level); |
| 621 | break; |
| 622 | case REVERB_PARAM_ROOM_HF_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 623 | level = *(int16_t *)value; |
| 624 | reverb_set_room_hf_level(reverb_ctxt, level); |
| 625 | break; |
| 626 | case REVERB_PARAM_DECAY_TIME: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 627 | time = *(uint32_t *)value; |
| 628 | reverb_set_decay_time(reverb_ctxt, time); |
| 629 | break; |
| 630 | case REVERB_PARAM_DECAY_HF_RATIO: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 631 | ratio = *(int16_t *)value; |
| 632 | reverb_set_decay_hf_ratio(reverb_ctxt, ratio); |
| 633 | break; |
| 634 | case REVERB_PARAM_REVERB_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 635 | level = *(int16_t *)value; |
| 636 | reverb_set_reverb_level(reverb_ctxt, level); |
| 637 | break; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 638 | case REVERB_PARAM_REVERB_DELAY: |
| 639 | delay = *(uint32_t *)value; |
| 640 | reverb_set_reverb_delay(reverb_ctxt, delay); |
| 641 | break; |
| 642 | case REVERB_PARAM_REFLECTIONS_LEVEL: |
| 643 | level = *(int16_t *)value; |
| 644 | reverb_set_reflections_level(reverb_ctxt, level); |
| 645 | break; |
| 646 | case REVERB_PARAM_REFLECTIONS_DELAY: |
| 647 | delay = *(uint32_t *)value; |
| 648 | reverb_set_reflections_delay(reverb_ctxt, delay); |
| 649 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 650 | case REVERB_PARAM_DIFFUSION: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 651 | ratio = *(int16_t *)value; |
| 652 | reverb_set_diffusion(reverb_ctxt, ratio); |
| 653 | break; |
| 654 | case REVERB_PARAM_DENSITY: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 655 | ratio = *(int16_t *)value; |
| 656 | reverb_set_density(reverb_ctxt, ratio); |
| 657 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 658 | default: |
| 659 | p->status = -EINVAL; |
| 660 | break; |
| 661 | } |
| 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | int reverb_set_device(effect_context_t *context, uint32_t device) |
| 667 | { |
| 668 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 669 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 670 | ALOGV("%s: ctxt %p, device: 0x%x", __func__, reverb_ctxt, device); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 671 | reverb_ctxt->device = device; |
| 672 | offload_reverb_set_device(&(reverb_ctxt->offload_reverb), device); |
| 673 | return 0; |
| 674 | } |
| 675 | |
| 676 | int reverb_reset(effect_context_t *context) |
| 677 | { |
| 678 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | int reverb_init(effect_context_t *context) |
| 684 | { |
| 685 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 686 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 687 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 688 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
| 689 | /* |
| 690 | FIXME: channel mode is mono for auxiliary. is it needed for offload ? |
| 691 | If so, this set config needs to be updated accordingly |
| 692 | */ |
| 693 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 694 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 695 | context->config.inputCfg.samplingRate = 44100; |
| 696 | context->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 697 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 698 | context->config.inputCfg.bufferProvider.cookie = NULL; |
| 699 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 700 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
| 701 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 702 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 703 | context->config.outputCfg.samplingRate = 44100; |
| 704 | context->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 705 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 706 | context->config.outputCfg.bufferProvider.cookie = NULL; |
| 707 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 708 | |
| 709 | set_config(context, &context->config); |
| 710 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 711 | reverb_ctxt->hw_acc_fd = -1; |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 712 | reverb_ctxt->enabled_by_client = false; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 713 | memset(&(reverb_ctxt->reverb_settings), 0, sizeof(reverb_settings_t)); |
| 714 | memset(&(reverb_ctxt->offload_reverb), 0, sizeof(struct reverb_params)); |
| 715 | |
| 716 | if (reverb_ctxt->preset && |
| 717 | reverb_ctxt->next_preset != reverb_ctxt->cur_preset) |
| 718 | reverb_load_preset(reverb_ctxt); |
| 719 | |
| 720 | return 0; |
| 721 | } |
| 722 | |
| 723 | int reverb_enable(effect_context_t *context) |
| 724 | { |
| 725 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 726 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 727 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 728 | reverb_ctxt->enabled_by_client = true; |
| 729 | |
| 730 | /* REVERB_PRESET_NONE is equivalent to disabled state, |
| 731 | * But support for this state is not provided in DSP. |
| 732 | * Hence, do not set enable flag, if in peset mode with preset "NONE". |
| 733 | * Effect would be enabled when valid preset is set. |
| 734 | */ |
| 735 | if ((reverb_ctxt->preset == true) && |
| 736 | (reverb_ctxt->next_preset == REVERB_PRESET_NONE)) |
| 737 | return 0; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 738 | |
| 739 | if (!offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) |
| 740 | offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), true); |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | int reverb_disable(effect_context_t *context) |
| 745 | { |
| 746 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 747 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 748 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 749 | reverb_ctxt->enabled_by_client = false; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 750 | if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) { |
| 751 | offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), false); |
| 752 | if (reverb_ctxt->ctl) |
| 753 | offload_reverb_send_params(reverb_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 754 | &reverb_ctxt->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 755 | OFFLOAD_SEND_REVERB_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 756 | if (reverb_ctxt->hw_acc_fd > 0) |
| 757 | hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd, |
| 758 | &reverb_ctxt->offload_reverb, |
| 759 | OFFLOAD_SEND_REVERB_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 760 | } |
| 761 | return 0; |
| 762 | } |
| 763 | |
| 764 | int reverb_start(effect_context_t *context, output_context_t *output) |
| 765 | { |
| 766 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 767 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 768 | ALOGV("%s: ctxt %p, ctl %p", __func__, reverb_ctxt, output->ctl); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 769 | reverb_ctxt->ctl = output->ctl; |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 770 | if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) { |
| 771 | if (reverb_ctxt->ctl && reverb_ctxt->preset) { |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 772 | offload_reverb_send_params(reverb_ctxt->ctl, &reverb_ctxt->offload_reverb, |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 773 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 774 | OFFLOAD_SEND_REVERB_PRESET); |
| 775 | } |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 776 | if ((reverb_ctxt->hw_acc_fd > 0) && reverb_ctxt->preset) { |
| 777 | hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd, |
| 778 | &reverb_ctxt->offload_reverb, |
| 779 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 780 | OFFLOAD_SEND_REVERB_PRESET); |
| 781 | } |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 782 | } |
| 783 | |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 784 | return 0; |
| 785 | } |
| 786 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 787 | int reverb_stop(effect_context_t *context, output_context_t *output __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 788 | { |
| 789 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 790 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 791 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 792 | if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb)) && |
| 793 | reverb_ctxt->ctl) { |
| 794 | struct reverb_params reverb; |
| 795 | reverb.enable_flag = false; |
| 796 | offload_reverb_send_params(reverb_ctxt->ctl, &reverb, |
| 797 | OFFLOAD_SEND_REVERB_ENABLE_FLAG); |
| 798 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 799 | reverb_ctxt->ctl = NULL; |
| 800 | return 0; |
| 801 | } |
| 802 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 803 | int reverb_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 804 | { |
| 805 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 806 | |
| 807 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
| 808 | reverb_ctxt->hw_acc_fd = hw_acc_fd; |
| 809 | if ((reverb_ctxt->hw_acc_fd > 0) && |
| 810 | (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb)))) |
| 811 | hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd, |
| 812 | &reverb_ctxt->offload_reverb, |
| 813 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 814 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
| 815 | return 0; |
| 816 | } |