Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -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 "Bundle" |
| 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 | 2c87e9c | 2010-07-09 12:28:50 -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 <EffectBundle.h> |
| 28 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 29 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 30 | // effect_handle_t interface implementation for bass boost |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 31 | extern "C" const struct effect_interface_s gLvmEffectInterface; |
| 32 | |
| 33 | #define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\ |
| 34 | if (LvmStatus == LVM_NULLADDRESS){\ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 35 | ALOGV("\tLVM_ERROR : Parameter error - "\ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 36 | "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\ |
| 37 | }\ |
| 38 | if (LvmStatus == LVM_ALIGNMENTERROR){\ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 39 | ALOGV("\tLVM_ERROR : Parameter error - "\ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 40 | "bad alignment returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\ |
| 41 | }\ |
| 42 | if (LvmStatus == LVM_INVALIDNUMSAMPLES){\ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 43 | ALOGV("\tLVM_ERROR : Parameter error - "\ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 44 | "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\ |
| 45 | }\ |
| 46 | if (LvmStatus == LVM_OUTOFRANGE){\ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 47 | ALOGV("\tLVM_ERROR : Parameter error - "\ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 48 | "out of range returned by %s in %s\n", callingFunc, calledFunc);\ |
| 49 | }\ |
| 50 | } |
| 51 | |
Eric Laurent | 8b4529e | 2011-10-31 17:36:03 -0700 | [diff] [blame] | 52 | |
| 53 | static inline int16_t clamp16(int32_t sample) |
| 54 | { |
| 55 | // check overflow for both positive and negative values: |
| 56 | // all bits above short range must me equal to sign bit |
| 57 | if ((sample>>15) ^ (sample>>31)) |
| 58 | sample = 0x7FFF ^ (sample>>31); |
| 59 | return sample; |
| 60 | } |
| 61 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 62 | // Namespaces |
| 63 | namespace android { |
| 64 | namespace { |
| 65 | |
Eric Laurent | 9b44c66 | 2011-03-01 12:18:41 -0800 | [diff] [blame] | 66 | // Flag to allow a one time init of global memory, only happens on first call ever |
| 67 | int LvmInitFlag = LVM_FALSE; |
| 68 | SessionContext GlobalSessionMemory[LVM_MAX_SESSIONS]; |
| 69 | int SessionIndex[LVM_MAX_SESSIONS]; |
| 70 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 71 | /* local functions */ |
| 72 | #define CHECK_ARG(cond) { \ |
| 73 | if (!(cond)) { \ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 74 | ALOGV("\tLVM_ERROR : Invalid argument: "#cond); \ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 75 | return -EINVAL; \ |
| 76 | } \ |
| 77 | } |
| 78 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 79 | |
| 80 | // NXP SW BassBoost UUID |
| 81 | const effect_descriptor_t gBassBoostDescriptor = { |
| 82 | {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, |
| 83 | {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 84 | EFFECT_CONTROL_API_VERSION, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 85 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND |
| 86 | | EFFECT_FLAG_VOLUME_CTRL), |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 87 | BASS_BOOST_CUP_LOAD_ARM9E, |
| 88 | BUNDLE_MEM_USAGE, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 89 | "Dynamic Bass Boost", |
| 90 | "NXP Software Ltd.", |
| 91 | }; |
| 92 | |
| 93 | // NXP SW Virtualizer UUID |
| 94 | const effect_descriptor_t gVirtualizerDescriptor = { |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 95 | {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
| 96 | {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 97 | EFFECT_CONTROL_API_VERSION, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 98 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND |
| 99 | | EFFECT_FLAG_VOLUME_CTRL), |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 100 | VIRTUALIZER_CUP_LOAD_ARM9E, |
| 101 | BUNDLE_MEM_USAGE, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 102 | "Virtualizer", |
| 103 | "NXP Software Ltd.", |
| 104 | }; |
| 105 | |
| 106 | // NXP SW Equalizer UUID |
| 107 | const effect_descriptor_t gEqualizerDescriptor = { |
| 108 | {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type |
| 109 | {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 110 | EFFECT_CONTROL_API_VERSION, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 111 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL), |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 112 | EQUALIZER_CUP_LOAD_ARM9E, |
| 113 | BUNDLE_MEM_USAGE, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 114 | "Equalizer", |
| 115 | "NXP Software Ltd.", |
| 116 | }; |
| 117 | |
| 118 | // NXP SW Volume UUID |
| 119 | const effect_descriptor_t gVolumeDescriptor = { |
| 120 | {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 121 | {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 122 | EFFECT_CONTROL_API_VERSION, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 123 | (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL), |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 124 | VOLUME_CUP_LOAD_ARM9E, |
| 125 | BUNDLE_MEM_USAGE, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 126 | "Volume", |
| 127 | "NXP Software Ltd.", |
| 128 | }; |
| 129 | |
| 130 | //--- local function prototypes |
| 131 | void LvmGlobalBundle_init (void); |
| 132 | int LvmBundle_init (EffectContext *pContext); |
| 133 | int LvmEffect_enable (EffectContext *pContext); |
| 134 | int LvmEffect_disable (EffectContext *pContext); |
| 135 | void LvmEffect_free (EffectContext *pContext); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 136 | int Effect_configure (EffectContext *pContext, effect_config_t *pConfig); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 137 | int BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 138 | int BassBoost_getParameter (EffectContext *pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 139 | void *pParam, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 140 | size_t *pValueSize, |
| 141 | void *pValue); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 142 | int Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 143 | int Virtualizer_getParameter (EffectContext *pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 144 | void *pParam, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 145 | size_t *pValueSize, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 146 | void *pValue); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 147 | int Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 148 | int Equalizer_getParameter (EffectContext *pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 149 | void *pParam, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 150 | size_t *pValueSize, |
| 151 | void *pValue); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 152 | int Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 153 | int Volume_getParameter (EffectContext *pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 154 | void *pParam, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 155 | size_t *pValueSize, |
| 156 | void *pValue); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 157 | int Effect_setEnabled(EffectContext *pContext, bool enabled); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 158 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 159 | /* Effect Library Interface Implementation */ |
| 160 | extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 161 | ALOGV("\n\tEffectQueryNumberEffects start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 162 | *pNumEffects = 4; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 163 | ALOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects); |
| 164 | ALOGV("\tEffectQueryNumberEffects end\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 165 | return 0; |
| 166 | } /* end EffectQueryNumberEffects */ |
| 167 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 168 | extern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 169 | ALOGV("\n\tEffectQueryEffect start"); |
| 170 | ALOGV("\tEffectQueryEffect processing index %d", index); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 171 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 172 | if (pDescriptor == NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 173 | ALOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 174 | return -EINVAL; |
| 175 | } |
| 176 | if (index > 3){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 177 | ALOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 178 | return -ENOENT; |
| 179 | } |
| 180 | if(index == LVM_BASS_BOOST){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 181 | ALOGV("\tEffectQueryEffect processing LVM_BASS_BOOST"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 182 | memcpy(pDescriptor, &gBassBoostDescriptor, sizeof(effect_descriptor_t)); |
| 183 | }else if(index == LVM_VIRTUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 184 | ALOGV("\tEffectQueryEffect processing LVM_VIRTUALIZER"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 185 | memcpy(pDescriptor, &gVirtualizerDescriptor, sizeof(effect_descriptor_t)); |
| 186 | } else if(index == LVM_EQUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 187 | ALOGV("\tEffectQueryEffect processing LVM_EQUALIZER"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 188 | memcpy(pDescriptor, &gEqualizerDescriptor, sizeof(effect_descriptor_t)); |
| 189 | } else if(index == LVM_VOLUME){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 190 | ALOGV("\tEffectQueryEffect processing LVM_VOLUME"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 191 | memcpy(pDescriptor, &gVolumeDescriptor, sizeof(effect_descriptor_t)); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 192 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 193 | ALOGV("\tEffectQueryEffect end\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 194 | return 0; |
| 195 | } /* end EffectQueryEffect */ |
| 196 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 197 | extern "C" int EffectCreate(effect_uuid_t *uuid, |
| 198 | int32_t sessionId, |
| 199 | int32_t ioId, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 200 | effect_handle_t *pHandle){ |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 201 | int ret = 0; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 202 | int sessionNo; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 203 | int i; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 204 | EffectContext *pContext = NULL; |
| 205 | bool newBundle = false; |
| 206 | SessionContext *pSessionContext; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 207 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 208 | ALOGV("\n\tEffectCreate start session %d", sessionId); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 209 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 210 | if (pHandle == NULL || uuid == NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 211 | ALOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 212 | ret = -EINVAL; |
| 213 | goto exit; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 216 | if(LvmInitFlag == LVM_FALSE){ |
| 217 | LvmInitFlag = LVM_TRUE; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 218 | ALOGV("\tEffectCreate - Initializing all global memory"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 219 | LvmGlobalBundle_init(); |
| 220 | } |
| 221 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 222 | // Find next available sessionNo |
| 223 | for(i=0; i<LVM_MAX_SESSIONS; i++){ |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 224 | if((SessionIndex[i] == LVM_UNUSED_SESSION)||(SessionIndex[i] == sessionId)){ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 225 | sessionNo = i; |
| 226 | SessionIndex[i] = sessionId; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 227 | ALOGV("\tEffectCreate: Allocating SessionNo %d for SessionId %d\n", sessionNo,sessionId); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 228 | break; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | if(i==LVM_MAX_SESSIONS){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 233 | ALOGV("\tLVM_ERROR : Cannot find memory to allocate for current session"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 234 | ret = -EINVAL; |
| 235 | goto exit; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 236 | } |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 237 | |
| 238 | pContext = new EffectContext; |
| 239 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 240 | // If this is the first create in this session |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 241 | if(GlobalSessionMemory[sessionNo].bBundledEffectsEnabled == LVM_FALSE){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 242 | ALOGV("\tEffectCreate - This is the first effect in current sessionId %d sessionNo %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 243 | sessionId, sessionNo); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 244 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 245 | GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_TRUE; |
| 246 | GlobalSessionMemory[sessionNo].pBundledContext = new BundledEffectContext; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 247 | newBundle = true; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 248 | |
| 249 | pContext->pBundledContext = GlobalSessionMemory[sessionNo].pBundledContext; |
| 250 | pContext->pBundledContext->SessionNo = sessionNo; |
| 251 | pContext->pBundledContext->SessionId = sessionId; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 252 | pContext->pBundledContext->hInstance = NULL; |
| 253 | pContext->pBundledContext->bVolumeEnabled = LVM_FALSE; |
| 254 | pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE; |
| 255 | pContext->pBundledContext->bBassEnabled = LVM_FALSE; |
| 256 | pContext->pBundledContext->bBassTempDisabled = LVM_FALSE; |
| 257 | pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE; |
| 258 | pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE; |
| 259 | pContext->pBundledContext->NumberEffectsEnabled = 0; |
| 260 | pContext->pBundledContext->NumberEffectsCalled = 0; |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 261 | pContext->pBundledContext->firstVolume = LVM_TRUE; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 262 | |
| 263 | #ifdef LVM_PCM |
Eric Laurent | a92ebfa | 2010-08-31 13:50:07 -0700 | [diff] [blame] | 264 | char fileName[256]; |
| 265 | snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_in.pcm", pContext->pBundledContext); |
| 266 | pContext->pBundledContext->PcmInPtr = fopen(fileName, "w"); |
| 267 | if (pContext->pBundledContext->PcmInPtr == NULL) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 268 | ALOGV("cannot open %s", fileName); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 269 | ret = -EINVAL; |
| 270 | goto exit; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 271 | } |
Eric Laurent | a92ebfa | 2010-08-31 13:50:07 -0700 | [diff] [blame] | 272 | |
| 273 | snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_out.pcm", pContext->pBundledContext); |
| 274 | pContext->pBundledContext->PcmOutPtr = fopen(fileName, "w"); |
| 275 | if (pContext->pBundledContext->PcmOutPtr == NULL) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 276 | ALOGV("cannot open %s", fileName); |
Eric Laurent | a92ebfa | 2010-08-31 13:50:07 -0700 | [diff] [blame] | 277 | fclose(pContext->pBundledContext->PcmInPtr); |
| 278 | pContext->pBundledContext->PcmInPtr = NULL; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 279 | ret = -EINVAL; |
| 280 | goto exit; |
Eric Laurent | a92ebfa | 2010-08-31 13:50:07 -0700 | [diff] [blame] | 281 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 282 | #endif |
| 283 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 284 | /* Saved strength is used to return the exact strength that was used in the set to the get |
| 285 | * because we map the original strength range of 0:1000 to 1:15, and this will avoid |
| 286 | * quantisation like effect when returning |
| 287 | */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 288 | pContext->pBundledContext->BassStrengthSaved = 0; |
| 289 | pContext->pBundledContext->VirtStrengthSaved = 0; |
| 290 | pContext->pBundledContext->CurPreset = PRESET_CUSTOM; |
| 291 | pContext->pBundledContext->levelSaved = 0; |
| 292 | pContext->pBundledContext->bMuteEnabled = LVM_FALSE; |
| 293 | pContext->pBundledContext->bStereoPositionEnabled = LVM_FALSE; |
| 294 | pContext->pBundledContext->positionSaved = 0; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 295 | pContext->pBundledContext->workBuffer = NULL; |
| 296 | pContext->pBundledContext->frameCount = -1; |
| 297 | pContext->pBundledContext->SamplesToExitCountVirt = 0; |
| 298 | pContext->pBundledContext->SamplesToExitCountBb = 0; |
| 299 | pContext->pBundledContext->SamplesToExitCountEq = 0; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 300 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 301 | ALOGV("\tEffectCreate - Calling LvmBundle_init"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 302 | ret = LvmBundle_init(pContext); |
| 303 | |
| 304 | if (ret < 0){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 305 | ALOGV("\tLVM_ERROR : EffectCreate() Bundle init failed"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 306 | goto exit; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 310 | ALOGV("\tEffectCreate - Assigning memory for previously created effect on sessionNo %d", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 311 | sessionNo); |
| 312 | pContext->pBundledContext = |
| 313 | GlobalSessionMemory[sessionNo].pBundledContext; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 314 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 315 | ALOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 316 | |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 317 | pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo]; |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 318 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 319 | // Create each Effect |
| 320 | if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){ |
| 321 | // Create Bass Boost |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 322 | ALOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 323 | pSessionContext->bBassInstantiated = LVM_TRUE; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 324 | pContext->pBundledContext->SamplesToExitCountBb = 0; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 325 | |
| 326 | pContext->itfe = &gLvmEffectInterface; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 327 | pContext->EffectType = LVM_BASS_BOOST; |
| 328 | } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){ |
| 329 | // Create Virtualizer |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 330 | ALOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 331 | pSessionContext->bVirtualizerInstantiated=LVM_TRUE; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 332 | pContext->pBundledContext->SamplesToExitCountVirt = 0; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 333 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 334 | pContext->itfe = &gLvmEffectInterface; |
| 335 | pContext->EffectType = LVM_VIRTUALIZER; |
| 336 | } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){ |
| 337 | // Create Equalizer |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 338 | ALOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 339 | pSessionContext->bEqualizerInstantiated = LVM_TRUE; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 340 | pContext->pBundledContext->SamplesToExitCountEq = 0; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 341 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 342 | pContext->itfe = &gLvmEffectInterface; |
| 343 | pContext->EffectType = LVM_EQUALIZER; |
| 344 | } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){ |
| 345 | // Create Volume |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 346 | ALOGV("\tEffectCreate - Effect to be created is LVM_VOLUME"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 347 | pSessionContext->bVolumeInstantiated = LVM_TRUE; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 348 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 349 | pContext->itfe = &gLvmEffectInterface; |
| 350 | pContext->EffectType = LVM_VOLUME; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 351 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 352 | else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 353 | ALOGV("\tLVM_ERROR : EffectCreate() invalid UUID"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 354 | ret = -EINVAL; |
| 355 | goto exit; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 358 | exit: |
| 359 | if (ret != 0) { |
| 360 | if (pContext != NULL) { |
| 361 | if (newBundle) { |
| 362 | GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_FALSE; |
| 363 | SessionIndex[sessionNo] = LVM_UNUSED_SESSION; |
| 364 | delete pContext->pBundledContext; |
| 365 | } |
| 366 | delete pContext; |
| 367 | } |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 368 | *pHandle = (effect_handle_t)NULL; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 369 | } else { |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 370 | *pHandle = (effect_handle_t)pContext; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 371 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 372 | ALOGV("\tEffectCreate end..\n\n"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 373 | return ret; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 374 | } /* end EffectCreate */ |
| 375 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 376 | extern "C" int EffectRelease(effect_handle_t handle){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 377 | ALOGV("\n\tEffectRelease start %p", handle); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 378 | EffectContext * pContext = (EffectContext *)handle; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 379 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 380 | ALOGV("\tEffectRelease start handle: %p, context %p", handle, pContext->pBundledContext); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 381 | if (pContext == NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 382 | ALOGV("\tLVM_ERROR : EffectRelease called with NULL pointer"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 383 | return -EINVAL; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 384 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 385 | |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 386 | SessionContext *pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo]; |
| 387 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 388 | // Clear the instantiated flag for the effect |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 389 | // protect agains the case where an effect is un-instantiated without being disabled |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 390 | if(pContext->EffectType == LVM_BASS_BOOST) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 391 | ALOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 392 | pSessionContext->bBassInstantiated = LVM_FALSE; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 393 | if(pContext->pBundledContext->SamplesToExitCountBb > 0){ |
| 394 | pContext->pBundledContext->NumberEffectsEnabled--; |
| 395 | } |
| 396 | pContext->pBundledContext->SamplesToExitCountBb = 0; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 397 | } else if(pContext->EffectType == LVM_VIRTUALIZER) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 398 | ALOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 399 | pSessionContext->bVirtualizerInstantiated = LVM_FALSE; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 400 | if(pContext->pBundledContext->SamplesToExitCountVirt > 0){ |
| 401 | pContext->pBundledContext->NumberEffectsEnabled--; |
| 402 | } |
| 403 | pContext->pBundledContext->SamplesToExitCountVirt = 0; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 404 | } else if(pContext->EffectType == LVM_EQUALIZER) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 405 | ALOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 406 | pSessionContext->bEqualizerInstantiated =LVM_FALSE; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 407 | if(pContext->pBundledContext->SamplesToExitCountEq > 0){ |
| 408 | pContext->pBundledContext->NumberEffectsEnabled--; |
| 409 | } |
| 410 | pContext->pBundledContext->SamplesToExitCountEq = 0; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 411 | } else if(pContext->EffectType == LVM_VOLUME) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 412 | ALOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 413 | pSessionContext->bVolumeInstantiated = LVM_FALSE; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 414 | if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){ |
| 415 | pContext->pBundledContext->NumberEffectsEnabled--; |
| 416 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 417 | } else { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 418 | ALOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 419 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 420 | |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 421 | // Disable effect, in this case ignore errors (return codes) |
| 422 | // if an effect has already been disabled |
| 423 | Effect_setEnabled(pContext, LVM_FALSE); |
| 424 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 425 | // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 426 | if ((pSessionContext->bBassInstantiated == LVM_FALSE) && |
| 427 | (pSessionContext->bVolumeInstantiated == LVM_FALSE) && |
| 428 | (pSessionContext->bEqualizerInstantiated ==LVM_FALSE) && |
| 429 | (pSessionContext->bVirtualizerInstantiated==LVM_FALSE)) |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 430 | { |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 431 | #ifdef LVM_PCM |
Eric Laurent | a92ebfa | 2010-08-31 13:50:07 -0700 | [diff] [blame] | 432 | if (pContext->pBundledContext->PcmInPtr != NULL) { |
| 433 | fclose(pContext->pBundledContext->PcmInPtr); |
| 434 | pContext->pBundledContext->PcmInPtr = NULL; |
| 435 | } |
| 436 | if (pContext->pBundledContext->PcmOutPtr != NULL) { |
| 437 | fclose(pContext->pBundledContext->PcmOutPtr); |
| 438 | pContext->pBundledContext->PcmOutPtr = NULL; |
| 439 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 440 | #endif |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 441 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 442 | |
| 443 | // Clear the SessionIndex |
| 444 | for(int i=0; i<LVM_MAX_SESSIONS; i++){ |
| 445 | if(SessionIndex[i] == pContext->pBundledContext->SessionId){ |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 446 | SessionIndex[i] = LVM_UNUSED_SESSION; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 447 | ALOGV("\tEffectRelease: Clearing SessionIndex SessionNo %d for SessionId %d\n", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 448 | i, pContext->pBundledContext->SessionId); |
| 449 | break; |
| 450 | } |
| 451 | } |
| 452 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 453 | ALOGV("\tEffectRelease: All effects are no longer instantiated\n"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 454 | pSessionContext->bBundledEffectsEnabled = LVM_FALSE; |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 455 | pSessionContext->pBundledContext = LVM_NULL; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 456 | ALOGV("\tEffectRelease: Freeing LVM Bundle memory\n"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 457 | LvmEffect_free(pContext); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 458 | ALOGV("\tEffectRelease: Deleting LVM Bundle context %p\n", pContext->pBundledContext); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 459 | if (pContext->pBundledContext->workBuffer != NULL) { |
| 460 | free(pContext->pBundledContext->workBuffer); |
| 461 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 462 | delete pContext->pBundledContext; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 463 | pContext->pBundledContext = LVM_NULL; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 464 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 465 | // free the effect context for current effect |
| 466 | delete pContext; |
| 467 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 468 | ALOGV("\tEffectRelease end\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 469 | return 0; |
| 470 | |
| 471 | } /* end EffectRelease */ |
| 472 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 473 | extern "C" int EffectGetDescriptor(effect_uuid_t *uuid, |
| 474 | effect_descriptor_t *pDescriptor) { |
| 475 | const effect_descriptor_t *desc = NULL; |
| 476 | |
| 477 | if (pDescriptor == NULL || uuid == NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 478 | ALOGV("EffectGetDescriptor() called with NULL pointer"); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 479 | return -EINVAL; |
| 480 | } |
| 481 | |
| 482 | if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0) { |
| 483 | desc = &gBassBoostDescriptor; |
| 484 | } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) { |
| 485 | desc = &gVirtualizerDescriptor; |
| 486 | } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) { |
| 487 | desc = &gEqualizerDescriptor; |
| 488 | } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0) { |
| 489 | desc = &gVolumeDescriptor; |
| 490 | } |
| 491 | |
| 492 | if (desc == NULL) { |
| 493 | return -EINVAL; |
| 494 | } |
| 495 | |
| 496 | memcpy(pDescriptor, desc, sizeof(effect_descriptor_t)); |
| 497 | |
| 498 | return 0; |
| 499 | } /* end EffectGetDescriptor */ |
| 500 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 501 | void LvmGlobalBundle_init(){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 502 | ALOGV("\tLvmGlobalBundle_init start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 503 | for(int i=0; i<LVM_MAX_SESSIONS; i++){ |
| 504 | GlobalSessionMemory[i].bBundledEffectsEnabled = LVM_FALSE; |
| 505 | GlobalSessionMemory[i].bVolumeInstantiated = LVM_FALSE; |
| 506 | GlobalSessionMemory[i].bEqualizerInstantiated = LVM_FALSE; |
| 507 | GlobalSessionMemory[i].bBassInstantiated = LVM_FALSE; |
| 508 | GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE; |
| 509 | GlobalSessionMemory[i].pBundledContext = LVM_NULL; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 510 | |
Eric Laurent | 27a2fdf | 2010-09-10 17:44:44 -0700 | [diff] [blame] | 511 | SessionIndex[i] = LVM_UNUSED_SESSION; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 512 | } |
| 513 | return; |
| 514 | } |
| 515 | //---------------------------------------------------------------------------- |
| 516 | // LvmBundle_init() |
| 517 | //---------------------------------------------------------------------------- |
| 518 | // Purpose: Initialize engine with default configuration, creates instance |
| 519 | // with all effects disabled. |
| 520 | // |
| 521 | // Inputs: |
| 522 | // pContext: effect engine context |
| 523 | // |
| 524 | // Outputs: |
| 525 | // |
| 526 | //---------------------------------------------------------------------------- |
| 527 | |
| 528 | int LvmBundle_init(EffectContext *pContext){ |
| 529 | int status; |
| 530 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 531 | ALOGV("\tLvmBundle_init start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 532 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 533 | pContext->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ; |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 534 | pContext->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 535 | pContext->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 536 | pContext->config.inputCfg.samplingRate = 44100; |
| 537 | pContext->config.inputCfg.bufferProvider.getBuffer = NULL; |
| 538 | pContext->config.inputCfg.bufferProvider.releaseBuffer = NULL; |
| 539 | pContext->config.inputCfg.bufferProvider.cookie = NULL; |
| 540 | pContext->config.inputCfg.mask = EFFECT_CONFIG_ALL; |
| 541 | pContext->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE; |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 542 | pContext->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO; |
| 543 | pContext->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 544 | pContext->config.outputCfg.samplingRate = 44100; |
| 545 | pContext->config.outputCfg.bufferProvider.getBuffer = NULL; |
| 546 | pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL; |
| 547 | pContext->config.outputCfg.bufferProvider.cookie = NULL; |
| 548 | pContext->config.outputCfg.mask = EFFECT_CONFIG_ALL; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 549 | |
| 550 | CHECK_ARG(pContext != NULL); |
| 551 | |
| 552 | if (pContext->pBundledContext->hInstance != NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 553 | ALOGV("\tLvmBundle_init pContext->pBassBoost != NULL " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 554 | "-> Calling pContext->pBassBoost->free()"); |
| 555 | |
| 556 | LvmEffect_free(pContext); |
| 557 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 558 | ALOGV("\tLvmBundle_init pContext->pBassBoost != NULL " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 559 | "-> Called pContext->pBassBoost->free()"); |
| 560 | } |
| 561 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 562 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
| 563 | LVM_ControlParams_t params; /* Control Parameters */ |
| 564 | LVM_InstParams_t InstParams; /* Instance parameters */ |
| 565 | LVM_EQNB_BandDef_t BandDefs[MAX_NUM_BANDS]; /* Equaliser band definitions */ |
| 566 | LVM_HeadroomParams_t HeadroomParams; /* Headroom parameters */ |
| 567 | LVM_HeadroomBandDef_t HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS]; |
| 568 | LVM_MemTab_t MemTab; /* Memory allocation table */ |
| 569 | bool bMallocFailure = LVM_FALSE; |
| 570 | |
| 571 | /* Set the capabilities */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 572 | InstParams.BufferMode = LVM_UNMANAGED_BUFFERS; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 573 | InstParams.MaxBlockSize = MAX_CALL_SIZE; |
| 574 | InstParams.EQNB_NumBands = MAX_NUM_BANDS; |
| 575 | InstParams.PSA_Included = LVM_PSA_ON; |
| 576 | |
| 577 | /* Allocate memory, forcing alignment */ |
| 578 | LvmStatus = LVM_GetMemoryTable(LVM_NULL, |
| 579 | &MemTab, |
| 580 | &InstParams); |
| 581 | |
| 582 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init") |
| 583 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 584 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 585 | ALOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 586 | |
| 587 | /* Allocate memory */ |
| 588 | for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){ |
| 589 | if (MemTab.Region[i].Size != 0){ |
| 590 | MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size); |
| 591 | |
| 592 | if (MemTab.Region[i].pBaseAddress == LVM_NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 593 | ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes " |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 594 | "for region %u\n", MemTab.Region[i].Size, i ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 595 | bMallocFailure = LVM_TRUE; |
| 596 | }else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 597 | ALOGV("\tLvmBundle_init CreateInstance allocated %ld bytes for region %u at %p\n", |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 598 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | /* If one or more of the memory regions failed to allocate, free the regions that were |
| 604 | * succesfully allocated and return with an error |
| 605 | */ |
| 606 | if(bMallocFailure == LVM_TRUE){ |
| 607 | for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){ |
| 608 | if (MemTab.Region[i].pBaseAddress == LVM_NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 609 | ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes " |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 610 | "for region %u Not freeing\n", MemTab.Region[i].Size, i ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 611 | }else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 612 | ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %ld bytes " |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 613 | "for region %u at %p- free\n", |
| 614 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 615 | free(MemTab.Region[i].pBaseAddress); |
| 616 | } |
| 617 | } |
| 618 | return -EINVAL; |
| 619 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 620 | ALOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 621 | |
| 622 | /* Initialise */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 623 | pContext->pBundledContext->hInstance = LVM_NULL; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 624 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 625 | /* Init sets the instance handle */ |
| 626 | LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 627 | &MemTab, |
| 628 | &InstParams); |
| 629 | |
| 630 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init") |
| 631 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 632 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 633 | ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 634 | |
| 635 | /* Set the initial process parameters */ |
| 636 | /* General parameters */ |
| 637 | params.OperatingMode = LVM_MODE_ON; |
| 638 | params.SampleRate = LVM_FS_44100; |
| 639 | params.SourceFormat = LVM_STEREO; |
| 640 | params.SpeakerType = LVM_HEADPHONES; |
| 641 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 642 | pContext->pBundledContext->SampleRate = LVM_FS_44100; |
| 643 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 644 | /* Concert Sound parameters */ |
| 645 | params.VirtualizerOperatingMode = LVM_MODE_OFF; |
| 646 | params.VirtualizerType = LVM_CONCERTSOUND; |
| 647 | params.VirtualizerReverbLevel = 100; |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 648 | params.CS_EffectLevel = LVM_CS_EFFECT_NONE; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 649 | |
| 650 | /* N-Band Equaliser parameters */ |
| 651 | params.EQNB_OperatingMode = LVM_EQNB_OFF; |
| 652 | params.EQNB_NBands = FIVEBAND_NUMBANDS; |
| 653 | params.pEQNB_BandDefinition = &BandDefs[0]; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 654 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 655 | for (int i=0; i<FIVEBAND_NUMBANDS; i++) |
| 656 | { |
| 657 | BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i]; |
| 658 | BandDefs[i].QFactor = EQNB_5BandPresetsQFactors[i]; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 659 | BandDefs[i].Gain = EQNB_5BandSoftPresets[i]; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | /* Volume Control parameters */ |
| 663 | params.VC_EffectLevel = 0; |
| 664 | params.VC_Balance = 0; |
| 665 | |
| 666 | /* Treble Enhancement parameters */ |
| 667 | params.TE_OperatingMode = LVM_TE_OFF; |
| 668 | params.TE_EffectLevel = 0; |
| 669 | |
| 670 | /* PSA Control parameters */ |
| 671 | params.PSA_Enable = LVM_PSA_OFF; |
| 672 | params.PSA_PeakDecayRate = (LVM_PSA_DecaySpeed_en)0; |
| 673 | |
| 674 | /* Bass Enhancement parameters */ |
| 675 | params.BE_OperatingMode = LVM_BE_OFF; |
| 676 | params.BE_EffectLevel = 0; |
| 677 | params.BE_CentreFreq = LVM_BE_CENTRE_90Hz; |
| 678 | params.BE_HPF = LVM_BE_HPF_ON; |
| 679 | |
| 680 | /* PSA Control parameters */ |
| 681 | params.PSA_Enable = LVM_PSA_OFF; |
| 682 | params.PSA_PeakDecayRate = LVM_PSA_SPEED_MEDIUM; |
| 683 | |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 684 | /* TE Control parameters */ |
| 685 | params.TE_OperatingMode = LVM_TE_OFF; |
| 686 | params.TE_EffectLevel = 0; |
| 687 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 688 | /* Activate the initial settings */ |
| 689 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 690 | ¶ms); |
| 691 | |
| 692 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init") |
| 693 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 694 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 695 | ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 696 | |
| 697 | /* Set the headroom parameters */ |
| 698 | HeadroomBandDef[0].Limit_Low = 20; |
| 699 | HeadroomBandDef[0].Limit_High = 4999; |
| 700 | HeadroomBandDef[0].Headroom_Offset = 3; |
| 701 | HeadroomBandDef[1].Limit_Low = 5000; |
| 702 | HeadroomBandDef[1].Limit_High = 24000; |
| 703 | HeadroomBandDef[1].Headroom_Offset = 4; |
| 704 | HeadroomParams.pHeadroomDefinition = &HeadroomBandDef[0]; |
| 705 | HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON; |
| 706 | HeadroomParams.NHeadroomBands = 2; |
| 707 | |
| 708 | LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance, |
| 709 | &HeadroomParams); |
| 710 | |
| 711 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init") |
| 712 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 713 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 714 | ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n"); |
| 715 | ALOGV("\tLvmBundle_init End"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 716 | return 0; |
| 717 | } /* end LvmBundle_init */ |
| 718 | |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 719 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 720 | //---------------------------------------------------------------------------- |
| 721 | // LvmBundle_process() |
| 722 | //---------------------------------------------------------------------------- |
| 723 | // Purpose: |
| 724 | // Apply LVM Bundle effects |
| 725 | // |
| 726 | // Inputs: |
| 727 | // pIn: pointer to stereo 16 bit input data |
| 728 | // pOut: pointer to stereo 16 bit output data |
| 729 | // frameCount: Frames to process |
| 730 | // pContext: effect engine context |
| 731 | // strength strength to be applied |
| 732 | // |
| 733 | // Outputs: |
| 734 | // pOut: pointer to updated stereo 16 bit output data |
| 735 | // |
| 736 | //---------------------------------------------------------------------------- |
| 737 | |
| 738 | int LvmBundle_process(LVM_INT16 *pIn, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 739 | LVM_INT16 *pOut, |
| 740 | int frameCount, |
| 741 | EffectContext *pContext){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 742 | |
| 743 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 744 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 745 | LVM_INT16 *pOutTmp; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 746 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 747 | if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){ |
| 748 | pOutTmp = pOut; |
| 749 | }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){ |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 750 | if (pContext->pBundledContext->frameCount != frameCount) { |
| 751 | if (pContext->pBundledContext->workBuffer != NULL) { |
| 752 | free(pContext->pBundledContext->workBuffer); |
| 753 | } |
| 754 | pContext->pBundledContext->workBuffer = |
| 755 | (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2); |
| 756 | pContext->pBundledContext->frameCount = frameCount; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 757 | } |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 758 | pOutTmp = pContext->pBundledContext->workBuffer; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 759 | }else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 760 | ALOGV("LVM_ERROR : LvmBundle_process invalid access mode"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 761 | return -EINVAL; |
| 762 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 763 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 764 | #ifdef LVM_PCM |
| 765 | fwrite(pIn, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmInPtr); |
| 766 | fflush(pContext->pBundledContext->PcmInPtr); |
| 767 | #endif |
| 768 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 769 | //ALOGV("Calling LVM_Process"); |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 770 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 771 | /* Process the samples */ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 772 | LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */ |
| 773 | pIn, /* Input buffer */ |
| 774 | pOutTmp, /* Output buffer */ |
| 775 | (LVM_UINT16)frameCount, /* Number of samples to read */ |
| 776 | 0); /* Audo Time */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 777 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 778 | LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process") |
| 779 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 780 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 781 | #ifdef LVM_PCM |
| 782 | fwrite(pOutTmp, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmOutPtr); |
| 783 | fflush(pContext->pBundledContext->PcmOutPtr); |
| 784 | #endif |
| 785 | |
| 786 | if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){ |
| 787 | for (int i=0; i<frameCount*2; i++){ |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 788 | pOut[i] = clamp16((LVM_INT32)pOut[i] + (LVM_INT32)pOutTmp[i]); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 789 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 790 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 791 | return 0; |
| 792 | } /* end LvmBundle_process */ |
| 793 | |
| 794 | //---------------------------------------------------------------------------- |
| 795 | // LvmEffect_enable() |
| 796 | //---------------------------------------------------------------------------- |
| 797 | // Purpose: Enable the effect in the bundle |
| 798 | // |
| 799 | // Inputs: |
| 800 | // pContext: effect engine context |
| 801 | // |
| 802 | // Outputs: |
| 803 | // |
| 804 | //---------------------------------------------------------------------------- |
| 805 | |
| 806 | int LvmEffect_enable(EffectContext *pContext){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 807 | //ALOGV("\tLvmEffect_enable start"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 808 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 809 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 810 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
| 811 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 812 | /* Get the current settings */ |
| 813 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 814 | &ActiveParams); |
| 815 | |
| 816 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable") |
| 817 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 818 | //ALOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 819 | |
| 820 | if(pContext->EffectType == LVM_BASS_BOOST) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 821 | ALOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 822 | ActiveParams.BE_OperatingMode = LVM_BE_ON; |
| 823 | } |
| 824 | if(pContext->EffectType == LVM_VIRTUALIZER) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 825 | ALOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 826 | ActiveParams.VirtualizerOperatingMode = LVM_MODE_ON; |
| 827 | } |
| 828 | if(pContext->EffectType == LVM_EQUALIZER) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 829 | ALOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 830 | ActiveParams.EQNB_OperatingMode = LVM_EQNB_ON; |
| 831 | } |
| 832 | if(pContext->EffectType == LVM_VOLUME) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 833 | ALOGV("\tLvmEffect_enable : Enabling LVM_VOLUME"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 836 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 837 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable") |
| 838 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 839 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 840 | //ALOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n"); |
| 841 | //ALOGV("\tLvmEffect_enable end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 842 | return 0; |
| 843 | } |
| 844 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 845 | //---------------------------------------------------------------------------- |
| 846 | // LvmEffect_disable() |
| 847 | //---------------------------------------------------------------------------- |
| 848 | // Purpose: Disable the effect in the bundle |
| 849 | // |
| 850 | // Inputs: |
| 851 | // pContext: effect engine context |
| 852 | // |
| 853 | // Outputs: |
| 854 | // |
| 855 | //---------------------------------------------------------------------------- |
| 856 | |
| 857 | int LvmEffect_disable(EffectContext *pContext){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 858 | //ALOGV("\tLvmEffect_disable start"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 859 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 860 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 861 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 862 | /* Get the current settings */ |
| 863 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 864 | &ActiveParams); |
| 865 | |
| 866 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable") |
| 867 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 868 | //ALOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 869 | |
| 870 | if(pContext->EffectType == LVM_BASS_BOOST) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 871 | ALOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 872 | ActiveParams.BE_OperatingMode = LVM_BE_OFF; |
| 873 | } |
| 874 | if(pContext->EffectType == LVM_VIRTUALIZER) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 875 | ALOGV("\tLvmEffect_disable : Disabling LVM_VIRTUALIZER"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 876 | ActiveParams.VirtualizerOperatingMode = LVM_MODE_OFF; |
| 877 | } |
| 878 | if(pContext->EffectType == LVM_EQUALIZER) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 879 | ALOGV("\tLvmEffect_disable : Disabling LVM_EQUALIZER"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 880 | ActiveParams.EQNB_OperatingMode = LVM_EQNB_OFF; |
| 881 | } |
| 882 | if(pContext->EffectType == LVM_VOLUME) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 883 | ALOGV("\tLvmEffect_disable : Disabling LVM_VOLUME"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 886 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 887 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable") |
| 888 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 889 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 890 | //ALOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n"); |
| 891 | //ALOGV("\tLvmEffect_disable end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 892 | return 0; |
| 893 | } |
| 894 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 895 | //---------------------------------------------------------------------------- |
| 896 | // LvmEffect_free() |
| 897 | //---------------------------------------------------------------------------- |
| 898 | // Purpose: Free all memory associated with the Bundle. |
| 899 | // |
| 900 | // Inputs: |
| 901 | // pContext: effect engine context |
| 902 | // |
| 903 | // Outputs: |
| 904 | // |
| 905 | //---------------------------------------------------------------------------- |
| 906 | |
| 907 | void LvmEffect_free(EffectContext *pContext){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 908 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
| 909 | LVM_ControlParams_t params; /* Control Parameters */ |
| 910 | LVM_MemTab_t MemTab; |
| 911 | |
| 912 | /* Free the algorithm memory */ |
| 913 | LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance, |
| 914 | &MemTab, |
| 915 | LVM_NULL); |
| 916 | |
| 917 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free") |
| 918 | |
| 919 | for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){ |
| 920 | if (MemTab.Region[i].Size != 0){ |
| 921 | if (MemTab.Region[i].pBaseAddress != NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 922 | ALOGV("\tLvmEffect_free - START freeing %ld bytes for region %u at %p\n", |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 923 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
| 924 | |
| 925 | free(MemTab.Region[i].pBaseAddress); |
| 926 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 927 | ALOGV("\tLvmEffect_free - END freeing %ld bytes for region %u at %p\n", |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 928 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
| 929 | }else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 930 | ALOGV("\tLVM_ERROR : LvmEffect_free - trying to free with NULL pointer %ld bytes " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 931 | "for region %u at %p ERROR\n", |
| 932 | MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress); |
| 933 | } |
| 934 | } |
| 935 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 936 | } /* end LvmEffect_free */ |
| 937 | |
| 938 | //---------------------------------------------------------------------------- |
| 939 | // Effect_configure() |
| 940 | //---------------------------------------------------------------------------- |
| 941 | // Purpose: Set input and output audio configuration. |
| 942 | // |
| 943 | // Inputs: |
| 944 | // pContext: effect engine context |
| 945 | // pConfig: pointer to effect_config_t structure holding input and output |
| 946 | // configuration parameters |
| 947 | // |
| 948 | // Outputs: |
| 949 | // |
| 950 | //---------------------------------------------------------------------------- |
| 951 | |
| 952 | int Effect_configure(EffectContext *pContext, effect_config_t *pConfig){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 953 | LVM_Fs_en SampleRate; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 954 | //ALOGV("\tEffect_configure start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 955 | |
| 956 | CHECK_ARG(pContext != NULL); |
| 957 | CHECK_ARG(pConfig != NULL); |
| 958 | |
| 959 | CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate); |
| 960 | CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels); |
| 961 | CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 962 | CHECK_ARG(pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 963 | CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE |
| 964 | || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 965 | CHECK_ARG(pConfig->inputCfg.format == AUDIO_FORMAT_PCM_16_BIT); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 966 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 967 | memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 968 | |
| 969 | switch (pConfig->inputCfg.samplingRate) { |
| 970 | case 8000: |
| 971 | SampleRate = LVM_FS_8000; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 972 | pContext->pBundledContext->SamplesPerSecond = 8000*2; // 2 secs Stereo |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 973 | break; |
| 974 | case 16000: |
| 975 | SampleRate = LVM_FS_16000; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 976 | pContext->pBundledContext->SamplesPerSecond = 16000*2; // 2 secs Stereo |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 977 | break; |
| 978 | case 22050: |
| 979 | SampleRate = LVM_FS_22050; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 980 | pContext->pBundledContext->SamplesPerSecond = 22050*2; // 2 secs Stereo |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 981 | break; |
| 982 | case 32000: |
| 983 | SampleRate = LVM_FS_32000; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 984 | pContext->pBundledContext->SamplesPerSecond = 32000*2; // 2 secs Stereo |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 985 | break; |
| 986 | case 44100: |
| 987 | SampleRate = LVM_FS_44100; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 988 | pContext->pBundledContext->SamplesPerSecond = 44100*2; // 2 secs Stereo |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 989 | break; |
| 990 | case 48000: |
| 991 | SampleRate = LVM_FS_48000; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 992 | pContext->pBundledContext->SamplesPerSecond = 48000*2; // 2 secs Stereo |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 993 | break; |
| 994 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 995 | ALOGV("\tEffect_Configure invalid sampling rate %d", pConfig->inputCfg.samplingRate); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 996 | return -EINVAL; |
| 997 | } |
| 998 | |
| 999 | if(pContext->pBundledContext->SampleRate != SampleRate){ |
| 1000 | |
| 1001 | LVM_ControlParams_t ActiveParams; |
| 1002 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; |
| 1003 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1004 | ALOGV("\tEffect_configure change sampling rate to %d", SampleRate); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1005 | |
| 1006 | /* Get the current settings */ |
| 1007 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, |
| 1008 | &ActiveParams); |
| 1009 | |
| 1010 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_configure") |
| 1011 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1012 | |
| 1013 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1014 | |
| 1015 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_configure") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1016 | ALOGV("\tEffect_configure Succesfully called LVM_SetControlParameters\n"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1017 | pContext->pBundledContext->SampleRate = SampleRate; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1018 | |
| 1019 | }else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1020 | //ALOGV("\tEffect_configure keep sampling rate at %d", SampleRate); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1023 | //ALOGV("\tEffect_configure End...."); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1024 | return 0; |
| 1025 | } /* end Effect_configure */ |
| 1026 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1027 | //---------------------------------------------------------------------------- |
| 1028 | // BassGetStrength() |
| 1029 | //---------------------------------------------------------------------------- |
| 1030 | // Purpose: |
| 1031 | // get the effect strength currently being used, what is actually returned is the strengh that was |
| 1032 | // previously used in the set, this is because the app uses a strength in the range 0-1000 while |
| 1033 | // the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the |
| 1034 | // actual used value is checked to make sure it corresponds to the one being returned |
| 1035 | // |
| 1036 | // Inputs: |
| 1037 | // pContext: effect engine context |
| 1038 | // |
| 1039 | //---------------------------------------------------------------------------- |
| 1040 | |
| 1041 | uint32_t BassGetStrength(EffectContext *pContext){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1042 | //ALOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1043 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1044 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1045 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1046 | /* Get the current settings */ |
| 1047 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1048 | &ActiveParams); |
| 1049 | |
| 1050 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength") |
| 1051 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1052 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1053 | //ALOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1054 | |
| 1055 | /* Check that the strength returned matches the strength that was set earlier */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1056 | if(ActiveParams.BE_EffectLevel != |
| 1057 | (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1058 | ALOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n", |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1059 | ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved); |
| 1060 | return -EINVAL; |
| 1061 | } |
| 1062 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1063 | //ALOGV("\tBassGetStrength() (0-15) -> %d\n", ActiveParams.BE_EffectLevel ); |
| 1064 | //ALOGV("\tBassGetStrength() (saved) -> %d\n", pContext->pBundledContext->BassStrengthSaved ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1065 | return pContext->pBundledContext->BassStrengthSaved; |
| 1066 | } /* end BassGetStrength */ |
| 1067 | |
| 1068 | //---------------------------------------------------------------------------- |
| 1069 | // BassSetStrength() |
| 1070 | //---------------------------------------------------------------------------- |
| 1071 | // Purpose: |
| 1072 | // Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15 |
| 1073 | // |
| 1074 | // Inputs: |
| 1075 | // pContext: effect engine context |
| 1076 | // strength strength to be applied |
| 1077 | // |
| 1078 | //---------------------------------------------------------------------------- |
| 1079 | |
| 1080 | void BassSetStrength(EffectContext *pContext, uint32_t strength){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1081 | //ALOGV("\tBassSetStrength(%d)", strength); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1082 | |
| 1083 | pContext->pBundledContext->BassStrengthSaved = (int)strength; |
| 1084 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1085 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1086 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
| 1087 | |
| 1088 | /* Get the current settings */ |
| 1089 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, |
| 1090 | &ActiveParams); |
| 1091 | |
| 1092 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1093 | //ALOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1094 | |
| 1095 | /* Bass Enhancement parameters */ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1096 | ActiveParams.BE_EffectLevel = (LVM_INT16)((15*strength)/1000); |
| 1097 | ActiveParams.BE_CentreFreq = LVM_BE_CENTRE_90Hz; |
| 1098 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1099 | //ALOGV("\tBassSetStrength() (0-15) -> %d\n", ActiveParams.BE_EffectLevel ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1100 | |
| 1101 | /* Activate the initial settings */ |
| 1102 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1103 | |
| 1104 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1105 | //ALOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1106 | } /* end BassSetStrength */ |
| 1107 | |
| 1108 | //---------------------------------------------------------------------------- |
| 1109 | // VirtualizerGetStrength() |
| 1110 | //---------------------------------------------------------------------------- |
| 1111 | // Purpose: |
| 1112 | // get the effect strength currently being used, what is actually returned is the strengh that was |
| 1113 | // previously used in the set, this is because the app uses a strength in the range 0-1000 while |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1114 | // the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1115 | // actual used value is checked to make sure it corresponds to the one being returned |
| 1116 | // |
| 1117 | // Inputs: |
| 1118 | // pContext: effect engine context |
| 1119 | // |
| 1120 | //---------------------------------------------------------------------------- |
| 1121 | |
| 1122 | uint32_t VirtualizerGetStrength(EffectContext *pContext){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1123 | //ALOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1124 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1125 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1126 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
| 1127 | |
| 1128 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1129 | |
| 1130 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength") |
| 1131 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1132 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1133 | //ALOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n"); |
| 1134 | //ALOGV("\tVirtualizerGetStrength() (0-100) -> %d\n", ActiveParams.VirtualizerReverbLevel*10); |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1135 | return pContext->pBundledContext->VirtStrengthSaved; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1136 | } /* end getStrength */ |
| 1137 | |
| 1138 | //---------------------------------------------------------------------------- |
| 1139 | // VirtualizerSetStrength() |
| 1140 | //---------------------------------------------------------------------------- |
| 1141 | // Purpose: |
| 1142 | // Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15 |
| 1143 | // |
| 1144 | // Inputs: |
| 1145 | // pContext: effect engine context |
| 1146 | // strength strength to be applied |
| 1147 | // |
| 1148 | //---------------------------------------------------------------------------- |
| 1149 | |
| 1150 | void VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1151 | //ALOGV("\tVirtualizerSetStrength(%d)", strength); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1152 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1153 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
| 1154 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1155 | pContext->pBundledContext->VirtStrengthSaved = (int)strength; |
| 1156 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1157 | /* Get the current settings */ |
| 1158 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams); |
| 1159 | |
| 1160 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1161 | //ALOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1162 | |
| 1163 | /* Virtualizer parameters */ |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1164 | ActiveParams.CS_EffectLevel = (int)((strength*32767)/1000); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1165 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1166 | //ALOGV("\tVirtualizerSetStrength() (0-1000) -> %d\n", strength ); |
| 1167 | //ALOGV("\tVirtualizerSetStrength() (0- 100) -> %d\n", ActiveParams.CS_EffectLevel ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1168 | |
| 1169 | /* Activate the initial settings */ |
| 1170 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1171 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1172 | //ALOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1173 | } /* end setStrength */ |
| 1174 | |
| 1175 | //---------------------------------------------------------------------------- |
| 1176 | // EqualizerGetBandLevel() |
| 1177 | //---------------------------------------------------------------------------- |
| 1178 | // Purpose: Retrieve the gain currently being used for the band passed in |
| 1179 | // |
| 1180 | // Inputs: |
| 1181 | // band: band number |
| 1182 | // pContext: effect engine context |
| 1183 | // |
| 1184 | // Outputs: |
| 1185 | // |
| 1186 | //---------------------------------------------------------------------------- |
| 1187 | int32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){ |
| 1188 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1189 | int32_t Gain =0; |
| 1190 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1191 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
| 1192 | LVM_EQNB_BandDef_t *BandDef; |
| 1193 | /* Get the current settings */ |
| 1194 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, |
| 1195 | &ActiveParams); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1196 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1197 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel") |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1198 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1199 | BandDef = ActiveParams.pEQNB_BandDefinition; |
| 1200 | Gain = (int32_t)BandDef[band].Gain*100; // Convert to millibels |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1201 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1202 | //ALOGV("\tEqualizerGetBandLevel -> %d\n", Gain ); |
| 1203 | //ALOGV("\tEqualizerGetBandLevel Succesfully returned from LVM_GetControlParameters\n"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1204 | return Gain; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | //---------------------------------------------------------------------------- |
| 1208 | // EqualizerSetBandLevel() |
| 1209 | //---------------------------------------------------------------------------- |
| 1210 | // Purpose: |
| 1211 | // Sets gain value for the given band. |
| 1212 | // |
| 1213 | // Inputs: |
| 1214 | // band: band number |
| 1215 | // Gain: Gain to be applied in millibels |
| 1216 | // pContext: effect engine context |
| 1217 | // |
| 1218 | // Outputs: |
| 1219 | // |
| 1220 | //--------------------------------------------------------------------------- |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1221 | void EqualizerSetBandLevel(EffectContext *pContext, int band, short Gain){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1222 | int gainRounded; |
| 1223 | if(Gain > 0){ |
| 1224 | gainRounded = (int)((Gain+50)/100); |
| 1225 | }else{ |
| 1226 | gainRounded = (int)((Gain-50)/100); |
| 1227 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1228 | //ALOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1229 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1230 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1231 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1232 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1233 | LVM_EQNB_BandDef_t *BandDef; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1234 | |
| 1235 | /* Get the current settings */ |
| 1236 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1237 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetBandLevel") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1238 | //ALOGV("\tEqualizerSetBandLevel Succesfully returned from LVM_GetControlParameters\n"); |
| 1239 | //ALOGV("\tEqualizerSetBandLevel just Got -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1240 | |
| 1241 | /* Set local EQ parameters */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1242 | BandDef = ActiveParams.pEQNB_BandDefinition; |
| 1243 | ActiveParams.pEQNB_BandDefinition[band].Gain = gainRounded; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1244 | |
| 1245 | /* Activate the initial settings */ |
| 1246 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1247 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetBandLevel") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1248 | //ALOGV("\tEqualizerSetBandLevel just Set -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1249 | |
| 1250 | pContext->pBundledContext->CurPreset = PRESET_CUSTOM; |
| 1251 | return; |
| 1252 | } |
| 1253 | //---------------------------------------------------------------------------- |
| 1254 | // EqualizerGetCentreFrequency() |
| 1255 | //---------------------------------------------------------------------------- |
| 1256 | // Purpose: Retrieve the frequency being used for the band passed in |
| 1257 | // |
| 1258 | // Inputs: |
| 1259 | // band: band number |
| 1260 | // pContext: effect engine context |
| 1261 | // |
| 1262 | // Outputs: |
| 1263 | // |
| 1264 | //---------------------------------------------------------------------------- |
| 1265 | int32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1266 | int32_t Frequency =0; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1267 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1268 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1269 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
| 1270 | LVM_EQNB_BandDef_t *BandDef; |
| 1271 | /* Get the current settings */ |
| 1272 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, |
| 1273 | &ActiveParams); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1274 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1275 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency") |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1276 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1277 | BandDef = ActiveParams.pEQNB_BandDefinition; |
| 1278 | Frequency = (int32_t)BandDef[band].Frequency*1000; // Convert to millibels |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1279 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1280 | //ALOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency ); |
| 1281 | //ALOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1282 | return Frequency; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | //---------------------------------------------------------------------------- |
| 1286 | // EqualizerGetBandFreqRange( |
| 1287 | //---------------------------------------------------------------------------- |
| 1288 | // Purpose: |
| 1289 | // |
| 1290 | // Gets lower and upper boundaries of a band. |
| 1291 | // For the high shelf, the low bound is the band frequency and the high |
| 1292 | // bound is Nyquist. |
| 1293 | // For the peaking filters, they are the gain[dB]/2 points. |
| 1294 | // |
| 1295 | // Inputs: |
| 1296 | // band: band number |
| 1297 | // pContext: effect engine context |
| 1298 | // |
| 1299 | // Outputs: |
| 1300 | // pLow: lower band range |
| 1301 | // pLow: upper band range |
| 1302 | //---------------------------------------------------------------------------- |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1303 | int32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow, |
| 1304 | uint32_t *pHi){ |
| 1305 | *pLow = bandFreqRange[band][0]; |
| 1306 | *pHi = bandFreqRange[band][1]; |
| 1307 | return 0; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | //---------------------------------------------------------------------------- |
| 1311 | // EqualizerGetBand( |
| 1312 | //---------------------------------------------------------------------------- |
| 1313 | // Purpose: |
| 1314 | // |
| 1315 | // Returns the band with the maximum influence on a given frequency. |
| 1316 | // Result is unaffected by whether EQ is enabled or not, or by whether |
| 1317 | // changes have been committed or not. |
| 1318 | // |
| 1319 | // Inputs: |
| 1320 | // targetFreq The target frequency, in millihertz. |
| 1321 | // pContext: effect engine context |
| 1322 | // |
| 1323 | // Outputs: |
| 1324 | // pLow: lower band range |
| 1325 | // pLow: upper band range |
| 1326 | //---------------------------------------------------------------------------- |
| 1327 | int32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){ |
| 1328 | int band = 0; |
| 1329 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1330 | if(targetFreq < bandFreqRange[0][0]){ |
| 1331 | return -EINVAL; |
| 1332 | }else if(targetFreq == bandFreqRange[0][0]){ |
| 1333 | return 0; |
| 1334 | } |
| 1335 | for(int i=0; i<FIVEBAND_NUMBANDS;i++){ |
| 1336 | if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){ |
| 1337 | band = i; |
| 1338 | } |
| 1339 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1340 | return band; |
| 1341 | } |
| 1342 | |
| 1343 | //---------------------------------------------------------------------------- |
| 1344 | // EqualizerGetPreset( |
| 1345 | //---------------------------------------------------------------------------- |
| 1346 | // Purpose: |
| 1347 | // |
| 1348 | // Gets the currently set preset ID. |
| 1349 | // Will return PRESET_CUSTOM in case the EQ parameters have been modified |
| 1350 | // manually since a preset was set. |
| 1351 | // |
| 1352 | // Inputs: |
| 1353 | // pContext: effect engine context |
| 1354 | // |
| 1355 | //---------------------------------------------------------------------------- |
| 1356 | int32_t EqualizerGetPreset(EffectContext *pContext){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1357 | return pContext->pBundledContext->CurPreset; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | //---------------------------------------------------------------------------- |
| 1361 | // EqualizerSetPreset( |
| 1362 | //---------------------------------------------------------------------------- |
| 1363 | // Purpose: |
| 1364 | // |
| 1365 | // Sets the current preset by ID. |
| 1366 | // All the band parameters will be overridden. |
| 1367 | // |
| 1368 | // Inputs: |
| 1369 | // pContext: effect engine context |
| 1370 | // preset The preset ID. |
| 1371 | // |
| 1372 | //---------------------------------------------------------------------------- |
| 1373 | void EqualizerSetPreset(EffectContext *pContext, int preset){ |
| 1374 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1375 | //ALOGV("\tEqualizerSetPreset(%d)", preset); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1376 | pContext->pBundledContext->CurPreset = preset; |
| 1377 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1378 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1379 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
| 1380 | |
| 1381 | /* Get the current settings */ |
| 1382 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1383 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetPreset") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1384 | //ALOGV("\tEqualizerSetPreset Succesfully returned from LVM_GetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1385 | |
| 1386 | //ActiveParams.pEQNB_BandDefinition = &BandDefs[0]; |
| 1387 | for (int i=0; i<FIVEBAND_NUMBANDS; i++) |
| 1388 | { |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1389 | ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i]; |
| 1390 | ActiveParams.pEQNB_BandDefinition[i].QFactor = EQNB_5BandPresetsQFactors[i]; |
| 1391 | ActiveParams.pEQNB_BandDefinition[i].Gain |
| 1392 | = EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS]; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1393 | } |
| 1394 | /* Activate the new settings */ |
| 1395 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1396 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetPreset") |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1397 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1398 | //ALOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1399 | return; |
| 1400 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1401 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1402 | int32_t EqualizerGetNumPresets(){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1403 | return sizeof(gEqualizerPresets) / sizeof(PresetConfig); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | //---------------------------------------------------------------------------- |
| 1407 | // EqualizerGetPresetName( |
| 1408 | //---------------------------------------------------------------------------- |
| 1409 | // Purpose: |
| 1410 | // Gets a human-readable name for a preset ID. Will return "Custom" if |
| 1411 | // PRESET_CUSTOM is passed. |
| 1412 | // |
| 1413 | // Inputs: |
| 1414 | // preset The preset ID. Must be less than number of presets. |
| 1415 | // |
| 1416 | //------------------------------------------------------------------------- |
| 1417 | const char * EqualizerGetPresetName(int32_t preset){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1418 | //ALOGV("\tEqualizerGetPresetName start(%d)", preset); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1419 | if (preset == PRESET_CUSTOM) { |
| 1420 | return "Custom"; |
| 1421 | } else { |
| 1422 | return gEqualizerPresets[preset].name; |
| 1423 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1424 | //ALOGV("\tEqualizerGetPresetName end(%d)", preset); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1425 | return 0; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | //---------------------------------------------------------------------------- |
| 1429 | // VolumeSetVolumeLevel() |
| 1430 | //---------------------------------------------------------------------------- |
| 1431 | // Purpose: |
| 1432 | // |
| 1433 | // Inputs: |
| 1434 | // pContext: effect engine context |
| 1435 | // level level to be applied |
| 1436 | // |
| 1437 | //---------------------------------------------------------------------------- |
| 1438 | |
| 1439 | int VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1440 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1441 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1442 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
| 1443 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1444 | //ALOGV("\tVolumeSetVolumeLevel Level to be set is %d %d\n", level, (LVM_INT16)(level/100)); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1445 | /* Get the current settings */ |
| 1446 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1447 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel") |
| 1448 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1449 | //ALOGV("\tVolumeSetVolumeLevel Succesfully returned from LVM_GetControlParameters got: %d\n", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1450 | //ActiveParams.VC_EffectLevel); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1451 | |
| 1452 | /* Volume parameters */ |
| 1453 | ActiveParams.VC_EffectLevel = (LVM_INT16)(level/100); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1454 | //ALOGV("\tVolumeSetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1455 | |
| 1456 | /* Activate the initial settings */ |
| 1457 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1458 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetVolumeLevel") |
| 1459 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1460 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1461 | //ALOGV("\tVolumeSetVolumeLevel Succesfully called LVM_SetControlParameters\n"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1462 | |
| 1463 | /* Get the current settings */ |
| 1464 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1465 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel") |
| 1466 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1467 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1468 | //ALOGV("\tVolumeSetVolumeLevel just set (-96dB -> 0dB) -> %d\n",ActiveParams.VC_EffectLevel ); |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1469 | if(pContext->pBundledContext->firstVolume == LVM_TRUE){ |
| 1470 | LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1471 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process") |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1472 | ALOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks"); |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1473 | pContext->pBundledContext->firstVolume = LVM_FALSE; |
| 1474 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1475 | return 0; |
| 1476 | } /* end setVolumeLevel */ |
| 1477 | |
| 1478 | //---------------------------------------------------------------------------- |
| 1479 | // VolumeGetVolumeLevel() |
| 1480 | //---------------------------------------------------------------------------- |
| 1481 | // Purpose: |
| 1482 | // |
| 1483 | // Inputs: |
| 1484 | // pContext: effect engine context |
| 1485 | // |
| 1486 | //---------------------------------------------------------------------------- |
| 1487 | |
| 1488 | int VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){ |
| 1489 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1490 | //ALOGV("\tVolumeGetVolumeLevel start"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1491 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1492 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1493 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
| 1494 | |
| 1495 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1496 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetVolumeLevel") |
| 1497 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1498 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1499 | //ALOGV("\tVolumeGetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel ); |
| 1500 | //ALOGV("\tVolumeGetVolumeLevel Succesfully returned from LVM_GetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1501 | |
| 1502 | *level = ActiveParams.VC_EffectLevel*100; // Convert dB to millibels |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1503 | //ALOGV("\tVolumeGetVolumeLevel end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1504 | return 0; |
| 1505 | } /* end VolumeGetVolumeLevel */ |
| 1506 | |
| 1507 | //---------------------------------------------------------------------------- |
| 1508 | // VolumeSetMute() |
| 1509 | //---------------------------------------------------------------------------- |
| 1510 | // Purpose: |
| 1511 | // |
| 1512 | // Inputs: |
| 1513 | // pContext: effect engine context |
| 1514 | // mute: enable/disable flag |
| 1515 | // |
| 1516 | //---------------------------------------------------------------------------- |
| 1517 | |
| 1518 | int32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1519 | //ALOGV("\tVolumeSetMute start(%d)", mute); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1520 | |
| 1521 | pContext->pBundledContext->bMuteEnabled = mute; |
| 1522 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1523 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1524 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
| 1525 | |
| 1526 | /* Get the current settings */ |
| 1527 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1528 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetMute") |
| 1529 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1530 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1531 | //ALOGV("\tVolumeSetMute Succesfully returned from LVM_GetControlParameters\n"); |
| 1532 | //ALOGV("\tVolumeSetMute to %d, level was %d\n", mute, ActiveParams.VC_EffectLevel ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1533 | |
| 1534 | /* Set appropriate volume level */ |
| 1535 | if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1536 | pContext->pBundledContext->levelSaved = ActiveParams.VC_EffectLevel; |
| 1537 | ActiveParams.VC_EffectLevel = -96; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1538 | }else{ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1539 | ActiveParams.VC_EffectLevel = pContext->pBundledContext->levelSaved; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | /* Activate the initial settings */ |
| 1543 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1544 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetMute") |
| 1545 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1546 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1547 | //ALOGV("\tVolumeSetMute Succesfully called LVM_SetControlParameters\n"); |
| 1548 | //ALOGV("\tVolumeSetMute end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1549 | return 0; |
| 1550 | } /* end setMute */ |
| 1551 | |
| 1552 | //---------------------------------------------------------------------------- |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1553 | // VolumeGetMute() |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1554 | //---------------------------------------------------------------------------- |
| 1555 | // Purpose: |
| 1556 | // |
| 1557 | // Inputs: |
| 1558 | // pContext: effect engine context |
| 1559 | // |
| 1560 | // Ourputs: |
| 1561 | // mute: enable/disable flag |
| 1562 | //---------------------------------------------------------------------------- |
| 1563 | |
| 1564 | int32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1565 | //ALOGV("\tVolumeGetMute start"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1566 | if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)|| |
| 1567 | (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){ |
| 1568 | *mute = pContext->pBundledContext->bMuteEnabled; |
| 1569 | return 0; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1570 | }else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1571 | ALOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1572 | pContext->pBundledContext->bMuteEnabled); |
| 1573 | return -EINVAL; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1574 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1575 | //ALOGV("\tVolumeGetMute end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1576 | } /* end getMute */ |
| 1577 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1578 | int16_t VolumeConvertStereoPosition(int16_t position){ |
| 1579 | int16_t convertedPosition = 0; |
| 1580 | |
| 1581 | convertedPosition = (int16_t)(((float)position/1000)*96); |
| 1582 | return convertedPosition; |
| 1583 | |
| 1584 | } |
| 1585 | |
| 1586 | //---------------------------------------------------------------------------- |
| 1587 | // VolumeSetStereoPosition() |
| 1588 | //---------------------------------------------------------------------------- |
| 1589 | // Purpose: |
| 1590 | // |
| 1591 | // Inputs: |
| 1592 | // pContext: effect engine context |
| 1593 | // position: stereo position |
| 1594 | // |
| 1595 | // Outputs: |
| 1596 | //---------------------------------------------------------------------------- |
| 1597 | |
| 1598 | int VolumeSetStereoPosition(EffectContext *pContext, int16_t position){ |
| 1599 | |
| 1600 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1601 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
| 1602 | LVM_INT16 Balance = 0; |
| 1603 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1604 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1605 | |
| 1606 | pContext->pBundledContext->positionSaved = position; |
| 1607 | Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved); |
| 1608 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1609 | //ALOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1610 | //pContext->pBundledContext->positionSaved); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1611 | |
| 1612 | if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){ |
| 1613 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1614 | //ALOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1615 | pContext->pBundledContext->positionSaved = position; |
| 1616 | /* Get the current settings */ |
| 1617 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1618 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition") |
| 1619 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1620 | //ALOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:" |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1621 | // " %d\n", ActiveParams.VC_Balance); |
| 1622 | |
| 1623 | /* Volume parameters */ |
| 1624 | ActiveParams.VC_Balance = Balance; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1625 | //ALOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB) -> %d\n", ActiveParams.VC_Balance ); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1626 | |
| 1627 | /* Activate the initial settings */ |
| 1628 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1629 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition") |
| 1630 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1631 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1632 | //ALOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1633 | |
| 1634 | /* Get the current settings */ |
| 1635 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1636 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition") |
| 1637 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1638 | //ALOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: " |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1639 | // "%d\n", ActiveParams.VC_Balance); |
| 1640 | } |
| 1641 | else{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1642 | //ALOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1643 | //position, Balance); |
| 1644 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1645 | //ALOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1646 | //pContext->pBundledContext->positionSaved); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1647 | return 0; |
| 1648 | } /* end VolumeSetStereoPosition */ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1649 | |
| 1650 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1651 | //---------------------------------------------------------------------------- |
| 1652 | // VolumeGetStereoPosition() |
| 1653 | //---------------------------------------------------------------------------- |
| 1654 | // Purpose: |
| 1655 | // |
| 1656 | // Inputs: |
| 1657 | // pContext: effect engine context |
| 1658 | // |
| 1659 | // Outputs: |
| 1660 | // position: stereo position |
| 1661 | //---------------------------------------------------------------------------- |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1662 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1663 | int32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1664 | //ALOGV("\tVolumeGetStereoPosition start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1665 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1666 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1667 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
| 1668 | LVM_INT16 balance; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1669 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1670 | //ALOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1671 | //pContext->pBundledContext->positionSaved); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1672 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1673 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1674 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition") |
| 1675 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1676 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1677 | //ALOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance); |
| 1678 | //ALOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1679 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1680 | balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1681 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1682 | if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){ |
| 1683 | if(balance != ActiveParams.VC_Balance){ |
| 1684 | return -EINVAL; |
| 1685 | } |
| 1686 | } |
| 1687 | *position = (LVM_INT16)pContext->pBundledContext->positionSaved; // Convert dB to millibels |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1688 | //ALOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved =%d\n", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 1689 | //pContext->pBundledContext->positionSaved); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1690 | return 0; |
| 1691 | } /* end VolumeGetStereoPosition */ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1692 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1693 | //---------------------------------------------------------------------------- |
| 1694 | // VolumeEnableStereoPosition() |
| 1695 | //---------------------------------------------------------------------------- |
| 1696 | // Purpose: |
| 1697 | // |
| 1698 | // Inputs: |
| 1699 | // pContext: effect engine context |
| 1700 | // mute: enable/disable flag |
| 1701 | // |
| 1702 | //---------------------------------------------------------------------------- |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1703 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1704 | int32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1705 | //ALOGV("\tVolumeEnableStereoPosition start()"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1706 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1707 | pContext->pBundledContext->bStereoPositionEnabled = enabled; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1708 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1709 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 1710 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1711 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1712 | /* Get the current settings */ |
| 1713 | LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1714 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition") |
| 1715 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1716 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1717 | //ALOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n"); |
| 1718 | //ALOGV("\tVolumeEnableStereoPosition to %d, position was %d\n", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1719 | // enabled, ActiveParams.VC_Balance ); |
| 1720 | |
| 1721 | /* Set appropriate stereo position */ |
| 1722 | if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){ |
| 1723 | ActiveParams.VC_Balance = 0; |
| 1724 | }else{ |
| 1725 | ActiveParams.VC_Balance = |
| 1726 | VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved); |
| 1727 | } |
| 1728 | |
| 1729 | /* Activate the initial settings */ |
| 1730 | LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); |
| 1731 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition") |
| 1732 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 1733 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1734 | //ALOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n"); |
| 1735 | //ALOGV("\tVolumeEnableStereoPosition end()\n"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1736 | return 0; |
| 1737 | } /* end VolumeEnableStereoPosition */ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1738 | |
| 1739 | //---------------------------------------------------------------------------- |
| 1740 | // BassBoost_getParameter() |
| 1741 | //---------------------------------------------------------------------------- |
| 1742 | // Purpose: |
| 1743 | // Get a BassBoost parameter |
| 1744 | // |
| 1745 | // Inputs: |
| 1746 | // pBassBoost - handle to instance data |
| 1747 | // pParam - pointer to parameter |
| 1748 | // pValue - pointer to variable to hold retrieved value |
| 1749 | // pValueSize - pointer to value size: maximum size as input |
| 1750 | // |
| 1751 | // Outputs: |
| 1752 | // *pValue updated with parameter value |
| 1753 | // *pValueSize updated with actual value size |
| 1754 | // |
| 1755 | // |
| 1756 | // Side Effects: |
| 1757 | // |
| 1758 | //---------------------------------------------------------------------------- |
| 1759 | |
| 1760 | int BassBoost_getParameter(EffectContext *pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1761 | void *pParam, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1762 | size_t *pValueSize, |
| 1763 | void *pValue){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1764 | int status = 0; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1765 | int32_t *pParamTemp = (int32_t *)pParam; |
| 1766 | int32_t param = *pParamTemp++; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1767 | int32_t param2; |
| 1768 | char *name; |
| 1769 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1770 | //ALOGV("\tBassBoost_getParameter start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1771 | |
| 1772 | switch (param){ |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 1773 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: |
Eric Laurent | ba8da2e | 2010-08-18 14:31:25 -0700 | [diff] [blame] | 1774 | if (*pValueSize != sizeof(uint32_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1775 | ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize1 %d", *pValueSize); |
Eric Laurent | ba8da2e | 2010-08-18 14:31:25 -0700 | [diff] [blame] | 1776 | return -EINVAL; |
| 1777 | } |
| 1778 | *pValueSize = sizeof(uint32_t); |
| 1779 | break; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1780 | case BASSBOOST_PARAM_STRENGTH: |
| 1781 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1782 | ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize2 %d", *pValueSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1783 | return -EINVAL; |
| 1784 | } |
| 1785 | *pValueSize = sizeof(int16_t); |
| 1786 | break; |
| 1787 | |
| 1788 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1789 | ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1790 | return -EINVAL; |
| 1791 | } |
| 1792 | |
| 1793 | switch (param){ |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 1794 | case BASSBOOST_PARAM_STRENGTH_SUPPORTED: |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1795 | *(uint32_t *)pValue = 1; |
| 1796 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1797 | //ALOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1798 | // *(uint32_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1799 | break; |
| 1800 | |
| 1801 | case BASSBOOST_PARAM_STRENGTH: |
| 1802 | *(int16_t *)pValue = BassGetStrength(pContext); |
| 1803 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1804 | //ALOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1805 | // *(int16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1806 | break; |
| 1807 | |
| 1808 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1809 | ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1810 | status = -EINVAL; |
| 1811 | break; |
| 1812 | } |
| 1813 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1814 | //ALOGV("\tBassBoost_getParameter end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1815 | return status; |
| 1816 | } /* end BassBoost_getParameter */ |
| 1817 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1818 | //---------------------------------------------------------------------------- |
| 1819 | // BassBoost_setParameter() |
| 1820 | //---------------------------------------------------------------------------- |
| 1821 | // Purpose: |
| 1822 | // Set a BassBoost parameter |
| 1823 | // |
| 1824 | // Inputs: |
| 1825 | // pBassBoost - handle to instance data |
| 1826 | // pParam - pointer to parameter |
| 1827 | // pValue - pointer to value |
| 1828 | // |
| 1829 | // Outputs: |
| 1830 | // |
| 1831 | //---------------------------------------------------------------------------- |
| 1832 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1833 | int BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1834 | int status = 0; |
| 1835 | int16_t strength; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1836 | int32_t *pParamTemp = (int32_t *)pParam; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1837 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1838 | //ALOGV("\tBassBoost_setParameter start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1839 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1840 | switch (*pParamTemp){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1841 | case BASSBOOST_PARAM_STRENGTH: |
| 1842 | strength = *(int16_t *)pValue; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1843 | //ALOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength); |
| 1844 | //ALOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1845 | BassSetStrength(pContext, (int32_t)strength); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1846 | //ALOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1847 | break; |
| 1848 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1849 | ALOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParamTemp); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1850 | break; |
| 1851 | } |
| 1852 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1853 | //ALOGV("\tBassBoost_setParameter end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1854 | return status; |
| 1855 | } /* end BassBoost_setParameter */ |
| 1856 | |
| 1857 | //---------------------------------------------------------------------------- |
| 1858 | // Virtualizer_getParameter() |
| 1859 | //---------------------------------------------------------------------------- |
| 1860 | // Purpose: |
| 1861 | // Get a Virtualizer parameter |
| 1862 | // |
| 1863 | // Inputs: |
| 1864 | // pVirtualizer - handle to instance data |
| 1865 | // pParam - pointer to parameter |
| 1866 | // pValue - pointer to variable to hold retrieved value |
| 1867 | // pValueSize - pointer to value size: maximum size as input |
| 1868 | // |
| 1869 | // Outputs: |
| 1870 | // *pValue updated with parameter value |
| 1871 | // *pValueSize updated with actual value size |
| 1872 | // |
| 1873 | // |
| 1874 | // Side Effects: |
| 1875 | // |
| 1876 | //---------------------------------------------------------------------------- |
| 1877 | |
| 1878 | int Virtualizer_getParameter(EffectContext *pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1879 | void *pParam, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1880 | size_t *pValueSize, |
| 1881 | void *pValue){ |
| 1882 | int status = 0; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1883 | int32_t *pParamTemp = (int32_t *)pParam; |
| 1884 | int32_t param = *pParamTemp++; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1885 | int32_t param2; |
| 1886 | char *name; |
| 1887 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1888 | //ALOGV("\tVirtualizer_getParameter start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1889 | |
| 1890 | switch (param){ |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 1891 | case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: |
Eric Laurent | ba8da2e | 2010-08-18 14:31:25 -0700 | [diff] [blame] | 1892 | if (*pValueSize != sizeof(uint32_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1893 | ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize); |
Eric Laurent | ba8da2e | 2010-08-18 14:31:25 -0700 | [diff] [blame] | 1894 | return -EINVAL; |
| 1895 | } |
| 1896 | *pValueSize = sizeof(uint32_t); |
| 1897 | break; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1898 | case VIRTUALIZER_PARAM_STRENGTH: |
| 1899 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1900 | ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize2 %d",*pValueSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1901 | return -EINVAL; |
| 1902 | } |
| 1903 | *pValueSize = sizeof(int16_t); |
| 1904 | break; |
| 1905 | |
| 1906 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1907 | ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1908 | return -EINVAL; |
| 1909 | } |
| 1910 | |
| 1911 | switch (param){ |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 1912 | case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1913 | *(uint32_t *)pValue = 1; |
| 1914 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1915 | //ALOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1916 | // *(uint32_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1917 | break; |
| 1918 | |
| 1919 | case VIRTUALIZER_PARAM_STRENGTH: |
| 1920 | *(int16_t *)pValue = VirtualizerGetStrength(pContext); |
| 1921 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1922 | //ALOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 1923 | // *(int16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1924 | break; |
| 1925 | |
| 1926 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1927 | ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1928 | status = -EINVAL; |
| 1929 | break; |
| 1930 | } |
| 1931 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1932 | //ALOGV("\tVirtualizer_getParameter end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1933 | return status; |
| 1934 | } /* end Virtualizer_getParameter */ |
| 1935 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1936 | //---------------------------------------------------------------------------- |
| 1937 | // Virtualizer_setParameter() |
| 1938 | //---------------------------------------------------------------------------- |
| 1939 | // Purpose: |
| 1940 | // Set a Virtualizer parameter |
| 1941 | // |
| 1942 | // Inputs: |
| 1943 | // pVirtualizer - handle to instance data |
| 1944 | // pParam - pointer to parameter |
| 1945 | // pValue - pointer to value |
| 1946 | // |
| 1947 | // Outputs: |
| 1948 | // |
| 1949 | //---------------------------------------------------------------------------- |
| 1950 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1951 | int Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1952 | int status = 0; |
| 1953 | int16_t strength; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1954 | int32_t *pParamTemp = (int32_t *)pParam; |
| 1955 | int32_t param = *pParamTemp++; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1956 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1957 | //ALOGV("\tVirtualizer_setParameter start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1958 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1959 | switch (param){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1960 | case VIRTUALIZER_PARAM_STRENGTH: |
| 1961 | strength = *(int16_t *)pValue; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1962 | //ALOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength); |
| 1963 | //ALOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1964 | VirtualizerSetStrength(pContext, (int32_t)strength); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1965 | //ALOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1966 | break; |
| 1967 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1968 | ALOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1969 | break; |
| 1970 | } |
| 1971 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 1972 | //ALOGV("\tVirtualizer_setParameter end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1973 | return status; |
| 1974 | } /* end Virtualizer_setParameter */ |
| 1975 | |
| 1976 | //---------------------------------------------------------------------------- |
| 1977 | // Equalizer_getParameter() |
| 1978 | //---------------------------------------------------------------------------- |
| 1979 | // Purpose: |
| 1980 | // Get a Equalizer parameter |
| 1981 | // |
| 1982 | // Inputs: |
| 1983 | // pEqualizer - handle to instance data |
| 1984 | // pParam - pointer to parameter |
| 1985 | // pValue - pointer to variable to hold retrieved value |
| 1986 | // pValueSize - pointer to value size: maximum size as input |
| 1987 | // |
| 1988 | // Outputs: |
| 1989 | // *pValue updated with parameter value |
| 1990 | // *pValueSize updated with actual value size |
| 1991 | // |
| 1992 | // |
| 1993 | // Side Effects: |
| 1994 | // |
| 1995 | //---------------------------------------------------------------------------- |
| 1996 | int Equalizer_getParameter(EffectContext *pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 1997 | void *pParam, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 1998 | size_t *pValueSize, |
| 1999 | void *pValue){ |
| 2000 | int status = 0; |
| 2001 | int bMute = 0; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2002 | int32_t *pParamTemp = (int32_t *)pParam; |
| 2003 | int32_t param = *pParamTemp++; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2004 | int32_t param2; |
| 2005 | char *name; |
| 2006 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2007 | //ALOGV("\tEqualizer_getParameter start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2008 | |
| 2009 | switch (param) { |
| 2010 | case EQ_PARAM_NUM_BANDS: |
| 2011 | case EQ_PARAM_CUR_PRESET: |
| 2012 | case EQ_PARAM_GET_NUM_OF_PRESETS: |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2013 | case EQ_PARAM_BAND_LEVEL: |
| 2014 | case EQ_PARAM_GET_BAND: |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2015 | if (*pValueSize < sizeof(int16_t)) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2016 | ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2017 | return -EINVAL; |
| 2018 | } |
| 2019 | *pValueSize = sizeof(int16_t); |
| 2020 | break; |
| 2021 | |
| 2022 | case EQ_PARAM_LEVEL_RANGE: |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2023 | if (*pValueSize < 2 * sizeof(int16_t)) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2024 | ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2 %d", *pValueSize); |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2025 | return -EINVAL; |
| 2026 | } |
| 2027 | *pValueSize = 2 * sizeof(int16_t); |
| 2028 | break; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2029 | case EQ_PARAM_BAND_FREQ_RANGE: |
| 2030 | if (*pValueSize < 2 * sizeof(int32_t)) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2031 | ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 3 %d", *pValueSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2032 | return -EINVAL; |
| 2033 | } |
| 2034 | *pValueSize = 2 * sizeof(int32_t); |
| 2035 | break; |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2036 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2037 | case EQ_PARAM_CENTER_FREQ: |
| 2038 | if (*pValueSize < sizeof(int32_t)) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2039 | ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 5 %d", *pValueSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2040 | return -EINVAL; |
| 2041 | } |
| 2042 | *pValueSize = sizeof(int32_t); |
| 2043 | break; |
| 2044 | |
| 2045 | case EQ_PARAM_GET_PRESET_NAME: |
| 2046 | break; |
| 2047 | |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 2048 | case EQ_PARAM_PROPERTIES: |
| 2049 | if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2050 | ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 2051 | return -EINVAL; |
| 2052 | } |
| 2053 | *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t); |
| 2054 | break; |
| 2055 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2056 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2057 | ALOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2058 | return -EINVAL; |
| 2059 | } |
| 2060 | |
| 2061 | switch (param) { |
| 2062 | case EQ_PARAM_NUM_BANDS: |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2063 | *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2064 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2065 | break; |
| 2066 | |
| 2067 | case EQ_PARAM_LEVEL_RANGE: |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2068 | *(int16_t *)pValue = -1500; |
| 2069 | *((int16_t *)pValue + 1) = 1500; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2070 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 2071 | // *(int16_t *)pValue, *((int16_t *)pValue + 1)); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2072 | break; |
| 2073 | |
| 2074 | case EQ_PARAM_BAND_LEVEL: |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2075 | param2 = *pParamTemp; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2076 | if (param2 >= FIVEBAND_NUMBANDS) { |
| 2077 | status = -EINVAL; |
| 2078 | break; |
| 2079 | } |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2080 | *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2081 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2082 | // param2, *(int32_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2083 | break; |
| 2084 | |
| 2085 | case EQ_PARAM_CENTER_FREQ: |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2086 | param2 = *pParamTemp; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2087 | if (param2 >= FIVEBAND_NUMBANDS) { |
| 2088 | status = -EINVAL; |
| 2089 | break; |
| 2090 | } |
| 2091 | *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2092 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2093 | // param2, *(int32_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2094 | break; |
| 2095 | |
| 2096 | case EQ_PARAM_BAND_FREQ_RANGE: |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2097 | param2 = *pParamTemp; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2098 | if (param2 >= FIVEBAND_NUMBANDS) { |
| 2099 | status = -EINVAL; |
| 2100 | break; |
| 2101 | } |
| 2102 | EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1)); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2103 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2104 | // param2, *(int32_t *)pValue, *((int32_t *)pValue + 1)); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2105 | break; |
| 2106 | |
| 2107 | case EQ_PARAM_GET_BAND: |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2108 | param2 = *pParamTemp; |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2109 | *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2110 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 2111 | // param2, *(uint16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2112 | break; |
| 2113 | |
| 2114 | case EQ_PARAM_CUR_PRESET: |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2115 | *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2116 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2117 | break; |
| 2118 | |
| 2119 | case EQ_PARAM_GET_NUM_OF_PRESETS: |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2120 | *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets(); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2121 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2122 | break; |
| 2123 | |
| 2124 | case EQ_PARAM_GET_PRESET_NAME: |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2125 | param2 = *pParamTemp; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2126 | if (param2 >= EqualizerGetNumPresets()) { |
| 2127 | //if (param2 >= 20) { // AGO FIX |
| 2128 | status = -EINVAL; |
| 2129 | break; |
| 2130 | } |
| 2131 | name = (char *)pValue; |
| 2132 | strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1); |
| 2133 | name[*pValueSize - 1] = 0; |
| 2134 | *pValueSize = strlen(name) + 1; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2135 | //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2136 | // param2, gEqualizerPresets[param2].name, *pValueSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2137 | break; |
| 2138 | |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 2139 | case EQ_PARAM_PROPERTIES: { |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2140 | int16_t *p = (int16_t *)pValue; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2141 | ALOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES"); |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2142 | p[0] = (int16_t)EqualizerGetPreset(pContext); |
| 2143 | p[1] = (int16_t)FIVEBAND_NUMBANDS; |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 2144 | for (int i = 0; i < FIVEBAND_NUMBANDS; i++) { |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2145 | p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i); |
Eric Laurent | ca57d1c | 2010-07-23 00:19:11 -0700 | [diff] [blame] | 2146 | } |
| 2147 | } break; |
| 2148 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2149 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2150 | ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2151 | status = -EINVAL; |
| 2152 | break; |
| 2153 | } |
| 2154 | |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 2155 | //GV("\tEqualizer_getParameter end\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2156 | return status; |
| 2157 | } /* end Equalizer_getParameter */ |
| 2158 | |
| 2159 | //---------------------------------------------------------------------------- |
| 2160 | // Equalizer_setParameter() |
| 2161 | //---------------------------------------------------------------------------- |
| 2162 | // Purpose: |
| 2163 | // Set a Equalizer parameter |
| 2164 | // |
| 2165 | // Inputs: |
| 2166 | // pEqualizer - handle to instance data |
| 2167 | // pParam - pointer to parameter |
| 2168 | // pValue - pointer to value |
| 2169 | // |
| 2170 | // Outputs: |
| 2171 | // |
| 2172 | //---------------------------------------------------------------------------- |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2173 | int Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2174 | int status = 0; |
| 2175 | int32_t preset; |
| 2176 | int32_t band; |
| 2177 | int32_t level; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2178 | int32_t *pParamTemp = (int32_t *)pParam; |
| 2179 | int32_t param = *pParamTemp++; |
| 2180 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2181 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2182 | //ALOGV("\tEqualizer_setParameter start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2183 | switch (param) { |
| 2184 | case EQ_PARAM_CUR_PRESET: |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2185 | preset = (int32_t)(*(uint16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2186 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2187 | //ALOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2188 | if ((preset >= EqualizerGetNumPresets())||(preset < 0)) { |
| 2189 | status = -EINVAL; |
| 2190 | break; |
| 2191 | } |
| 2192 | EqualizerSetPreset(pContext, preset); |
| 2193 | break; |
| 2194 | case EQ_PARAM_BAND_LEVEL: |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2195 | band = *pParamTemp; |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2196 | level = (int32_t)(*(int16_t *)pValue); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2197 | //ALOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2198 | if (band >= FIVEBAND_NUMBANDS) { |
| 2199 | status = -EINVAL; |
| 2200 | break; |
| 2201 | } |
| 2202 | EqualizerSetBandLevel(pContext, band, level); |
| 2203 | break; |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2204 | case EQ_PARAM_PROPERTIES: { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2205 | //ALOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES"); |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2206 | int16_t *p = (int16_t *)pValue; |
| 2207 | if ((int)p[0] >= EqualizerGetNumPresets()) { |
| 2208 | status = -EINVAL; |
| 2209 | break; |
| 2210 | } |
| 2211 | if (p[0] >= 0) { |
| 2212 | EqualizerSetPreset(pContext, (int)p[0]); |
| 2213 | } else { |
| 2214 | if ((int)p[1] != FIVEBAND_NUMBANDS) { |
| 2215 | status = -EINVAL; |
| 2216 | break; |
| 2217 | } |
| 2218 | for (int i = 0; i < FIVEBAND_NUMBANDS; i++) { |
| 2219 | EqualizerSetBandLevel(pContext, i, (int)p[2 + i]); |
| 2220 | } |
| 2221 | } |
| 2222 | } break; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2223 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2224 | ALOGV("\tLVM_ERROR : Equalizer_setParameter() invalid param %d", param); |
Eric Laurent | 92e847e | 2010-07-30 09:12:51 -0700 | [diff] [blame] | 2225 | status = -EINVAL; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2226 | break; |
| 2227 | } |
| 2228 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2229 | //ALOGV("\tEqualizer_setParameter end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2230 | return status; |
| 2231 | } /* end Equalizer_setParameter */ |
| 2232 | |
| 2233 | //---------------------------------------------------------------------------- |
| 2234 | // Volume_getParameter() |
| 2235 | //---------------------------------------------------------------------------- |
| 2236 | // Purpose: |
| 2237 | // Get a Volume parameter |
| 2238 | // |
| 2239 | // Inputs: |
| 2240 | // pVolume - handle to instance data |
| 2241 | // pParam - pointer to parameter |
| 2242 | // pValue - pointer to variable to hold retrieved value |
| 2243 | // pValueSize - pointer to value size: maximum size as input |
| 2244 | // |
| 2245 | // Outputs: |
| 2246 | // *pValue updated with parameter value |
| 2247 | // *pValueSize updated with actual value size |
| 2248 | // |
| 2249 | // |
| 2250 | // Side Effects: |
| 2251 | // |
| 2252 | //---------------------------------------------------------------------------- |
| 2253 | |
| 2254 | int Volume_getParameter(EffectContext *pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2255 | void *pParam, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2256 | size_t *pValueSize, |
| 2257 | void *pValue){ |
| 2258 | int status = 0; |
| 2259 | int bMute = 0; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2260 | int32_t *pParamTemp = (int32_t *)pParam; |
| 2261 | int32_t param = *pParamTemp++;; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2262 | char *name; |
| 2263 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2264 | //ALOGV("\tVolume_getParameter start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2265 | |
| 2266 | switch (param){ |
| 2267 | case VOLUME_PARAM_LEVEL: |
| 2268 | case VOLUME_PARAM_MAXLEVEL: |
| 2269 | case VOLUME_PARAM_STEREOPOSITION: |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2270 | if (*pValueSize != sizeof(int16_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2271 | ALOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1 %d", *pValueSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2272 | return -EINVAL; |
| 2273 | } |
| 2274 | *pValueSize = sizeof(int16_t); |
| 2275 | break; |
| 2276 | |
| 2277 | case VOLUME_PARAM_MUTE: |
| 2278 | case VOLUME_PARAM_ENABLESTEREOPOSITION: |
| 2279 | if (*pValueSize < sizeof(int32_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2280 | ALOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2 %d", *pValueSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2281 | return -EINVAL; |
| 2282 | } |
| 2283 | *pValueSize = sizeof(int32_t); |
| 2284 | break; |
| 2285 | |
| 2286 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2287 | ALOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2288 | return -EINVAL; |
| 2289 | } |
| 2290 | |
| 2291 | switch (param){ |
| 2292 | case VOLUME_PARAM_LEVEL: |
| 2293 | status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue)); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2294 | //ALOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 2295 | // *(int16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2296 | break; |
| 2297 | |
| 2298 | case VOLUME_PARAM_MAXLEVEL: |
| 2299 | *(int16_t *)pValue = 0; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2300 | //ALOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 2301 | // *(int16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2302 | break; |
| 2303 | |
| 2304 | case VOLUME_PARAM_STEREOPOSITION: |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2305 | VolumeGetStereoPosition(pContext, (int16_t *)pValue); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2306 | //ALOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 2307 | // *(int16_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2308 | break; |
| 2309 | |
| 2310 | case VOLUME_PARAM_MUTE: |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2311 | status = VolumeGetMute(pContext, (uint32_t *)pValue); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2312 | ALOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2313 | *(uint32_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2314 | break; |
| 2315 | |
| 2316 | case VOLUME_PARAM_ENABLESTEREOPOSITION: |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2317 | *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2318 | //ALOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 2319 | // *(uint32_t *)pValue); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2320 | break; |
| 2321 | |
| 2322 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2323 | ALOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2324 | status = -EINVAL; |
| 2325 | break; |
| 2326 | } |
| 2327 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2328 | //ALOGV("\tVolume_getParameter end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2329 | return status; |
| 2330 | } /* end Volume_getParameter */ |
| 2331 | |
| 2332 | |
| 2333 | //---------------------------------------------------------------------------- |
| 2334 | // Volume_setParameter() |
| 2335 | //---------------------------------------------------------------------------- |
| 2336 | // Purpose: |
| 2337 | // Set a Volume parameter |
| 2338 | // |
| 2339 | // Inputs: |
| 2340 | // pVolume - handle to instance data |
| 2341 | // pParam - pointer to parameter |
| 2342 | // pValue - pointer to value |
| 2343 | // |
| 2344 | // Outputs: |
| 2345 | // |
| 2346 | //---------------------------------------------------------------------------- |
| 2347 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2348 | int Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2349 | int status = 0; |
| 2350 | int16_t level; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2351 | int16_t position; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2352 | uint32_t mute; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2353 | uint32_t positionEnabled; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2354 | int32_t *pParamTemp = (int32_t *)pParam; |
| 2355 | int32_t param = *pParamTemp++; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2356 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2357 | //ALOGV("\tVolume_setParameter start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2358 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2359 | switch (param){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2360 | case VOLUME_PARAM_LEVEL: |
| 2361 | level = *(int16_t *)pValue; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2362 | //ALOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level); |
| 2363 | //ALOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2364 | status = VolumeSetVolumeLevel(pContext, (int16_t)level); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2365 | //ALOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2366 | break; |
| 2367 | |
| 2368 | case VOLUME_PARAM_MUTE: |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2369 | mute = *(uint32_t *)pValue; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2370 | //ALOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute); |
| 2371 | //ALOGV("\tVolume_setParameter() Calling pVolume->setMute"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2372 | status = VolumeSetMute(pContext, mute); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2373 | //ALOGV("\tVolume_setParameter() Called pVolume->setMute"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2374 | break; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2375 | |
| 2376 | case VOLUME_PARAM_ENABLESTEREOPOSITION: |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2377 | positionEnabled = *(uint32_t *)pValue; |
| 2378 | status = VolumeEnableStereoPosition(pContext, positionEnabled); |
| 2379 | status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2380 | //ALOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2381 | break; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2382 | |
| 2383 | case VOLUME_PARAM_STEREOPOSITION: |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2384 | position = *(int16_t *)pValue; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2385 | //ALOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position); |
| 2386 | //ALOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2387 | status = VolumeSetStereoPosition(pContext, (int16_t)position); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2388 | //ALOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2389 | break; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2390 | |
| 2391 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2392 | ALOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", param); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2393 | break; |
| 2394 | } |
| 2395 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2396 | //ALOGV("\tVolume_setParameter end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2397 | return status; |
| 2398 | } /* end Volume_setParameter */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2399 | |
| 2400 | /**************************************************************************************** |
| 2401 | * Name : LVC_ToDB_s32Tos16() |
| 2402 | * Input : Signed 32-bit integer |
| 2403 | * Output : Signed 16-bit integer |
| 2404 | * MSB (16) = sign bit |
| 2405 | * (15->05) = integer part |
| 2406 | * (04->01) = decimal part |
| 2407 | * Returns : Db value with respect to full scale |
| 2408 | * Description : |
| 2409 | * Remarks : |
| 2410 | ****************************************************************************************/ |
| 2411 | |
| 2412 | LVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix) |
| 2413 | { |
| 2414 | LVM_INT16 db_fix; |
| 2415 | LVM_INT16 Shift; |
| 2416 | LVM_INT16 SmallRemainder; |
| 2417 | LVM_UINT32 Remainder = (LVM_UINT32)Lin_fix; |
| 2418 | |
| 2419 | /* Count leading bits, 1 cycle in assembly*/ |
| 2420 | for (Shift = 0; Shift<32; Shift++) |
| 2421 | { |
| 2422 | if ((Remainder & 0x80000000U)!=0) |
| 2423 | { |
| 2424 | break; |
| 2425 | } |
| 2426 | Remainder = Remainder << 1; |
| 2427 | } |
| 2428 | |
| 2429 | /* |
| 2430 | * Based on the approximation equation (for Q11.4 format): |
| 2431 | * |
| 2432 | * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2) |
| 2433 | */ |
| 2434 | db_fix = (LVM_INT16)(-96 * Shift); /* Six dB steps in Q11.4 format*/ |
| 2435 | SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24); |
| 2436 | db_fix = (LVM_INT16)(db_fix + SmallRemainder ); |
| 2437 | SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder); |
| 2438 | db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9)); |
| 2439 | |
| 2440 | /* Correct for small offset */ |
| 2441 | db_fix = (LVM_INT16)(db_fix - 5); |
| 2442 | |
| 2443 | return db_fix; |
| 2444 | } |
| 2445 | |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2446 | //---------------------------------------------------------------------------- |
| 2447 | // Effect_setEnabled() |
| 2448 | //---------------------------------------------------------------------------- |
| 2449 | // Purpose: |
| 2450 | // Enable or disable effect |
| 2451 | // |
| 2452 | // Inputs: |
| 2453 | // pContext - pointer to effect context |
| 2454 | // enabled - true if enabling the effect, false otherwise |
| 2455 | // |
| 2456 | // Outputs: |
| 2457 | // |
| 2458 | //---------------------------------------------------------------------------- |
| 2459 | |
| 2460 | int Effect_setEnabled(EffectContext *pContext, bool enabled) |
| 2461 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2462 | ALOGV("\tEffect_setEnabled() type %d, enabled %d", pContext->EffectType, enabled); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2463 | |
| 2464 | if (enabled) { |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 2465 | // Bass boost or Virtualizer can be temporarily disabled if playing over device speaker due |
| 2466 | // to their nature. |
| 2467 | bool tempDisabled = false; |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2468 | switch (pContext->EffectType) { |
| 2469 | case LVM_BASS_BOOST: |
| 2470 | if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2471 | ALOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already enabled"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2472 | return -EINVAL; |
| 2473 | } |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2474 | if(pContext->pBundledContext->SamplesToExitCountBb <= 0){ |
| 2475 | pContext->pBundledContext->NumberEffectsEnabled++; |
| 2476 | } |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2477 | pContext->pBundledContext->SamplesToExitCountBb = |
| 2478 | (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); |
| 2479 | pContext->pBundledContext->bBassEnabled = LVM_TRUE; |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 2480 | tempDisabled = pContext->pBundledContext->bBassTempDisabled; |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2481 | break; |
| 2482 | case LVM_EQUALIZER: |
| 2483 | if (pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2484 | ALOGV("\tEffect_setEnabled() LVM_EQUALIZER is already enabled"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2485 | return -EINVAL; |
| 2486 | } |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2487 | if(pContext->pBundledContext->SamplesToExitCountEq <= 0){ |
| 2488 | pContext->pBundledContext->NumberEffectsEnabled++; |
| 2489 | } |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2490 | pContext->pBundledContext->SamplesToExitCountEq = |
| 2491 | (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); |
| 2492 | pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE; |
| 2493 | break; |
| 2494 | case LVM_VIRTUALIZER: |
| 2495 | if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2496 | ALOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already enabled"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2497 | return -EINVAL; |
| 2498 | } |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2499 | if(pContext->pBundledContext->SamplesToExitCountVirt <= 0){ |
| 2500 | pContext->pBundledContext->NumberEffectsEnabled++; |
| 2501 | } |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2502 | pContext->pBundledContext->SamplesToExitCountVirt = |
| 2503 | (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); |
| 2504 | pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE; |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 2505 | tempDisabled = pContext->pBundledContext->bVirtualizerTempDisabled; |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2506 | break; |
| 2507 | case LVM_VOLUME: |
| 2508 | if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2509 | ALOGV("\tEffect_setEnabled() LVM_VOLUME is already enabled"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2510 | return -EINVAL; |
| 2511 | } |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2512 | pContext->pBundledContext->NumberEffectsEnabled++; |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2513 | pContext->pBundledContext->bVolumeEnabled = LVM_TRUE; |
| 2514 | break; |
| 2515 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2516 | ALOGV("\tEffect_setEnabled() invalid effect type"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2517 | return -EINVAL; |
| 2518 | } |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 2519 | if (!tempDisabled) { |
| 2520 | LvmEffect_enable(pContext); |
| 2521 | } |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2522 | } else { |
| 2523 | switch (pContext->EffectType) { |
| 2524 | case LVM_BASS_BOOST: |
| 2525 | if (pContext->pBundledContext->bBassEnabled == LVM_FALSE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2526 | ALOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already disabled"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2527 | return -EINVAL; |
| 2528 | } |
| 2529 | pContext->pBundledContext->bBassEnabled = LVM_FALSE; |
| 2530 | break; |
| 2531 | case LVM_EQUALIZER: |
| 2532 | if (pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2533 | ALOGV("\tEffect_setEnabled() LVM_EQUALIZER is already disabled"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2534 | return -EINVAL; |
| 2535 | } |
| 2536 | pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE; |
| 2537 | break; |
| 2538 | case LVM_VIRTUALIZER: |
| 2539 | if (pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2540 | ALOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already disabled"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2541 | return -EINVAL; |
| 2542 | } |
| 2543 | pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE; |
| 2544 | break; |
| 2545 | case LVM_VOLUME: |
| 2546 | if (pContext->pBundledContext->bVolumeEnabled == LVM_FALSE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2547 | ALOGV("\tEffect_setEnabled() LVM_VOLUME is already disabled"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2548 | return -EINVAL; |
| 2549 | } |
| 2550 | pContext->pBundledContext->bVolumeEnabled = LVM_FALSE; |
| 2551 | break; |
| 2552 | default: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2553 | ALOGV("\tEffect_setEnabled() invalid effect type"); |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2554 | return -EINVAL; |
| 2555 | } |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2556 | LvmEffect_disable(pContext); |
| 2557 | } |
| 2558 | |
| 2559 | return 0; |
| 2560 | } |
| 2561 | |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2562 | //---------------------------------------------------------------------------- |
| 2563 | // LVC_Convert_VolToDb() |
| 2564 | //---------------------------------------------------------------------------- |
| 2565 | // Purpose: |
| 2566 | // Convery volume in Q24 to dB |
| 2567 | // |
| 2568 | // Inputs: |
| 2569 | // vol: Q.24 volume dB |
| 2570 | // |
| 2571 | //----------------------------------------------------------------------- |
| 2572 | |
| 2573 | int16_t LVC_Convert_VolToDb(uint32_t vol){ |
| 2574 | int16_t dB; |
| 2575 | |
| 2576 | dB = LVC_ToDB_s32Tos16(vol <<7); |
| 2577 | dB = (dB +8)>>4; |
| 2578 | dB = (dB <-96) ? -96 : dB ; |
| 2579 | |
| 2580 | return dB; |
| 2581 | } |
| 2582 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2583 | } // namespace |
| 2584 | } // namespace |
| 2585 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 2586 | extern "C" { |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2587 | /* Effect Control Interface Implementation: Process */ |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 2588 | int Effect_process(effect_handle_t self, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2589 | audio_buffer_t *inBuffer, |
| 2590 | audio_buffer_t *outBuffer){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2591 | EffectContext * pContext = (EffectContext *) self; |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2592 | LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2593 | int status = 0; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2594 | int lvmStatus = 0; |
| 2595 | LVM_INT16 *in = (LVM_INT16 *)inBuffer->raw; |
| 2596 | LVM_INT16 *out = (LVM_INT16 *)outBuffer->raw; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2597 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2598 | //ALOGV("\tEffect_process Start : Enabled = %d Called = %d (%8d %8d %8d)", |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2599 | //pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2600 | // pContext->pBundledContext->SamplesToExitCountBb, |
| 2601 | // pContext->pBundledContext->SamplesToExitCountVirt, |
| 2602 | // pContext->pBundledContext->SamplesToExitCountEq); |
| 2603 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2604 | if (pContext == NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2605 | ALOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2606 | return -EINVAL; |
| 2607 | } |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2608 | |
| 2609 | //if(pContext->EffectType == LVM_BASS_BOOST){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2610 | // ALOGV("\tEffect_process: Effect type is BASS_BOOST"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2611 | //}else if(pContext->EffectType == LVM_EQUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2612 | // ALOGV("\tEffect_process: Effect type is LVM_EQUALIZER"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2613 | //}else if(pContext->EffectType == LVM_VIRTUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2614 | // ALOGV("\tEffect_process: Effect type is LVM_VIRTUALIZER"); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2615 | //} |
| 2616 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2617 | if (inBuffer == NULL || inBuffer->raw == NULL || |
| 2618 | outBuffer == NULL || outBuffer->raw == NULL || |
| 2619 | inBuffer->frameCount != outBuffer->frameCount){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2620 | ALOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2621 | return -EINVAL; |
| 2622 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2623 | if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&& |
| 2624 | (pContext->EffectType == LVM_BASS_BOOST)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2625 | //ALOGV("\tEffect_process() LVM_BASS_BOOST Effect is not enabled"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2626 | if(pContext->pBundledContext->SamplesToExitCountBb > 0){ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2627 | pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2628 | //ALOGV("\tEffect_process: Waiting to turn off BASS_BOOST, %d samples left", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2629 | // pContext->pBundledContext->SamplesToExitCountBb); |
Eric Laurent | 9b44c66 | 2011-03-01 12:18:41 -0800 | [diff] [blame] | 2630 | } |
| 2631 | if(pContext->pBundledContext->SamplesToExitCountBb <= 0) { |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 2632 | status = -ENODATA; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2633 | pContext->pBundledContext->NumberEffectsEnabled--; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2634 | ALOGV("\tEffect_process() this is the last frame for LVM_BASS_BOOST"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2635 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2636 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2637 | if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&& |
| 2638 | (pContext->EffectType == LVM_VOLUME)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2639 | //ALOGV("\tEffect_process() LVM_VOLUME Effect is not enabled"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2640 | status = -ENODATA; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2641 | pContext->pBundledContext->NumberEffectsEnabled--; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2642 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2643 | if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&& |
| 2644 | (pContext->EffectType == LVM_EQUALIZER)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2645 | //ALOGV("\tEffect_process() LVM_EQUALIZER Effect is not enabled"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2646 | if(pContext->pBundledContext->SamplesToExitCountEq > 0){ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2647 | pContext->pBundledContext->SamplesToExitCountEq -= outBuffer->frameCount * 2; // STEREO |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2648 | //ALOGV("\tEffect_process: Waiting to turn off EQUALIZER, %d samples left", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2649 | // pContext->pBundledContext->SamplesToExitCountEq); |
Eric Laurent | 9b44c66 | 2011-03-01 12:18:41 -0800 | [diff] [blame] | 2650 | } |
| 2651 | if(pContext->pBundledContext->SamplesToExitCountEq <= 0) { |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2652 | status = -ENODATA; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2653 | pContext->pBundledContext->NumberEffectsEnabled--; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2654 | ALOGV("\tEffect_process() this is the last frame for LVM_EQUALIZER"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2655 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2656 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2657 | if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&& |
| 2658 | (pContext->EffectType == LVM_VIRTUALIZER)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2659 | //ALOGV("\tEffect_process() LVM_VIRTUALIZER Effect is not enabled"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2660 | if(pContext->pBundledContext->SamplesToExitCountVirt > 0){ |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2661 | pContext->pBundledContext->SamplesToExitCountVirt -= outBuffer->frameCount * 2;// STEREO |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2662 | //ALOGV("\tEffect_process: Waiting for to turn off VIRTUALIZER, %d samples left", |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2663 | // pContext->pBundledContext->SamplesToExitCountVirt); |
Eric Laurent | 9b44c66 | 2011-03-01 12:18:41 -0800 | [diff] [blame] | 2664 | } |
| 2665 | if(pContext->pBundledContext->SamplesToExitCountVirt <= 0) { |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2666 | status = -ENODATA; |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2667 | pContext->pBundledContext->NumberEffectsEnabled--; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2668 | ALOGV("\tEffect_process() this is the last frame for LVM_VIRTUALIZER"); |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2669 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2672 | if(status != -ENODATA){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2673 | pContext->pBundledContext->NumberEffectsCalled++; |
| 2674 | } |
| 2675 | |
| 2676 | if(pContext->pBundledContext->NumberEffectsCalled == |
| 2677 | pContext->pBundledContext->NumberEffectsEnabled){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2678 | //ALOGV("\tEffect_process Calling process with %d effects enabled, %d called: Effect %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2679 | //pContext->pBundledContext->NumberEffectsEnabled, |
| 2680 | //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType); |
| 2681 | |
| 2682 | if(status == -ENODATA){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2683 | ALOGV("\tEffect_process() processing last frame"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2684 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2685 | pContext->pBundledContext->NumberEffectsCalled = 0; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2686 | /* Process all the available frames, block processing is |
| 2687 | handled internalLY by the LVM bundle */ |
| 2688 | lvmStatus = android::LvmBundle_process( (LVM_INT16 *)inBuffer->raw, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2689 | (LVM_INT16 *)outBuffer->raw, |
| 2690 | outBuffer->frameCount, |
| 2691 | pContext); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2692 | if(lvmStatus != LVM_SUCCESS){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2693 | ALOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2694 | return lvmStatus; |
| 2695 | } |
Eric Laurent | 8b4529e | 2011-10-31 17:36:03 -0700 | [diff] [blame] | 2696 | } else { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2697 | //ALOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2698 | //pContext->pBundledContext->NumberEffectsEnabled, |
| 2699 | //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType); |
| 2700 | // 2 is for stereo input |
Eric Laurent | 8b4529e | 2011-10-31 17:36:03 -0700 | [diff] [blame] | 2701 | if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) { |
| 2702 | for (size_t i=0; i < outBuffer->frameCount*2; i++){ |
| 2703 | outBuffer->s16[i] = |
| 2704 | clamp16((LVM_INT32)outBuffer->s16[i] + (LVM_INT32)inBuffer->s16[i]); |
| 2705 | } |
| 2706 | } else { |
| 2707 | memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2); |
| 2708 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2709 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2710 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2711 | return status; |
| 2712 | } /* end Effect_process */ |
| 2713 | |
| 2714 | /* Effect Control Interface Implementation: Command */ |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 2715 | int Effect_command(effect_handle_t self, |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 2716 | uint32_t cmdCode, |
| 2717 | uint32_t cmdSize, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2718 | void *pCmdData, |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 2719 | uint32_t *replySize, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2720 | void *pReplyData){ |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2721 | EffectContext * pContext = (EffectContext *) self; |
| 2722 | int retsize; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2723 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2724 | //ALOGV("\t\nEffect_command start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2725 | |
| 2726 | if(pContext->EffectType == LVM_BASS_BOOST){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2727 | //ALOGV("\tEffect_command setting command for LVM_BASS_BOOST"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2728 | } |
| 2729 | if(pContext->EffectType == LVM_VIRTUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2730 | //ALOGV("\tEffect_command setting command for LVM_VIRTUALIZER"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2731 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2732 | if(pContext->EffectType == LVM_EQUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2733 | //ALOGV("\tEffect_command setting command for LVM_EQUALIZER"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2734 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2735 | if(pContext->EffectType == LVM_VOLUME){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2736 | //ALOGV("\tEffect_command setting command for LVM_VOLUME"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2737 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2738 | |
| 2739 | if (pContext == NULL){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2740 | ALOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2741 | return -EINVAL; |
| 2742 | } |
| 2743 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2744 | //ALOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2745 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2746 | // Incase we disable an effect, next time process is |
| 2747 | // called the number of effect called could be greater |
| 2748 | // pContext->pBundledContext->NumberEffectsCalled = 0; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2749 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2750 | //ALOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2751 | // pContext->pBundledContext->NumberEffectsCalled, |
| 2752 | // pContext->pBundledContext->NumberEffectsEnabled); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2753 | |
| 2754 | switch (cmdCode){ |
| 2755 | case EFFECT_CMD_INIT: |
Eric Laurent | 1c454cc | 2010-07-26 01:03:37 -0700 | [diff] [blame] | 2756 | if (pReplyData == NULL || *replySize != sizeof(int)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2757 | ALOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d", |
Eric Laurent | 1c454cc | 2010-07-26 01:03:37 -0700 | [diff] [blame] | 2758 | pContext->EffectType); |
| 2759 | return -EINVAL; |
| 2760 | } |
| 2761 | *(int *) pReplyData = 0; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2762 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2763 | if(pContext->EffectType == LVM_BASS_BOOST){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2764 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2765 | android::BassSetStrength(pContext, 0); |
| 2766 | } |
| 2767 | if(pContext->EffectType == LVM_VIRTUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2768 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2769 | android::VirtualizerSetStrength(pContext, 0); |
| 2770 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2771 | if(pContext->EffectType == LVM_EQUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2772 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2773 | android::EqualizerSetPreset(pContext, 0); |
| 2774 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2775 | if(pContext->EffectType == LVM_VOLUME){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2776 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VOLUME"); |
Eric Laurent | 1c454cc | 2010-07-26 01:03:37 -0700 | [diff] [blame] | 2777 | *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2778 | } |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2779 | break; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2780 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2781 | case EFFECT_CMD_CONFIGURE: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2782 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2783 | if (pCmdData == NULL|| |
| 2784 | cmdSize != sizeof(effect_config_t)|| |
| 2785 | pReplyData == NULL|| |
| 2786 | *replySize != sizeof(int)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2787 | ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2788 | "EFFECT_CMD_CONFIGURE: ERROR"); |
| 2789 | return -EINVAL; |
| 2790 | } |
| 2791 | *(int *) pReplyData = android::Effect_configure(pContext, (effect_config_t *) pCmdData); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2792 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2793 | break; |
| 2794 | |
| 2795 | case EFFECT_CMD_RESET: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2796 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2797 | android::Effect_configure(pContext, &pContext->config); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2798 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2799 | break; |
| 2800 | |
| 2801 | case EFFECT_CMD_GET_PARAM:{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2802 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2803 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2804 | if(pContext->EffectType == LVM_BASS_BOOST){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2805 | if (pCmdData == NULL || |
| 2806 | cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || |
| 2807 | pReplyData == NULL || |
| 2808 | *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2809 | ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2810 | "EFFECT_CMD_GET_PARAM: ERROR"); |
| 2811 | return -EINVAL; |
| 2812 | } |
| 2813 | effect_param_t *p = (effect_param_t *)pCmdData; |
| 2814 | |
| 2815 | memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); |
| 2816 | |
| 2817 | p = (effect_param_t *)pReplyData; |
| 2818 | |
| 2819 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 2820 | |
| 2821 | p->status = android::BassBoost_getParameter(pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2822 | p->data, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2823 | (size_t *)&p->vsize, |
| 2824 | p->data + voffset); |
| 2825 | |
| 2826 | *replySize = sizeof(effect_param_t) + voffset + p->vsize; |
| 2827 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2828 | //ALOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM " |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2829 | // "*pCmdData %d, *replySize %d, *pReplyData %d ", |
| 2830 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 2831 | // *replySize, |
| 2832 | // *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2833 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2834 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2835 | if(pContext->EffectType == LVM_VIRTUALIZER){ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2836 | if (pCmdData == NULL || |
| 2837 | cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || |
| 2838 | pReplyData == NULL || |
| 2839 | *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2840 | ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2841 | "EFFECT_CMD_GET_PARAM: ERROR"); |
| 2842 | return -EINVAL; |
| 2843 | } |
| 2844 | effect_param_t *p = (effect_param_t *)pCmdData; |
| 2845 | |
| 2846 | memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); |
| 2847 | |
| 2848 | p = (effect_param_t *)pReplyData; |
| 2849 | |
| 2850 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 2851 | |
| 2852 | p->status = android::Virtualizer_getParameter(pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2853 | (void *)p->data, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2854 | (size_t *)&p->vsize, |
| 2855 | p->data + voffset); |
| 2856 | |
| 2857 | *replySize = sizeof(effect_param_t) + voffset + p->vsize; |
| 2858 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2859 | //ALOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM " |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2860 | // "*pCmdData %d, *replySize %d, *pReplyData %d ", |
| 2861 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 2862 | // *replySize, |
| 2863 | // *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2864 | } |
| 2865 | if(pContext->EffectType == LVM_EQUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2866 | //ALOGV("\tEqualizer_command cmdCode Case: " |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2867 | // "EFFECT_CMD_GET_PARAM start"); |
| 2868 | if (pCmdData == NULL || |
| 2869 | cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || |
| 2870 | pReplyData == NULL || |
| 2871 | *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2872 | ALOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2873 | "EFFECT_CMD_GET_PARAM"); |
| 2874 | return -EINVAL; |
| 2875 | } |
| 2876 | effect_param_t *p = (effect_param_t *)pCmdData; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2877 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2878 | memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2879 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2880 | p = (effect_param_t *)pReplyData; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2881 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2882 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2883 | |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2884 | p->status = android::Equalizer_getParameter(pContext, |
| 2885 | p->data, |
| 2886 | &p->vsize, |
| 2887 | p->data + voffset); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2888 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2889 | *replySize = sizeof(effect_param_t) + voffset + p->vsize; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2890 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2891 | //ALOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, " |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2892 | // "*pReplyData %08x %08x", |
| 2893 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize, |
| 2894 | // *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset), |
| 2895 | // *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset + |
| 2896 | // sizeof(int32_t))); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2897 | } |
| 2898 | if(pContext->EffectType == LVM_VOLUME){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2899 | //ALOGV("\tVolume_command cmdCode Case: EFFECT_CMD_GET_PARAM start"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2900 | if (pCmdData == NULL || |
| 2901 | cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || |
| 2902 | pReplyData == NULL || |
| 2903 | *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2904 | ALOGV("\tLVM_ERROR : Volume_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2905 | "EFFECT_CMD_GET_PARAM: ERROR"); |
| 2906 | return -EINVAL; |
| 2907 | } |
| 2908 | effect_param_t *p = (effect_param_t *)pCmdData; |
| 2909 | |
| 2910 | memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); |
| 2911 | |
| 2912 | p = (effect_param_t *)pReplyData; |
| 2913 | |
| 2914 | int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); |
| 2915 | |
| 2916 | p->status = android::Volume_getParameter(pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2917 | (void *)p->data, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2918 | (size_t *)&p->vsize, |
| 2919 | p->data + voffset); |
| 2920 | |
| 2921 | *replySize = sizeof(effect_param_t) + voffset + p->vsize; |
| 2922 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2923 | //ALOGV("\tVolume_command EFFECT_CMD_GET_PARAM " |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2924 | // "*pCmdData %d, *replySize %d, *pReplyData %d ", |
| 2925 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 2926 | // *replySize, |
| 2927 | // *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); |
| 2928 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2929 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2930 | } break; |
| 2931 | case EFFECT_CMD_SET_PARAM:{ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2932 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2933 | if(pContext->EffectType == LVM_BASS_BOOST){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2934 | //ALOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d", |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 2935 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 2936 | // *replySize, |
| 2937 | // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2938 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2939 | if (pCmdData == NULL|| |
| 2940 | cmdSize != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))|| |
| 2941 | pReplyData == NULL|| |
| 2942 | *replySize != sizeof(int32_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2943 | ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2944 | "EFFECT_CMD_SET_PARAM: ERROR"); |
| 2945 | return -EINVAL; |
| 2946 | } |
| 2947 | effect_param_t *p = (effect_param_t *) pCmdData; |
| 2948 | |
| 2949 | if (p->psize != sizeof(int32_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2950 | ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2951 | "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)"); |
| 2952 | return -EINVAL; |
| 2953 | } |
| 2954 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2955 | //ALOGV("\tnBassBoost_command cmdSize is %d\n" |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2956 | // "\tsizeof(effect_param_t) is %d\n" |
| 2957 | // "\tp->psize is %d\n" |
| 2958 | // "\tp->vsize is %d" |
| 2959 | // "\n", |
| 2960 | // cmdSize, sizeof(effect_param_t), p->psize, p->vsize ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2961 | |
| 2962 | *(int *)pReplyData = android::BassBoost_setParameter(pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2963 | (void *)p->data, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2964 | p->data + p->psize); |
| 2965 | } |
| 2966 | if(pContext->EffectType == LVM_VIRTUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2967 | //ALOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 2968 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 2969 | // *replySize, |
| 2970 | // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2971 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2972 | if (pCmdData == NULL|| |
| 2973 | cmdSize != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))|| |
| 2974 | pReplyData == NULL|| |
| 2975 | *replySize != sizeof(int32_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2976 | ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2977 | "EFFECT_CMD_SET_PARAM: ERROR"); |
| 2978 | return -EINVAL; |
| 2979 | } |
| 2980 | effect_param_t *p = (effect_param_t *) pCmdData; |
| 2981 | |
| 2982 | if (p->psize != sizeof(int32_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2983 | ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2984 | "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)"); |
| 2985 | return -EINVAL; |
| 2986 | } |
| 2987 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 2988 | //ALOGV("\tnVirtualizer_command cmdSize is %d\n" |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2989 | // "\tsizeof(effect_param_t) is %d\n" |
| 2990 | // "\tp->psize is %d\n" |
| 2991 | // "\tp->vsize is %d" |
| 2992 | // "\n", |
| 2993 | // cmdSize, sizeof(effect_param_t), p->psize, p->vsize ); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2994 | |
| 2995 | *(int *)pReplyData = android::Virtualizer_setParameter(pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 2996 | (void *)p->data, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 2997 | p->data + p->psize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 2998 | } |
| 2999 | if(pContext->EffectType == LVM_EQUALIZER){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3000 | //ALOGV("\tEqualizer_command cmdCode Case: " |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 3001 | // "EFFECT_CMD_SET_PARAM start"); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3002 | //ALOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 3003 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 3004 | // *replySize, |
| 3005 | // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3006 | |
| 3007 | if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || |
| 3008 | pReplyData == NULL || *replySize != sizeof(int32_t)) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3009 | ALOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3010 | "EFFECT_CMD_SET_PARAM: ERROR"); |
| 3011 | return -EINVAL; |
| 3012 | } |
| 3013 | effect_param_t *p = (effect_param_t *) pCmdData; |
| 3014 | |
| 3015 | *(int *)pReplyData = android::Equalizer_setParameter(pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 3016 | (void *)p->data, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3017 | p->data + p->psize); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3018 | } |
| 3019 | if(pContext->EffectType == LVM_VOLUME){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3020 | //ALOGV("\tVolume_command cmdCode Case: EFFECT_CMD_SET_PARAM start"); |
| 3021 | //ALOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3022 | // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), |
| 3023 | // *replySize, |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 3024 | // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) +sizeof(int32_t))); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3025 | |
| 3026 | if ( pCmdData == NULL|| |
| 3027 | cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t))|| |
| 3028 | pReplyData == NULL|| |
| 3029 | *replySize != sizeof(int32_t)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3030 | ALOGV("\tLVM_ERROR : Volume_command cmdCode Case: " |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3031 | "EFFECT_CMD_SET_PARAM: ERROR"); |
| 3032 | return -EINVAL; |
| 3033 | } |
| 3034 | effect_param_t *p = (effect_param_t *) pCmdData; |
| 3035 | |
| 3036 | *(int *)pReplyData = android::Volume_setParameter(pContext, |
Eric Laurent | a1a96f3 | 2010-08-04 06:33:52 -0700 | [diff] [blame] | 3037 | (void *)p->data, |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3038 | p->data + p->psize); |
| 3039 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3040 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3041 | } break; |
| 3042 | |
| 3043 | case EFFECT_CMD_ENABLE: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3044 | ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3045 | if (pReplyData == NULL || *replySize != sizeof(int)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3046 | ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3047 | return -EINVAL; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3048 | } |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 3049 | |
| 3050 | *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_TRUE); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3051 | break; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3052 | |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3053 | case EFFECT_CMD_DISABLE: |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3054 | //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3055 | if (pReplyData == NULL || *replySize != sizeof(int)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3056 | ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3057 | return -EINVAL; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3058 | } |
Eric Laurent | f0f95b8 | 2010-09-15 18:29:49 -0700 | [diff] [blame] | 3059 | *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_FALSE); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3060 | break; |
| 3061 | |
| 3062 | case EFFECT_CMD_SET_DEVICE: |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3063 | { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3064 | ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start"); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 3065 | uint32_t device = *(uint32_t *)pCmdData; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3066 | |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3067 | if (pContext->EffectType == LVM_BASS_BOOST) { |
| 3068 | if((device == AUDIO_DEVICE_OUT_SPEAKER) || |
| 3069 | (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) || |
| 3070 | (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3071 | ALOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3072 | *(int32_t *)pCmdData); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3073 | ALOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3074 | |
| 3075 | // If a device doesnt support bassboost the effect must be temporarily disabled |
| 3076 | // the effect must still report its original state as this can only be changed |
| 3077 | // by the ENABLE/DISABLE command |
| 3078 | |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3079 | if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3080 | ALOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3081 | *(int32_t *)pCmdData); |
| 3082 | android::LvmEffect_disable(pContext); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3083 | } |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3084 | pContext->pBundledContext->bBassTempDisabled = LVM_TRUE; |
| 3085 | } else { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3086 | ALOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3087 | *(int32_t *)pCmdData); |
| 3088 | |
| 3089 | // If a device supports bassboost and the effect has been temporarily disabled |
| 3090 | // previously then re-enable it |
| 3091 | |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3092 | if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3093 | ALOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3094 | *(int32_t *)pCmdData); |
| 3095 | android::LvmEffect_enable(pContext); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3096 | } |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3097 | pContext->pBundledContext->bBassTempDisabled = LVM_FALSE; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3098 | } |
| 3099 | } |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3100 | if (pContext->EffectType == LVM_VIRTUALIZER) { |
| 3101 | if((device == AUDIO_DEVICE_OUT_SPEAKER)|| |
| 3102 | (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)|| |
| 3103 | (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3104 | ALOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3105 | *(int32_t *)pCmdData); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3106 | ALOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3107 | |
| 3108 | //If a device doesnt support virtualizer the effect must be temporarily disabled |
| 3109 | // the effect must still report its original state as this can only be changed |
| 3110 | // by the ENABLE/DISABLE command |
| 3111 | |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3112 | if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3113 | ALOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3114 | *(int32_t *)pCmdData); |
| 3115 | android::LvmEffect_disable(pContext); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3116 | } |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3117 | pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE; |
| 3118 | } else { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3119 | ALOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3120 | *(int32_t *)pCmdData); |
| 3121 | |
| 3122 | // If a device supports virtualizer and the effect has been temporarily disabled |
| 3123 | // previously then re-enable it |
| 3124 | |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3125 | if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){ |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3126 | ALOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d", |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3127 | *(int32_t *)pCmdData); |
| 3128 | android::LvmEffect_enable(pContext); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3129 | } |
Eric Laurent | b0c6e3b | 2011-10-31 18:48:15 -0700 | [diff] [blame] | 3130 | pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3131 | } |
| 3132 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3133 | ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end"); |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3134 | break; |
| 3135 | } |
| 3136 | case EFFECT_CMD_SET_VOLUME: |
| 3137 | { |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 3138 | uint32_t leftVolume, rightVolume; |
| 3139 | int16_t leftdB, rightdB; |
| 3140 | int16_t maxdB, pandB; |
| 3141 | int32_t vol_ret[2] = {1<<24,1<<24}; // Apply no volume |
| 3142 | int status = 0; |
| 3143 | LVM_ControlParams_t ActiveParams; /* Current control Parameters */ |
| 3144 | LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3145 | |
| 3146 | // if pReplyData is NULL, VOL_CTRL is delegated to another effect |
| 3147 | if(pReplyData == LVM_NULL){ |
| 3148 | break; |
| 3149 | } |
| 3150 | |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 3151 | if (pCmdData == NULL || |
| 3152 | cmdSize != 2 * sizeof(uint32_t)) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3153 | ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: " |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 3154 | "EFFECT_CMD_SET_VOLUME: ERROR"); |
| 3155 | return -EINVAL; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3156 | } |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3157 | |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 3158 | leftVolume = ((*(uint32_t *)pCmdData)); |
| 3159 | rightVolume = ((*((uint32_t *)pCmdData + 1))); |
| 3160 | |
| 3161 | if(leftVolume == 0x1000000){ |
| 3162 | leftVolume -= 1; |
| 3163 | } |
| 3164 | if(rightVolume == 0x1000000){ |
| 3165 | rightVolume -= 1; |
| 3166 | } |
| 3167 | |
| 3168 | // Convert volume to dB |
| 3169 | leftdB = android::LVC_Convert_VolToDb(leftVolume); |
| 3170 | rightdB = android::LVC_Convert_VolToDb(rightVolume); |
| 3171 | |
| 3172 | pandB = rightdB - leftdB; |
| 3173 | |
| 3174 | // Calculate max volume in dB |
| 3175 | maxdB = leftdB; |
| 3176 | if(rightdB > maxdB){ |
| 3177 | maxdB = rightdB; |
| 3178 | } |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3179 | //ALOGV("\tEFFECT_CMD_SET_VOLUME Session: %d, SessionID: %d VOLUME is %d dB (%d), " |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 3180 | // "effect is %d", |
| 3181 | //pContext->pBundledContext->SessionNo, pContext->pBundledContext->SessionId, |
| 3182 | //(int32_t)maxdB, maxVol<<7, pContext->EffectType); |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3183 | //ALOGV("\tEFFECT_CMD_SET_VOLUME: Left is %d, Right is %d", leftVolume, rightVolume); |
| 3184 | //ALOGV("\tEFFECT_CMD_SET_VOLUME: Left %ddB, Right %ddB, Position %ddB", |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 3185 | // leftdB, rightdB, pandB); |
Eric Laurent | adecf1c | 2010-08-27 10:52:56 -0700 | [diff] [blame] | 3186 | |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3187 | memcpy(pReplyData, vol_ret, sizeof(int32_t)*2); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 3188 | android::VolumeSetVolumeLevel(pContext, (int16_t)(maxdB*100)); |
| 3189 | |
| 3190 | /* Get the current settings */ |
| 3191 | LvmStatus =LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams); |
| 3192 | LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition") |
| 3193 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
| 3194 | |
| 3195 | /* Volume parameters */ |
| 3196 | ActiveParams.VC_Balance = pandB; |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3197 | ALOGV("\t\tVolumeSetStereoPosition() (-96dB -> +96dB)-> %d\n", ActiveParams.VC_Balance ); |
Eric Laurent | 4fd3ecc | 2010-09-28 14:09:57 -0700 | [diff] [blame] | 3198 | |
| 3199 | /* Activate the initial settings */ |
| 3200 | LvmStatus =LVM_SetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams); |
| 3201 | LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition") |
| 3202 | if(LvmStatus != LVM_SUCCESS) return -EINVAL; |
Eric Laurent | 021697a | 2010-07-23 00:54:58 -0700 | [diff] [blame] | 3203 | break; |
| 3204 | } |
| 3205 | case EFFECT_CMD_SET_AUDIO_MODE: |
| 3206 | break; |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3207 | default: |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3208 | return -EINVAL; |
| 3209 | } |
| 3210 | |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3211 | //ALOGV("\tEffect_command end...\n\n"); |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3212 | return 0; |
| 3213 | } /* end Effect_command */ |
| 3214 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 3215 | /* Effect Control Interface Implementation: get_descriptor */ |
| 3216 | int Effect_getDescriptor(effect_handle_t self, |
| 3217 | effect_descriptor_t *pDescriptor) |
| 3218 | { |
| 3219 | EffectContext * pContext = (EffectContext *) self; |
| 3220 | const effect_descriptor_t *desc; |
| 3221 | |
| 3222 | if (pContext == NULL || pDescriptor == NULL) { |
Steve Block | 71f2cf1 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 3223 | ALOGV("Effect_getDescriptor() invalid param"); |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 3224 | return -EINVAL; |
| 3225 | } |
| 3226 | |
| 3227 | switch(pContext->EffectType) { |
| 3228 | case LVM_BASS_BOOST: |
| 3229 | desc = &android::gBassBoostDescriptor; |
| 3230 | break; |
| 3231 | case LVM_VIRTUALIZER: |
| 3232 | desc = &android::gVirtualizerDescriptor; |
| 3233 | break; |
| 3234 | case LVM_EQUALIZER: |
| 3235 | desc = &android::gEqualizerDescriptor; |
| 3236 | break; |
| 3237 | case LVM_VOLUME: |
| 3238 | desc = &android::gVolumeDescriptor; |
| 3239 | break; |
| 3240 | default: |
| 3241 | return -EINVAL; |
| 3242 | } |
| 3243 | |
| 3244 | memcpy(pDescriptor, desc, sizeof(effect_descriptor_t)); |
| 3245 | |
| 3246 | return 0; |
| 3247 | } /* end Effect_getDescriptor */ |
| 3248 | |
| 3249 | // effect_handle_t interface implementation for effect |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3250 | const struct effect_interface_s gLvmEffectInterface = { |
| 3251 | Effect_process, |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 3252 | Effect_command, |
Eric Laurent | 325b8e8 | 2011-06-17 18:54:16 -0700 | [diff] [blame] | 3253 | Effect_getDescriptor, |
| 3254 | NULL, |
Eric Laurent | 2c87e9c | 2010-07-09 12:28:50 -0700 | [diff] [blame] | 3255 | }; /* end gLvmEffectInterface */ |
| 3256 | |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 3257 | audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = { |
| 3258 | tag : AUDIO_EFFECT_LIBRARY_TAG, |
| 3259 | version : EFFECT_LIBRARY_API_VERSION, |
| 3260 | name : "Effect Bundle Library", |
| 3261 | implementor : "NXP Software Ltd.", |
| 3262 | query_num_effects : android::EffectQueryNumberEffects, |
| 3263 | query_effect : android::EffectQueryEffect, |
| 3264 | create_effect : android::EffectCreate, |
| 3265 | release_effect : android::EffectRelease, |
| 3266 | get_descriptor : android::EffectGetDescriptor, |
| 3267 | }; |
| 3268 | |
| 3269 | } |