EffectBundle.cpp revision 7fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0
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_SUPPORTED: 1629 if (*pValueSize != sizeof(uint32_t)){ 1630 LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize %d", *pValueSize); 1631 return -EINVAL; 1632 } 1633 *pValueSize = sizeof(uint32_t); 1634 break; 1635 case BASSBOOST_PARAM_STRENGTH: 1636 if (*pValueSize != sizeof(int16_t)){ 1637 LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize %d", *pValueSize); 1638 return -EINVAL; 1639 } 1640 *pValueSize = sizeof(int16_t); 1641 break; 1642 1643 default: 1644 LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param); 1645 return -EINVAL; 1646 } 1647 1648 switch (param){ 1649 case BASSBOOST_PARAM_STRENGTH_SUPPORTED: 1650 *(uint32_t *)pValue = 1; 1651 1652 //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d", 1653 // *(uint32_t *)pValue); 1654 break; 1655 1656 case BASSBOOST_PARAM_STRENGTH: 1657 *(int16_t *)pValue = BassGetStrength(pContext); 1658 1659 //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d", 1660 // *(int16_t *)pValue); 1661 break; 1662 1663 default: 1664 LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param); 1665 status = -EINVAL; 1666 break; 1667 } 1668 1669 //LOGV("\tBassBoost_getParameter end"); 1670 return status; 1671} /* end BassBoost_getParameter */ 1672 1673//---------------------------------------------------------------------------- 1674// BassBoost_setParameter() 1675//---------------------------------------------------------------------------- 1676// Purpose: 1677// Set a BassBoost parameter 1678// 1679// Inputs: 1680// pBassBoost - handle to instance data 1681// pParam - pointer to parameter 1682// pValue - pointer to value 1683// 1684// Outputs: 1685// 1686//---------------------------------------------------------------------------- 1687 1688int BassBoost_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){ 1689 int status = 0; 1690 int16_t strength; 1691 1692 //LOGV("\tBassBoost_setParameter start"); 1693 1694 switch (*pParam){ 1695 case BASSBOOST_PARAM_STRENGTH: 1696 strength = *(int16_t *)pValue; 1697 //LOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength); 1698 //LOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength"); 1699 BassSetStrength(pContext, (int32_t)strength); 1700 //LOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength"); 1701 break; 1702 default: 1703 LOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParam); 1704 break; 1705 } 1706 1707 //LOGV("\tBassBoost_setParameter end"); 1708 return status; 1709} /* end BassBoost_setParameter */ 1710 1711//---------------------------------------------------------------------------- 1712// Virtualizer_getParameter() 1713//---------------------------------------------------------------------------- 1714// Purpose: 1715// Get a Virtualizer parameter 1716// 1717// Inputs: 1718// pVirtualizer - handle to instance data 1719// pParam - pointer to parameter 1720// pValue - pointer to variable to hold retrieved value 1721// pValueSize - pointer to value size: maximum size as input 1722// 1723// Outputs: 1724// *pValue updated with parameter value 1725// *pValueSize updated with actual value size 1726// 1727// 1728// Side Effects: 1729// 1730//---------------------------------------------------------------------------- 1731 1732int Virtualizer_getParameter(EffectContext *pContext, 1733 int32_t *pParam, 1734 size_t *pValueSize, 1735 void *pValue){ 1736 int status = 0; 1737 int32_t param = *pParam++; 1738 int32_t param2; 1739 char *name; 1740 1741 //LOGV("\tVirtualizer_getParameter start"); 1742 1743 switch (param){ 1744 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: 1745 if (*pValueSize != sizeof(uint32_t)){ 1746 LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize); 1747 return -EINVAL; 1748 } 1749 *pValueSize = sizeof(uint32_t); 1750 break; 1751 1752 case VIRTUALIZER_PARAM_STRENGTH: 1753 if (*pValueSize != sizeof(int16_t)){ 1754 LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize); 1755 return -EINVAL; 1756 } 1757 *pValueSize = sizeof(int16_t); 1758 break; 1759 1760 default: 1761 LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param); 1762 return -EINVAL; 1763 } 1764 1765 switch (param){ 1766 case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED: 1767 *(uint32_t *)pValue = 1; 1768 1769 //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d", 1770 // *(uint32_t *)pValue); 1771 break; 1772 1773 case VIRTUALIZER_PARAM_STRENGTH: 1774 *(int16_t *)pValue = VirtualizerGetStrength(pContext); 1775 1776 //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d", 1777 // *(int16_t *)pValue); 1778 break; 1779 1780 default: 1781 LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param); 1782 status = -EINVAL; 1783 break; 1784 } 1785 1786 //LOGV("\tVirtualizer_getParameter end"); 1787 return status; 1788} /* end Virtualizer_getParameter */ 1789 1790//---------------------------------------------------------------------------- 1791// Virtualizer_setParameter() 1792//---------------------------------------------------------------------------- 1793// Purpose: 1794// Set a Virtualizer parameter 1795// 1796// Inputs: 1797// pVirtualizer - handle to instance data 1798// pParam - pointer to parameter 1799// pValue - pointer to value 1800// 1801// Outputs: 1802// 1803//---------------------------------------------------------------------------- 1804 1805int Virtualizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){ 1806 int status = 0; 1807 int16_t strength; 1808 1809 //LOGV("\tVirtualizer_setParameter start"); 1810 1811 switch (*pParam){ 1812 case VIRTUALIZER_PARAM_STRENGTH: 1813 strength = *(int16_t *)pValue; 1814 //LOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength); 1815 //LOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength"); 1816 VirtualizerSetStrength(pContext, (int32_t)strength); 1817 //LOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength"); 1818 break; 1819 default: 1820 LOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", *pParam); 1821 break; 1822 } 1823 1824 //LOGV("\tVirtualizer_setParameter end"); 1825 return status; 1826} /* end Virtualizer_setParameter */ 1827 1828//---------------------------------------------------------------------------- 1829// Equalizer_getParameter() 1830//---------------------------------------------------------------------------- 1831// Purpose: 1832// Get a Equalizer parameter 1833// 1834// Inputs: 1835// pEqualizer - handle to instance data 1836// pParam - pointer to parameter 1837// pValue - pointer to variable to hold retrieved value 1838// pValueSize - pointer to value size: maximum size as input 1839// 1840// Outputs: 1841// *pValue updated with parameter value 1842// *pValueSize updated with actual value size 1843// 1844// 1845// Side Effects: 1846// 1847//---------------------------------------------------------------------------- 1848int Equalizer_getParameter(EffectContext *pContext, 1849 int32_t *pParam, 1850 size_t *pValueSize, 1851 void *pValue){ 1852 int status = 0; 1853 int bMute = 0; 1854 int32_t param = *pParam++; 1855 int32_t param2; 1856 char *name; 1857 1858 //LOGV("\tEqualizer_getParameter start"); 1859 1860 switch (param) { 1861 case EQ_PARAM_NUM_BANDS: 1862 case EQ_PARAM_CUR_PRESET: 1863 case EQ_PARAM_GET_NUM_OF_PRESETS: 1864 case EQ_PARAM_BAND_LEVEL: 1865 case EQ_PARAM_GET_BAND: 1866 if (*pValueSize < sizeof(int16_t)) { 1867 LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); 1868 return -EINVAL; 1869 } 1870 *pValueSize = sizeof(int16_t); 1871 break; 1872 1873 case EQ_PARAM_LEVEL_RANGE: 1874 if (*pValueSize < 2 * sizeof(int16_t)) { 1875 LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2 %d", *pValueSize); 1876 return -EINVAL; 1877 } 1878 *pValueSize = 2 * sizeof(int16_t); 1879 break; 1880 1881 case EQ_PARAM_BAND_FREQ_RANGE: 1882 if (*pValueSize < 2 * sizeof(int32_t)) { 1883 LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2 %d", *pValueSize); 1884 return -EINVAL; 1885 } 1886 *pValueSize = 2 * sizeof(int32_t); 1887 break; 1888 1889 case EQ_PARAM_CENTER_FREQ: 1890 if (*pValueSize < sizeof(int32_t)) { 1891 LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); 1892 return -EINVAL; 1893 } 1894 *pValueSize = sizeof(int32_t); 1895 break; 1896 1897 case EQ_PARAM_GET_PRESET_NAME: 1898 break; 1899 1900 case EQ_PARAM_PROPERTIES: 1901 if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) { 1902 LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1 %d", *pValueSize); 1903 return -EINVAL; 1904 } 1905 *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t); 1906 break; 1907 1908 default: 1909 LOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param); 1910 return -EINVAL; 1911 } 1912 1913 switch (param) { 1914 case EQ_PARAM_NUM_BANDS: 1915 *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS; 1916 //LOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue); 1917 break; 1918 1919 case EQ_PARAM_LEVEL_RANGE: 1920 *(int16_t *)pValue = -1500; 1921 *((int16_t *)pValue + 1) = 1500; 1922 //LOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d", 1923 // *(int32_t *)pValue, *((int32_t *)pValue + 1)); 1924 break; 1925 1926 case EQ_PARAM_BAND_LEVEL: 1927 param2 = *pParam; 1928 if (param2 >= FIVEBAND_NUMBANDS) { 1929 status = -EINVAL; 1930 break; 1931 } 1932 *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2); 1933 //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", 1934 // param2, *(int32_t *)pValue); 1935 break; 1936 1937 case EQ_PARAM_CENTER_FREQ: 1938 param2 = *pParam; 1939 if (param2 >= FIVEBAND_NUMBANDS) { 1940 status = -EINVAL; 1941 break; 1942 } 1943 *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2); 1944 //LOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d", 1945 // param2, *(int32_t *)pValue); 1946 break; 1947 1948 case EQ_PARAM_BAND_FREQ_RANGE: 1949 param2 = *pParam; 1950 if (param2 >= FIVEBAND_NUMBANDS) { 1951 status = -EINVAL; 1952 break; 1953 } 1954 EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1)); 1955 //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d", 1956 // param2, *(int32_t *)pValue, *((int32_t *)pValue + 1)); 1957 break; 1958 1959 case EQ_PARAM_GET_BAND: 1960 param2 = *pParam; 1961 *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2); 1962 //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d", 1963 // param2, *(int32_t *)pValue); 1964 break; 1965 1966 case EQ_PARAM_CUR_PRESET: 1967 *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext); 1968 //LOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue); 1969 break; 1970 1971 case EQ_PARAM_GET_NUM_OF_PRESETS: 1972 *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets(); 1973 //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue); 1974 break; 1975 1976 case EQ_PARAM_GET_PRESET_NAME: 1977 param2 = *pParam; 1978 if (param2 >= EqualizerGetNumPresets()) { 1979 //if (param2 >= 20) { // AGO FIX 1980 status = -EINVAL; 1981 break; 1982 } 1983 name = (char *)pValue; 1984 strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1); 1985 name[*pValueSize - 1] = 0; 1986 *pValueSize = strlen(name) + 1; 1987 //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d", 1988 // param2, gEqualizerPresets[param2].name, *pValueSize); 1989 break; 1990 1991 case EQ_PARAM_PROPERTIES: { 1992 int16_t *p = (int16_t *)pValue; 1993 LOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES"); 1994 p[0] = (int16_t)EqualizerGetPreset(pContext); 1995 p[1] = (int16_t)FIVEBAND_NUMBANDS; 1996 for (int i = 0; i < FIVEBAND_NUMBANDS; i++) { 1997 p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i); 1998 } 1999 } break; 2000 2001 default: 2002 LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param); 2003 status = -EINVAL; 2004 break; 2005 } 2006 2007 //LOGV("\tEqualizer_getParameter end"); 2008 return status; 2009} /* end Equalizer_getParameter */ 2010 2011//---------------------------------------------------------------------------- 2012// Equalizer_setParameter() 2013//---------------------------------------------------------------------------- 2014// Purpose: 2015// Set a Equalizer parameter 2016// 2017// Inputs: 2018// pEqualizer - handle to instance data 2019// pParam - pointer to parameter 2020// pValue - pointer to value 2021// 2022// Outputs: 2023// 2024//---------------------------------------------------------------------------- 2025int Equalizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){ 2026 int status = 0; 2027 int32_t preset; 2028 int32_t band; 2029 int32_t level; 2030 int32_t param = *pParam++; 2031 2032 //LOGV("\tEqualizer_setParameter start"); 2033 switch (param) { 2034 case EQ_PARAM_CUR_PRESET: 2035 preset = (int32_t)(*(uint16_t *)pValue); 2036 2037 //LOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset); 2038 if ((preset >= EqualizerGetNumPresets())||(preset < 0)) { 2039 status = -EINVAL; 2040 break; 2041 } 2042 EqualizerSetPreset(pContext, preset); 2043 break; 2044 case EQ_PARAM_BAND_LEVEL: 2045 band = *pParam; 2046 level = (int32_t)(*(int16_t *)pValue); 2047 //LOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level); 2048 if (band >= FIVEBAND_NUMBANDS) { 2049 status = -EINVAL; 2050 break; 2051 } 2052 EqualizerSetBandLevel(pContext, band, level); 2053 break; 2054 case EQ_PARAM_PROPERTIES: { 2055 //LOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES"); 2056 int16_t *p = (int16_t *)pValue; 2057 if ((int)p[0] >= EqualizerGetNumPresets()) { 2058 status = -EINVAL; 2059 break; 2060 } 2061 if (p[0] >= 0) { 2062 EqualizerSetPreset(pContext, (int)p[0]); 2063 } else { 2064 if ((int)p[1] != FIVEBAND_NUMBANDS) { 2065 status = -EINVAL; 2066 break; 2067 } 2068 for (int i = 0; i < FIVEBAND_NUMBANDS; i++) { 2069 EqualizerSetBandLevel(pContext, i, (int)p[2 + i]); 2070 } 2071 } 2072 } break; 2073 default: 2074 LOGV("\tLVM_ERROR : setParameter() invalid param %d", param); 2075 status = -EINVAL; 2076 break; 2077 } 2078 2079 //LOGV("\tEqualizer_setParameter end"); 2080 return status; 2081} /* end Equalizer_setParameter */ 2082 2083//---------------------------------------------------------------------------- 2084// Volume_getParameter() 2085//---------------------------------------------------------------------------- 2086// Purpose: 2087// Get a Volume parameter 2088// 2089// Inputs: 2090// pVolume - handle to instance data 2091// pParam - pointer to parameter 2092// pValue - pointer to variable to hold retrieved value 2093// pValueSize - pointer to value size: maximum size as input 2094// 2095// Outputs: 2096// *pValue updated with parameter value 2097// *pValueSize updated with actual value size 2098// 2099// 2100// Side Effects: 2101// 2102//---------------------------------------------------------------------------- 2103 2104int Volume_getParameter(EffectContext *pContext, 2105 int32_t *pParam, 2106 size_t *pValueSize, 2107 void *pValue){ 2108 int status = 0; 2109 int bMute = 0; 2110 int32_t param = *pParam++; 2111 int32_t param2; 2112 char *name; 2113 2114 LOGV("\tVolume_getParameter start"); 2115 2116 switch (param){ 2117 case VOLUME_PARAM_LEVEL: 2118 case VOLUME_PARAM_MAXLEVEL: 2119 case VOLUME_PARAM_STEREOPOSITION: 2120 if (*pValueSize != sizeof(int16_t)){ 2121 LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1 %d", *pValueSize); 2122 return -EINVAL; 2123 } 2124 *pValueSize = sizeof(int16_t); 2125 break; 2126 2127 case VOLUME_PARAM_MUTE: 2128 case VOLUME_PARAM_ENABLESTEREOPOSITION: 2129 if (*pValueSize < sizeof(int32_t)){ 2130 LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2 %d", *pValueSize); 2131 return -EINVAL; 2132 } 2133 *pValueSize = sizeof(int32_t); 2134 break; 2135 2136 default: 2137 LOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param); 2138 return -EINVAL; 2139 } 2140 2141 switch (param){ 2142 case VOLUME_PARAM_LEVEL: 2143 status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue)); 2144 LOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d", 2145 *(int16_t *)pValue); 2146 break; 2147 2148 case VOLUME_PARAM_MAXLEVEL: 2149 *(int16_t *)pValue = 0; 2150 LOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d", 2151 *(int16_t *)pValue); 2152 break; 2153 2154 case VOLUME_PARAM_STEREOPOSITION: 2155 VolumeGetStereoPosition(pContext, (int16_t *)pValue); 2156 LOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d", 2157 *(int16_t *)pValue); 2158 break; 2159 2160 case VOLUME_PARAM_MUTE: 2161 status = VolumeGetMute(pContext, (uint32_t *)pValue); 2162 LOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d", 2163 *(uint32_t *)pValue); 2164 break; 2165 2166 case VOLUME_PARAM_ENABLESTEREOPOSITION: 2167 *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled; 2168 LOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d", 2169 *(uint32_t *)pValue); 2170 break; 2171 2172 default: 2173 LOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param); 2174 status = -EINVAL; 2175 break; 2176 } 2177 2178 //LOGV("\tVolume_getParameter end"); 2179 return status; 2180} /* end Volume_getParameter */ 2181 2182 2183//---------------------------------------------------------------------------- 2184// Volume_setParameter() 2185//---------------------------------------------------------------------------- 2186// Purpose: 2187// Set a Volume parameter 2188// 2189// Inputs: 2190// pVolume - handle to instance data 2191// pParam - pointer to parameter 2192// pValue - pointer to value 2193// 2194// Outputs: 2195// 2196//---------------------------------------------------------------------------- 2197 2198int Volume_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){ 2199 int status = 0; 2200 int16_t level; 2201 int16_t position; 2202 uint32_t mute; 2203 uint32_t positionEnabled; 2204 2205 LOGV("\tVolume_setParameter start"); 2206 2207 switch (*pParam){ 2208 case VOLUME_PARAM_LEVEL: 2209 level = *(int16_t *)pValue; 2210 LOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level); 2211 LOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel"); 2212 status = VolumeSetVolumeLevel(pContext, (int16_t)level); 2213 LOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel"); 2214 break; 2215 2216 case VOLUME_PARAM_MUTE: 2217 mute = *(uint32_t *)pValue; 2218 LOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute); 2219 LOGV("\tVolume_setParameter() Calling pVolume->setMute"); 2220 status = VolumeSetMute(pContext, mute); 2221 LOGV("\tVolume_setParameter() Called pVolume->setMute"); 2222 break; 2223 2224 case VOLUME_PARAM_ENABLESTEREOPOSITION: 2225 positionEnabled = *(uint32_t *)pValue; 2226 status = VolumeEnableStereoPosition(pContext, positionEnabled); 2227 status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved); 2228 LOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called"); 2229 break; 2230 2231 case VOLUME_PARAM_STEREOPOSITION: 2232 position = *(int16_t *)pValue; 2233 LOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position); 2234 LOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition"); 2235 status = VolumeSetStereoPosition(pContext, (int16_t)position); 2236 LOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition"); 2237 break; 2238 2239 default: 2240 LOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", *pParam); 2241 break; 2242 } 2243 2244 //LOGV("\tVolume_setParameter end"); 2245 return status; 2246} /* end Volume_setParameter */ 2247 2248/**************************************************************************************** 2249 * Name : LVC_ToDB_s32Tos16() 2250 * Input : Signed 32-bit integer 2251 * Output : Signed 16-bit integer 2252 * MSB (16) = sign bit 2253 * (15->05) = integer part 2254 * (04->01) = decimal part 2255 * Returns : Db value with respect to full scale 2256 * Description : 2257 * Remarks : 2258 ****************************************************************************************/ 2259 2260LVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix) 2261{ 2262 LVM_INT16 db_fix; 2263 LVM_INT16 Shift; 2264 LVM_INT16 SmallRemainder; 2265 LVM_UINT32 Remainder = (LVM_UINT32)Lin_fix; 2266 2267 /* Count leading bits, 1 cycle in assembly*/ 2268 for (Shift = 0; Shift<32; Shift++) 2269 { 2270 if ((Remainder & 0x80000000U)!=0) 2271 { 2272 break; 2273 } 2274 Remainder = Remainder << 1; 2275 } 2276 2277 /* 2278 * Based on the approximation equation (for Q11.4 format): 2279 * 2280 * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2) 2281 */ 2282 db_fix = (LVM_INT16)(-96 * Shift); /* Six dB steps in Q11.4 format*/ 2283 SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24); 2284 db_fix = (LVM_INT16)(db_fix + SmallRemainder ); 2285 SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder); 2286 db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9)); 2287 2288 /* Correct for small offset */ 2289 db_fix = (LVM_INT16)(db_fix - 5); 2290 2291 return db_fix; 2292} 2293 2294} // namespace 2295} // namespace 2296 2297/* Effect Control Interface Implementation: Process */ 2298extern "C" int Effect_process(effect_interface_t self, 2299 audio_buffer_t *inBuffer, 2300 audio_buffer_t *outBuffer){ 2301 EffectContext * pContext = (EffectContext *) self; 2302 int status = 0; 2303 int lvmStatus = 0; 2304 LVM_INT16 *in = (LVM_INT16 *)inBuffer->raw; 2305 LVM_INT16 *out = (LVM_INT16 *)outBuffer->raw; 2306 2307 //LOGV("\tEffect_process Start : Enabled = %d Called = %d", 2308 //pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled); 2309 2310 if (pContext == NULL){ 2311 LOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL"); 2312 return -EINVAL; 2313 } 2314 if (inBuffer == NULL || inBuffer->raw == NULL || 2315 outBuffer == NULL || outBuffer->raw == NULL || 2316 inBuffer->frameCount != outBuffer->frameCount){ 2317 LOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG"); 2318 return -EINVAL; 2319 } 2320 if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&& 2321 (pContext->EffectType == LVM_BASS_BOOST)){ 2322 LOGV("\tEffect_process() ERROR LVM_BASS_BOOST Effect is not enabled"); 2323 status = -ENODATA; 2324 } 2325 if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&& 2326 (pContext->EffectType == LVM_VOLUME)){ 2327 LOGV("\tEffect_process() ERROR LVM_VOLUME Effect is not enabled"); 2328 status = -ENODATA; 2329 } 2330 if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&& 2331 (pContext->EffectType == LVM_EQUALIZER)){ 2332 LOGV("\tEffect_process() ERROR LVM_EQUALIZER Effect is not enabled"); 2333 status = -ENODATA; 2334 } 2335 if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&& 2336 (pContext->EffectType == LVM_VIRTUALIZER)){ 2337 LOGV("\tEffect_process() ERROR LVM_VIRTUALIZER Effect is not enabled"); 2338 status = -ENODATA; 2339 } 2340 2341 // If this is the last frame of an effect process its output with no effect 2342 if(status == -ENODATA){ 2343 if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){ 2344 //LOGV("\tLVM_ERROR : Effect_process() accumulating last frame into output buffer"); 2345 //LOGV("\tLVM_ERROR : Effect_process() trying copying last frame into output buffer"); 2346 //LOGV("\tLVM_ERROR : Enabled = %d Called = %d", 2347 //pContext->pBundledContext->NumberEffectsEnabled, 2348 //pContext->pBundledContext->NumberEffectsCalled); 2349 2350 }else{ 2351 //LOGV("\tLVM_ERROR : Effect_process() copying last frame into output buffer"); 2352 } 2353 } 2354 2355 if(status != -ENODATA){ 2356 pContext->pBundledContext->NumberEffectsCalled++; 2357 } 2358 2359 if(pContext->pBundledContext->NumberEffectsCalled == 2360 pContext->pBundledContext->NumberEffectsEnabled){ 2361 //LOGV("\tEffect_process Calling process with %d effects enabled, %d called: Effect %d", 2362 //pContext->pBundledContext->NumberEffectsEnabled, 2363 //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType); 2364 2365 if(status == -ENODATA){ 2366 //LOGV("\tLVM_ERROR : Effect_process() actually processing last frame"); 2367 } 2368 pContext->pBundledContext->NumberEffectsCalled = 0; 2369 /* Process all the available frames, block processing is 2370 handled internalLY by the LVM bundle */ 2371 lvmStatus = android::LvmBundle_process( (LVM_INT16 *)inBuffer->raw, 2372 (LVM_INT16 *)outBuffer->raw, 2373 outBuffer->frameCount, 2374 pContext); 2375 if(lvmStatus != LVM_SUCCESS){ 2376 LOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus); 2377 return lvmStatus; 2378 } 2379 }else{ 2380 //LOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d", 2381 //pContext->pBundledContext->NumberEffectsEnabled, 2382 //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType); 2383 // 2 is for stereo input 2384 memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2); 2385 } 2386 2387 return status; 2388} /* end Effect_process */ 2389 2390/* Effect Control Interface Implementation: Command */ 2391extern "C" int Effect_command(effect_interface_t self, 2392 uint32_t cmdCode, 2393 uint32_t cmdSize, 2394 void *pCmdData, 2395 uint32_t *replySize, 2396 void *pReplyData){ 2397 EffectContext * pContext = (EffectContext *) self; 2398 int retsize; 2399 2400 //LOGV("\t\nEffect_command start"); 2401 2402 if(pContext->EffectType == LVM_BASS_BOOST){ 2403 //LOGV("\tEffect_command setting command for LVM_BASS_BOOST"); 2404 } 2405 if(pContext->EffectType == LVM_VIRTUALIZER){ 2406 //LOGV("\tEffect_command setting command for LVM_VIRTUALIZER"); 2407 } 2408 if(pContext->EffectType == LVM_EQUALIZER){ 2409 //LOGV("\tEffect_command setting command for LVM_EQUALIZER"); 2410 } 2411 if(pContext->EffectType == LVM_VOLUME){ 2412 //LOGV("\tEffect_command setting command for LVM_VOLUME"); 2413 } 2414 2415 if (pContext == NULL){ 2416 LOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL"); 2417 return -EINVAL; 2418 } 2419 2420 //LOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize); 2421 2422 // Incase we disable an effect, next time process is 2423 // called the number of effect called could be greater 2424 // pContext->pBundledContext->NumberEffectsCalled = 0; 2425 2426 //LOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d", 2427 // pContext->pBundledContext->NumberEffectsCalled, 2428 // pContext->pBundledContext->NumberEffectsEnabled); 2429 2430 switch (cmdCode){ 2431 case EFFECT_CMD_INIT: 2432 if (pReplyData == NULL || *replySize != sizeof(int)){ 2433 LOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d", 2434 pContext->EffectType); 2435 return -EINVAL; 2436 } 2437 *(int *) pReplyData = 0; 2438 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start"); 2439 if(pContext->EffectType == LVM_BASS_BOOST){ 2440 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST"); 2441 android::BassSetStrength(pContext, 0); 2442 } 2443 if(pContext->EffectType == LVM_VIRTUALIZER){ 2444 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER"); 2445 android::VirtualizerSetStrength(pContext, 0); 2446 } 2447 if(pContext->EffectType == LVM_EQUALIZER){ 2448 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER"); 2449 android::EqualizerSetPreset(pContext, 0); 2450 } 2451 if(pContext->EffectType == LVM_VOLUME){ 2452 //LOGV("\tEffect_command cmdCode Case: " 2453 // "EFFECT_CMD_INIT start"); 2454 *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0); 2455 } 2456 break; 2457 2458 case EFFECT_CMD_CONFIGURE: 2459 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE start"); 2460 if (pCmdData == NULL|| 2461 cmdSize != sizeof(effect_config_t)|| 2462 pReplyData == NULL|| 2463 *replySize != sizeof(int)){ 2464 LOGV("\tLVM_ERROR : Effect_command cmdCode Case: " 2465 "EFFECT_CMD_CONFIGURE: ERROR"); 2466 return -EINVAL; 2467 } 2468 *(int *) pReplyData = android::Effect_configure(pContext, (effect_config_t *) pCmdData); 2469 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE end"); 2470 break; 2471 2472 case EFFECT_CMD_RESET: 2473 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start"); 2474 android::Effect_configure(pContext, &pContext->config); 2475 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end"); 2476 break; 2477 2478 case EFFECT_CMD_GET_PARAM:{ 2479 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start"); 2480 2481 if(pContext->EffectType == LVM_BASS_BOOST){ 2482 if (pCmdData == NULL || 2483 cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || 2484 pReplyData == NULL || 2485 *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ 2486 LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " 2487 "EFFECT_CMD_GET_PARAM: ERROR"); 2488 return -EINVAL; 2489 } 2490 effect_param_t *p = (effect_param_t *)pCmdData; 2491 2492 memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); 2493 2494 p = (effect_param_t *)pReplyData; 2495 2496 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); 2497 2498 p->status = android::BassBoost_getParameter(pContext, 2499 (int32_t *)p->data, 2500 (size_t *)&p->vsize, 2501 p->data + voffset); 2502 2503 *replySize = sizeof(effect_param_t) + voffset + p->vsize; 2504 2505 //LOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM " 2506 // "*pCmdData %d, *replySize %d, *pReplyData %d ", 2507 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), 2508 // *replySize, 2509 // *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); 2510 } 2511 2512 if(pContext->EffectType == LVM_VIRTUALIZER){ 2513 if (pCmdData == NULL || 2514 cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || 2515 pReplyData == NULL || 2516 *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ 2517 LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " 2518 "EFFECT_CMD_GET_PARAM: ERROR"); 2519 return -EINVAL; 2520 } 2521 effect_param_t *p = (effect_param_t *)pCmdData; 2522 2523 memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); 2524 2525 p = (effect_param_t *)pReplyData; 2526 2527 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); 2528 2529 p->status = android::Virtualizer_getParameter(pContext, 2530 (int32_t *)p->data, 2531 (size_t *)&p->vsize, 2532 p->data + voffset); 2533 2534 *replySize = sizeof(effect_param_t) + voffset + p->vsize; 2535 2536 //LOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM " 2537 // "*pCmdData %d, *replySize %d, *pReplyData %d ", 2538 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), 2539 // *replySize, 2540 // *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); 2541 } 2542 if(pContext->EffectType == LVM_EQUALIZER){ 2543 //LOGV("\tEqualizer_command cmdCode Case: " 2544 // "EFFECT_CMD_GET_PARAM start"); 2545 if (pCmdData == NULL || 2546 cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || 2547 pReplyData == NULL || 2548 *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) { 2549 LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " 2550 "EFFECT_CMD_GET_PARAM"); 2551 return -EINVAL; 2552 } 2553 effect_param_t *p = (effect_param_t *)pCmdData; 2554 2555 memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); 2556 2557 p = (effect_param_t *)pReplyData; 2558 2559 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); 2560 2561 p->status = android::Equalizer_getParameter(pContext, (int32_t *)p->data, &p->vsize, 2562 p->data + voffset); 2563 2564 *replySize = sizeof(effect_param_t) + voffset + p->vsize; 2565 2566 //LOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, " 2567 // "*pReplyData %08x %08x", 2568 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize, 2569 // *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset), 2570 // *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset + 2571 // sizeof(int32_t))); 2572 } 2573 if(pContext->EffectType == LVM_VOLUME){ 2574 //LOGV("\tVolume_command cmdCode Case: " 2575 // "EFFECT_CMD_GET_PARAM start"); 2576 if (pCmdData == NULL || 2577 cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || 2578 pReplyData == NULL || 2579 *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){ 2580 LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " 2581 "EFFECT_CMD_GET_PARAM: ERROR"); 2582 return -EINVAL; 2583 } 2584 effect_param_t *p = (effect_param_t *)pCmdData; 2585 2586 memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize); 2587 2588 p = (effect_param_t *)pReplyData; 2589 2590 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t); 2591 2592 p->status = android::Volume_getParameter(pContext, 2593 (int32_t *)p->data, 2594 (size_t *)&p->vsize, 2595 p->data + voffset); 2596 2597 *replySize = sizeof(effect_param_t) + voffset + p->vsize; 2598 2599 //LOGV("\tVolume_command EFFECT_CMD_GET_PARAM " 2600 // "*pCmdData %d, *replySize %d, *pReplyData %d ", 2601 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), 2602 // *replySize, 2603 // *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset)); 2604 } 2605 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end"); 2606 } break; 2607 case EFFECT_CMD_SET_PARAM:{ 2608 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start"); 2609 if(pContext->EffectType == LVM_BASS_BOOST){ 2610 //LOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", 2611 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), 2612 // *replySize, 2613 // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); 2614 2615 if (pCmdData == NULL|| 2616 cmdSize != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))|| 2617 pReplyData == NULL|| 2618 *replySize != sizeof(int32_t)){ 2619 LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " 2620 "EFFECT_CMD_SET_PARAM: ERROR"); 2621 return -EINVAL; 2622 } 2623 effect_param_t *p = (effect_param_t *) pCmdData; 2624 2625 if (p->psize != sizeof(int32_t)){ 2626 LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " 2627 "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)"); 2628 return -EINVAL; 2629 } 2630 2631 //LOGV("\tnBassBoost_command cmdSize is %d\n" 2632 // "\tsizeof(effect_param_t) is %d\n" 2633 // "\tp->psize is %d\n" 2634 // "\tp->vsize is %d" 2635 // "\n", 2636 // cmdSize, sizeof(effect_param_t), p->psize, p->vsize ); 2637 2638 *(int *)pReplyData = android::BassBoost_setParameter(pContext, 2639 (int32_t *)p->data, 2640 p->data + p->psize); 2641 } 2642 if(pContext->EffectType == LVM_VIRTUALIZER){ 2643 //LOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d", 2644 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), 2645 // *replySize, 2646 // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); 2647 2648 if (pCmdData == NULL|| 2649 cmdSize != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))|| 2650 pReplyData == NULL|| 2651 *replySize != sizeof(int32_t)){ 2652 LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " 2653 "EFFECT_CMD_SET_PARAM: ERROR"); 2654 return -EINVAL; 2655 } 2656 effect_param_t *p = (effect_param_t *) pCmdData; 2657 2658 if (p->psize != sizeof(int32_t)){ 2659 LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " 2660 "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)"); 2661 return -EINVAL; 2662 } 2663 2664 //LOGV("\tnVirtualizer_command cmdSize is %d\n" 2665 // "\tsizeof(effect_param_t) is %d\n" 2666 // "\tp->psize is %d\n" 2667 // "\tp->vsize is %d" 2668 // "\n", 2669 // cmdSize, sizeof(effect_param_t), p->psize, p->vsize ); 2670 2671 *(int *)pReplyData = android::Virtualizer_setParameter(pContext, 2672 (int32_t *)p->data, 2673 p->data + p->psize); 2674 } 2675 if(pContext->EffectType == LVM_EQUALIZER){ 2676 //LOGV("\tEqualizer_command cmdCode Case: " 2677 // "EFFECT_CMD_SET_PARAM start"); 2678 //LOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", 2679 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), 2680 // *replySize, 2681 // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); 2682 2683 if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) || 2684 pReplyData == NULL || *replySize != sizeof(int32_t)) { 2685 LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " 2686 "EFFECT_CMD_SET_PARAM: ERROR"); 2687 return -EINVAL; 2688 } 2689 effect_param_t *p = (effect_param_t *) pCmdData; 2690 2691 *(int *)pReplyData = android::Equalizer_setParameter(pContext, 2692 (int32_t *)p->data, 2693 p->data + p->psize); 2694 } 2695 if(pContext->EffectType == LVM_VOLUME){ 2696 //LOGV("\tVolume_command cmdCode Case: " 2697 // "EFFECT_CMD_SET_PARAM start"); 2698 //LOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ", 2699 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), 2700 // *replySize, 2701 // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t))); 2702 2703 if ( pCmdData == NULL|| 2704 cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t))|| 2705 pReplyData == NULL|| 2706 *replySize != sizeof(int32_t)){ 2707 LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " 2708 "EFFECT_CMD_SET_PARAM: ERROR"); 2709 return -EINVAL; 2710 } 2711 effect_param_t *p = (effect_param_t *) pCmdData; 2712 2713 *(int *)pReplyData = android::Volume_setParameter(pContext, 2714 (int32_t *)p->data, 2715 p->data + p->psize); 2716 } 2717 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end"); 2718 } break; 2719 2720 case EFFECT_CMD_ENABLE: 2721 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start"); 2722 if (pReplyData == NULL || *replySize != sizeof(int)){ 2723 LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR"); 2724 return -EINVAL; 2725 } 2726 switch (pContext->EffectType){ 2727 case LVM_BASS_BOOST: 2728 if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){ 2729 LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " 2730 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); 2731 return -EINVAL; 2732 } 2733 pContext->pBundledContext->bBassEnabled = LVM_TRUE; 2734 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_BASS_BOOST enabled"); 2735 break; 2736 case LVM_EQUALIZER: 2737 if(pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE){ 2738 LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " 2739 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); 2740 return -EINVAL; 2741 } 2742 pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE; 2743 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_EQUALIZER enabled"); 2744 break; 2745 case LVM_VIRTUALIZER: 2746 if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){ 2747 LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " 2748 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); 2749 return -EINVAL; 2750 } 2751 pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE; 2752 //LOGV("\tEffect_command cmdCode Case:EFFECT_CMD_ENABLE LVM_VIRTUALIZER enabled"); 2753 break; 2754 case LVM_VOLUME: 2755 if(pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){ 2756 LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " 2757 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled"); 2758 return -EINVAL; 2759 } 2760 pContext->pBundledContext->bVolumeEnabled = LVM_TRUE; 2761 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_VOLUME enabled"); 2762 break; 2763 default: 2764 LOGV("\tLVM_ERROR : Effect_command cmdCode Case: " 2765 "EFFECT_CMD_ENABLE: ERROR, invalid Effect Type"); 2766 return -EINVAL; 2767 } 2768 *(int *)pReplyData = 0; 2769 pContext->pBundledContext->NumberEffectsEnabled++; 2770 android::LvmEffect_enable(pContext); 2771 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE NumberEffectsEnabled = %d", 2772 // pContext->pBundledContext->NumberEffectsEnabled); 2773 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE end"); 2774 break; 2775 2776 case EFFECT_CMD_DISABLE: 2777 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start"); 2778 if (pReplyData == NULL || *replySize != sizeof(int)){ 2779 LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR"); 2780 return -EINVAL; 2781 } 2782 switch (pContext->EffectType){ 2783 case LVM_BASS_BOOST: 2784 if(pContext->pBundledContext->bBassEnabled == LVM_FALSE){ 2785 LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: " 2786 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); 2787 return -EINVAL; 2788 } 2789 pContext->pBundledContext->bBassEnabled = LVM_FALSE; 2790 //LOGV("\tEffect_command cmdCode Case: " 2791 // "EFFECT_CMD_DISABLE LVM_BASS_BOOST disabled"); 2792 break; 2793 case LVM_EQUALIZER: 2794 if(pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE){ 2795 LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: " 2796 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); 2797 return -EINVAL; 2798 } 2799 pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE; 2800 //LOGV("\tEffect_command cmdCode Case: " 2801 // "EFFECT_CMD_DISABLE LVM_EQUALIZER disabled"); 2802 break; 2803 case LVM_VIRTUALIZER: 2804 if(pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE){ 2805 LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: " 2806 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); 2807 return -EINVAL; 2808 } 2809 pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE; 2810 //LOGV("\tEffect_command cmdCode Case: " 2811 // "EFFECT_CMD_DISABLE LVM_VIRTUALIZER disabled"); 2812 break; 2813 case LVM_VOLUME: 2814 if(pContext->pBundledContext->bVolumeEnabled == LVM_FALSE){ 2815 LOGV("\tLVM_ERROR : Volume_command cmdCode Case: " 2816 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled"); 2817 return -EINVAL; 2818 } 2819 pContext->pBundledContext->bVolumeEnabled = LVM_FALSE; 2820 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_VOLUME disabled"); 2821 break; 2822 default: 2823 LOGV("\tLVM_ERROR : Effect_command cmdCode Case: " 2824 "EFFECT_CMD_DISABLE: ERROR, invalid Effect Type"); 2825 return -EINVAL; 2826 } 2827 *(int *)pReplyData = 0; 2828 pContext->pBundledContext->NumberEffectsEnabled--; 2829 android::LvmEffect_disable(pContext); 2830 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE NumberEffectsEnabled = %d", 2831 // pContext->pBundledContext->NumberEffectsEnabled); 2832 //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE end"); 2833 break; 2834 2835 case EFFECT_CMD_SET_DEVICE: 2836 { 2837 LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start"); 2838 audio_device_e device = *(audio_device_e *)pCmdData; 2839 2840 if(pContext->EffectType == LVM_BASS_BOOST){ 2841 if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)|| 2842 (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){ 2843 LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d", 2844 *(int32_t *)pCmdData); 2845 LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST"); 2846 2847 // If a device doesnt support bassboost the effect must be temporarily disabled 2848 // the effect must still report its original state as this can only be changed 2849 // by the ENABLE/DISABLE command 2850 2851 if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){ 2852 LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d", 2853 *(int32_t *)pCmdData); 2854 android::LvmEffect_disable(pContext); 2855 pContext->pBundledContext->bBassTempDisabled = LVM_TRUE; 2856 } 2857 }else{ 2858 LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d", 2859 *(int32_t *)pCmdData); 2860 2861 // If a device supports bassboost and the effect has been temporarily disabled 2862 // previously then re-enable it 2863 2864 if(pContext->pBundledContext->bBassTempDisabled == LVM_TRUE){ 2865 LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d", 2866 *(int32_t *)pCmdData); 2867 android::LvmEffect_enable(pContext); 2868 pContext->pBundledContext->bBassTempDisabled = LVM_FALSE; 2869 } 2870 } 2871 } 2872 if(pContext->EffectType == LVM_VIRTUALIZER){ 2873 if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)|| 2874 (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){ 2875 LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d", 2876 *(int32_t *)pCmdData); 2877 LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER"); 2878 2879 //If a device doesnt support virtualizer the effect must be temporarily disabled 2880 // the effect must still report its original state as this can only be changed 2881 // by the ENABLE/DISABLE command 2882 2883 if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){ 2884 LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d", 2885 *(int32_t *)pCmdData); 2886 android::LvmEffect_disable(pContext); 2887 pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE; 2888 } 2889 }else{ 2890 LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d", 2891 *(int32_t *)pCmdData); 2892 2893 // If a device supports virtualizer and the effect has been temporarily disabled 2894 // previously then re-enable it 2895 2896 if(pContext->pBundledContext->bVirtualizerTempDisabled == LVM_TRUE){ 2897 LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d", 2898 *(int32_t *)pCmdData); 2899 android::LvmEffect_enable(pContext); 2900 pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE; 2901 } 2902 } 2903 } 2904 LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end"); 2905 break; 2906 } 2907 case EFFECT_CMD_SET_VOLUME: 2908 { 2909 int32_t channels = cmdSize/sizeof(int32_t); 2910 int32_t vol = *(int32_t *)pCmdData; 2911 int16_t vol_db; 2912 int16_t dB; 2913 int16_t vol_db_rnd; 2914 int32_t vol_ret[2] = {1<<24,1<<24}; // Apply no volume 2915 2916 // if pReplyData is NULL, VOL_CTRL is delegated to another effect 2917 if(pReplyData == LVM_NULL){ 2918 break; 2919 } 2920 2921 if(vol==0x1000000){ 2922 vol -= 1; 2923 } 2924 // Convert volume linear (Q8.24) to volume dB (0->-96) 2925 dB = android::LVC_ToDB_s32Tos16(vol <<7); 2926 dB = (dB +8)>>4; 2927 dB = (dB <-96) ? -96 : dB ; 2928 2929 //LOGV("\tSession: %d, VOLUME is %d dB (%d), effect is %d", 2930 //pContext->pBundledContext->SessionNo, (int32_t)dB, vol<<7, pContext->EffectType); 2931 memcpy(pReplyData, vol_ret, sizeof(int32_t)*2); 2932 android::VolumeSetVolumeLevel(pContext, (int16_t)(dB*100)); 2933 break; 2934 } 2935 case EFFECT_CMD_SET_AUDIO_MODE: 2936 break; 2937 default: 2938 return -EINVAL; 2939 } 2940 2941 //LOGV("\tEffect_command end...\n\n"); 2942 return 0; 2943} /* end Effect_command */ 2944 2945// effect_interface_t interface implementation for effect 2946const struct effect_interface_s gLvmEffectInterface = { 2947 Effect_process, 2948 Effect_command 2949}; /* end gLvmEffectInterface */ 2950 2951