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,
85209bbbcf4190231f9dede758cbe77d109919f9f1Jean-Michel Trivi        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | 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,
111209bbbcf4190231f9dede758cbe77d109919f9f1Jean-Michel Trivi        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | 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;
2276a5c6ed13e3ea1b19835e08624125c9b1505b32cMarco Nelissen        pContext->pBundledContext->volume                   = 0;
228163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
229163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
2308f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        char fileName[256];
2318f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_in.pcm", pContext->pBundledContext);
2328f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmInPtr = fopen(fileName, "w");
2338f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr == NULL) {
2343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("cannot open %s", fileName);
235dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            ret = -EINVAL;
236dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            goto exit;
2378f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
238163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2398f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_out.pcm", pContext->pBundledContext);
2408f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmOutPtr = fopen(fileName, "w");
2418f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr == NULL) {
2423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("cannot open %s", fileName);
2438f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
2448f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent           pContext->pBundledContext->PcmInPtr = NULL;
245dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent           ret = -EINVAL;
246dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent           goto exit;
247163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
248163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
249163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        /* Saved strength is used to return the exact strength that was used in the set to the get
2512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * because we map the original strength range of 0:1000 to 1:15, and this will avoid
2522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * quantisation like effect when returning
2532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         */
254163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->BassStrengthSaved        = 0;
255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->VirtStrengthSaved        = 0;
256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->CurPreset                = PRESET_CUSTOM;
257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved               = 0;
258163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bMuteEnabled             = LVM_FALSE;
259163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bStereoPositionEnabled   = LVM_FALSE;
260163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved            = 0;
261dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->workBuffer               = NULL;
262dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->frameCount               = -1;
263dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt   = 0;
264dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb     = 0;
265dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq     = 0;
266163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2679b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
2689b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent            pContext->pBundledContext->bandGaindB[i] = EQNB_5BandSoftPresets[i];
2699b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        }
2709b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
2713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Calling LvmBundle_init");
2722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ret = LvmBundle_init(pContext);
2732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (ret < 0){
2753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : EffectCreate() Bundle init failed");
276dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            goto exit;
2772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
2782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
2803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Assigning memory for previously created effect on sessionNo %d",
281c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionNo);
282c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext =
283c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                GlobalSessionMemory[sessionNo].pBundledContext;
2842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext);
2862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
287dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo];
28829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
2892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Create each Effect
2902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Bass Boost
2923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST");
29329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bBassInstantiated = LVM_TRUE;
294dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb = 0;
295163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
296163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->itfe       = &gLvmEffectInterface;
2972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_BASS_BOOST;
2982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Virtualizer
3003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER");
30129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVirtualizerInstantiated=LVM_TRUE;
302dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt = 0;
303163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VIRTUALIZER;
3062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Equalizer
3083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER");
30929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bEqualizerInstantiated = LVM_TRUE;
310dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq = 0;
311163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_EQUALIZER;
3142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Volume
3163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_VOLUME");
31729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVolumeInstantiated = LVM_TRUE;
318163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VOLUME;
321163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
3233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectCreate() invalid UUID");
324dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
325dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
3262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
328dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentexit:
329dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if (ret != 0) {
330dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext != NULL) {
331dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (newBundle) {
332dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_FALSE;
333dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                SessionIndex[sessionNo] = LVM_UNUSED_SESSION;
334dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                delete pContext->pBundledContext;
335dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
336dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            delete pContext;
337dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
338e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        *pHandle = (effect_handle_t)NULL;
339dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    } else {
340e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        *pHandle = (effect_handle_t)pContext;
341dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    }
3423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectCreate end..\n\n");
343dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return ret;
3442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectCreate */
3452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
346e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentextern "C" int EffectRelease(effect_handle_t handle){
3473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\n\tEffectRelease start %p", handle);
348e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    EffectContext * pContext = (EffectContext *)handle;
3492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectRelease start handle: %p, context %p", handle, pContext->pBundledContext);
3512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
3523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
3532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
354163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
35629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    SessionContext *pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo];
35729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
3582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Clear the instantiated flag for the effect
359dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // protect agains the case where an effect is un-instantiated without being disabled
3602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
3613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag");
36229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bBassInstantiated = LVM_FALSE;
363dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
364dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
365dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
366dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb = 0;
3672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VIRTUALIZER) {
3683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag");
36929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVirtualizerInstantiated = LVM_FALSE;
370dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
371dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
372dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
373dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt = 0;
3742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_EQUALIZER) {
3753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag");
37629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bEqualizerInstantiated =LVM_FALSE;
377dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
378dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
379dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
380dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq = 0;
3812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VOLUME) {
3823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag");
38329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVolumeInstantiated = LVM_FALSE;
384dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){
385dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
386dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
3872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
3883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n");
3892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
390163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
391dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // Disable effect, in this case ignore errors (return codes)
392dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // if an effect has already been disabled
393dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    Effect_setEnabled(pContext, LVM_FALSE);
394dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext
39629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    if ((pSessionContext->bBassInstantiated == LVM_FALSE) &&
39729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bVolumeInstantiated == LVM_FALSE) &&
39829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bEqualizerInstantiated ==LVM_FALSE) &&
39929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bVirtualizerInstantiated==LVM_FALSE))
4002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
401163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
4028f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr != NULL) {
4038f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
4048f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmInPtr = NULL;
4058f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
4068f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr != NULL) {
4078f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmOutPtr);
4088f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmOutPtr = NULL;
4098f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
410163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
411c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
412c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
413c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        // Clear the SessionIndex
414c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        for(int i=0; i<LVM_MAX_SESSIONS; i++){
415c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(SessionIndex[i] == pContext->pBundledContext->SessionId){
416e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                SessionIndex[i] = LVM_UNUSED_SESSION;
4173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffectRelease: Clearing SessionIndex SessionNo %d for SessionId %d\n",
418c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        i, pContext->pBundledContext->SessionId);
419c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                break;
420c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
421c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
422c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
4233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: All effects are no longer instantiated\n");
424dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pSessionContext->bBundledEffectsEnabled = LVM_FALSE;
42529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->pBundledContext = LVM_NULL;
4263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: Freeing LVM Bundle memory\n");
427163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmEffect_free(pContext);
4283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: Deleting LVM Bundle context %p\n", pContext->pBundledContext);
429dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->workBuffer != NULL) {
430dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            free(pContext->pBundledContext->workBuffer);
431dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
432163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        delete pContext->pBundledContext;
433c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = LVM_NULL;
4342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // free the effect context for current effect
4362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    delete pContext;
4372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectRelease end\n");
4392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
4402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectRelease */
4422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4435e92a7861196ddae14638d4b7a63fc4892b7ef59Glenn Kastenextern "C" int EffectGetDescriptor(const effect_uuid_t *uuid,
444e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                                   effect_descriptor_t *pDescriptor) {
445e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    const effect_descriptor_t *desc = NULL;
446e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
447e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pDescriptor == NULL || uuid == NULL){
4483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("EffectGetDescriptor() called with NULL pointer");
449e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return -EINVAL;
450e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
451e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
452e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
453e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gBassBoostDescriptor;
454e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
455e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gVirtualizerDescriptor;
456e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
457e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gEqualizerDescriptor;
458e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
459e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gVolumeDescriptor;
460e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
461e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
462e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (desc == NULL) {
463e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return  -EINVAL;
464e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
465e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
466a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pDescriptor = *desc;
467e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
468e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    return 0;
469e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent} /* end EffectGetDescriptor */
470e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
4712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init(){
4723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmGlobalBundle_init start");
4732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for(int i=0; i<LVM_MAX_SESSIONS; i++){
4742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBundledEffectsEnabled   = LVM_FALSE;
4752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVolumeInstantiated      = LVM_FALSE;
4762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bEqualizerInstantiated   = LVM_FALSE;
4772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBassInstantiated        = LVM_FALSE;
4782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE;
4792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].pBundledContext          = LVM_NULL;
480c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
481e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        SessionIndex[i] = LVM_UNUSED_SESSION;
4822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
4842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
4852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_init()
4872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Initialize engine with default configuration, creates instance
4892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// with all effects disabled.
4902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
4922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
4932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
4952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_init(EffectContext *pContext){
4992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status;
5002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init start");
5022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
503163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
504e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.inputCfg.channels                      = AUDIO_CHANNEL_OUT_STEREO;
505e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.inputCfg.format                        = AUDIO_FORMAT_PCM_16_BIT;
506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
511163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
512e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.outputCfg.channels                     = AUDIO_CHANNEL_OUT_STEREO;
513e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.outputCfg.format                       = AUDIO_FORMAT_PCM_16_BIT;
514163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
516163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
518163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
5192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
5212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext->pBundledContext->hInstance != NULL){
5233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
5242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Calling pContext->pBassBoost->free()");
5252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmEffect_free(pContext);
5272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
5292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Called pContext->pBassBoost->free()");
5302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;          /* Function call status */
5332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                         /* Control Parameters */
5342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_InstParams_t        InstParams;                     /* Instance parameters */
5352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_EQNB_BandDef_t      BandDefs[MAX_NUM_BANDS];        /* Equaliser band definitions */
5362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomParams_t    HeadroomParams;                 /* Headroom parameters */
5372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomBandDef_t   HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS];
5382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;                         /* Memory allocation table */
5392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    bool                    bMallocFailure = LVM_FALSE;
5402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the capabilities */
542163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    InstParams.BufferMode       = LVM_UNMANAGED_BUFFERS;
5432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.MaxBlockSize     = MAX_CALL_SIZE;
5442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.EQNB_NumBands    = MAX_NUM_BANDS;
5452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.PSA_Included     = LVM_PSA_ON;
5462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory, forcing alignment */
5482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(LVM_NULL,
5492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &MemTab,
5502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &InstParams);
5512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init")
5532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
5562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory */
5582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
5602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
5612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
5633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
564d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u\n", MemTab.Region[i].Size, i );
5652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                bMallocFailure = LVM_TRUE;
5662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
5673856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLvmBundle_init CreateInstance allocated %ld bytes for region %u at %p\n",
5682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
5742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     * succesfully allocated and return with an error
5752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     */
5762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(bMallocFailure == LVM_TRUE){
5772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
5793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes "
580d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        "for region %u Not freeing\n", MemTab.Region[i].Size, i );
5812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
5823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %ld bytes "
583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "for region %u at %p- free\n",
584163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
5862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
5892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5903856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n");
5912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Initialise */
593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->hInstance = LVM_NULL;
5942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Init sets the instance handle */
596163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,
5972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &MemTab,
5982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &InstParams);
5992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init")
6012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
6042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the initial process parameters */
6062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* General parameters */
6072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.OperatingMode          = LVM_MODE_ON;
6082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SampleRate             = LVM_FS_44100;
6092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SourceFormat           = LVM_STEREO;
6102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SpeakerType            = LVM_HEADPHONES;
6112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->SampleRate = LVM_FS_44100;
613163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Concert Sound parameters */
6152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerOperatingMode   = LVM_MODE_OFF;
6162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerType            = LVM_CONCERTSOUND;
6172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerReverbLevel     = 100;
618d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.CS_EffectLevel             = LVM_CS_EFFECT_NONE;
6192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* N-Band Equaliser parameters */
6212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_OperatingMode     = LVM_EQNB_OFF;
6222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_NBands            = FIVEBAND_NUMBANDS;
6232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.pEQNB_BandDefinition   = &BandDefs[0];
624163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
6262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
6272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i];
6282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].QFactor   = EQNB_5BandPresetsQFactors[i];
629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        BandDefs[i].Gain      = EQNB_5BandSoftPresets[i];
6302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
6312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume Control parameters */
6332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_EffectLevel         = 0;
6342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_Balance             = 0;
6352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Treble Enhancement parameters */
6372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
6382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_EffectLevel         = 0;
6392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = (LVM_PSA_DecaySpeed_en)0;
6432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
6452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_OperatingMode       = LVM_BE_OFF;
6462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_EffectLevel         = 0;
6472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_CentreFreq          = LVM_BE_CENTRE_90Hz;
6482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_HPF                 = LVM_BE_HPF_ON;
6492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = LVM_PSA_SPEED_MEDIUM;
6532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
654d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    /* TE Control parameters */
655d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
656d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_EffectLevel         = 0;
657d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance,
6602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &params);
6612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init")
6632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n");
6662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the headroom parameters */
6682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_Low          = 20;
6692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_High         = 4999;
670e44615ff6022239850a3ea459ad6e07b44c37544Eric Laurent    HeadroomBandDef[0].Headroom_Offset    = 0;
6712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_Low          = 5000;
6722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_High         = 24000;
673e44615ff6022239850a3ea459ad6e07b44c37544Eric Laurent    HeadroomBandDef[1].Headroom_Offset    = 0;
6742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.pHeadroomDefinition    = &HeadroomBandDef[0];
6752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
6762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.NHeadroomBands         = 2;
6772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance,
6792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &HeadroomParams);
6802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init")
6822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n");
6853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init End");
6862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
6872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end LvmBundle_init */
6882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
689dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
6902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_process()
6922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
6942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply LVM Bundle effects
6952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
6972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pIn:        pointer to stereo 16 bit input data
6982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to stereo 16 bit output data
6992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  frameCount: Frames to process
7002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
7022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Outputs:
7042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to updated stereo 16 bit output data
7052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_process(LVM_INT16        *pIn,
709163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      LVM_INT16        *pOut,
710163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      int              frameCount,
711163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      EffectContext    *pContext){
7122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
715163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               *pOutTmp;
716dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
717163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){
718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = pOut;
719163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
720dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->frameCount != frameCount) {
721dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (pContext->pBundledContext->workBuffer != NULL) {
722dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                free(pContext->pBundledContext->workBuffer);
723dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
724dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->workBuffer =
725dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2);
726dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->frameCount = frameCount;
727163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
728dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pOutTmp = pContext->pBundledContext->workBuffer;
729163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
7303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("LVM_ERROR : LvmBundle_process invalid access mode");
731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
734163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
735163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pIn, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmInPtr);
736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmInPtr);
737163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
738163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("Calling LVM_Process");
740d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
741163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Process the samples */
7422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */
7432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pIn,                                  /* Input buffer */
7442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pOutTmp,                              /* Output buffer */
7452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            (LVM_UINT16)frameCount,               /* Number of samples to read */
7462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            0);                                   /* Audo Time */
747163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process")
7492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
7502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
751163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pOutTmp, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmOutPtr);
753163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmOutPtr);
754163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
755163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
757163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        for (int i=0; i<frameCount*2; i++){
758dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pOut[i] = clamp16((LVM_INT32)pOut[i] + (LVM_INT32)pOutTmp[i]);
759163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
760163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmBundle_process */
7632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_enable()
7662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Enable the effect in the bundle
7682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_enable(EffectContext *pContext){
7773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable start");
778163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
7812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
782163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
783163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable")
7872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
7883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n");
7892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
7913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST");
7922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_ON;
7932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
7953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER");
7962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_ON;
7972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
7993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER");
8002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_ON;
8012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
8033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_VOLUME");
804163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
805163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable")
8082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
809163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n");
8113856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable end");
8122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_disable()
8172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Disable the effect in the bundle
8192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_disable(EffectContext *pContext){
8283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable start");
829163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
8312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
832163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
833163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
8342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
8352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable")
8372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
8383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n");
8392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
8413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST");
8422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_OFF;
8432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
8453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_VIRTUALIZER");
8462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_OFF;
8472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
8493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_EQUALIZER");
8502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_OFF;
8512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
8533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_VOLUME");
854163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
855163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable")
8582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
859163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n");
8613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable end");
8622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_free()
8672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Free all memory associated with the Bundle.
8692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free(EffectContext *pContext){
8782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;         /* Function call status */
8792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                        /* Control Parameters */
8802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;
8812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Free the algorithm memory */
8832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance,
8842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   &MemTab,
8852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   LVM_NULL);
8862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free")
8882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
8902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
8912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress != NULL){
8923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLvmEffect_free - START freeing %ld bytes for region %u at %p\n",
8932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
8962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8973856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLvmEffect_free - END   freeing %ld bytes for region %u at %p\n",
8982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
9003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : LvmEffect_free - trying to free with NULL pointer %ld bytes "
9012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "for region %u at %p ERROR\n",
9022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
9032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
9042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
9052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
9062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmEffect_free */
9072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9093d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Effect_setConfig()
9102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Set input and output audio configuration.
9122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
9162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//      configuration parameters
9172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
9192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9223d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentint Effect_setConfig(EffectContext *pContext, effect_config_t *pConfig){
923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_Fs_en   SampleRate;
9243d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tEffect_setConfig start");
9252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
9272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig != NULL);
9282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
9302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels);
9312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
932e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    CHECK_ARG(pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO);
9332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
9342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
935e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    CHECK_ARG(pConfig->inputCfg.format == AUDIO_FORMAT_PCM_16_BIT);
9362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
937a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    pContext->config = *pConfig;
9382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
939163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    switch (pConfig->inputCfg.samplingRate) {
940163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 8000:
941163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_8000;
942c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 8000*2; // 2 secs Stereo
943163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 16000:
945163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_16000;
946c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 16000*2; // 2 secs Stereo
947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 22050:
949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_22050;
950c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 22050*2; // 2 secs Stereo
951163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
952163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 32000:
953163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_32000;
954c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 32000*2; // 2 secs Stereo
955163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
956163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 44100:
957163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_44100;
958c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 44100*2; // 2 secs Stereo
959163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
960163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 48000:
961163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_48000;
962c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 48000*2; // 2 secs Stereo
963163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
964163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    default:
9653d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig invalid sampling rate %d", pConfig->inputCfg.samplingRate);
966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
967163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
969163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->SampleRate != SampleRate){
9702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
971163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ControlParams_t     ActiveParams;
972163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;
9732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9743d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig change sampling rate to %d", SampleRate);
9752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
977163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
978163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
9792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9803d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_setConfig")
981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9839f6f0a7eb1d7f2c35f3547779364a1a8d6d4a24cEric Laurent        ActiveParams.SampleRate = SampleRate;
9849f6f0a7eb1d7f2c35f3547779364a1a8d6d4a24cEric Laurent
985163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9873d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_setConfig")
9883d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig Succesfully called LVM_SetControlParameters\n");
989c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SampleRate = SampleRate;
9902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
991163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
9923d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        //ALOGV("\tEffect_setConfig keep sampling rate at %d", SampleRate);
993163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9953d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tEffect_setConfig End....");
996163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
9973d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent}   /* end Effect_setConfig */
9983d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
9993d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
10003d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Effect_getConfig()
10013d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
10023d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Purpose: Get input and output audio configuration.
10033d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10043d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Inputs:
10053d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//  pContext:   effect engine context
10063d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
10073d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//      configuration parameters
10083d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10093d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Outputs:
10103d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10113d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
10123d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
10133d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentvoid Effect_getConfig(EffectContext *pContext, effect_config_t *pConfig)
10143d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent{
1015a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pConfig = pContext->config;
10163d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent}   /* end Effect_getConfig */
10172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassGetStrength()
10202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
10232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
10242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the
10252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
10262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t BassGetStrength(EffectContext *pContext){
10333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved);
10342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
10362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1038163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength")
10422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
10432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n");
10452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Check that the strength returned matches the strength that was set earlier */
1047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(ActiveParams.BE_EffectLevel !=
1048163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){
10493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n",
10502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved);
10512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
10522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
10532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (saved)  -> %d\n", pContext->pBundledContext->BassStrengthSaved );
10562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return pContext->pBundledContext->BassStrengthSaved;
10572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassGetStrength */
10582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassSetStrength()
10612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15
10642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid BassSetStrength(EffectContext *pContext, uint32_t strength){
10723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength(%d)", strength);
10732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->BassStrengthSaved = (int)strength;
10752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength")
10843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n");
10852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
10872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_EffectLevel    = (LVM_INT16)((15*strength)/1000);
10882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_CentreFreq     = LVM_BE_CENTRE_90Hz;
10892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10903856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength")
10963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n");
10972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassSetStrength */
10982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerGetStrength()
11012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
11042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
1105163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the
11062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
11072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t VirtualizerGetStrength(EffectContext *pContext){
11143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved);
11152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
11172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
11182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength")
11222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
11232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n");
11253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength() (0-100)   -> %d\n", ActiveParams.VirtualizerReverbLevel*10);
1126d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    return pContext->pBundledContext->VirtStrengthSaved;
11272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getStrength */
11282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerSetStrength()
11312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15
11342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
11382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
11423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength(%d)", strength);
11432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
11452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1146163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->VirtStrengthSaved = (int)strength;
1147163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
11482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
11502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength")
11523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n");
11532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Virtualizer parameters */
1155d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    ActiveParams.CS_EffectLevel             = (int)((strength*32767)/1000);
11562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11573856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength() (0-1000)   -> %d\n", strength );
11583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength() (0- 100)   -> %d\n", ActiveParams.CS_EffectLevel );
11592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength")
11633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n\n");
11642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setStrength */
11652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11669b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
11672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11689b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// EqualizerLimitBandLevels()
11692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11700ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent// Purpose: limit all EQ band gains to a value less than 0 dB while
11719b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//          preserving the relative band levels.
11722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11799b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurentvoid EqualizerLimitBandLevels(EffectContext *pContext) {
11809b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11819b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
11822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11839b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    /* Get the current settings */
11849b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11859b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerLimitBandLevels")
11869b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels Succesfully returned from LVM_GetControlParameters\n");
11879b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels just Got -> %d\n",
11889b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //          ActiveParams.pEQNB_BandDefinition[band].Gain);
11899b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
11900ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // Apply a volume correction to avoid clipping in the EQ based on 2 factors:
11910ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // - the maximum EQ band gain: the volume correction is such that the total of volume + max
11920ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // band gain is <= 0 dB
11930ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // - the average gain in all bands weighted by their proximity to max gain band.
11940ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int maxGain = 0;
11950ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int avgGain = 0;
11960ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int avgCount = 0;
11979b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
11980ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        if (pContext->pBundledContext->bandGaindB[i] >= maxGain) {
11990ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpMaxGain = pContext->pBundledContext->bandGaindB[i];
12000ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpAvgGain = 0;
12010ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpAvgCount = 0;
12020ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            for (int j = 0; j < FIVEBAND_NUMBANDS; j++) {
12030ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                int gain = pContext->pBundledContext->bandGaindB[j];
12040ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // skip current band and gains < 0 dB
12050ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (j == i || gain < 0)
12060ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    continue;
12070ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // no need to continue if one band not processed yet has a higher gain than current
12080ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // max
12090ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (gain > tmpMaxGain) {
12100ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    // force skipping "if (tmpAvgGain >= avgGain)" below as tmpAvgGain is not
12110ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    // meaningful in this case
12120ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    tmpAvgGain = -1;
12130ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    break;
12140ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                }
12150ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12160ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                int weight = 1;
12170ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (j < (i + 2) && j > (i - 2))
12180ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    weight = 4;
12190ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                tmpAvgGain += weight * gain;
12200ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                tmpAvgCount += weight;
12210ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            }
12220ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            if (tmpAvgGain >= avgGain) {
12230ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                maxGain = tmpMaxGain;
12240ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                avgGain = tmpAvgGain;
12250ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                avgCount = tmpAvgCount;
12269b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent            }
12279b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        }
12280ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
12290ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
12300ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].Gain = pContext->pBundledContext->bandGaindB[i];
12319b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    }
12322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12330ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int gainCorrection = 0;
12340ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (maxGain + pContext->pBundledContext->volume > 0) {
12350ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        gainCorrection = maxGain + pContext->pBundledContext->volume;
12360ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
12370ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (avgCount) {
12380ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        gainCorrection += avgGain/avgCount;
12390ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
12400ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12410ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    ALOGV("EqualizerLimitBandLevels() gainCorrection %d maxGain %d avgGain %d avgCount %d",
12420ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            gainCorrection, maxGain, avgGain, avgCount);
12430ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12440ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    ActiveParams.VC_EffectLevel  = pContext->pBundledContext->volume - gainCorrection;
12450ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (ActiveParams.VC_EffectLevel < -96) {
12460ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.VC_EffectLevel = -96;
12479b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    }
12480ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12499b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    /* Activate the initial settings */
12509b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
12519b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerLimitBandLevels")
12529b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels just Set -> %d\n",
12539b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //          ActiveParams.pEQNB_BandDefinition[band].Gain);
12540ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
12550ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    //ALOGV("\tEqualizerLimitBandLevels just set (-96dB -> 0dB)   -> %d\n",ActiveParams.VC_EffectLevel );
12560ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if(pContext->pBundledContext->firstVolume == LVM_TRUE){
12570ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams);
12580ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process")
12590ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ALOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks");
12600ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->firstVolume = LVM_FALSE;
12610ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
12629b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent}
12632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12649b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
12659b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
12669b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// EqualizerGetBandLevel()
12679b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
12689b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Purpose: Retrieve the gain currently being used for the band passed in
12699b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
12709b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Inputs:
12719b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//  band:       band number
12729b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//  pContext:   effect engine context
12739b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
12749b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Outputs:
12759b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
12769b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
12779b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurentint32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
12789b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerGetBandLevel -> %d\n", pContext->pBundledContext->bandGaindB[band] );
12799b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    return pContext->pBundledContext->bandGaindB[band] * 100;
12802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetBandLevel()
12842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Sets gain value for the given band.
12872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
12902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Gain:       Gain to be applied in millibels
12912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
12922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
12942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//---------------------------------------------------------------------------
1296d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurentvoid EqualizerSetBandLevel(EffectContext *pContext, int band, short Gain){
1297163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int gainRounded;
1298163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(Gain > 0){
1299163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain+50)/100);
1300163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1301163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain-50)/100);
1302163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
13033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);
13049b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    pContext->pBundledContext->bandGaindB[band] = gainRounded;
13052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
13069b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
13079b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
13082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13099b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
13102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetCentreFrequency()
13122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the frequency being used for the band passed in
13142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
13172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
13202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){
1323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Frequency =0;
13242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1327163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1328163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1329163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
13312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1332163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency")
13332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1334163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef   = ActiveParams.pEQNB_BandDefinition;
1335163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Frequency = (int32_t)BandDef[band].Frequency*1000;     // Convert to millibels
13362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency );
13383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n");
1339163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Frequency;
13402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandFreqRange(
13442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets lower and upper boundaries of a band.
13482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the high shelf, the low bound is the band frequency and the high
13492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// bound is Nyquist.
13502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the peaking filters, they are the gain[dB]/2 points.
13512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
13542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
13572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
13582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
13592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow,
1361163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                  uint32_t *pHi){
1362163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pLow = bandFreqRange[band][0];
1363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pHi  = bandFreqRange[band][1];
1364163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
13652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBand(
13692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Returns the band with the maximum influence on a given frequency.
13732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Result is unaffected by whether EQ is enabled or not, or by whether
13742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// changes have been committed or not.
13752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  targetFreq   The target frequency, in millihertz.
13782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
13792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
13812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
13822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
13832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){
13852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int band = 0;
13862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1387163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(targetFreq < bandFreqRange[0][0]){
1388163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
1389163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if(targetFreq == bandFreqRange[0][0]){
1390163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
1391163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1392163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for(int i=0; i<FIVEBAND_NUMBANDS;i++){
1393163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){
1394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            band = i;
1395163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1396163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
13972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return band;
13982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
13992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPreset(
14022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets the currently set preset ID.
14062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Will return PRESET_CUSTOM in case the EQ parameters have been modified
14072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// manually since a preset was set.
14082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
14112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetPreset(EffectContext *pContext){
1414163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return pContext->pBundledContext->CurPreset;
14152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
14162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetPreset(
14192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Sets the current preset by ID.
14232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// All the band parameters will be overridden.
14242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
14272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  preset       The preset ID.
14282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetPreset(EffectContext *pContext, int preset){
14312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetPreset(%d)", preset);
14332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = preset;
14342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    //ActiveParams.pEQNB_BandDefinition = &BandDefs[0];
14362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
14372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
14389b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        pContext->pBundledContext->bandGaindB[i] =
14399b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent                EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
14402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
14412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14429b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
14439b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
14452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
14462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
1447163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
14482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetNumPresets(){
1449163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return sizeof(gEqualizerPresets) / sizeof(PresetConfig);
14502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
14512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPresetName(
14542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets a human-readable name for a preset ID. Will return "Custom" if
14572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// PRESET_CUSTOM is passed.
14582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// preset       The preset ID. Must be less than number of presets.
14612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//-------------------------------------------------------------------------
14632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst char * EqualizerGetPresetName(int32_t preset){
14643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetPresetName start(%d)", preset);
14652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (preset == PRESET_CUSTOM) {
14662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return "Custom";
14672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
14682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return gEqualizerPresets[preset].name;
14692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
14703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetPresetName end(%d)", preset);
1471163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
14722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
14732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetVolumeLevel()
14762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  level       level to be applied
14822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
14862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14870ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (level > 0 || level < -9600) {
14880ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        return -EINVAL;
14890ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
1490163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
14910ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (pContext->pBundledContext->bMuteEnabled == LVM_TRUE) {
14920ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->levelSaved = level / 100;
14930ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    } else {
14940ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = level / 100;
1495d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    }
14969b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14979b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
14989b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
150017a736c3e1d062d7fc916329eb32aef8935614afGlenn Kasten}    /* end VolumeSetVolumeLevel */
15012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeGetVolumeLevel()
15042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){
15132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15140ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (pContext->pBundledContext->bMuteEnabled == LVM_TRUE) {
15150ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        *level = pContext->pBundledContext->levelSaved * 100;
15160ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    } else {
15170ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        *level = pContext->pBundledContext->volume * 100;
15180ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
15192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
15202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end VolumeGetVolumeLevel */
15212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetMute()
15242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
15302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){
15343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetMute start(%d)", mute);
15352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->bMuteEnabled = mute;
15372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set appropriate volume level */
15392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){
15400ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->levelSaved = pContext->pBundledContext->volume;
15410ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = -96;
15422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
15430ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = pContext->pBundledContext->levelSaved;
15442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
15452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15460ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    EqualizerLimitBandLevels(pContext);
15472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
15492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setMute */
15502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1552163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetMute()
15532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Ourputs:
15602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
15612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){
15643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetMute start");
1565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||
1566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){
1567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        *mute = pContext->pBundledContext->bMuteEnabled;
1568163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
15692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
15703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d",
1571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent              pContext->pBundledContext->bMuteEnabled);
1572163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
15732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
15743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetMute end");
15752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getMute */
15762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint16_t VolumeConvertStereoPosition(int16_t position){
1578163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t convertedPosition = 0;
1579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1580163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    convertedPosition = (int16_t)(((float)position/1000)*96);
1581163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return convertedPosition;
1582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
1584163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1586163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeSetStereoPosition()
1587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1591163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1592163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1596163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint VolumeSetStereoPosition(EffectContext *pContext, int16_t position){
1598163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               Balance = 0;
1602163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1603c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1604163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->positionSaved = position;
1606163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1607163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1609d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance);
1614163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved = position;
1615163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:"
1620163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     " %d\n", ActiveParams.VC_Balance);
1621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1622163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Volume parameters */
1623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  = Balance;
16243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB)   -> %d\n", ActiveParams.VC_Balance );
1625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1626163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Activate the initial settings */
1627163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
1629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1630163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n");
16322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
16373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: "
1638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     "%d\n", ActiveParams.VC_Balance);
1639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1640163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    else{
16413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n",
1642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //position, Balance);
1643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
16443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n",
1645d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeSetStereoPosition */
16482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetStereoPosition()
1652163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1653163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1654163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1655163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
16612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1662163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){
16633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition start");
16642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               balance;
1668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1670d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1671163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
1674163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1675163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance);
16773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1682163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(balance != ActiveParams.VC_Balance){
1683163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
1684163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1686163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *position = (LVM_INT16)pContext->pBundledContext->positionSaved;     // Convert dB to millibels
16873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved =%d\n",
1688d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1689163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1690163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeGetStereoPosition */
16912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeEnableStereoPosition()
1694163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1695163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:   effect engine context
1699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  mute:       enable/disable flag
1700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1701163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
17022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1703163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){
17043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition start()");
17052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1706163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->bStereoPositionEnabled = enabled;
17072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1709163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
17102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1711163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1712163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1713163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition")
1714163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
17152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n");
17173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition to %d, position was %d\n",
1718163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //     enabled, ActiveParams.VC_Balance );
17192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1720163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Set appropriate stereo position */
1721163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){
1722163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance = 0;
1723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1724163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  =
1725163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                            VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1726163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
17272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1728163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
1729163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1730163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition")
1731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
17322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n");
17343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition end()\n");
1735163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeEnableStereoPosition */
17372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_getParameter()
17402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a BassBoost parameter
17432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
17462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
17482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
17492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
17522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
17532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
17562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_getParameter(EffectContext     *pContext,
1760c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
1761163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           size_t            *pValueSize,
1762163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           void              *pValue){
17632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1764c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1765c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
17662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
17672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
17682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_getParameter start");
17702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
177223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17737fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
17743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize1 %d", *pValueSize);
17757fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
17767fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
17777fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
17787fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
17792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
17802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
17813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize2 %d", *pValueSize);
17822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
17832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
17842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
17852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
17892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
17902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
179323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
17942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
17952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d",
1797163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
17982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
18012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = BassGetStrength(pContext);
18022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d",
1804163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
18052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
18092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
18102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_getParameter end");
18142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_getParameter */
18162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_setParameter()
18192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a BassBoost parameter
18222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
18252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
18272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1832c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue){
18332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
18342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1835c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
18362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_setParameter start");
18382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1839c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (*pParamTemp){
18402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
18412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
18423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength);
18433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength");
18442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            BassSetStrength(pContext, (int32_t)strength);
18453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength");
18462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
18472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParamTemp);
18492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_setParameter end");
18532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_setParameter */
18552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_getParameter()
18582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Virtualizer parameter
18612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
18642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
18662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
18672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
18702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
18712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
18742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_getParameter(EffectContext        *pContext,
1878c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void                 *pParam,
18792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             size_t               *pValueSize,
18802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             void                 *pValue){
18812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1882c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1883c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
18842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
18852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
18862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_getParameter start");
18882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
189023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
18917fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
18923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
18937fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
18947fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
18957fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
18967fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
18972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
18993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize2 %d",*pValueSize);
19002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
19012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
19022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
19032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
19063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
19072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
191123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
19122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
19132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d",
1915163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
19162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
19192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = VirtualizerGetStrength(pContext);
19202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d",
1922163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
19232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
19263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
19272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
19282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_getParameter end");
19322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_getParameter */
19342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_setParameter()
19372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Virtualizer parameter
19402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
19432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
19452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1950c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
19512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
19522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
1953c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1954c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
19552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_setParameter start");
19572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1958c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
19592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
19602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
19613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength);
19623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength");
19632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            VirtualizerSetStrength(pContext, (int32_t)strength);
19643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength");
19652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
19662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
19673856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", param);
19682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_setParameter end");
19722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_setParameter */
19742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_getParameter()
19772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Equalizer parameter
19802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer       - handle to instance data
19832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
19852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
19862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
19892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
19902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
19932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_getParameter(EffectContext     *pContext,
1996c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
19972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           size_t            *pValueSize,
19982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           void              *pValue){
19992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
20002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2001c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2002c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
20032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
20042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
20052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_getParameter start");
20072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
20092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
20102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
20112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
20123be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_BAND_LEVEL:
20133be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_GET_BAND:
20142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int16_t)) {
20153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
20162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int16_t);
20192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
20223be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (*pValueSize < 2 * sizeof(int16_t)) {
20233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
20243be9523784cc4038f601e510faee595117cdacb3Eric Laurent            return -EINVAL;
20253be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
20263be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *pValueSize = 2 * sizeof(int16_t);
20273be9523784cc4038f601e510faee595117cdacb3Eric Laurent        break;
20282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
20292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < 2 * sizeof(int32_t)) {
20303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 3  %d", *pValueSize);
20312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = 2 * sizeof(int32_t);
20342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20353be9523784cc4038f601e510faee595117cdacb3Eric Laurent
20362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
20372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int32_t)) {
20383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 5  %d", *pValueSize);
20392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int32_t);
20422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
20452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
204723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES:
204823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) {
20493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
205023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            return -EINVAL;
205123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
205223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t);
205323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        break;
205423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
20552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
20563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param);
20572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
20582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
20612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
20623be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS;
20633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue);
20642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
20673be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = -1500;
20683be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *((int16_t *)pValue + 1) = 1500;
20693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d",
2070d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      *(int16_t *)pValue, *((int16_t *)pValue + 1));
20712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2074c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20793be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2);
20803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d",
2081163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
2085c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2);
20913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d",
2092163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
20932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
2096c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
20972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
20982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1));
21023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d",
2103163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue, *((int32_t *)pValue + 1));
21042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_BAND:
2107c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
21083be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2);
21093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d",
2110d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      param2, *(uint16_t *)pValue);
21112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
21143be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext);
21153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue);
21162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
21193be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets();
21203856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue);
21212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
2124c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
21252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= EqualizerGetNumPresets()) {
21262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        //if (param2 >= 20) {     // AGO FIX
21272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name = (char *)pValue;
21312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1);
21322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name[*pValueSize - 1] = 0;
21332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = strlen(name) + 1;
21343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d",
2135163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, gEqualizerPresets[param2].name, *pValueSize);
21362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
213823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES: {
21393be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
21403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES");
21413be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[0] = (int16_t)EqualizerGetPreset(pContext);
21423be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[1] = (int16_t)FIVEBAND_NUMBANDS;
214323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
21443be9523784cc4038f601e510faee595117cdacb3Eric Laurent            p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i);
214523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
214623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    } break;
214723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
21482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
21493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param);
21502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        status = -EINVAL;
21512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2154d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //GV("\tEqualizer_getParameter end\n");
21552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_getParameter */
21572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_setParameter()
21602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Equalizer parameter
21632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer    - handle to instance data
21662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
21672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
21682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
2172c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
21732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t preset;
21752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t band;
21762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t level;
2177c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2178c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
2179c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
21802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_setParameter start");
21822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
21832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
21843be9523784cc4038f601e510faee595117cdacb3Eric Laurent        preset = (int32_t)(*(uint16_t *)pValue);
21852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset);
21872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if ((preset >= EqualizerGetNumPresets())||(preset < 0)) {
21882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
21912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetPreset(pContext, preset);
21922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
21932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2194c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        band =  *pParamTemp;
21953be9523784cc4038f601e510faee595117cdacb3Eric Laurent        level = (int32_t)(*(int16_t *)pValue);
21963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level);
21972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (band >= FIVEBAND_NUMBANDS) {
21982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
22012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetBandLevel(pContext, band, level);
22022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22033be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_PROPERTIES: {
22043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES");
22053be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
22063be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if ((int)p[0] >= EqualizerGetNumPresets()) {
22073be9523784cc4038f601e510faee595117cdacb3Eric Laurent            status = -EINVAL;
22083be9523784cc4038f601e510faee595117cdacb3Eric Laurent            break;
22093be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
22103be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (p[0] >= 0) {
22113be9523784cc4038f601e510faee595117cdacb3Eric Laurent            EqualizerSetPreset(pContext, (int)p[0]);
22123be9523784cc4038f601e510faee595117cdacb3Eric Laurent        } else {
22133be9523784cc4038f601e510faee595117cdacb3Eric Laurent            if ((int)p[1] != FIVEBAND_NUMBANDS) {
22143be9523784cc4038f601e510faee595117cdacb3Eric Laurent                status = -EINVAL;
22153be9523784cc4038f601e510faee595117cdacb3Eric Laurent                break;
22163be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
22173be9523784cc4038f601e510faee595117cdacb3Eric Laurent            for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
22183be9523784cc4038f601e510faee595117cdacb3Eric Laurent                EqualizerSetBandLevel(pContext, i, (int)p[2 + i]);
22193be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
22203be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
22213be9523784cc4038f601e510faee595117cdacb3Eric Laurent    } break;
22222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
22233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_setParameter() invalid param %d", param);
22243be9523784cc4038f601e510faee595117cdacb3Eric Laurent        status = -EINVAL;
22252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_setParameter end");
22292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
22302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_setParameter */
22312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_getParameter()
22342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
22362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Volume parameter
22372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
22392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume          - handle to instance data
22402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
22412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
22422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
22432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
22452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
22462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
22472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
22502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_getParameter(EffectContext     *pContext,
2254c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void              *pParam,
22552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        size_t            *pValueSize,
22562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        void              *pValue){
22572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
22582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2259c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2260c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;;
22612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
22622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_getParameter start");
22642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2269163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if (*pValueSize != sizeof(int16_t)){
22703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1  %d", *pValueSize);
22712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
22742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
22772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
22782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize < sizeof(int32_t)){
22793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2  %d", *pValueSize);
22802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
22812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
22822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int32_t);
22832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
22863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param);
22872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
22912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue));
22933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d",
2294d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
22952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
22982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = 0;
22993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d",
2300d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
23012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2304163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            VolumeGetStereoPosition(pContext, (int16_t *)pValue);
23053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d",
2306d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
23072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2310163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeGetMute(pContext, (uint32_t *)pValue);
23113856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d",
2312163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(uint32_t *)pValue);
23132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2316163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled;
23173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d",
2318d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(uint32_t *)pValue);
23192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
23223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param);
23232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
23242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_getParameter end");
23282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_getParameter */
23302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_setParameter()
23342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
23362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Volume parameter
23372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
23392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume       - handle to instance data
23402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
23412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
23422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
23442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2347c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue){
23482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int      status = 0;
23492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t  level;
2350163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t  position;
23512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    uint32_t mute;
2352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    uint32_t positionEnabled;
2353c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2354c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
23552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_setParameter start");
23572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2358c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
23592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
23602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            level = *(int16_t *)pValue;
23613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level);
23623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel");
23632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeSetVolumeLevel(pContext, (int16_t)level);
23643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel");
23652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2368163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            mute = *(uint32_t *)pValue;
23693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute);
23703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setMute");
2371163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetMute(pContext, mute);
23723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->setMute");
2373163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            positionEnabled = *(uint32_t *)pValue;
2377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeEnableStereoPosition(pContext, positionEnabled);
2378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved);
23793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called");
2380163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2383163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            position = *(int16_t *)pValue;
23843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position);
23853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition");
2386163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, (int16_t)position);
23873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition");
2388163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
23892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
23913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", param);
23922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_setParameter end");
23962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_setParameter */
23982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2399163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent/****************************************************************************************
2400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent * Name : LVC_ToDB_s32Tos16()
2401163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Input       : Signed 32-bit integer
2402163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Output      : Signed 16-bit integer
2403163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  MSB (16) = sign bit
2404163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (15->05) = integer part
2405163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (04->01) = decimal part
2406163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Returns     : Db value with respect to full scale
2407163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Description :
2408163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Remarks     :
2409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent ****************************************************************************************/
2410163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2411163fbcf84010b98e0374110454d85b804bc8d13bEric LaurentLVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix)
2412163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent{
2413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   db_fix;
2414163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   Shift;
2415163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   SmallRemainder;
2416163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_UINT32  Remainder = (LVM_UINT32)Lin_fix;
2417163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2418163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Count leading bits, 1 cycle in assembly*/
2419163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for (Shift = 0; Shift<32; Shift++)
2420163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
2421163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if ((Remainder & 0x80000000U)!=0)
2422163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2423163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2424163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2425163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        Remainder = Remainder << 1;
2426163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
24272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2428163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /*
2429163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * Based on the approximation equation (for Q11.4 format):
2430163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     *
2431163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2)
2432163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     */
2433163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix    = (LVM_INT16)(-96 * Shift);               /* Six dB steps in Q11.4 format*/
2434163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24);
2435163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix + SmallRemainder );
2436163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder);
2437163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9));
24382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2439163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Correct for small offset */
2440163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - 5);
24412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2442163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return db_fix;
2443163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
24442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
244529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
244629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Effect_setEnabled()
244729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
244829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Purpose:
244929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Enable or disable effect
245029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
245129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Inputs:
245229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//  pContext      - pointer to effect context
245329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//  enabled       - true if enabling the effect, false otherwise
245429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
245529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Outputs:
245629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
245729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
245829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
245929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurentint Effect_setEnabled(EffectContext *pContext, bool enabled)
246029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent{
24613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffect_setEnabled() type %d, enabled %d", pContext->EffectType, enabled);
246229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
246329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    if (enabled) {
2464b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        // Bass boost or Virtualizer can be temporarily disabled if playing over device speaker due
2465b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        // to their nature.
2466b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        bool tempDisabled = false;
246729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        switch (pContext->EffectType) {
246829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_BASS_BOOST:
246929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
24703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                     ALOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already enabled");
247129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     return -EINVAL;
247229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2473dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountBb <= 0){
2474dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2475dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
247629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountBb =
247729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
247829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bBassEnabled = LVM_TRUE;
2479b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                tempDisabled = pContext->pBundledContext->bBassTempDisabled;
248029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
248129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_EQUALIZER:
248229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE) {
24833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_EQUALIZER is already enabled");
248429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
248529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2486dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountEq <= 0){
2487dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2488dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
248929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountEq =
249029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
249129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE;
249229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
249329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VIRTUALIZER:
249429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) {
24953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already enabled");
249629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
249729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2498dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountVirt <= 0){
2499dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2500dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
250129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountVirt =
250229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
250329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE;
2504b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                tempDisabled = pContext->pBundledContext->bVirtualizerTempDisabled;
250529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
250629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VOLUME:
250729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE) {
25083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VOLUME is already enabled");
250929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
251029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2511dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                pContext->pBundledContext->NumberEffectsEnabled++;
251229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVolumeEnabled = LVM_TRUE;
251329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
251429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            default:
25153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffect_setEnabled() invalid effect type");
251629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                return -EINVAL;
251729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        }
2518b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        if (!tempDisabled) {
2519b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            LvmEffect_enable(pContext);
2520b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        }
252129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    } else {
252229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        switch (pContext->EffectType) {
252329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_BASS_BOOST:
252429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bBassEnabled == LVM_FALSE) {
25253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already disabled");
252629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
252729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
252829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bBassEnabled = LVM_FALSE;
252929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
253029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_EQUALIZER:
253129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE) {
25323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_EQUALIZER is already disabled");
253329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
253429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
253529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE;
253629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
253729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VIRTUALIZER:
253829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE) {
25393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already disabled");
254029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
254129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
254229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE;
254329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
254429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VOLUME:
254529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVolumeEnabled == LVM_FALSE) {
25463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VOLUME is already disabled");
254729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
254829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
254929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVolumeEnabled = LVM_FALSE;
255029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
255129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            default:
25523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffect_setEnabled() invalid effect type");
255329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                return -EINVAL;
255429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        }
255529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        LvmEffect_disable(pContext);
255629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    }
255729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
255829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    return 0;
255929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent}
256029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
2561dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//----------------------------------------------------------------------------
2562dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// LVC_Convert_VolToDb()
2563dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//----------------------------------------------------------------------------
2564dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Purpose:
2565dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Convery volume in Q24 to dB
2566dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//
2567dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Inputs:
2568dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//  vol:   Q.24 volume dB
2569dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//
2570dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//-----------------------------------------------------------------------
2571dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2572dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentint16_t LVC_Convert_VolToDb(uint32_t vol){
2573dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    int16_t  dB;
2574dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2575dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = LVC_ToDB_s32Tos16(vol <<7);
2576dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = (dB +8)>>4;
2577dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = (dB <-96) ? -96 : dB ;
2578dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2579dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return dB;
2580dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent}
2581dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
2583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
25842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2585e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentextern "C" {
25862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Process */
2587e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_process(effect_handle_t     self,
2588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *inBuffer,
2589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *outBuffer){
25902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
2591c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
25922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int    status = 0;
2593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int    lvmStatus = 0;
2594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *in  = (LVM_INT16 *)inBuffer->raw;
2595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *out = (LVM_INT16 *)outBuffer->raw;
25962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25973856b090cd04ba5dd4a59a12430ed724d5995909Steve Block//ALOGV("\tEffect_process Start : Enabled = %d     Called = %d (%8d %8d %8d)",
2598dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled,
2599c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountBb,
2600c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountVirt,
2601c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountEq);
2602c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
26032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
26043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL");
26052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
26062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2607dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2608dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //if(pContext->EffectType == LVM_BASS_BOOST){
26093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is BASS_BOOST");
2610dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}else if(pContext->EffectType == LVM_EQUALIZER){
26113856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is LVM_EQUALIZER");
2612dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}else if(pContext->EffectType == LVM_VIRTUALIZER){
26133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is LVM_VIRTUALIZER");
2614dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}
2615dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
26162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
26172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
26182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            inBuffer->frameCount != outBuffer->frameCount){
26193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
26202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
26212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2622163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&
2623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_BASS_BOOST)){
26243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_BASS_BOOST Effect is not enabled");
2625c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
2626c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO
26273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting to turn off BASS_BOOST, %d samples left",
2628c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountBb);
2629d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2630d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb <= 0) {
263129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            status = -ENODATA;
2632dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
26333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_BASS_BOOST");
2634c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
2635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&
2637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VOLUME)){
26383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_VOLUME Effect is not enabled");
2639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2640dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->NumberEffectsEnabled--;
2641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&
2643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_EQUALIZER)){
26443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_EQUALIZER Effect is not enabled");
2645c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
2646c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq -= outBuffer->frameCount * 2; // STEREO
26473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting to turn off EQUALIZER, %d samples left",
2648c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountEq);
2649d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2650d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq <= 0) {
2651c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2652dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
26533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_EQUALIZER");
2654c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
26552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&
2657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VIRTUALIZER)){
26583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_VIRTUALIZER Effect is not enabled");
2659c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
2660c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt -= outBuffer->frameCount * 2;// STEREO
26613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting for to turn off VIRTUALIZER, %d samples left",
2662c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountVirt);
2663d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2664d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt <= 0) {
2665c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2666dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
26673856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_VIRTUALIZER");
2668c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
26692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2670163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2671dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if(status != -ENODATA){
2672163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled++;
26732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
26742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2675163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->NumberEffectsCalled ==
2676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       pContext->pBundledContext->NumberEffectsEnabled){
26773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process     Calling process with %d effects enabled, %d called: Effect %d",
2678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
26802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(status == -ENODATA){
26823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() processing last frame");
2683163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
26842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext->NumberEffectsCalled = 0;
2685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Process all the available frames, block processing is
2686163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           handled internalLY by the LVM bundle */
2687163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        lvmStatus = android::LvmBundle_process(    (LVM_INT16 *)inBuffer->raw,
26882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                (LVM_INT16 *)outBuffer->raw,
26892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                outBuffer->frameCount,
26902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                pContext);
2691163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(lvmStatus != LVM_SUCCESS){
26923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
2693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return lvmStatus;
2694163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
26955dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    } else {
26963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
2697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
2699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        // 2 is for stereo input
27005dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
27015dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            for (size_t i=0; i < outBuffer->frameCount*2; i++){
27025dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent                outBuffer->s16[i] =
27035dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent                        clamp16((LVM_INT32)outBuffer->s16[i] + (LVM_INT32)inBuffer->s16[i]);
27045dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            }
270597bb6e89845cb6d85f4d34a4efcc1de2ce585336Marco Nelissen        } else if (outBuffer->raw != inBuffer->raw) {
27065dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
27075dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent        }
27082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2709163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
27102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
27112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end Effect_process */
27122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Command */
2714e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_command(effect_handle_t  self,
271525f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdCode,
271625f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdSize,
2717163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pCmdData,
271825f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            *replySize,
2719163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pReplyData){
27202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
27212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int retsize;
27222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\t\nEffect_command start");
27242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST){
27263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_BASS_BOOST");
27272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
27282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER){
27293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_VIRTUALIZER");
2730163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
27312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER){
27323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_EQUALIZER");
2733163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
27342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME){
27353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_VOLUME");
2736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
27372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
27393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL");
27402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
27412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
27422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
27442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2745163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // Incase we disable an effect, next time process is
2746163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // called the number of effect called could be greater
2747163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // pContext->pBundledContext->NumberEffectsCalled = 0;
27482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d",
2750163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsCalled,
2751163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsEnabled);
27522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (cmdCode){
27542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_INIT:
2755010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
27563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d",
2757010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                        pContext->EffectType);
2758010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                return -EINVAL;
2759010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            }
2760010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            *(int *) pReplyData = 0;
27613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start");
27622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
27633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST");
27642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                android::BassSetStrength(pContext, 0);
27652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
27673856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER");
2768163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::VirtualizerSetStrength(pContext, 0);
2769163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
27713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER");
2772163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::EqualizerSetPreset(pContext, 0);
2773163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
27753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VOLUME");
2776010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0);
2777163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2779163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
27803d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        case EFFECT_CMD_SET_CONFIG:
27813d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_CONFIG start");
27822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pCmdData    == NULL||
27832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                cmdSize     != sizeof(effect_config_t)||
27842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                pReplyData  == NULL||
27852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize  != sizeof(int)){
27863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
27873d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                        "EFFECT_CMD_SET_CONFIG: ERROR");
27883d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                return -EINVAL;
27893d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            }
27903d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            *(int *) pReplyData = android::Effect_setConfig(pContext, (effect_config_t *) pCmdData);
27913d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_CONFIG end");
27923d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            break;
27933d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
27943d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        case EFFECT_CMD_GET_CONFIG:
27953d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            if (pReplyData == NULL ||
27963d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                *replySize != sizeof(effect_config_t)) {
27973d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
27983d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                        "EFFECT_CMD_GET_CONFIG: ERROR");
27992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
28002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28013d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
28023d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            android::Effect_getConfig(pContext, (effect_config_t *)pReplyData);
28032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
28042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_RESET:
28063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start");
28073d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            android::Effect_setConfig(pContext, &pContext->config);
28083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end");
28092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
28102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_GET_PARAM:{
28123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2813163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2815163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2816163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2817163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2818163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
28193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
28202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
28212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
28242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
28262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
28282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
28302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::BassBoost_getParameter(pContext,
2832c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
28332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            (size_t  *)&p->vsize,
28342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            p->data + voffset);
28352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
28372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM "
2839163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2840163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2841163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2842163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
28432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
2844163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2846163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2847163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2848163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2849163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
28503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
28512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
28522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
28552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
28572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
28592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
28612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Virtualizer_getParameter(pContext,
2863c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                             (void *)p->data,
28642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                             (size_t  *)&p->vsize,
28652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                              p->data + voffset);
28662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
28682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM "
2870163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2871163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2872163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2873163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
28742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
28752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
28763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEqualizer_command cmdCode Case: "
2877163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2878163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2879163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2880163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL ||
2881163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) {
28823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
28832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM");
28842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
28852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
28862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
2887163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
2889163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
2891163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
2893163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2894c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                p->status = android::Equalizer_getParameter(pContext,
2895c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
2896c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            &p->vsize,
2897c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data + voffset);
2898163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
28992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
2900163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
29013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, "
2902163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //       "*pReplyData %08x %08x",
2903163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize,
2904163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset),
2905163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset +
2906163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        sizeof(int32_t)));
29072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
29082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
29093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2910163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2912163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
29143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
29152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
29162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
29192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
29212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
29232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
29252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Volume_getParameter(pContext,
2927c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                         (void *)p->data,
29282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         (size_t  *)&p->vsize,
29292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         p->data + voffset);
29302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
29322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command EFFECT_CMD_GET_PARAM "
2934163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2935163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2936163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2937163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
2938163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end");
29402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
29412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_PARAM:{
29423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
29432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
29443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2945dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2946dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *replySize,
2947dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2951163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2952163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
29533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
29542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
29552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
29582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
29603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
29612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
29622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tnBassBoost_command cmdSize is %d\n"
2966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2967163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2969163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2970163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
29712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::BassBoost_setParameter(pContext,
2973c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
29742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    p->data + p->psize);
29752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
29762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
29773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block              //ALOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2978d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2979d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *replySize,
2980d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2982163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2983163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2984163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2985163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
29863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
29882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
29912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
29933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
29942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
29952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
29962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
29972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tnVirtualizer_command cmdSize is %d\n"
2999163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
3000163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
3001163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
3002163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
3003163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
30042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Virtualizer_setParameter(pContext,
3006c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                      (void *)p->data,
3007163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                       p->data + p->psize);
30082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
30092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
30103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block               //ALOGV("\tEqualizer_command cmdCode Case: "
3011d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        "EFFECT_CMD_SET_PARAM start");
30123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block               //ALOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
3013d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3014d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *replySize,
3015d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
30162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
30182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pReplyData == NULL || *replySize != sizeof(int32_t)) {
30193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
30202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
30212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
30222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
30232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
30242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Equalizer_setParameter(pContext,
3026c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
3027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                     p->data + p->psize);
30282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
30292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
30303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
30313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
3032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3033163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
3034d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) +sizeof(int32_t)));
30352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (    pCmdData   == NULL||
30372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        cmdSize    < (int)(sizeof(effect_param_t) + sizeof(int32_t))||
30382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        pReplyData == NULL||
30392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        *replySize != sizeof(int32_t)){
30403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
30412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
30422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
30432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
30442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
30452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Volume_setParameter(pContext,
3047c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                 (void *)p->data,
3048163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                 p->data + p->psize);
3049163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
30503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end");
30512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
30522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_ENABLE:
30543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start");
30552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
30563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
30572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
3058163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
305929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
306029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_TRUE);
30612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3062163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
30632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_DISABLE:
30643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start");
30652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
30663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
30672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
3068163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
306929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_FALSE);
30702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
30712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_DEVICE:
3073163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
30743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start");
3075e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            uint32_t device = *(uint32_t *)pCmdData;
3076163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3077b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            if (pContext->EffectType == LVM_BASS_BOOST) {
3078b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                if((device == AUDIO_DEVICE_OUT_SPEAKER) ||
3079b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) ||
3080b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
30813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d",
3082163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
30833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST");
3084163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3085163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device doesnt support bassboost the effect must be temporarily disabled
3086163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3087163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3088163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3089b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
30903856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d",
3091163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3092163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3093163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3094b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bBassTempDisabled = LVM_TRUE;
3095b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                } else {
30963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d",
3097163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                         *(int32_t *)pCmdData);
3098163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3099163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports bassboost and the effect has been temporarily disabled
3100163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3101163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3102b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
31033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d",
3104163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3105163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3106163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3107b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bBassTempDisabled = LVM_FALSE;
3108163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3109163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3110b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            if (pContext->EffectType == LVM_VIRTUALIZER) {
3111b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                if((device == AUDIO_DEVICE_OUT_SPEAKER)||
3112b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)||
3113b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
31143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d",
3115163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
31163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER");
3117163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3118163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //If a device doesnt support virtualizer the effect must be temporarily disabled
3119163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3120163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3121163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3122b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) {
31233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d",
3124163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3125163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3126163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3127b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
3128b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                } else {
31293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d",
3130163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
3131163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3132163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports virtualizer and the effect has been temporarily disabled
3133163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3134163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3135b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
31363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d",
3137163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
3138163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3139163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3140b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
3141163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3142163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
31433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end");
31442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3145163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
3146163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_VOLUME:
3147163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
3148dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            uint32_t leftVolume, rightVolume;
3149dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int16_t  leftdB, rightdB;
3150dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int16_t  maxdB, pandB;
3151dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int32_t  vol_ret[2] = {1<<24,1<<24}; // Apply no volume
3152dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int      status = 0;
3153dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ControlParams_t     ActiveParams;           /* Current control Parameters */
3154dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;  /* Function call status */
3155163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3156163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // if pReplyData is NULL, VOL_CTRL is delegated to another effect
3157163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pReplyData == LVM_NULL){
3158163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                break;
3159163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
31602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3161dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (pCmdData == NULL ||
3162dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                cmdSize != 2 * sizeof(uint32_t)) {
31633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
3164dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                        "EFFECT_CMD_SET_VOLUME: ERROR");
3165dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                return -EINVAL;
3166163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3168dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            leftVolume  = ((*(uint32_t *)pCmdData));
3169dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            rightVolume = ((*((uint32_t *)pCmdData + 1)));
3170dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3171dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(leftVolume == 0x1000000){
3172dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                leftVolume -= 1;
3173dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3174dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(rightVolume == 0x1000000){
3175dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                rightVolume -= 1;
3176dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3177dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3178dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            // Convert volume to dB
3179dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            leftdB  = android::LVC_Convert_VolToDb(leftVolume);
3180dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            rightdB = android::LVC_Convert_VolToDb(rightVolume);
3181dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3182dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pandB = rightdB - leftdB;
3183dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3184dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            // Calculate max volume in dB
3185dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            maxdB = leftdB;
3186dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(rightdB > maxdB){
3187dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                maxdB = rightdB;
3188dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
31893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME Session: %d, SessionID: %d VOLUME is %d dB (%d), "
3190dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //      "effect is %d",
3191dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //pContext->pBundledContext->SessionNo, pContext->pBundledContext->SessionId,
3192dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //(int32_t)maxdB, maxVol<<7, pContext->EffectType);
31933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME: Left is %d, Right is %d", leftVolume, rightVolume);
31943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME: Left %ddB, Right %ddB, Position %ddB",
3195dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //        leftdB, rightdB, pandB);
3196d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
3197163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            memcpy(pReplyData, vol_ret, sizeof(int32_t)*2);
3198dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            android::VolumeSetVolumeLevel(pContext, (int16_t)(maxdB*100));
3199dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3200dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Get the current settings */
3201dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LvmStatus =LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
3202dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
3203dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(LvmStatus != LVM_SUCCESS) return -EINVAL;
3204dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3205dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Volume parameters */
3206dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            ActiveParams.VC_Balance  = pandB;
32073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\t\tVolumeSetStereoPosition() (-96dB -> +96dB)-> %d\n", ActiveParams.VC_Balance );
3208dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3209dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Activate the initial settings */
3210dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LvmStatus =LVM_SetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
3211dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
3212dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(LvmStatus != LVM_SUCCESS) return -EINVAL;
3213163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
3214163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent         }
3215163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
3216163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
32172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
32182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
32192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
32202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command end...\n\n");
32222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
32232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end Effect_command */
32242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3225e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent/* Effect Control Interface Implementation: get_descriptor */
3226e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_getDescriptor(effect_handle_t   self,
3227e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                                    effect_descriptor_t *pDescriptor)
3228e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent{
3229e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    EffectContext * pContext = (EffectContext *) self;
3230e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    const effect_descriptor_t *desc;
3231e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3232e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pContext == NULL || pDescriptor == NULL) {
32333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("Effect_getDescriptor() invalid param");
3234e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return -EINVAL;
3235e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
3236e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3237e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    switch(pContext->EffectType) {
3238e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_BASS_BOOST:
3239e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gBassBoostDescriptor;
3240e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3241e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_VIRTUALIZER:
3242e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gVirtualizerDescriptor;
3243e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3244e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_EQUALIZER:
3245e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gEqualizerDescriptor;
3246e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3247e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_VOLUME:
3248e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gVolumeDescriptor;
3249e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3250e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        default:
3251e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            return -EINVAL;
3252e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
3253e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3254a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pDescriptor = *desc;
3255e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3256e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    return 0;
3257e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent}   /* end Effect_getDescriptor */
3258e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3259e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent// effect_handle_t interface implementation for effect
32602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst struct effect_interface_s gLvmEffectInterface = {
32612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_process,
3262e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    Effect_command,
3263ba7b8f881a9b6b21803752326d2932a3bd42d7cfEric Laurent    Effect_getDescriptor,
3264ba7b8f881a9b6b21803752326d2932a3bd42d7cfEric Laurent    NULL,
32652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};    /* end gLvmEffectInterface */
32662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32677f16b197c76fbae9399242f055a7ee16dcd0fd6dMarco Nelissen// This is the only symbol that needs to be exported
32687f16b197c76fbae9399242f055a7ee16dcd0fd6dMarco Nelissen__attribute__ ((visibility ("default")))
3269e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentaudio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
3270e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    tag : AUDIO_EFFECT_LIBRARY_TAG,
3271e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    version : EFFECT_LIBRARY_API_VERSION,
3272e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    name : "Effect Bundle Library",
3273e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    implementor : "NXP Software Ltd.",
3274e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    create_effect : android::EffectCreate,
3275e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    release_effect : android::EffectRelease,
3276e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    get_descriptor : android::EffectGetDescriptor,
3277e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent};
3278e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3279e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent}
3280