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