EffectBundle.cpp revision 8f45bd725549436eeacd12ee69349e2332ed8da5
12c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/*
22c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Copyright (C) 2010-2010 NXP Software
32c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Copyright (C) 2009 The Android Open Source Project
42c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
52c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
62c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * you may not use this file except in compliance with the License.
72c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * You may obtain a copy of the License at
82c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
92c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Unless required by applicable law or agreed to in writing, software
122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * See the License for the specific language governing permissions and
152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * limitations under the License.
162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent */
172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LOG_TAG "Bundle"
192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
2097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//#define LOG_NDEBUG 0
212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <cutils/log.h>
232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <assert.h>
242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <stdlib.h>
252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <string.h>
262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <new>
272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <EffectBundle.h>
282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for bass boost
312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" const struct effect_interface_s gLvmEffectInterface;
322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_NULLADDRESS){\
352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_ALIGNMENTERROR){\
392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad alignment returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_INVALIDNUMSAMPLES){\
432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_OUTOFRANGE){\
472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "out of range returned by %s in %s\n", callingFunc, calledFunc);\
492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Namespaces
532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace android {
542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace {
552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* local functions */
572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define CHECK_ARG(cond) {                     \
582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (!(cond)) {                            \
592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Invalid argument: "#cond);      \
602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;                       \
612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }                                         \
622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
64163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Flag to allow a one time init of global memory, only happens on first call ever
652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmInitFlag = LVM_FALSE;
66c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint LvmSessionsActive = 0;
67c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric LaurentSessionContext GlobalSessionMemory[LVM_MAX_SESSIONS];
68c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint SessionIndex[LVM_MAX_SESSIONS];
692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW BassBoost UUID
712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gBassBoostDescriptor = {
722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
75163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
76163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
77d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BASS_BOOST_CUP_LOAD_ARM9E,
78d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Dynamic Bass Boost",
802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Virtualizer UUID
842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVirtualizerDescriptor = {
85163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
86163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
88163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
89163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
90d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VIRTUALIZER_CUP_LOAD_ARM9E,
91d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Virtualizer",
932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Equalizer UUID
972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gEqualizerDescriptor = {
982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP
1002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
101163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
102d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        EQUALIZER_CUP_LOAD_ARM9E,
103d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Equalizer",
1052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Volume UUID
1092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVolumeDescriptor = {
1102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
1112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP
1122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
113163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
114d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VOLUME_CUP_LOAD_ARM9E,
115d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Volume",
1172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//--- local function prototypes
1212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init      (void);
1222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmBundle_init            (EffectContext *pContext);
1232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_enable          (EffectContext *pContext);
1242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_disable         (EffectContext *pContext);
1252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free            (EffectContext *pContext);
126163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  Effect_configure          (EffectContext *pContext, effect_config_t *pConfig);
127c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  BassBoost_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
128163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  BassBoost_getParameter    (EffectContext *pContext,
129c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
1312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               void           *pValue);
132c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Virtualizer_setParameter  (EffectContext *pContext, void *pParam, void *pValue);
1332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Virtualizer_getParameter  (EffectContext *pContext,
134c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
136163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                               void           *pValue);
137c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Equalizer_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
1382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Equalizer_getParameter    (EffectContext *pContext,
139c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
142c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Volume_setParameter       (EffectContext *pContext, void *pParam, void *pValue);
1432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Volume_getParameter       (EffectContext *pContext,
144c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
1472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Library Interface Implementation */
1492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){
1502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryNumberEffects start");
1512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pNumEffects = 4;
152163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects);
153163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects end\n");
1542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryNumberEffects */
1562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor){
1582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryEffect start");
1592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect processing index %d", index);
160163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pDescriptor == NULL){
162163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer");
1632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
1642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (index > 3){
166163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index);
1672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -ENOENT;
1682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(index == LVM_BASS_BOOST){
1702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_BASS_BOOST");
1712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gBassBoostDescriptor,   sizeof(effect_descriptor_t));
1722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else if(index == LVM_VIRTUALIZER){
1732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VIRTUALIZER");
1742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVirtualizerDescriptor, sizeof(effect_descriptor_t));
1752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_EQUALIZER){
1762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_EQUALIZER");
1772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gEqualizerDescriptor,   sizeof(effect_descriptor_t));
1782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_VOLUME){
1792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VOLUME");
1802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVolumeDescriptor, sizeof(effect_descriptor_t));
181163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect end\n");
1832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryEffect */
1852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectCreate(effect_uuid_t       *uuid,
1872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             sessionId,
1882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             ioId,
1892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            effect_interface_t  *pInterface){
1902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int ret;
191c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int sessionNo;
1922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int i;
1932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext *pContext = new EffectContext;
1942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectCreate start session %d", sessionId);
1962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pInterface == NULL || uuid == NULL){
198163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer");
1992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
2002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
202c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(sessionId < 0){
2032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : EffectCreate sessionId is less than 0");
204163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
2052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmInitFlag == LVM_FALSE){
2082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmInitFlag = LVM_TRUE;
2092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Initializing all global memory");
2102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmGlobalBundle_init();
2112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
213c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LOGV("\tEffectCreate: There are %d LVM sessions acive\n", LvmSessionsActive);
214c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
215c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Find next available sessionNo
216c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for(i=0; i<LVM_MAX_SESSIONS; i++){
217c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if((SessionIndex[i] == -1)||(SessionIndex[i] == sessionId)){
218c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            sessionNo       = i;
219c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            SessionIndex[i] = sessionId;
220c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffectCreate: Allocating SessionNo %d for SessionId %d\n", sessionNo,sessionId);
221c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
222c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
223c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
224c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
225c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(i==LVM_MAX_SESSIONS){
226c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tLVM_ERROR : Cannot find memory to allocate for current session");
227c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
228c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
2292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // If this is the first create in this session
230c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(GlobalSessionMemory[sessionNo].bBundledEffectsEnabled == LVM_FALSE){
231c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectCreate - This is the first effect in current sessionId %d sessionNo %d",
232c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionId, sessionNo);
233c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
234c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LvmSessionsActive++;
235c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
236c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(LvmSessionsActive >= LVM_MAX_SESSIONS){
237c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Number of active session is greater than LVM_MAX_SESSIONS (%d)",
238c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                  LVM_MAX_SESSIONS);
239c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            return -EINVAL;
240c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
241163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
242c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_TRUE;
243c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].pBundledContext        = new BundledEffectContext;
2442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
245c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = GlobalSessionMemory[sessionNo].pBundledContext;
246c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionNo                = sessionNo;
247c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionId                = sessionId;
248163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->hInstance                = NULL;
249163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVolumeEnabled           = LVM_FALSE;
250163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bEqualizerEnabled        = LVM_FALSE;
251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassEnabled             = LVM_FALSE;
252163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassTempDisabled        = LVM_FALSE;
253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerEnabled      = LVM_FALSE;
254163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsEnabled     = 0;
256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled      = 0;
257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->frameCount               = 0;
258d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        pContext->pBundledContext->firstVolume              = LVM_TRUE;
259163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
260163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
261163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2628f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        char fileName[256];
2638f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_in.pcm", pContext->pBundledContext);
2648f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmInPtr = fopen(fileName, "w");
2658f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr == NULL) {
2668f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            LOGV("cannot open %s", fileName);
2678f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent           return -EINVAL;
2688f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
269163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2708f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_out.pcm", pContext->pBundledContext);
2718f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmOutPtr = fopen(fileName, "w");
2728f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr == NULL) {
2738f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            LOGV("cannot open %s", fileName);
2748f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
2758f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent           pContext->pBundledContext->PcmInPtr = NULL;
276163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           return -EINVAL;
277163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2788f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent
279163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
280163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        /* Saved strength is used to return the exact strength that was used in the set to the get
2822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * because we map the original strength range of 0:1000 to 1:15, and this will avoid
2832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * quantisation like effect when returning
2842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         */
285163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->BassStrengthSaved        = 0;
286163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->VirtStrengthSaved        = 0;
287163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->CurPreset                = PRESET_CUSTOM;
288163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved               = 0;
289163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bMuteEnabled             = LVM_FALSE;
290163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bStereoPositionEnabled   = LVM_FALSE;
291163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved            = 0;
292163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Calling LvmBundle_init");
2942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ret = LvmBundle_init(pContext);
2952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (ret < 0){
2972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : EffectCreate() Bundle init failed");
2982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            delete pContext->pBundledContext;
2992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            delete pContext;
3002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return ret;
3012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
3022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
304c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectCreate - Assigning memory for previously created effect on sessionNo %d",
305c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionNo);
306c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext =
307c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                GlobalSessionMemory[sessionNo].pBundledContext;
3082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext);
3102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Create each Effect
3122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Bass Boost
3142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST");
315c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated = LVM_TRUE;
316163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
317163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_BASS_BOOST;
3192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Virtualizer
321163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER");
322c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated=LVM_TRUE;
323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VIRTUALIZER;
3262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Equalizer
328163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER");
329c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated = LVM_TRUE;
330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_EQUALIZER;
3332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Volume
335163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VOLUME");
336c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated = LVM_TRUE;
337163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VOLUME;
340163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
342163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() invalid UUID");
343163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
3442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pInterface = (effect_interface_t)pContext;
347163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectCreate end..\n\n");
3482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
3492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectCreate */
3502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectRelease(effect_interface_t interface){
3522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectRelease start %p", interface);
3532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *)interface;
3542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
355c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LOGV("\n\tEffectRelease start interface: %p, context %p", interface, pContext->pBundledContext);
3562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
357163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
3582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Clear the instantiated flag for the effect
3622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
3632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag");
364163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated = LVM_FALSE;
3652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VIRTUALIZER) {
3662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag");
367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated
368163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            = LVM_FALSE;
3692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_EQUALIZER) {
3702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag");
371163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated =LVM_FALSE;
3722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VOLUME) {
3732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag");
374163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated = LVM_FALSE;
3752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
3762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n");
3772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext
3802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if((GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated == LVM_FALSE)&&
381163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated == LVM_FALSE)&&
382163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated ==LVM_FALSE)&&
383163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated==LVM_FALSE))
3842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
385163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
3868f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr != NULL) {
3878f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
3888f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmInPtr = NULL;
3898f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
3908f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr != NULL) {
3918f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmOutPtr);
3928f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmOutPtr = NULL;
3938f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
395c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
396c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LvmSessionsActive--;
397c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectRelease: There are %d LVM sessions remaining\n", LvmSessionsActive);
398c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
399c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        // Clear the SessionIndex
400c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        for(int i=0; i<LVM_MAX_SESSIONS; i++){
401c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(SessionIndex[i] == pContext->pBundledContext->SessionId){
402c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                SessionIndex[i] = -1;
403c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                LOGV("\tEffectRelease: Clearing SessionIndex SessionNo %d for SessionId %d\n",
404c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        i, pContext->pBundledContext->SessionId);
405c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                break;
406c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
407c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
408c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: All effects are no longer instantiated\n");
410163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBundledEffectsEnabled =LVM_FALSE;
411163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].pBundledContext = LVM_NULL;
412163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: Freeing LVM Bundle memory\n");
413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmEffect_free(pContext);
414c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectRelease: Deleting LVM Bundle context %p\n", pContext->pBundledContext);
415163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        delete pContext->pBundledContext;
416c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = LVM_NULL;
4172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // free the effect context for current effect
4192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    delete pContext;
4202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectRelease end\n");
4222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
4232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectRelease */
4252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init(){
4272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmGlobalBundle_init start");
4282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for(int i=0; i<LVM_MAX_SESSIONS; i++){
4292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBundledEffectsEnabled   = LVM_FALSE;
4302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVolumeInstantiated      = LVM_FALSE;
4312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bEqualizerInstantiated   = LVM_FALSE;
4322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBassInstantiated        = LVM_FALSE;
4332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE;
4342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].pBundledContext          = LVM_NULL;
435c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
436c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        SessionIndex[i] = -1;
4372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
4392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
4402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_init()
4422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Initialize engine with default configuration, creates instance
4442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// with all effects disabled.
4452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
4472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
4482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
4502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_init(EffectContext *pContext){
4542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status;
4552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init start");
4572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
458163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
459163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.channels                      = CHANNEL_STEREO;
460163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.format                        = SAMPLE_FORMAT_PCM_S15;
461163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
462163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
463163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
464163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
465163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
466163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
467163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.channels                     = CHANNEL_STEREO;
468163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.format                       = SAMPLE_FORMAT_PCM_S15;
469163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
470163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
471163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
472163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
4742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
4762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext->pBundledContext->hInstance != NULL){
4782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
4792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Calling pContext->pBassBoost->free()");
4802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmEffect_free(pContext);
4822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
4842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Called pContext->pBassBoost->free()");
4852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;          /* Function call status */
4882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                         /* Control Parameters */
4892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_InstParams_t        InstParams;                     /* Instance parameters */
4902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_EQNB_BandDef_t      BandDefs[MAX_NUM_BANDS];        /* Equaliser band definitions */
4912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomParams_t    HeadroomParams;                 /* Headroom parameters */
4922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomBandDef_t   HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS];
4932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;                         /* Memory allocation table */
4942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    bool                    bMallocFailure = LVM_FALSE;
4952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the capabilities */
497163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    InstParams.BufferMode       = LVM_UNMANAGED_BUFFERS;
4982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.MaxBlockSize     = MAX_CALL_SIZE;
4992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.EQNB_NumBands    = MAX_NUM_BANDS;
5002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.PSA_Included     = LVM_PSA_ON;
5012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory, forcing alignment */
5032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(LVM_NULL,
5042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &MemTab,
5052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &InstParams);
5062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init")
5082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
5112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory */
5132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
5152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
5162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
518d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
519d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u\n", MemTab.Region[i].Size, i );
5202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                bMallocFailure = LVM_TRUE;
5212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
522163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmBundle_init CreateInstance allocated %ld bytes for region %u at %p\n",
5232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
5292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     * succesfully allocated and return with an error
5302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     */
5312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(bMallocFailure == LVM_TRUE){
5322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
534d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
535d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u Not freeing\n", MemTab.Region[i].Size, i );
5362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
537163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %ld bytes "
538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "for region %u at %p- free\n",
539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
5412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
5442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n");
5462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Initialise */
548163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->hInstance = LVM_NULL;
5492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
550163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Init sets the instance handle */
551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,
5522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &MemTab,
5532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &InstParams);
5542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init")
5562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
558163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
5592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the initial process parameters */
5612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* General parameters */
5622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.OperatingMode          = LVM_MODE_ON;
5632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SampleRate             = LVM_FS_44100;
5642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SourceFormat           = LVM_STEREO;
5652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SpeakerType            = LVM_HEADPHONES;
5662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->SampleRate = LVM_FS_44100;
568c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->pBundledContext->SamplesToExitCountEq   = 44100*2*2; // 2 secs Stereo
569c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->pBundledContext->SamplesToExitCountBb   = 44100*2*2; // 2 secs Stereo
570c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->pBundledContext->SamplesToExitCountVirt = 44100*2*2; // 2 secs Stereo
571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
5722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Concert Sound parameters */
5732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerOperatingMode   = LVM_MODE_OFF;
5742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerType            = LVM_CONCERTSOUND;
5752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerReverbLevel     = 100;
576d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.CS_EffectLevel             = LVM_CS_EFFECT_NONE;
5772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* N-Band Equaliser parameters */
5792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_OperatingMode     = LVM_EQNB_OFF;
5802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_NBands            = FIVEBAND_NUMBANDS;
5812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.pEQNB_BandDefinition   = &BandDefs[0];
582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
5832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
5842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
5852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i];
5862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].QFactor   = EQNB_5BandPresetsQFactors[i];
587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        BandDefs[i].Gain      = EQNB_5BandSoftPresets[i];
5882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume Control parameters */
5912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_EffectLevel         = 0;
5922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_Balance             = 0;
5932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Treble Enhancement parameters */
5952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
5962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_EffectLevel         = 0;
5972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
5992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = (LVM_PSA_DecaySpeed_en)0;
6012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
6032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_OperatingMode       = LVM_BE_OFF;
6042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_EffectLevel         = 0;
6052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_CentreFreq          = LVM_BE_CENTRE_90Hz;
6062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_HPF                 = LVM_BE_HPF_ON;
6072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = LVM_PSA_SPEED_MEDIUM;
6112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
612d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    /* TE Control parameters */
613d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
614d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_EffectLevel         = 0;
615d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance,
6182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &params);
6192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init")
6212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n");
6242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the headroom parameters */
6262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_Low          = 20;
6272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_High         = 4999;
6282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Headroom_Offset    = 3;
6292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_Low          = 5000;
6302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_High         = 24000;
6312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Headroom_Offset    = 4;
6322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.pHeadroomDefinition    = &HeadroomBandDef[0];
6332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
6342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.NHeadroomBands         = 2;
6352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance,
6372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &HeadroomParams);
6382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init")
6402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n");
6432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init End");
6442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
6452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end LvmBundle_init */
6462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_process()
6492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
6512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply LVM Bundle effects
6522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
6542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pIn:        pointer to stereo 16 bit input data
6552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to stereo 16 bit output data
6562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  frameCount: Frames to process
6572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
6582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
6592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Outputs:
6612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to updated stereo 16 bit output data
6622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_process(LVM_INT16        *pIn,
666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      LVM_INT16        *pOut,
667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      int              frameCount,
668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      EffectContext    *pContext){
6692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
6712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
6722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               *pOutTmp;
674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){
675163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = pOut;
676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
677163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2);
678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(pOutTmp == NULL){
679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process failed to allocate memory for "
680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            "EFFECT_BUFFER_ACCESS_ACCUMULATE mode");
681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
682163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
683163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("LVM_ERROR : LvmBundle_process invalid access mode");
685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
686163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
6872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
688163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
689163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
6902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
6912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmBundle_process")
6932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
695163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->frameCount++;
696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->frameCount == 100)
697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tBB: %d VIRT: %d EQ: %d, session (%d), context is %p\n",
699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //ActiveParams.BE_OperatingMode,
700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //ActiveParams.VirtualizerOperatingMode, ActiveParams.EQNB_OperatingMode,
701163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->SessionNo, pContext->pBundledContext);
702163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->frameCount = 0;
703163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
704163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
705163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
706163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pIn, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmInPtr);
707163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmInPtr);
708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
709163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
710d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("Calling LVM_Process");
711d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
712163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Process the samples */
7132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */
7142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pIn,                                  /* Input buffer */
7152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pOutTmp,                              /* Output buffer */
7162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            (LVM_UINT16)frameCount,               /* Number of samples to read */
7172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            0);                                   /* Audo Time */
718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process")
7202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
7212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
722163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pOutTmp, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmOutPtr);
724163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmOutPtr);
725163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
726163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
727163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
728163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        for (int i=0; i<frameCount*2; i++){
729163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            pOut[i] +=  pOutTmp[i];
730163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        free(pOutTmp);
732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmBundle_process */
7352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_enable()
7382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Enable the effect in the bundle
7402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_enable(EffectContext *pContext){
749163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable start");
750163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
7532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
754163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
755163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable")
7592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
760163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n");
7612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
763163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST");
7642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_ON;
7652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
767163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER");
7682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_ON;
7692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
771163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER");
7722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_ON;
7732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
775163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VOLUME");
776163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
777163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
7792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable")
7802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
781163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
782163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n");
783163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable end");
7842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
7862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_disable()
7892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Disable the effect in the bundle
7912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_disable(EffectContext *pContext){
800163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable start");
801163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
8032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
804163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
805163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
8062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
8072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable")
8092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
810163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n");
8112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
813163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST");
8142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_OFF;
8152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
817163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_VIRTUALIZER");
8182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_OFF;
8192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
821163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_EQUALIZER");
8222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_OFF;
8232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
825163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_VOLUME");
826163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
827163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable")
8302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
831163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
832163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n");
833163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable end");
8342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_free()
8392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Free all memory associated with the Bundle.
8412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free(EffectContext *pContext){
8502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;         /* Function call status */
8512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                        /* Control Parameters */
8522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;
8532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Free the algorithm memory */
8552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance,
8562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   &MemTab,
8572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   LVM_NULL);
8582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free")
8602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
8622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
8632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress != NULL){
864163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - START freeing %ld bytes for region %u at %p\n",
8652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
8682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
869163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - END   freeing %ld bytes for region %u at %p\n",
8702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
872163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR : LvmEffect_free - trying to free with NULL pointer %ld bytes "
8732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "for region %u at %p ERROR\n",
8742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
8762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
8772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmEffect_free */
8792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Effect_configure()
8822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Set input and output audio configuration.
8842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
8882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//      configuration parameters
8892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Effect_configure(EffectContext *pContext, effect_config_t *pConfig){
895163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_Fs_en   SampleRate;
896163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure start");
8972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
8992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig != NULL);
9002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
9022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels);
9032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
9042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == CHANNEL_STEREO);
9052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
9062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
9072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15);
9082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    memcpy(&pContext->config, pConfig, sizeof(effect_config_t));
9102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    switch (pConfig->inputCfg.samplingRate) {
912163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 8000:
913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_8000;
914c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 8000*2; // 2 secs Stereo
915163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
916163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 16000:
917163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_16000;
918c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 16000*2; // 2 secs Stereo
919163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
920163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 22050:
921163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_22050;
922c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 22050*2; // 2 secs Stereo
923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
924163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 32000:
925163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_32000;
926c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 32000*2; // 2 secs Stereo
927163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
928163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 44100:
929163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_44100;
930c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 44100*2; // 2 secs Stereo
931163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
932163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 48000:
933163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_48000;
934c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 48000*2; // 2 secs Stereo
935163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
936163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    default:
937163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_Configure invalid sampling rate %d", pConfig->inputCfg.samplingRate);
938163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
939163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
941163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->SampleRate != SampleRate){
9422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
943163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ControlParams_t     ActiveParams;
944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;
9452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
946163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure change sampling rate to %d", SampleRate);
9472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
9512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
952163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_configure")
953163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
955163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
957163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_configure")
958163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure Succesfully called LVM_SetControlParameters\n");
959c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SampleRate = SampleRate;
9602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
961163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
962163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_configure keep sampling rate at %d", SampleRate);
963163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
965163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure End....");
966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
967163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}   /* end Effect_configure */
9682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassGetStrength()
9712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
9732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
9742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
9752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the
9762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
9772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t BassGetStrength(EffectContext *pContext){
984163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved);
9852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
9872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
988163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
989163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
9902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
9912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength")
9932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
995163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n");
9962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Check that the strength returned matches the strength that was set earlier */
998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(ActiveParams.BE_EffectLevel !=
999163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){
10002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n",
10012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved);
10022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
10032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
10042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1005163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
1006163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (saved)  -> %d\n", pContext->pBundledContext->BassStrengthSaved );
10072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return pContext->pBundledContext->BassStrengthSaved;
10082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassGetStrength */
10092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassSetStrength()
10122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15
10152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid BassSetStrength(EffectContext *pContext, uint32_t strength){
1023163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength(%d)", strength);
10242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->BassStrengthSaved = (int)strength;
10262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength")
1035163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n");
10362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
10382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_EffectLevel    = (LVM_INT16)((15*strength)/1000);
10392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_CentreFreq     = LVM_BE_CENTRE_90Hz;
10402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1041163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength")
1047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n");
10482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassSetStrength */
10492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerGetStrength()
10522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
10552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
1056163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the
10572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
10582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t VirtualizerGetStrength(EffectContext *pContext){
1065163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved);
10662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
10682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
10692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength")
10732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
10742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1075163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n");
1076163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength() (0-100)   -> %d\n", ActiveParams.VirtualizerReverbLevel*10);
1077d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    return pContext->pBundledContext->VirtStrengthSaved;
10782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getStrength */
10792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerSetStrength()
10822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15
10852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
1093163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength(%d)", strength);
10942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1097163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->VirtStrengthSaved = (int)strength;
1098163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
10992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
11012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength")
1103163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n");
11042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Virtualizer parameters */
1106d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    ActiveParams.CS_EffectLevel             = (int)((strength*32767)/1000);
11072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1108163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength() (0-1000)   -> %d\n", strength );
1109d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVirtualizerSetStrength() (0- 100)   -> %d\n", ActiveParams.CS_EffectLevel );
11102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength")
1114d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n\n");
11152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setStrength */
11162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandLevel()
11192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the gain currently being used for the band passed in
11212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
11302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1131163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Gain =0;
1132163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1133163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1134163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1135163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1136163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1137163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
11382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1139163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel")
11402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1141163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1142163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Gain    = (int32_t)BandDef[band].Gain*100;    // Convert to millibels
11432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1144163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel -> %d\n", Gain );
1145163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1146163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Gain;
11472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetBandLevel()
11512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Sets gain value for the given band.
11542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Gain:       Gain to be applied in millibels
11582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//---------------------------------------------------------------------------
1163d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurentvoid EqualizerSetBandLevel(EffectContext *pContext, int band, short Gain){
1164163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int gainRounded;
1165163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(Gain > 0){
1166163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain+50)/100);
1167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1168163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain-50)/100);
1169163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1170163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);
1171163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1172163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
11732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1175163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
11762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1179163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetBandLevel")
1180163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1181d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tEqualizerSetBandLevel just Got -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain);
11822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set local EQ parameters */
1184163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1185163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    ActiveParams.pEQNB_BandDefinition[band].Gain = gainRounded;
11862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1189163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetBandLevel")
1190d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tEqualizerSetBandLevel just Set -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain);
11912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
11932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
11942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetCentreFrequency()
11972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the frequency being used for the band passed in
11992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
12022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
12032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){
1208163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Frequency =0;
12092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1210163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1211163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1212163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1213163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1214163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1215163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
12162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1217163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency")
12182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1219163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef   = ActiveParams.pEQNB_BandDefinition;
1220163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Frequency = (int32_t)BandDef[band].Frequency*1000;     // Convert to millibels
12212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1222163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency );
1223163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n");
1224163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Frequency;
12252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandFreqRange(
12292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets lower and upper boundaries of a band.
12332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the high shelf, the low bound is the band frequency and the high
12342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// bound is Nyquist.
12352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the peaking filters, they are the gain[dB]/2 points.
12362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
12392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
12402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
12432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
12442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1245163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow,
1246163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                  uint32_t *pHi){
1247163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pLow = bandFreqRange[band][0];
1248163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pHi  = bandFreqRange[band][1];
1249163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
12502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBand(
12542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Returns the band with the maximum influence on a given frequency.
12582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Result is unaffected by whether EQ is enabled or not, or by whether
12592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// changes have been committed or not.
12602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  targetFreq   The target frequency, in millihertz.
12632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
12672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
12682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){
12702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int band = 0;
12712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1272163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(targetFreq < bandFreqRange[0][0]){
1273163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
1274163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if(targetFreq == bandFreqRange[0][0]){
1275163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
1276163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1277163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for(int i=0; i<FIVEBAND_NUMBANDS;i++){
1278163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){
1279163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            band = i;
1280163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
12822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return band;
12832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPreset(
12872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets the currently set preset ID.
12912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Will return PRESET_CUSTOM in case the EQ parameters have been modified
12922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// manually since a preset was set.
12932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetPreset(EffectContext *pContext){
1299163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return pContext->pBundledContext->CurPreset;
13002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetPreset(
13042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Sets the current preset by ID.
13082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// All the band parameters will be overridden.
13092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
13122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  preset       The preset ID.
13132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetPreset(EffectContext *pContext, int preset){
13162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1317163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset(%d)", preset);
13182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = preset;
13192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetPreset")
1326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully returned from LVM_GetControlParameters\n");
13272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    //ActiveParams.pEQNB_BandDefinition = &BandDefs[0];
13292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
13302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
1331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
1332163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
1333163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Gain
1334163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        = EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
13352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
13362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the new settings */
13372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetPreset")
13392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1340163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
13412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
13422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
1343163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
13442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetNumPresets(){
1345163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return sizeof(gEqualizerPresets) / sizeof(PresetConfig);
13462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPresetName(
13502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets a human-readable name for a preset ID. Will return "Custom" if
13532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// PRESET_CUSTOM is passed.
13542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// preset       The preset ID. Must be less than number of presets.
13572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//-------------------------------------------------------------------------
13592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst char * EqualizerGetPresetName(int32_t preset){
1360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName start(%d)", preset);
13612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (preset == PRESET_CUSTOM) {
13622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return "Custom";
13632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
13642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return gEqualizerPresets[preset].name;
13652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1366163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName end(%d)", preset);
1367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
13682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetVolumeLevel()
13722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  level       level to be applied
13782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
13822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1386163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Level to be set is %d %d\n", level, (LVM_INT16)(level/100));
13872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
13902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1391163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully returned from LVM_GetControlParameters got: %d\n",
1392163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //ActiveParams.VC_EffectLevel);
13932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume parameters */
13952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.VC_EffectLevel  = (LVM_INT16)(level/100);
1396163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel() (-96dB -> 0dB)   -> %d\n", ActiveParams.VC_EffectLevel );
13972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
13992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetVolumeLevel")
14012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1403163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully called LVM_SetControlParameters\n");
1404163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1405163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1406163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1407163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
1408163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1410d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetVolumeLevel just set (-96dB -> 0dB)   -> %d\n",ActiveParams.VC_EffectLevel );
1411d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    if(pContext->pBundledContext->firstVolume == LVM_TRUE){
1412d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams);
1413d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process")
1414d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks");
1415d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        pContext->pBundledContext->firstVolume = LVM_FALSE;
1416d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    }
14172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setVolumeLevel */
14192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeGetVolumeLevel()
14222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){
14312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1432163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel start");
1433163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
14342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
14352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
14362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetVolumeLevel")
14392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1441163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel );
1442163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel Succesfully returned from LVM_GetControlParameters\n");
14432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *level = ActiveParams.VC_EffectLevel*100;     // Convert dB to millibels
1445163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel end");
14462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end VolumeGetVolumeLevel */
14482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetMute()
14512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
14572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){
1461163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute start(%d)", mute);
14622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->bMuteEnabled = mute;
14642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
14662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
14672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
14692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetMute")
14712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully returned from LVM_GetControlParameters\n");
1474163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute to %d, level was %d\n", mute, ActiveParams.VC_EffectLevel );
14752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set appropriate volume level */
14772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){
1478163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved = ActiveParams.VC_EffectLevel;
1479163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel           = -96;
14802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1481163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel  = pContext->pBundledContext->levelSaved;
14822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
14832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
14852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetMute")
14872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1489163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully called LVM_SetControlParameters\n");
1490163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute end");
14912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setMute */
14932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1495163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetMute()
14962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Ourputs:
15032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
15042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){
1507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute start");
1508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||
1509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){
1510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        *mute = pContext->pBundledContext->bMuteEnabled;
1511163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
15122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d",
1514163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent              pContext->pBundledContext->bMuteEnabled);
1515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
15162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute end");
15182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getMute */
15192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1520163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint16_t VolumeConvertStereoPosition(int16_t position){
1521163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t convertedPosition = 0;
1522163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1523163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    convertedPosition = (int16_t)(((float)position/1000)*96);
1524163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return convertedPosition;
1525163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1526163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
1527163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1528163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1529163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeSetStereoPosition()
1530163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1531163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1532163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1533163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1534163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1535163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1536163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1537163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1540163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint VolumeSetStereoPosition(EffectContext *pContext, int16_t position){
1541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1542163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1543163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1544163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               Balance = 0;
1545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1546c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1547163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1548163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->positionSaved = position;
1549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1550163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1551d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1552d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1553163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1554163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance);
1557163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved = position;
1558163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1559163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1560163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1561163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1562163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:"
1563163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     " %d\n", ActiveParams.VC_Balance);
1564163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Volume parameters */
1566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  = Balance;
1567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB)   -> %d\n", ActiveParams.VC_Balance );
1568163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Activate the initial settings */
1570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
1572163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1573163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n");
15752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1576163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1578163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1580163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: "
1581163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     "%d\n", ActiveParams.VC_Balance);
1582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    else{
1584163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n",
1585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //position, Balance);
1586163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1587d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n",
1588d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeSetStereoPosition */
15912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetStereoPosition()
1595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1596163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1598163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1602163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
16042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){
1606163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition start");
16072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1609163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               balance;
1611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1612d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1613d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1614163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1615163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
1617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance);
1620163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1622163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1624163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(balance != ActiveParams.VC_Balance){
1626163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
1627163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *position = (LVM_INT16)pContext->pBundledContext->positionSaved;     // Convert dB to millibels
1630d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved =%d\n",
1631d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeGetStereoPosition */
16342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeEnableStereoPosition()
1637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1640163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:   effect engine context
1642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  mute:       enable/disable flag
1643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1644163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
16452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){
1647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition start()");
16482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->bStereoPositionEnabled = enabled;
16502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1652163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
16532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1654163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1655163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition")
1657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition to %d, position was %d\n",
1661163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //     enabled, ActiveParams.VC_Balance );
16622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1663163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Set appropriate stereo position */
1664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){
1665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance = 0;
1666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  =
1668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                            VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1669163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
16702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
1672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition")
1674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n");
1677163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition end()\n");
1678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeEnableStereoPosition */
16802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_getParameter()
16832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
16852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a BassBoost parameter
16862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
16892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
16902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
16912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
16922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
16942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
16952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
16962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
16992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_getParameter(EffectContext     *pContext,
1703c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
1704163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           size_t            *pValueSize,
1705163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           void              *pValue){
17062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1707c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1708c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
17092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
17102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
17112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1712163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter start");
17132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
171523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17167fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
1717d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize1 %d", *pValueSize);
17187fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
17197fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
17207fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
17217fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
17222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
1724d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize2 %d", *pValueSize);
17252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
17262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
17272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
17282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
17332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
173623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
17382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
173923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d",
1740163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
17412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = BassGetStrength(pContext);
17452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1746163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d",
1747163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
17482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
17532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter end");
17572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_getParameter */
17592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_setParameter()
17622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a BassBoost parameter
17652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
17682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
17702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1775c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue){
17762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
17772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1778c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
17792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1780163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter start");
17812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1782c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (*pParamTemp){
17832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1785163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength);
1786163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength");
17872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            BassSetStrength(pContext, (int32_t)strength);
1788163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength");
17892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
17902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1791c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParamTemp);
17922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1795163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter end");
17962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_setParameter */
17982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_getParameter()
18012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Virtualizer parameter
18042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
18072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
18092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
18102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
18132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
18142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
18172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_getParameter(EffectContext        *pContext,
1821c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void                 *pParam,
18222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             size_t               *pValueSize,
18232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             void                 *pValue){
18242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1825c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1826c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
18272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
18282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
18292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1830163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter start");
18312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
183323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18347fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
18357fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
18367fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
18377fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
18387fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
18397fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
18402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
1842d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize2 %d",*pValueSize);
18432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
18442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
18452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
18462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
18502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
18512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
185423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
18562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
185723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d",
1858163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
18592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = VirtualizerGetStrength(pContext);
18632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1864163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d",
1865163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
18662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
18702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
18712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1874163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter end");
18752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_getParameter */
18772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_setParameter()
18802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Virtualizer parameter
18832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
18862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
18882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1893c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
18942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
18952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1896c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1897c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
18982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1899163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter start");
19002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1901c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
19022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
19032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1904163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength);
1905163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength");
19062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            VirtualizerSetStrength(pContext, (int32_t)strength);
1907163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength");
19082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
19092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1910c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", param);
19112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1914163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter end");
19152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_setParameter */
19172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_getParameter()
19202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Equalizer parameter
19232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer       - handle to instance data
19262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
19282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
19292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
19322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
19332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
19362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_getParameter(EffectContext     *pContext,
1939c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
19402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           size_t            *pValueSize,
19412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           void              *pValue){
19422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
19432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
1944c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1945c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
19462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
19472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
19482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_getParameter start");
19502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
19522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
19532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
19542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
19553be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_BAND_LEVEL:
19563be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_GET_BAND:
19572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int16_t)) {
1958163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
19592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int16_t);
19622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
19653be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (*pValueSize < 2 * sizeof(int16_t)) {
19663be9523784cc4038f601e510faee595117cdacb3Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
19673be9523784cc4038f601e510faee595117cdacb3Eric Laurent            return -EINVAL;
19683be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
19693be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *pValueSize = 2 * sizeof(int16_t);
19703be9523784cc4038f601e510faee595117cdacb3Eric Laurent        break;
19712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
19722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < 2 * sizeof(int32_t)) {
1973d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 3  %d", *pValueSize);
19742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = 2 * sizeof(int32_t);
19772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19783be9523784cc4038f601e510faee595117cdacb3Eric Laurent
19792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
19802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int32_t)) {
1981d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 5  %d", *pValueSize);
19822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int32_t);
19852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
19882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
199023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES:
199123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) {
199223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
199323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            return -EINVAL;
199423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
199523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t);
199623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        break;
199723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
19982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
1999163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param);
20002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
20012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
20042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
20053be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS;
2006163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue);
20072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
20103be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = -1500;
20113be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *((int16_t *)pValue + 1) = 1500;
2012163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d",
2013d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      *(int16_t *)pValue, *((int16_t *)pValue + 1));
20142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2017c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20223be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2);
2023163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d",
2024163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
2028c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2);
2034163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d",
2035163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
2039c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1));
2045163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d",
2046163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue, *((int32_t *)pValue + 1));
20472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_BAND:
2050c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20513be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2);
2052163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d",
2053d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      param2, *(uint16_t *)pValue);
20542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
20573be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext);
2058163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue);
20592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
20623be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets();
2063163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue);
20642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
2067c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= EqualizerGetNumPresets()) {
20692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        //if (param2 >= 20) {     // AGO FIX
20702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name = (char *)pValue;
20742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1);
20752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name[*pValueSize - 1] = 0;
20762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = strlen(name) + 1;
2077163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d",
2078163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, gEqualizerPresets[param2].name, *pValueSize);
20792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
208123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES: {
20823be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
208323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        LOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES");
20843be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[0] = (int16_t)EqualizerGetPreset(pContext);
20853be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[1] = (int16_t)FIVEBAND_NUMBANDS;
208623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
20873be9523784cc4038f601e510faee595117cdacb3Eric Laurent            p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i);
208823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
208923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    } break;
209023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
20912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
20922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param);
20932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        status = -EINVAL;
20942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2097d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //GV("\tEqualizer_getParameter end\n");
20982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
20992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_getParameter */
21002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_setParameter()
21032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Equalizer parameter
21062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer    - handle to instance data
21092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
21102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
21112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
2115c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
21162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t preset;
21182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t band;
21192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t level;
2120c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2121c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
2122c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
21232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2124163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter start");
21252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
21262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
21273be9523784cc4038f601e510faee595117cdacb3Eric Laurent        preset = (int32_t)(*(uint16_t *)pValue);
21282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2129163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset);
21302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if ((preset >= EqualizerGetNumPresets())||(preset < 0)) {
21312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetPreset(pContext, preset);
21352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2137c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        band =  *pParamTemp;
21383be9523784cc4038f601e510faee595117cdacb3Eric Laurent        level = (int32_t)(*(int16_t *)pValue);
2139163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level);
21402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (band >= FIVEBAND_NUMBANDS) {
21412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetBandLevel(pContext, band, level);
21452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21463be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_PROPERTIES: {
21473be9523784cc4038f601e510faee595117cdacb3Eric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES");
21483be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
21493be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if ((int)p[0] >= EqualizerGetNumPresets()) {
21503be9523784cc4038f601e510faee595117cdacb3Eric Laurent            status = -EINVAL;
21513be9523784cc4038f601e510faee595117cdacb3Eric Laurent            break;
21523be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
21533be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (p[0] >= 0) {
21543be9523784cc4038f601e510faee595117cdacb3Eric Laurent            EqualizerSetPreset(pContext, (int)p[0]);
21553be9523784cc4038f601e510faee595117cdacb3Eric Laurent        } else {
21563be9523784cc4038f601e510faee595117cdacb3Eric Laurent            if ((int)p[1] != FIVEBAND_NUMBANDS) {
21573be9523784cc4038f601e510faee595117cdacb3Eric Laurent                status = -EINVAL;
21583be9523784cc4038f601e510faee595117cdacb3Eric Laurent                break;
21593be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
21603be9523784cc4038f601e510faee595117cdacb3Eric Laurent            for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
21613be9523784cc4038f601e510faee595117cdacb3Eric Laurent                EqualizerSetBandLevel(pContext, i, (int)p[2 + i]);
21623be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
21633be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
21643be9523784cc4038f601e510faee595117cdacb3Eric Laurent    } break;
21652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
2166d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LOGV("\tLVM_ERROR : Equalizer_setParameter() invalid param %d", param);
21673be9523784cc4038f601e510faee595117cdacb3Eric Laurent        status = -EINVAL;
21682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2171163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter end");
21722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_setParameter */
21742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_getParameter()
21772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Volume parameter
21802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume          - handle to instance data
21832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
21842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
21852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
21862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
21892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
21902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
21932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_getParameter(EffectContext     *pContext,
2197c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void              *pParam,
21982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        size_t            *pValueSize,
21992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        void              *pValue){
22002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
22012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2202c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2203c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;;
22042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
22052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2206d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolume_getParameter start");
22072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2212163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if (*pValueSize != sizeof(int16_t)){
22132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1  %d", *pValueSize);
22142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
22172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
22202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
22212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize < sizeof(int32_t)){
22222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2  %d", *pValueSize);
22232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int32_t);
22262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2229163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param);
22302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue));
2236d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d",
2237d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = 0;
2242d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d",
2243d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2247163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            VolumeGetStereoPosition(pContext, (int16_t *)pValue);
2248d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d",
2249d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeGetMute(pContext, (uint32_t *)pValue);
2254163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d",
2255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(uint32_t *)pValue);
22562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2259163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled;
2260d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d",
2261d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(uint32_t *)pValue);
22622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
22652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param);
22662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
22672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2270163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_getParameter end");
22712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
22722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_getParameter */
22732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_setParameter()
22772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
22792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Volume parameter
22802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
22822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume       - handle to instance data
22832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
22842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
22852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
22872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2290c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue){
22912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int      status = 0;
22922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t  level;
2293163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t  position;
22942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    uint32_t mute;
2295163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    uint32_t positionEnabled;
2296c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2297c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
22982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2299d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolume_setParameter start");
23002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2301c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
23022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
23032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            level = *(int16_t *)pValue;
2304d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level);
2305d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel");
23062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeSetVolumeLevel(pContext, (int16_t)level);
2307d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel");
23082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2311163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            mute = *(uint32_t *)pValue;
2312d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute);
2313d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setMute");
2314163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetMute(pContext, mute);
2315d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->setMute");
2316163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2319163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            positionEnabled = *(uint32_t *)pValue;
2320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeEnableStereoPosition(pContext, positionEnabled);
2321163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved);
2322d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called");
2323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            position = *(int16_t *)pValue;
2327d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position);
2328d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition");
2329163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, (int16_t)position);
2330d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition");
2331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2334c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", param);
23352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_setParameter end");
23392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_setParameter */
23412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2342163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent/****************************************************************************************
2343163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent * Name : LVC_ToDB_s32Tos16()
2344163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Input       : Signed 32-bit integer
2345163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Output      : Signed 16-bit integer
2346163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  MSB (16) = sign bit
2347163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (15->05) = integer part
2348163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (04->01) = decimal part
2349163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Returns     : Db value with respect to full scale
2350163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Description :
2351163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Remarks     :
2352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent ****************************************************************************************/
2353163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2354163fbcf84010b98e0374110454d85b804bc8d13bEric LaurentLVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix)
2355163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent{
2356163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   db_fix;
2357163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   Shift;
2358163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   SmallRemainder;
2359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_UINT32  Remainder = (LVM_UINT32)Lin_fix;
2360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2361163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Count leading bits, 1 cycle in assembly*/
2362163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for (Shift = 0; Shift<32; Shift++)
2363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
2364163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if ((Remainder & 0x80000000U)!=0)
2365163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2366163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2368163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        Remainder = Remainder << 1;
2369163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
23702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2371163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /*
2372163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * Based on the approximation equation (for Q11.4 format):
2373163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     *
2374163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2)
2375163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     */
2376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix    = (LVM_INT16)(-96 * Shift);               /* Six dB steps in Q11.4 format*/
2377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24);
2378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix + SmallRemainder );
2379163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder);
2380163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9));
23812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2382163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Correct for small offset */
2383163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - 5);
23842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2385163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return db_fix;
2386163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
23872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2388163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
2389163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
23902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Process */
23922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_process(effect_interface_t     self,
2393163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *inBuffer,
2394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *outBuffer){
23952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
2396c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
2397c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
23982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int    status = 0;
2399c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int    status2Sec = 0;
2400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int    lvmStatus = 0;
2401163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *in  = (LVM_INT16 *)inBuffer->raw;
2402163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *out = (LVM_INT16 *)outBuffer->raw;
24032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2404d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent//LOGV("\tEffect_process Start : Enabled = %d     Called = %d",
2405d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent//pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled);
2406c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LOGV("\tEffect_process Start : Samples left %d %d %d",
2407c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountBb,
2408c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountVirt,
2409c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountEq);
2410c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2411c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
2412c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
2413c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
2414c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LOGV("\tEffect_process Internal Operating Modes: BB %d   VIRT %d    EQ %d",
2415c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//        ActiveParams.BE_OperatingMode, ActiveParams.VirtualizerOperatingMode,
2416c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//        ActiveParams.EQNB_OperatingMode);
24172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
24192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL");
24202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
24212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
24222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
24232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
24242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            inBuffer->frameCount != outBuffer->frameCount){
24252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
24262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
24272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2428163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&
2429163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_BASS_BOOST)){
2430c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_BASS_BOOST Effect is not enabled");
2431c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
2432c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2433c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO
2434c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //LOGV("\tEffect_process: Waiting for 2 secs to turn off BASS_BOOST, %d samples left",
2435c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountBb);
2436c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2437163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2438c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
2439163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2440163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&
2441163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VOLUME)){
2442c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_VOLUME Effect is not enabled");
2443163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2444163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2445163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&
2446163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_EQUALIZER)){
2447c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_EQUALIZER Effect is not enabled");
2448c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
2449c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2450c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq -= outBuffer->frameCount * 2; // STEREO
2451c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //LOGV("\tEffect_process: Waiting for 2 secs to turn off EQUALIZER, %d samples left",
2452c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountEq);
2453c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2454c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2455c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
24562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2457163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&
2458163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VIRTUALIZER)){
2459c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_VIRTUALIZER Effect is not enabled");
2460c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
2461c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2462c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt -= outBuffer->frameCount * 2;// STEREO
2463c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //LOGV("\tEffect_process: Waiting for 2 secs to turn off VIRTUALIZER, %d samples left",
2464c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountVirt);
2465c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2466c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2467c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
24682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2469163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2470163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // If this is the last frame of an effect process its output with no effect
2471163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(status == -ENODATA){
2472163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
2473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() accumulating last frame into output buffer");
2474163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() trying copying last frame into output buffer");
2475163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Enabled = %d     Called = %d",
2476163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->NumberEffectsEnabled,
2477163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->NumberEffectsCalled);
2478163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2479163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }else{
2480163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() copying last frame into output buffer");
2481163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
24822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2483163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2484c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if((status2Sec != -ENODATA)&&(status != -ENODATA)){
2485163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled++;
24862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
24872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2488163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->NumberEffectsCalled ==
2489163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       pContext->pBundledContext->NumberEffectsEnabled){
2490163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Calling process with %d effects enabled, %d called: Effect %d",
2491163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2492163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
24932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2494163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(status == -ENODATA){
2495163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() actually processing last frame");
2496163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
24972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext->NumberEffectsCalled = 0;
2498163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Process all the available frames, block processing is
2499163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           handled internalLY by the LVM bundle */
2500163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        lvmStatus = android::LvmBundle_process(    (LVM_INT16 *)inBuffer->raw,
25012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                (LVM_INT16 *)outBuffer->raw,
25022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                outBuffer->frameCount,
25032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                pContext);
2504163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(lvmStatus != LVM_SUCCESS){
2505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
2506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return lvmStatus;
2507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
25082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
2509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
2510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2511163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
2512163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        // 2 is for stereo input
2513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
25142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
25172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end Effect_process */
25182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Command */
25202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_command(effect_interface_t  self,
252125f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdCode,
252225f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdSize,
2523163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pCmdData,
252425f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            *replySize,
2525163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pReplyData){
25262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
25272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int retsize;
25282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2529163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\t\nEffect_command start");
25302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST){
2532163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_BASS_BOOST");
25332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
25342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER){
2535163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VIRTUALIZER");
2536163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER){
2538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_EQUALIZER");
2539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME){
2541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VOLUME");
2542163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
25452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL");
25462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
25472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
25482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
25502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // Incase we disable an effect, next time process is
2552163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // called the number of effect called could be greater
2553163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // pContext->pBundledContext->NumberEffectsCalled = 0;
25542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d",
2556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsCalled,
2557163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsEnabled);
25582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (cmdCode){
25602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_INIT:
2561010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
2562010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                LOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d",
2563010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                        pContext->EffectType);
2564010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                return -EINVAL;
2565010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            }
2566010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            *(int *) pReplyData = 0;
2567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start");
25682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST");
25702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                android::BassSetStrength(pContext, 0);
25712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
25722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2573163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER");
2574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::VirtualizerSetStrength(pContext, 0);
2575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER");
2578163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::EqualizerSetPreset(pContext, 0);
2579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2581d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VOLUME");
2582010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0);
2583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_CONFIGURE:
2587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE start");
25882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pCmdData    == NULL||
25892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                cmdSize     != sizeof(effect_config_t)||
25902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                pReplyData  == NULL||
25912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize  != sizeof(int)){
25922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
25932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_CONFIGURE: ERROR");
25942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
25952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
25962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *) pReplyData = android::Effect_configure(pContext, (effect_config_t *) pCmdData);
2597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE end");
25982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_RESET:
2601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start");
26022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            android::Effect_configure(pContext, &pContext->config);
2603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end");
26042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
26052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_GET_PARAM:{
2607163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2613163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
26142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
26152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
26162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
26192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
26212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
26232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
26252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::BassBoost_getParameter(pContext,
2627c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
26282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            (size_t  *)&p->vsize,
26292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            p->data + voffset);
26302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
26322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM "
2634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
26382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
2639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2644163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
26452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
26462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
26472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
26502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
26522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
26542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
26562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Virtualizer_getParameter(pContext,
2658c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                             (void *)p->data,
26592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                             (size_t  *)&p->vsize,
26602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                              p->data + voffset);
26612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
26632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM "
2665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
26692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
26702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command cmdCode Case: "
2672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2675163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL ||
2676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) {
26772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
26782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM");
26792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
2682163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
2684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
2686163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
2688163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2689c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                p->status = android::Equalizer_getParameter(pContext,
2690c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
2691c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            &p->vsize,
2692c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data + voffset);
2693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
2695163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, "
2697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //       "*pReplyData %08x %08x",
2698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize,
2699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset),
2700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset +
2701163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        sizeof(int32_t)));
27022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2704d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tVolume_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2705163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2706163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2707163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
27092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
27102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
27112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
27142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
27162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
27182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
27202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Volume_getParameter(pContext,
2722c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                         (void *)p->data,
27232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         (size_t  *)&p->vsize,
27242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         p->data + voffset);
27252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
27272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2728163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_GET_PARAM "
2729163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2730163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
2733163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2734163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end");
27352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
27362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_PARAM:{
2737163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
27382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2739163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2740163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2741163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2742163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2743163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2744163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2745163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2746163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2747163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
27482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
27502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
27532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
27552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
27572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2760163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnBassBoost_command cmdSize is %d\n"
2761163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2762163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2763163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2764163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2765163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
27662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::BassBoost_setParameter(pContext,
2768c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
27692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    p->data + p->psize);
27702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2772d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //LOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2773d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2774d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *replySize,
2775d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2776163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2777163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2778163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2779163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2780163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
27812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
27822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
27832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
27862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
27882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
27892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
27902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2793163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnVirtualizer_command cmdSize is %d\n"
2794163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2795163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2796163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2797163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2798163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
27992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Virtualizer_setParameter(pContext,
2801c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                      (void *)p->data,
2802163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                       p->data + p->psize);
28032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2805d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //LOGV("\tEqualizer_command cmdCode Case: "
2806d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        "EFFECT_CMD_SET_PARAM start");
2807d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //LOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2808d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2809d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *replySize,
2810d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
28112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
28132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pReplyData == NULL || *replySize != sizeof(int32_t)) {
28142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
28152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
28162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
28192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Equalizer_setParameter(pContext,
2821c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
2822163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                     p->data + p->psize);
28232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2825d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tVolume_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
2826163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2827163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2828163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2829d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) +sizeof(int32_t)));
28302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (    pCmdData   == NULL||
28322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        cmdSize    < (int)(sizeof(effect_param_t) + sizeof(int32_t))||
28332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        pReplyData == NULL||
28342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        *replySize != sizeof(int32_t)){
28352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
28362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
28372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
28402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Volume_setParameter(pContext,
2842c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                 (void *)p->data,
2843163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                 p->data + p->psize);
2844163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2845163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end");
28462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
28472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_ENABLE:
2849c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start");
28502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
28512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
28522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
2853163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
28542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            switch (pContext->EffectType){
28552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_BASS_BOOST:
28562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
28572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
28582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bBassEnabled = LVM_TRUE;
2862d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                    //LOGV("\tEffect_command cmdCode Case:EFFECT_CMD_ENABLE LVM_BASS_BOOSTenabled");
28632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
28642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_EQUALIZER:
28652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE){
28662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
28672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE;
2871d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                    //LOGV("\tEffect_command cmdCode Case:EFFECT_CMD_ENABLE LVM_EQUALIZER enabled");
2872163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
28732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VIRTUALIZER:
28742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
28752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
28762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE;
2880d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                    //LOGV("\tEffect_command cmdCode :EFFECT_CMD_ENABLE LVM_VIRTUALIZER enabled");
2881163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
28822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VOLUME:
28832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){
28842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
28852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVolumeEnabled = LVM_TRUE;
2889d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                    LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_VOLUME enabled");
28902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
28912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                default:
28922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
28932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_ENABLE: ERROR, invalid Effect Type");
2894163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    return -EINVAL;
28952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *)pReplyData = 0;
28972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            pContext->pBundledContext->NumberEffectsEnabled++;
2898163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::LvmEffect_enable(pContext);
2899c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq =
2900c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*1); // 0.1 secs Stereo
2901c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb =
2902c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*6); // 2 secs Stereo
2903c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt =
2904c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*1); // 2 secs Stereo
2905c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE Samples to Exit = %d",
2906c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pContext->pBundledContext->SamplesToExitCountBb);
2907163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE NumberEffectsEnabled = %d",
2908163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        pContext->pBundledContext->NumberEffectsEnabled);
2909163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE end");
29102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
29122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_DISABLE:
2913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start");
29142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
29152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
29162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
2917163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            switch (pContext->EffectType){
29192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_BASS_BOOST:
29202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_FALSE){
29212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
29222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
2925163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pContext->pBundledContext->bBassEnabled      = LVM_FALSE;
2926163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2927163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //       "EFFECT_CMD_DISABLE LVM_BASS_BOOST disabled");
29282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
29292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_EQUALIZER:
29302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE){
29312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
29322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE;
2936163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2937163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //       "EFFECT_CMD_DISABLE LVM_EQUALIZER disabled");
2938163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
29392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VIRTUALIZER:
29402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE){
29412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE;
2946163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //     "EFFECT_CMD_DISABLE LVM_VIRTUALIZER disabled");
2948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
29492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VOLUME:
29502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVolumeEnabled == LVM_FALSE){
29512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
29522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVolumeEnabled = LVM_FALSE;
2956163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_VOLUME disabled");
29572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
29582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                default:
29592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
29602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_DISABLE: ERROR, invalid Effect Type");
2961163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    return -EINVAL;
2962163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *)pReplyData = 0;
29642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
2965163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::LvmEffect_disable(pContext);
2966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE NumberEffectsEnabled = %d",
2967163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        pContext->pBundledContext->NumberEffectsEnabled);
2968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE end");
29692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
29702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_DEVICE:
2972163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2973163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start");
2974163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            audio_device_e device = *(audio_device_e *)pCmdData;
2975163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2977163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
2978163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
2979163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d",
2980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
2981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST");
2982163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2983163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device doesnt support bassboost the effect must be temporarily disabled
2984163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
2985163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
2986163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2987163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
2988163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d",
2989163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
2990163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
2991163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_TRUE;
2992163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2993163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
2994163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d",
2995163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                         *(int32_t *)pCmdData);
2996163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2997163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports bassboost and the effect has been temporarily disabled
2998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
2999163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3000163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassTempDisabled == LVM_TRUE){
3001163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d",
3002163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3003163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3004163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_FALSE;
3005163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3006163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3007163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3008163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
3009163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
3010163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
3011163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d",
3012163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3013163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER");
3014163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3015163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //If a device doesnt support virtualizer the effect must be temporarily disabled
3016163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3017163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3018163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3019163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
3020163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d",
3021163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3022163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3023163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
3024163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3025163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
3026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d",
3027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3028163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3029163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports virtualizer and the effect has been temporarily disabled
3030163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3031163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerTempDisabled == LVM_TRUE){
3033163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d",
3034163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3035163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3036163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
3037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3038163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3039163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3040163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end");
30412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3042163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
3043163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_VOLUME:
3044163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
3045163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t vol     = *(int32_t *)pCmdData;
3046163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int16_t dB;
3047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t vol_ret[2] = {1<<24,1<<24}; // Apply no volume
3048163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3049163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // if pReplyData is NULL, VOL_CTRL is delegated to another effect
3050163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pReplyData == LVM_NULL){
3051163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                break;
3052163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
30532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3054163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(vol==0x1000000){
3055163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                vol -= 1;
3056163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3057163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // Convert volume linear (Q8.24) to volume dB (0->-96)
3058163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = android::LVC_ToDB_s32Tos16(vol <<7);
3059163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = (dB +8)>>4;
3060163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = (dB <-96) ? -96 : dB ;
3061163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3062d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            LOGV("\tEFFECT_CMD_SET_VOLUME Session: %d, SessionID: %d VOLUME is %d dB (%d), "
3063d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                  "effect is %d",
3064d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            pContext->pBundledContext->SessionNo, pContext->pBundledContext->SessionId,
3065d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            (int32_t)dB, vol<<7, pContext->EffectType);
3066d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
3067163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            memcpy(pReplyData, vol_ret, sizeof(int32_t)*2);
3068163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::VolumeSetVolumeLevel(pContext, (int16_t)(dB*100));
3069163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
3070163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent         }
3071163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
3072163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
30732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
30742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
30752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
30762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3077163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command end...\n\n");
30782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
30792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end Effect_command */
30802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for effect
30822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst struct effect_interface_s gLvmEffectInterface = {
30832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_process,
30842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_command
30852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};    /* end gLvmEffectInterface */
30862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3087