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