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