Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 1 | /* |
Weiyin Jiang | 90ac1ea | 2017-04-13 14:18:23 +0800 | [diff] [blame] | 2 | * Copyright (c) 2013 - 2014, 2017, 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 | |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 33 | #define REVERB_MAX_LATENCY 100 |
| 34 | |
| 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; |
| 539 | default: |
| 540 | p->status = -EINVAL; |
| 541 | } |
| 542 | |
| 543 | *size = sizeof(effect_param_t) + voffset + p->vsize; |
| 544 | |
| 545 | if (p->status != 0) |
| 546 | return 0; |
| 547 | |
| 548 | switch (param) { |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 549 | case REVERB_PARAM_ROOM_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 550 | *(int16_t *)value = reverb_get_room_level(reverb_ctxt); |
| 551 | break; |
| 552 | case REVERB_PARAM_ROOM_HF_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 553 | *(int16_t *)value = reverb_get_room_hf_level(reverb_ctxt); |
| 554 | break; |
| 555 | case REVERB_PARAM_DECAY_TIME: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 556 | *(uint32_t *)value = reverb_get_decay_time(reverb_ctxt); |
| 557 | break; |
| 558 | case REVERB_PARAM_DECAY_HF_RATIO: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 559 | *(int16_t *)value = reverb_get_decay_hf_ratio(reverb_ctxt); |
| 560 | break; |
| 561 | case REVERB_PARAM_REVERB_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 562 | *(int16_t *)value = reverb_get_reverb_level(reverb_ctxt); |
| 563 | break; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 564 | case REVERB_PARAM_REVERB_DELAY: |
| 565 | *(uint32_t *)value = reverb_get_reverb_delay(reverb_ctxt); |
| 566 | break; |
| 567 | case REVERB_PARAM_REFLECTIONS_LEVEL: |
| 568 | *(int16_t *)value = reverb_get_reflections_level(reverb_ctxt); |
| 569 | break; |
| 570 | case REVERB_PARAM_REFLECTIONS_DELAY: |
| 571 | *(uint32_t *)value = reverb_get_reflections_delay(reverb_ctxt); |
| 572 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 573 | case REVERB_PARAM_DIFFUSION: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 574 | *(int16_t *)value = reverb_get_diffusion(reverb_ctxt); |
| 575 | break; |
| 576 | case REVERB_PARAM_DENSITY: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 577 | *(int16_t *)value = reverb_get_density(reverb_ctxt); |
| 578 | break; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 579 | case REVERB_PARAM_PROPERTIES: |
| 580 | reverb_settings = (reverb_settings_t *)value; |
| 581 | reverb_settings->roomLevel = reverb_get_room_level(reverb_ctxt); |
| 582 | reverb_settings->roomHFLevel = reverb_get_room_hf_level(reverb_ctxt); |
| 583 | reverb_settings->decayTime = reverb_get_decay_time(reverb_ctxt); |
| 584 | reverb_settings->decayHFRatio = reverb_get_decay_hf_ratio(reverb_ctxt); |
| 585 | reverb_settings->reverbLevel = reverb_get_reverb_level(reverb_ctxt); |
| 586 | reverb_settings->reverbDelay = reverb_get_reverb_delay(reverb_ctxt); |
| 587 | reverb_settings->reflectionsLevel = reverb_get_reflections_level(reverb_ctxt); |
| 588 | reverb_settings->reflectionsDelay = reverb_get_reflections_delay(reverb_ctxt); |
| 589 | reverb_settings->diffusion = reverb_get_diffusion(reverb_ctxt); |
| 590 | reverb_settings->density = reverb_get_density(reverb_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 591 | break; |
| 592 | default: |
| 593 | p->status = -EINVAL; |
| 594 | break; |
| 595 | } |
| 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | 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] | 601 | uint32_t size __unused) |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 602 | { |
| 603 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 604 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 605 | void *value = p->data + voffset; |
| 606 | int32_t *param_tmp = (int32_t *)p->data; |
| 607 | int32_t param = *param_tmp++; |
| 608 | reverb_settings_t *reverb_settings; |
| 609 | int16_t level; |
| 610 | int16_t ratio; |
| 611 | uint32_t time; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 612 | uint32_t delay; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 613 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 614 | ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 615 | |
| 616 | p->status = 0; |
| 617 | |
| 618 | if (reverb_ctxt->preset) { |
| 619 | if (param != REVERB_PARAM_PRESET) |
| 620 | return -EINVAL; |
| 621 | uint16_t preset = *(uint16_t *)value; |
| 622 | ALOGV("set REVERB_PARAM_PRESET, preset %d", preset); |
| 623 | if (preset > REVERB_PRESET_LAST) { |
| 624 | return -EINVAL; |
| 625 | } |
| 626 | reverb_set_preset(reverb_ctxt, preset); |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 627 | return 0; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 628 | } |
| 629 | switch (param) { |
| 630 | case REVERB_PARAM_PROPERTIES: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 631 | reverb_settings = (reverb_settings_t *)value; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 632 | reverb_set_all_properties(reverb_ctxt, reverb_settings); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 633 | break; |
| 634 | case REVERB_PARAM_ROOM_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 635 | level = *(int16_t *)value; |
| 636 | reverb_set_room_level(reverb_ctxt, level); |
| 637 | break; |
| 638 | case REVERB_PARAM_ROOM_HF_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 639 | level = *(int16_t *)value; |
| 640 | reverb_set_room_hf_level(reverb_ctxt, level); |
| 641 | break; |
| 642 | case REVERB_PARAM_DECAY_TIME: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 643 | time = *(uint32_t *)value; |
| 644 | reverb_set_decay_time(reverb_ctxt, time); |
| 645 | break; |
| 646 | case REVERB_PARAM_DECAY_HF_RATIO: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 647 | ratio = *(int16_t *)value; |
| 648 | reverb_set_decay_hf_ratio(reverb_ctxt, ratio); |
| 649 | break; |
| 650 | case REVERB_PARAM_REVERB_LEVEL: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 651 | level = *(int16_t *)value; |
| 652 | reverb_set_reverb_level(reverb_ctxt, level); |
| 653 | break; |
Weiyin Jiang | 6211dd0 | 2015-11-10 16:25:07 +0800 | [diff] [blame] | 654 | case REVERB_PARAM_REVERB_DELAY: |
| 655 | delay = *(uint32_t *)value; |
| 656 | reverb_set_reverb_delay(reverb_ctxt, delay); |
| 657 | break; |
| 658 | case REVERB_PARAM_REFLECTIONS_LEVEL: |
| 659 | level = *(int16_t *)value; |
| 660 | reverb_set_reflections_level(reverb_ctxt, level); |
| 661 | break; |
| 662 | case REVERB_PARAM_REFLECTIONS_DELAY: |
| 663 | delay = *(uint32_t *)value; |
| 664 | reverb_set_reflections_delay(reverb_ctxt, delay); |
| 665 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 666 | case REVERB_PARAM_DIFFUSION: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 667 | ratio = *(int16_t *)value; |
| 668 | reverb_set_diffusion(reverb_ctxt, ratio); |
| 669 | break; |
| 670 | case REVERB_PARAM_DENSITY: |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 671 | ratio = *(int16_t *)value; |
| 672 | reverb_set_density(reverb_ctxt, ratio); |
| 673 | break; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 674 | default: |
| 675 | p->status = -EINVAL; |
| 676 | break; |
| 677 | } |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | int reverb_set_device(effect_context_t *context, uint32_t device) |
| 683 | { |
| 684 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 685 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 686 | 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] | 687 | reverb_ctxt->device = device; |
| 688 | offload_reverb_set_device(&(reverb_ctxt->offload_reverb), device); |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | int reverb_reset(effect_context_t *context) |
| 693 | { |
| 694 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | int reverb_init(effect_context_t *context) |
| 700 | { |
| 701 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 702 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 703 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 704 | context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
| 705 | /* |
| 706 | FIXME: channel mode is mono for auxiliary. is it needed for offload ? |
| 707 | If so, this set config needs to be updated accordingly |
| 708 | */ |
| 709 | context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 710 | context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 711 | context->config.inputCfg.samplingRate = 44100; |
| 712 | context->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 713 | context->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 714 | context->config.inputCfg.bufferProvider.cookie = NULL; |
| 715 | context->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 716 | context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
| 717 | context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 718 | context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
| 719 | context->config.outputCfg.samplingRate = 44100; |
| 720 | context->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 721 | context->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 722 | context->config.outputCfg.bufferProvider.cookie = NULL; |
| 723 | context->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 724 | |
| 725 | set_config(context, &context->config); |
| 726 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 727 | reverb_ctxt->hw_acc_fd = -1; |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 728 | reverb_ctxt->enabled_by_client = false; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 729 | memset(&(reverb_ctxt->reverb_settings), 0, sizeof(reverb_settings_t)); |
| 730 | memset(&(reverb_ctxt->offload_reverb), 0, sizeof(struct reverb_params)); |
| 731 | |
| 732 | if (reverb_ctxt->preset && |
| 733 | reverb_ctxt->next_preset != reverb_ctxt->cur_preset) |
| 734 | reverb_load_preset(reverb_ctxt); |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 735 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | int reverb_enable(effect_context_t *context) |
| 740 | { |
| 741 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 742 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 743 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 744 | reverb_ctxt->enabled_by_client = true; |
| 745 | |
| 746 | /* REVERB_PRESET_NONE is equivalent to disabled state, |
| 747 | * But support for this state is not provided in DSP. |
| 748 | * Hence, do not set enable flag, if in peset mode with preset "NONE". |
| 749 | * Effect would be enabled when valid preset is set. |
| 750 | */ |
| 751 | if ((reverb_ctxt->preset == true) && |
| 752 | (reverb_ctxt->next_preset == REVERB_PRESET_NONE)) |
| 753 | return 0; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 754 | |
| 755 | if (!offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) |
| 756 | offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), true); |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 757 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
| 761 | int reverb_disable(effect_context_t *context) |
| 762 | { |
| 763 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 764 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 765 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
Dhananjay Kumar | 3fa6a00 | 2015-07-14 18:58:18 +0530 | [diff] [blame] | 766 | reverb_ctxt->enabled_by_client = false; |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 767 | if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) { |
| 768 | offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), false); |
| 769 | if (reverb_ctxt->ctl) |
| 770 | offload_reverb_send_params(reverb_ctxt->ctl, |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 771 | &reverb_ctxt->offload_reverb, |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 772 | OFFLOAD_SEND_REVERB_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 773 | if (reverb_ctxt->hw_acc_fd > 0) |
| 774 | hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd, |
| 775 | &reverb_ctxt->offload_reverb, |
| 776 | OFFLOAD_SEND_REVERB_ENABLE_FLAG); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 777 | } |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 778 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | int reverb_start(effect_context_t *context, output_context_t *output) |
| 783 | { |
| 784 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 785 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 786 | 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] | 787 | reverb_ctxt->ctl = output->ctl; |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 788 | if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) { |
| 789 | if (reverb_ctxt->ctl && reverb_ctxt->preset) { |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 790 | offload_reverb_send_params(reverb_ctxt->ctl, &reverb_ctxt->offload_reverb, |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 791 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 792 | OFFLOAD_SEND_REVERB_PRESET); |
| 793 | } |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 794 | if ((reverb_ctxt->hw_acc_fd > 0) && reverb_ctxt->preset) { |
| 795 | hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd, |
| 796 | &reverb_ctxt->offload_reverb, |
| 797 | OFFLOAD_SEND_REVERB_ENABLE_FLAG | |
| 798 | OFFLOAD_SEND_REVERB_PRESET); |
| 799 | } |
wjiang | c37c260 | 2014-03-24 23:43:09 +0800 | [diff] [blame] | 800 | } |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 801 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 802 | return 0; |
| 803 | } |
| 804 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 805 | 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] | 806 | { |
| 807 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 808 | |
Dhananjay Kumar | 574f392 | 2014-03-25 17:41:44 +0530 | [diff] [blame] | 809 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 810 | if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb)) && |
| 811 | reverb_ctxt->ctl) { |
| 812 | struct reverb_params reverb; |
| 813 | reverb.enable_flag = false; |
| 814 | offload_reverb_send_params(reverb_ctxt->ctl, &reverb, |
| 815 | OFFLOAD_SEND_REVERB_ENABLE_FLAG); |
| 816 | } |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 817 | reverb_ctxt->ctl = NULL; |
Vatsal Bucha | a135899 | 2018-11-14 13:25:08 +0530 | [diff] [blame] | 818 | enable_gcov(); |
Subhash Chandra Bose Naripeddy | 3eedc00 | 2013-11-12 20:45:15 -0800 | [diff] [blame] | 819 | return 0; |
| 820 | } |
| 821 | |
Subhash Chandra Bose Naripeddy | e40a7cd | 2014-06-03 19:42:41 -0700 | [diff] [blame] | 822 | int reverb_set_mode(effect_context_t *context, int32_t hw_acc_fd) |
| 823 | { |
| 824 | reverb_context_t *reverb_ctxt = (reverb_context_t *)context; |
| 825 | |
| 826 | ALOGV("%s: ctxt %p", __func__, reverb_ctxt); |
| 827 | reverb_ctxt->hw_acc_fd = hw_acc_fd; |
| 828 | if ((reverb_ctxt->hw_acc_fd > 0) && |
| 829 | (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb)))) |
| 830 | hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd, |
| 831 | &reverb_ctxt->offload_reverb, |
| 832 | OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG | |
| 833 | OFFLOAD_SEND_BASSBOOST_STRENGTH); |
| 834 | return 0; |
| 835 | } |