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