Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010-2010 NXP Software |
| 3 | * Copyright (C) 2009 The Android Open Source Project |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "Reverb" |
| 19 | #define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 20 | //#define LOG_NDEBUG 0 |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 21 | |
| 22 | #include <cutils/log.h> |
| 23 | #include <assert.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <new> |
| 27 | #include <EffectReverb.h> |
| 28 | #include <LVREV.h> |
| 29 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 30 | // effect_handle_t interface implementation for reverb |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 31 | extern "C" const struct effect_interface_s gReverbInterface; |
| 32 | |
| 33 | #define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\ |
| 34 | if (LvmStatus == LVREV_NULLADDRESS){\ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 35 | ALOGV("\tLVREV_ERROR : Parameter error - "\ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 36 | "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\ |
| 37 | }\ |
| 38 | if (LvmStatus == LVREV_INVALIDNUMSAMPLES){\ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 39 | ALOGV("\tLVREV_ERROR : Parameter error - "\ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 40 | "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\ |
| 41 | }\ |
| 42 | if (LvmStatus == LVREV_OUTOFRANGE){\ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 43 | ALOGV("\tLVREV_ERROR : Parameter error - "\ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 44 | "out of range returned by %s in %s\n", callingFunc, calledFunc);\ |
| 45 | }\ |
| 46 | } |
| 47 | |
| 48 | // Namespaces |
| 49 | namespace android { |
| 50 | namespace { |
| 51 | |
| 52 | /************************************************************************************/ |
| 53 | /* */ |
| 54 | /* Preset definitions */ |
| 55 | /* */ |
| 56 | /************************************************************************************/ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 57 | |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 58 | const static t_reverb_settings sReverbPresets[] = { |
| 59 | // REVERB_PRESET_NONE: values are unused |
| 60 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, |
| 61 | // REVERB_PRESET_SMALLROOM |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 62 | {-400, -600, 1100, 830, -400, 5, 500, 10, 1000, 1000}, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 63 | // REVERB_PRESET_MEDIUMROOM |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 64 | {-400, -600, 1300, 830, -1000, 20, -200, 20, 1000, 1000}, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 65 | // REVERB_PRESET_LARGEROOM |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 66 | {-400, -600, 1500, 830, -1600, 5, -1000, 40, 1000, 1000}, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 67 | // REVERB_PRESET_MEDIUMHALL |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 68 | {-400, -600, 1800, 700, -1300, 15, -800, 30, 1000, 1000}, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 69 | // REVERB_PRESET_LARGEHALL |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 70 | {-400, -600, 1800, 700, -2000, 30, -1400, 60, 1000, 1000}, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 71 | // REVERB_PRESET_PLATE |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 72 | {-400, -200, 1300, 900, 0, 2, 0, 10, 1000, 750}, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 73 | }; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 74 | |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 75 | |
| 76 | // NXP SW auxiliary environmental reverb |
| 77 | const effect_descriptor_t gAuxEnvReverbDescriptor = { |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 78 | { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e } }, |
| 79 | { 0x4a387fc0, 0x8ab3, 0x11df, 0x8bad, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } }, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 80 | EFFECT_CONTROL_API_VERSION, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 81 | EFFECT_FLAG_TYPE_AUXILIARY, |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 82 | LVREV_CUP_LOAD_ARM9E, |
| 83 | LVREV_MEM_USAGE, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 84 | "Auxiliary Environmental Reverb", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 85 | "NXP Software Ltd.", |
| 86 | }; |
| 87 | |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 88 | // NXP SW insert environmental reverb |
| 89 | static const effect_descriptor_t gInsertEnvReverbDescriptor = { |
| 90 | {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}}, |
| 91 | {0xc7a511a0, 0xa3bb, 0x11df, 0x860e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 92 | EFFECT_CONTROL_API_VERSION, |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 93 | EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_VOLUME_CTRL, |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 94 | LVREV_CUP_LOAD_ARM9E, |
| 95 | LVREV_MEM_USAGE, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 96 | "Insert Environmental Reverb", |
| 97 | "NXP Software Ltd.", |
| 98 | }; |
| 99 | |
| 100 | // NXP SW auxiliary preset reverb |
| 101 | static const effect_descriptor_t gAuxPresetReverbDescriptor = { |
| 102 | {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 103 | {0xf29a1400, 0xa3bb, 0x11df, 0x8ddc, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 104 | EFFECT_CONTROL_API_VERSION, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 105 | EFFECT_FLAG_TYPE_AUXILIARY, |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 106 | LVREV_CUP_LOAD_ARM9E, |
| 107 | LVREV_MEM_USAGE, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 108 | "Auxiliary Preset Reverb", |
| 109 | "NXP Software Ltd.", |
| 110 | }; |
| 111 | |
| 112 | // NXP SW insert preset reverb |
| 113 | static const effect_descriptor_t gInsertPresetReverbDescriptor = { |
| 114 | {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 115 | {0x172cdf00, 0xa3bc, 0x11df, 0xa72f, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 116 | EFFECT_CONTROL_API_VERSION, |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 117 | EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_VOLUME_CTRL, |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 118 | LVREV_CUP_LOAD_ARM9E, |
| 119 | LVREV_MEM_USAGE, |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 120 | "Insert Preset Reverb", |
| 121 | "NXP Software Ltd.", |
| 122 | }; |
| 123 | |
| 124 | // gDescriptors contains pointers to all defined effect descriptor in this library |
| 125 | static const effect_descriptor_t * const gDescriptors[] = { |
| 126 | &gAuxEnvReverbDescriptor, |
| 127 | &gInsertEnvReverbDescriptor, |
| 128 | &gAuxPresetReverbDescriptor, |
| 129 | &gInsertPresetReverbDescriptor |
| 130 | }; |
| 131 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 132 | struct ReverbContext{ |
| 133 | const struct effect_interface_s *itfe; |
| 134 | effect_config_t config; |
| 135 | LVREV_Handle_t hInstance; |
| 136 | int16_t SavedRoomLevel; |
| 137 | int16_t SavedHfLevel; |
| 138 | int16_t SavedDecayTime; |
| 139 | int16_t SavedDecayHfRatio; |
| 140 | int16_t SavedReverbLevel; |
| 141 | int16_t SavedDiffusion; |
| 142 | int16_t SavedDensity; |
| 143 | bool bEnabled; |
| 144 | #ifdef LVM_PCM |
| 145 | FILE *PcmInPtr; |
| 146 | FILE *PcmOutPtr; |
| 147 | #endif |
| 148 | LVM_Fs_en SampleRate; |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 149 | LVM_INT32 *InFrames32; |
| 150 | LVM_INT32 *OutFrames32; |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 151 | bool auxiliary; |
| 152 | bool preset; |
| 153 | uint16_t curPreset; |
| 154 | uint16_t nextPreset; |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 155 | int SamplesToExitCount; |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 156 | LVM_INT16 leftVolume; |
| 157 | LVM_INT16 rightVolume; |
| 158 | LVM_INT16 prevLeftVolume; |
| 159 | LVM_INT16 prevRightVolume; |
| 160 | int volumeMode; |
| 161 | }; |
| 162 | |
| 163 | enum { |
| 164 | REVERB_VOLUME_OFF, |
| 165 | REVERB_VOLUME_FLAT, |
| 166 | REVERB_VOLUME_RAMP, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
Glenn Kasten | 161fb37 | 2011-01-25 10:53:40 -0800 | [diff] [blame] | 169 | #define REVERB_DEFAULT_PRESET REVERB_PRESET_NONE |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 170 | |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 171 | |
| 172 | #define REVERB_SEND_LEVEL (0x0C00) // 0.75 in 4.12 format |
| 173 | #define REVERB_UNIT_VOLUME (0x1000) // 1.0 in 4.12 format |
| 174 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 175 | //--- local function prototypes |
| 176 | int Reverb_init (ReverbContext *pContext); |
| 177 | void Reverb_free (ReverbContext *pContext); |
| 178 | int Reverb_configure (ReverbContext *pContext, effect_config_t *pConfig); |
| 179 | int Reverb_setParameter (ReverbContext *pContext, void *pParam, void *pValue); |
| 180 | int Reverb_getParameter (ReverbContext *pContext, |
| 181 | void *pParam, |
| 182 | size_t *pValueSize, |
| 183 | void *pValue); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 184 | int Reverb_LoadPreset (ReverbContext *pContext); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 185 | |
| 186 | /* Effect Library Interface Implementation */ |
| 187 | extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 188 | ALOGV("\n\tEffectQueryNumberEffects start"); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 189 | *pNumEffects = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 190 | ALOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects); |
| 191 | ALOGV("\tEffectQueryNumberEffects end\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 192 | return 0; |
| 193 | } /* end EffectQueryNumberEffects */ |
| 194 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 195 | extern "C" int EffectQueryEffect(uint32_t index, |
| 196 | effect_descriptor_t *pDescriptor){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 197 | ALOGV("\n\tEffectQueryEffect start"); |
| 198 | ALOGV("\tEffectQueryEffect processing index %d", index); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 199 | if (pDescriptor == NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 200 | ALOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 201 | return -EINVAL; |
| 202 | } |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 203 | if (index >= sizeof(gDescriptors) / sizeof(const effect_descriptor_t *)) { |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 204 | ALOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 205 | return -ENOENT; |
| 206 | } |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 207 | memcpy(pDescriptor, gDescriptors[index], sizeof(effect_descriptor_t)); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 208 | ALOGV("\tEffectQueryEffect end\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 209 | return 0; |
| 210 | } /* end EffectQueryEffect */ |
| 211 | |
| 212 | extern "C" int EffectCreate(effect_uuid_t *uuid, |
| 213 | int32_t sessionId, |
| 214 | int32_t ioId, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 215 | effect_handle_t *pHandle){ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 216 | int ret; |
| 217 | int i; |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 218 | int length = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *); |
| 219 | const effect_descriptor_t *desc; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 220 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 221 | ALOGV("\t\nEffectCreate start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 222 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 223 | if (pHandle == NULL || uuid == NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 224 | ALOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 225 | return -EINVAL; |
| 226 | } |
| 227 | |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 228 | for (i = 0; i < length; i++) { |
| 229 | desc = gDescriptors[i]; |
| 230 | if (memcmp(uuid, &desc->uuid, sizeof(effect_uuid_t)) |
| 231 | == 0) { |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 232 | ALOGV("\tEffectCreate - UUID matched Reverb type %d, UUID = %x", i, desc->uuid.timeLow); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 233 | break; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | if (i == length) { |
| 238 | return -ENOENT; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | ReverbContext *pContext = new ReverbContext; |
| 242 | |
| 243 | pContext->itfe = &gReverbInterface; |
| 244 | pContext->hInstance = NULL; |
| 245 | |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 246 | pContext->auxiliary = false; |
| 247 | if ((desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY){ |
| 248 | pContext->auxiliary = true; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 249 | ALOGV("\tEffectCreate - AUX"); |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 250 | }else{ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 251 | ALOGV("\tEffectCreate - INS"); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | pContext->preset = false; |
| 255 | if (memcmp(&desc->type, SL_IID_PRESETREVERB, sizeof(effect_uuid_t)) == 0) { |
| 256 | pContext->preset = true; |
| 257 | // force reloading preset at first call to process() |
| 258 | pContext->curPreset = REVERB_PRESET_LAST + 1; |
| 259 | pContext->nextPreset = REVERB_DEFAULT_PRESET; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 260 | ALOGV("\tEffectCreate - PRESET"); |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 261 | }else{ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 262 | ALOGV("\tEffectCreate - ENVIRONMENTAL"); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 265 | ALOGV("\tEffectCreate - Calling Reverb_init"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 266 | ret = Reverb_init(pContext); |
| 267 | |
| 268 | if (ret < 0){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 269 | ALOGV("\tLVM_ERROR : EffectCreate() init failed"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 270 | delete pContext; |
| 271 | return ret; |
| 272 | } |
| 273 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 274 | *pHandle = (effect_handle_t)pContext; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 275 | |
| 276 | #ifdef LVM_PCM |
| 277 | pContext->PcmInPtr = NULL; |
| 278 | pContext->PcmOutPtr = NULL; |
| 279 | |
| 280 | pContext->PcmInPtr = fopen("/data/tmp/reverb_pcm_in.pcm", "w"); |
| 281 | pContext->PcmOutPtr = fopen("/data/tmp/reverb_pcm_out.pcm", "w"); |
| 282 | |
| 283 | if((pContext->PcmInPtr == NULL)|| |
| 284 | (pContext->PcmOutPtr == NULL)){ |
| 285 | return -EINVAL; |
| 286 | } |
| 287 | #endif |
| 288 | |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 289 | |
| 290 | // Allocate memory for reverb process (*2 is for STEREO) |
| 291 | pContext->InFrames32 = (LVM_INT32 *)malloc(LVREV_MAX_FRAME_SIZE * sizeof(LVM_INT32) * 2); |
| 292 | pContext->OutFrames32 = (LVM_INT32 *)malloc(LVREV_MAX_FRAME_SIZE * sizeof(LVM_INT32) * 2); |
| 293 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 294 | ALOGV("\tEffectCreate %p, size %d", pContext, sizeof(ReverbContext)); |
| 295 | ALOGV("\tEffectCreate end\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 296 | return 0; |
| 297 | } /* end EffectCreate */ |
| 298 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 299 | extern "C" int EffectRelease(effect_handle_t handle){ |
| 300 | ReverbContext * pContext = (ReverbContext *)handle; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 301 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 302 | ALOGV("\tEffectRelease %p", handle); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 303 | if (pContext == NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 304 | ALOGV("\tLVM_ERROR : EffectRelease called with NULL pointer"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 305 | return -EINVAL; |
| 306 | } |
| 307 | |
| 308 | #ifdef LVM_PCM |
| 309 | fclose(pContext->PcmInPtr); |
| 310 | fclose(pContext->PcmOutPtr); |
| 311 | #endif |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 312 | free(pContext->InFrames32); |
| 313 | free(pContext->OutFrames32); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 314 | Reverb_free(pContext); |
| 315 | delete pContext; |
| 316 | return 0; |
| 317 | } /* end EffectRelease */ |
| 318 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 319 | extern "C" int EffectGetDescriptor(effect_uuid_t *uuid, |
| 320 | effect_descriptor_t *pDescriptor) { |
| 321 | int i; |
| 322 | int length = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *); |
| 323 | |
| 324 | if (pDescriptor == NULL || uuid == NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 325 | ALOGV("EffectGetDescriptor() called with NULL pointer"); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 326 | return -EINVAL; |
| 327 | } |
| 328 | |
| 329 | for (i = 0; i < length; i++) { |
| 330 | if (memcmp(uuid, &gDescriptors[i]->uuid, sizeof(effect_uuid_t)) == 0) { |
| 331 | memcpy(pDescriptor, gDescriptors[i], sizeof(effect_descriptor_t)); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 332 | ALOGV("EffectGetDescriptor - UUID matched Reverb type %d, UUID = %x", |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 333 | i, gDescriptors[i]->uuid.timeLow); |
| 334 | return 0; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | return -EINVAL; |
| 339 | } /* end EffectGetDescriptor */ |
| 340 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 341 | /* local functions */ |
| 342 | #define CHECK_ARG(cond) { \ |
| 343 | if (!(cond)) { \ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 344 | ALOGV("\tLVM_ERROR : Invalid argument: "#cond); \ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 345 | return -EINVAL; \ |
| 346 | } \ |
| 347 | } |
| 348 | |
| 349 | //---------------------------------------------------------------------------- |
| 350 | // MonoTo2I_32() |
| 351 | //---------------------------------------------------------------------------- |
| 352 | // Purpose: |
| 353 | // Convert MONO to STEREO |
| 354 | // |
| 355 | //---------------------------------------------------------------------------- |
| 356 | |
| 357 | void MonoTo2I_32( const LVM_INT32 *src, |
| 358 | LVM_INT32 *dst, |
| 359 | LVM_INT16 n) |
| 360 | { |
| 361 | LVM_INT16 ii; |
| 362 | src += (n-1); |
| 363 | dst += ((n*2)-1); |
| 364 | |
| 365 | for (ii = n; ii != 0; ii--) |
| 366 | { |
| 367 | *dst = *src; |
| 368 | dst--; |
| 369 | |
| 370 | *dst = *src; |
| 371 | dst--; |
| 372 | src--; |
| 373 | } |
| 374 | |
| 375 | return; |
| 376 | } |
| 377 | |
| 378 | //---------------------------------------------------------------------------- |
| 379 | // From2iToMono_32() |
| 380 | //---------------------------------------------------------------------------- |
| 381 | // Purpose: |
| 382 | // Convert STEREO to MONO |
| 383 | // |
| 384 | //---------------------------------------------------------------------------- |
| 385 | |
| 386 | void From2iToMono_32( const LVM_INT32 *src, |
| 387 | LVM_INT32 *dst, |
| 388 | LVM_INT16 n) |
| 389 | { |
| 390 | LVM_INT16 ii; |
| 391 | LVM_INT32 Temp; |
| 392 | |
| 393 | for (ii = n; ii != 0; ii--) |
| 394 | { |
| 395 | Temp = (*src>>1); |
| 396 | src++; |
| 397 | |
| 398 | Temp +=(*src>>1); |
| 399 | src++; |
| 400 | |
| 401 | *dst = Temp; |
| 402 | dst++; |
| 403 | } |
| 404 | |
| 405 | return; |
| 406 | } |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 407 | |
| 408 | static inline int16_t clamp16(int32_t sample) |
| 409 | { |
| 410 | if ((sample>>15) ^ (sample>>31)) |
| 411 | sample = 0x7FFF ^ (sample>>31); |
| 412 | return sample; |
| 413 | } |
| 414 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 415 | //---------------------------------------------------------------------------- |
| 416 | // process() |
| 417 | //---------------------------------------------------------------------------- |
| 418 | // Purpose: |
| 419 | // Apply the Reverb |
| 420 | // |
| 421 | // Inputs: |
| 422 | // pIn: pointer to stereo/mono 16 bit input data |
| 423 | // pOut: pointer to stereo 16 bit output data |
| 424 | // frameCount: Frames to process |
| 425 | // pContext: effect engine context |
| 426 | // strength strength to be applied |
| 427 | // |
| 428 | // Outputs: |
| 429 | // pOut: pointer to updated stereo 16 bit output data |
| 430 | // |
| 431 | //---------------------------------------------------------------------------- |
| 432 | |
| 433 | int process( LVM_INT16 *pIn, |
| 434 | LVM_INT16 *pOut, |
| 435 | int frameCount, |
| 436 | ReverbContext *pContext){ |
| 437 | |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 438 | LVM_INT16 samplesPerFrame = 1; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 439 | LVREV_ReturnStatus_en LvmStatus = LVREV_SUCCESS; /* Function call status */ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 440 | LVM_INT16 *OutFrames16; |
| 441 | |
| 442 | |
| 443 | // Check that the input is either mono or stereo |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 444 | if (pContext->config.inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO) { |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 445 | samplesPerFrame = 2; |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 446 | } else if (pContext->config.inputCfg.channels != AUDIO_CHANNEL_OUT_MONO) { |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 447 | ALOGV("\tLVREV_ERROR : process invalid PCM format"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 448 | return -EINVAL; |
| 449 | } |
| 450 | |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 451 | OutFrames16 = (LVM_INT16 *)pContext->OutFrames32; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 452 | |
| 453 | // Check for NULL pointers |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 454 | if((pContext->InFrames32 == NULL)||(pContext->OutFrames32 == NULL)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 455 | ALOGV("\tLVREV_ERROR : process failed to allocate memory for temporary buffers "); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 456 | return -EINVAL; |
| 457 | } |
| 458 | |
| 459 | #ifdef LVM_PCM |
| 460 | fwrite(pIn, frameCount*sizeof(LVM_INT16)*samplesPerFrame, 1, pContext->PcmInPtr); |
| 461 | fflush(pContext->PcmInPtr); |
| 462 | #endif |
| 463 | |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 464 | if (pContext->preset && pContext->nextPreset != pContext->curPreset) { |
| 465 | Reverb_LoadPreset(pContext); |
| 466 | } |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 467 | |
| 468 | |
| 469 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 470 | // Convert to Input 32 bits |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 471 | if (pContext->auxiliary) { |
| 472 | for(int i=0; i<frameCount*samplesPerFrame; i++){ |
| 473 | pContext->InFrames32[i] = (LVM_INT32)pIn[i]<<8; |
| 474 | } |
| 475 | } else { |
| 476 | // insert reverb input is always stereo |
| 477 | for (int i = 0; i < frameCount; i++) { |
| 478 | pContext->InFrames32[2*i] = (pIn[2*i] * REVERB_SEND_LEVEL) >> 4; // <<8 + >>12 |
| 479 | pContext->InFrames32[2*i+1] = (pIn[2*i+1] * REVERB_SEND_LEVEL) >> 4; // <<8 + >>12 |
| 480 | } |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 483 | if (pContext->preset && pContext->curPreset == REVERB_PRESET_NONE) { |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 484 | memset(pContext->OutFrames32, 0, frameCount * sizeof(LVM_INT32) * 2); //always stereo here |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 485 | } else { |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 486 | if(pContext->bEnabled == LVM_FALSE && pContext->SamplesToExitCount > 0) { |
Eric Laurent | 305443c | 2010-09-09 12:01:11 -0700 | [diff] [blame] | 487 | memset(pContext->InFrames32,0,frameCount * sizeof(LVM_INT32) * samplesPerFrame); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 488 | ALOGV("\tZeroing %d samples per frame at the end of call", samplesPerFrame); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 489 | } |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 490 | |
Eric Laurent | 305443c | 2010-09-09 12:01:11 -0700 | [diff] [blame] | 491 | /* Process the samples, producing a stereo output */ |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 492 | LvmStatus = LVREV_Process(pContext->hInstance, /* Instance handle */ |
| 493 | pContext->InFrames32, /* Input buffer */ |
| 494 | pContext->OutFrames32, /* Output buffer */ |
| 495 | frameCount); /* Number of samples to read */ |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 496 | } |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 497 | |
| 498 | LVM_ERROR_CHECK(LvmStatus, "LVREV_Process", "process") |
| 499 | if(LvmStatus != LVREV_SUCCESS) return -EINVAL; |
| 500 | |
| 501 | // Convert to 16 bits |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 502 | if (pContext->auxiliary) { |
| 503 | for (int i=0; i < frameCount*2; i++) { //always stereo here |
| 504 | OutFrames16[i] = clamp16(pContext->OutFrames32[i]>>8); |
| 505 | } |
| 506 | } else { |
| 507 | for (int i=0; i < frameCount*2; i++) { //always stereo here |
| 508 | OutFrames16[i] = clamp16((pContext->OutFrames32[i]>>8) + (LVM_INT32)pIn[i]); |
| 509 | } |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 510 | |
| 511 | // apply volume with ramp if needed |
| 512 | if ((pContext->leftVolume != pContext->prevLeftVolume || |
| 513 | pContext->rightVolume != pContext->prevRightVolume) && |
| 514 | pContext->volumeMode == REVERB_VOLUME_RAMP) { |
| 515 | LVM_INT32 vl = (LVM_INT32)pContext->prevLeftVolume << 16; |
| 516 | LVM_INT32 incl = (((LVM_INT32)pContext->leftVolume << 16) - vl) / frameCount; |
| 517 | LVM_INT32 vr = (LVM_INT32)pContext->prevRightVolume << 16; |
| 518 | LVM_INT32 incr = (((LVM_INT32)pContext->rightVolume << 16) - vr) / frameCount; |
| 519 | |
| 520 | for (int i = 0; i < frameCount; i++) { |
| 521 | OutFrames16[2*i] = |
| 522 | clamp16((LVM_INT32)((vl >> 16) * OutFrames16[2*i]) >> 12); |
| 523 | OutFrames16[2*i+1] = |
| 524 | clamp16((LVM_INT32)((vr >> 16) * OutFrames16[2*i+1]) >> 12); |
| 525 | |
| 526 | vl += incl; |
| 527 | vr += incr; |
| 528 | } |
| 529 | |
| 530 | pContext->prevLeftVolume = pContext->leftVolume; |
| 531 | pContext->prevRightVolume = pContext->rightVolume; |
| 532 | } else if (pContext->volumeMode != REVERB_VOLUME_OFF) { |
| 533 | if (pContext->leftVolume != REVERB_UNIT_VOLUME || |
| 534 | pContext->rightVolume != REVERB_UNIT_VOLUME) { |
| 535 | for (int i = 0; i < frameCount; i++) { |
| 536 | OutFrames16[2*i] = |
| 537 | clamp16((LVM_INT32)(pContext->leftVolume * OutFrames16[2*i]) >> 12); |
| 538 | OutFrames16[2*i+1] = |
| 539 | clamp16((LVM_INT32)(pContext->rightVolume * OutFrames16[2*i+1]) >> 12); |
| 540 | } |
| 541 | } |
| 542 | pContext->prevLeftVolume = pContext->leftVolume; |
| 543 | pContext->prevRightVolume = pContext->rightVolume; |
| 544 | pContext->volumeMode = REVERB_VOLUME_RAMP; |
| 545 | } |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | #ifdef LVM_PCM |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 549 | fwrite(OutFrames16, frameCount*sizeof(LVM_INT16)*2, 1, pContext->PcmOutPtr); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 550 | fflush(pContext->PcmOutPtr); |
| 551 | #endif |
| 552 | |
| 553 | // Accumulate if required |
| 554 | if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 555 | //ALOGV("\tBuffer access is ACCUMULATE"); |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 556 | for (int i=0; i<frameCount*2; i++){ //always stereo here |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 557 | pOut[i] = clamp16((int32_t)pOut[i] + (int32_t)OutFrames16[i]); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 558 | } |
| 559 | }else{ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 560 | //ALOGV("\tBuffer access is WRITE"); |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 561 | memcpy(pOut, OutFrames16, frameCount*sizeof(LVM_INT16)*2); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 564 | return 0; |
| 565 | } /* end process */ |
| 566 | |
| 567 | //---------------------------------------------------------------------------- |
| 568 | // Reverb_free() |
| 569 | //---------------------------------------------------------------------------- |
| 570 | // Purpose: Free all memory associated with the Bundle. |
| 571 | // |
| 572 | // Inputs: |
| 573 | // pContext: effect engine context |
| 574 | // |
| 575 | // Outputs: |
| 576 | // |
| 577 | //---------------------------------------------------------------------------- |
| 578 | |
| 579 | void Reverb_free(ReverbContext *pContext){ |
| 580 | |
| 581 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 582 | LVREV_ControlParams_st params; /* Control Parameters */ |
| 583 | LVREV_MemoryTable_st MemTab; |
| 584 | |
| 585 | /* Free the algorithm memory */ |
| 586 | LvmStatus = LVREV_GetMemoryTable(pContext->hInstance, |
| 587 | &MemTab, |
| 588 | LVM_NULL); |
| 589 | |
| 590 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "Reverb_free") |
| 591 | |
| 592 | for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){ |
| 593 | if (MemTab.Region[i].Size != 0){ |
| 594 | if (MemTab.Region[i].pBaseAddress != NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 595 | ALOGV("\tfree() - START freeing %ld bytes for region %u at %p\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 596 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
| 597 | |
| 598 | free(MemTab.Region[i].pBaseAddress); |
| 599 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 600 | ALOGV("\tfree() - END freeing %ld bytes for region %u at %p\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 601 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
| 602 | }else{ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 603 | ALOGV("\tLVM_ERROR : free() - trying to free with NULL pointer %ld bytes " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 604 | "for region %u at %p ERROR\n", |
| 605 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | } /* end Reverb_free */ |
| 610 | |
| 611 | //---------------------------------------------------------------------------- |
| 612 | // Reverb_configure() |
| 613 | //---------------------------------------------------------------------------- |
| 614 | // Purpose: Set input and output audio configuration. |
| 615 | // |
| 616 | // Inputs: |
| 617 | // pContext: effect engine context |
| 618 | // pConfig: pointer to effect_config_t structure holding input and output |
| 619 | // configuration parameters |
| 620 | // |
| 621 | // Outputs: |
| 622 | // |
| 623 | //---------------------------------------------------------------------------- |
| 624 | |
| 625 | int Reverb_configure(ReverbContext *pContext, effect_config_t *pConfig){ |
| 626 | LVM_Fs_en SampleRate; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 627 | //ALOGV("\tReverb_configure start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 628 | |
| 629 | CHECK_ARG(pContext != NULL); |
| 630 | CHECK_ARG(pConfig != NULL); |
| 631 | |
| 632 | CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate); |
| 633 | CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 634 | CHECK_ARG((pContext->auxiliary && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_MONO) || |
| 635 | ((!pContext->auxiliary) && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO)); |
| 636 | CHECK_ARG(pConfig->outputCfg.channels == AUDIO_CHANNEL_OUT_STEREO); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 637 | CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE |
| 638 | || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 639 | CHECK_ARG(pConfig->inputCfg.format == AUDIO_FORMAT_PCM_16_BIT); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 640 | |
| 641 | if(pConfig->inputCfg.samplingRate != 44100){ |
| 642 | return -EINVAL; |
| 643 | } |
| 644 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 645 | //ALOGV("\tReverb_configure calling memcpy"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 646 | memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); |
| 647 | |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 648 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 649 | switch (pConfig->inputCfg.samplingRate) { |
| 650 | case 8000: |
| 651 | SampleRate = LVM_FS_8000; |
| 652 | break; |
| 653 | case 16000: |
| 654 | SampleRate = LVM_FS_16000; |
| 655 | break; |
| 656 | case 22050: |
| 657 | SampleRate = LVM_FS_22050; |
| 658 | break; |
| 659 | case 32000: |
| 660 | SampleRate = LVM_FS_32000; |
| 661 | break; |
| 662 | case 44100: |
| 663 | SampleRate = LVM_FS_44100; |
| 664 | break; |
| 665 | case 48000: |
| 666 | SampleRate = LVM_FS_48000; |
| 667 | break; |
| 668 | default: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 669 | ALOGV("\rReverb_Configure invalid sampling rate %d", pConfig->inputCfg.samplingRate); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 670 | return -EINVAL; |
| 671 | } |
| 672 | |
| 673 | if(pContext->SampleRate != SampleRate){ |
| 674 | |
| 675 | LVREV_ControlParams_st ActiveParams; |
| 676 | LVREV_ReturnStatus_en LvmStatus = LVREV_SUCCESS; |
| 677 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 678 | //ALOGV("\tReverb_configure change sampling rate to %d", SampleRate); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 679 | |
| 680 | /* Get the current settings */ |
| 681 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, |
| 682 | &ActiveParams); |
| 683 | |
| 684 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "Reverb_configure") |
| 685 | if(LvmStatus != LVREV_SUCCESS) return -EINVAL; |
| 686 | |
| 687 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams); |
| 688 | |
| 689 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "Reverb_configure") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 690 | //ALOGV("\tReverb_configure Succesfully called LVREV_SetControlParameters\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 691 | |
| 692 | }else{ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 693 | //ALOGV("\tReverb_configure keep sampling rate at %d", SampleRate); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 694 | } |
| 695 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 696 | //ALOGV("\tReverb_configure End"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 697 | return 0; |
| 698 | } /* end Reverb_configure */ |
| 699 | |
| 700 | |
| 701 | //---------------------------------------------------------------------------- |
| 702 | // Reverb_init() |
| 703 | //---------------------------------------------------------------------------- |
| 704 | // Purpose: Initialize engine with default configuration |
| 705 | // |
| 706 | // Inputs: |
| 707 | // pContext: effect engine context |
| 708 | // |
| 709 | // Outputs: |
| 710 | // |
| 711 | //---------------------------------------------------------------------------- |
| 712 | |
| 713 | int Reverb_init(ReverbContext *pContext){ |
| 714 | int status; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 715 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 716 | ALOGV("\tReverb_init start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 717 | |
| 718 | CHECK_ARG(pContext != NULL); |
| 719 | |
| 720 | if (pContext->hInstance != NULL){ |
| 721 | Reverb_free(pContext); |
| 722 | } |
| 723 | |
| 724 | pContext->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 725 | if (pContext->auxiliary) { |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 726 | pContext->config.inputCfg.channels = AUDIO_CHANNEL_OUT_MONO; |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 727 | } else { |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 728 | pContext->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 729 | } |
| 730 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 731 | pContext->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 732 | pContext->config.inputCfg.samplingRate = 44100; |
| 733 | pContext->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 734 | pContext->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 735 | pContext->config.inputCfg.bufferProvider.cookie = NULL; |
| 736 | pContext->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 737 | pContext->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 738 | pContext->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 739 | pContext->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 740 | pContext->config.outputCfg.samplingRate = 44100; |
| 741 | pContext->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 742 | pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 743 | pContext->config.outputCfg.bufferProvider.cookie = NULL; |
| 744 | pContext->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
| 745 | |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 746 | pContext->leftVolume = REVERB_UNIT_VOLUME; |
| 747 | pContext->rightVolume = REVERB_UNIT_VOLUME; |
| 748 | pContext->prevLeftVolume = REVERB_UNIT_VOLUME; |
| 749 | pContext->prevRightVolume = REVERB_UNIT_VOLUME; |
| 750 | pContext->volumeMode = REVERB_VOLUME_FLAT; |
| 751 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 752 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 753 | LVREV_ControlParams_st params; /* Control Parameters */ |
| 754 | LVREV_InstanceParams_st InstParams; /* Instance parameters */ |
| 755 | LVREV_MemoryTable_st MemTab; /* Memory allocation table */ |
| 756 | bool bMallocFailure = LVM_FALSE; |
| 757 | |
| 758 | /* Set the capabilities */ |
| 759 | InstParams.MaxBlockSize = MAX_CALL_SIZE; |
Eric Laurent | 305443c | 2010-09-09 12:01:11 -0700 | [diff] [blame] | 760 | InstParams.SourceFormat = LVM_STEREO; // Max format, could be mono during process |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 761 | InstParams.NumDelays = LVREV_DELAYLINES_4; |
| 762 | |
| 763 | /* Allocate memory, forcing alignment */ |
| 764 | LvmStatus = LVREV_GetMemoryTable(LVM_NULL, |
| 765 | &MemTab, |
| 766 | &InstParams); |
| 767 | |
| 768 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetMemoryTable", "Reverb_init") |
| 769 | if(LvmStatus != LVREV_SUCCESS) return -EINVAL; |
| 770 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 771 | ALOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 772 | |
| 773 | /* Allocate memory */ |
| 774 | for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){ |
| 775 | if (MemTab.Region[i].Size != 0){ |
| 776 | MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size); |
| 777 | |
| 778 | if (MemTab.Region[i].pBaseAddress == LVM_NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 779 | ALOGV("\tLVREV_ERROR :Reverb_init CreateInstance Failed to allocate %ld " |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 780 | "bytes for region %u\n", MemTab.Region[i].Size, i ); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 781 | bMallocFailure = LVM_TRUE; |
| 782 | }else{ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 783 | ALOGV("\tReverb_init CreateInstance allocate %ld bytes for region %u at %p\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 784 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
| 785 | } |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | /* If one or more of the memory regions failed to allocate, free the regions that were |
| 790 | * succesfully allocated and return with an error |
| 791 | */ |
| 792 | if(bMallocFailure == LVM_TRUE){ |
| 793 | for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){ |
| 794 | if (MemTab.Region[i].pBaseAddress == LVM_NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 795 | ALOGV("\tLVM_ERROR :Reverb_init CreateInstance Failed to allocate %ld bytes " |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 796 | "for region %u - Not freeing\n", MemTab.Region[i].Size, i ); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 797 | }else{ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 798 | ALOGV("\tLVM_ERROR :Reverb_init CreateInstance Failed: but allocated %ld bytes " |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 799 | "for region %u at %p- free\n", |
| 800 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 801 | free(MemTab.Region[i].pBaseAddress); |
| 802 | } |
| 803 | } |
| 804 | return -EINVAL; |
| 805 | } |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 806 | ALOGV("\tReverb_init CreateInstance Succesfully malloc'd memory\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 807 | |
| 808 | /* Initialise */ |
| 809 | pContext->hInstance = LVM_NULL; |
| 810 | |
| 811 | /* Init sets the instance handle */ |
| 812 | LvmStatus = LVREV_GetInstanceHandle(&pContext->hInstance, |
| 813 | &MemTab, |
| 814 | &InstParams); |
| 815 | |
| 816 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "Reverb_init") |
| 817 | if(LvmStatus != LVREV_SUCCESS) return -EINVAL; |
| 818 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 819 | ALOGV("\tReverb_init CreateInstance Succesfully called LVM_GetInstanceHandle\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 820 | |
| 821 | /* Set the initial process parameters */ |
| 822 | /* General parameters */ |
| 823 | params.OperatingMode = LVM_MODE_ON; |
| 824 | params.SampleRate = LVM_FS_44100; |
Eric Laurent | 305443c | 2010-09-09 12:01:11 -0700 | [diff] [blame] | 825 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 826 | if(pContext->config.inputCfg.channels == AUDIO_CHANNEL_OUT_MONO){ |
Eric Laurent | 305443c | 2010-09-09 12:01:11 -0700 | [diff] [blame] | 827 | params.SourceFormat = LVM_MONO; |
| 828 | } else { |
| 829 | params.SourceFormat = LVM_STEREO; |
| 830 | } |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 831 | |
| 832 | /* Reverb parameters */ |
| 833 | params.Level = 0; |
| 834 | params.LPF = 23999; |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 835 | params.HPF = 50; |
| 836 | params.T60 = 1490; |
| 837 | params.Density = 100; |
| 838 | params.Damping = 21; |
| 839 | params.RoomSize = 100; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 840 | |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 841 | pContext->SamplesToExitCount = (params.T60 * pContext->config.inputCfg.samplingRate)/1000; |
| 842 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 843 | /* Saved strength is used to return the exact strength that was used in the set to the get |
| 844 | * because we map the original strength range of 0:1000 to 1:15, and this will avoid |
| 845 | * quantisation like effect when returning |
| 846 | */ |
| 847 | pContext->SavedRoomLevel = -6000; |
| 848 | pContext->SavedHfLevel = 0; |
| 849 | pContext->bEnabled = LVM_FALSE; |
| 850 | pContext->SavedDecayTime = params.T60; |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 851 | pContext->SavedDecayHfRatio = params.Damping*20; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 852 | pContext->SavedDensity = params.RoomSize*10; |
| 853 | pContext->SavedDiffusion = params.Density*10; |
| 854 | pContext->SavedReverbLevel = -6000; |
| 855 | |
| 856 | /* Activate the initial settings */ |
| 857 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, |
| 858 | ¶ms); |
| 859 | |
| 860 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "Reverb_init") |
| 861 | if(LvmStatus != LVREV_SUCCESS) return -EINVAL; |
| 862 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 863 | ALOGV("\tReverb_init CreateInstance Succesfully called LVREV_SetControlParameters\n"); |
| 864 | ALOGV("\tReverb_init End"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 865 | return 0; |
| 866 | } /* end Reverb_init */ |
| 867 | |
| 868 | //---------------------------------------------------------------------------- |
| 869 | // ReverbConvertLevel() |
| 870 | //---------------------------------------------------------------------------- |
| 871 | // Purpose: |
| 872 | // Convert level from OpenSL ES format to LVM format |
| 873 | // |
| 874 | // Inputs: |
| 875 | // level level to be applied |
| 876 | // |
| 877 | //---------------------------------------------------------------------------- |
| 878 | |
| 879 | int16_t ReverbConvertLevel(int16_t level){ |
| 880 | static int16_t LevelArray[101] = |
| 881 | { |
| 882 | -12000, -4000, -3398, -3046, -2796, -2603, -2444, -2310, -2194, -2092, |
| 883 | -2000, -1918, -1842, -1773, -1708, -1648, -1592, -1540, -1490, -1443, |
| 884 | -1398, -1356, -1316, -1277, -1240, -1205, -1171, -1138, -1106, -1076, |
| 885 | -1046, -1018, -990, -963, -938, -912, -888, -864, -841, -818, |
| 886 | -796, -775, -754, -734, -714, -694, -675, -656, -638, -620, |
| 887 | -603, -585, -568, -552, -536, -520, -504, -489, -474, -459, |
| 888 | -444, -430, -416, -402, -388, -375, -361, -348, -335, -323, |
| 889 | -310, -298, -286, -274, -262, -250, -239, -228, -216, -205, |
| 890 | -194, -184, -173, -162, -152, -142, -132, -121, -112, -102, |
| 891 | -92, -82, -73, -64, -54, -45, -36, -27, -18, -9, |
| 892 | 0 |
| 893 | }; |
| 894 | int16_t i; |
| 895 | |
| 896 | for(i = 0; i < 101; i++) |
| 897 | { |
| 898 | if(level <= LevelArray[i]) |
| 899 | break; |
| 900 | } |
| 901 | return i; |
| 902 | } |
| 903 | |
| 904 | //---------------------------------------------------------------------------- |
| 905 | // ReverbConvertHFLevel() |
| 906 | //---------------------------------------------------------------------------- |
| 907 | // Purpose: |
| 908 | // Convert level from OpenSL ES format to LVM format |
| 909 | // |
| 910 | // Inputs: |
| 911 | // level level to be applied |
| 912 | // |
| 913 | //---------------------------------------------------------------------------- |
| 914 | |
| 915 | int16_t ReverbConvertHfLevel(int16_t Hflevel){ |
| 916 | int16_t i; |
| 917 | |
| 918 | static LPFPair_t LPFArray[97] = |
| 919 | { // Limit range to 50 for LVREV parameter range |
| 920 | {-10000, 50}, { -5000, 50 }, { -4000, 50}, { -3000, 158}, { -2000, 502}, |
| 921 | {-1000, 1666},{ -900, 1897}, { -800, 2169}, { -700, 2496}, { -600, 2895}, |
| 922 | {-500, 3400}, { -400, 4066}, { -300, 5011}, { -200, 6537}, { -100, 9826}, |
| 923 | {-99, 9881 }, { -98, 9937 }, { -97, 9994 }, { -96, 10052}, { -95, 10111}, |
| 924 | {-94, 10171}, { -93, 10231}, { -92, 10293}, { -91, 10356}, { -90, 10419}, |
| 925 | {-89, 10484}, { -88, 10549}, { -87, 10616}, { -86, 10684}, { -85, 10753}, |
| 926 | {-84, 10823}, { -83, 10895}, { -82, 10968}, { -81, 11042}, { -80, 11117}, |
| 927 | {-79, 11194}, { -78, 11272}, { -77, 11352}, { -76, 11433}, { -75, 11516}, |
| 928 | {-74, 11600}, { -73, 11686}, { -72, 11774}, { -71, 11864}, { -70, 11955}, |
| 929 | {-69, 12049}, { -68, 12144}, { -67, 12242}, { -66, 12341}, { -65, 12443}, |
| 930 | {-64, 12548}, { -63, 12654}, { -62, 12763}, { -61, 12875}, { -60, 12990}, |
| 931 | {-59, 13107}, { -58, 13227}, { -57, 13351}, { -56, 13477}, { -55, 13607}, |
| 932 | {-54, 13741}, { -53, 13878}, { -52, 14019}, { -51, 14164}, { -50, 14313}, |
| 933 | {-49, 14467}, { -48, 14626}, { -47, 14789}, { -46, 14958}, { -45, 15132}, |
| 934 | {-44, 15312}, { -43, 15498}, { -42, 15691}, { -41, 15890}, { -40, 16097}, |
| 935 | {-39, 16311}, { -38, 16534}, { -37, 16766}, { -36, 17007}, { -35, 17259}, |
| 936 | {-34, 17521}, { -33, 17795}, { -32, 18081}, { -31, 18381}, { -30, 18696}, |
| 937 | {-29, 19027}, { -28, 19375}, { -27, 19742}, { -26, 20129}, { -25, 20540}, |
| 938 | {-24, 20976}, { -23, 21439}, { -22, 21934}, { -21, 22463}, { -20, 23031}, |
| 939 | {-19, 23643}, { -18, 23999} |
| 940 | }; |
| 941 | |
| 942 | for(i = 0; i < 96; i++) |
| 943 | { |
| 944 | if(Hflevel <= LPFArray[i].Room_HF) |
| 945 | break; |
| 946 | } |
| 947 | return LPFArray[i].LPF; |
| 948 | } |
| 949 | |
| 950 | //---------------------------------------------------------------------------- |
| 951 | // ReverbSetRoomHfLevel() |
| 952 | //---------------------------------------------------------------------------- |
| 953 | // Purpose: |
| 954 | // Apply the HF level to the Reverb. Must first be converted to LVM format |
| 955 | // |
| 956 | // Inputs: |
| 957 | // pContext: effect engine context |
| 958 | // level level to be applied |
| 959 | // |
| 960 | //---------------------------------------------------------------------------- |
| 961 | |
| 962 | void ReverbSetRoomHfLevel(ReverbContext *pContext, int16_t level){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 963 | //ALOGV("\tReverbSetRoomHfLevel start (%d)", level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 964 | |
| 965 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 966 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 967 | |
| 968 | /* Get the current settings */ |
| 969 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 970 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetRoomHfLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 971 | //ALOGV("\tReverbSetRoomHfLevel Succesfully returned from LVM_GetControlParameters\n"); |
| 972 | //ALOGV("\tReverbSetRoomHfLevel() just Got -> %d\n", ActiveParams.LPF); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 973 | |
| 974 | ActiveParams.LPF = ReverbConvertHfLevel(level); |
| 975 | |
| 976 | /* Activate the initial settings */ |
| 977 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams); |
| 978 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetRoomHfLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 979 | //ALOGV("\tReverbSetRoomhfLevel() just Set -> %d\n", ActiveParams.LPF); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 980 | pContext->SavedHfLevel = level; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 981 | //ALOGV("\tReverbSetHfRoomLevel end.. saving %d", pContext->SavedHfLevel); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 982 | return; |
| 983 | } |
| 984 | |
| 985 | //---------------------------------------------------------------------------- |
| 986 | // ReverbGetRoomHfLevel() |
| 987 | //---------------------------------------------------------------------------- |
| 988 | // Purpose: |
| 989 | // Get the level applied to the Revervb. Must first be converted to LVM format |
| 990 | // |
| 991 | // Inputs: |
| 992 | // pContext: effect engine context |
| 993 | // |
| 994 | //---------------------------------------------------------------------------- |
| 995 | |
| 996 | int16_t ReverbGetRoomHfLevel(ReverbContext *pContext){ |
| 997 | int16_t level; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 998 | //ALOGV("\tReverbGetRoomHfLevel start, saved level is %d", pContext->SavedHfLevel); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 999 | |
| 1000 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1001 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1002 | |
| 1003 | /* Get the current settings */ |
| 1004 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1005 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetRoomHfLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1006 | //ALOGV("\tReverbGetRoomHfLevel Succesfully returned from LVM_GetControlParameters\n"); |
| 1007 | //ALOGV("\tReverbGetRoomHfLevel() just Got -> %d\n", ActiveParams.LPF); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1008 | |
| 1009 | level = ReverbConvertHfLevel(pContext->SavedHfLevel); |
| 1010 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1011 | //ALOGV("\tReverbGetRoomHfLevel() ActiveParams.LPFL %d, pContext->SavedHfLevel: %d, " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1012 | // "converted level: %d\n", ActiveParams.LPF, pContext->SavedHfLevel, level); |
| 1013 | |
| 1014 | if(ActiveParams.LPF != level){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1015 | ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetRoomHfLevel() has wrong level -> %d %d\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1016 | ActiveParams.Level, level); |
| 1017 | } |
| 1018 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1019 | //ALOGV("\tReverbGetRoomHfLevel end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1020 | return pContext->SavedHfLevel; |
| 1021 | } |
| 1022 | |
| 1023 | //---------------------------------------------------------------------------- |
| 1024 | // ReverbSetReverbLevel() |
| 1025 | //---------------------------------------------------------------------------- |
| 1026 | // Purpose: |
| 1027 | // Apply the level to the Reverb. Must first be converted to LVM format |
| 1028 | // |
| 1029 | // Inputs: |
| 1030 | // pContext: effect engine context |
| 1031 | // level level to be applied |
| 1032 | // |
| 1033 | //---------------------------------------------------------------------------- |
| 1034 | |
| 1035 | void ReverbSetReverbLevel(ReverbContext *pContext, int16_t level){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1036 | //ALOGV("\n\tReverbSetReverbLevel start (%d)", level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1037 | |
| 1038 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1039 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1040 | LVM_INT32 CombinedLevel; // Sum of room and reverb level controls |
| 1041 | |
| 1042 | /* Get the current settings */ |
| 1043 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1044 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetReverbLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1045 | //ALOGV("\tReverbSetReverbLevel Succesfully returned from LVM_GetControlParameters\n"); |
| 1046 | //ALOGV("\tReverbSetReverbLevel just Got -> %d\n", ActiveParams.Level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1047 | |
| 1048 | // needs to subtract max levels for both RoomLevel and ReverbLevel |
| 1049 | CombinedLevel = (level + pContext->SavedRoomLevel)-LVREV_MAX_REVERB_LEVEL; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1050 | //ALOGV("\tReverbSetReverbLevel() CombinedLevel is %d = %d + %d\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1051 | // CombinedLevel, level, pContext->SavedRoomLevel); |
| 1052 | |
| 1053 | ActiveParams.Level = ReverbConvertLevel(CombinedLevel); |
| 1054 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1055 | //ALOGV("\tReverbSetReverbLevel() Trying to set -> %d\n", ActiveParams.Level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1056 | |
| 1057 | /* Activate the initial settings */ |
| 1058 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams); |
| 1059 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetReverbLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1060 | //ALOGV("\tReverbSetReverbLevel() just Set -> %d\n", ActiveParams.Level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1061 | |
| 1062 | pContext->SavedReverbLevel = level; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1063 | //ALOGV("\tReverbSetReverbLevel end pContext->SavedReverbLevel is %d\n\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1064 | // pContext->SavedReverbLevel); |
| 1065 | return; |
| 1066 | } |
| 1067 | |
| 1068 | //---------------------------------------------------------------------------- |
| 1069 | // ReverbGetReverbLevel() |
| 1070 | //---------------------------------------------------------------------------- |
| 1071 | // Purpose: |
| 1072 | // Get the level applied to the Revervb. Must first be converted to LVM format |
| 1073 | // |
| 1074 | // Inputs: |
| 1075 | // pContext: effect engine context |
| 1076 | // |
| 1077 | //---------------------------------------------------------------------------- |
| 1078 | |
| 1079 | int16_t ReverbGetReverbLevel(ReverbContext *pContext){ |
| 1080 | int16_t level; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1081 | //ALOGV("\tReverbGetReverbLevel start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1082 | |
| 1083 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1084 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1085 | LVM_INT32 CombinedLevel; // Sum of room and reverb level controls |
| 1086 | |
| 1087 | /* Get the current settings */ |
| 1088 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1089 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetReverbLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1090 | //ALOGV("\tReverbGetReverbLevel Succesfully returned from LVM_GetControlParameters\n"); |
| 1091 | //ALOGV("\tReverbGetReverbLevel() just Got -> %d\n", ActiveParams.Level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1092 | |
| 1093 | // needs to subtract max levels for both RoomLevel and ReverbLevel |
| 1094 | CombinedLevel = (pContext->SavedReverbLevel + pContext->SavedRoomLevel)-LVREV_MAX_REVERB_LEVEL; |
| 1095 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1096 | //ALOGV("\tReverbGetReverbLevel() CombinedLevel is %d = %d + %d\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1097 | //CombinedLevel, pContext->SavedReverbLevel, pContext->SavedRoomLevel); |
| 1098 | level = ReverbConvertLevel(CombinedLevel); |
| 1099 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1100 | //ALOGV("\tReverbGetReverbLevel(): ActiveParams.Level: %d, pContext->SavedReverbLevel: %d, " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1101 | //"pContext->SavedRoomLevel: %d, CombinedLevel: %d, converted level: %d\n", |
| 1102 | //ActiveParams.Level, pContext->SavedReverbLevel,pContext->SavedRoomLevel, CombinedLevel,level); |
| 1103 | |
| 1104 | if(ActiveParams.Level != level){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1105 | ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetReverbLevel() has wrong level -> %d %d\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1106 | ActiveParams.Level, level); |
| 1107 | } |
| 1108 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1109 | //ALOGV("\tReverbGetReverbLevel end\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1110 | |
| 1111 | return pContext->SavedReverbLevel; |
| 1112 | } |
| 1113 | |
| 1114 | //---------------------------------------------------------------------------- |
| 1115 | // ReverbSetRoomLevel() |
| 1116 | //---------------------------------------------------------------------------- |
| 1117 | // Purpose: |
| 1118 | // Apply the level to the Reverb. Must first be converted to LVM format |
| 1119 | // |
| 1120 | // Inputs: |
| 1121 | // pContext: effect engine context |
| 1122 | // level level to be applied |
| 1123 | // |
| 1124 | //---------------------------------------------------------------------------- |
| 1125 | |
| 1126 | void ReverbSetRoomLevel(ReverbContext *pContext, int16_t level){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1127 | //ALOGV("\tReverbSetRoomLevel start (%d)", level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1128 | |
| 1129 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1130 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1131 | LVM_INT32 CombinedLevel; // Sum of room and reverb level controls |
| 1132 | |
| 1133 | /* Get the current settings */ |
| 1134 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1135 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetRoomLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1136 | //ALOGV("\tReverbSetRoomLevel Succesfully returned from LVM_GetControlParameters\n"); |
| 1137 | //ALOGV("\tReverbSetRoomLevel() just Got -> %d\n", ActiveParams.Level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1138 | |
| 1139 | // needs to subtract max levels for both RoomLevel and ReverbLevel |
| 1140 | CombinedLevel = (level + pContext->SavedReverbLevel)-LVREV_MAX_REVERB_LEVEL; |
| 1141 | ActiveParams.Level = ReverbConvertLevel(CombinedLevel); |
| 1142 | |
| 1143 | /* Activate the initial settings */ |
| 1144 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams); |
| 1145 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetRoomLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1146 | //ALOGV("\tReverbSetRoomLevel() just Set -> %d\n", ActiveParams.Level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1147 | |
| 1148 | pContext->SavedRoomLevel = level; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1149 | //ALOGV("\tReverbSetRoomLevel end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1150 | return; |
| 1151 | } |
| 1152 | |
| 1153 | //---------------------------------------------------------------------------- |
| 1154 | // ReverbGetRoomLevel() |
| 1155 | //---------------------------------------------------------------------------- |
| 1156 | // Purpose: |
| 1157 | // Get the level applied to the Revervb. Must first be converted to LVM format |
| 1158 | // |
| 1159 | // Inputs: |
| 1160 | // pContext: effect engine context |
| 1161 | // |
| 1162 | //---------------------------------------------------------------------------- |
| 1163 | |
| 1164 | int16_t ReverbGetRoomLevel(ReverbContext *pContext){ |
| 1165 | int16_t level; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1166 | //ALOGV("\tReverbGetRoomLevel start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1167 | |
| 1168 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1169 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1170 | LVM_INT32 CombinedLevel; // Sum of room and reverb level controls |
| 1171 | |
| 1172 | /* Get the current settings */ |
| 1173 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1174 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetRoomLevel") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1175 | //ALOGV("\tReverbGetRoomLevel Succesfully returned from LVM_GetControlParameters\n"); |
| 1176 | //ALOGV("\tReverbGetRoomLevel() just Got -> %d\n", ActiveParams.Level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1177 | |
| 1178 | // needs to subtract max levels for both RoomLevel and ReverbLevel |
| 1179 | CombinedLevel = (pContext->SavedRoomLevel + pContext->SavedReverbLevel-LVREV_MAX_REVERB_LEVEL); |
| 1180 | level = ReverbConvertLevel(CombinedLevel); |
| 1181 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1182 | //ALOGV("\tReverbGetRoomLevel, Level = %d, pContext->SavedRoomLevel = %d, " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1183 | // "pContext->SavedReverbLevel = %d, CombinedLevel = %d, level = %d", |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 1184 | // ActiveParams.Level, pContext->SavedRoomLevel, |
| 1185 | // pContext->SavedReverbLevel, CombinedLevel, level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1186 | |
| 1187 | if(ActiveParams.Level != level){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1188 | ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetRoomLevel() has wrong level -> %d %d\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1189 | ActiveParams.Level, level); |
| 1190 | } |
| 1191 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1192 | //ALOGV("\tReverbGetRoomLevel end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1193 | return pContext->SavedRoomLevel; |
| 1194 | } |
| 1195 | |
| 1196 | //---------------------------------------------------------------------------- |
| 1197 | // ReverbSetDecayTime() |
| 1198 | //---------------------------------------------------------------------------- |
| 1199 | // Purpose: |
| 1200 | // Apply the decay time to the Reverb. |
| 1201 | // |
| 1202 | // Inputs: |
| 1203 | // pContext: effect engine context |
| 1204 | // time decay to be applied |
| 1205 | // |
| 1206 | //---------------------------------------------------------------------------- |
| 1207 | |
| 1208 | void ReverbSetDecayTime(ReverbContext *pContext, uint32_t time){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1209 | //ALOGV("\tReverbSetDecayTime start (%d)", time); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1210 | |
| 1211 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1212 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1213 | |
| 1214 | /* Get the current settings */ |
| 1215 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1216 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDecayTime") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1217 | //ALOGV("\tReverbSetDecayTime Succesfully returned from LVM_GetControlParameters\n"); |
| 1218 | //ALOGV("\tReverbSetDecayTime() just Got -> %d\n", ActiveParams.T60); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1219 | |
| 1220 | if (time <= LVREV_MAX_T60) { |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1221 | ActiveParams.T60 = (LVM_UINT16)time; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1222 | } |
| 1223 | else { |
| 1224 | ActiveParams.T60 = LVREV_MAX_T60; |
| 1225 | } |
| 1226 | |
| 1227 | /* Activate the initial settings */ |
| 1228 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams); |
| 1229 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDecayTime") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1230 | //ALOGV("\tReverbSetDecayTime() just Set -> %d\n", ActiveParams.T60); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1231 | |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 1232 | pContext->SamplesToExitCount = (ActiveParams.T60 * pContext->config.inputCfg.samplingRate)/1000; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1233 | //ALOGV("\tReverbSetDecayTime() just Set SamplesToExitCount-> %d\n",pContext->SamplesToExitCount); |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1234 | pContext->SavedDecayTime = (int16_t)time; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1235 | //ALOGV("\tReverbSetDecayTime end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1236 | return; |
| 1237 | } |
| 1238 | |
| 1239 | //---------------------------------------------------------------------------- |
| 1240 | // ReverbGetDecayTime() |
| 1241 | //---------------------------------------------------------------------------- |
| 1242 | // Purpose: |
| 1243 | // Get the decay time applied to the Revervb. |
| 1244 | // |
| 1245 | // Inputs: |
| 1246 | // pContext: effect engine context |
| 1247 | // |
| 1248 | //---------------------------------------------------------------------------- |
| 1249 | |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1250 | uint32_t ReverbGetDecayTime(ReverbContext *pContext){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1251 | //ALOGV("\tReverbGetDecayTime start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1252 | |
| 1253 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1254 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1255 | |
| 1256 | /* Get the current settings */ |
| 1257 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1258 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDecayTime") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1259 | //ALOGV("\tReverbGetDecayTime Succesfully returned from LVM_GetControlParameters\n"); |
| 1260 | //ALOGV("\tReverbGetDecayTime() just Got -> %d\n", ActiveParams.T60); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1261 | |
| 1262 | if(ActiveParams.T60 != pContext->SavedDecayTime){ |
| 1263 | // This will fail if the decay time is set to more than 7000 |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1264 | ALOGV("\tLVM_ERROR : ReverbGetDecayTime() has wrong level -> %d %d\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1265 | ActiveParams.T60, pContext->SavedDecayTime); |
| 1266 | } |
| 1267 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1268 | //ALOGV("\tReverbGetDecayTime end"); |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1269 | return (uint32_t)ActiveParams.T60; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | //---------------------------------------------------------------------------- |
| 1273 | // ReverbSetDecayHfRatio() |
| 1274 | //---------------------------------------------------------------------------- |
| 1275 | // Purpose: |
| 1276 | // Apply the HF decay ratio to the Reverb. |
| 1277 | // |
| 1278 | // Inputs: |
| 1279 | // pContext: effect engine context |
| 1280 | // ratio ratio to be applied |
| 1281 | // |
| 1282 | //---------------------------------------------------------------------------- |
| 1283 | |
| 1284 | void ReverbSetDecayHfRatio(ReverbContext *pContext, int16_t ratio){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1285 | //ALOGV("\tReverbSetDecayHfRatioe start (%d)", ratio); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1286 | |
| 1287 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1288 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1289 | |
| 1290 | /* Get the current settings */ |
| 1291 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1292 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDecayHfRatio") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1293 | //ALOGV("\tReverbSetDecayHfRatio Succesfully returned from LVM_GetControlParameters\n"); |
| 1294 | //ALOGV("\tReverbSetDecayHfRatio() just Got -> %d\n", ActiveParams.Damping); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1295 | |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1296 | ActiveParams.Damping = (LVM_INT16)(ratio/20); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1297 | |
| 1298 | /* Activate the initial settings */ |
| 1299 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams); |
| 1300 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDecayHfRatio") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1301 | //ALOGV("\tReverbSetDecayHfRatio() just Set -> %d\n", ActiveParams.Damping); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1302 | |
| 1303 | pContext->SavedDecayHfRatio = ratio; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1304 | //ALOGV("\tReverbSetDecayHfRatio end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1305 | return; |
| 1306 | } |
| 1307 | |
| 1308 | //---------------------------------------------------------------------------- |
| 1309 | // ReverbGetDecayHfRatio() |
| 1310 | //---------------------------------------------------------------------------- |
| 1311 | // Purpose: |
| 1312 | // Get the HF decay ratio applied to the Revervb. |
| 1313 | // |
| 1314 | // Inputs: |
| 1315 | // pContext: effect engine context |
| 1316 | // |
| 1317 | //---------------------------------------------------------------------------- |
| 1318 | |
| 1319 | int32_t ReverbGetDecayHfRatio(ReverbContext *pContext){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1320 | //ALOGV("\tReverbGetDecayHfRatio start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1321 | |
| 1322 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1323 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1324 | |
| 1325 | /* Get the current settings */ |
| 1326 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1327 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDecayHfRatio") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1328 | //ALOGV("\tReverbGetDecayHfRatio Succesfully returned from LVM_GetControlParameters\n"); |
| 1329 | //ALOGV("\tReverbGetDecayHfRatio() just Got -> %d\n", ActiveParams.Damping); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1330 | |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1331 | if(ActiveParams.Damping != (LVM_INT16)(pContext->SavedDecayHfRatio / 20)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1332 | ALOGV("\tLVM_ERROR : ReverbGetDecayHfRatio() has wrong level -> %d %d\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1333 | ActiveParams.Damping, pContext->SavedDecayHfRatio); |
| 1334 | } |
| 1335 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1336 | //ALOGV("\tReverbGetDecayHfRatio end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1337 | return pContext->SavedDecayHfRatio; |
| 1338 | } |
| 1339 | |
| 1340 | //---------------------------------------------------------------------------- |
| 1341 | // ReverbSetDiffusion() |
| 1342 | //---------------------------------------------------------------------------- |
| 1343 | // Purpose: |
| 1344 | // Apply the diffusion to the Reverb. |
| 1345 | // |
| 1346 | // Inputs: |
| 1347 | // pContext: effect engine context |
| 1348 | // level decay to be applied |
| 1349 | // |
| 1350 | //---------------------------------------------------------------------------- |
| 1351 | |
| 1352 | void ReverbSetDiffusion(ReverbContext *pContext, int16_t level){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1353 | //ALOGV("\tReverbSetDiffusion start (%d)", level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1354 | |
| 1355 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1356 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1357 | |
| 1358 | /* Get the current settings */ |
| 1359 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1360 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDiffusion") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1361 | //ALOGV("\tReverbSetDiffusion Succesfully returned from LVM_GetControlParameters\n"); |
| 1362 | //ALOGV("\tReverbSetDiffusion() just Got -> %d\n", ActiveParams.Density); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1363 | |
| 1364 | ActiveParams.Density = (LVM_INT16)(level/10); |
| 1365 | |
| 1366 | /* Activate the initial settings */ |
| 1367 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams); |
| 1368 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDiffusion") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1369 | //ALOGV("\tReverbSetDiffusion() just Set -> %d\n", ActiveParams.Density); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1370 | |
| 1371 | pContext->SavedDiffusion = level; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1372 | //ALOGV("\tReverbSetDiffusion end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1373 | return; |
| 1374 | } |
| 1375 | |
| 1376 | //---------------------------------------------------------------------------- |
| 1377 | // ReverbGetDiffusion() |
| 1378 | //---------------------------------------------------------------------------- |
| 1379 | // Purpose: |
| 1380 | // Get the decay time applied to the Revervb. |
| 1381 | // |
| 1382 | // Inputs: |
| 1383 | // pContext: effect engine context |
| 1384 | // |
| 1385 | //---------------------------------------------------------------------------- |
| 1386 | |
| 1387 | int32_t ReverbGetDiffusion(ReverbContext *pContext){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1388 | //ALOGV("\tReverbGetDiffusion start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1389 | |
| 1390 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1391 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1392 | LVM_INT16 Temp; |
| 1393 | |
| 1394 | /* Get the current settings */ |
| 1395 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1396 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDiffusion") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1397 | //ALOGV("\tReverbGetDiffusion Succesfully returned from LVM_GetControlParameters\n"); |
| 1398 | //ALOGV("\tReverbGetDiffusion just Got -> %d\n", ActiveParams.Density); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1399 | |
| 1400 | Temp = (LVM_INT16)(pContext->SavedDiffusion/10); |
| 1401 | |
| 1402 | if(ActiveParams.Density != Temp){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1403 | ALOGV("\tLVM_ERROR : ReverbGetDiffusion invalid value %d %d", Temp, ActiveParams.Density); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1406 | //ALOGV("\tReverbGetDiffusion end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1407 | return pContext->SavedDiffusion; |
| 1408 | } |
| 1409 | |
| 1410 | //---------------------------------------------------------------------------- |
| 1411 | // ReverbSetDensity() |
| 1412 | //---------------------------------------------------------------------------- |
| 1413 | // Purpose: |
| 1414 | // Apply the density level the Reverb. |
| 1415 | // |
| 1416 | // Inputs: |
| 1417 | // pContext: effect engine context |
| 1418 | // level decay to be applied |
| 1419 | // |
| 1420 | //---------------------------------------------------------------------------- |
| 1421 | |
| 1422 | void ReverbSetDensity(ReverbContext *pContext, int16_t level){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1423 | //ALOGV("\tReverbSetDensity start (%d)", level); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1424 | |
| 1425 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1426 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1427 | |
| 1428 | /* Get the current settings */ |
| 1429 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1430 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDensity") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1431 | //ALOGV("\tReverbSetDensity Succesfully returned from LVM_GetControlParameters\n"); |
| 1432 | //ALOGV("\tReverbSetDensity just Got -> %d\n", ActiveParams.RoomSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1433 | |
| 1434 | ActiveParams.RoomSize = (LVM_INT16)(((level * 99) / 1000) + 1); |
| 1435 | |
| 1436 | /* Activate the initial settings */ |
| 1437 | LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams); |
| 1438 | LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDensity") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1439 | //ALOGV("\tReverbSetDensity just Set -> %d\n", ActiveParams.RoomSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1440 | |
| 1441 | pContext->SavedDensity = level; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1442 | //ALOGV("\tReverbSetDensity end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1443 | return; |
| 1444 | } |
| 1445 | |
| 1446 | //---------------------------------------------------------------------------- |
| 1447 | // ReverbGetDensity() |
| 1448 | //---------------------------------------------------------------------------- |
| 1449 | // Purpose: |
| 1450 | // Get the density level applied to the Revervb. |
| 1451 | // |
| 1452 | // Inputs: |
| 1453 | // pContext: effect engine context |
| 1454 | // |
| 1455 | //---------------------------------------------------------------------------- |
| 1456 | |
| 1457 | int32_t ReverbGetDensity(ReverbContext *pContext){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1458 | //ALOGV("\tReverbGetDensity start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1459 | |
| 1460 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1461 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1462 | LVM_INT16 Temp; |
| 1463 | /* Get the current settings */ |
| 1464 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 1465 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDensity") |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1466 | //ALOGV("\tReverbGetDensity Succesfully returned from LVM_GetControlParameters\n"); |
| 1467 | //ALOGV("\tReverbGetDensity() just Got -> %d\n", ActiveParams.RoomSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1468 | |
| 1469 | |
| 1470 | Temp = (LVM_INT16)(((pContext->SavedDensity * 99) / 1000) + 1); |
| 1471 | |
| 1472 | if(Temp != ActiveParams.RoomSize){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1473 | ALOGV("\tLVM_ERROR : ReverbGetDensity invalid value %d %d", Temp, ActiveParams.RoomSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1476 | //ALOGV("\tReverbGetDensity end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1477 | return pContext->SavedDensity; |
| 1478 | } |
| 1479 | |
| 1480 | //---------------------------------------------------------------------------- |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 1481 | // Reverb_LoadPreset() |
| 1482 | //---------------------------------------------------------------------------- |
| 1483 | // Purpose: |
| 1484 | // Load a the next preset |
| 1485 | // |
| 1486 | // Inputs: |
| 1487 | // pContext - handle to instance data |
| 1488 | // |
| 1489 | // Outputs: |
| 1490 | // |
| 1491 | // Side Effects: |
| 1492 | // |
| 1493 | //---------------------------------------------------------------------------- |
| 1494 | int Reverb_LoadPreset(ReverbContext *pContext) |
| 1495 | { |
| 1496 | //TODO: add reflections delay, level and reverb delay when early reflections are |
| 1497 | // implemented |
| 1498 | pContext->curPreset = pContext->nextPreset; |
| 1499 | |
| 1500 | if (pContext->curPreset != REVERB_PRESET_NONE) { |
| 1501 | const t_reverb_settings *preset = &sReverbPresets[pContext->curPreset]; |
| 1502 | ReverbSetRoomLevel(pContext, preset->roomLevel); |
| 1503 | ReverbSetRoomHfLevel(pContext, preset->roomHFLevel); |
| 1504 | ReverbSetDecayTime(pContext, preset->decayTime); |
| 1505 | ReverbSetDecayHfRatio(pContext, preset->decayHFRatio); |
| 1506 | //reflectionsLevel |
| 1507 | //reflectionsDelay |
| 1508 | ReverbSetReverbLevel(pContext, preset->reverbLevel); |
| 1509 | // reverbDelay |
| 1510 | ReverbSetDiffusion(pContext, preset->diffusion); |
| 1511 | ReverbSetDensity(pContext, preset->density); |
| 1512 | } |
| 1513 | |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | |
| 1518 | //---------------------------------------------------------------------------- |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1519 | // Reverb_getParameter() |
| 1520 | //---------------------------------------------------------------------------- |
| 1521 | // Purpose: |
| 1522 | // Get a Reverb parameter |
| 1523 | // |
| 1524 | // Inputs: |
| 1525 | // pContext - handle to instance data |
| 1526 | // pParam - pointer to parameter |
| 1527 | // pValue - pointer to variable to hold retrieved value |
| 1528 | // pValueSize - pointer to value size: maximum size as input |
| 1529 | // |
| 1530 | // Outputs: |
| 1531 | // *pValue updated with parameter value |
| 1532 | // *pValueSize updated with actual value size |
| 1533 | // |
| 1534 | // |
| 1535 | // Side Effects: |
| 1536 | // |
| 1537 | //---------------------------------------------------------------------------- |
| 1538 | |
| 1539 | int Reverb_getParameter(ReverbContext *pContext, |
| 1540 | void *pParam, |
| 1541 | size_t *pValueSize, |
| 1542 | void *pValue){ |
| 1543 | int status = 0; |
| 1544 | int32_t *pParamTemp = (int32_t *)pParam; |
| 1545 | int32_t param = *pParamTemp++; |
| 1546 | char *name; |
| 1547 | t_reverb_settings *pProperties; |
| 1548 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1549 | //ALOGV("\tReverb_getParameter start"); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 1550 | if (pContext->preset) { |
| 1551 | if (param != REVERB_PARAM_PRESET || *pValueSize < sizeof(uint16_t)) { |
| 1552 | return -EINVAL; |
| 1553 | } |
| 1554 | |
| 1555 | *(uint16_t *)pValue = pContext->nextPreset; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1556 | ALOGV("get REVERB_PARAM_PRESET, preset %d", pContext->nextPreset); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 1557 | return 0; |
| 1558 | } |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1559 | |
| 1560 | switch (param){ |
| 1561 | case REVERB_PARAM_ROOM_LEVEL: |
| 1562 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1563 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize1 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1564 | return -EINVAL; |
| 1565 | } |
| 1566 | *pValueSize = sizeof(int16_t); |
| 1567 | break; |
| 1568 | case REVERB_PARAM_ROOM_HF_LEVEL: |
| 1569 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1570 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize12 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1571 | return -EINVAL; |
| 1572 | } |
| 1573 | *pValueSize = sizeof(int16_t); |
| 1574 | break; |
| 1575 | case REVERB_PARAM_DECAY_TIME: |
| 1576 | if (*pValueSize != sizeof(uint32_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1577 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize3 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1578 | return -EINVAL; |
| 1579 | } |
| 1580 | *pValueSize = sizeof(uint32_t); |
| 1581 | break; |
| 1582 | case REVERB_PARAM_DECAY_HF_RATIO: |
| 1583 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1584 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize4 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1585 | return -EINVAL; |
| 1586 | } |
| 1587 | *pValueSize = sizeof(int16_t); |
| 1588 | break; |
| 1589 | case REVERB_PARAM_REFLECTIONS_LEVEL: |
| 1590 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1591 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize5 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1592 | return -EINVAL; |
| 1593 | } |
| 1594 | *pValueSize = sizeof(int16_t); |
| 1595 | break; |
| 1596 | case REVERB_PARAM_REFLECTIONS_DELAY: |
| 1597 | if (*pValueSize != sizeof(uint32_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1598 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize6 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1599 | return -EINVAL; |
| 1600 | } |
| 1601 | *pValueSize = sizeof(uint32_t); |
| 1602 | break; |
| 1603 | case REVERB_PARAM_REVERB_LEVEL: |
| 1604 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1605 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize7 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1606 | return -EINVAL; |
| 1607 | } |
| 1608 | *pValueSize = sizeof(int16_t); |
| 1609 | break; |
| 1610 | case REVERB_PARAM_REVERB_DELAY: |
| 1611 | if (*pValueSize != sizeof(uint32_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1612 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize8 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1613 | return -EINVAL; |
| 1614 | } |
| 1615 | *pValueSize = sizeof(uint32_t); |
| 1616 | break; |
| 1617 | case REVERB_PARAM_DIFFUSION: |
| 1618 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1619 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize9 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1620 | return -EINVAL; |
| 1621 | } |
| 1622 | *pValueSize = sizeof(int16_t); |
| 1623 | break; |
| 1624 | case REVERB_PARAM_DENSITY: |
| 1625 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1626 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize10 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1627 | return -EINVAL; |
| 1628 | } |
| 1629 | *pValueSize = sizeof(int16_t); |
| 1630 | break; |
| 1631 | case REVERB_PARAM_PROPERTIES: |
| 1632 | if (*pValueSize != sizeof(t_reverb_settings)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1633 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize11 %d", *pValueSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1634 | return -EINVAL; |
| 1635 | } |
| 1636 | *pValueSize = sizeof(t_reverb_settings); |
| 1637 | break; |
| 1638 | |
| 1639 | default: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1640 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid param %d", param); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1641 | return -EINVAL; |
| 1642 | } |
| 1643 | |
| 1644 | pProperties = (t_reverb_settings *) pValue; |
| 1645 | |
| 1646 | switch (param){ |
| 1647 | case REVERB_PARAM_PROPERTIES: |
| 1648 | pProperties->roomLevel = ReverbGetRoomLevel(pContext); |
| 1649 | pProperties->roomHFLevel = ReverbGetRoomHfLevel(pContext); |
| 1650 | pProperties->decayTime = ReverbGetDecayTime(pContext); |
| 1651 | pProperties->decayHFRatio = ReverbGetDecayHfRatio(pContext); |
| 1652 | pProperties->reflectionsLevel = 0; |
| 1653 | pProperties->reflectionsDelay = 0; |
| 1654 | pProperties->reverbDelay = 0; |
| 1655 | pProperties->reverbLevel = ReverbGetReverbLevel(pContext); |
| 1656 | pProperties->diffusion = ReverbGetDiffusion(pContext); |
| 1657 | pProperties->density = ReverbGetDensity(pContext); |
| 1658 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1659 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is roomLevel %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1660 | pProperties->roomLevel); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1661 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is roomHFLevel %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1662 | pProperties->roomHFLevel); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1663 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is decayTime %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1664 | pProperties->decayTime); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1665 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is decayHFRatio %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1666 | pProperties->decayHFRatio); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1667 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reflectionsLevel %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1668 | pProperties->reflectionsLevel); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1669 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reflectionsDelay %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1670 | pProperties->reflectionsDelay); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1671 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reverbDelay %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1672 | pProperties->reverbDelay); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1673 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reverbLevel %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1674 | pProperties->reverbLevel); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1675 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is diffusion %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1676 | pProperties->diffusion); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1677 | ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is density %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1678 | pProperties->density); |
| 1679 | break; |
| 1680 | |
| 1681 | case REVERB_PARAM_ROOM_LEVEL: |
| 1682 | *(int16_t *)pValue = ReverbGetRoomLevel(pContext); |
| 1683 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1684 | //ALOGV("\tReverb_getParameter() REVERB_PARAM_ROOM_LEVEL Value is %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1685 | // *(int16_t *)pValue); |
| 1686 | break; |
| 1687 | case REVERB_PARAM_ROOM_HF_LEVEL: |
| 1688 | *(int16_t *)pValue = ReverbGetRoomHfLevel(pContext); |
| 1689 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1690 | //ALOGV("\tReverb_getParameter() REVERB_PARAM_ROOM_HF_LEVEL Value is %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1691 | // *(int16_t *)pValue); |
| 1692 | break; |
| 1693 | case REVERB_PARAM_DECAY_TIME: |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1694 | *(uint32_t *)pValue = ReverbGetDecayTime(pContext); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1695 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1696 | //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_TIME Value is %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1697 | // *(int32_t *)pValue); |
| 1698 | break; |
| 1699 | case REVERB_PARAM_DECAY_HF_RATIO: |
| 1700 | *(int16_t *)pValue = ReverbGetDecayHfRatio(pContext); |
| 1701 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1702 | //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_HF_RATION Value is %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1703 | // *(int16_t *)pValue); |
| 1704 | break; |
| 1705 | case REVERB_PARAM_REVERB_LEVEL: |
| 1706 | *(int16_t *)pValue = ReverbGetReverbLevel(pContext); |
| 1707 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1708 | //ALOGV("\tReverb_getParameter() REVERB_PARAM_REVERB_LEVEL Value is %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1709 | // *(int16_t *)pValue); |
| 1710 | break; |
| 1711 | case REVERB_PARAM_DIFFUSION: |
| 1712 | *(int16_t *)pValue = ReverbGetDiffusion(pContext); |
| 1713 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1714 | //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_DIFFUSION Value is %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1715 | // *(int16_t *)pValue); |
| 1716 | break; |
| 1717 | case REVERB_PARAM_DENSITY: |
| 1718 | *(uint16_t *)pValue = 0; |
| 1719 | *(int16_t *)pValue = ReverbGetDensity(pContext); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1720 | //ALOGV("\tReverb_getParameter() REVERB_PARAM_DENSITY Value is %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1721 | // *(uint32_t *)pValue); |
| 1722 | break; |
| 1723 | case REVERB_PARAM_REFLECTIONS_LEVEL: |
| 1724 | *(uint16_t *)pValue = 0; |
| 1725 | case REVERB_PARAM_REFLECTIONS_DELAY: |
| 1726 | *(uint32_t *)pValue = 0; |
| 1727 | case REVERB_PARAM_REVERB_DELAY: |
| 1728 | *(uint32_t *)pValue = 0; |
| 1729 | break; |
| 1730 | |
| 1731 | default: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1732 | ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid param %d", param); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1733 | status = -EINVAL; |
| 1734 | break; |
| 1735 | } |
| 1736 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1737 | //ALOGV("\tReverb_getParameter end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1738 | return status; |
| 1739 | } /* end Reverb_getParameter */ |
| 1740 | |
| 1741 | //---------------------------------------------------------------------------- |
| 1742 | // Reverb_setParameter() |
| 1743 | //---------------------------------------------------------------------------- |
| 1744 | // Purpose: |
| 1745 | // Set a Reverb parameter |
| 1746 | // |
| 1747 | // Inputs: |
| 1748 | // pContext - handle to instance data |
| 1749 | // pParam - pointer to parameter |
| 1750 | // pValue - pointer to value |
| 1751 | // |
| 1752 | // Outputs: |
| 1753 | // |
| 1754 | //---------------------------------------------------------------------------- |
| 1755 | |
| 1756 | int Reverb_setParameter (ReverbContext *pContext, void *pParam, void *pValue){ |
| 1757 | int status = 0; |
| 1758 | int16_t level; |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1759 | int16_t ratio; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1760 | uint32_t time; |
| 1761 | t_reverb_settings *pProperties; |
| 1762 | int32_t *pParamTemp = (int32_t *)pParam; |
| 1763 | int32_t param = *pParamTemp++; |
| 1764 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1765 | //ALOGV("\tReverb_setParameter start"); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 1766 | if (pContext->preset) { |
| 1767 | if (param != REVERB_PARAM_PRESET) { |
| 1768 | return -EINVAL; |
| 1769 | } |
| 1770 | |
| 1771 | uint16_t preset = *(uint16_t *)pValue; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1772 | ALOGV("set REVERB_PARAM_PRESET, preset %d", preset); |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 1773 | if (preset > REVERB_PRESET_LAST) { |
| 1774 | return -EINVAL; |
| 1775 | } |
| 1776 | pContext->nextPreset = preset; |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1777 | return 0; |
Eric Laurent | a7e5648 | 2010-08-24 14:21:57 -0700 | [diff] [blame] | 1778 | } |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1779 | |
| 1780 | switch (param){ |
| 1781 | case REVERB_PARAM_PROPERTIES: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1782 | ALOGV("\tReverb_setParameter() REVERB_PARAM_PROPERTIES"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1783 | pProperties = (t_reverb_settings *) pValue; |
| 1784 | ReverbSetRoomLevel(pContext, pProperties->roomLevel); |
| 1785 | ReverbSetRoomHfLevel(pContext, pProperties->roomHFLevel); |
| 1786 | ReverbSetDecayTime(pContext, pProperties->decayTime); |
| 1787 | ReverbSetDecayHfRatio(pContext, pProperties->decayHFRatio); |
| 1788 | ReverbSetReverbLevel(pContext, pProperties->reverbLevel); |
| 1789 | ReverbSetDiffusion(pContext, pProperties->diffusion); |
| 1790 | ReverbSetDensity(pContext, pProperties->density); |
| 1791 | break; |
| 1792 | case REVERB_PARAM_ROOM_LEVEL: |
| 1793 | level = *(int16_t *)pValue; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1794 | //ALOGV("\tReverb_setParameter() REVERB_PARAM_ROOM_LEVEL value is %d", level); |
| 1795 | //ALOGV("\tReverb_setParameter() Calling ReverbSetRoomLevel"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1796 | ReverbSetRoomLevel(pContext, level); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1797 | //ALOGV("\tReverb_setParameter() Called ReverbSetRoomLevel"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1798 | break; |
| 1799 | case REVERB_PARAM_ROOM_HF_LEVEL: |
| 1800 | level = *(int16_t *)pValue; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1801 | //ALOGV("\tReverb_setParameter() REVERB_PARAM_ROOM_HF_LEVEL value is %d", level); |
| 1802 | //ALOGV("\tReverb_setParameter() Calling ReverbSetRoomHfLevel"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1803 | ReverbSetRoomHfLevel(pContext, level); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1804 | //ALOGV("\tReverb_setParameter() Called ReverbSetRoomHfLevel"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1805 | break; |
| 1806 | case REVERB_PARAM_DECAY_TIME: |
| 1807 | time = *(uint32_t *)pValue; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1808 | //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_TIME value is %d", time); |
| 1809 | //ALOGV("\tReverb_setParameter() Calling ReverbSetDecayTime"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1810 | ReverbSetDecayTime(pContext, time); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1811 | //ALOGV("\tReverb_setParameter() Called ReverbSetDecayTime"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1812 | break; |
| 1813 | case REVERB_PARAM_DECAY_HF_RATIO: |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1814 | ratio = *(int16_t *)pValue; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1815 | //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_HF_RATIO value is %d", ratio); |
| 1816 | //ALOGV("\tReverb_setParameter() Calling ReverbSetDecayHfRatio"); |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1817 | ReverbSetDecayHfRatio(pContext, ratio); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1818 | //ALOGV("\tReverb_setParameter() Called ReverbSetDecayHfRatio"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1819 | break; |
| 1820 | case REVERB_PARAM_REVERB_LEVEL: |
| 1821 | level = *(int16_t *)pValue; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1822 | //ALOGV("\tReverb_setParameter() REVERB_PARAM_REVERB_LEVEL value is %d", level); |
| 1823 | //ALOGV("\tReverb_setParameter() Calling ReverbSetReverbLevel"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1824 | ReverbSetReverbLevel(pContext, level); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1825 | //ALOGV("\tReverb_setParameter() Called ReverbSetReverbLevel"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1826 | break; |
| 1827 | case REVERB_PARAM_DIFFUSION: |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1828 | ratio = *(int16_t *)pValue; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1829 | //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_DIFFUSION value is %d", ratio); |
| 1830 | //ALOGV("\tReverb_setParameter() Calling ReverbSetDiffusion"); |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1831 | ReverbSetDiffusion(pContext, ratio); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1832 | //ALOGV("\tReverb_setParameter() Called ReverbSetDiffusion"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1833 | break; |
| 1834 | case REVERB_PARAM_DENSITY: |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1835 | ratio = *(int16_t *)pValue; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1836 | //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_DENSITY value is %d", ratio); |
| 1837 | //ALOGV("\tReverb_setParameter() Calling ReverbSetDensity"); |
Eric Laurent | 95d5de0 | 2010-09-08 16:06:18 -0700 | [diff] [blame] | 1838 | ReverbSetDensity(pContext, ratio); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1839 | //ALOGV("\tReverb_setParameter() Called ReverbSetDensity"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1840 | break; |
| 1841 | break; |
| 1842 | case REVERB_PARAM_REFLECTIONS_LEVEL: |
| 1843 | case REVERB_PARAM_REFLECTIONS_DELAY: |
| 1844 | case REVERB_PARAM_REVERB_DELAY: |
| 1845 | break; |
| 1846 | default: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1847 | ALOGV("\tLVM_ERROR : Reverb_setParameter() invalid param %d", param); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1848 | break; |
| 1849 | } |
| 1850 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1851 | //ALOGV("\tReverb_setParameter end"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1852 | return status; |
| 1853 | } /* end Reverb_setParameter */ |
| 1854 | |
| 1855 | } // namespace |
| 1856 | } // namespace |
| 1857 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 1858 | extern "C" { |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1859 | /* Effect Control Interface Implementation: Process */ |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 1860 | int Reverb_process(effect_handle_t self, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1861 | audio_buffer_t *inBuffer, |
| 1862 | audio_buffer_t *outBuffer){ |
| 1863 | android::ReverbContext * pContext = (android::ReverbContext *) self; |
| 1864 | int status = 0; |
| 1865 | |
| 1866 | if (pContext == NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1867 | ALOGV("\tLVM_ERROR : Reverb_process() ERROR pContext == NULL"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1868 | return -EINVAL; |
| 1869 | } |
| 1870 | if (inBuffer == NULL || inBuffer->raw == NULL || |
| 1871 | outBuffer == NULL || outBuffer->raw == NULL || |
| 1872 | inBuffer->frameCount != outBuffer->frameCount){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1873 | ALOGV("\tLVM_ERROR : Reverb_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1874 | return -EINVAL; |
| 1875 | } |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1876 | //ALOGV("\tReverb_process() Calling process with %d frames", outBuffer->frameCount); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1877 | /* Process all the available frames, block processing is handled internalLY by the LVM bundle */ |
| 1878 | status = process( (LVM_INT16 *)inBuffer->raw, |
| 1879 | (LVM_INT16 *)outBuffer->raw, |
| 1880 | outBuffer->frameCount, |
| 1881 | pContext); |
| 1882 | |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 1883 | if (pContext->bEnabled == LVM_FALSE) { |
| 1884 | if (pContext->SamplesToExitCount > 0) { |
| 1885 | pContext->SamplesToExitCount -= outBuffer->frameCount; |
| 1886 | } else { |
| 1887 | status = -ENODATA; |
| 1888 | } |
| 1889 | } |
| 1890 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1891 | return status; |
| 1892 | } /* end Reverb_process */ |
| 1893 | |
| 1894 | /* Effect Control Interface Implementation: Command */ |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 1895 | int Reverb_command(effect_handle_t self, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1896 | uint32_t cmdCode, |
| 1897 | uint32_t cmdSize, |
| 1898 | void *pCmdData, |
| 1899 | uint32_t *replySize, |
| 1900 | void *pReplyData){ |
| 1901 | android::ReverbContext * pContext = (android::ReverbContext *) self; |
| 1902 | int retsize; |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 1903 | LVREV_ControlParams_st ActiveParams; /* Current control Parameters */ |
| 1904 | LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */ |
| 1905 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1906 | |
| 1907 | if (pContext == NULL){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1908 | ALOGV("\tLVM_ERROR : Reverb_command ERROR pContext == NULL"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1909 | return -EINVAL; |
| 1910 | } |
| 1911 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1912 | //ALOGV("\tReverb_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1913 | |
| 1914 | switch (cmdCode){ |
| 1915 | case EFFECT_CMD_INIT: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1916 | //ALOGV("\tReverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1917 | // "EFFECT_CMD_INIT start"); |
| 1918 | |
| 1919 | if (pReplyData == NULL || *replySize != sizeof(int)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1920 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1921 | "EFFECT_CMD_INIT: ERROR"); |
| 1922 | return -EINVAL; |
| 1923 | } |
| 1924 | *(int *) pReplyData = 0; |
| 1925 | break; |
| 1926 | |
| 1927 | case EFFECT_CMD_CONFIGURE: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1928 | //ALOGV("\tReverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1929 | // "EFFECT_CMD_CONFIGURE start"); |
| 1930 | if (pCmdData == NULL|| |
| 1931 | cmdSize != sizeof(effect_config_t)|| |
| 1932 | pReplyData == NULL|| |
| 1933 | *replySize != sizeof(int)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1934 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1935 | "EFFECT_CMD_CONFIGURE: ERROR"); |
| 1936 | return -EINVAL; |
| 1937 | } |
| 1938 | *(int *) pReplyData = Reverb_configure(pContext, (effect_config_t *) pCmdData); |
| 1939 | break; |
| 1940 | |
| 1941 | case EFFECT_CMD_RESET: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1942 | //ALOGV("\tReverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1943 | // "EFFECT_CMD_RESET start"); |
| 1944 | Reverb_configure(pContext, &pContext->config); |
| 1945 | break; |
| 1946 | |
| 1947 | case EFFECT_CMD_GET_PARAM:{ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1948 | //ALOGV("\tReverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1949 | // "EFFECT_CMD_GET_PARAM start"); |
| 1950 | if (pCmdData == NULL || |
| 1951 | cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || |
| 1952 | pReplyData == NULL || |
| 1953 | *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1954 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1955 | "EFFECT_CMD_GET_PARAM: ERROR"); |
| 1956 | return -EINVAL; |
| 1957 | } |
| 1958 | effect_param_t *p = (effect_param_t *)pCmdData; |
| 1959 | |
| 1960 | memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); |
| 1961 | |
| 1962 | p = (effect_param_t *)pReplyData; |
| 1963 | |
| 1964 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 1965 | |
| 1966 | p->status = android::Reverb_getParameter(pContext, |
| 1967 | (void *)p->data, |
| 1968 | (size_t *)&p->vsize, |
| 1969 | p->data + voffset); |
| 1970 | |
| 1971 | *replySize = sizeof(effect_param_t) + voffset + p->vsize; |
| 1972 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1973 | //ALOGV("\tReverb_command EFFECT_CMD_GET_PARAM " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1974 | // "*pCmdData %d, *replySize %d, *pReplyData %d ", |
| 1975 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 1976 | // *replySize, |
| 1977 | // *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); |
| 1978 | |
| 1979 | } break; |
| 1980 | case EFFECT_CMD_SET_PARAM:{ |
| 1981 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1982 | //ALOGV("\tReverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1983 | // "EFFECT_CMD_SET_PARAM start"); |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1984 | //ALOGV("\tReverb_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1985 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 1986 | // *replySize, |
| 1987 | // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); |
| 1988 | |
| 1989 | if (pCmdData == NULL || (cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t))) |
| 1990 | || pReplyData == NULL || *replySize != (int)sizeof(int32_t)) { |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1991 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1992 | "EFFECT_CMD_SET_PARAM: ERROR"); |
| 1993 | return -EINVAL; |
| 1994 | } |
| 1995 | |
| 1996 | effect_param_t *p = (effect_param_t *) pCmdData; |
| 1997 | |
| 1998 | if (p->psize != sizeof(int32_t)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 1999 | ALOGV("\t4LVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2000 | "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)"); |
| 2001 | return -EINVAL; |
| 2002 | } |
| 2003 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2004 | //ALOGV("\tn5Reverb_command cmdSize is %d\n" |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2005 | // "\tsizeof(effect_param_t) is %d\n" |
| 2006 | // "\tp->psize is %d\n" |
| 2007 | // "\tp->vsize is %d" |
| 2008 | // "\n", |
| 2009 | // cmdSize, sizeof(effect_param_t), p->psize, p->vsize ); |
| 2010 | |
| 2011 | *(int *)pReplyData = android::Reverb_setParameter(pContext, |
| 2012 | (void *)p->data, |
| 2013 | p->data + p->psize); |
| 2014 | } break; |
| 2015 | |
| 2016 | case EFFECT_CMD_ENABLE: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2017 | //ALOGV("\tReverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2018 | // "EFFECT_CMD_ENABLE start"); |
| 2019 | |
| 2020 | if (pReplyData == NULL || *replySize != sizeof(int)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2021 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2022 | "EFFECT_CMD_ENABLE: ERROR"); |
| 2023 | return -EINVAL; |
| 2024 | } |
| 2025 | if(pContext->bEnabled == LVM_TRUE){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2026 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2027 | "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); |
| 2028 | return -EINVAL; |
| 2029 | } |
| 2030 | *(int *)pReplyData = 0; |
| 2031 | pContext->bEnabled = LVM_TRUE; |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 2032 | /* Get the current settings */ |
| 2033 | LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams); |
| 2034 | LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "EFFECT_CMD_ENABLE") |
| 2035 | pContext->SamplesToExitCount = |
| 2036 | (ActiveParams.T60 * pContext->config.inputCfg.samplingRate)/1000; |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 2037 | // force no volume ramp for first buffer processed after enabling the effect |
| 2038 | pContext->volumeMode = android::REVERB_VOLUME_FLAT; |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2039 | //ALOGV("\tEFFECT_CMD_ENABLE SamplesToExitCount = %d", pContext->SamplesToExitCount); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2040 | break; |
| 2041 | case EFFECT_CMD_DISABLE: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2042 | //ALOGV("\tReverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2043 | // "EFFECT_CMD_DISABLE start"); |
| 2044 | |
| 2045 | if (pReplyData == NULL || *replySize != sizeof(int)){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2046 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2047 | "EFFECT_CMD_DISABLE: ERROR"); |
| 2048 | return -EINVAL; |
| 2049 | } |
| 2050 | if(pContext->bEnabled == LVM_FALSE){ |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2051 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2052 | "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); |
| 2053 | return -EINVAL; |
| 2054 | } |
| 2055 | *(int *)pReplyData = 0; |
| 2056 | pContext->bEnabled = LVM_FALSE; |
| 2057 | break; |
| 2058 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2059 | case EFFECT_CMD_SET_VOLUME: |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 2060 | if (pCmdData == NULL || |
| 2061 | cmdSize != 2 * sizeof(uint32_t)) { |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2062 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 2063 | "EFFECT_CMD_SET_VOLUME: ERROR"); |
| 2064 | return -EINVAL; |
| 2065 | } |
| 2066 | |
| 2067 | |
| 2068 | if (pReplyData != NULL) { // we have volume control |
| 2069 | pContext->leftVolume = (LVM_INT16)((*(uint32_t *)pCmdData + (1 << 11)) >> 12); |
| 2070 | pContext->rightVolume = (LVM_INT16)((*((uint32_t *)pCmdData + 1) + (1 << 11)) >> 12); |
| 2071 | *(uint32_t *)pReplyData = (1 << 24); |
| 2072 | *((uint32_t *)pReplyData + 1) = (1 << 24); |
| 2073 | if (pContext->volumeMode == android::REVERB_VOLUME_OFF) { |
| 2074 | // force no volume ramp for first buffer processed after getting volume control |
| 2075 | pContext->volumeMode = android::REVERB_VOLUME_FLAT; |
| 2076 | } |
| 2077 | } else { // we don't have volume control |
| 2078 | pContext->leftVolume = REVERB_UNIT_VOLUME; |
| 2079 | pContext->rightVolume = REVERB_UNIT_VOLUME; |
| 2080 | pContext->volumeMode = android::REVERB_VOLUME_OFF; |
| 2081 | } |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2082 | ALOGV("EFFECT_CMD_SET_VOLUME left %d, right %d mode %d", |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 2083 | pContext->leftVolume, pContext->rightVolume, pContext->volumeMode); |
| 2084 | break; |
| 2085 | |
| 2086 | case EFFECT_CMD_SET_DEVICE: |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2087 | case EFFECT_CMD_SET_AUDIO_MODE: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2088 | //ALOGV("\tReverb_command cmdCode Case: " |
Eric Laurent | 5fa6df6 | 2010-09-02 17:18:20 -0700 | [diff] [blame] | 2089 | // "EFFECT_CMD_SET_DEVICE/EFFECT_CMD_SET_VOLUME/EFFECT_CMD_SET_AUDIO_MODE start"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2090 | break; |
| 2091 | |
| 2092 | default: |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2093 | ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: " |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2094 | "DEFAULT start %d ERROR",cmdCode); |
| 2095 | return -EINVAL; |
| 2096 | } |
| 2097 | |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2098 | //ALOGV("\tReverb_command end\n\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2099 | return 0; |
| 2100 | } /* end Reverb_command */ |
| 2101 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 2102 | /* Effect Control Interface Implementation: get_descriptor */ |
| 2103 | int Reverb_getDescriptor(effect_handle_t self, |
| 2104 | effect_descriptor_t *pDescriptor) |
| 2105 | { |
| 2106 | android::ReverbContext * pContext = (android::ReverbContext *)self; |
| 2107 | const effect_descriptor_t *desc; |
| 2108 | |
| 2109 | if (pContext == NULL || pDescriptor == NULL) { |
Steve Block | 06ade6a | 2011-10-20 11:56:00 +0100 | [diff] [blame^] | 2110 | ALOGV("Reverb_getDescriptor() invalid param"); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 2111 | return -EINVAL; |
| 2112 | } |
| 2113 | |
| 2114 | if (pContext->auxiliary) { |
| 2115 | if (pContext->preset) { |
| 2116 | desc = &android::gAuxPresetReverbDescriptor; |
| 2117 | } else { |
| 2118 | desc = &android::gAuxEnvReverbDescriptor; |
| 2119 | } |
| 2120 | } else { |
| 2121 | if (pContext->preset) { |
| 2122 | desc = &android::gInsertPresetReverbDescriptor; |
| 2123 | } else { |
| 2124 | desc = &android::gInsertEnvReverbDescriptor; |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | memcpy(pDescriptor, desc, sizeof(effect_descriptor_t)); |
| 2129 | |
| 2130 | return 0; |
| 2131 | } /* end Reverb_getDescriptor */ |
| 2132 | |
| 2133 | // effect_handle_t interface implementation for Reverb effect |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2134 | const struct effect_interface_s gReverbInterface = { |
| 2135 | Reverb_process, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 2136 | Reverb_command, |
Eric Laurent | 325b8e8 | 2011-06-17 18:54:16 -0700 | [diff] [blame] | 2137 | Reverb_getDescriptor, |
| 2138 | NULL, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2139 | }; /* end gReverbInterface */ |
| 2140 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 2141 | audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = { |
| 2142 | tag : AUDIO_EFFECT_LIBRARY_TAG, |
| 2143 | version : EFFECT_LIBRARY_API_VERSION, |
| 2144 | name : "Reverb Library", |
| 2145 | implementor : "NXP Software Ltd.", |
| 2146 | query_num_effects : android::EffectQueryNumberEffects, |
| 2147 | query_effect : android::EffectQueryEffect, |
| 2148 | create_effect : android::EffectCreate, |
| 2149 | release_effect : android::EffectRelease, |
| 2150 | get_descriptor : android::EffectGetDescriptor, |
| 2151 | }; |
| 2152 | |
| 2153 | } |