EffectBundle.cpp revision c59c6fd7f859b4010d788db89b8d4d76bbb70e57
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])
20163fbcf84010b98e0374110454d85b804bc8d13bEric 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#define LVM_MAX_SESSIONS        32
302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define MAX_NUM_BANDS           5
312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define MAX_CALL_SIZE           256
322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for bass boost
342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" const struct effect_interface_s gLvmEffectInterface;
352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_NULLADDRESS){\
382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_ALIGNMENTERROR){\
422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad alignment returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_INVALIDNUMSAMPLES){\
462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_OUTOFRANGE){\
502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "out of range returned by %s in %s\n", callingFunc, calledFunc);\
522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Namespaces
562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace android {
572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace {
582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* local functions */
602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define CHECK_ARG(cond) {                     \
612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (!(cond)) {                            \
622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Invalid argument: "#cond);      \
632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;                       \
642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }                                         \
652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
67163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Flag to allow a one time init of global memory, only happens on first call ever
682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmInitFlag = LVM_FALSE;
69c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint LvmSessionsActive = 0;
70c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric LaurentSessionContext GlobalSessionMemory[LVM_MAX_SESSIONS];
71c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint SessionIndex[LVM_MAX_SESSIONS];
722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW BassBoost UUID
742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gBassBoostDescriptor = {
752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
78163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
79163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        0, // TODO
812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        1,
822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Dynamic Bass Boost",
832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Virtualizer UUID
872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVirtualizerDescriptor = {
88163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
89163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
91163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
92163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        0, // TODO
942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        1,
952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Virtualizer",
962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Equalizer UUID
1002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gEqualizerDescriptor = {
1012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
1022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP
1032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
104163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
1052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        0, // TODO
1062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        1,
1072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Equalizer",
1082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Volume UUID
1122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVolumeDescriptor = {
1132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
1142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP
1152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
116163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
1172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        0, // TODO
1182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        1,
1192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Volume",
1202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//--- local function prototypes
1242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init      (void);
1252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmBundle_init            (EffectContext *pContext);
1262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_enable          (EffectContext *pContext);
1272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_disable         (EffectContext *pContext);
1282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free            (EffectContext *pContext);
129163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  Effect_configure          (EffectContext *pContext, effect_config_t *pConfig);
130c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  BassBoost_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
131163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  BassBoost_getParameter    (EffectContext *pContext,
132c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
1342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               void           *pValue);
135c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Virtualizer_setParameter  (EffectContext *pContext, void *pParam, void *pValue);
1362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Virtualizer_getParameter  (EffectContext *pContext,
137c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
139163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                               void           *pValue);
140c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Equalizer_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
1412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Equalizer_getParameter    (EffectContext *pContext,
142c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
145c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Volume_setParameter       (EffectContext *pContext, void *pParam, void *pValue);
1462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Volume_getParameter       (EffectContext *pContext,
147c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
1502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Library Interface Implementation */
1522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){
1532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryNumberEffects start");
1542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pNumEffects = 4;
155163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects);
156163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects end\n");
1572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryNumberEffects */
1592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor){
1612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryEffect start");
1622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect processing index %d", index);
163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pDescriptor == NULL){
165163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer");
1662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
1672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (index > 3){
169163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index);
1702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -ENOENT;
1712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(index == LVM_BASS_BOOST){
1732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_BASS_BOOST");
1742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gBassBoostDescriptor,   sizeof(effect_descriptor_t));
1752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else if(index == LVM_VIRTUALIZER){
1762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VIRTUALIZER");
1772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVirtualizerDescriptor, sizeof(effect_descriptor_t));
1782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_EQUALIZER){
1792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_EQUALIZER");
1802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gEqualizerDescriptor,   sizeof(effect_descriptor_t));
1812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_VOLUME){
1822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VOLUME");
1832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVolumeDescriptor, sizeof(effect_descriptor_t));
184163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect end\n");
1862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryEffect */
1882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectCreate(effect_uuid_t       *uuid,
1902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             sessionId,
1912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             ioId,
1922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            effect_interface_t  *pInterface){
1932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int ret;
194c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int sessionNo;
1952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int i;
1962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext *pContext = new EffectContext;
1972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectCreate start session %d", sessionId);
1992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pInterface == NULL || uuid == NULL){
201163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer");
2022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
2032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
205c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(sessionId < 0){
2062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : EffectCreate sessionId is less than 0");
207163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
2082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmInitFlag == LVM_FALSE){
2112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmInitFlag = LVM_TRUE;
2122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Initializing all global memory");
2132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmGlobalBundle_init();
2142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
216c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LOGV("\tEffectCreate: There are %d LVM sessions acive\n", LvmSessionsActive);
217c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
218c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Find next available sessionNo
219c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for(i=0; i<LVM_MAX_SESSIONS; i++){
220c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if((SessionIndex[i] == -1)||(SessionIndex[i] == sessionId)){
221c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            sessionNo       = i;
222c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            SessionIndex[i] = sessionId;
223c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffectCreate: Allocating SessionNo %d for SessionId %d\n", sessionNo,sessionId);
224c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
225c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
226c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
227c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
228c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(i==LVM_MAX_SESSIONS){
229c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tLVM_ERROR : Cannot find memory to allocate for current session");
230c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
231c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
2322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // If this is the first create in this session
233c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(GlobalSessionMemory[sessionNo].bBundledEffectsEnabled == LVM_FALSE){
234c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectCreate - This is the first effect in current sessionId %d sessionNo %d",
235c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionId, sessionNo);
236c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
237c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LvmSessionsActive++;
238c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
239c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(LvmSessionsActive >= LVM_MAX_SESSIONS){
240c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Number of active session is greater than LVM_MAX_SESSIONS (%d)",
241c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                  LVM_MAX_SESSIONS);
242c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            return -EINVAL;
243c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
244163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
245c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_TRUE;
246c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].pBundledContext        = new BundledEffectContext;
2472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
248c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = GlobalSessionMemory[sessionNo].pBundledContext;
249c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionNo                = sessionNo;
250c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionId                = sessionId;
251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->hInstance                = NULL;
252163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVolumeEnabled           = LVM_FALSE;
253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bEqualizerEnabled        = LVM_FALSE;
254163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassEnabled             = LVM_FALSE;
255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassTempDisabled        = LVM_FALSE;
256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerEnabled      = LVM_FALSE;
257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
258163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsEnabled     = 0;
259163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled      = 0;
260163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->frameCount               = 0;
261163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
262163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
263163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->PcmInPtr  = NULL;
264163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->PcmOutPtr = NULL;
265163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
266163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->PcmInPtr  = fopen("/data/tmp/bundle_pcm_in.pcm", "w");
267163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->PcmOutPtr = fopen("/data/tmp/bundle_pcm_out.pcm", "w");
268163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
269163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((pContext->pBundledContext->PcmInPtr  == NULL)||
270163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           (pContext->pBundledContext->PcmOutPtr == NULL)){
271163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           return -EINVAL;
272163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
273163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
274163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        /* Saved strength is used to return the exact strength that was used in the set to the get
2762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * because we map the original strength range of 0:1000 to 1:15, and this will avoid
2772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * quantisation like effect when returning
2782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         */
279163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->BassStrengthSaved        = 0;
280163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->VirtStrengthSaved        = 0;
281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->CurPreset                = PRESET_CUSTOM;
282163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved               = 0;
283163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bMuteEnabled             = LVM_FALSE;
284163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bStereoPositionEnabled   = LVM_FALSE;
285163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved            = 0;
286163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Calling LvmBundle_init");
2882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ret = LvmBundle_init(pContext);
2892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (ret < 0){
2912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : EffectCreate() Bundle init failed");
2922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            delete pContext->pBundledContext;
2932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            delete pContext;
2942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return ret;
2952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
2962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
298c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectCreate - Assigning memory for previously created effect on sessionNo %d",
299c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionNo);
300c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext =
301c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                GlobalSessionMemory[sessionNo].pBundledContext;
3022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext);
3042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Create each Effect
3062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Bass Boost
3082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST");
309c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated = LVM_TRUE;
310163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
311163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_BASS_BOOST;
3132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Virtualizer
315163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER");
316c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated=LVM_TRUE;
317163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VIRTUALIZER;
3202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Equalizer
322163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER");
323c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated = LVM_TRUE;
324163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_EQUALIZER;
3272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Volume
329163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VOLUME");
330c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated = LVM_TRUE;
331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VOLUME;
334163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
336163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() invalid UUID");
337163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
3382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pInterface = (effect_interface_t)pContext;
341163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectCreate end..\n\n");
3422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
3432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectCreate */
3442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectRelease(effect_interface_t interface){
3462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectRelease start %p", interface);
3472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *)interface;
3482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
349c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LOGV("\n\tEffectRelease start interface: %p, context %p", interface, pContext->pBundledContext);
3502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
351163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
3522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
353163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Clear the instantiated flag for the effect
3562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
3572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag");
358163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated = LVM_FALSE;
3592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VIRTUALIZER) {
3602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag");
361163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated
362163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            = LVM_FALSE;
3632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_EQUALIZER) {
3642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag");
365163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated =LVM_FALSE;
3662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VOLUME) {
3672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag");
368163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated = LVM_FALSE;
3692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
3702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n");
3712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
372163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext
3742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if((GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated == LVM_FALSE)&&
375163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated == LVM_FALSE)&&
376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated ==LVM_FALSE)&&
377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated==LVM_FALSE))
3782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
379163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
380163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        fclose(pContext->pBundledContext->PcmInPtr);
381163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        fclose(pContext->pBundledContext->PcmOutPtr);
382163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
383c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
384c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LvmSessionsActive--;
385c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectRelease: There are %d LVM sessions remaining\n", LvmSessionsActive);
386c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
387c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        // Clear the SessionIndex
388c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        for(int i=0; i<LVM_MAX_SESSIONS; i++){
389c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(SessionIndex[i] == pContext->pBundledContext->SessionId){
390c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                SessionIndex[i] = -1;
391c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                LOGV("\tEffectRelease: Clearing SessionIndex SessionNo %d for SessionId %d\n",
392c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        i, pContext->pBundledContext->SessionId);
393c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                break;
394c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
395c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
396c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
397163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: All effects are no longer instantiated\n");
398163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBundledEffectsEnabled =LVM_FALSE;
399163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].pBundledContext = LVM_NULL;
400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: Freeing LVM Bundle memory\n");
401163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmEffect_free(pContext);
402c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectRelease: Deleting LVM Bundle context %p\n", pContext->pBundledContext);
403163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        delete pContext->pBundledContext;
404c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = LVM_NULL;
4052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // free the effect context for current effect
4072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    delete pContext;
4082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectRelease end\n");
4102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
4112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectRelease */
4132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init(){
4152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmGlobalBundle_init start");
4162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for(int i=0; i<LVM_MAX_SESSIONS; i++){
4172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBundledEffectsEnabled   = LVM_FALSE;
4182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVolumeInstantiated      = LVM_FALSE;
4192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bEqualizerInstantiated   = LVM_FALSE;
4202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBassInstantiated        = LVM_FALSE;
4212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE;
4222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].pBundledContext          = LVM_NULL;
423c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
424c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        SessionIndex[i] = -1;
4252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
4272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
4282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_init()
4302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Initialize engine with default configuration, creates instance
4322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// with all effects disabled.
4332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
4352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
4362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
4382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_init(EffectContext *pContext){
4422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status;
4432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init start");
4452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
446163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
447163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.channels                      = CHANNEL_STEREO;
448163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.format                        = SAMPLE_FORMAT_PCM_S15;
449163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
450163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
451163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
452163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
453163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
454163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
455163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.channels                     = CHANNEL_STEREO;
456163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.format                       = SAMPLE_FORMAT_PCM_S15;
457163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
458163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
459163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
460163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
461163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
4622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
4642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext->pBundledContext->hInstance != NULL){
4662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
4672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Calling pContext->pBassBoost->free()");
4682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmEffect_free(pContext);
4702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
4722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Called pContext->pBassBoost->free()");
4732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;          /* Function call status */
4762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                         /* Control Parameters */
4772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_InstParams_t        InstParams;                     /* Instance parameters */
4782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_EQNB_BandDef_t      BandDefs[MAX_NUM_BANDS];        /* Equaliser band definitions */
4792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomParams_t    HeadroomParams;                 /* Headroom parameters */
4802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomBandDef_t   HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS];
4812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;                         /* Memory allocation table */
4822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    bool                    bMallocFailure = LVM_FALSE;
4832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the capabilities */
485163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    InstParams.BufferMode       = LVM_UNMANAGED_BUFFERS;
4862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.MaxBlockSize     = MAX_CALL_SIZE;
4872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.EQNB_NumBands    = MAX_NUM_BANDS;
4882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.PSA_Included     = LVM_PSA_ON;
4892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory, forcing alignment */
4912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(LVM_NULL,
4922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &MemTab,
4932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &InstParams);
4942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init")
4962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
4972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
4992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory */
5012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
5032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
5042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes for region %u\n",
5072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i );
5082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                bMallocFailure = LVM_TRUE;
5092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmBundle_init CreateInstance allocated %ld bytes for region %u at %p\n",
5112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
5172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     * succesfully allocated and return with an error
5182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     */
5192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(bMallocFailure == LVM_TRUE){
5202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
522163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes for region %u - +"
523163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "Not freeing\n", MemTab.Region[i].Size, i );
5242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
525163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %ld bytes "
526163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "for region %u at %p- free\n",
527163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
5292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
5322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
533163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n");
5342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Initialise */
536163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->hInstance = LVM_NULL;
5372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Init sets the instance handle */
539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,
5402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &MemTab,
5412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &InstParams);
5422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init")
5442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
546163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
5472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the initial process parameters */
5492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* General parameters */
5502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.OperatingMode          = LVM_MODE_ON;
5512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SampleRate             = LVM_FS_44100;
5522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SourceFormat           = LVM_STEREO;
5532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SpeakerType            = LVM_HEADPHONES;
5542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->SampleRate = LVM_FS_44100;
556c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->pBundledContext->SamplesToExitCountEq   = 44100*2*2; // 2 secs Stereo
557c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->pBundledContext->SamplesToExitCountBb   = 44100*2*2; // 2 secs Stereo
558c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->pBundledContext->SamplesToExitCountVirt = 44100*2*2; // 2 secs Stereo
559163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
5602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Concert Sound parameters */
5612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerOperatingMode   = LVM_MODE_OFF;
5622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerType            = LVM_CONCERTSOUND;
5632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerReverbLevel     = 100;
5642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.CS_EffectLevel             = LVM_CS_EFFECT_HIGH;
5652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* N-Band Equaliser parameters */
5672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_OperatingMode     = LVM_EQNB_OFF;
5682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_NBands            = FIVEBAND_NUMBANDS;
5692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.pEQNB_BandDefinition   = &BandDefs[0];
570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
5712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
5722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
5732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i];
5742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].QFactor   = EQNB_5BandPresetsQFactors[i];
575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        BandDefs[i].Gain      = EQNB_5BandSoftPresets[i];
5762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume Control parameters */
5792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_EffectLevel         = 0;
5802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_Balance             = 0;
5812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Treble Enhancement parameters */
5832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
5842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_EffectLevel         = 0;
5852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
5872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
5882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = (LVM_PSA_DecaySpeed_en)0;
5892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
5912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_OperatingMode       = LVM_BE_OFF;
5922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_EffectLevel         = 0;
5932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_CentreFreq          = LVM_BE_CENTRE_90Hz;
5942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_HPF                 = LVM_BE_HPF_ON;
5952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
5972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
5982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = LVM_PSA_SPEED_MEDIUM;
5992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance,
6022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &params);
6032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init")
6052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
607163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n");
6082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the headroom parameters */
6102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_Low          = 20;
6112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_High         = 4999;
6122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Headroom_Offset    = 3;
6132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_Low          = 5000;
6142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_High         = 24000;
6152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Headroom_Offset    = 4;
6162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.pHeadroomDefinition    = &HeadroomBandDef[0];
6172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
6182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.NHeadroomBands         = 2;
6192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance,
6212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &HeadroomParams);
6222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init")
6242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
626163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n");
6272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init End");
6282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
6292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end LvmBundle_init */
6302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_process()
6332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
6352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply LVM Bundle effects
6362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
6382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pIn:        pointer to stereo 16 bit input data
6392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to stereo 16 bit output data
6402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  frameCount: Frames to process
6412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
6422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
6432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Outputs:
6452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to updated stereo 16 bit output data
6462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_process(LVM_INT16        *pIn,
650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      LVM_INT16        *pOut,
651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      int              frameCount,
652163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      EffectContext    *pContext){
6532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
6552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
6562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               *pOutTmp;
658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){
659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = pOut;
660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
661163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2);
662163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(pOutTmp == NULL){
663163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process failed to allocate memory for "
664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            "EFFECT_BUFFER_ACCESS_ACCUMULATE mode");
665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("LVM_ERROR : LvmBundle_process invalid access mode");
669163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
670163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
6712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
6742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
6752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmBundle_process")
6772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->frameCount++;
680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->frameCount == 100)
681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
682163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tBB: %d VIRT: %d EQ: %d, session (%d), context is %p\n",
683163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //ActiveParams.BE_OperatingMode,
684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //ActiveParams.VirtualizerOperatingMode, ActiveParams.EQNB_OperatingMode,
685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->SessionNo, pContext->pBundledContext);
686163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->frameCount = 0;
687163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
688163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
689163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
690163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pIn, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmInPtr);
691163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmInPtr);
692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
694163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Process the samples */
6952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */
6962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pIn,                                  /* Input buffer */
6972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pOutTmp,                              /* Output buffer */
6982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            (LVM_UINT16)frameCount,               /* Number of samples to read */
6992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            0);                                   /* Audo Time */
700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process")
7022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
7032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
704163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
705163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pOutTmp, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmOutPtr);
706163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmOutPtr);
707163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
709163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
710163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        for (int i=0; i<frameCount*2; i++){
711163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            pOut[i] +=  pOutTmp[i];
712163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
713163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        free(pOutTmp);
714163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmBundle_process */
7172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_enable()
7202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Enable the effect in the bundle
7222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_enable(EffectContext *pContext){
731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable start");
732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
7352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
737163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable")
7412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
742163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n");
7432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
745163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST");
7462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_ON;
7472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
749163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER");
7502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_ON;
7512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
753163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER");
7542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_ON;
7552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
757163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VOLUME");
758163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
759163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
7612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable")
7622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
763163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
764163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n");
765163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable end");
7662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
7682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_disable()
7712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Disable the effect in the bundle
7732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_disable(EffectContext *pContext){
782163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable start");
783163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
786163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
787163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable")
7912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
792163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n");
7932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
795163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST");
7962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_OFF;
7972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
799163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_VIRTUALIZER");
8002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_OFF;
8012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
803163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_EQUALIZER");
8042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_OFF;
8052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
807163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_VOLUME");
808163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
809163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable")
8122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
813163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
814163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n");
815163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable end");
8162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_free()
8212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Free all memory associated with the Bundle.
8232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free(EffectContext *pContext){
8322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;         /* Function call status */
8332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                        /* Control Parameters */
8342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;
8352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Free the algorithm memory */
8372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance,
8382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   &MemTab,
8392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   LVM_NULL);
8402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free")
8422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
8442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
8452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress != NULL){
846163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - START freeing %ld bytes for region %u at %p\n",
8472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
8502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
851163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - END   freeing %ld bytes for region %u at %p\n",
8522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
854163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR : LvmEffect_free - trying to free with NULL pointer %ld bytes "
8552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "for region %u at %p ERROR\n",
8562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
8582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
8592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmEffect_free */
8612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Effect_configure()
8642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Set input and output audio configuration.
8662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
8702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//      configuration parameters
8712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Effect_configure(EffectContext *pContext, effect_config_t *pConfig){
877163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_Fs_en   SampleRate;
878163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure start");
8792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
8812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig != NULL);
8822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
8842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels);
8852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
8862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == CHANNEL_STEREO);
8872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
8882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
8892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15);
8902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    memcpy(&pContext->config, pConfig, sizeof(effect_config_t));
8922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
893163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    switch (pConfig->inputCfg.samplingRate) {
894163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 8000:
895163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_8000;
896c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 8000*2; // 2 secs Stereo
897163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
898163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 16000:
899163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_16000;
900c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 16000*2; // 2 secs Stereo
901163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
902163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 22050:
903163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_22050;
904c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 22050*2; // 2 secs Stereo
905163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
906163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 32000:
907163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_32000;
908c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 32000*2; // 2 secs Stereo
909163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
910163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 44100:
911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_44100;
912c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 44100*2; // 2 secs Stereo
913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
914163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 48000:
915163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_48000;
916c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 48000*2; // 2 secs Stereo
917163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
918163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    default:
919163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_Configure invalid sampling rate %d", pConfig->inputCfg.samplingRate);
920163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
921163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->SampleRate != SampleRate){
9242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
925163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ControlParams_t     ActiveParams;
926163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;
9272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
928163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure change sampling rate to %d", SampleRate);
9292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
930163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
931163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
932163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
9332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
934163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_configure")
935163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
937163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
939163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_configure")
940163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure Succesfully called LVM_SetControlParameters\n");
941c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SampleRate = SampleRate;
9422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
943163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_configure keep sampling rate at %d", SampleRate);
945163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure End....");
948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}   /* end Effect_configure */
9502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassGetStrength()
9532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
9552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
9562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
9572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the
9582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
9592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t BassGetStrength(EffectContext *pContext){
966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved);
9672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
9692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
970163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
971163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
9722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
9732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength")
9752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
977163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n");
9782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Check that the strength returned matches the strength that was set earlier */
980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(ActiveParams.BE_EffectLevel !=
981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){
9822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n",
9832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved);
9842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
9852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
9862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
987163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
988163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (saved)  -> %d\n", pContext->pBundledContext->BassStrengthSaved );
9892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return pContext->pBundledContext->BassStrengthSaved;
9902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassGetStrength */
9912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassSetStrength()
9942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
9962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15
9972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid BassSetStrength(EffectContext *pContext, uint32_t strength){
1005163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength(%d)", strength);
10062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->BassStrengthSaved = (int)strength;
10082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength")
1017163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n");
10182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
10202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_EffectLevel    = (LVM_INT16)((15*strength)/1000);
10212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_CentreFreq     = LVM_BE_CENTRE_90Hz;
10222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1023163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength")
1029163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n");
10302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassSetStrength */
10312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerGetStrength()
10342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
10372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
1038163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the
10392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
10402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t VirtualizerGetStrength(EffectContext *pContext){
1047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved);
10482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
10502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
10512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength")
10552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
10562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1057163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n");
1058163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength() (0-100)   -> %d\n", ActiveParams.VirtualizerReverbLevel*10);
10592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return ActiveParams.VirtualizerReverbLevel*10;
10602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getStrength */
10612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerSetStrength()
10642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15
10672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
1075163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength(%d)", strength);
10762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1079163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->VirtStrengthSaved = (int)strength;
1080163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
10812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
10832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength")
1085163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n");
10862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Virtualizer parameters */
10882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.VirtualizerReverbLevel    = (LVM_INT16)(strength/10);
10892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1090163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength() (0-1000)   -> %d\n", strength );
1091163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength() (0- 100)   -> %d\n", ActiveParams.VirtualizerReverbLevel );
10922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength")
1096163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n");
10972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setStrength */
10982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandLevel()
11012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the gain currently being used for the band passed in
11032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
11122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1113163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Gain =0;
1114163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1115163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1116163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1117163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1118163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1119163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
11202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1121163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel")
11222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1123163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1124163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Gain    = (int32_t)BandDef[band].Gain*100;    // Convert to millibels
11252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1126163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel -> %d\n", Gain );
1127163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1128163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Gain;
11292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetBandLevel()
11332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Sets gain value for the given band.
11362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Gain:       Gain to be applied in millibels
11402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//---------------------------------------------------------------------------
11452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetBandLevel(EffectContext *pContext, int band, int Gain){
1146163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int gainRounded;
1147163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(Gain > 0){
1148163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain+50)/100);
1149163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1150163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain-50)/100);
1151163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1152163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);
1153163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1154163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
11552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1157163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
11582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1161163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetBandLevel")
1162163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel just Got -> %d\n", ActiveParams.pEQNB_BandDefinition[band].Gain);
11642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set local EQ parameters */
1166163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    ActiveParams.pEQNB_BandDefinition[band].Gain = gainRounded;
11682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1171163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetBandLevel")
1172163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel just Set -> %d\n", ActiveParams.pEQNB_BandDefinition[band].Gain);
11732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
11752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
11762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetCentreFrequency()
11792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the frequency being used for the band passed in
11812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){
1190163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Frequency =0;
11912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1192163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1193163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1194163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1195163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1196163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1197163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
11982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1199163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency")
12002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1201163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef   = ActiveParams.pEQNB_BandDefinition;
1202163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Frequency = (int32_t)BandDef[band].Frequency*1000;     // Convert to millibels
12032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1204163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency );
1205163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n");
1206163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Frequency;
12072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandFreqRange(
12112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets lower and upper boundaries of a band.
12152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the high shelf, the low bound is the band frequency and the high
12162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// bound is Nyquist.
12172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the peaking filters, they are the gain[dB]/2 points.
12182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
12212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
12222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
12252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
12262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1227163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow,
1228163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                  uint32_t *pHi){
1229163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pLow = bandFreqRange[band][0];
1230163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pHi  = bandFreqRange[band][1];
1231163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
12322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBand(
12362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Returns the band with the maximum influence on a given frequency.
12402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Result is unaffected by whether EQ is enabled or not, or by whether
12412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// changes have been committed or not.
12422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  targetFreq   The target frequency, in millihertz.
12452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
12492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
12502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){
12522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int band = 0;
12532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1254163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(targetFreq < bandFreqRange[0][0]){
1255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
1256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if(targetFreq == bandFreqRange[0][0]){
1257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
1258163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1259163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for(int i=0; i<FIVEBAND_NUMBANDS;i++){
1260163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){
1261163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            band = i;
1262163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1263163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
12642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return band;
12652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPreset(
12692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets the currently set preset ID.
12732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Will return PRESET_CUSTOM in case the EQ parameters have been modified
12742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// manually since a preset was set.
12752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetPreset(EffectContext *pContext){
1281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return pContext->pBundledContext->CurPreset;
12822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetPreset(
12862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Sets the current preset by ID.
12902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// All the band parameters will be overridden.
12912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  preset       The preset ID.
12952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetPreset(EffectContext *pContext, int preset){
12982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1299163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset(%d)", preset);
13002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = preset;
13012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1307163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetPreset")
1308163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully returned from LVM_GetControlParameters\n");
13092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    //ActiveParams.pEQNB_BandDefinition = &BandDefs[0];
13112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
13122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
1313163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
1314163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
1315163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Gain
1316163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        = EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
13172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
13182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the new settings */
13192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetPreset")
13212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1322163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
13232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
13242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
1325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
13262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetNumPresets(){
1327163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return sizeof(gEqualizerPresets) / sizeof(PresetConfig);
13282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPresetName(
13322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets a human-readable name for a preset ID. Will return "Custom" if
13352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// PRESET_CUSTOM is passed.
13362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// preset       The preset ID. Must be less than number of presets.
13392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//-------------------------------------------------------------------------
13412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst char * EqualizerGetPresetName(int32_t preset){
1342163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName start(%d)", preset);
13432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (preset == PRESET_CUSTOM) {
13442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return "Custom";
13452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
13462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return gEqualizerPresets[preset].name;
13472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1348163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName end(%d)", preset);
1349163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
13502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetVolumeLevel()
13542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  level       level to be applied
13602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
13642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1368163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Level to be set is %d %d\n", level, (LVM_INT16)(level/100));
13692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
13722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1373163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully returned from LVM_GetControlParameters got: %d\n",
1374163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //ActiveParams.VC_EffectLevel);
13752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume parameters */
13772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.VC_EffectLevel  = (LVM_INT16)(level/100);
1378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel() (-96dB -> 0dB)   -> %d\n", ActiveParams.VC_EffectLevel );
13792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
13812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetVolumeLevel")
13832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
13842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1385163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully called LVM_SetControlParameters\n");
1386163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1387163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1388163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1389163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
1390163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1391163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1392163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel just set (-96dB -> 0dB)   -> %d\n", ActiveParams.VC_EffectLevel );
13932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
13942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setVolumeLevel */
13952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeGetVolumeLevel()
13982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){
14072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1408163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel start");
1409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
14102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
14112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
14122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetVolumeLevel")
14152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1417163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel );
1418163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel Succesfully returned from LVM_GetControlParameters\n");
14192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *level = ActiveParams.VC_EffectLevel*100;     // Convert dB to millibels
1421163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel end");
14222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end VolumeGetVolumeLevel */
14242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetMute()
14272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
14332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){
1437163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute start(%d)", mute);
14382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->bMuteEnabled = mute;
14402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
14422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
14432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
14452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetMute")
14472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1449163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully returned from LVM_GetControlParameters\n");
1450163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute to %d, level was %d\n", mute, ActiveParams.VC_EffectLevel );
14512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set appropriate volume level */
14532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){
1454163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved = ActiveParams.VC_EffectLevel;
1455163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel           = -96;
14562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1457163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel  = pContext->pBundledContext->levelSaved;
14582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
14592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
14612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetMute")
14632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1465163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully called LVM_SetControlParameters\n");
1466163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute end");
14672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setMute */
14692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1471163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetMute()
14722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Ourputs:
14792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
14802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){
1483163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute start");
1484163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||
1485163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){
1486163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        *mute = pContext->pBundledContext->bMuteEnabled;
1487163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
14882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1489163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d",
1490163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent              pContext->pBundledContext->bMuteEnabled);
1491163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
14922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1493163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute end");
14942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getMute */
14952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1496163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint16_t VolumeConvertStereoPosition(int16_t position){
1497163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t convertedPosition = 0;
1498163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1499163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    convertedPosition = (int16_t)(((float)position/1000)*96);
1500163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return convertedPosition;
1501163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1502163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
1503163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1504163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeSetStereoPosition()
1506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1511163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1512163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1514163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1516163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint VolumeSetStereoPosition(EffectContext *pContext, int16_t position){
1517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1518163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1519163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1520163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               Balance = 0;
1521163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1522c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1523163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1524163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->positionSaved = position;
1525163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1526163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1527163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d", pContext->pBundledContext->positionSaved);
1528163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1529163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1530163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1531163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance);
1532163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved = position;
1533163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1534163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1535163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1536163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1537163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:"
1538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     " %d\n", ActiveParams.VC_Balance);
1539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1540163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Volume parameters */
1541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  = Balance;
1542163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB)   -> %d\n", ActiveParams.VC_Balance );
1543163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1544163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Activate the initial settings */
1545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1546163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
1547163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1548163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n");
15502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1552163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1553163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1554163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: "
1556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     "%d\n", ActiveParams.VC_Balance);
1557163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1558163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    else{
1559163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n",
1560163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //position, Balance);
1561163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1562163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n", pContext->pBundledContext->positionSaved);
1563163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1564163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeSetStereoPosition */
15652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1568163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetStereoPosition()
1569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1572163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1573163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1576163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
15782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){
1580163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition start");
15812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1584163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               balance;
1585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1586163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d", pContext->pBundledContext->positionSaved);
1587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
1590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1591163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1592163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance);
1593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1596163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1598163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(balance != ActiveParams.VC_Balance){
1599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
1600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1602163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *position = (LVM_INT16)pContext->pBundledContext->positionSaved;     // Convert dB to millibels
1603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved = %d\n", pContext->pBundledContext->positionSaved);
1604163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeGetStereoPosition */
16062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1607163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeEnableStereoPosition()
1609163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1613163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:   effect engine context
1614163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  mute:       enable/disable flag
1615163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
16172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){
1619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition start()");
16202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->bStereoPositionEnabled = enabled;
16222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1624163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
16252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1626163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1627163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition")
1629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1631163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition to %d, position was %d\n",
1633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //     enabled, ActiveParams.VC_Balance );
16342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Set appropriate stereo position */
1636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){
1637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance = 0;
1638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  =
1640163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                            VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
16422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
1644163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1645163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition")
1646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1648163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n");
1649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition end()\n");
1650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeEnableStereoPosition */
16522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_getParameter()
16552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
16572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a BassBoost parameter
16582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
16612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
16622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
16632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
16642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
16662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
16672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
16682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
16712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_getParameter(EffectContext     *pContext,
1675c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
1676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           size_t            *pValueSize,
1677163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           void              *pValue){
16782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1679c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1680c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
16812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
16822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
16832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter start");
16852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
168723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
16887fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
16897fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize %d", *pValueSize);
16907fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
16917fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
16927fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
16937fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
16942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
16952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
16967fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize %d", *pValueSize);
16972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
16982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
16992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
17002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1703163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
17052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
170823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
17102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
171123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d",
1712163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
17132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = BassGetStrength(pContext);
17172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d",
1719163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
17202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
17252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1728163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter end");
17292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_getParameter */
17312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_setParameter()
17342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a BassBoost parameter
17372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
17402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
17422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1747c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue){
17482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
17492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1750c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
17512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter start");
17532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1754c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (*pParamTemp){
17552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1757163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength);
1758163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength");
17592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            BassSetStrength(pContext, (int32_t)strength);
1760163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength");
17612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
17622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1763c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParamTemp);
17642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1767163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter end");
17682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_setParameter */
17702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_getParameter()
17732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Virtualizer parameter
17762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
17792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
17812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
17822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
17852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
17862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
17892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_getParameter(EffectContext        *pContext,
1793c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void                 *pParam,
17942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             size_t               *pValueSize,
17952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             void                 *pValue){
17962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1797c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1798c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
17992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
18002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
18012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1802163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter start");
18032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
180523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18067fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
18077fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
18087fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
18097fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
18107fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
18117fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
18127fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent
18132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
18157fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
18162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
18172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
18182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
18192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
18232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
18242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
182723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
18292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
183023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d",
1831163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
18322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = VirtualizerGetStrength(pContext);
18362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1837163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d",
1838163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
18392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
18432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
18442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1847163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter end");
18482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_getParameter */
18502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_setParameter()
18532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Virtualizer parameter
18562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
18592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
18612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1866c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
18672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
18682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1869c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1870c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
18712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1872163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter start");
18732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1874c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
18752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1877163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength);
1878163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength");
18792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            VirtualizerSetStrength(pContext, (int32_t)strength);
1880163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength");
18812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
18822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1883c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", param);
18842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1887163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter end");
18882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_setParameter */
18902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_getParameter()
18932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Equalizer parameter
18962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer       - handle to instance data
18992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
19012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
19022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
19052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
19062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
19092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_getParameter(EffectContext     *pContext,
1912c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
19132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           size_t            *pValueSize,
19142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           void              *pValue){
19152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
19162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
1917c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1918c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
19192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
19202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
19212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1922163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_getParameter start");
19232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
19252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
19262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
19272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
19283be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_BAND_LEVEL:
19293be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_GET_BAND:
19302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int16_t)) {
1931163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
19322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int16_t);
19352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
19383be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (*pValueSize < 2 * sizeof(int16_t)) {
19393be9523784cc4038f601e510faee595117cdacb3Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
19403be9523784cc4038f601e510faee595117cdacb3Eric Laurent            return -EINVAL;
19413be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
19423be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *pValueSize = 2 * sizeof(int16_t);
19433be9523784cc4038f601e510faee595117cdacb3Eric Laurent        break;
19443be9523784cc4038f601e510faee595117cdacb3Eric Laurent
19452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
19462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < 2 * sizeof(int32_t)) {
1947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
19482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = 2 * sizeof(int32_t);
19512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19523be9523784cc4038f601e510faee595117cdacb3Eric Laurent
19532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
19542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int32_t)) {
1955163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
19562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int32_t);
19592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
19622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
196423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES:
196523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) {
196623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
196723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            return -EINVAL;
196823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
196923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t);
197023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        break;
197123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
19722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
1973163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param);
19742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
19752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
19782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
19793be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS;
1980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue);
19812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
19843be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = -1500;
19853be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *((int16_t *)pValue + 1) = 1500;
1986163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d",
1987163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      *(int32_t *)pValue, *((int32_t *)pValue + 1));
19882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
1991c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
19922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
19932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
19942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19963be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2);
1997163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d",
1998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
19992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
2002c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2);
2008163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d",
2009163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
2013c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1));
2019163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d",
2020163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue, *((int32_t *)pValue + 1));
20212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_BAND:
2024c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20253be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2);
2026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d",
2027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
20313be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext);
2032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue);
20332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
20363be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets();
2037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue);
20382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
2041c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= EqualizerGetNumPresets()) {
20432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        //if (param2 >= 20) {     // AGO FIX
20442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name = (char *)pValue;
20482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1);
20492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name[*pValueSize - 1] = 0;
20502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = strlen(name) + 1;
2051163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d",
2052163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, gEqualizerPresets[param2].name, *pValueSize);
20532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
205523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES: {
20563be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
205723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        LOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES");
20583be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[0] = (int16_t)EqualizerGetPreset(pContext);
20593be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[1] = (int16_t)FIVEBAND_NUMBANDS;
206023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
20613be9523784cc4038f601e510faee595117cdacb3Eric Laurent            p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i);
206223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
206323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    } break;
206423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
20652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
20662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param);
20672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        status = -EINVAL;
20682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2071163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_getParameter end");
20722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
20732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_getParameter */
20742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_setParameter()
20772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
20792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Equalizer parameter
20802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
20822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer    - handle to instance data
20832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
20842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
20852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
20872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
2089c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
20902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
20912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t preset;
20922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t band;
20932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t level;
2094c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2095c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
2096c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
20972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2098163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter start");
20992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
21002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
21013be9523784cc4038f601e510faee595117cdacb3Eric Laurent        preset = (int32_t)(*(uint16_t *)pValue);
21022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2103163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset);
21042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if ((preset >= EqualizerGetNumPresets())||(preset < 0)) {
21052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetPreset(pContext, preset);
21092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2111c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        band =  *pParamTemp;
21123be9523784cc4038f601e510faee595117cdacb3Eric Laurent        level = (int32_t)(*(int16_t *)pValue);
2113163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level);
21142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (band >= FIVEBAND_NUMBANDS) {
21152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetBandLevel(pContext, band, level);
21192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21203be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_PROPERTIES: {
21213be9523784cc4038f601e510faee595117cdacb3Eric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES");
21223be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
21233be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if ((int)p[0] >= EqualizerGetNumPresets()) {
21243be9523784cc4038f601e510faee595117cdacb3Eric Laurent            status = -EINVAL;
21253be9523784cc4038f601e510faee595117cdacb3Eric Laurent            break;
21263be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
21273be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (p[0] >= 0) {
21283be9523784cc4038f601e510faee595117cdacb3Eric Laurent            EqualizerSetPreset(pContext, (int)p[0]);
21293be9523784cc4038f601e510faee595117cdacb3Eric Laurent        } else {
21303be9523784cc4038f601e510faee595117cdacb3Eric Laurent            if ((int)p[1] != FIVEBAND_NUMBANDS) {
21313be9523784cc4038f601e510faee595117cdacb3Eric Laurent                status = -EINVAL;
21323be9523784cc4038f601e510faee595117cdacb3Eric Laurent                break;
21333be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
21343be9523784cc4038f601e510faee595117cdacb3Eric Laurent            for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
21353be9523784cc4038f601e510faee595117cdacb3Eric Laurent                EqualizerSetBandLevel(pContext, i, (int)p[2 + i]);
21363be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
21373be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
21383be9523784cc4038f601e510faee595117cdacb3Eric Laurent    } break;
21392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
21402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : setParameter() invalid param %d", param);
21413be9523784cc4038f601e510faee595117cdacb3Eric Laurent        status = -EINVAL;
21422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2145163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter end");
21462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_setParameter */
21482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_getParameter()
21512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Volume parameter
21542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume          - handle to instance data
21572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
21582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
21592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
21602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
21632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
21642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
21672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_getParameter(EffectContext     *pContext,
2171c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void              *pParam,
21722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        size_t            *pValueSize,
21732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        void              *pValue){
21742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2176c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2177c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;;
21782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
21792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tVolume_getParameter start");
21812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
21832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
21842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
21852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2186163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if (*pValueSize != sizeof(int16_t)){
21872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1  %d", *pValueSize);
21882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
21892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
21902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
21912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
21942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
21952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize < sizeof(int32_t)){
21962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2  %d", *pValueSize);
21972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
21982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
21992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int32_t);
22002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2203163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param);
22042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue));
2210163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d",
2211163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(int16_t *)pValue);
22122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = 0;
22162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d",
22172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    *(int16_t *)pValue);
22182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2221163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            VolumeGetStereoPosition(pContext, (int16_t *)pValue);
22222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d",
22232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    *(int16_t *)pValue);
22242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2227163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeGetMute(pContext, (uint32_t *)pValue);
2228163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d",
2229163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(uint32_t *)pValue);
22302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2233163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled;
22342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d",
22352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    *(uint32_t *)pValue);
22362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
22392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param);
22402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
22412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2244163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_getParameter end");
22452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
22462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_getParameter */
22472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_setParameter()
22512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
22532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Volume parameter
22542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
22562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume       - handle to instance data
22572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
22582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
22592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
22612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2264c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue){
22652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int      status = 0;
22662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t  level;
2267163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t  position;
22682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    uint32_t mute;
2269163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    uint32_t positionEnabled;
2270c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2271c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
22722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tVolume_setParameter start");
22742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2275c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
22762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            level = *(int16_t *)pValue;
22782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level);
22792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel");
22802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeSetVolumeLevel(pContext, (int16_t)level);
22812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel");
22822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2285163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            mute = *(uint32_t *)pValue;
2286163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute);
2287163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Calling pVolume->setMute");
2288163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetMute(pContext, mute);
2289163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Called pVolume->setMute");
2290163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
22912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2293163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            positionEnabled = *(uint32_t *)pValue;
2294163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeEnableStereoPosition(pContext, positionEnabled);
2295163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved);
2296163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called");
2297163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
22982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2300163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            position = *(int16_t *)pValue;
2301163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position);
2302163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition");
2303163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, (int16_t)position);
2304163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition");
2305163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2308c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", param);
23092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2312163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_setParameter end");
23132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_setParameter */
23152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2316163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent/****************************************************************************************
2317163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent * Name : LVC_ToDB_s32Tos16()
2318163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Input       : Signed 32-bit integer
2319163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Output      : Signed 16-bit integer
2320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  MSB (16) = sign bit
2321163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (15->05) = integer part
2322163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (04->01) = decimal part
2323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Returns     : Db value with respect to full scale
2324163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Description :
2325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Remarks     :
2326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent ****************************************************************************************/
2327163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2328163fbcf84010b98e0374110454d85b804bc8d13bEric LaurentLVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix)
2329163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent{
2330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   db_fix;
2331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   Shift;
2332163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   SmallRemainder;
2333163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_UINT32  Remainder = (LVM_UINT32)Lin_fix;
2334163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2335163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Count leading bits, 1 cycle in assembly*/
2336163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for (Shift = 0; Shift<32; Shift++)
2337163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
2338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if ((Remainder & 0x80000000U)!=0)
2339163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2340163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2341163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2342163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        Remainder = Remainder << 1;
2343163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
23442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2345163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /*
2346163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * Based on the approximation equation (for Q11.4 format):
2347163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     *
2348163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2)
2349163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     */
2350163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix    = (LVM_INT16)(-96 * Shift);               /* Six dB steps in Q11.4 format*/
2351163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24);
2352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix + SmallRemainder );
2353163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder);
2354163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9));
23552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2356163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Correct for small offset */
2357163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - 5);
23582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return db_fix;
2360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
23612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2362163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
2363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
23642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Process */
23662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_process(effect_interface_t     self,
2367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *inBuffer,
2368163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *outBuffer){
23692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
2370c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
2371c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
23722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int    status = 0;
2373c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int    status2Sec = 0;
2374163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int    lvmStatus = 0;
2375163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *in  = (LVM_INT16 *)inBuffer->raw;
2376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *out = (LVM_INT16 *)outBuffer->raw;
23772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_process Start : Enabled = %d     Called = %d",
2379163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled);
2380c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LOGV("\tEffect_process Start : Samples left %d %d %d",
2381c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountBb,
2382c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountVirt,
2383c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountEq);
2384c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2385c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
2386c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
2387c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
2388c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    LOGV("\tEffect_process Internal Operating Modes: BB %d   VIRT %d    EQ %d",
2389c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//        ActiveParams.BE_OperatingMode, ActiveParams.VirtualizerOperatingMode,
2390c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//        ActiveParams.EQNB_OperatingMode);
23912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
23932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL");
23942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
23952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
23972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
23982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            inBuffer->frameCount != outBuffer->frameCount){
23992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
24002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
24012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2402163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&
2403163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_BASS_BOOST)){
2404c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_BASS_BOOST Effect is not enabled");
2405c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
2406c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2407c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO
2408c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //LOGV("\tEffect_process: Waiting for 2 secs to turn off BASS_BOOST, %d samples left",
2409c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountBb);
2410c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2411163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2412c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
2413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2414163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&
2415163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VOLUME)){
2416c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_VOLUME Effect is not enabled");
2417163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2418163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2419163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&
2420163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_EQUALIZER)){
2421c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_EQUALIZER Effect is not enabled");
2422c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
2423c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2424c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq -= outBuffer->frameCount * 2; // STEREO
2425c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //LOGV("\tEffect_process: Waiting for 2 secs to turn off EQUALIZER, %d samples left",
2426c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountEq);
2427c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2428c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2429c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
24302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2431163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&
2432163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VIRTUALIZER)){
2433c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_VIRTUALIZER Effect is not enabled");
2434c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
2435c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status2Sec = -ENODATA;
2436c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt -= outBuffer->frameCount * 2;// STEREO
2437c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //LOGV("\tEffect_process: Waiting for 2 secs to turn off VIRTUALIZER, %d samples left",
2438c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountVirt);
2439c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } else {
2440c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2441c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
24422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2443163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2444163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // If this is the last frame of an effect process its output with no effect
2445163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(status == -ENODATA){
2446163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
2447163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() accumulating last frame into output buffer");
2448163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() trying copying last frame into output buffer");
2449163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Enabled = %d     Called = %d",
2450163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->NumberEffectsEnabled,
2451163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->NumberEffectsCalled);
2452163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2453163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }else{
2454163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() copying last frame into output buffer");
2455163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
24562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2457163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2458c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if((status2Sec != -ENODATA)&&(status != -ENODATA)){
2459163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled++;
24602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
24612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2462163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->NumberEffectsCalled ==
2463163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       pContext->pBundledContext->NumberEffectsEnabled){
2464163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Calling process with %d effects enabled, %d called: Effect %d",
2465163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2466163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
24672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2468163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(status == -ENODATA){
2469163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() actually processing last frame");
2470163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
24712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext->NumberEffectsCalled = 0;
2472163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Process all the available frames, block processing is
2473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           handled internalLY by the LVM bundle */
2474163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        lvmStatus = android::LvmBundle_process(    (LVM_INT16 *)inBuffer->raw,
24752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                (LVM_INT16 *)outBuffer->raw,
24762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                outBuffer->frameCount,
24772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                pContext);
2478163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(lvmStatus != LVM_SUCCESS){
2479163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
2480163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return lvmStatus;
2481163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
24822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
2483163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
2484163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2485163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
2486163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        // 2 is for stereo input
2487163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
24882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2489163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
24902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
24912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end Effect_process */
24922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Command */
24942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_command(effect_interface_t  self,
249525f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdCode,
249625f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdSize,
2497163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pCmdData,
249825f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            *replySize,
2499163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pReplyData){
25002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
25012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int retsize;
25022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2503163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\t\nEffect_command start");
25042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST){
2506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_BASS_BOOST");
25072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
25082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER){
2509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VIRTUALIZER");
2510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER){
2512163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_EQUALIZER");
2513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME){
2515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VOLUME");
2516163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
25172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
25192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL");
25202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
25212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
25222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2523163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
25242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2525163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // Incase we disable an effect, next time process is
2526163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // called the number of effect called could be greater
2527163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // pContext->pBundledContext->NumberEffectsCalled = 0;
25282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2529163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d",
2530163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsCalled,
2531163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsEnabled);
25322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (cmdCode){
25342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_INIT:
2535010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
2536010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                LOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d",
2537010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                        pContext->EffectType);
2538010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                return -EINVAL;
2539010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            }
2540010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            *(int *) pReplyData = 0;
2541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start");
25422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2543163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST");
25442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                android::BassSetStrength(pContext, 0);
25452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
25462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2547163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER");
2548163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::VirtualizerSetStrength(pContext, 0);
2549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER");
2552163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::EqualizerSetPreset(pContext, 0);
2553163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: "
2556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_INIT start");
2557010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0);
2558163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
25592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2560163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_CONFIGURE:
2562163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE start");
25632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pCmdData    == NULL||
25642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                cmdSize     != sizeof(effect_config_t)||
25652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                pReplyData  == NULL||
25662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize  != sizeof(int)){
25672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
25682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_CONFIGURE: ERROR");
25692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
25702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
25712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *) pReplyData = android::Effect_configure(pContext, (effect_config_t *) pCmdData);
2572163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE end");
25732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_RESET:
2576163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start");
25772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            android::Effect_configure(pContext, &pContext->config);
2578163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end");
25792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_GET_PARAM:{
2582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2586163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
25892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
25902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
25912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
25922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
25932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
25942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
25962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
25982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
26002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::BassBoost_getParameter(pContext,
2602c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
26032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            (size_t  *)&p->vsize,
26042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            p->data + voffset);
26052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
26072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM "
2609163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
26132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
2614163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
26202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
26212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
26222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
26252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
26272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
26292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
26312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Virtualizer_getParameter(pContext,
2633c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                             (void *)p->data,
26342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                             (size_t  *)&p->vsize,
26352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                              p->data + voffset);
26362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
26382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM "
2640163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
26442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
26452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command cmdCode Case: "
2647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2648163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL ||
2651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) {
26522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
26532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM");
26542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
2657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
2659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
2661163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
2663163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2664c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                p->status = android::Equalizer_getParameter(pContext,
2665c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
2666c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            &p->vsize,
2667c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data + voffset);
2668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
2670163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, "
2672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //       "*pReplyData %08x %08x",
2673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize,
2674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset),
2675163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset +
2676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        sizeof(int32_t)));
26772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
26782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command cmdCode Case: "
2680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2682163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2683163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
26852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
26862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
26872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
26902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
26922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
26942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
26962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Volume_getParameter(pContext,
2698c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                         (void *)p->data,
26992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         (size_t  *)&p->vsize,
27002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         p->data + voffset);
27012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
27032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2704163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_GET_PARAM "
2705163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2706163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2707163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
2709163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2710163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end");
27112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
27122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_PARAM:{
2713163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
27142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2715163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2716163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2717163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2719163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2720163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2721163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2722163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
27242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
27262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
27292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
27312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
27332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnBassBoost_command cmdSize is %d\n"
2737163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2738163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2739163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2740163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2741163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
27422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::BassBoost_setParameter(pContext,
2744c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
27452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    p->data + p->psize);
27462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2748163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2749163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2750163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2751163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2753163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2754163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2755163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
27572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
27582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
27592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
27622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
27642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
27652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
27662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2769163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnVirtualizer_command cmdSize is %d\n"
2770163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2771163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2772163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2773163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2774163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
27752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Virtualizer_setParameter(pContext,
2777c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                      (void *)p->data,
2778163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                       p->data + p->psize);
27792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2781163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command cmdCode Case: "
2782163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_SET_PARAM start");
2783163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2784163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2785163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2786163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
27872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
27892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pReplyData == NULL || *replySize != sizeof(int32_t)) {
27902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
27912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
27922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
27952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Equalizer_setParameter(pContext,
2797c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
2798163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                     p->data + p->psize);
27992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2801163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command cmdCode Case: "
2802163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_SET_PARAM start");
2803163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2804163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2805163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2806163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
28072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (    pCmdData   == NULL||
28092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        cmdSize    < (int)(sizeof(effect_param_t) + sizeof(int32_t))||
28102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        pReplyData == NULL||
28112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        *replySize != sizeof(int32_t)){
28122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
28132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
28142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
28172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Volume_setParameter(pContext,
2819c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                 (void *)p->data,
2820163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                 p->data + p->psize);
2821163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2822163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end");
28232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
28242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_ENABLE:
2826c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start");
28272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
28282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
28292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
2830163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
28312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            switch (pContext->EffectType){
28322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_BASS_BOOST:
28332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
28342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
28352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bBassEnabled = LVM_TRUE;
2839163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_BASS_BOOST enabled");
28402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
28412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_EQUALIZER:
28422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE){
28432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
28442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE;
2848163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_EQUALIZER enabled");
2849163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
28502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VIRTUALIZER:
28512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
28522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
28532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE;
2857163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case:EFFECT_CMD_ENABLE LVM_VIRTUALIZER enabled");
2858163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
28592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VOLUME:
28602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){
28612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
28622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
28632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVolumeEnabled = LVM_TRUE;
2866163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_VOLUME enabled");
28672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
28682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                default:
28692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
28702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_ENABLE: ERROR, invalid Effect Type");
2871163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    return -EINVAL;
28722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *)pReplyData = 0;
28742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            pContext->pBundledContext->NumberEffectsEnabled++;
2875163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::LvmEffect_enable(pContext);
2876c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq =
2877c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*1); // 0.1 secs Stereo
2878c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb =
2879c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*6); // 2 secs Stereo
2880c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt =
2881c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                 (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*1); // 2 secs Stereo
2882c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE Samples to Exit = %d",
2883c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pContext->pBundledContext->SamplesToExitCountBb);
2884163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE NumberEffectsEnabled = %d",
2885163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        pContext->pBundledContext->NumberEffectsEnabled);
2886163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE end");
28872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2888163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_DISABLE:
2890163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start");
28912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
28922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
28932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
2894163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
28952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            switch (pContext->EffectType){
28962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_BASS_BOOST:
28972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_FALSE){
28982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
28992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
2902163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pContext->pBundledContext->bBassEnabled      = LVM_FALSE;
2903163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2904163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //       "EFFECT_CMD_DISABLE LVM_BASS_BOOST disabled");
29052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
29062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_EQUALIZER:
29072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE){
29082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
29092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE;
2913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2914163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //       "EFFECT_CMD_DISABLE LVM_EQUALIZER disabled");
2915163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
29162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VIRTUALIZER:
29172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE){
29182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE;
2923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2924163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //     "EFFECT_CMD_DISABLE LVM_VIRTUALIZER disabled");
2925163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
29262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VOLUME:
29272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVolumeEnabled == LVM_FALSE){
29282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
29292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
29302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
29312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
29322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVolumeEnabled = LVM_FALSE;
2933163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_VOLUME disabled");
29342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
29352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                default:
29362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
29372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_DISABLE: ERROR, invalid Effect Type");
2938163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    return -EINVAL;
2939163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *)pReplyData = 0;
29412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
2942163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::LvmEffect_disable(pContext);
2943163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE NumberEffectsEnabled = %d",
2944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        pContext->pBundledContext->NumberEffectsEnabled);
2945163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE end");
29462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
29472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_DEVICE:
2949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start");
2951163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            audio_device_e device = *(audio_device_e *)pCmdData;
2952163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2953163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2954163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
2955163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
2956163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d",
2957163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
2958163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST");
2959163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2960163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device doesnt support bassboost the effect must be temporarily disabled
2961163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
2962163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
2963163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2964163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
2965163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d",
2966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
2967163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
2968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_TRUE;
2969163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2970163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
2971163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d",
2972163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                         *(int32_t *)pCmdData);
2973163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2974163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports bassboost and the effect has been temporarily disabled
2975163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
2976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2977163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassTempDisabled == LVM_TRUE){
2978163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d",
2979163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
2980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
2981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_FALSE;
2982163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2983163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
2984163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2985163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2986163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
2987163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
2988163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d",
2989163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
2990163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER");
2991163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2992163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //If a device doesnt support virtualizer the effect must be temporarily disabled
2993163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
2994163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
2995163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2996163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
2997163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d",
2998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
2999163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3000163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
3001163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3002163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
3003163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d",
3004163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3005163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3006163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports virtualizer and the effect has been temporarily disabled
3007163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3008163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3009163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerTempDisabled == LVM_TRUE){
3010163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d",
3011163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3012163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3013163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
3014163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3015163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3016163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3017163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end");
30182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3019163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
3020163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_VOLUME:
3021163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
3022163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t vol     = *(int32_t *)pCmdData;
3023163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int16_t dB;
3024163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t vol_ret[2] = {1<<24,1<<24}; // Apply no volume
3025163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // if pReplyData is NULL, VOL_CTRL is delegated to another effect
3027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pReplyData == LVM_NULL){
3028163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                break;
3029163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
30302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3031163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(vol==0x1000000){
3032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                vol -= 1;
3033163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3034163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // Convert volume linear (Q8.24) to volume dB (0->-96)
3035163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = android::LVC_ToDB_s32Tos16(vol <<7);
3036163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = (dB +8)>>4;
3037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = (dB <-96) ? -96 : dB ;
3038163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3039163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tSession: %d, VOLUME is %d dB (%d), effect is %d",
3040163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->SessionNo, (int32_t)dB, vol<<7, pContext->EffectType);
3041163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            memcpy(pReplyData, vol_ret, sizeof(int32_t)*2);
3042163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::VolumeSetVolumeLevel(pContext, (int16_t)(dB*100));
3043163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
3044163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent         }
3045163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
3046163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
30472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
30482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
30492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
30502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3051163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command end...\n\n");
30522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
30532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end Effect_command */
30542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for effect
30562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst struct effect_interface_s gLvmEffectInterface = {
30572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_process,
30582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_command
30592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};    /* end gLvmEffectInterface */
30602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3061