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