EffectBundle.cpp revision 7f16b197c76fbae9399242f055a7ee16dcd0fd6d
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>
27b4d307481960b6b348fae4b4e8edefd003c3d36cGlenn Kasten#include "EffectBundle.h"
282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent// effect_handle_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){\
353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\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){\
393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\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){\
433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\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){\
473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Parameter error - "\
482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "out of range returned by %s in %s\n", callingFunc, calledFunc);\
492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
525dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent
535dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurentstatic inline int16_t clamp16(int32_t sample)
545dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent{
555dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    // check overflow for both positive and negative values:
565dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    // all bits above short range must me equal to sign bit
575dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    if ((sample>>15) ^ (sample>>31))
585dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent        sample = 0x7FFF ^ (sample>>31);
595dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    return sample;
605dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent}
615dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent
622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Namespaces
632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace android {
642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace {
652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
66d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent// Flag to allow a one time init of global memory, only happens on first call ever
67d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurentint LvmInitFlag = LVM_FALSE;
68d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric LaurentSessionContext GlobalSessionMemory[LVM_MAX_SESSIONS];
69d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurentint SessionIndex[LVM_MAX_SESSIONS];
70d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent
712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* local functions */
722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define CHECK_ARG(cond) {                     \
732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (!(cond)) {                            \
743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Invalid argument: "#cond);      \
752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;                       \
762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }                                         \
772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW BassBoost UUID
812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gBassBoostDescriptor = {
822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
84e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
85163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
86163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
87d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BASS_BOOST_CUP_LOAD_ARM9E,
88d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Dynamic Bass Boost",
902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Virtualizer UUID
942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVirtualizerDescriptor = {
95163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
96163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
97e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
98163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
99163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
100d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VIRTUALIZER_CUP_LOAD_ARM9E,
101d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Virtualizer",
1032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Equalizer UUID
1072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gEqualizerDescriptor = {
1082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
1092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP
110e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
111163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
112d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        EQUALIZER_CUP_LOAD_ARM9E,
113d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Equalizer",
1152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Volume UUID
1192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVolumeDescriptor = {
1202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
1212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP
122e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
123163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
124d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VOLUME_CUP_LOAD_ARM9E,
125d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Volume",
1272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//--- local function prototypes
1312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init      (void);
1322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmBundle_init            (EffectContext *pContext);
1332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_enable          (EffectContext *pContext);
1342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_disable         (EffectContext *pContext);
1352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free            (EffectContext *pContext);
1363d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentint  Effect_setConfig          (EffectContext *pContext, effect_config_t *pConfig);
1373d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentvoid Effect_getConfig          (EffectContext *pContext, effect_config_t *pConfig);
138c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  BassBoost_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
139163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  BassBoost_getParameter    (EffectContext *pContext,
140c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
1422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               void           *pValue);
143c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Virtualizer_setParameter  (EffectContext *pContext, void *pParam, void *pValue);
1442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Virtualizer_getParameter  (EffectContext *pContext,
145c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
1462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
147163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                               void           *pValue);
148c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Equalizer_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
1492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Equalizer_getParameter    (EffectContext *pContext,
150c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
153c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Volume_setParameter       (EffectContext *pContext, void *pParam, void *pValue);
1542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Volume_getParameter       (EffectContext *pContext,
155c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
1562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
15829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurentint Effect_setEnabled(EffectContext *pContext, bool enabled);
1592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Library Interface Implementation */
1612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1625e92a7861196ddae14638d4b7a63fc4892b7ef59Glenn Kastenextern "C" int EffectCreate(const effect_uuid_t *uuid,
1632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             sessionId,
1642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             ioId,
165e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                            effect_handle_t  *pHandle){
166dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    int ret = 0;
167c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int sessionNo;
1682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int i;
169dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    EffectContext *pContext = NULL;
170dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    bool newBundle = false;
171dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    SessionContext *pSessionContext;
1722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\n\tEffectCreate start session %d", sessionId);
1742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
175e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pHandle == NULL || uuid == NULL){
1763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer");
177dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
178dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
1792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmInitFlag == LVM_FALSE){
1822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmInitFlag = LVM_TRUE;
1833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Initializing all global memory");
1842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmGlobalBundle_init();
1852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
187c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Find next available sessionNo
188c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for(i=0; i<LVM_MAX_SESSIONS; i++){
189e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        if((SessionIndex[i] == LVM_UNUSED_SESSION)||(SessionIndex[i] == sessionId)){
190c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            sessionNo       = i;
191c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            SessionIndex[i] = sessionId;
1923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffectCreate: Allocating SessionNo %d for SessionId %d\n", sessionNo,sessionId);
193c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
194c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
195c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
196c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
197c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(i==LVM_MAX_SESSIONS){
1983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Cannot find memory to allocate for current session");
199dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
200dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
201c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
202dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
203dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    pContext = new EffectContext;
204dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // If this is the first create in this session
206c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(GlobalSessionMemory[sessionNo].bBundledEffectsEnabled == LVM_FALSE){
2073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - This is the first effect in current sessionId %d sessionNo %d",
208c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionId, sessionNo);
209c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
210c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_TRUE;
211c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].pBundledContext        = new BundledEffectContext;
212dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        newBundle = true;
2132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
214c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = GlobalSessionMemory[sessionNo].pBundledContext;
215c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionNo                = sessionNo;
216c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionId                = sessionId;
217163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->hInstance                = NULL;
218163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVolumeEnabled           = LVM_FALSE;
219163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bEqualizerEnabled        = LVM_FALSE;
220163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassEnabled             = LVM_FALSE;
221163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassTempDisabled        = LVM_FALSE;
222163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerEnabled      = LVM_FALSE;
223163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
224163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsEnabled     = 0;
225163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled      = 0;
226d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        pContext->pBundledContext->firstVolume              = LVM_TRUE;
227163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
228163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
2298f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        char fileName[256];
2308f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_in.pcm", pContext->pBundledContext);
2318f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmInPtr = fopen(fileName, "w");
2328f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr == NULL) {
2333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("cannot open %s", fileName);
234dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            ret = -EINVAL;
235dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            goto exit;
2368f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
237163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2388f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_out.pcm", pContext->pBundledContext);
2398f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmOutPtr = fopen(fileName, "w");
2408f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr == NULL) {
2413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("cannot open %s", fileName);
2428f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
2438f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent           pContext->pBundledContext->PcmInPtr = NULL;
244dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent           ret = -EINVAL;
245dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent           goto exit;
246163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
247163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
248163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        /* Saved strength is used to return the exact strength that was used in the set to the get
2502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * because we map the original strength range of 0:1000 to 1:15, and this will avoid
2512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * quantisation like effect when returning
2522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         */
253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->BassStrengthSaved        = 0;
254163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->VirtStrengthSaved        = 0;
255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->CurPreset                = PRESET_CUSTOM;
256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved               = 0;
257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bMuteEnabled             = LVM_FALSE;
258163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bStereoPositionEnabled   = LVM_FALSE;
259163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved            = 0;
260dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->workBuffer               = NULL;
261dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->frameCount               = -1;
262dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt   = 0;
263dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb     = 0;
264dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq     = 0;
265163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2669b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
2679b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent            pContext->pBundledContext->bandGaindB[i] = EQNB_5BandSoftPresets[i];
2689b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        }
2699b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
2703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Calling LvmBundle_init");
2712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ret = LvmBundle_init(pContext);
2722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (ret < 0){
2743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : EffectCreate() Bundle init failed");
275dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            goto exit;
2762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
2772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
2793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Assigning memory for previously created effect on sessionNo %d",
280c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionNo);
281c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext =
282c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                GlobalSessionMemory[sessionNo].pBundledContext;
2832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext);
2852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
286dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo];
28729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
2882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Create each Effect
2892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Bass Boost
2913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST");
29229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bBassInstantiated = LVM_TRUE;
293dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb = 0;
294163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
295163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->itfe       = &gLvmEffectInterface;
2962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_BASS_BOOST;
2972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Virtualizer
2993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER");
30029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVirtualizerInstantiated=LVM_TRUE;
301dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt = 0;
302163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VIRTUALIZER;
3052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Equalizer
3073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER");
30829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bEqualizerInstantiated = LVM_TRUE;
309dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq = 0;
310163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_EQUALIZER;
3132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Volume
3153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_VOLUME");
31629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVolumeInstantiated = LVM_TRUE;
317163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VOLUME;
320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
3223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectCreate() invalid UUID");
323dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
324dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
3252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
327dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentexit:
328dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if (ret != 0) {
329dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext != NULL) {
330dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (newBundle) {
331dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_FALSE;
332dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                SessionIndex[sessionNo] = LVM_UNUSED_SESSION;
333dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                delete pContext->pBundledContext;
334dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
335dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            delete pContext;
336dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
337e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        *pHandle = (effect_handle_t)NULL;
338dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    } else {
339e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        *pHandle = (effect_handle_t)pContext;
340dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    }
3413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectCreate end..\n\n");
342dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return ret;
3432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectCreate */
3442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
345e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentextern "C" int EffectRelease(effect_handle_t handle){
3463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\n\tEffectRelease start %p", handle);
347e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    EffectContext * pContext = (EffectContext *)handle;
3482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectRelease start handle: %p, context %p", handle, pContext->pBundledContext);
3502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
3513856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
3522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
353163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
35529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    SessionContext *pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo];
35629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
3572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Clear the instantiated flag for the effect
358dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // protect agains the case where an effect is un-instantiated without being disabled
3592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
3603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag");
36129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bBassInstantiated = LVM_FALSE;
362dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
363dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
364dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
365dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb = 0;
3662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VIRTUALIZER) {
3673856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag");
36829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVirtualizerInstantiated = LVM_FALSE;
369dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
370dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
371dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
372dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt = 0;
3732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_EQUALIZER) {
3743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag");
37529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bEqualizerInstantiated =LVM_FALSE;
376dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
377dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
378dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
379dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq = 0;
3802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VOLUME) {
3813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag");
38229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVolumeInstantiated = LVM_FALSE;
383dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){
384dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
385dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
3862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
3873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n");
3882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
389163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
390dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // Disable effect, in this case ignore errors (return codes)
391dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // if an effect has already been disabled
392dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    Effect_setEnabled(pContext, LVM_FALSE);
393dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext
39529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    if ((pSessionContext->bBassInstantiated == LVM_FALSE) &&
39629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bVolumeInstantiated == LVM_FALSE) &&
39729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bEqualizerInstantiated ==LVM_FALSE) &&
39829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bVirtualizerInstantiated==LVM_FALSE))
3992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
4018f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr != NULL) {
4028f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
4038f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmInPtr = NULL;
4048f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
4058f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr != NULL) {
4068f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmOutPtr);
4078f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmOutPtr = NULL;
4088f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
410c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
411c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
412c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        // Clear the SessionIndex
413c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        for(int i=0; i<LVM_MAX_SESSIONS; i++){
414c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(SessionIndex[i] == pContext->pBundledContext->SessionId){
415e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                SessionIndex[i] = LVM_UNUSED_SESSION;
4163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffectRelease: Clearing SessionIndex SessionNo %d for SessionId %d\n",
417c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        i, pContext->pBundledContext->SessionId);
418c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                break;
419c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
420c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
421c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
4223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: All effects are no longer instantiated\n");
423dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pSessionContext->bBundledEffectsEnabled = LVM_FALSE;
42429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->pBundledContext = LVM_NULL;
4253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: Freeing LVM Bundle memory\n");
426163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmEffect_free(pContext);
4273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: Deleting LVM Bundle context %p\n", pContext->pBundledContext);
428dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->workBuffer != NULL) {
429dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            free(pContext->pBundledContext->workBuffer);
430dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
431163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        delete pContext->pBundledContext;
432c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = LVM_NULL;
4332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // free the effect context for current effect
4352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    delete pContext;
4362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectRelease end\n");
4382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
4392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectRelease */
4412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4425e92a7861196ddae14638d4b7a63fc4892b7ef59Glenn Kastenextern "C" int EffectGetDescriptor(const effect_uuid_t *uuid,
443e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                                   effect_descriptor_t *pDescriptor) {
444e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    const effect_descriptor_t *desc = NULL;
445e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
446e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pDescriptor == NULL || uuid == NULL){
4473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("EffectGetDescriptor() called with NULL pointer");
448e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return -EINVAL;
449e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
450e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
451e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
452e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gBassBoostDescriptor;
453e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
454e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gVirtualizerDescriptor;
455e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
456e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gEqualizerDescriptor;
457e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
458e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gVolumeDescriptor;
459e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
460e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
461e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (desc == NULL) {
462e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return  -EINVAL;
463e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
464e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
465a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pDescriptor = *desc;
466e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
467e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    return 0;
468e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent} /* end EffectGetDescriptor */
469e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
4702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init(){
4713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmGlobalBundle_init start");
4722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for(int i=0; i<LVM_MAX_SESSIONS; i++){
4732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBundledEffectsEnabled   = LVM_FALSE;
4742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVolumeInstantiated      = LVM_FALSE;
4752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bEqualizerInstantiated   = LVM_FALSE;
4762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBassInstantiated        = LVM_FALSE;
4772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE;
4782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].pBundledContext          = LVM_NULL;
479c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
480e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        SessionIndex[i] = LVM_UNUSED_SESSION;
4812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
4832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
4842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_init()
4862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Initialize engine with default configuration, creates instance
4882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// with all effects disabled.
4892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
4912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
4922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
4942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_init(EffectContext *pContext){
4982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status;
4992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init start");
5012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
502163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
503e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.inputCfg.channels                      = AUDIO_CHANNEL_OUT_STEREO;
504e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.inputCfg.format                        = AUDIO_FORMAT_PCM_16_BIT;
505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
511e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.outputCfg.channels                     = AUDIO_CHANNEL_OUT_STEREO;
512e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.outputCfg.format                       = AUDIO_FORMAT_PCM_16_BIT;
513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
514163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
516163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
5182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
5202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext->pBundledContext->hInstance != NULL){
5223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
5232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Calling pContext->pBassBoost->free()");
5242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmEffect_free(pContext);
5262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
5282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Called pContext->pBassBoost->free()");
5292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;          /* Function call status */
5322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                         /* Control Parameters */
5332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_InstParams_t        InstParams;                     /* Instance parameters */
5342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_EQNB_BandDef_t      BandDefs[MAX_NUM_BANDS];        /* Equaliser band definitions */
5352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomParams_t    HeadroomParams;                 /* Headroom parameters */
5362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomBandDef_t   HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS];
5372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;                         /* Memory allocation table */
5382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    bool                    bMallocFailure = LVM_FALSE;
5392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the capabilities */
541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    InstParams.BufferMode       = LVM_UNMANAGED_BUFFERS;
5422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.MaxBlockSize     = MAX_CALL_SIZE;
5432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.EQNB_NumBands    = MAX_NUM_BANDS;
5442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.PSA_Included     = LVM_PSA_ON;
5452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory, forcing alignment */
5472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(LVM_NULL,
5482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &MemTab,
5492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &InstParams);
5502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init")
5522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
5552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory */
5572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
5592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
5602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
5623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
563d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u\n", MemTab.Region[i].Size, i );
5642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                bMallocFailure = LVM_TRUE;
5652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
5663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLvmBundle_init CreateInstance allocated %ld bytes for region %u at %p\n",
5672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
5732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     * succesfully allocated and return with an error
5742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     */
5752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(bMallocFailure == LVM_TRUE){
5762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
5783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
579d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u Not freeing\n", MemTab.Region[i].Size, i );
5802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
5813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %ld bytes "
582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "for region %u at %p- free\n",
583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
5852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
5882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n");
5902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Initialise */
592163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->hInstance = LVM_NULL;
5932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Init sets the instance handle */
595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,
5962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &MemTab,
5972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &InstParams);
5982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init")
6002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
6032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the initial process parameters */
6052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* General parameters */
6062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.OperatingMode          = LVM_MODE_ON;
6072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SampleRate             = LVM_FS_44100;
6082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SourceFormat           = LVM_STEREO;
6092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SpeakerType            = LVM_HEADPHONES;
6102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->SampleRate = LVM_FS_44100;
612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Concert Sound parameters */
6142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerOperatingMode   = LVM_MODE_OFF;
6152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerType            = LVM_CONCERTSOUND;
6162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerReverbLevel     = 100;
617d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.CS_EffectLevel             = LVM_CS_EFFECT_NONE;
6182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* N-Band Equaliser parameters */
6202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_OperatingMode     = LVM_EQNB_OFF;
6212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_NBands            = FIVEBAND_NUMBANDS;
6222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.pEQNB_BandDefinition   = &BandDefs[0];
623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
6252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
6262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i];
6272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].QFactor   = EQNB_5BandPresetsQFactors[i];
628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        BandDefs[i].Gain      = EQNB_5BandSoftPresets[i];
6292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
6302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume Control parameters */
6322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_EffectLevel         = 0;
6332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_Balance             = 0;
6342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Treble Enhancement parameters */
6362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
6372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_EffectLevel         = 0;
6382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = (LVM_PSA_DecaySpeed_en)0;
6422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
6442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_OperatingMode       = LVM_BE_OFF;
6452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_EffectLevel         = 0;
6462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_CentreFreq          = LVM_BE_CENTRE_90Hz;
6472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_HPF                 = LVM_BE_HPF_ON;
6482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = LVM_PSA_SPEED_MEDIUM;
6522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
653d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    /* TE Control parameters */
654d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
655d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_EffectLevel         = 0;
656d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance,
6592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &params);
6602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init")
6622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n");
6652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the headroom parameters */
6672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_Low          = 20;
6682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_High         = 4999;
669e44615ff6022239850a3ea459ad6e07b44c37544Eric Laurent    HeadroomBandDef[0].Headroom_Offset    = 0;
6702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_Low          = 5000;
6712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_High         = 24000;
672e44615ff6022239850a3ea459ad6e07b44c37544Eric Laurent    HeadroomBandDef[1].Headroom_Offset    = 0;
6732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.pHeadroomDefinition    = &HeadroomBandDef[0];
6742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
6752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.NHeadroomBands         = 2;
6762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance,
6782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &HeadroomParams);
6792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init")
6812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n");
6843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init End");
6852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
6862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end LvmBundle_init */
6872c8e5cab3faa6d360e222b7a6c40a80083d021acEric 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{
7293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("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
7383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("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){
7763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\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;
7873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n");
7882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
7903856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST");
7912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_ON;
7922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
7943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER");
7952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_ON;
7962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
7983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER");
7992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_ON;
8002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
8023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\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
8093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n");
8103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\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){
8273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\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;
8373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n");
8382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
8403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST");
8412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_OFF;
8422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
8443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_VIRTUALIZER");
8452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_OFF;
8462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
8483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_EQUALIZER");
8492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_OFF;
8502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
8523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\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
8593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n");
8603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\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){
8913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\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
8963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\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{
8993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\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//----------------------------------------------------------------------------
9083d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Effect_setConfig()
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
9213d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentint Effect_setConfig(EffectContext *pContext, effect_config_t *pConfig){
922163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_Fs_en   SampleRate;
9233d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tEffect_setConfig 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);
931e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    CHECK_ARG(pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO);
9322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
9332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
934e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    CHECK_ARG(pConfig->inputCfg.format == AUDIO_FORMAT_PCM_16_BIT);
9352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
936a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    pContext->config = *pConfig;
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:
9643d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig 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
9733d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig 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
9793d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_setConfig")
980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9829f6f0a7eb1d7f2c35f3547779364a1a8d6d4a24cEric Laurent        ActiveParams.SampleRate = SampleRate;
9839f6f0a7eb1d7f2c35f3547779364a1a8d6d4a24cEric Laurent
984163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9863d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_setConfig")
9873d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig Succesfully called LVM_SetControlParameters\n");
988c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SampleRate = SampleRate;
9892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
990163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
9913d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        //ALOGV("\tEffect_setConfig keep sampling rate at %d", SampleRate);
992163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9943d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tEffect_setConfig End....");
995163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
9963d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent}   /* end Effect_setConfig */
9973d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
9983d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
9993d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Effect_getConfig()
10003d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
10013d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Purpose: Get input and output audio configuration.
10023d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10033d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Inputs:
10043d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//  pContext:   effect engine context
10053d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
10063d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//      configuration parameters
10073d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10083d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Outputs:
10093d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10103d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
10113d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
10123d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentvoid Effect_getConfig(EffectContext *pContext, effect_config_t *pConfig)
10133d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent{
1014a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pConfig = pContext->config;
10153d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent}   /* end Effect_getConfig */
10162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassGetStrength()
10192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
10222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
10232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the
10242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
10252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t BassGetStrength(EffectContext *pContext){
10323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved);
10332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
10352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1036163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength")
10412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
10422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n");
10442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Check that the strength returned matches the strength that was set earlier */
1046163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(ActiveParams.BE_EffectLevel !=
1047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){
10483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n",
10492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved);
10502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
10512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
10522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (saved)  -> %d\n", pContext->pBundledContext->BassStrengthSaved );
10552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return pContext->pBundledContext->BassStrengthSaved;
10562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassGetStrength */
10572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassSetStrength()
10602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15
10632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid BassSetStrength(EffectContext *pContext, uint32_t strength){
10713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength(%d)", strength);
10722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->BassStrengthSaved = (int)strength;
10742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength")
10833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n");
10842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
10862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_EffectLevel    = (LVM_INT16)((15*strength)/1000);
10872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_CentreFreq     = LVM_BE_CENTRE_90Hz;
10882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength")
10953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n");
10962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassSetStrength */
10972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerGetStrength()
11002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
11032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
1104163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the
11052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
11062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t VirtualizerGetStrength(EffectContext *pContext){
11133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved);
11142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
11162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
11172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength")
11212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
11222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n");
11243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength() (0-100)   -> %d\n", ActiveParams.VirtualizerReverbLevel*10);
1125d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    return pContext->pBundledContext->VirtStrengthSaved;
11262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getStrength */
11272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerSetStrength()
11302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15
11332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
11372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
11413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength(%d)", strength);
11422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
11442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1145163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->VirtStrengthSaved = (int)strength;
1146163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
11472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
11492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength")
11513856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n");
11522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Virtualizer parameters */
1154d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    ActiveParams.CS_EffectLevel             = (int)((strength*32767)/1000);
11552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength() (0-1000)   -> %d\n", strength );
11573856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength() (0- 100)   -> %d\n", ActiveParams.CS_EffectLevel );
11582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength")
11623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n\n");
11632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setStrength */
11642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11659b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
11662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11679b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// EqualizerLimitBandLevels()
11682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11690ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent// Purpose: limit all EQ band gains to a value less than 0 dB while
11709b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//          preserving the relative band levels.
11712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11789b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurentvoid EqualizerLimitBandLevels(EffectContext *pContext) {
11799b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11809b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
11812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11829b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    /* Get the current settings */
11839b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11849b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerLimitBandLevels")
11859b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels Succesfully returned from LVM_GetControlParameters\n");
11869b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels just Got -> %d\n",
11879b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //          ActiveParams.pEQNB_BandDefinition[band].Gain);
11889b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
11890ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // Apply a volume correction to avoid clipping in the EQ based on 2 factors:
11900ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // - the maximum EQ band gain: the volume correction is such that the total of volume + max
11910ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // band gain is <= 0 dB
11920ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // - the average gain in all bands weighted by their proximity to max gain band.
11930ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int maxGain = 0;
11940ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int avgGain = 0;
11950ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int avgCount = 0;
11969b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
11970ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        if (pContext->pBundledContext->bandGaindB[i] >= maxGain) {
11980ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpMaxGain = pContext->pBundledContext->bandGaindB[i];
11990ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpAvgGain = 0;
12000ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpAvgCount = 0;
12010ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            for (int j = 0; j < FIVEBAND_NUMBANDS; j++) {
12020ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                int gain = pContext->pBundledContext->bandGaindB[j];
12030ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // skip current band and gains < 0 dB
12040ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (j == i || gain < 0)
12050ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    continue;
12060ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // no need to continue if one band not processed yet has a higher gain than current
12070ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // max
12080ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (gain > tmpMaxGain) {
12090ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    // force skipping "if (tmpAvgGain >= avgGain)" below as tmpAvgGain is not
12100ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    // meaningful in this case
12110ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    tmpAvgGain = -1;
12120ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    break;
12130ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                }
12140ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12150ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                int weight = 1;
12160ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (j < (i + 2) && j > (i - 2))
12170ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    weight = 4;
12180ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                tmpAvgGain += weight * gain;
12190ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                tmpAvgCount += weight;
12200ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            }
12210ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            if (tmpAvgGain >= avgGain) {
12220ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                maxGain = tmpMaxGain;
12230ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                avgGain = tmpAvgGain;
12240ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                avgCount = tmpAvgCount;
12259b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent            }
12269b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        }
12270ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
12280ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
12290ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].Gain = pContext->pBundledContext->bandGaindB[i];
12309b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    }
12312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12320ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int gainCorrection = 0;
12330ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (maxGain + pContext->pBundledContext->volume > 0) {
12340ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        gainCorrection = maxGain + pContext->pBundledContext->volume;
12350ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
12360ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (avgCount) {
12370ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        gainCorrection += avgGain/avgCount;
12380ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
12390ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12400ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    ALOGV("EqualizerLimitBandLevels() gainCorrection %d maxGain %d avgGain %d avgCount %d",
12410ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            gainCorrection, maxGain, avgGain, avgCount);
12420ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12430ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    ActiveParams.VC_EffectLevel  = pContext->pBundledContext->volume - gainCorrection;
12440ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (ActiveParams.VC_EffectLevel < -96) {
12450ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.VC_EffectLevel = -96;
12469b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    }
12470ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12489b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    /* Activate the initial settings */
12499b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
12509b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerLimitBandLevels")
12519b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels just Set -> %d\n",
12529b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //          ActiveParams.pEQNB_BandDefinition[band].Gain);
12530ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12540ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    //ALOGV("\tEqualizerLimitBandLevels just set (-96dB -> 0dB)   -> %d\n",ActiveParams.VC_EffectLevel );
12550ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if(pContext->pBundledContext->firstVolume == LVM_TRUE){
12560ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams);
12570ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process")
12580ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ALOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks");
12590ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->firstVolume = LVM_FALSE;
12600ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
12619b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent}
12622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12639b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
12649b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
12659b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// EqualizerGetBandLevel()
12669b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
12679b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Purpose: Retrieve the gain currently being used for the band passed in
12689b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
12699b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Inputs:
12709b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//  band:       band number
12719b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//  pContext:   effect engine context
12729b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
12739b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Outputs:
12749b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
12759b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
12769b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurentint32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
12779b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerGetBandLevel -> %d\n", pContext->pBundledContext->bandGaindB[band] );
12789b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    return pContext->pBundledContext->bandGaindB[band] * 100;
12792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetBandLevel()
12832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Sets gain value for the given band.
12862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
12892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Gain:       Gain to be applied in millibels
12902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
12912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//---------------------------------------------------------------------------
1295d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurentvoid EqualizerSetBandLevel(EffectContext *pContext, int band, short Gain){
1296163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int gainRounded;
1297163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(Gain > 0){
1298163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain+50)/100);
1299163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1300163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain-50)/100);
1301163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
13023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);
13039b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    pContext->pBundledContext->bandGaindB[band] = gainRounded;
13042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
13059b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
13069b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
13072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13089b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
13092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetCentreFrequency()
13112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the frequency being used for the band passed in
13132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
13162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
13192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){
1322163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Frequency =0;
13232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1324163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1327163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1328163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1329163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
13302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency")
13322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1333163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef   = ActiveParams.pEQNB_BandDefinition;
1334163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Frequency = (int32_t)BandDef[band].Frequency*1000;     // Convert to millibels
13352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency );
13373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n");
1338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Frequency;
13392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandFreqRange(
13432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets lower and upper boundaries of a band.
13472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the high shelf, the low bound is the band frequency and the high
13482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// bound is Nyquist.
13492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the peaking filters, they are the gain[dB]/2 points.
13502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
13532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
13562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
13572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
13582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow,
1360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                  uint32_t *pHi){
1361163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pLow = bandFreqRange[band][0];
1362163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pHi  = bandFreqRange[band][1];
1363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
13642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBand(
13682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Returns the band with the maximum influence on a given frequency.
13722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Result is unaffected by whether EQ is enabled or not, or by whether
13732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// changes have been committed or not.
13742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  targetFreq   The target frequency, in millihertz.
13772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
13782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
13802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
13812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
13822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){
13842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int band = 0;
13852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1386163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(targetFreq < bandFreqRange[0][0]){
1387163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
1388163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if(targetFreq == bandFreqRange[0][0]){
1389163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
1390163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1391163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for(int i=0; i<FIVEBAND_NUMBANDS;i++){
1392163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){
1393163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            band = i;
1394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1395163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
13962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return band;
13972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPreset(
14012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets the currently set preset ID.
14052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Will return PRESET_CUSTOM in case the EQ parameters have been modified
14062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// manually since a preset was set.
14072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
14102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetPreset(EffectContext *pContext){
1413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return pContext->pBundledContext->CurPreset;
14142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
14152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetPreset(
14182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Sets the current preset by ID.
14222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// All the band parameters will be overridden.
14232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
14262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  preset       The preset ID.
14272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetPreset(EffectContext *pContext, int preset){
14302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetPreset(%d)", preset);
14322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = preset;
14332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    //ActiveParams.pEQNB_BandDefinition = &BandDefs[0];
14352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
14362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
14379b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        pContext->pBundledContext->bandGaindB[i] =
14389b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent                EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
14392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
14402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14419b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
14429b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
14442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
14452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
1446163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
14472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetNumPresets(){
1448163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return sizeof(gEqualizerPresets) / sizeof(PresetConfig);
14492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
14502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPresetName(
14532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets a human-readable name for a preset ID. Will return "Custom" if
14562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// PRESET_CUSTOM is passed.
14572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// preset       The preset ID. Must be less than number of presets.
14602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//-------------------------------------------------------------------------
14622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst char * EqualizerGetPresetName(int32_t preset){
14633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetPresetName start(%d)", preset);
14642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (preset == PRESET_CUSTOM) {
14652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return "Custom";
14662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
14672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return gEqualizerPresets[preset].name;
14682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
14693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetPresetName end(%d)", preset);
1470163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
14712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
14722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetVolumeLevel()
14752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  level       level to be applied
14812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
14852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14860ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (level > 0 || level < -9600) {
14870ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        return -EINVAL;
14880ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
1489163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
14900ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (pContext->pBundledContext->bMuteEnabled == LVM_TRUE) {
14910ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->levelSaved = level / 100;
14920ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    } else {
14930ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = level / 100;
1494d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    }
14959b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14969b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
14979b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
149917a736c3e1d062d7fc916329eb32aef8935614afGlenn Kasten}    /* end VolumeSetVolumeLevel */
15002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeGetVolumeLevel()
15032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){
15122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15130ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (pContext->pBundledContext->bMuteEnabled == LVM_TRUE) {
15140ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        *level = pContext->pBundledContext->levelSaved * 100;
15150ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    } else {
15160ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        *level = pContext->pBundledContext->volume * 100;
15170ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
15182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
15192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end VolumeGetVolumeLevel */
15202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetMute()
15232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
15292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){
15333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetMute start(%d)", mute);
15342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->bMuteEnabled = mute;
15362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set appropriate volume level */
15382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){
15390ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->levelSaved = pContext->pBundledContext->volume;
15400ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = -96;
15412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
15420ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = pContext->pBundledContext->levelSaved;
15432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
15442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15450ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    EqualizerLimitBandLevels(pContext);
15462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
15482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setMute */
15492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetMute()
15522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Ourputs:
15592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
15602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){
15633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetMute start");
1564163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||
1565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){
1566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        *mute = pContext->pBundledContext->bMuteEnabled;
1567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
15682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
15693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d",
1570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent              pContext->pBundledContext->bMuteEnabled);
1571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
15722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
15733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetMute end");
15742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getMute */
15752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1576163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint16_t VolumeConvertStereoPosition(int16_t position){
1577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t convertedPosition = 0;
1578163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    convertedPosition = (int16_t)(((float)position/1000)*96);
1580163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return convertedPosition;
1581163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
1583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1584163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeSetStereoPosition()
1586163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1591163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1592163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1596163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint VolumeSetStereoPosition(EffectContext *pContext, int16_t position){
1597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1598163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               Balance = 0;
1601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1602c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1604163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->positionSaved = position;
1605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1606163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1608d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1609163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance);
1613163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved = position;
1614163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1615163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:"
1619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     " %d\n", ActiveParams.VC_Balance);
1620163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Volume parameters */
1622163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  = Balance;
16233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB)   -> %d\n", ActiveParams.VC_Balance );
1624163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Activate the initial settings */
1626163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1627163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
1628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n");
16312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: "
1637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     "%d\n", ActiveParams.VC_Balance);
1638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    else{
16403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n",
1641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //position, Balance);
1642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
16433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n",
1644d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1645163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeSetStereoPosition */
16472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetStereoPosition()
1651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1652163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1653163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1654163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1655163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
16602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1661163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){
16623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition start");
16632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               balance;
1667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1669d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1670163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
1673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance);
16763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1677163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(balance != ActiveParams.VC_Balance){
1682163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
1683163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *position = (LVM_INT16)pContext->pBundledContext->positionSaved;     // Convert dB to millibels
16863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved =%d\n",
1687d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1688163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1689163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeGetStereoPosition */
16902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1691163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeEnableStereoPosition()
1693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1694163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1695163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:   effect engine context
1698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  mute:       enable/disable flag
1699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
17012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1702163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){
17033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition start()");
17042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1705163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->bStereoPositionEnabled = enabled;
17062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1707163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
17092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1710163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1711163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1712163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition")
1713163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
17142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n");
17163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition to %d, position was %d\n",
1717163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //     enabled, ActiveParams.VC_Balance );
17182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1719163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Set appropriate stereo position */
1720163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){
1721163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance = 0;
1722163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  =
1724163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                            VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1725163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
17262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1727163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
1728163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1729163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition")
1730163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
17312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n");
17333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition end()\n");
1734163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1735163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeEnableStereoPosition */
17362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_getParameter()
17392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a BassBoost parameter
17422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
17452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
17472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
17482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
17512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
17522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
17552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_getParameter(EffectContext     *pContext,
1759c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
1760163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           size_t            *pValueSize,
1761163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           void              *pValue){
17622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1763c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1764c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
17652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
17662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
17672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_getParameter start");
17692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
177123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17727fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
17733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize1 %d", *pValueSize);
17747fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
17757fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
17767fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
17777fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
17782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
17803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize2 %d", *pValueSize);
17812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
17822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
17832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
17842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
17892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
179223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
17942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d",
1796163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
17972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
18002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = BassGetStrength(pContext);
18012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d",
1803163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
18042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
18082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
18092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_getParameter end");
18132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_getParameter */
18152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_setParameter()
18182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a BassBoost parameter
18212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
18242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
18262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1831c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue){
18322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
18332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1834c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
18352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_setParameter start");
18372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1838c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (*pParamTemp){
18392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
18402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
18413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength);
18423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength");
18432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            BassSetStrength(pContext, (int32_t)strength);
18443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength");
18452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
18462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParamTemp);
18482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18513856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_setParameter end");
18522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_setParameter */
18542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_getParameter()
18572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Virtualizer parameter
18602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
18632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
18652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
18662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
18692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
18702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
18732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_getParameter(EffectContext        *pContext,
1877c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void                 *pParam,
18782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             size_t               *pValueSize,
18792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             void                 *pValue){
18802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1881c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1882c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
18832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
18842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
18852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_getParameter start");
18872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
188923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18907fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
18913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
18927fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
18937fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
18947fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
18957fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
18962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
18983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize2 %d",*pValueSize);
18992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
19002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
19012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
19022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
19053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
19062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
191023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
19112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
19122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d",
1914163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
19152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
19182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = VirtualizerGetStrength(pContext);
19192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19203856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d",
1921163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
19222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
19253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
19262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
19272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_getParameter end");
19312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_getParameter */
19332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_setParameter()
19362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Virtualizer parameter
19392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
19422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
19442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1949c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
19502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
19512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1952c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1953c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
19542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_setParameter start");
19562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1957c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
19582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
19592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
19603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength);
19613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength");
19622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            VirtualizerSetStrength(pContext, (int32_t)strength);
19633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength");
19642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
19652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
19663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", param);
19672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_setParameter end");
19712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_setParameter */
19732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_getParameter()
19762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Equalizer parameter
19792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer       - handle to instance data
19822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
19842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
19852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
19882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
19892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
19922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_getParameter(EffectContext     *pContext,
1995c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
19962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           size_t            *pValueSize,
19972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           void              *pValue){
19982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
19992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2000c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2001c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
20022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
20032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
20042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_getParameter start");
20062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
20082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
20092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
20102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
20113be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_BAND_LEVEL:
20123be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_GET_BAND:
20132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int16_t)) {
20143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
20152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int16_t);
20182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
20213be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (*pValueSize < 2 * sizeof(int16_t)) {
20223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
20233be9523784cc4038f601e510faee595117cdacb3Eric Laurent            return -EINVAL;
20243be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
20253be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *pValueSize = 2 * sizeof(int16_t);
20263be9523784cc4038f601e510faee595117cdacb3Eric Laurent        break;
20272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
20282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < 2 * sizeof(int32_t)) {
20293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 3  %d", *pValueSize);
20302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = 2 * sizeof(int32_t);
20332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20343be9523784cc4038f601e510faee595117cdacb3Eric Laurent
20352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
20362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int32_t)) {
20373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 5  %d", *pValueSize);
20382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int32_t);
20412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
20442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
204623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES:
204723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) {
20483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
204923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            return -EINVAL;
205023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
205123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t);
205223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        break;
205323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
20542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
20553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param);
20562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
20572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
20602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
20613be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS;
20623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue);
20632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
20663be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = -1500;
20673be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *((int16_t *)pValue + 1) = 1500;
20683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d",
2069d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      *(int16_t *)pValue, *((int16_t *)pValue + 1));
20702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2073c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20783be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2);
20793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d",
2080163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
2084c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2);
20903856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d",
2091163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
2095c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1));
21013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d",
2102163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue, *((int32_t *)pValue + 1));
21032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_BAND:
2106c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
21073be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2);
21083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d",
2109d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      param2, *(uint16_t *)pValue);
21102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
21133be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext);
21143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue);
21152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
21183be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets();
21193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue);
21202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
2123c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
21242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= EqualizerGetNumPresets()) {
21252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        //if (param2 >= 20) {     // AGO FIX
21262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name = (char *)pValue;
21302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1);
21312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name[*pValueSize - 1] = 0;
21322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = strlen(name) + 1;
21333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d",
2134163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, gEqualizerPresets[param2].name, *pValueSize);
21352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
213723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES: {
21383be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
21393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES");
21403be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[0] = (int16_t)EqualizerGetPreset(pContext);
21413be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[1] = (int16_t)FIVEBAND_NUMBANDS;
214223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
21433be9523784cc4038f601e510faee595117cdacb3Eric Laurent            p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i);
214423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
214523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    } break;
214623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
21472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
21483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param);
21492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        status = -EINVAL;
21502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2153d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //GV("\tEqualizer_getParameter end\n");
21542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_getParameter */
21562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_setParameter()
21592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Equalizer parameter
21622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer    - handle to instance data
21652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
21662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
21672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
2171c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
21722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t preset;
21742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t band;
21752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t level;
2176c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2177c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
2178c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
21792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_setParameter start");
21812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
21822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
21833be9523784cc4038f601e510faee595117cdacb3Eric Laurent        preset = (int32_t)(*(uint16_t *)pValue);
21842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset);
21862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if ((preset >= EqualizerGetNumPresets())||(preset < 0)) {
21872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetPreset(pContext, preset);
21912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2193c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        band =  *pParamTemp;
21943be9523784cc4038f601e510faee595117cdacb3Eric Laurent        level = (int32_t)(*(int16_t *)pValue);
21953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level);
21962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (band >= FIVEBAND_NUMBANDS) {
21972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
22002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetBandLevel(pContext, band, level);
22012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22023be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_PROPERTIES: {
22033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES");
22043be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
22053be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if ((int)p[0] >= EqualizerGetNumPresets()) {
22063be9523784cc4038f601e510faee595117cdacb3Eric Laurent            status = -EINVAL;
22073be9523784cc4038f601e510faee595117cdacb3Eric Laurent            break;
22083be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
22093be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (p[0] >= 0) {
22103be9523784cc4038f601e510faee595117cdacb3Eric Laurent            EqualizerSetPreset(pContext, (int)p[0]);
22113be9523784cc4038f601e510faee595117cdacb3Eric Laurent        } else {
22123be9523784cc4038f601e510faee595117cdacb3Eric Laurent            if ((int)p[1] != FIVEBAND_NUMBANDS) {
22133be9523784cc4038f601e510faee595117cdacb3Eric Laurent                status = -EINVAL;
22143be9523784cc4038f601e510faee595117cdacb3Eric Laurent                break;
22153be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
22163be9523784cc4038f601e510faee595117cdacb3Eric Laurent            for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
22173be9523784cc4038f601e510faee595117cdacb3Eric Laurent                EqualizerSetBandLevel(pContext, i, (int)p[2 + i]);
22183be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
22193be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
22203be9523784cc4038f601e510faee595117cdacb3Eric Laurent    } break;
22212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
22223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_setParameter() invalid param %d", param);
22233be9523784cc4038f601e510faee595117cdacb3Eric Laurent        status = -EINVAL;
22242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_setParameter end");
22282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
22292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_setParameter */
22302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_getParameter()
22332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
22352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Volume parameter
22362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
22382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume          - handle to instance data
22392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
22402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
22412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
22422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
22442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
22452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
22462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
22492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_getParameter(EffectContext     *pContext,
2253c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void              *pParam,
22542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        size_t            *pValueSize,
22552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        void              *pValue){
22562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
22572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2258c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2259c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;;
22602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
22612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_getParameter start");
22632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2268163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if (*pValueSize != sizeof(int16_t)){
22693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1  %d", *pValueSize);
22702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
22732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
22762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
22772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize < sizeof(int32_t)){
22783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2  %d", *pValueSize);
22792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int32_t);
22822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
22853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param);
22862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue));
22923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d",
2293d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = 0;
22983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d",
2299d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
23002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2303163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            VolumeGetStereoPosition(pContext, (int16_t *)pValue);
23043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d",
2305d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
23062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2309163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeGetMute(pContext, (uint32_t *)pValue);
23103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d",
2311163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(uint32_t *)pValue);
23122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2315163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled;
23163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d",
2317d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(uint32_t *)pValue);
23182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
23213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param);
23222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
23232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_getParameter end");
23272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_getParameter */
23292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_setParameter()
23332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
23352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Volume parameter
23362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
23382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume       - handle to instance data
23392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
23402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
23412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
23432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2346c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue){
23472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int      status = 0;
23482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t  level;
2349163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t  position;
23502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    uint32_t mute;
2351163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    uint32_t positionEnabled;
2352c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2353c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
23542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_setParameter start");
23562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2357c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
23582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
23592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            level = *(int16_t *)pValue;
23603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level);
23613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel");
23622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeSetVolumeLevel(pContext, (int16_t)level);
23633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel");
23642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            mute = *(uint32_t *)pValue;
23683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute);
23693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setMute");
2370163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetMute(pContext, mute);
23713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->setMute");
2372163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2375163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            positionEnabled = *(uint32_t *)pValue;
2376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeEnableStereoPosition(pContext, positionEnabled);
2377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved);
23783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called");
2379163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2382163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            position = *(int16_t *)pValue;
23833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position);
23843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition");
2385163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, (int16_t)position);
23863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition");
2387163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
23903856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", param);
23912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_setParameter end");
23952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_setParameter */
23972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2398163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent/****************************************************************************************
2399163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent * Name : LVC_ToDB_s32Tos16()
2400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Input       : Signed 32-bit integer
2401163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Output      : Signed 16-bit integer
2402163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  MSB (16) = sign bit
2403163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (15->05) = integer part
2404163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (04->01) = decimal part
2405163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Returns     : Db value with respect to full scale
2406163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Description :
2407163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Remarks     :
2408163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent ****************************************************************************************/
2409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2410163fbcf84010b98e0374110454d85b804bc8d13bEric LaurentLVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix)
2411163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent{
2412163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   db_fix;
2413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   Shift;
2414163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   SmallRemainder;
2415163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_UINT32  Remainder = (LVM_UINT32)Lin_fix;
2416163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2417163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Count leading bits, 1 cycle in assembly*/
2418163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for (Shift = 0; Shift<32; Shift++)
2419163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
2420163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if ((Remainder & 0x80000000U)!=0)
2421163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2422163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2423163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2424163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        Remainder = Remainder << 1;
2425163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
24262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2427163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /*
2428163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * Based on the approximation equation (for Q11.4 format):
2429163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     *
2430163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2)
2431163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     */
2432163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix    = (LVM_INT16)(-96 * Shift);               /* Six dB steps in Q11.4 format*/
2433163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24);
2434163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix + SmallRemainder );
2435163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder);
2436163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9));
24372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2438163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Correct for small offset */
2439163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - 5);
24402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2441163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return db_fix;
2442163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
24432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
244429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
244529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Effect_setEnabled()
244629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
244729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Purpose:
244829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Enable or disable effect
244929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
245029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Inputs:
245129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//  pContext      - pointer to effect context
245229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//  enabled       - true if enabling the effect, false otherwise
245329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
245429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Outputs:
245529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
245629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
245729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
245829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurentint Effect_setEnabled(EffectContext *pContext, bool enabled)
245929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent{
24603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffect_setEnabled() type %d, enabled %d", pContext->EffectType, enabled);
246129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
246229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    if (enabled) {
2463b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        // Bass boost or Virtualizer can be temporarily disabled if playing over device speaker due
2464b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        // to their nature.
2465b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        bool tempDisabled = false;
246629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        switch (pContext->EffectType) {
246729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_BASS_BOOST:
246829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
24693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                     ALOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already enabled");
247029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     return -EINVAL;
247129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2472dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountBb <= 0){
2473dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2474dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
247529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountBb =
247629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
247729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bBassEnabled = LVM_TRUE;
2478b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                tempDisabled = pContext->pBundledContext->bBassTempDisabled;
247929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
248029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_EQUALIZER:
248129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE) {
24823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_EQUALIZER is already enabled");
248329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
248429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2485dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountEq <= 0){
2486dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2487dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
248829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountEq =
248929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
249029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE;
249129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
249229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VIRTUALIZER:
249329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) {
24943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already enabled");
249529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
249629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2497dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountVirt <= 0){
2498dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2499dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
250029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountVirt =
250129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
250229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE;
2503b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                tempDisabled = pContext->pBundledContext->bVirtualizerTempDisabled;
250429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
250529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VOLUME:
250629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE) {
25073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VOLUME is already enabled");
250829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
250929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2510dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                pContext->pBundledContext->NumberEffectsEnabled++;
251129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVolumeEnabled = LVM_TRUE;
251229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
251329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            default:
25143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffect_setEnabled() invalid effect type");
251529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                return -EINVAL;
251629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        }
2517b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        if (!tempDisabled) {
2518b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            LvmEffect_enable(pContext);
2519b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        }
252029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    } else {
252129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        switch (pContext->EffectType) {
252229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_BASS_BOOST:
252329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bBassEnabled == LVM_FALSE) {
25243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already disabled");
252529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
252629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
252729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bBassEnabled = LVM_FALSE;
252829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
252929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_EQUALIZER:
253029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE) {
25313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_EQUALIZER is already disabled");
253229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
253329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
253429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE;
253529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
253629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VIRTUALIZER:
253729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE) {
25383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already disabled");
253929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
254029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
254129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE;
254229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
254329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VOLUME:
254429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVolumeEnabled == LVM_FALSE) {
25453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VOLUME is already disabled");
254629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
254729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
254829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVolumeEnabled = LVM_FALSE;
254929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
255029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            default:
25513856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffect_setEnabled() invalid effect type");
255229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                return -EINVAL;
255329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        }
255429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        LvmEffect_disable(pContext);
255529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    }
255629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
255729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    return 0;
255829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent}
255929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
2560dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//----------------------------------------------------------------------------
2561dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// LVC_Convert_VolToDb()
2562dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//----------------------------------------------------------------------------
2563dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Purpose:
2564dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Convery volume in Q24 to dB
2565dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//
2566dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Inputs:
2567dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//  vol:   Q.24 volume dB
2568dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//
2569dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//-----------------------------------------------------------------------
2570dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2571dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentint16_t LVC_Convert_VolToDb(uint32_t vol){
2572dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    int16_t  dB;
2573dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2574dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = LVC_ToDB_s32Tos16(vol <<7);
2575dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = (dB +8)>>4;
2576dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = (dB <-96) ? -96 : dB ;
2577dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2578dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return dB;
2579dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent}
2580dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2581163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
2582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
25832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2584e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentextern "C" {
25852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Process */
2586e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_process(effect_handle_t     self,
2587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *inBuffer,
2588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *outBuffer){
25892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
2590c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
25912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int    status = 0;
2592163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int    lvmStatus = 0;
2593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *in  = (LVM_INT16 *)inBuffer->raw;
2594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *out = (LVM_INT16 *)outBuffer->raw;
25952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block//ALOGV("\tEffect_process Start : Enabled = %d     Called = %d (%8d %8d %8d)",
2597dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled,
2598c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountBb,
2599c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountVirt,
2600c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountEq);
2601c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
26022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
26033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL");
26042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
26052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2606dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2607dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //if(pContext->EffectType == LVM_BASS_BOOST){
26083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is BASS_BOOST");
2609dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}else if(pContext->EffectType == LVM_EQUALIZER){
26103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is LVM_EQUALIZER");
2611dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}else if(pContext->EffectType == LVM_VIRTUALIZER){
26123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is LVM_VIRTUALIZER");
2613dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}
2614dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
26152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
26162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
26172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            inBuffer->frameCount != outBuffer->frameCount){
26183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
26192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
26202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&
2622163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_BASS_BOOST)){
26233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_BASS_BOOST Effect is not enabled");
2624c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
2625c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO
26263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting to turn off BASS_BOOST, %d samples left",
2627c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountBb);
2628d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2629d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb <= 0) {
263029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            status = -ENODATA;
2631dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
26323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_BASS_BOOST");
2633c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
2634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&
2636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VOLUME)){
26373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_VOLUME Effect is not enabled");
2638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2639dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->NumberEffectsEnabled--;
2640163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&
2642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_EQUALIZER)){
26433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_EQUALIZER Effect is not enabled");
2644c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
2645c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq -= outBuffer->frameCount * 2; // STEREO
26463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting to turn off EQUALIZER, %d samples left",
2647c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountEq);
2648d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2649d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq <= 0) {
2650c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2651dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
26523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_EQUALIZER");
2653c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
26542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2655163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&
2656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VIRTUALIZER)){
26573856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_VIRTUALIZER Effect is not enabled");
2658c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
2659c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt -= outBuffer->frameCount * 2;// STEREO
26603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting for to turn off VIRTUALIZER, %d samples left",
2661c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountVirt);
2662d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2663d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt <= 0) {
2664c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2665dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
26663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_VIRTUALIZER");
2667c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
26682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2669163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2670dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if(status != -ENODATA){
2671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled++;
26722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
26732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->NumberEffectsCalled ==
2675163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       pContext->pBundledContext->NumberEffectsEnabled){
26763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process     Calling process with %d effects enabled, %d called: Effect %d",
2677163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
26792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(status == -ENODATA){
26813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() processing last frame");
2682163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
26832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext->NumberEffectsCalled = 0;
2684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Process all the available frames, block processing is
2685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           handled internalLY by the LVM bundle */
2686163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        lvmStatus = android::LvmBundle_process(    (LVM_INT16 *)inBuffer->raw,
26872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                (LVM_INT16 *)outBuffer->raw,
26882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                outBuffer->frameCount,
26892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                pContext);
2690163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(lvmStatus != LVM_SUCCESS){
26913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
2692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return lvmStatus;
2693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
26945dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    } else {
26953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
2696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
2698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        // 2 is for stereo input
26995dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
27005dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            for (size_t i=0; i < outBuffer->frameCount*2; i++){
27015dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent                outBuffer->s16[i] =
27025dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent                        clamp16((LVM_INT32)outBuffer->s16[i] + (LVM_INT32)inBuffer->s16[i]);
27035dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            }
270497bb6e89845cb6d85f4d34a4efcc1de2ce585336Marco Nelissen        } else if (outBuffer->raw != inBuffer->raw) {
27055dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
27065dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent        }
27072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
27092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
27102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end Effect_process */
27112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Command */
2713e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_command(effect_handle_t  self,
271425f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdCode,
271525f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdSize,
2716163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pCmdData,
271725f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            *replySize,
2718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pReplyData){
27192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
27202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int retsize;
27212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\t\nEffect_command start");
27232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST){
27253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_BASS_BOOST");
27262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
27272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER){
27283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_VIRTUALIZER");
2729163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
27302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER){
27313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_EQUALIZER");
2732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
27332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME){
27343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_VOLUME");
2735163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
27362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
27383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL");
27392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
27402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
27412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
27432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2744163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // Incase we disable an effect, next time process is
2745163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // called the number of effect called could be greater
2746163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // pContext->pBundledContext->NumberEffectsCalled = 0;
27472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d",
2749163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsCalled,
2750163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsEnabled);
27512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (cmdCode){
27532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_INIT:
2754010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
27553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d",
2756010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                        pContext->EffectType);
2757010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                return -EINVAL;
2758010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            }
2759010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            *(int *) pReplyData = 0;
27603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start");
27612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
27623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST");
27632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                android::BassSetStrength(pContext, 0);
27642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
27663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER");
2767163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::VirtualizerSetStrength(pContext, 0);
2768163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
27703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER");
2771163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::EqualizerSetPreset(pContext, 0);
2772163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
27743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VOLUME");
2775010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0);
2776163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2778163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
27793d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        case EFFECT_CMD_SET_CONFIG:
27803d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_CONFIG start");
27812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pCmdData    == NULL||
27822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                cmdSize     != sizeof(effect_config_t)||
27832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                pReplyData  == NULL||
27842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize  != sizeof(int)){
27853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
27863d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                        "EFFECT_CMD_SET_CONFIG: ERROR");
27873d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                return -EINVAL;
27883d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            }
27893d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            *(int *) pReplyData = android::Effect_setConfig(pContext, (effect_config_t *) pCmdData);
27903d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_CONFIG end");
27913d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            break;
27923d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
27933d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        case EFFECT_CMD_GET_CONFIG:
27943d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            if (pReplyData == NULL ||
27953d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                *replySize != sizeof(effect_config_t)) {
27963d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
27973d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                        "EFFECT_CMD_GET_CONFIG: ERROR");
27982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
27992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28003d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
28013d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            android::Effect_getConfig(pContext, (effect_config_t *)pReplyData);
28022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
28032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_RESET:
28053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start");
28063d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            android::Effect_setConfig(pContext, &pContext->config);
28073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end");
28082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
28092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_GET_PARAM:{
28113856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2812163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2814163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2815163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2816163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2817163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
28183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
28192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
28202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
28232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
28252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
28272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
28292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::BassBoost_getParameter(pContext,
2831c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
28322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            (size_t  *)&p->vsize,
28332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            p->data + voffset);
28342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
28362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM "
2838163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2839163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2840163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2841163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
28422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
2843163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2845163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2846163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2847163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2848163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
28493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
28502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
28512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
28542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
28562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
28582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
28602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Virtualizer_getParameter(pContext,
2862c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                             (void *)p->data,
28632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                             (size_t  *)&p->vsize,
28642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                              p->data + voffset);
28652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
28672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM "
2869163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2870163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2871163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2872163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
28732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
28753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEqualizer_command cmdCode Case: "
2876163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2877163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2878163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2879163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL ||
2880163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) {
28813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
28822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM");
28832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
2886163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
2888163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
2890163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
2892163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2893c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                p->status = android::Equalizer_getParameter(pContext,
2894c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
2895c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            &p->vsize,
2896c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data + voffset);
2897163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
2899163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
29003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, "
2901163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //       "*pReplyData %08x %08x",
2902163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize,
2903163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset),
2904163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset +
2905163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        sizeof(int32_t)));
29062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
29072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
29083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2909163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2910163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2912163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
29133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
29142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
29152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
29182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
29202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
29222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
29242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Volume_getParameter(pContext,
2926c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                         (void *)p->data,
29272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         (size_t  *)&p->vsize,
29282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         p->data + voffset);
29292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
29312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command EFFECT_CMD_GET_PARAM "
2933163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2934163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2935163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2936163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
2937163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end");
29392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
29402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_PARAM:{
29413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
29422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
29433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2944dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2945dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *replySize,
2946dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2951163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
29523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
29532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
29542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
29572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
29593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
29602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
29612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tnBassBoost_command cmdSize is %d\n"
2965163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2967163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2969163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
29702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::BassBoost_setParameter(pContext,
2972c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
29732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    p->data + p->psize);
29742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
29752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
29763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block              //ALOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2977d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2978d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *replySize,
2979d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2982163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2983163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2984163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
29853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
29872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
29902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
29923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
29942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29973856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tnVirtualizer_command cmdSize is %d\n"
2998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2999163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
3000163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
3001163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
3002163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
30032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Virtualizer_setParameter(pContext,
3005c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                      (void *)p->data,
3006163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                       p->data + p->psize);
30072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
30082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
30093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block               //ALOGV("\tEqualizer_command cmdCode Case: "
3010d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        "EFFECT_CMD_SET_PARAM start");
30113856b090cd04ba5dd4a59a12430ed724d5995909Steve Block               //ALOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
3012d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3013d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *replySize,
3014d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
30152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
30172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pReplyData == NULL || *replySize != sizeof(int32_t)) {
30183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
30192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
30202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
30212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
30222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
30232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Equalizer_setParameter(pContext,
3025c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
3026163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                     p->data + p->psize);
30272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
30282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
30293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
30303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
3031163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
3033d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) +sizeof(int32_t)));
30342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (    pCmdData   == NULL||
30362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        cmdSize    < (int)(sizeof(effect_param_t) + sizeof(int32_t))||
30372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        pReplyData == NULL||
30382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        *replySize != sizeof(int32_t)){
30393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
30402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
30412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
30422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
30432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
30442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Volume_setParameter(pContext,
3046c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                 (void *)p->data,
3047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                 p->data + p->psize);
3048163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
30493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end");
30502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
30512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_ENABLE:
30533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start");
30542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
30553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
30562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
3057163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
305829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
305929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_TRUE);
30602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3061163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
30622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_DISABLE:
30633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start");
30642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
30653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
30662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
3067163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
306829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_FALSE);
30692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
30702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_DEVICE:
3072163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
30733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start");
3074e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            uint32_t device = *(uint32_t *)pCmdData;
3075163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3076b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            if (pContext->EffectType == LVM_BASS_BOOST) {
3077b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                if((device == AUDIO_DEVICE_OUT_SPEAKER) ||
3078b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) ||
3079b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
30803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d",
3081163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
30823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST");
3083163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3084163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device doesnt support bassboost the effect must be temporarily disabled
3085163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3086163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3087163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3088b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
30893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d",
3090163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3091163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3092163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3093b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bBassTempDisabled = LVM_TRUE;
3094b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                } else {
30953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d",
3096163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                         *(int32_t *)pCmdData);
3097163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3098163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports bassboost and the effect has been temporarily disabled
3099163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3100163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3101b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
31023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d",
3103163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3104163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3105163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3106b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bBassTempDisabled = LVM_FALSE;
3107163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3108163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3109b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            if (pContext->EffectType == LVM_VIRTUALIZER) {
3110b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                if((device == AUDIO_DEVICE_OUT_SPEAKER)||
3111b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)||
3112b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
31133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d",
3114163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
31153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER");
3116163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3117163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //If a device doesnt support virtualizer the effect must be temporarily disabled
3118163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3119163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3120163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3121b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) {
31223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d",
3123163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3124163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3125163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3126b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
3127b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                } else {
31283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d",
3129163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3130163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3131163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports virtualizer and the effect has been temporarily disabled
3132163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3133163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3134b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
31353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d",
3136163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3137163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3138163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3139b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
3140163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3141163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
31423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end");
31432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3144163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
3145163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_VOLUME:
3146163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
3147dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            uint32_t leftVolume, rightVolume;
3148dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int16_t  leftdB, rightdB;
3149dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int16_t  maxdB, pandB;
3150dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int32_t  vol_ret[2] = {1<<24,1<<24}; // Apply no volume
3151dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int      status = 0;
3152dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ControlParams_t     ActiveParams;           /* Current control Parameters */
3153dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;  /* Function call status */
3154163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3155163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // if pReplyData is NULL, VOL_CTRL is delegated to another effect
3156163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pReplyData == LVM_NULL){
3157163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                break;
3158163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
31592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3160dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (pCmdData == NULL ||
3161dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                cmdSize != 2 * sizeof(uint32_t)) {
31623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
3163dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                        "EFFECT_CMD_SET_VOLUME: ERROR");
3164dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                return -EINVAL;
3165163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3166163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3167dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            leftVolume  = ((*(uint32_t *)pCmdData));
3168dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            rightVolume = ((*((uint32_t *)pCmdData + 1)));
3169dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3170dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(leftVolume == 0x1000000){
3171dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                leftVolume -= 1;
3172dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3173dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(rightVolume == 0x1000000){
3174dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                rightVolume -= 1;
3175dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3176dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3177dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            // Convert volume to dB
3178dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            leftdB  = android::LVC_Convert_VolToDb(leftVolume);
3179dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            rightdB = android::LVC_Convert_VolToDb(rightVolume);
3180dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3181dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pandB = rightdB - leftdB;
3182dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3183dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            // Calculate max volume in dB
3184dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            maxdB = leftdB;
3185dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(rightdB > maxdB){
3186dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                maxdB = rightdB;
3187dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
31883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME Session: %d, SessionID: %d VOLUME is %d dB (%d), "
3189dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //      "effect is %d",
3190dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //pContext->pBundledContext->SessionNo, pContext->pBundledContext->SessionId,
3191dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //(int32_t)maxdB, maxVol<<7, pContext->EffectType);
31923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME: Left is %d, Right is %d", leftVolume, rightVolume);
31933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME: Left %ddB, Right %ddB, Position %ddB",
3194dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //        leftdB, rightdB, pandB);
3195d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
3196163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            memcpy(pReplyData, vol_ret, sizeof(int32_t)*2);
3197dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            android::VolumeSetVolumeLevel(pContext, (int16_t)(maxdB*100));
3198dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3199dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Get the current settings */
3200dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LvmStatus =LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
3201dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
3202dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(LvmStatus != LVM_SUCCESS) return -EINVAL;
3203dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3204dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Volume parameters */
3205dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            ActiveParams.VC_Balance  = pandB;
32063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\t\tVolumeSetStereoPosition() (-96dB -> +96dB)-> %d\n", ActiveParams.VC_Balance );
3207dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3208dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Activate the initial settings */
3209dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LvmStatus =LVM_SetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
3210dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
3211dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(LvmStatus != LVM_SUCCESS) return -EINVAL;
3212163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
3213163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent         }
3214163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
3215163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
32162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
32172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
32182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
32192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32203856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command end...\n\n");
32212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
32222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end Effect_command */
32232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3224e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent/* Effect Control Interface Implementation: get_descriptor */
3225e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_getDescriptor(effect_handle_t   self,
3226e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                                    effect_descriptor_t *pDescriptor)
3227e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent{
3228e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    EffectContext * pContext = (EffectContext *) self;
3229e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    const effect_descriptor_t *desc;
3230e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3231e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pContext == NULL || pDescriptor == NULL) {
32323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("Effect_getDescriptor() invalid param");
3233e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return -EINVAL;
3234e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
3235e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3236e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    switch(pContext->EffectType) {
3237e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_BASS_BOOST:
3238e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gBassBoostDescriptor;
3239e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3240e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_VIRTUALIZER:
3241e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gVirtualizerDescriptor;
3242e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3243e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_EQUALIZER:
3244e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gEqualizerDescriptor;
3245e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3246e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_VOLUME:
3247e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gVolumeDescriptor;
3248e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3249e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        default:
3250e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            return -EINVAL;
3251e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
3252e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3253a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pDescriptor = *desc;
3254e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3255e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    return 0;
3256e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent}   /* end Effect_getDescriptor */
3257e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3258e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent// effect_handle_t interface implementation for effect
32592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst struct effect_interface_s gLvmEffectInterface = {
32602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_process,
3261e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    Effect_command,
3262ba7b8f881a9b6b21803752326d2932a3bd42d7cfEric Laurent    Effect_getDescriptor,
3263ba7b8f881a9b6b21803752326d2932a3bd42d7cfEric Laurent    NULL,
32642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};    /* end gLvmEffectInterface */
32652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32667f16b197c76fbae9399242f055a7ee16dcd0fd6dMarco Nelissen// This is the only symbol that needs to be exported
32677f16b197c76fbae9399242f055a7ee16dcd0fd6dMarco Nelissen__attribute__ ((visibility ("default")))
3268e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentaudio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
3269e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    tag : AUDIO_EFFECT_LIBRARY_TAG,
3270e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    version : EFFECT_LIBRARY_API_VERSION,
3271e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    name : "Effect Bundle Library",
3272e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    implementor : "NXP Software Ltd.",
3273e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    create_effect : android::EffectCreate,
3274e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    release_effect : android::EffectRelease,
3275e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    get_descriptor : android::EffectGetDescriptor,
3276e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent};
3277e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3278e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent}
3279