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