EffectBundle.cpp revision e0aed6ddcb4e3c301b80aa26706b6052dab42c41
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];
68e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
69c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint SessionIndex[LVM_MAX_SESSIONS];
702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW BassBoost UUID
722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gBassBoostDescriptor = {
732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
76163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
77163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
78d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BASS_BOOST_CUP_LOAD_ARM9E,
79d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Dynamic Bass Boost",
812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Virtualizer UUID
852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVirtualizerDescriptor = {
86163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
87163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
89163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
90163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
91d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VIRTUALIZER_CUP_LOAD_ARM9E,
92d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Virtualizer",
942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Equalizer UUID
982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gEqualizerDescriptor = {
992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
1002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP
1012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
102163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
103d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        EQUALIZER_CUP_LOAD_ARM9E,
104d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Equalizer",
1062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Volume UUID
1102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVolumeDescriptor = {
1112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
1122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP
1132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
114163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
115d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VOLUME_CUP_LOAD_ARM9E,
116d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Volume",
1182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//--- local function prototypes
1222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init      (void);
1232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmBundle_init            (EffectContext *pContext);
1242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_enable          (EffectContext *pContext);
1252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_disable         (EffectContext *pContext);
1262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free            (EffectContext *pContext);
127163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  Effect_configure          (EffectContext *pContext, effect_config_t *pConfig);
128c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  BassBoost_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
129163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  BassBoost_getParameter    (EffectContext *pContext,
130c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
1322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               void           *pValue);
133c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Virtualizer_setParameter  (EffectContext *pContext, void *pParam, void *pValue);
1342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Virtualizer_getParameter  (EffectContext *pContext,
135c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
137163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                               void           *pValue);
138c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Equalizer_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
1392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Equalizer_getParameter    (EffectContext *pContext,
140c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
143c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Volume_setParameter       (EffectContext *pContext, void *pParam, void *pValue);
1442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Volume_getParameter       (EffectContext *pContext,
145c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
1482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Library Interface Implementation */
1502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){
1512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryNumberEffects start");
1522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pNumEffects = 4;
153163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects);
154163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects end\n");
1552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryNumberEffects */
1572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor){
1592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryEffect start");
1602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect processing index %d", index);
161163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pDescriptor == NULL){
163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer");
1642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
1652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (index > 3){
167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index);
1682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -ENOENT;
1692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(index == LVM_BASS_BOOST){
1712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_BASS_BOOST");
1722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gBassBoostDescriptor,   sizeof(effect_descriptor_t));
1732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else if(index == LVM_VIRTUALIZER){
1742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VIRTUALIZER");
1752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVirtualizerDescriptor, sizeof(effect_descriptor_t));
1762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_EQUALIZER){
1772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_EQUALIZER");
1782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gEqualizerDescriptor,   sizeof(effect_descriptor_t));
1792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_VOLUME){
1802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VOLUME");
1812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVolumeDescriptor, sizeof(effect_descriptor_t));
182163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect end\n");
1842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryEffect */
1862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectCreate(effect_uuid_t       *uuid,
1882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             sessionId,
1892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             ioId,
1902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            effect_interface_t  *pInterface){
1912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int ret;
192c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int sessionNo;
1932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int i;
1942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext *pContext = new EffectContext;
1952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectCreate start session %d", sessionId);
1972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pInterface == NULL || uuid == NULL){
199163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer");
2002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
2012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmInitFlag == LVM_FALSE){
2042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmInitFlag = LVM_TRUE;
2052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Initializing all global memory");
2062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmGlobalBundle_init();
2072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
209c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LOGV("\tEffectCreate: There are %d LVM sessions acive\n", LvmSessionsActive);
210c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
211c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Find next available sessionNo
212c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for(i=0; i<LVM_MAX_SESSIONS; i++){
213e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        if((SessionIndex[i] == LVM_UNUSED_SESSION)||(SessionIndex[i] == sessionId)){
214c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            sessionNo       = i;
215c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            SessionIndex[i] = sessionId;
216c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffectCreate: Allocating SessionNo %d for SessionId %d\n", sessionNo,sessionId);
217c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
218c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
219c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
220c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
221c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(i==LVM_MAX_SESSIONS){
222c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tLVM_ERROR : Cannot find memory to allocate for current session");
223c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
224c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
2252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // If this is the first create in this session
226c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(GlobalSessionMemory[sessionNo].bBundledEffectsEnabled == LVM_FALSE){
227c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectCreate - This is the first effect in current sessionId %d sessionNo %d",
228c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionId, sessionNo);
229c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
230c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LvmSessionsActive++;
231c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
232c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(LvmSessionsActive >= LVM_MAX_SESSIONS){
233c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Number of active session is greater than LVM_MAX_SESSIONS (%d)",
234c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                  LVM_MAX_SESSIONS);
235c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            return -EINVAL;
236c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
237163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
238c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_TRUE;
239c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].pBundledContext        = new BundledEffectContext;
2402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
241c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = GlobalSessionMemory[sessionNo].pBundledContext;
242c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionNo                = sessionNo;
243c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionId                = sessionId;
244163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->hInstance                = NULL;
245163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVolumeEnabled           = LVM_FALSE;
246163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bEqualizerEnabled        = LVM_FALSE;
247163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassEnabled             = LVM_FALSE;
248163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassTempDisabled        = LVM_FALSE;
249163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerEnabled      = LVM_FALSE;
250163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsEnabled     = 0;
252163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled      = 0;
253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->frameCount               = 0;
254d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        pContext->pBundledContext->firstVolume              = LVM_TRUE;
255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2588f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        char fileName[256];
2598f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_in.pcm", pContext->pBundledContext);
2608f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmInPtr = fopen(fileName, "w");
2618f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr == NULL) {
2628f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            LOGV("cannot open %s", fileName);
2638f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent           return -EINVAL;
2648f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
265163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2668f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_out.pcm", pContext->pBundledContext);
2678f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmOutPtr = fopen(fileName, "w");
2688f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr == NULL) {
2698f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            LOGV("cannot open %s", fileName);
2708f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
2718f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent           pContext->pBundledContext->PcmInPtr = NULL;
272163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           return -EINVAL;
273163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
274163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
275163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        /* Saved strength is used to return the exact strength that was used in the set to the get
2772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * because we map the original strength range of 0:1000 to 1:15, and this will avoid
2782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * quantisation like effect when returning
2792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         */
280163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->BassStrengthSaved        = 0;
281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->VirtStrengthSaved        = 0;
282163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->CurPreset                = PRESET_CUSTOM;
283163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved               = 0;
284163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bMuteEnabled             = LVM_FALSE;
285163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bStereoPositionEnabled   = LVM_FALSE;
286163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved            = 0;
287163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Calling LvmBundle_init");
2892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ret = LvmBundle_init(pContext);
2902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (ret < 0){
2922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : EffectCreate() Bundle init failed");
2932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            delete pContext->pBundledContext;
2942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            delete pContext;
2952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return ret;
2962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
2972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
299c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectCreate - Assigning memory for previously created effect on sessionNo %d",
300c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionNo);
301c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext =
302c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                GlobalSessionMemory[sessionNo].pBundledContext;
3032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext);
3052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Create each Effect
3072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Bass Boost
3092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST");
310c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated = LVM_TRUE;
311163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
312163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_BASS_BOOST;
3142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Virtualizer
316163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER");
317c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated=LVM_TRUE;
318163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VIRTUALIZER;
3212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Equalizer
323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER");
324c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated = LVM_TRUE;
325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_EQUALIZER;
3282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Volume
330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VOLUME");
331c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated = LVM_TRUE;
332163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VOLUME;
335163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
337163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() invalid UUID");
338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
3392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pInterface = (effect_interface_t)pContext;
342163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectCreate end..\n\n");
3432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
3442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectCreate */
3452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectRelease(effect_interface_t interface){
3472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectRelease start %p", interface);
3482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *)interface;
3492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
350c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LOGV("\n\tEffectRelease start interface: %p, context %p", interface, pContext->pBundledContext);
3512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
3532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
354163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Clear the instantiated flag for the effect
3572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
3582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag");
359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated = LVM_FALSE;
3602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VIRTUALIZER) {
3612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag");
362163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated
363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            = LVM_FALSE;
3642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_EQUALIZER) {
3652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag");
366163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated =LVM_FALSE;
3672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VOLUME) {
3682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag");
369163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated = LVM_FALSE;
3702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
3712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n");
3722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
373163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext
3752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if((GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated == LVM_FALSE)&&
376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated == LVM_FALSE)&&
377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated ==LVM_FALSE)&&
378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated==LVM_FALSE))
3792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
380163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
3818f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr != NULL) {
3828f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
3838f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmInPtr = NULL;
3848f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
3858f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr != NULL) {
3868f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmOutPtr);
3878f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmOutPtr = NULL;
3888f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
389163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
390c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
391c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LvmSessionsActive--;
392c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectRelease: There are %d LVM sessions remaining\n", LvmSessionsActive);
393c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
394c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        // Clear the SessionIndex
395c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        for(int i=0; i<LVM_MAX_SESSIONS; i++){
396c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(SessionIndex[i] == pContext->pBundledContext->SessionId){
397e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                SessionIndex[i] = LVM_UNUSED_SESSION;
398c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                LOGV("\tEffectRelease: Clearing SessionIndex SessionNo %d for SessionId %d\n",
399c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        i, pContext->pBundledContext->SessionId);
400c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                break;
401c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
402c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
403c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
404163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: All effects are no longer instantiated\n");
405163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBundledEffectsEnabled =LVM_FALSE;
406163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].pBundledContext = LVM_NULL;
407163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: Freeing LVM Bundle memory\n");
408163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmEffect_free(pContext);
409c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectRelease: Deleting LVM Bundle context %p\n", pContext->pBundledContext);
410163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        delete pContext->pBundledContext;
411c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = LVM_NULL;
4122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // free the effect context for current effect
4142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    delete pContext;
4152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectRelease end\n");
4172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
4182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectRelease */
4202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init(){
4222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmGlobalBundle_init start");
4232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for(int i=0; i<LVM_MAX_SESSIONS; i++){
4242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBundledEffectsEnabled   = LVM_FALSE;
4252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVolumeInstantiated      = LVM_FALSE;
4262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bEqualizerInstantiated   = LVM_FALSE;
4272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBassInstantiated        = LVM_FALSE;
4282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE;
4292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].pBundledContext          = LVM_NULL;
430c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
431e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        SessionIndex[i] = LVM_UNUSED_SESSION;
4322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
4342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
4352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_init()
4372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Initialize engine with default configuration, creates instance
4392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// with all effects disabled.
4402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
4422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
4432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
4452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_init(EffectContext *pContext){
4492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status;
4502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init start");
4522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
453163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
454163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.channels                      = CHANNEL_STEREO;
455163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.format                        = SAMPLE_FORMAT_PCM_S15;
456163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
457163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
458163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
459163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
460163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
461163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
462163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.channels                     = CHANNEL_STEREO;
463163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.format                       = SAMPLE_FORMAT_PCM_S15;
464163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
465163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
466163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
467163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
468163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
4692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
4712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext->pBundledContext->hInstance != NULL){
4732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
4742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Calling pContext->pBassBoost->free()");
4752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmEffect_free(pContext);
4772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
4792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Called pContext->pBassBoost->free()");
4802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;          /* Function call status */
4832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                         /* Control Parameters */
4842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_InstParams_t        InstParams;                     /* Instance parameters */
4852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_EQNB_BandDef_t      BandDefs[MAX_NUM_BANDS];        /* Equaliser band definitions */
4862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomParams_t    HeadroomParams;                 /* Headroom parameters */
4872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomBandDef_t   HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS];
4882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;                         /* Memory allocation table */
4892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    bool                    bMallocFailure = LVM_FALSE;
4902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the capabilities */
492163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    InstParams.BufferMode       = LVM_UNMANAGED_BUFFERS;
4932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.MaxBlockSize     = MAX_CALL_SIZE;
4942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.EQNB_NumBands    = MAX_NUM_BANDS;
4952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.PSA_Included     = LVM_PSA_ON;
4962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory, forcing alignment */
4982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(LVM_NULL,
4992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &MemTab,
5002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &InstParams);
5012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init")
5032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
5062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory */
5082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
5102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
5112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
513d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
514d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u\n", MemTab.Region[i].Size, i );
5152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                bMallocFailure = LVM_TRUE;
5162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmBundle_init CreateInstance allocated %ld bytes for region %u at %p\n",
5182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
5242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     * succesfully allocated and return with an error
5252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     */
5262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(bMallocFailure == LVM_TRUE){
5272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
529d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
530d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u Not freeing\n", MemTab.Region[i].Size, i );
5312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
532163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %ld bytes "
533163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "for region %u at %p- free\n",
534163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
5362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
5392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
540163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n");
5412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Initialise */
543163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->hInstance = LVM_NULL;
5442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Init sets the instance handle */
546163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,
5472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &MemTab,
5482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &InstParams);
5492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init")
5512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
553163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
5542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the initial process parameters */
5562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* General parameters */
5572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.OperatingMode          = LVM_MODE_ON;
5582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SampleRate             = LVM_FS_44100;
5592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SourceFormat           = LVM_STEREO;
5602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SpeakerType            = LVM_HEADPHONES;
5612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
562163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->SampleRate = LVM_FS_44100;
563163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
5642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Concert Sound parameters */
5652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerOperatingMode   = LVM_MODE_OFF;
5662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerType            = LVM_CONCERTSOUND;
5672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerReverbLevel     = 100;
568d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.CS_EffectLevel             = LVM_CS_EFFECT_NONE;
5692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* N-Band Equaliser parameters */
5712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_OperatingMode     = LVM_EQNB_OFF;
5722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_NBands            = FIVEBAND_NUMBANDS;
5732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.pEQNB_BandDefinition   = &BandDefs[0];
574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
5752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
5762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
5772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i];
5782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].QFactor   = EQNB_5BandPresetsQFactors[i];
579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        BandDefs[i].Gain      = EQNB_5BandSoftPresets[i];
5802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume Control parameters */
5832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_EffectLevel         = 0;
5842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_Balance             = 0;
5852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Treble Enhancement parameters */
5872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
5882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_EffectLevel         = 0;
5892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
5912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
5922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = (LVM_PSA_DecaySpeed_en)0;
5932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
5952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_OperatingMode       = LVM_BE_OFF;
5962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_EffectLevel         = 0;
5972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_CentreFreq          = LVM_BE_CENTRE_90Hz;
5982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_HPF                 = LVM_BE_HPF_ON;
5992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = LVM_PSA_SPEED_MEDIUM;
6032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
604d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    /* TE Control parameters */
605d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
606d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_EffectLevel         = 0;
607d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
609163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance,
6102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &params);
6112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init")
6132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
615163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n");
6162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the headroom parameters */
6182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_Low          = 20;
6192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_High         = 4999;
6202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Headroom_Offset    = 3;
6212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_Low          = 5000;
6222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_High         = 24000;
6232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Headroom_Offset    = 4;
6242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.pHeadroomDefinition    = &HeadroomBandDef[0];
6252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
6262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.NHeadroomBands         = 2;
6272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance,
6292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &HeadroomParams);
6302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init")
6322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n");
6352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init End");
6362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
6372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end LvmBundle_init */
6382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_process()
6412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
6432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply LVM Bundle effects
6442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
6462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pIn:        pointer to stereo 16 bit input data
6472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to stereo 16 bit output data
6482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  frameCount: Frames to process
6492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
6502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
6512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Outputs:
6532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to updated stereo 16 bit output data
6542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_process(LVM_INT16        *pIn,
658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      LVM_INT16        *pOut,
659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      int              frameCount,
660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      EffectContext    *pContext){
6612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
6632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
6642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               *pOutTmp;
666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){
667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = pOut;
668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
669163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2);
670163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(pOutTmp == NULL){
671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process failed to allocate memory for "
672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            "EFFECT_BUFFER_ACCESS_ACCUMULATE mode");
673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
675163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("LVM_ERROR : LvmBundle_process invalid access mode");
677163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
6792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
6822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
6832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmBundle_process")
6852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
687163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->frameCount++;
688163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->frameCount == 100)
689163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
690163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tBB: %d VIRT: %d EQ: %d, session (%d), context is %p\n",
691163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //ActiveParams.BE_OperatingMode,
692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //ActiveParams.VirtualizerOperatingMode, ActiveParams.EQNB_OperatingMode,
693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->SessionNo, pContext->pBundledContext);
694163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->frameCount = 0;
695163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pIn, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmInPtr);
699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmInPtr);
700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
701163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
702d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("Calling LVM_Process");
703d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
704163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Process the samples */
7052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */
7062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pIn,                                  /* Input buffer */
7072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pOutTmp,                              /* Output buffer */
7082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            (LVM_UINT16)frameCount,               /* Number of samples to read */
7092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            0);                                   /* Audo Time */
710163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process")
7122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
7132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
714163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
715163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pOutTmp, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmOutPtr);
716163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmOutPtr);
717163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
719163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
720163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        for (int i=0; i<frameCount*2; i++){
721163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            pOut[i] +=  pOutTmp[i];
722163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        free(pOutTmp);
724163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmBundle_process */
7272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_enable()
7302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Enable the effect in the bundle
7322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_enable(EffectContext *pContext){
741163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable start");
742163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
7452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
746163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
747163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable")
7512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n");
7532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
755163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST");
7562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_ON;
7572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
759163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER");
7602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_ON;
7612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
763163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER");
7642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_ON;
7652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
767163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VOLUME");
768163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
769163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
7712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable")
7722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
773163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
774163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n");
775163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable end");
7762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
7782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_disable()
7812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Disable the effect in the bundle
7832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_disable(EffectContext *pContext){
792163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable start");
793163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
796163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
797163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable")
8012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
802163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n");
8032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
805163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST");
8062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_OFF;
8072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
809163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_VIRTUALIZER");
8102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_OFF;
8112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
813163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_EQUALIZER");
8142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_OFF;
8152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
817163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_VOLUME");
818163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
819163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable")
8222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
823163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
824163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n");
825163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable end");
8262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_free()
8312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Free all memory associated with the Bundle.
8332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free(EffectContext *pContext){
8422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;         /* Function call status */
8432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                        /* Control Parameters */
8442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;
8452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Free the algorithm memory */
8472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance,
8482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   &MemTab,
8492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   LVM_NULL);
8502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free")
8522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
8542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
8552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress != NULL){
856163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - START freeing %ld bytes for region %u at %p\n",
8572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
8602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
861163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - END   freeing %ld bytes for region %u at %p\n",
8622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
864163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR : LvmEffect_free - trying to free with NULL pointer %ld bytes "
8652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "for region %u at %p ERROR\n",
8662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
8682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
8692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmEffect_free */
8712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Effect_configure()
8742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Set input and output audio configuration.
8762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
8802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//      configuration parameters
8812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Effect_configure(EffectContext *pContext, effect_config_t *pConfig){
887163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_Fs_en   SampleRate;
888163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure start");
8892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
8912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig != NULL);
8922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
8942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels);
8952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
8962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == CHANNEL_STEREO);
8972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
8982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
8992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15);
9002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    memcpy(&pContext->config, pConfig, sizeof(effect_config_t));
9022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
903163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    switch (pConfig->inputCfg.samplingRate) {
904163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 8000:
905163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_8000;
906c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 8000*2; // 2 secs Stereo
907163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
908163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 16000:
909163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_16000;
910c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 16000*2; // 2 secs Stereo
911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
912163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 22050:
913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_22050;
914c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 22050*2; // 2 secs Stereo
915163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
916163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 32000:
917163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_32000;
918c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 32000*2; // 2 secs Stereo
919163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
920163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 44100:
921163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_44100;
922c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 44100*2; // 2 secs Stereo
923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
924163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 48000:
925163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_48000;
926c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 48000*2; // 2 secs Stereo
927163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
928163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    default:
929163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_Configure invalid sampling rate %d", pConfig->inputCfg.samplingRate);
930163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
931163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
933163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->SampleRate != SampleRate){
9342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
935163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ControlParams_t     ActiveParams;
936163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;
9372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
938163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure change sampling rate to %d", SampleRate);
9392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
940163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
941163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
942163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
9432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_configure")
945163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_configure")
950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure Succesfully called LVM_SetControlParameters\n");
951c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SampleRate = SampleRate;
9522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
953163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
954163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_configure keep sampling rate at %d", SampleRate);
955163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
957163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure End....");
958163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
959163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}   /* end Effect_configure */
9602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassGetStrength()
9632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
9652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
9662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
9672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the
9682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
9692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t BassGetStrength(EffectContext *pContext){
976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved);
9772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
9792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
9822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
9832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength")
9852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
987163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n");
9882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Check that the strength returned matches the strength that was set earlier */
990163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(ActiveParams.BE_EffectLevel !=
991163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){
9922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n",
9932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved);
9942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
9952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
9962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
997163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (saved)  -> %d\n", pContext->pBundledContext->BassStrengthSaved );
9992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return pContext->pBundledContext->BassStrengthSaved;
10002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassGetStrength */
10012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassSetStrength()
10042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15
10072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid BassSetStrength(EffectContext *pContext, uint32_t strength){
1015163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength(%d)", strength);
10162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->BassStrengthSaved = (int)strength;
10182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength")
1027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n");
10282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
10302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_EffectLevel    = (LVM_INT16)((15*strength)/1000);
10312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_CentreFreq     = LVM_BE_CENTRE_90Hz;
10322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1033163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength")
1039163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n");
10402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassSetStrength */
10412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerGetStrength()
10442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
10472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
1048163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the
10492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
10502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t VirtualizerGetStrength(EffectContext *pContext){
1057163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved);
10582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
10602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
10612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength")
10652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
10662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1067163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n");
1068163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength() (0-100)   -> %d\n", ActiveParams.VirtualizerReverbLevel*10);
1069d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    return pContext->pBundledContext->VirtStrengthSaved;
10702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getStrength */
10712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerSetStrength()
10742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15
10772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
1085163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength(%d)", strength);
10862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1089163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->VirtStrengthSaved = (int)strength;
1090163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
10912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
10932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength")
1095163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n");
10962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Virtualizer parameters */
1098d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    ActiveParams.CS_EffectLevel             = (int)((strength*32767)/1000);
10992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1100163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength() (0-1000)   -> %d\n", strength );
1101d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVirtualizerSetStrength() (0- 100)   -> %d\n", ActiveParams.CS_EffectLevel );
11022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength")
1106d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n\n");
11072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setStrength */
11082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandLevel()
11112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the gain currently being used for the band passed in
11132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
11222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1123163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Gain =0;
1124163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1125163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1126163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1127163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1128163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1129163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
11302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1131163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel")
11322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1133163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1134163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Gain    = (int32_t)BandDef[band].Gain*100;    // Convert to millibels
11352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1136163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel -> %d\n", Gain );
1137163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1138163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Gain;
11392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetBandLevel()
11432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Sets gain value for the given band.
11462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Gain:       Gain to be applied in millibels
11502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//---------------------------------------------------------------------------
1155d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurentvoid EqualizerSetBandLevel(EffectContext *pContext, int band, short Gain){
1156163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int gainRounded;
1157163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(Gain > 0){
1158163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain+50)/100);
1159163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1160163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain-50)/100);
1161163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1162163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);
1163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1164163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
11652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
11682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1171163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetBandLevel")
1172163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1173d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tEqualizerSetBandLevel just Got -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain);
11742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set local EQ parameters */
1176163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1177163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    ActiveParams.pEQNB_BandDefinition[band].Gain = gainRounded;
11782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1181163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetBandLevel")
1182d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tEqualizerSetBandLevel just Set -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain);
11832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
11852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
11862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetCentreFrequency()
11892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the frequency being used for the band passed in
11912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){
1200163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Frequency =0;
12012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1202163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1203163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1204163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1205163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1206163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1207163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
12082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1209163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency")
12102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1211163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef   = ActiveParams.pEQNB_BandDefinition;
1212163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Frequency = (int32_t)BandDef[band].Frequency*1000;     // Convert to millibels
12132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1214163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency );
1215163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n");
1216163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Frequency;
12172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandFreqRange(
12212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets lower and upper boundaries of a band.
12252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the high shelf, the low bound is the band frequency and the high
12262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// bound is Nyquist.
12272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the peaking filters, they are the gain[dB]/2 points.
12282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
12312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
12322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
12352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
12362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1237163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow,
1238163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                  uint32_t *pHi){
1239163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pLow = bandFreqRange[band][0];
1240163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pHi  = bandFreqRange[band][1];
1241163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
12422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBand(
12462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Returns the band with the maximum influence on a given frequency.
12502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Result is unaffected by whether EQ is enabled or not, or by whether
12512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// changes have been committed or not.
12522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  targetFreq   The target frequency, in millihertz.
12552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
12592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
12602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){
12622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int band = 0;
12632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1264163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(targetFreq < bandFreqRange[0][0]){
1265163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
1266163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if(targetFreq == bandFreqRange[0][0]){
1267163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
1268163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1269163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for(int i=0; i<FIVEBAND_NUMBANDS;i++){
1270163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){
1271163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            band = i;
1272163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1273163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
12742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return band;
12752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPreset(
12792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets the currently set preset ID.
12832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Will return PRESET_CUSTOM in case the EQ parameters have been modified
12842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// manually since a preset was set.
12852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetPreset(EffectContext *pContext){
1291163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return pContext->pBundledContext->CurPreset;
12922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetPreset(
12962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Sets the current preset by ID.
13002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// All the band parameters will be overridden.
13012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
13042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  preset       The preset ID.
13052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetPreset(EffectContext *pContext, int preset){
13082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1309163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset(%d)", preset);
13102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = preset;
13112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1317163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetPreset")
1318163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully returned from LVM_GetControlParameters\n");
13192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    //ActiveParams.pEQNB_BandDefinition = &BandDefs[0];
13212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
13222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
1323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
1324163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
1325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Gain
1326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        = EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
13272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
13282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the new settings */
13292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetPreset")
13312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1332163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
13332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
13342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
1335163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
13362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetNumPresets(){
1337163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return sizeof(gEqualizerPresets) / sizeof(PresetConfig);
13382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPresetName(
13422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets a human-readable name for a preset ID. Will return "Custom" if
13452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// PRESET_CUSTOM is passed.
13462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// preset       The preset ID. Must be less than number of presets.
13492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//-------------------------------------------------------------------------
13512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst char * EqualizerGetPresetName(int32_t preset){
1352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName start(%d)", preset);
13532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (preset == PRESET_CUSTOM) {
13542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return "Custom";
13552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
13562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return gEqualizerPresets[preset].name;
13572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1358163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName end(%d)", preset);
1359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
13602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetVolumeLevel()
13642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  level       level to be applied
13702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
13742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Level to be set is %d %d\n", level, (LVM_INT16)(level/100));
13792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
13822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1383163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully returned from LVM_GetControlParameters got: %d\n",
1384163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //ActiveParams.VC_EffectLevel);
13852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume parameters */
13872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.VC_EffectLevel  = (LVM_INT16)(level/100);
1388163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel() (-96dB -> 0dB)   -> %d\n", ActiveParams.VC_EffectLevel );
13892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
13912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetVolumeLevel")
13932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
13942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1395163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully called LVM_SetControlParameters\n");
1396163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1397163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1398163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1399163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
1400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1401163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1402d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetVolumeLevel just set (-96dB -> 0dB)   -> %d\n",ActiveParams.VC_EffectLevel );
1403d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    if(pContext->pBundledContext->firstVolume == LVM_TRUE){
1404d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams);
1405d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process")
1406d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks");
1407d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        pContext->pBundledContext->firstVolume = LVM_FALSE;
1408d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    }
14092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setVolumeLevel */
14112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeGetVolumeLevel()
14142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){
14232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1424163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel start");
1425163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
14262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
14272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
14282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetVolumeLevel")
14312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1433163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel );
1434163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel Succesfully returned from LVM_GetControlParameters\n");
14352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *level = ActiveParams.VC_EffectLevel*100;     // Convert dB to millibels
1437163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel end");
14382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end VolumeGetVolumeLevel */
14402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetMute()
14432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
14492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){
1453163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute start(%d)", mute);
14542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->bMuteEnabled = mute;
14562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
14582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
14592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
14612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetMute")
14632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1465163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully returned from LVM_GetControlParameters\n");
1466163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute to %d, level was %d\n", mute, ActiveParams.VC_EffectLevel );
14672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set appropriate volume level */
14692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){
1470163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved = ActiveParams.VC_EffectLevel;
1471163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel           = -96;
14722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel  = pContext->pBundledContext->levelSaved;
14742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
14752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
14772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetMute")
14792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1481163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully called LVM_SetControlParameters\n");
1482163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute end");
14832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setMute */
14852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1487163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetMute()
14882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Ourputs:
14952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
14962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){
1499163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute start");
1500163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||
1501163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){
1502163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        *mute = pContext->pBundledContext->bMuteEnabled;
1503163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
15042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d",
1506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent              pContext->pBundledContext->bMuteEnabled);
1507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
15082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute end");
15102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getMute */
15112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1512163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint16_t VolumeConvertStereoPosition(int16_t position){
1513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t convertedPosition = 0;
1514163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    convertedPosition = (int16_t)(((float)position/1000)*96);
1516163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return convertedPosition;
1517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1518163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
1519163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1520163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1521163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeSetStereoPosition()
1522163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1523163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1524163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1525163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1526163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1527163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1528163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1529163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1530163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1531163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1532163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint VolumeSetStereoPosition(EffectContext *pContext, int16_t position){
1533163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1534163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1535163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1536163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               Balance = 0;
1537163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1538c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1540163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->positionSaved = position;
1541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1542163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1543d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1544d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1546163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1547163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1548163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance);
1549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved = position;
1550163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1552163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1553163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1554163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:"
1555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     " %d\n", ActiveParams.VC_Balance);
1556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1557163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Volume parameters */
1558163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  = Balance;
1559163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB)   -> %d\n", ActiveParams.VC_Balance );
1560163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1561163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Activate the initial settings */
1562163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1563163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
1564163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n");
15672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1568163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1572163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: "
1573163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     "%d\n", ActiveParams.VC_Balance);
1574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    else{
1576163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n",
1577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //position, Balance);
1578163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1579d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n",
1580d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1581163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeSetStereoPosition */
15832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1586163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetStereoPosition()
1587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1591163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1592163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
15962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){
1598163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition start");
15992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1602163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               balance;
1603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1604d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1605d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1606163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1607163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
1609163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance);
1612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1613163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1614163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1615163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(balance != ActiveParams.VC_Balance){
1618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
1619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1620163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *position = (LVM_INT16)pContext->pBundledContext->positionSaved;     // Convert dB to millibels
1622d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved =%d\n",
1623d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1624163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeGetStereoPosition */
16262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1627163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeEnableStereoPosition()
1629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1630163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1631163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:   effect engine context
1634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  mute:       enable/disable flag
1635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
16372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){
1639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition start()");
16402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->bStereoPositionEnabled = enabled;
16422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1644163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
16452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1648163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition")
1649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1652163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition to %d, position was %d\n",
1653163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //     enabled, ActiveParams.VC_Balance );
16542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1655163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Set appropriate stereo position */
1656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){
1657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance = 0;
1658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  =
1660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                            VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1661163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
16622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1663163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
1664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition")
1666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n");
1669163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition end()\n");
1670163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeEnableStereoPosition */
16722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_getParameter()
16752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
16772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a BassBoost parameter
16782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
16812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
16822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
16832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
16842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
16862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
16872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
16882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
16912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_getParameter(EffectContext     *pContext,
1695c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
1696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           size_t            *pValueSize,
1697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           void              *pValue){
16982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1699c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1700c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
17012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
17022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
17032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1704163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter start");
17052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
170723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17087fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
1709d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize1 %d", *pValueSize);
17107fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
17117fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
17127fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
17137fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
17142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
1716d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize2 %d", *pValueSize);
17172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
17182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
17192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
17202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
17252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
172823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
17302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
173123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d",
1732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
17332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = BassGetStrength(pContext);
17372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1738163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d",
1739163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
17402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
17452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1748163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter end");
17492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_getParameter */
17512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_setParameter()
17542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a BassBoost parameter
17572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
17602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
17622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1767c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue){
17682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
17692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1770c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
17712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1772163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter start");
17732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1774c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (*pParamTemp){
17752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1777163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength);
1778163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength");
17792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            BassSetStrength(pContext, (int32_t)strength);
1780163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength");
17812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
17822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1783c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParamTemp);
17842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1787163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter end");
17882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_setParameter */
17902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_getParameter()
17932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Virtualizer parameter
17962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
17992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
18012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
18022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
18052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
18062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
18092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_getParameter(EffectContext        *pContext,
1813c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void                 *pParam,
18142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             size_t               *pValueSize,
18152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             void                 *pValue){
18162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1817c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1818c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
18192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
18202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
18212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1822163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter start");
18232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
182523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18267fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
18277fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
18287fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
18297fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
18307fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
18317fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
18322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
1834d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize2 %d",*pValueSize);
18352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
18362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
18372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
18382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
18422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
18432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
184623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
18482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
184923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d",
1850163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
18512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = VirtualizerGetStrength(pContext);
18552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1856163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d",
1857163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
18582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
18622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
18632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1866163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter end");
18672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_getParameter */
18692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_setParameter()
18722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Virtualizer parameter
18752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
18782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
18802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1885c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
18862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
18872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1888c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1889c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
18902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1891163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter start");
18922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1893c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
18942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1896163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength);
1897163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength");
18982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            VirtualizerSetStrength(pContext, (int32_t)strength);
1899163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength");
19002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
19012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1902c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", param);
19032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1906163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter end");
19072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_setParameter */
19092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_getParameter()
19122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Equalizer parameter
19152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer       - handle to instance data
19182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
19202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
19212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
19242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
19252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
19282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_getParameter(EffectContext     *pContext,
1931c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
19322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           size_t            *pValueSize,
19332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           void              *pValue){
19342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
19352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
1936c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1937c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
19382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
19392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
19402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1941163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_getParameter start");
19422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
19442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
19452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
19462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
19473be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_BAND_LEVEL:
19483be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_GET_BAND:
19492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int16_t)) {
1950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
19512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int16_t);
19542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
19573be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (*pValueSize < 2 * sizeof(int16_t)) {
19583be9523784cc4038f601e510faee595117cdacb3Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
19593be9523784cc4038f601e510faee595117cdacb3Eric Laurent            return -EINVAL;
19603be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
19613be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *pValueSize = 2 * sizeof(int16_t);
19623be9523784cc4038f601e510faee595117cdacb3Eric Laurent        break;
19632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
19642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < 2 * sizeof(int32_t)) {
1965d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 3  %d", *pValueSize);
19662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = 2 * sizeof(int32_t);
19692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19703be9523784cc4038f601e510faee595117cdacb3Eric Laurent
19712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
19722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int32_t)) {
1973d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 5  %d", *pValueSize);
19742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int32_t);
19772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
19802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
198223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES:
198323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) {
198423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
198523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            return -EINVAL;
198623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
198723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t);
198823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        break;
198923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
19902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
1991163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param);
19922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
19932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
19962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
19973be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS;
1998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue);
19992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
20023be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = -1500;
20033be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *((int16_t *)pValue + 1) = 1500;
2004163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d",
2005d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      *(int16_t *)pValue, *((int16_t *)pValue + 1));
20062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2009c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20143be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2);
2015163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d",
2016163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
2020c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2);
2026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d",
2027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
2031c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1));
2037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d",
2038163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue, *((int32_t *)pValue + 1));
20392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_BAND:
2042c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20433be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2);
2044163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d",
2045d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      param2, *(uint16_t *)pValue);
20462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
20493be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext);
2050163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue);
20512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
20543be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets();
2055163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue);
20562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
2059c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= EqualizerGetNumPresets()) {
20612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        //if (param2 >= 20) {     // AGO FIX
20622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name = (char *)pValue;
20662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1);
20672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name[*pValueSize - 1] = 0;
20682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = strlen(name) + 1;
2069163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d",
2070163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, gEqualizerPresets[param2].name, *pValueSize);
20712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
207323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES: {
20743be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
207523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        LOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES");
20763be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[0] = (int16_t)EqualizerGetPreset(pContext);
20773be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[1] = (int16_t)FIVEBAND_NUMBANDS;
207823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
20793be9523784cc4038f601e510faee595117cdacb3Eric Laurent            p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i);
208023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
208123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    } break;
208223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
20832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
20842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param);
20852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        status = -EINVAL;
20862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2089d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //GV("\tEqualizer_getParameter end\n");
20902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
20912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_getParameter */
20922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_setParameter()
20952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
20972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Equalizer parameter
20982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer    - handle to instance data
21012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
21022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
21032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
2107c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
21082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t preset;
21102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t band;
21112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t level;
2112c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2113c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
2114c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
21152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2116163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter start");
21172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
21182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
21193be9523784cc4038f601e510faee595117cdacb3Eric Laurent        preset = (int32_t)(*(uint16_t *)pValue);
21202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2121163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset);
21222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if ((preset >= EqualizerGetNumPresets())||(preset < 0)) {
21232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetPreset(pContext, preset);
21272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2129c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        band =  *pParamTemp;
21303be9523784cc4038f601e510faee595117cdacb3Eric Laurent        level = (int32_t)(*(int16_t *)pValue);
2131163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level);
21322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (band >= FIVEBAND_NUMBANDS) {
21332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetBandLevel(pContext, band, level);
21372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21383be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_PROPERTIES: {
21393be9523784cc4038f601e510faee595117cdacb3Eric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES");
21403be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
21413be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if ((int)p[0] >= EqualizerGetNumPresets()) {
21423be9523784cc4038f601e510faee595117cdacb3Eric Laurent            status = -EINVAL;
21433be9523784cc4038f601e510faee595117cdacb3Eric Laurent            break;
21443be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
21453be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (p[0] >= 0) {
21463be9523784cc4038f601e510faee595117cdacb3Eric Laurent            EqualizerSetPreset(pContext, (int)p[0]);
21473be9523784cc4038f601e510faee595117cdacb3Eric Laurent        } else {
21483be9523784cc4038f601e510faee595117cdacb3Eric Laurent            if ((int)p[1] != FIVEBAND_NUMBANDS) {
21493be9523784cc4038f601e510faee595117cdacb3Eric Laurent                status = -EINVAL;
21503be9523784cc4038f601e510faee595117cdacb3Eric Laurent                break;
21513be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
21523be9523784cc4038f601e510faee595117cdacb3Eric Laurent            for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
21533be9523784cc4038f601e510faee595117cdacb3Eric Laurent                EqualizerSetBandLevel(pContext, i, (int)p[2 + i]);
21543be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
21553be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
21563be9523784cc4038f601e510faee595117cdacb3Eric Laurent    } break;
21572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
2158d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LOGV("\tLVM_ERROR : Equalizer_setParameter() invalid param %d", param);
21593be9523784cc4038f601e510faee595117cdacb3Eric Laurent        status = -EINVAL;
21602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter end");
21642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_setParameter */
21662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_getParameter()
21692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Volume parameter
21722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume          - handle to instance data
21752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
21762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
21772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
21782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
21812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
21822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
21852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_getParameter(EffectContext     *pContext,
2189c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void              *pParam,
21902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        size_t            *pValueSize,
21912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        void              *pValue){
21922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2194c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2195c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;;
21962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
21972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2198d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolume_getParameter start");
21992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2204163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if (*pValueSize != sizeof(int16_t)){
22052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1  %d", *pValueSize);
22062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
22092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
22122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
22132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize < sizeof(int32_t)){
22142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2  %d", *pValueSize);
22152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int32_t);
22182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2221163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param);
22222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue));
2228d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d",
2229d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = 0;
2234d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d",
2235d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2239163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            VolumeGetStereoPosition(pContext, (int16_t *)pValue);
2240d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d",
2241d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2245163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeGetMute(pContext, (uint32_t *)pValue);
2246163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d",
2247163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(uint32_t *)pValue);
22482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled;
2252d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d",
2253d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(uint32_t *)pValue);
22542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
22572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param);
22582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
22592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2262163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_getParameter end");
22632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
22642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_getParameter */
22652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_setParameter()
22692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
22712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Volume parameter
22722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
22742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume       - handle to instance data
22752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
22762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
22772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
22792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2282c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue){
22832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int      status = 0;
22842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t  level;
2285163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t  position;
22862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    uint32_t mute;
2287163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    uint32_t positionEnabled;
2288c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2289c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
22902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2291d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolume_setParameter start");
22922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2293c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
22942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            level = *(int16_t *)pValue;
2296d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level);
2297d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel");
22982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeSetVolumeLevel(pContext, (int16_t)level);
2299d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel");
23002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2303163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            mute = *(uint32_t *)pValue;
2304d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute);
2305d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setMute");
2306163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetMute(pContext, mute);
2307d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->setMute");
2308163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2311163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            positionEnabled = *(uint32_t *)pValue;
2312163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeEnableStereoPosition(pContext, positionEnabled);
2313163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved);
2314d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called");
2315163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2318163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            position = *(int16_t *)pValue;
2319d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position);
2320d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition");
2321163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, (int16_t)position);
2322d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition");
2323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2326c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", param);
23272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_setParameter end");
23312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_setParameter */
23332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2334163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent/****************************************************************************************
2335163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent * Name : LVC_ToDB_s32Tos16()
2336163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Input       : Signed 32-bit integer
2337163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Output      : Signed 16-bit integer
2338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  MSB (16) = sign bit
2339163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (15->05) = integer part
2340163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (04->01) = decimal part
2341163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Returns     : Db value with respect to full scale
2342163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Description :
2343163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Remarks     :
2344163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent ****************************************************************************************/
2345163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2346163fbcf84010b98e0374110454d85b804bc8d13bEric LaurentLVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix)
2347163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent{
2348163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   db_fix;
2349163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   Shift;
2350163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   SmallRemainder;
2351163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_UINT32  Remainder = (LVM_UINT32)Lin_fix;
2352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2353163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Count leading bits, 1 cycle in assembly*/
2354163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for (Shift = 0; Shift<32; Shift++)
2355163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
2356163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if ((Remainder & 0x80000000U)!=0)
2357163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2358163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        Remainder = Remainder << 1;
2361163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
23622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /*
2364163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * Based on the approximation equation (for Q11.4 format):
2365163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     *
2366163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2)
2367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     */
2368163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix    = (LVM_INT16)(-96 * Shift);               /* Six dB steps in Q11.4 format*/
2369163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24);
2370163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix + SmallRemainder );
2371163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder);
2372163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9));
23732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2374163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Correct for small offset */
2375163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - 5);
23762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return db_fix;
2378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
23792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2380163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
2381163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
23822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Process */
23842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_process(effect_interface_t     self,
2385163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *inBuffer,
2386163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *outBuffer){
23872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
2388c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
2389c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
23902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int    status = 0;
2391c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int    status2Sec = 0;
2392163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int    lvmStatus = 0;
2393163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *in  = (LVM_INT16 *)inBuffer->raw;
2394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *out = (LVM_INT16 *)outBuffer->raw;
23952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2396d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent//LOGV("\tEffect_process Start : Enabled = %d     Called = %d",
2397d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent//pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled);
2398c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LOGV("\tEffect_process Start : Samples left %d %d %d",
2399c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountBb,
2400c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountVirt,
2401c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountEq);
2402c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2403c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
2404c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
2405c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
2406c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LOGV("\tEffect_process Internal Operating Modes: BB %d   VIRT %d    EQ %d",
2407c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//        ActiveParams.BE_OperatingMode, ActiveParams.VirtualizerOperatingMode,
2408c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//        ActiveParams.EQNB_OperatingMode);
24092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
24112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL");
24122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
24132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
24142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
24152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
24162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            inBuffer->frameCount != outBuffer->frameCount){
24172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
24182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
24192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2420163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&
2421163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_BASS_BOOST)){
2422c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_BASS_BOOST Effect is not enabled");
2423c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
2424c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2425c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO
24262d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent            //LOGV("\tEffect_process: Waiting to turn off BASS_BOOST, %d samples left",
2427c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountBb);
2428c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2429163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2430c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
2431163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2432163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&
2433163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VOLUME)){
2434c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_VOLUME Effect is not enabled");
2435163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2436163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2437163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&
2438163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_EQUALIZER)){
2439c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_EQUALIZER Effect is not enabled");
2440c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
2441c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2442c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq -= outBuffer->frameCount * 2; // STEREO
2443c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //LOGV("\tEffect_process: Waiting for 2 secs to turn off EQUALIZER, %d samples left",
2444c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountEq);
2445c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2446c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2447c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
24482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2449163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&
2450163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VIRTUALIZER)){
2451c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_VIRTUALIZER Effect is not enabled");
2452c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
2453c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2454c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt -= outBuffer->frameCount * 2;// STEREO
2455c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //LOGV("\tEffect_process: Waiting for 2 secs to turn off VIRTUALIZER, %d samples left",
2456c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountVirt);
2457c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2458c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2459c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
24602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2461163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2462163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // If this is the last frame of an effect process its output with no effect
2463163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(status == -ENODATA){
2464163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
2465163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() accumulating last frame into output buffer");
2466163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() trying copying last frame into output buffer");
2467163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Enabled = %d     Called = %d",
2468163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->NumberEffectsEnabled,
2469163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->NumberEffectsCalled);
2470163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2471163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }else{
2472163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() copying last frame into output buffer");
2473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
24742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2475163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2476c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if((status2Sec != -ENODATA)&&(status != -ENODATA)){
2477163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled++;
24782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
24792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2480163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->NumberEffectsCalled ==
2481163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       pContext->pBundledContext->NumberEffectsEnabled){
2482163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Calling process with %d effects enabled, %d called: Effect %d",
2483163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2484163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
24852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2486163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(status == -ENODATA){
2487163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() actually processing last frame");
2488163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
24892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext->NumberEffectsCalled = 0;
2490163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Process all the available frames, block processing is
2491163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           handled internalLY by the LVM bundle */
2492163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        lvmStatus = android::LvmBundle_process(    (LVM_INT16 *)inBuffer->raw,
24932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                (LVM_INT16 *)outBuffer->raw,
24942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                outBuffer->frameCount,
24952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                pContext);
2496163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(lvmStatus != LVM_SUCCESS){
2497163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
2498163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return lvmStatus;
2499163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
25002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
2501163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
2502163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2503163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
2504163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        // 2 is for stereo input
2505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
25062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
25092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end Effect_process */
25102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Command */
25122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_command(effect_interface_t  self,
251325f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdCode,
251425f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdSize,
2515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pCmdData,
251625f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            *replySize,
2517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pReplyData){
25182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
25192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int retsize;
25202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2521163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\t\nEffect_command start");
25222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST){
2524163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_BASS_BOOST");
25252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
25262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER){
2527163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VIRTUALIZER");
2528163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER){
2530163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_EQUALIZER");
2531163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME){
2533163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VOLUME");
2534163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
25372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL");
25382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
25392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
25402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
25422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2543163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // Incase we disable an effect, next time process is
2544163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // called the number of effect called could be greater
2545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // pContext->pBundledContext->NumberEffectsCalled = 0;
25462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2547163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d",
2548163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsCalled,
2549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsEnabled);
25502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (cmdCode){
25522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_INIT:
2553010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
2554010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                LOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d",
2555010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                        pContext->EffectType);
2556010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                return -EINVAL;
2557010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            }
2558010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            *(int *) pReplyData = 0;
2559163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start");
25602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2561163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST");
25622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                android::BassSetStrength(pContext, 0);
25632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
25642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER");
2566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::VirtualizerSetStrength(pContext, 0);
2567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER");
2570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::EqualizerSetPreset(pContext, 0);
2571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2573d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VOLUME");
2574010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0);
2575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_CONFIGURE:
2579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE start");
25802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pCmdData    == NULL||
25812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                cmdSize     != sizeof(effect_config_t)||
25822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                pReplyData  == NULL||
25832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize  != sizeof(int)){
25842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
25852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_CONFIGURE: ERROR");
25862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
25872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
25882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *) pReplyData = android::Effect_configure(pContext, (effect_config_t *) pCmdData);
2589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE end");
25902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_RESET:
2593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start");
25942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            android::Effect_configure(pContext, &pContext->config);
2595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end");
25962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_GET_PARAM:{
2599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2602163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2604163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
26062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
26072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
26082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
26112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
26132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
26152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
26172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::BassBoost_getParameter(pContext,
2619c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
26202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            (size_t  *)&p->vsize,
26212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            p->data + voffset);
26222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
26242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM "
2626163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2627163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
26302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
2631163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
26372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
26382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
26392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
26422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
26442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
26462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
26482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Virtualizer_getParameter(pContext,
2650c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                             (void *)p->data,
26512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                             (size_t  *)&p->vsize,
26522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                              p->data + voffset);
26532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
26552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM "
2657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
26612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
26622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2663163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command cmdCode Case: "
2664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL ||
2668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) {
26692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
26702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM");
26712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
2674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
2676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
2678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
2680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2681c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                p->status = android::Equalizer_getParameter(pContext,
2682c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
2683c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            &p->vsize,
2684c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data + voffset);
2685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
2687163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2688163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, "
2689163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //       "*pReplyData %08x %08x",
2690163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize,
2691163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset),
2692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset +
2693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        sizeof(int32_t)));
26942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
26952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2696d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tVolume_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
27012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
27022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
27032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
27062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
27082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
27102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
27122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Volume_getParameter(pContext,
2714c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                         (void *)p->data,
27152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         (size_t  *)&p->vsize,
27162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         p->data + voffset);
27172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
27192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2720163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_GET_PARAM "
2721163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2722163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2724163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
2725163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2726163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end");
27272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
27282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_PARAM:{
2729163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
27302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2733163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2734163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2735163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2737163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2738163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2739163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
27402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
27422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
27452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
27472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
27492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnBassBoost_command cmdSize is %d\n"
2753163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2754163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2755163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2757163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
27582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::BassBoost_setParameter(pContext,
2760c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
27612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    p->data + p->psize);
27622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2764d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //LOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2765d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2766d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *replySize,
2767d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2768163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2769163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2770163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2771163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2772163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
27732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
27742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
27752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
27782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
27802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
27812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
27822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2785163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnVirtualizer_command cmdSize is %d\n"
2786163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2787163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2788163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2789163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2790163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
27912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Virtualizer_setParameter(pContext,
2793c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                      (void *)p->data,
2794163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                       p->data + p->psize);
27952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2797d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //LOGV("\tEqualizer_command cmdCode Case: "
2798d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        "EFFECT_CMD_SET_PARAM start");
2799d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //LOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2800d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2801d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *replySize,
2802d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
28032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
28052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pReplyData == NULL || *replySize != sizeof(int32_t)) {
28062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
28072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
28082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
28112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Equalizer_setParameter(pContext,
2813c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
2814163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                     p->data + p->psize);
28152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2817d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tVolume_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
2818163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2819163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2820163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2821d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) +sizeof(int32_t)));
28222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (    pCmdData   == NULL||
28242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        cmdSize    < (int)(sizeof(effect_param_t) + sizeof(int32_t))||
28252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        pReplyData == NULL||
28262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        *replySize != sizeof(int32_t)){
28272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
28282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
28292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
28322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Volume_setParameter(pContext,
2834c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                 (void *)p->data,
2835163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                 p->data + p->psize);
2836163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2837163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end");
28382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
28392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_ENABLE:
2841c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start");
28422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
28432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
28442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
2845163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
28462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            switch (pContext->EffectType){
28472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_BASS_BOOST:
28482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
28492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
28502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bBassEnabled = LVM_TRUE;
2854d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                    //LOGV("\tEffect_command cmdCode Case:EFFECT_CMD_ENABLE LVM_BASS_BOOSTenabled");
28552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
28562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_EQUALIZER:
28572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE){
28582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
28592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE;
2863d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                    //LOGV("\tEffect_command cmdCode Case:EFFECT_CMD_ENABLE LVM_EQUALIZER enabled");
2864163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
28652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VIRTUALIZER:
28662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
28672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
28682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE;
2872d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                    //LOGV("\tEffect_command cmdCode :EFFECT_CMD_ENABLE LVM_VIRTUALIZER enabled");
2873163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
28742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VOLUME:
28752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){
28762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
28772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVolumeEnabled = LVM_TRUE;
2881d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                    LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_VOLUME enabled");
28822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
28832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                default:
28842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
28852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_ENABLE: ERROR, invalid Effect Type");
2886163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    return -EINVAL;
28872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *)pReplyData = 0;
28892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            pContext->pBundledContext->NumberEffectsEnabled++;
2890163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::LvmEffect_enable(pContext);
2891c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq =
28922d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); // 0.1 secs Stereo
2893c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb =
28942d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); // 0.1 secs Stereo
2895c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt =
28962d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1); // 0.1 secs Stereo
2897c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE Samples to Exit = %d",
2898c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pContext->pBundledContext->SamplesToExitCountBb);
2899163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE NumberEffectsEnabled = %d",
2900163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        pContext->pBundledContext->NumberEffectsEnabled);
2901163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE end");
29022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2903163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
29042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_DISABLE:
2905163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start");
29062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
29072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
29082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
2909163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            switch (pContext->EffectType){
29112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_BASS_BOOST:
29122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_FALSE){
29132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
29142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
2917163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pContext->pBundledContext->bBassEnabled      = LVM_FALSE;
2918163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2919163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //       "EFFECT_CMD_DISABLE LVM_BASS_BOOST disabled");
29202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
29212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_EQUALIZER:
29222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE){
29232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
29242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE;
2928163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2929163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //       "EFFECT_CMD_DISABLE LVM_EQUALIZER disabled");
2930163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
29312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VIRTUALIZER:
29322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE){
29332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE;
2938163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2939163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //     "EFFECT_CMD_DISABLE LVM_VIRTUALIZER disabled");
2940163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
29412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VOLUME:
29422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVolumeEnabled == LVM_FALSE){
29432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
29442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVolumeEnabled = LVM_FALSE;
2948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_VOLUME disabled");
29492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
29502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                default:
29512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
29522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_DISABLE: ERROR, invalid Effect Type");
2953163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    return -EINVAL;
2954163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *)pReplyData = 0;
29562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
2957163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::LvmEffect_disable(pContext);
2958163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE NumberEffectsEnabled = %d",
2959163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        pContext->pBundledContext->NumberEffectsEnabled);
2960163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE end");
29612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
29622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_DEVICE:
2964163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2965163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start");
2966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            audio_device_e device = *(audio_device_e *)pCmdData;
2967163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2969163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
2970163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
2971163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d",
2972163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
2973163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST");
2974163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2975163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device doesnt support bassboost the effect must be temporarily disabled
2976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
2977163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
2978163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2979163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
2980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d",
2981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
2982163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
2983163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_TRUE;
2984163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2985163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
2986163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d",
2987163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                         *(int32_t *)pCmdData);
2988163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2989163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports bassboost and the effect has been temporarily disabled
2990163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
2991163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2992163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassTempDisabled == LVM_TRUE){
2993163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d",
2994163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
2995163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
2996163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_FALSE;
2997163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
2999163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3000163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
3001163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
3002163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
3003163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d",
3004163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3005163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER");
3006163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3007163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //If a device doesnt support virtualizer the effect must be temporarily disabled
3008163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3009163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3010163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3011163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
3012163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d",
3013163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3014163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3015163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
3016163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3017163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
3018163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d",
3019163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3020163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3021163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports virtualizer and the effect has been temporarily disabled
3022163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3023163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3024163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerTempDisabled == LVM_TRUE){
3025163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d",
3026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3028163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
3029163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3030163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3031163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end");
30332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3034163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
3035163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_VOLUME:
3036163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
3037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t vol     = *(int32_t *)pCmdData;
3038163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int16_t dB;
3039163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t vol_ret[2] = {1<<24,1<<24}; // Apply no volume
3040163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3041163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // if pReplyData is NULL, VOL_CTRL is delegated to another effect
3042163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pReplyData == LVM_NULL){
3043163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                break;
3044163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
30452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3046163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(vol==0x1000000){
3047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                vol -= 1;
3048163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3049163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // Convert volume linear (Q8.24) to volume dB (0->-96)
3050163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = android::LVC_ToDB_s32Tos16(vol <<7);
3051163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = (dB +8)>>4;
3052163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = (dB <-96) ? -96 : dB ;
3053163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3054d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            LOGV("\tEFFECT_CMD_SET_VOLUME Session: %d, SessionID: %d VOLUME is %d dB (%d), "
3055d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                  "effect is %d",
3056d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            pContext->pBundledContext->SessionNo, pContext->pBundledContext->SessionId,
3057d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            (int32_t)dB, vol<<7, pContext->EffectType);
3058d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
3059163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            memcpy(pReplyData, vol_ret, sizeof(int32_t)*2);
3060163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::VolumeSetVolumeLevel(pContext, (int16_t)(dB*100));
3061163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
3062163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent         }
3063163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
3064163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
30652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
30662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
30672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
30682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3069163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command end...\n\n");
30702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
30712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end Effect_command */
30722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for effect
30742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst struct effect_interface_s gLvmEffectInterface = {
30752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_process,
30762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_command
30772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};    /* end gLvmEffectInterface */
30782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3079