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