EffectBundle.cpp revision d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4
12c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/*
22c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Copyright (C) 2010-2010 NXP Software
32c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Copyright (C) 2009 The Android Open Source Project
42c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
52c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
62c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * you may not use this file except in compliance with the License.
72c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * You may obtain a copy of the License at
82c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
92c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Unless required by applicable law or agreed to in writing, software
122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * See the License for the specific language governing permissions and
152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * limitations under the License.
162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent */
172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LOG_TAG "Bundle"
192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
2097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//#define LOG_NDEBUG 0
212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <cutils/log.h>
232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <assert.h>
242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <stdlib.h>
252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <string.h>
262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <new>
272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <EffectBundle.h>
282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for bass boost
312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" const struct effect_interface_s gLvmEffectInterface;
322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_NULLADDRESS){\
352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_ALIGNMENTERROR){\
392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad alignment returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_INVALIDNUMSAMPLES){\
432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_OUTOFRANGE){\
472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "out of range returned by %s in %s\n", callingFunc, calledFunc);\
492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Namespaces
532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace android {
542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace {
552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
56d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent// Flag to allow a one time init of global memory, only happens on first call ever
57d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurentint LvmInitFlag = LVM_FALSE;
58d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric LaurentSessionContext GlobalSessionMemory[LVM_MAX_SESSIONS];
59d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurentint SessionIndex[LVM_MAX_SESSIONS];
60d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent
612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* local functions */
622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define CHECK_ARG(cond) {                     \
632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (!(cond)) {                            \
642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Invalid argument: "#cond);      \
652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;                       \
662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }                                         \
672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW BassBoost UUID
712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gBassBoostDescriptor = {
722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
75163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
76163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
77d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BASS_BOOST_CUP_LOAD_ARM9E,
78d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Dynamic Bass Boost",
802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Virtualizer UUID
842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVirtualizerDescriptor = {
85163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
86163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
88163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
89163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
90d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VIRTUALIZER_CUP_LOAD_ARM9E,
91d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Virtualizer",
932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Equalizer UUID
972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gEqualizerDescriptor = {
982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP
1002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
101163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
102d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        EQUALIZER_CUP_LOAD_ARM9E,
103d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Equalizer",
1052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Volume UUID
1092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVolumeDescriptor = {
1102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
1112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP
1122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
113163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
114d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VOLUME_CUP_LOAD_ARM9E,
115d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Volume",
1172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//--- local function prototypes
1212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init      (void);
1222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmBundle_init            (EffectContext *pContext);
1232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_enable          (EffectContext *pContext);
1242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_disable         (EffectContext *pContext);
1252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free            (EffectContext *pContext);
126163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  Effect_configure          (EffectContext *pContext, effect_config_t *pConfig);
127c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  BassBoost_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
128163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  BassBoost_getParameter    (EffectContext *pContext,
129c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
1312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               void           *pValue);
132c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Virtualizer_setParameter  (EffectContext *pContext, void *pParam, void *pValue);
1332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Virtualizer_getParameter  (EffectContext *pContext,
134c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
136163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                               void           *pValue);
137c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Equalizer_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
1382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Equalizer_getParameter    (EffectContext *pContext,
139c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
142c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Volume_setParameter       (EffectContext *pContext, void *pParam, void *pValue);
1432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Volume_getParameter       (EffectContext *pContext,
144c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
14729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurentint Effect_setEnabled(EffectContext *pContext, bool enabled);
1482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Library Interface Implementation */
1502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){
1512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryNumberEffects start");
1522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pNumEffects = 4;
153163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects);
154163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects end\n");
1552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryNumberEffects */
1572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor){
1592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryEffect start");
1602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect processing index %d", index);
161163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pDescriptor == NULL){
163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer");
1642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
1652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (index > 3){
167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index);
1682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -ENOENT;
1692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(index == LVM_BASS_BOOST){
1712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_BASS_BOOST");
1722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gBassBoostDescriptor,   sizeof(effect_descriptor_t));
1732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else if(index == LVM_VIRTUALIZER){
1742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VIRTUALIZER");
1752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVirtualizerDescriptor, sizeof(effect_descriptor_t));
1762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_EQUALIZER){
1772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_EQUALIZER");
1782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gEqualizerDescriptor,   sizeof(effect_descriptor_t));
1792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_VOLUME){
1802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VOLUME");
1812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVolumeDescriptor, sizeof(effect_descriptor_t));
182163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect end\n");
1842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryEffect */
1862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectCreate(effect_uuid_t       *uuid,
1882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             sessionId,
1892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             ioId,
1902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            effect_interface_t  *pInterface){
191dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    int ret = 0;
192c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int sessionNo;
1932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int i;
194dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    EffectContext *pContext = NULL;
195dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    bool newBundle = false;
196dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    SessionContext *pSessionContext;
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");
202dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
203dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
2042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmInitFlag == LVM_FALSE){
2072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmInitFlag = LVM_TRUE;
2082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Initializing all global memory");
2092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmGlobalBundle_init();
2102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
212c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Find next available sessionNo
213c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for(i=0; i<LVM_MAX_SESSIONS; i++){
214e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        if((SessionIndex[i] == LVM_UNUSED_SESSION)||(SessionIndex[i] == sessionId)){
215c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            sessionNo       = i;
216c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            SessionIndex[i] = sessionId;
217c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffectCreate: Allocating SessionNo %d for SessionId %d\n", sessionNo,sessionId);
218c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
219c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
220c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
221c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
222c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(i==LVM_MAX_SESSIONS){
223c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tLVM_ERROR : Cannot find memory to allocate for current session");
224dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
225dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
226c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
227dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
228dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    pContext = new EffectContext;
229dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // If this is the first create in this session
231c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(GlobalSessionMemory[sessionNo].bBundledEffectsEnabled == LVM_FALSE){
232c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectCreate - This is the first effect in current sessionId %d sessionNo %d",
233c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionId, sessionNo);
234c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
235c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_TRUE;
236c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].pBundledContext        = new BundledEffectContext;
237dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        newBundle = true;
2382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
239c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = GlobalSessionMemory[sessionNo].pBundledContext;
240c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionNo                = sessionNo;
241c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionId                = sessionId;
242163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->hInstance                = NULL;
243163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVolumeEnabled           = LVM_FALSE;
244163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bEqualizerEnabled        = LVM_FALSE;
245163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassEnabled             = LVM_FALSE;
246163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassTempDisabled        = LVM_FALSE;
247163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerEnabled      = LVM_FALSE;
248163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
249163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsEnabled     = 0;
250163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled      = 0;
251d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        pContext->pBundledContext->firstVolume              = LVM_TRUE;
252163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
2548f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        char fileName[256];
2558f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_in.pcm", pContext->pBundledContext);
2568f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmInPtr = fopen(fileName, "w");
2578f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr == NULL) {
2588f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            LOGV("cannot open %s", fileName);
259dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            ret = -EINVAL;
260dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            goto exit;
2618f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
262163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2638f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_out.pcm", pContext->pBundledContext);
2648f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmOutPtr = fopen(fileName, "w");
2658f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr == NULL) {
2668f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            LOGV("cannot open %s", fileName);
2678f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
2688f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent           pContext->pBundledContext->PcmInPtr = NULL;
269dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent           ret = -EINVAL;
270dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent           goto exit;
271163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
272163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
273163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        /* Saved strength is used to return the exact strength that was used in the set to the get
2752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * because we map the original strength range of 0:1000 to 1:15, and this will avoid
2762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * quantisation like effect when returning
2772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         */
278163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->BassStrengthSaved        = 0;
279163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->VirtStrengthSaved        = 0;
280163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->CurPreset                = PRESET_CUSTOM;
281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved               = 0;
282163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bMuteEnabled             = LVM_FALSE;
283163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bStereoPositionEnabled   = LVM_FALSE;
284163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved            = 0;
285dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->workBuffer               = NULL;
286dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->frameCount               = -1;
287dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt   = 0;
288dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb     = 0;
289dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq     = 0;
290163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Calling LvmBundle_init");
2922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ret = LvmBundle_init(pContext);
2932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (ret < 0){
2952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : EffectCreate() Bundle init failed");
296dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            goto exit;
2972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
2982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
300c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectCreate - Assigning memory for previously created effect on sessionNo %d",
301c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionNo);
302c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext =
303c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                GlobalSessionMemory[sessionNo].pBundledContext;
3042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext);
3062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
307dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo];
30829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
3092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Create each Effect
3102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Bass Boost
3122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST");
31329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bBassInstantiated = LVM_TRUE;
314dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb = 0;
315163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
316163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_BASS_BOOST;
3182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Virtualizer
320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER");
32129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVirtualizerInstantiated=LVM_TRUE;
322dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt = 0;
323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VIRTUALIZER;
3262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Equalizer
328163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER");
32929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bEqualizerInstantiated = LVM_TRUE;
330dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq = 0;
331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_EQUALIZER;
3342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Volume
336163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VOLUME");
33729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVolumeInstantiated = LVM_TRUE;
338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VOLUME;
341163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
343163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() invalid UUID");
344dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
345dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
3462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
348dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentexit:
349dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if (ret != 0) {
350dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext != NULL) {
351dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (newBundle) {
352dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_FALSE;
353dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                SessionIndex[sessionNo] = LVM_UNUSED_SESSION;
354dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                delete pContext->pBundledContext;
355dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
356dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            delete pContext;
357dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
358dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        *pInterface = (effect_interface_t)NULL;
359dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    } else {
360dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        *pInterface = (effect_interface_t)pContext;
361dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    }
362163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectCreate end..\n\n");
363dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return ret;
3642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectCreate */
3652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectRelease(effect_interface_t interface){
3672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectRelease start %p", interface);
3682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *)interface;
3692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
370dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    LOGV("\tEffectRelease start interface: %p, context %p", interface, pContext->pBundledContext);
3712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
372163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
3732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
374163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
37629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    SessionContext *pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo];
37729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
3782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Clear the instantiated flag for the effect
379dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // protect agains the case where an effect is un-instantiated without being disabled
3802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
3812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag");
38229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bBassInstantiated = LVM_FALSE;
383dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
384dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
385dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
386dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb = 0;
3872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VIRTUALIZER) {
3882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag");
38929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVirtualizerInstantiated = LVM_FALSE;
390dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
391dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
392dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
393dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt = 0;
3942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_EQUALIZER) {
3952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag");
39629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bEqualizerInstantiated =LVM_FALSE;
397dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
398dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
399dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
400dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq = 0;
4012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VOLUME) {
4022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag");
40329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVolumeInstantiated = LVM_FALSE;
404dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){
405dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
406dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
4072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
4082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n");
4092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
410163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
411dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // Disable effect, in this case ignore errors (return codes)
412dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // if an effect has already been disabled
413dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    Effect_setEnabled(pContext, LVM_FALSE);
414dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
4152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext
41629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    if ((pSessionContext->bBassInstantiated == LVM_FALSE) &&
41729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bVolumeInstantiated == LVM_FALSE) &&
41829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bEqualizerInstantiated ==LVM_FALSE) &&
41929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bVirtualizerInstantiated==LVM_FALSE))
4202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
421163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
4228f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr != NULL) {
4238f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
4248f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmInPtr = NULL;
4258f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
4268f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr != NULL) {
4278f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmOutPtr);
4288f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmOutPtr = NULL;
4298f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
430163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
431c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
432c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
433c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        // Clear the SessionIndex
434c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        for(int i=0; i<LVM_MAX_SESSIONS; i++){
435c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(SessionIndex[i] == pContext->pBundledContext->SessionId){
436e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                SessionIndex[i] = LVM_UNUSED_SESSION;
437c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                LOGV("\tEffectRelease: Clearing SessionIndex SessionNo %d for SessionId %d\n",
438c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        i, pContext->pBundledContext->SessionId);
439c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                break;
440c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
441c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
442c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
443163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: All effects are no longer instantiated\n");
444dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pSessionContext->bBundledEffectsEnabled = LVM_FALSE;
44529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->pBundledContext = LVM_NULL;
446163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: Freeing LVM Bundle memory\n");
447163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmEffect_free(pContext);
448c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LOGV("\tEffectRelease: Deleting LVM Bundle context %p\n", pContext->pBundledContext);
449dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->workBuffer != NULL) {
450dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            free(pContext->pBundledContext->workBuffer);
451dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
452163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        delete pContext->pBundledContext;
453c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = LVM_NULL;
4542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // free the effect context for current effect
4562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    delete pContext;
4572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectRelease end\n");
4592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
4602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectRelease */
4622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init(){
4642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmGlobalBundle_init start");
4652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for(int i=0; i<LVM_MAX_SESSIONS; i++){
4662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBundledEffectsEnabled   = LVM_FALSE;
4672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVolumeInstantiated      = LVM_FALSE;
4682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bEqualizerInstantiated   = LVM_FALSE;
4692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBassInstantiated        = LVM_FALSE;
4702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE;
4712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].pBundledContext          = LVM_NULL;
472c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
473e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        SessionIndex[i] = LVM_UNUSED_SESSION;
4742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
4762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
4772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_init()
4792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Initialize engine with default configuration, creates instance
4812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// with all effects disabled.
4822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
4842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
4852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
4872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_init(EffectContext *pContext){
4912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status;
4922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init start");
4942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
495163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
496163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.channels                      = CHANNEL_STEREO;
497163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.format                        = SAMPLE_FORMAT_PCM_S15;
498163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
499163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
500163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
501163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
502163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
503163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
504163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.channels                     = CHANNEL_STEREO;
505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.format                       = SAMPLE_FORMAT_PCM_S15;
506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
5112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
5132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext->pBundledContext->hInstance != NULL){
5152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
5162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Calling pContext->pBassBoost->free()");
5172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmEffect_free(pContext);
5192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
5212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Called pContext->pBassBoost->free()");
5222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;          /* Function call status */
5252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                         /* Control Parameters */
5262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_InstParams_t        InstParams;                     /* Instance parameters */
5272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_EQNB_BandDef_t      BandDefs[MAX_NUM_BANDS];        /* Equaliser band definitions */
5282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomParams_t    HeadroomParams;                 /* Headroom parameters */
5292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomBandDef_t   HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS];
5302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;                         /* Memory allocation table */
5312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    bool                    bMallocFailure = LVM_FALSE;
5322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the capabilities */
534163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    InstParams.BufferMode       = LVM_UNMANAGED_BUFFERS;
5352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.MaxBlockSize     = MAX_CALL_SIZE;
5362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.EQNB_NumBands    = MAX_NUM_BANDS;
5372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.PSA_Included     = LVM_PSA_ON;
5382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory, forcing alignment */
5402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(LVM_NULL,
5412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &MemTab,
5422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &InstParams);
5432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init")
5452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
5482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory */
5502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
5522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
5532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
555d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
556d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u\n", MemTab.Region[i].Size, i );
5572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                bMallocFailure = LVM_TRUE;
5582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
559163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmBundle_init CreateInstance allocated %ld bytes for region %u at %p\n",
5602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
5662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     * succesfully allocated and return with an error
5672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     */
5682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(bMallocFailure == LVM_TRUE){
5692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
571d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
572d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u Not freeing\n", MemTab.Region[i].Size, i );
5732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %ld bytes "
575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "for region %u at %p- free\n",
576163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
5782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
5812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n");
5832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Initialise */
585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->hInstance = LVM_NULL;
5862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Init sets the instance handle */
588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,
5892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &MemTab,
5902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &InstParams);
5912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init")
5932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
5962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the initial process parameters */
5982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* General parameters */
5992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.OperatingMode          = LVM_MODE_ON;
6002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SampleRate             = LVM_FS_44100;
6012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SourceFormat           = LVM_STEREO;
6022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SpeakerType            = LVM_HEADPHONES;
6032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
604163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->SampleRate = LVM_FS_44100;
605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Concert Sound parameters */
6072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerOperatingMode   = LVM_MODE_OFF;
6082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerType            = LVM_CONCERTSOUND;
6092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerReverbLevel     = 100;
610d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.CS_EffectLevel             = LVM_CS_EFFECT_NONE;
6112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* N-Band Equaliser parameters */
6132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_OperatingMode     = LVM_EQNB_OFF;
6142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_NBands            = FIVEBAND_NUMBANDS;
6152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.pEQNB_BandDefinition   = &BandDefs[0];
616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
6182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
6192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i];
6202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].QFactor   = EQNB_5BandPresetsQFactors[i];
621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        BandDefs[i].Gain      = EQNB_5BandSoftPresets[i];
6222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
6232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume Control parameters */
6252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_EffectLevel         = 0;
6262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_Balance             = 0;
6272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Treble Enhancement parameters */
6292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
6302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_EffectLevel         = 0;
6312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = (LVM_PSA_DecaySpeed_en)0;
6352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
6372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_OperatingMode       = LVM_BE_OFF;
6382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_EffectLevel         = 0;
6392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_CentreFreq          = LVM_BE_CENTRE_90Hz;
6402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_HPF                 = LVM_BE_HPF_ON;
6412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = LVM_PSA_SPEED_MEDIUM;
6452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
646d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    /* TE Control parameters */
647d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
648d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_EffectLevel         = 0;
649d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance,
6522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &params);
6532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init")
6552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n");
6582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the headroom parameters */
6602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_Low          = 20;
6612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_High         = 4999;
6622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Headroom_Offset    = 3;
6632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_Low          = 5000;
6642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_High         = 24000;
6652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Headroom_Offset    = 4;
6662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.pHeadroomDefinition    = &HeadroomBandDef[0];
6672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
6682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.NHeadroomBands         = 2;
6692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance,
6712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &HeadroomParams);
6722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init")
6742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n");
6772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init End");
6782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
6792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end LvmBundle_init */
6802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
681dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
682dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentstatic inline int16_t clamp16(int32_t sample)
683dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent{
684dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if ((sample>>15) ^ (sample>>31))
685dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        sample = 0x7FFF ^ (sample>>31);
686dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return sample;
687dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent}
688dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
6892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_process()
6912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
6932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply LVM Bundle effects
6942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
6962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pIn:        pointer to stereo 16 bit input data
6972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to stereo 16 bit output data
6982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  frameCount: Frames to process
6992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
7012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Outputs:
7032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to updated stereo 16 bit output data
7042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_process(LVM_INT16        *pIn,
708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      LVM_INT16        *pOut,
709163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      int              frameCount,
710163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      EffectContext    *pContext){
7112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
714163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               *pOutTmp;
715dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
716163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){
717163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = pOut;
718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
719dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->frameCount != frameCount) {
720dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (pContext->pBundledContext->workBuffer != NULL) {
721dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                free(pContext->pBundledContext->workBuffer);
722dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
723dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->workBuffer =
724dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2);
725dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->frameCount = frameCount;
726163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
727dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pOutTmp = pContext->pBundledContext->workBuffer;
728163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
729163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("LVM_ERROR : LvmBundle_process invalid access mode");
730163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
733163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
734163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pIn, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmInPtr);
735163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmInPtr);
736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
737163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
738d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("Calling LVM_Process");
739d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
740163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Process the samples */
7412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */
7422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pIn,                                  /* Input buffer */
7432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pOutTmp,                              /* Output buffer */
7442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            (LVM_UINT16)frameCount,               /* Number of samples to read */
7452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            0);                                   /* Audo Time */
746163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process")
7482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
7492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
750163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
751163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pOutTmp, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmOutPtr);
752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmOutPtr);
753163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
754163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
755163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        for (int i=0; i<frameCount*2; i++){
757dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pOut[i] = clamp16((LVM_INT32)pOut[i] + (LVM_INT32)pOutTmp[i]);
758163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
759163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmBundle_process */
7622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_enable()
7652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Enable the effect in the bundle
7672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_enable(EffectContext *pContext){
776163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable start");
777163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
7802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
781163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
782163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable")
7862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
787163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n");
7882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
790163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST");
7912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_ON;
7922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
794163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER");
7952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_ON;
7962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
798163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER");
7992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_ON;
8002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
802163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VOLUME");
803163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
804163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable")
8072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
808163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
809163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n");
810163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable end");
8112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_disable()
8162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Disable the effect in the bundle
8182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_disable(EffectContext *pContext){
827163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable start");
828163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
8302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
831163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
832163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
8332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
8342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable")
8362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
837163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n");
8382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
840163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST");
8412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_OFF;
8422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
844dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        LOGV("\tLvmEffect_disable : Disabling LVM_VIRTUALIZER");
8452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_OFF;
8462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
848dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        LOGV("\tLvmEffect_disable : Disabling LVM_EQUALIZER");
8492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_OFF;
8502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
852dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        LOGV("\tLvmEffect_disable : Disabling LVM_VOLUME");
853163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
854163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable")
8572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
858163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
859163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n");
860163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable end");
8612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_free()
8662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Free all memory associated with the Bundle.
8682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free(EffectContext *pContext){
8772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;         /* Function call status */
8782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                        /* Control Parameters */
8792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;
8802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Free the algorithm memory */
8822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance,
8832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   &MemTab,
8842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   LVM_NULL);
8852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free")
8872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
8892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
8902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress != NULL){
891163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - START freeing %ld bytes for region %u at %p\n",
8922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
8952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
896163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - END   freeing %ld bytes for region %u at %p\n",
8972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
899163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR : LvmEffect_free - trying to free with NULL pointer %ld bytes "
9002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "for region %u at %p ERROR\n",
9012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
9022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
9032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
9042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
9052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmEffect_free */
9062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Effect_configure()
9092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Set input and output audio configuration.
9112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
9152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//      configuration parameters
9162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
9182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Effect_configure(EffectContext *pContext, effect_config_t *pConfig){
922163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_Fs_en   SampleRate;
923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure start");
9242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
9262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig != NULL);
9272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
9292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels);
9302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
9312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == CHANNEL_STEREO);
9322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
9332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
9342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15);
9352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    memcpy(&pContext->config, pConfig, sizeof(effect_config_t));
9372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
938163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    switch (pConfig->inputCfg.samplingRate) {
939163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 8000:
940163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_8000;
941c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 8000*2; // 2 secs Stereo
942163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
943163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 16000:
944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_16000;
945c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 16000*2; // 2 secs Stereo
946163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 22050:
948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_22050;
949c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 22050*2; // 2 secs Stereo
950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
951163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 32000:
952163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_32000;
953c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 32000*2; // 2 secs Stereo
954163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
955163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 44100:
956163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_44100;
957c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 44100*2; // 2 secs Stereo
958163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
959163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 48000:
960163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_48000;
961c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 48000*2; // 2 secs Stereo
962163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
963163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    default:
964163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_Configure invalid sampling rate %d", pConfig->inputCfg.samplingRate);
965163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->SampleRate != SampleRate){
9692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
970163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ControlParams_t     ActiveParams;
971163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;
9722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
973163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure change sampling rate to %d", SampleRate);
9742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
975163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
977163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
9782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
979163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_configure")
980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
982163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
984163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_configure")
985163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure Succesfully called LVM_SetControlParameters\n");
986c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SampleRate = SampleRate;
9872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
988163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
989163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_configure keep sampling rate at %d", SampleRate);
990163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
992163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure End....");
993163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
994163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}   /* end Effect_configure */
9952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassGetStrength()
9982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
10012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
10022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the
10032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
10042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t BassGetStrength(EffectContext *pContext){
1011163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved);
10122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
10142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1015163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1016163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength")
10202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
10212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1022163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n");
10232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Check that the strength returned matches the strength that was set earlier */
1025163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(ActiveParams.BE_EffectLevel !=
1026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){
10272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n",
10282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved);
10292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
10302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
10312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
1033163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (saved)  -> %d\n", pContext->pBundledContext->BassStrengthSaved );
10342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return pContext->pBundledContext->BassStrengthSaved;
10352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassGetStrength */
10362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassSetStrength()
10392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15
10422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid BassSetStrength(EffectContext *pContext, uint32_t strength){
1050163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength(%d)", strength);
10512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->BassStrengthSaved = (int)strength;
10532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength")
1062163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n");
10632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
10652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_EffectLevel    = (LVM_INT16)((15*strength)/1000);
10662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_CentreFreq     = LVM_BE_CENTRE_90Hz;
10672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1068163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength")
1074163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n");
10752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassSetStrength */
10762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerGetStrength()
10792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
10822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
1083163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the
10842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
10852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t VirtualizerGetStrength(EffectContext *pContext){
1092163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved);
10932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
10952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
10962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength")
11002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
11012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1102163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n");
1103163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength() (0-100)   -> %d\n", ActiveParams.VirtualizerReverbLevel*10);
1104d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    return pContext->pBundledContext->VirtStrengthSaved;
11052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getStrength */
11062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerSetStrength()
11092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15
11122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
11162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
1120163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength(%d)", strength);
11212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
11232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1124163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->VirtStrengthSaved = (int)strength;
1125163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
11262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
11282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength")
1130163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n");
11312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Virtualizer parameters */
1133d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    ActiveParams.CS_EffectLevel             = (int)((strength*32767)/1000);
11342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1135163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength() (0-1000)   -> %d\n", strength );
1136d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVirtualizerSetStrength() (0- 100)   -> %d\n", ActiveParams.CS_EffectLevel );
11372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength")
1141d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n\n");
11422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setStrength */
11432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandLevel()
11462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the gain currently being used for the band passed in
11482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
11572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1158163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Gain =0;
1159163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1160163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1161163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1162163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1164163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
11652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1166163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel")
11672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1168163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1169163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Gain    = (int32_t)BandDef[band].Gain*100;    // Convert to millibels
11702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1171163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel -> %d\n", Gain );
1172163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1173163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Gain;
11742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetBandLevel()
11782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Sets gain value for the given band.
11812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Gain:       Gain to be applied in millibels
11852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//---------------------------------------------------------------------------
1190d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurentvoid EqualizerSetBandLevel(EffectContext *pContext, int band, short Gain){
1191163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int gainRounded;
1192163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(Gain > 0){
1193163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain+50)/100);
1194163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1195163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain-50)/100);
1196163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1197163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);
1198163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1199163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
12002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
12012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1202163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
12032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
12052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1206163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetBandLevel")
1207163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1208d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tEqualizerSetBandLevel just Got -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain);
12092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set local EQ parameters */
1211163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1212163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    ActiveParams.pEQNB_BandDefinition[band].Gain = gainRounded;
12132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
12152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1216163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetBandLevel")
1217d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tEqualizerSetBandLevel just Set -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain);
12182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
12202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
12212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetCentreFrequency()
12242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the frequency being used for the band passed in
12262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
12292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
12302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){
1235163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Frequency =0;
12362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1237163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1238163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1239163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1240163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1241163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1242163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
12432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1244163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency")
12452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1246163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef   = ActiveParams.pEQNB_BandDefinition;
1247163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Frequency = (int32_t)BandDef[band].Frequency*1000;     // Convert to millibels
12482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1249163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency );
1250163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n");
1251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Frequency;
12522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandFreqRange(
12562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets lower and upper boundaries of a band.
12602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the high shelf, the low bound is the band frequency and the high
12612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// bound is Nyquist.
12622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the peaking filters, they are the gain[dB]/2 points.
12632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
12662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
12672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
12702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
12712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1272163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow,
1273163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                  uint32_t *pHi){
1274163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pLow = bandFreqRange[band][0];
1275163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pHi  = bandFreqRange[band][1];
1276163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
12772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBand(
12812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Returns the band with the maximum influence on a given frequency.
12852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Result is unaffected by whether EQ is enabled or not, or by whether
12862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// changes have been committed or not.
12872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  targetFreq   The target frequency, in millihertz.
12902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
12942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
12952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){
12972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int band = 0;
12982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1299163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(targetFreq < bandFreqRange[0][0]){
1300163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
1301163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if(targetFreq == bandFreqRange[0][0]){
1302163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
1303163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1304163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for(int i=0; i<FIVEBAND_NUMBANDS;i++){
1305163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){
1306163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            band = i;
1307163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1308163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
13092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return band;
13102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPreset(
13142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets the currently set preset ID.
13182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Will return PRESET_CUSTOM in case the EQ parameters have been modified
13192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// manually since a preset was set.
13202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
13232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetPreset(EffectContext *pContext){
1326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return pContext->pBundledContext->CurPreset;
13272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetPreset(
13312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Sets the current preset by ID.
13352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// All the band parameters will be overridden.
13362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
13392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  preset       The preset ID.
13402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetPreset(EffectContext *pContext, int preset){
13432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1344163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset(%d)", preset);
13452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = preset;
13462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetPreset")
1353163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully returned from LVM_GetControlParameters\n");
13542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    //ActiveParams.pEQNB_BandDefinition = &BandDefs[0];
13562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
13572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
1358163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
1359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
1360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Gain
1361163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        = EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
13622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
13632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the new settings */
13642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1365163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetPreset")
13662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
13682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
13692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
1370163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
13712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetNumPresets(){
1372163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return sizeof(gEqualizerPresets) / sizeof(PresetConfig);
13732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPresetName(
13772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets a human-readable name for a preset ID. Will return "Custom" if
13802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// PRESET_CUSTOM is passed.
13812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// preset       The preset ID. Must be less than number of presets.
13842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//-------------------------------------------------------------------------
13862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst char * EqualizerGetPresetName(int32_t preset){
1387163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName start(%d)", preset);
13882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (preset == PRESET_CUSTOM) {
13892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return "Custom";
13902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
13912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return gEqualizerPresets[preset].name;
13922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1393163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName end(%d)", preset);
1394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
13952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetVolumeLevel()
13992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  level       level to be applied
14052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
14092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
14112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
14122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Level to be set is %d %d\n", level, (LVM_INT16)(level/100));
14142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
14152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
14172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1418163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully returned from LVM_GetControlParameters got: %d\n",
1419163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //ActiveParams.VC_EffectLevel);
14202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume parameters */
14222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.VC_EffectLevel  = (LVM_INT16)(level/100);
1423163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel() (-96dB -> 0dB)   -> %d\n", ActiveParams.VC_EffectLevel );
14242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
14262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetVolumeLevel")
14282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1430163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully called LVM_SetControlParameters\n");
1431163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1432163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1433163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1434163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
1435163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1436163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1437d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetVolumeLevel just set (-96dB -> 0dB)   -> %d\n",ActiveParams.VC_EffectLevel );
1438d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    if(pContext->pBundledContext->firstVolume == LVM_TRUE){
1439d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams);
1440d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process")
1441d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks");
1442d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        pContext->pBundledContext->firstVolume = LVM_FALSE;
1443d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    }
14442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setVolumeLevel */
14462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeGetVolumeLevel()
14492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){
14582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1459163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel start");
1460163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
14612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
14622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
14632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetVolumeLevel")
14662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1468163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel );
1469163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel Succesfully returned from LVM_GetControlParameters\n");
14702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *level = ActiveParams.VC_EffectLevel*100;     // Convert dB to millibels
1472163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel end");
14732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end VolumeGetVolumeLevel */
14752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetMute()
14782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
14842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){
1488163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute start(%d)", mute);
14892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->bMuteEnabled = mute;
14912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
14932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
14942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
14962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetMute")
14982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1500163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully returned from LVM_GetControlParameters\n");
1501163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute to %d, level was %d\n", mute, ActiveParams.VC_EffectLevel );
15022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set appropriate volume level */
15042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){
1505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved = ActiveParams.VC_EffectLevel;
1506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel           = -96;
15072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel  = pContext->pBundledContext->levelSaved;
15092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
15102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
15122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
15132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetMute")
15142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
15152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1516163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully called LVM_SetControlParameters\n");
1517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute end");
15182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
15192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setMute */
15202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1522163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetMute()
15232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Ourputs:
15302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
15312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){
1534163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute start");
1535163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||
1536163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){
1537163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        *mute = pContext->pBundledContext->bMuteEnabled;
1538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
15392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1540163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d",
1541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent              pContext->pBundledContext->bMuteEnabled);
1542163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
15432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1544163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute end");
15452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getMute */
15462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1547163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint16_t VolumeConvertStereoPosition(int16_t position){
1548163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t convertedPosition = 0;
1549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1550163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    convertedPosition = (int16_t)(((float)position/1000)*96);
1551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return convertedPosition;
1552163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1553163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
1554163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeSetStereoPosition()
1557163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1558163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1559163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1560163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1561163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1562163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1563163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1564163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint VolumeSetStereoPosition(EffectContext *pContext, int16_t position){
1568163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               Balance = 0;
1572163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1573c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->positionSaved = position;
1576163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1578d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1579d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1580163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1581163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance);
1584163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved = position;
1585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1586163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:"
1590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     " %d\n", ActiveParams.VC_Balance);
1591163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1592163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Volume parameters */
1593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  = Balance;
1594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB)   -> %d\n", ActiveParams.VC_Balance );
1595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1596163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Activate the initial settings */
1597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1598163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
1599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n");
16022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1604163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1606163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1607163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: "
1608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     "%d\n", ActiveParams.VC_Balance);
1609163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    else{
1611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n",
1612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //position, Balance);
1613163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1614d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n",
1615d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeSetStereoPosition */
16182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1620163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetStereoPosition()
1622163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1624163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1626163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1627163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1630163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
16312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){
1633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition start");
16342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               balance;
1638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1639d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1640d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
1644163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1645163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance);
1647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1648163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1652163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(balance != ActiveParams.VC_Balance){
1653163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
1654163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1655163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *position = (LVM_INT16)pContext->pBundledContext->positionSaved;     // Convert dB to millibels
1657d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved =%d\n",
1658d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeGetStereoPosition */
16612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1662163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1663163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeEnableStereoPosition()
1664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:   effect engine context
1669163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  mute:       enable/disable flag
1670163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
16722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){
1674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition start()");
16752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->bStereoPositionEnabled = enabled;
16772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
16802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1682163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1683163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition")
1684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1686163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1687163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition to %d, position was %d\n",
1688163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //     enabled, ActiveParams.VC_Balance );
16892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1690163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Set appropriate stereo position */
1691163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){
1692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance = 0;
1693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1694163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  =
1695163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                            VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
16972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
1699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition")
1701163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
17022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1703163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n");
1704163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition end()\n");
1705163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1706163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeEnableStereoPosition */
17072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_getParameter()
17102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a BassBoost parameter
17132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
17162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
17182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
17192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
17222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
17232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
17262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_getParameter(EffectContext     *pContext,
1730c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
1731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           size_t            *pValueSize,
1732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           void              *pValue){
17332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1734c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1735c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
17362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
17372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
17382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1739163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter start");
17402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
174223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17437fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
1744d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize1 %d", *pValueSize);
17457fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
17467fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
17477fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
17487fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
17492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
1751d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize2 %d", *pValueSize);
17522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
17532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
17542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
17552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1758163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
17602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
176323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
17652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
176623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d",
1767163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
17682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = BassGetStrength(pContext);
17722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1773163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d",
1774163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
17752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
17802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1783163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter end");
17842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_getParameter */
17862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_setParameter()
17892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a BassBoost parameter
17922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
17952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
17972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1802c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue){
18032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
18042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1805c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
18062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1807163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter start");
18082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1809c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (*pParamTemp){
18102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
18112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1812163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength);
1813163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength");
18142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            BassSetStrength(pContext, (int32_t)strength);
1815163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength");
18162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
18172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1818c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParamTemp);
18192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1822163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter end");
18232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_setParameter */
18252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_getParameter()
18282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Virtualizer parameter
18312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
18342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
18362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
18372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
18402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
18412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
18442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_getParameter(EffectContext        *pContext,
1848c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void                 *pParam,
18492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             size_t               *pValueSize,
18502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             void                 *pValue){
18512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1852c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1853c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
18542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
18552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
18562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1857163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter start");
18582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
186023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18617fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
18627fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
18637fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
18647fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
18657fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
18667fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
18672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
1869d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize2 %d",*pValueSize);
18702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
18712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
18722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
18732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
18772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
18782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
188123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
18832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
188423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d",
1885163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
18862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = VirtualizerGetStrength(pContext);
18902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1891163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d",
1892163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
18932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
18972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
18982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1901163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter end");
19022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_getParameter */
19042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_setParameter()
19072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Virtualizer parameter
19102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
19132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
19152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1920c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
19212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
19222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1923c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1924c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
19252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1926163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter start");
19272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1928c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
19292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
19302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1931163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength);
1932163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength");
19332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            VirtualizerSetStrength(pContext, (int32_t)strength);
1934163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength");
19352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
19362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1937c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", param);
19382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1941163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter end");
19422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_setParameter */
19442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_getParameter()
19472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Equalizer parameter
19502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer       - handle to instance data
19532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
19552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
19562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
19592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
19602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
19632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_getParameter(EffectContext     *pContext,
1966c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
19672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           size_t            *pValueSize,
19682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           void              *pValue){
19692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
19702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
1971c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1972c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
19732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
19742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
19752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_getParameter start");
19772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
19792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
19802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
19812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
19823be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_BAND_LEVEL:
19833be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_GET_BAND:
19842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int16_t)) {
1985163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
19862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int16_t);
19892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
19923be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (*pValueSize < 2 * sizeof(int16_t)) {
19933be9523784cc4038f601e510faee595117cdacb3Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
19943be9523784cc4038f601e510faee595117cdacb3Eric Laurent            return -EINVAL;
19953be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
19963be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *pValueSize = 2 * sizeof(int16_t);
19973be9523784cc4038f601e510faee595117cdacb3Eric Laurent        break;
19982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
19992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < 2 * sizeof(int32_t)) {
2000d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 3  %d", *pValueSize);
20012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = 2 * sizeof(int32_t);
20042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20053be9523784cc4038f601e510faee595117cdacb3Eric Laurent
20062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
20072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int32_t)) {
2008d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 5  %d", *pValueSize);
20092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int32_t);
20122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
20152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
201723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES:
201823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) {
201923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
202023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            return -EINVAL;
202123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
202223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t);
202323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        break;
202423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
20252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
2026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param);
20272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
20282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
20312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
20323be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS;
2033163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue);
20342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
20373be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = -1500;
20383be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *((int16_t *)pValue + 1) = 1500;
2039163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d",
2040d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      *(int16_t *)pValue, *((int16_t *)pValue + 1));
20412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2044c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20493be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2);
2050163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d",
2051163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
2055c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2);
2061163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d",
2062163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
2066c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1));
2072163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d",
2073163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue, *((int32_t *)pValue + 1));
20742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_BAND:
2077c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20783be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2);
2079163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d",
2080d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      param2, *(uint16_t *)pValue);
20812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
20843be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext);
2085163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue);
20862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
20893be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets();
2090163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue);
20912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
2094c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= EqualizerGetNumPresets()) {
20962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        //if (param2 >= 20) {     // AGO FIX
20972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name = (char *)pValue;
21012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1);
21022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name[*pValueSize - 1] = 0;
21032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = strlen(name) + 1;
2104163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d",
2105163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, gEqualizerPresets[param2].name, *pValueSize);
21062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
210823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES: {
21093be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
211023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        LOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES");
21113be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[0] = (int16_t)EqualizerGetPreset(pContext);
21123be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[1] = (int16_t)FIVEBAND_NUMBANDS;
211323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
21143be9523784cc4038f601e510faee595117cdacb3Eric Laurent            p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i);
211523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
211623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    } break;
211723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
21182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
21192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param);
21202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        status = -EINVAL;
21212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2124d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //GV("\tEqualizer_getParameter end\n");
21252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_getParameter */
21272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_setParameter()
21302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Equalizer parameter
21332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer    - handle to instance data
21362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
21372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
21382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
2142c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
21432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t preset;
21452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t band;
21462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t level;
2147c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2148c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
2149c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
21502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2151163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter start");
21522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
21532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
21543be9523784cc4038f601e510faee595117cdacb3Eric Laurent        preset = (int32_t)(*(uint16_t *)pValue);
21552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2156163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset);
21572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if ((preset >= EqualizerGetNumPresets())||(preset < 0)) {
21582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetPreset(pContext, preset);
21622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2164c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        band =  *pParamTemp;
21653be9523784cc4038f601e510faee595117cdacb3Eric Laurent        level = (int32_t)(*(int16_t *)pValue);
2166163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level);
21672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (band >= FIVEBAND_NUMBANDS) {
21682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetBandLevel(pContext, band, level);
21722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21733be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_PROPERTIES: {
21743be9523784cc4038f601e510faee595117cdacb3Eric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES");
21753be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
21763be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if ((int)p[0] >= EqualizerGetNumPresets()) {
21773be9523784cc4038f601e510faee595117cdacb3Eric Laurent            status = -EINVAL;
21783be9523784cc4038f601e510faee595117cdacb3Eric Laurent            break;
21793be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
21803be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (p[0] >= 0) {
21813be9523784cc4038f601e510faee595117cdacb3Eric Laurent            EqualizerSetPreset(pContext, (int)p[0]);
21823be9523784cc4038f601e510faee595117cdacb3Eric Laurent        } else {
21833be9523784cc4038f601e510faee595117cdacb3Eric Laurent            if ((int)p[1] != FIVEBAND_NUMBANDS) {
21843be9523784cc4038f601e510faee595117cdacb3Eric Laurent                status = -EINVAL;
21853be9523784cc4038f601e510faee595117cdacb3Eric Laurent                break;
21863be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
21873be9523784cc4038f601e510faee595117cdacb3Eric Laurent            for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
21883be9523784cc4038f601e510faee595117cdacb3Eric Laurent                EqualizerSetBandLevel(pContext, i, (int)p[2 + i]);
21893be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
21903be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
21913be9523784cc4038f601e510faee595117cdacb3Eric Laurent    } break;
21922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
2193d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LOGV("\tLVM_ERROR : Equalizer_setParameter() invalid param %d", param);
21943be9523784cc4038f601e510faee595117cdacb3Eric Laurent        status = -EINVAL;
21952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2198163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter end");
21992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
22002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_setParameter */
22012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_getParameter()
22042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
22062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Volume parameter
22072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
22092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume          - handle to instance data
22102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
22112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
22122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
22132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
22152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
22162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
22172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
22202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_getParameter(EffectContext     *pContext,
2224c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void              *pParam,
22252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        size_t            *pValueSize,
22262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        void              *pValue){
22272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
22282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2229c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2230c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;;
22312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
22322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2233d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolume_getParameter start");
22342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2239163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if (*pValueSize != sizeof(int16_t)){
22402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1  %d", *pValueSize);
22412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
22442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
22472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
22482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize < sizeof(int32_t)){
22492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2  %d", *pValueSize);
22502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int32_t);
22532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param);
22572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue));
2263d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d",
2264d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = 0;
2269d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d",
2270d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2274163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            VolumeGetStereoPosition(pContext, (int16_t *)pValue);
2275d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d",
2276d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2280163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeGetMute(pContext, (uint32_t *)pValue);
2281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d",
2282163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(uint32_t *)pValue);
22832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2286163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled;
2287d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d",
2288d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(uint32_t *)pValue);
22892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
22922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param);
22932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
22942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2297163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_getParameter end");
22982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
22992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_getParameter */
23002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_setParameter()
23042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
23062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Volume parameter
23072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
23092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume       - handle to instance data
23102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
23112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
23122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
23142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2317c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue){
23182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int      status = 0;
23192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t  level;
2320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t  position;
23212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    uint32_t mute;
2322163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    uint32_t positionEnabled;
2323c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2324c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
23252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2326d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //LOGV("\tVolume_setParameter start");
23272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2328c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
23292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
23302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            level = *(int16_t *)pValue;
2331d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level);
2332d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel");
23332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeSetVolumeLevel(pContext, (int16_t)level);
2334d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel");
23352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            mute = *(uint32_t *)pValue;
2339d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute);
2340d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->setMute");
2341163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetMute(pContext, mute);
2342d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->setMute");
2343163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2346163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            positionEnabled = *(uint32_t *)pValue;
2347163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeEnableStereoPosition(pContext, positionEnabled);
2348163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved);
2349d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called");
2350163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2353163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            position = *(int16_t *)pValue;
2354d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position);
2355d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition");
2356163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, (int16_t)position);
2357d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //LOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition");
2358163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2361c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", param);
23622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2365163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_setParameter end");
23662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_setParameter */
23682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2369163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent/****************************************************************************************
2370163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent * Name : LVC_ToDB_s32Tos16()
2371163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Input       : Signed 32-bit integer
2372163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Output      : Signed 16-bit integer
2373163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  MSB (16) = sign bit
2374163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (15->05) = integer part
2375163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (04->01) = decimal part
2376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Returns     : Db value with respect to full scale
2377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Description :
2378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Remarks     :
2379163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent ****************************************************************************************/
2380163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2381163fbcf84010b98e0374110454d85b804bc8d13bEric LaurentLVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix)
2382163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent{
2383163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   db_fix;
2384163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   Shift;
2385163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   SmallRemainder;
2386163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_UINT32  Remainder = (LVM_UINT32)Lin_fix;
2387163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2388163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Count leading bits, 1 cycle in assembly*/
2389163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for (Shift = 0; Shift<32; Shift++)
2390163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
2391163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if ((Remainder & 0x80000000U)!=0)
2392163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2393163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2395163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        Remainder = Remainder << 1;
2396163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
23972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2398163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /*
2399163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * Based on the approximation equation (for Q11.4 format):
2400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     *
2401163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2)
2402163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     */
2403163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix    = (LVM_INT16)(-96 * Shift);               /* Six dB steps in Q11.4 format*/
2404163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24);
2405163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix + SmallRemainder );
2406163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder);
2407163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9));
24082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Correct for small offset */
2410163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - 5);
24112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2412163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return db_fix;
2413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
24142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
241529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
241629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Effect_setEnabled()
241729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
241829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Purpose:
241929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Enable or disable effect
242029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
242129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Inputs:
242229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//  pContext      - pointer to effect context
242329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//  enabled       - true if enabling the effect, false otherwise
242429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
242529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Outputs:
242629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
242729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
242829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
242929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurentint Effect_setEnabled(EffectContext *pContext, bool enabled)
243029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent{
243129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    LOGV("\tEffect_setEnabled() type %d, enabled %d", pContext->EffectType, enabled);
243229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
243329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    if (enabled) {
243429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        switch (pContext->EffectType) {
243529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_BASS_BOOST:
243629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
2437dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                     LOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already enabled");
243829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     return -EINVAL;
243929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2440dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountBb <= 0){
2441dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2442dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
244329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountBb =
244429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
244529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bBassEnabled = LVM_TRUE;
244629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
244729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_EQUALIZER:
244829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE) {
2449dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    LOGV("\tEffect_setEnabled() LVM_EQUALIZER is already enabled");
245029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
245129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2452dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountEq <= 0){
2453dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2454dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
245529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountEq =
245629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
245729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE;
245829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
245929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VIRTUALIZER:
246029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) {
2461dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    LOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already enabled");
246229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
246329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2464dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountVirt <= 0){
2465dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2466dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
246729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountVirt =
246829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
246929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE;
247029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
247129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VOLUME:
247229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE) {
2473dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    LOGV("\tEffect_setEnabled() LVM_VOLUME is already enabled");
247429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
247529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2476dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                pContext->pBundledContext->NumberEffectsEnabled++;
247729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVolumeEnabled = LVM_TRUE;
247829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
247929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            default:
2480dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                LOGV("\tEffect_setEnabled() invalid effect type");
248129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                return -EINVAL;
248229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        }
248329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        LvmEffect_enable(pContext);
248429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    } else {
248529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        switch (pContext->EffectType) {
248629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_BASS_BOOST:
248729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bBassEnabled == LVM_FALSE) {
2488dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    LOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already disabled");
248929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
249029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
249129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bBassEnabled = LVM_FALSE;
249229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
249329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_EQUALIZER:
249429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE) {
2495dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    LOGV("\tEffect_setEnabled() LVM_EQUALIZER is already disabled");
249629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
249729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
249829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE;
249929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
250029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VIRTUALIZER:
250129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE) {
2502dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    LOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already disabled");
250329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
250429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
250529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE;
250629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
250729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VOLUME:
250829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVolumeEnabled == LVM_FALSE) {
2509dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    LOGV("\tEffect_setEnabled() LVM_VOLUME is already disabled");
251029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
251129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
251229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVolumeEnabled = LVM_FALSE;
251329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
251429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            default:
2515dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                LOGV("\tEffect_setEnabled() invalid effect type");
251629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                return -EINVAL;
251729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        }
251829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        LvmEffect_disable(pContext);
251929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    }
252029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
252129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    return 0;
252229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent}
252329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
2524dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//----------------------------------------------------------------------------
2525dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// LVC_Convert_VolToDb()
2526dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//----------------------------------------------------------------------------
2527dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Purpose:
2528dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Convery volume in Q24 to dB
2529dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//
2530dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Inputs:
2531dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//  vol:   Q.24 volume dB
2532dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//
2533dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//-----------------------------------------------------------------------
2534dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2535dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentint16_t LVC_Convert_VolToDb(uint32_t vol){
2536dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    int16_t  dB;
2537dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2538dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = LVC_ToDB_s32Tos16(vol <<7);
2539dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = (dB +8)>>4;
2540dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = (dB <-96) ? -96 : dB ;
2541dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2542dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return dB;
2543dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent}
2544dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
2546163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
25472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Process */
25492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_process(effect_interface_t     self,
2550163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *inBuffer,
2551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *outBuffer){
25522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
2553c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
25542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int    status = 0;
2555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int    lvmStatus = 0;
2556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *in  = (LVM_INT16 *)inBuffer->raw;
2557163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *out = (LVM_INT16 *)outBuffer->raw;
25582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2559dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//LOGV("\tEffect_process Start : Enabled = %d     Called = %d (%8d %8d %8d)",
2560dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled,
2561c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountBb,
2562c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountVirt,
2563c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountEq);
2564c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
25652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
25662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL");
25672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
25682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2569dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2570dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //if(pContext->EffectType == LVM_BASS_BOOST){
2571dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //  LOGV("\tEffect_process: Effect type is BASS_BOOST");
2572dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}else if(pContext->EffectType == LVM_EQUALIZER){
2573dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //  LOGV("\tEffect_process: Effect type is LVM_EQUALIZER");
2574dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}else if(pContext->EffectType == LVM_VIRTUALIZER){
2575dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //  LOGV("\tEffect_process: Effect type is LVM_VIRTUALIZER");
2576dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}
2577dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
25782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
25792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
25802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            inBuffer->frameCount != outBuffer->frameCount){
25812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
25822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
25832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2584163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&
2585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_BASS_BOOST)){
2586c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_BASS_BOOST Effect is not enabled");
2587c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
2588c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO
25892d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent            //LOGV("\tEffect_process: Waiting to turn off BASS_BOOST, %d samples left",
2590c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountBb);
2591d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2592d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb <= 0) {
259329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            status = -ENODATA;
2594dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
2595d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent            LOGV("\tEffect_process() this is the last frame for LVM_BASS_BOOST");
2596c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
2597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2598163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&
2599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VOLUME)){
2600c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_VOLUME Effect is not enabled");
2601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2602dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->NumberEffectsEnabled--;
2603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2604163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&
2605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_EQUALIZER)){
2606c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_EQUALIZER Effect is not enabled");
2607c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
2608c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq -= outBuffer->frameCount * 2; // STEREO
2609dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //LOGV("\tEffect_process: Waiting to turn off EQUALIZER, %d samples left",
2610c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountEq);
2611d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2612d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq <= 0) {
2613c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2614dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
2615d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent            LOGV("\tEffect_process() this is the last frame for LVM_EQUALIZER");
2616c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
26172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&
2619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VIRTUALIZER)){
2620c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        //LOGV("\tEffect_process() LVM_VIRTUALIZER Effect is not enabled");
2621c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
2622c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt -= outBuffer->frameCount * 2;// STEREO
2623dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //LOGV("\tEffect_process: Waiting for to turn off VIRTUALIZER, %d samples left",
2624c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountVirt);
2625d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2626d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt <= 0) {
2627c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2628dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
2629d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent            LOGV("\tEffect_process() this is the last frame for LVM_VIRTUALIZER");
2630c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
26312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2633dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if(status != -ENODATA){
2634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled++;
26352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
26362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->NumberEffectsCalled ==
2638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       pContext->pBundledContext->NumberEffectsEnabled){
2639dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        //LOGV("\tEffect_process     Calling process with %d effects enabled, %d called: Effect %d",
2640163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
26422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(status == -ENODATA){
2644dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LOGV("\tEffect_process() processing last frame");
2645163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
26462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext->NumberEffectsCalled = 0;
2647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Process all the available frames, block processing is
2648163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           handled internalLY by the LVM bundle */
2649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        lvmStatus = android::LvmBundle_process(    (LVM_INT16 *)inBuffer->raw,
26502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                (LVM_INT16 *)outBuffer->raw,
26512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                outBuffer->frameCount,
26522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                pContext);
2653163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(lvmStatus != LVM_SUCCESS){
2654163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
2655163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return lvmStatus;
2656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
26572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
2658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
2659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
2661163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        // 2 is for stereo input
2662163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
26632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
26652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
26662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end Effect_process */
26672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Command */
26692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_command(effect_interface_t  self,
267025f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdCode,
267125f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdSize,
2672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pCmdData,
267325f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            *replySize,
2674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pReplyData){
26752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
26762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int retsize;
26772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\t\nEffect_command start");
26792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST){
2681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_BASS_BOOST");
26822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
26832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER){
2684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VIRTUALIZER");
2685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
26862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER){
2687163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_EQUALIZER");
2688163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
26892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME){
2690163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VOLUME");
2691163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
26922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
26942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL");
26952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
26962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
26972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
26992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // Incase we disable an effect, next time process is
2701163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // called the number of effect called could be greater
2702163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // pContext->pBundledContext->NumberEffectsCalled = 0;
27032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2704163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d",
2705163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsCalled,
2706163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsEnabled);
27072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (cmdCode){
27092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_INIT:
2710010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
2711010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                LOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d",
2712010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                        pContext->EffectType);
2713010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                return -EINVAL;
2714010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            }
2715010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            *(int *) pReplyData = 0;
2716163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start");
27172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST");
27192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                android::BassSetStrength(pContext, 0);
27202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2722163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER");
2723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::VirtualizerSetStrength(pContext, 0);
2724163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2726163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER");
2727163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::EqualizerSetPreset(pContext, 0);
2728163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2730d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VOLUME");
2731010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0);
2732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2734163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
27352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_CONFIGURE:
2736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE start");
27372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pCmdData    == NULL||
27382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                cmdSize     != sizeof(effect_config_t)||
27392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                pReplyData  == NULL||
27402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize  != sizeof(int)){
27412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
27422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_CONFIGURE: ERROR");
27432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
27442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *) pReplyData = android::Effect_configure(pContext, (effect_config_t *) pCmdData);
2746163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE end");
27472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
27482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_RESET:
2750163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start");
27512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            android::Effect_configure(pContext, &pContext->config);
2752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end");
27532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
27542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_GET_PARAM:{
2756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2757163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
27582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2759163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2760163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2761163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2762163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
27632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
27652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
27682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
27702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
27722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
27742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::BassBoost_getParameter(pContext,
2776c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
27772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            (size_t  *)&p->vsize,
27782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            p->data + voffset);
27792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
27812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2782163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM "
2783163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2784163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2785163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2786163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
27872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
2788163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
27892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2790163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2791163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2792163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2793163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
27942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
27952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
27962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
27992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
28012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
28032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
28052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Virtualizer_getParameter(pContext,
2807c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                             (void *)p->data,
28082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                             (size_t  *)&p->vsize,
28092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                              p->data + voffset);
28102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
28122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2813163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM "
2814163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2815163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2816163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2817163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
28182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2820163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command cmdCode Case: "
2821163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2822163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2823163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2824163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL ||
2825163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) {
28262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
28272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM");
28282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
2831163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
2833163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
2835163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
2837163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2838c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                p->status = android::Equalizer_getParameter(pContext,
2839c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
2840c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            &p->vsize,
2841c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data + voffset);
2842163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
2844163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2845163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, "
2846163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //       "*pReplyData %08x %08x",
2847163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize,
2848163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset),
2849163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset +
2850163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        sizeof(int32_t)));
28512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2853d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tVolume_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2854163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2855163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2856163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2857163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
28582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
28592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
28602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
28632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
28652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
28672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
28692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Volume_getParameter(pContext,
2871c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                         (void *)p->data,
28722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         (size_t  *)&p->vsize,
28732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         p->data + voffset);
28742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
28762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2877163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_GET_PARAM "
2878163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2879163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2880163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2881163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
2882163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2883163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end");
28842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
28852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_PARAM:{
2886163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
28872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2888dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2889dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2890dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *replySize,
2891dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2892163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2893163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2894163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2895163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2896163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
28972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
28982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
28992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
29022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
29042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
29052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
29062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2909163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnBassBoost_command cmdSize is %d\n"
2910163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2912163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2914163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
29152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::BassBoost_setParameter(pContext,
2917c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
29182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    p->data + p->psize);
29192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
29202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2921d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //LOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2922d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2923d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *replySize,
2924d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2925163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2926163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2927163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2928163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2929163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
29302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
29322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
29352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
29372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
29392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2942163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnVirtualizer_command cmdSize is %d\n"
2943163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2945163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2946163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
29482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Virtualizer_setParameter(pContext,
2950c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                      (void *)p->data,
2951163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                       p->data + p->psize);
29522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
29532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2954d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //LOGV("\tEqualizer_command cmdCode Case: "
2955d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        "EFFECT_CMD_SET_PARAM start");
2956d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //LOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2957d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2958d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *replySize,
2959d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
29602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
29622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pReplyData == NULL || *replySize != sizeof(int32_t)) {
29632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
29642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
29652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
29682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Equalizer_setParameter(pContext,
2970c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
2971163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                     p->data + p->psize);
29722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
29732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2974d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //LOGV("\tVolume_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
2975163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2977163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2978d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) +sizeof(int32_t)));
29792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (    pCmdData   == NULL||
29812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        cmdSize    < (int)(sizeof(effect_param_t) + sizeof(int32_t))||
29822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        pReplyData == NULL||
29832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        *replySize != sizeof(int32_t)){
29842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
29852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
29862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
29892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Volume_setParameter(pContext,
2991c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                 (void *)p->data,
2992163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                 p->data + p->psize);
2993163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2994163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end");
29952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
29962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_ENABLE:
2998c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start");
29992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
30002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
30012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
3002163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
300329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
300429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_TRUE);
30052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3006163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
30072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_DISABLE:
3008163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start");
30092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
30102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
30112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
3012163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
301329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_FALSE);
30142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
30152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_DEVICE:
3017163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
3018163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start");
3019163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            audio_device_e device = *(audio_device_e *)pCmdData;
3020163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3021163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
3022163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
3023163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
3024163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d",
3025163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST");
3027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3028163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device doesnt support bassboost the effect must be temporarily disabled
3029163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3030163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3031163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
3033163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d",
3034163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3035163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3036163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_TRUE;
3037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3038163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
3039163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d",
3040163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                         *(int32_t *)pCmdData);
3041163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3042163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports bassboost and the effect has been temporarily disabled
3043163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3044163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3045163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassTempDisabled == LVM_TRUE){
3046163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d",
3047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3048163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3049163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_FALSE;
3050163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3051163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3052163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3053163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
3054163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
3055163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
3056163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d",
3057163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3058163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER");
3059163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3060163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //If a device doesnt support virtualizer the effect must be temporarily disabled
3061163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3062163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3063163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3064163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
3065163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d",
3066163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3067163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3068163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
3069163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3070163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
3071163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d",
3072163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3073163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3074163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports virtualizer and the effect has been temporarily disabled
3075163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3076163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3077163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerTempDisabled == LVM_TRUE){
3078163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d",
3079163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3080163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3081163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
3082163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3083163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3084163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3085163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end");
30862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3087163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
3088163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_VOLUME:
3089163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
3090dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            uint32_t leftVolume, rightVolume;
3091dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int16_t  leftdB, rightdB;
3092dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int16_t  maxdB, pandB;
3093dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int32_t  vol_ret[2] = {1<<24,1<<24}; // Apply no volume
3094dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int      status = 0;
3095dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ControlParams_t     ActiveParams;           /* Current control Parameters */
3096dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;  /* Function call status */
3097163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3098163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // if pReplyData is NULL, VOL_CTRL is delegated to another effect
3099163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pReplyData == LVM_NULL){
3100163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                break;
3101163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
31022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3103dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (pCmdData == NULL ||
3104dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                cmdSize != 2 * sizeof(uint32_t)) {
3105dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
3106dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                        "EFFECT_CMD_SET_VOLUME: ERROR");
3107dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                return -EINVAL;
3108163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3109163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3110dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            leftVolume  = ((*(uint32_t *)pCmdData));
3111dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            rightVolume = ((*((uint32_t *)pCmdData + 1)));
3112dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3113dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(leftVolume == 0x1000000){
3114dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                leftVolume -= 1;
3115dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3116dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(rightVolume == 0x1000000){
3117dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                rightVolume -= 1;
3118dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3119dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3120dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            // Convert volume to dB
3121dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            leftdB  = android::LVC_Convert_VolToDb(leftVolume);
3122dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            rightdB = android::LVC_Convert_VolToDb(rightVolume);
3123dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3124dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pandB = rightdB - leftdB;
3125dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3126dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            // Calculate max volume in dB
3127dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            maxdB = leftdB;
3128dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(rightdB > maxdB){
3129dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                maxdB = rightdB;
3130dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3131dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //LOGV("\tEFFECT_CMD_SET_VOLUME Session: %d, SessionID: %d VOLUME is %d dB (%d), "
3132dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //      "effect is %d",
3133dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //pContext->pBundledContext->SessionNo, pContext->pBundledContext->SessionId,
3134dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //(int32_t)maxdB, maxVol<<7, pContext->EffectType);
3135dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //LOGV("\tEFFECT_CMD_SET_VOLUME: Left is %d, Right is %d", leftVolume, rightVolume);
3136dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //LOGV("\tEFFECT_CMD_SET_VOLUME: Left %ddB, Right %ddB, Position %ddB",
3137dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //        leftdB, rightdB, pandB);
3138d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
3139163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            memcpy(pReplyData, vol_ret, sizeof(int32_t)*2);
3140dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            android::VolumeSetVolumeLevel(pContext, (int16_t)(maxdB*100));
3141dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3142dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Get the current settings */
3143dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LvmStatus =LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
3144dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
3145dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(LvmStatus != LVM_SUCCESS) return -EINVAL;
3146dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3147dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Volume parameters */
3148dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            ActiveParams.VC_Balance  = pandB;
3149dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LOGV("\t\tVolumeSetStereoPosition() (-96dB -> +96dB)-> %d\n", ActiveParams.VC_Balance );
3150dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3151dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Activate the initial settings */
3152dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LvmStatus =LVM_SetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
3153dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
3154dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(LvmStatus != LVM_SUCCESS) return -EINVAL;
3155163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
3156163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent         }
3157163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
3158163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
31592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
31602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
31612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
31622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command end...\n\n");
31642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
31652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end Effect_command */
31662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for effect
31682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst struct effect_interface_s gLvmEffectInterface = {
31692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_process,
31702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_command
31712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};    /* end gLvmEffectInterface */
31722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3173