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