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