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 <assert.h>
237b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn#include <inttypes.h>
247b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn#include <new>
252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <stdlib.h>
262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <string.h>
277b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn
287b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn#include <cutils/log.h>
29b4d307481960b6b348fae4b4e8edefd003c3d36cGlenn Kasten#include "EffectBundle.h"
302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent// effect_handle_t interface implementation for bass boost
332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" const struct effect_interface_s gLvmEffectInterface;
342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_NULLADDRESS){\
373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Parameter error - "\
382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_ALIGNMENTERROR){\
413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Parameter error - "\
422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad alignment returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_INVALIDNUMSAMPLES){\
453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Parameter error - "\
462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_OUTOFRANGE){\
493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Parameter error - "\
502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "out of range returned by %s in %s\n", callingFunc, calledFunc);\
512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
545dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent
555dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurentstatic inline int16_t clamp16(int32_t sample)
565dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent{
575dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    // check overflow for both positive and negative values:
585dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    // all bits above short range must me equal to sign bit
595dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    if ((sample>>15) ^ (sample>>31))
605dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent        sample = 0x7FFF ^ (sample>>31);
615dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    return sample;
625dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent}
635dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent
642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Namespaces
652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace android {
662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace {
672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
68d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent// Flag to allow a one time init of global memory, only happens on first call ever
69d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurentint LvmInitFlag = LVM_FALSE;
70d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric LaurentSessionContext GlobalSessionMemory[LVM_MAX_SESSIONS];
71d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurentint SessionIndex[LVM_MAX_SESSIONS];
72d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent
732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* local functions */
742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define CHECK_ARG(cond) {                     \
752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (!(cond)) {                            \
763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Invalid argument: "#cond);      \
772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;                       \
782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }                                         \
792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW BassBoost UUID
832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gBassBoostDescriptor = {
842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
86e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
87209bbbcf4190231f9dede758cbe77d109919f9f1Jean-Michel Trivi        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_DEVICE_IND
88163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
89d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BASS_BOOST_CUP_LOAD_ARM9E,
90d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Dynamic Bass Boost",
922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Virtualizer UUID
962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVirtualizerDescriptor = {
97163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
98163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
99e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
100163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
101163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
102d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VIRTUALIZER_CUP_LOAD_ARM9E,
103d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Virtualizer",
1052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Equalizer UUID
1092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gEqualizerDescriptor = {
1102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
1112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP
112e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
113209bbbcf4190231f9dede758cbe77d109919f9f1Jean-Michel Trivi        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_VOLUME_CTRL),
114d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        EQUALIZER_CUP_LOAD_ARM9E,
115d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Equalizer",
1172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Volume UUID
1212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVolumeDescriptor = {
1222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
1232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP
124e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
125163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
126d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        VOLUME_CUP_LOAD_ARM9E,
127d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        BUNDLE_MEM_USAGE,
1282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Volume",
1292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//--- local function prototypes
1332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init      (void);
1342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmBundle_init            (EffectContext *pContext);
1352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_enable          (EffectContext *pContext);
1362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_disable         (EffectContext *pContext);
1372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free            (EffectContext *pContext);
1383d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentint  Effect_setConfig          (EffectContext *pContext, effect_config_t *pConfig);
1393d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentvoid Effect_getConfig          (EffectContext *pContext, effect_config_t *pConfig);
140c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  BassBoost_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
141163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  BassBoost_getParameter    (EffectContext *pContext,
142c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
143377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                               uint32_t       *pValueSize,
1442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               void           *pValue);
145c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Virtualizer_setParameter  (EffectContext *pContext, void *pParam, void *pValue);
1462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Virtualizer_getParameter  (EffectContext *pContext,
147c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                               void           *pParam,
148377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                               uint32_t       *pValueSize,
149163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                               void           *pValue);
150c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Equalizer_setParameter    (EffectContext *pContext, void *pParam, void *pValue);
1512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Equalizer_getParameter    (EffectContext *pContext,
152c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
153377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                                uint32_t      *pValueSize,
1542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
155c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Volume_setParameter       (EffectContext *pContext, void *pParam, void *pValue);
1562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Volume_getParameter       (EffectContext *pContext,
157c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                void          *pParam,
158377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                                uint32_t      *pValueSize,
1592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
16029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurentint Effect_setEnabled(EffectContext *pContext, bool enabled);
1612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Library Interface Implementation */
1632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1645e92a7861196ddae14638d4b7a63fc4892b7ef59Glenn Kastenextern "C" int EffectCreate(const effect_uuid_t *uuid,
1652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             sessionId,
1667618c5cb2fd60e944307e46afa051987d1e016c6Jean-Michel Trivi                            int32_t             ioId __unused,
167e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                            effect_handle_t  *pHandle){
168dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    int ret = 0;
169c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int sessionNo;
1702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int i;
171dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    EffectContext *pContext = NULL;
172dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    bool newBundle = false;
173dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    SessionContext *pSessionContext;
1742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\n\tEffectCreate start session %d", sessionId);
1762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
177e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pHandle == NULL || uuid == NULL){
1783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer");
179dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
180dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
1812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmInitFlag == LVM_FALSE){
1842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmInitFlag = LVM_TRUE;
1853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Initializing all global memory");
1862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmGlobalBundle_init();
1872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
189c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Find next available sessionNo
190c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for(i=0; i<LVM_MAX_SESSIONS; i++){
191e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        if((SessionIndex[i] == LVM_UNUSED_SESSION)||(SessionIndex[i] == sessionId)){
192c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            sessionNo       = i;
193c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            SessionIndex[i] = sessionId;
1943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffectCreate: Allocating SessionNo %d for SessionId %d\n", sessionNo,sessionId);
195c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
196c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
197c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
198c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
199c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(i==LVM_MAX_SESSIONS){
2003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Cannot find memory to allocate for current session");
201dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
202dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
203c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
204dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
205dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    pContext = new EffectContext;
206dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // If this is the first create in this session
208c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(GlobalSessionMemory[sessionNo].bBundledEffectsEnabled == LVM_FALSE){
2093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - This is the first effect in current sessionId %d sessionNo %d",
210c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionId, sessionNo);
211c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
212c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_TRUE;
213c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        GlobalSessionMemory[sessionNo].pBundledContext        = new BundledEffectContext;
214dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        newBundle = true;
2152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
216c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = GlobalSessionMemory[sessionNo].pBundledContext;
217c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionNo                = sessionNo;
218c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SessionId                = sessionId;
219163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->hInstance                = NULL;
220163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVolumeEnabled           = LVM_FALSE;
221163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bEqualizerEnabled        = LVM_FALSE;
222163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassEnabled             = LVM_FALSE;
223163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassTempDisabled        = LVM_FALSE;
224163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerEnabled      = LVM_FALSE;
225163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
226333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        pContext->pBundledContext->nOutputDevice            = AUDIO_DEVICE_NONE;
227333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        pContext->pBundledContext->nVirtualizerForcedDevice = AUDIO_DEVICE_NONE;
228163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsEnabled     = 0;
229163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled      = 0;
230d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        pContext->pBundledContext->firstVolume              = LVM_TRUE;
2316a5c6ed13e3ea1b19835e08624125c9b1505b32cMarco Nelissen        pContext->pBundledContext->volume                   = 0;
232163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
233163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
2348f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        char fileName[256];
2358f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_in.pcm", pContext->pBundledContext);
2368f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmInPtr = fopen(fileName, "w");
2378f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr == NULL) {
2383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("cannot open %s", fileName);
239dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            ret = -EINVAL;
240dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            goto exit;
2418f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
242163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2438f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        snprintf(fileName, 256, "/data/tmp/bundle_%p_pcm_out.pcm", pContext->pBundledContext);
2448f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        pContext->pBundledContext->PcmOutPtr = fopen(fileName, "w");
2458f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr == NULL) {
2463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("cannot open %s", fileName);
2478f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
2488f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent           pContext->pBundledContext->PcmInPtr = NULL;
249dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent           ret = -EINVAL;
250dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent           goto exit;
251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
252163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        /* Saved strength is used to return the exact strength that was used in the set to the get
2552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * because we map the original strength range of 0:1000 to 1:15, and this will avoid
2562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * quantisation like effect when returning
2572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         */
258163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->BassStrengthSaved        = 0;
259163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->VirtStrengthSaved        = 0;
260163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->CurPreset                = PRESET_CUSTOM;
261163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved               = 0;
262163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bMuteEnabled             = LVM_FALSE;
263163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bStereoPositionEnabled   = LVM_FALSE;
264163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved            = 0;
265dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->workBuffer               = NULL;
266dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->frameCount               = -1;
267dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt   = 0;
268dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb     = 0;
269dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq     = 0;
270163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2719b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
2729b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent            pContext->pBundledContext->bandGaindB[i] = EQNB_5BandSoftPresets[i];
2739b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        }
2749b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
2753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Calling LvmBundle_init");
2762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ret = LvmBundle_init(pContext);
2772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (ret < 0){
2793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : EffectCreate() Bundle init failed");
280dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            goto exit;
2812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
2822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
2843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Assigning memory for previously created effect on sessionNo %d",
285c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                sessionNo);
286c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext =
287c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                GlobalSessionMemory[sessionNo].pBundledContext;
2882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext);
2902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
291dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo];
29229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
2932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Create each Effect
2942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Bass Boost
2963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST");
29729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bBassInstantiated = LVM_TRUE;
298dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb = 0;
299163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
300163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_BASS_BOOST;
3022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Virtualizer
3043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER");
30529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVirtualizerInstantiated=LVM_TRUE;
306dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt = 0;
307163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VIRTUALIZER;
3102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Equalizer
3123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER");
31329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bEqualizerInstantiated = LVM_TRUE;
314dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq = 0;
315163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_EQUALIZER;
3182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
3192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Volume
3203856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - Effect to be created is LVM_VOLUME");
32129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVolumeInstantiated = LVM_TRUE;
322163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VOLUME;
325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
3273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectCreate() invalid UUID");
328dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        ret = -EINVAL;
329dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        goto exit;
3302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
332dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentexit:
333dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if (ret != 0) {
334dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext != NULL) {
335dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (newBundle) {
336dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                GlobalSessionMemory[sessionNo].bBundledEffectsEnabled = LVM_FALSE;
337dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                SessionIndex[sessionNo] = LVM_UNUSED_SESSION;
338dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                delete pContext->pBundledContext;
339dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
340dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            delete pContext;
341dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
342e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        *pHandle = (effect_handle_t)NULL;
343dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    } else {
344e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        *pHandle = (effect_handle_t)pContext;
345dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    }
3463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectCreate end..\n\n");
347dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return ret;
3482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectCreate */
3492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
350e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentextern "C" int EffectRelease(effect_handle_t handle){
3513856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\n\tEffectRelease start %p", handle);
352e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    EffectContext * pContext = (EffectContext *)handle;
3532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectRelease start handle: %p, context %p", handle, pContext->pBundledContext);
3552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
3563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
3572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
358163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
36029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    SessionContext *pSessionContext = &GlobalSessionMemory[pContext->pBundledContext->SessionNo];
36129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
3622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Clear the instantiated flag for the effect
363dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // protect agains the case where an effect is un-instantiated without being disabled
3642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
3653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag");
36629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bBassInstantiated = LVM_FALSE;
367dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
368dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
369dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
370dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountBb = 0;
3712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VIRTUALIZER) {
3723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag");
37329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVirtualizerInstantiated = LVM_FALSE;
374dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
375dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
376dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
377dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountVirt = 0;
3782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_EQUALIZER) {
3793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag");
38029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bEqualizerInstantiated =LVM_FALSE;
381dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
382dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
383dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
384dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->SamplesToExitCountEq = 0;
3852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VOLUME) {
3863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag");
38729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->bVolumeInstantiated = LVM_FALSE;
388dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){
389dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
390dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
3912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
3923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n");
3932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
395dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // Disable effect, in this case ignore errors (return codes)
396dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    // if an effect has already been disabled
397dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    Effect_setEnabled(pContext, LVM_FALSE);
398dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext
40029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    if ((pSessionContext->bBassInstantiated == LVM_FALSE) &&
40129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bVolumeInstantiated == LVM_FALSE) &&
40229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bEqualizerInstantiated ==LVM_FALSE) &&
40329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            (pSessionContext->bVirtualizerInstantiated==LVM_FALSE))
4042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
405163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
4068f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmInPtr != NULL) {
4078f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmInPtr);
4088f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmInPtr = NULL;
4098f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
4108f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        if (pContext->pBundledContext->PcmOutPtr != NULL) {
4118f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            fclose(pContext->pBundledContext->PcmOutPtr);
4128f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent            pContext->pBundledContext->PcmOutPtr = NULL;
4138f45bd725549436eeacd12ee69349e2332ed8da5Eric Laurent        }
414163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
415c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
416c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
417c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        // Clear the SessionIndex
418c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        for(int i=0; i<LVM_MAX_SESSIONS; i++){
419c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(SessionIndex[i] == pContext->pBundledContext->SessionId){
420e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                SessionIndex[i] = LVM_UNUSED_SESSION;
4213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffectRelease: Clearing SessionIndex SessionNo %d for SessionId %d\n",
422c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        i, pContext->pBundledContext->SessionId);
423c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                break;
424c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
425c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
426c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
4273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: All effects are no longer instantiated\n");
428dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pSessionContext->bBundledEffectsEnabled = LVM_FALSE;
42929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        pSessionContext->pBundledContext = LVM_NULL;
4303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: Freeing LVM Bundle memory\n");
431163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmEffect_free(pContext);
4323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectRelease: Deleting LVM Bundle context %p\n", pContext->pBundledContext);
433dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->workBuffer != NULL) {
434dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            free(pContext->pBundledContext->workBuffer);
435dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        }
436163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        delete pContext->pBundledContext;
437c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext = LVM_NULL;
4382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // free the effect context for current effect
4402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    delete pContext;
4412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectRelease end\n");
4432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
4442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectRelease */
4462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4475e92a7861196ddae14638d4b7a63fc4892b7ef59Glenn Kastenextern "C" int EffectGetDescriptor(const effect_uuid_t *uuid,
448e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                                   effect_descriptor_t *pDescriptor) {
449e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    const effect_descriptor_t *desc = NULL;
450e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
451e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pDescriptor == NULL || uuid == NULL){
4523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("EffectGetDescriptor() called with NULL pointer");
453e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return -EINVAL;
454e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
455e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
456e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
457e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gBassBoostDescriptor;
458e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
459e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gVirtualizerDescriptor;
460e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
461e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gEqualizerDescriptor;
462e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0) {
463e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        desc = &gVolumeDescriptor;
464e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
465e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
466e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (desc == NULL) {
467e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return  -EINVAL;
468e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
469e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
470a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pDescriptor = *desc;
471e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
472e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    return 0;
473e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent} /* end EffectGetDescriptor */
474e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
4752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init(){
4763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmGlobalBundle_init start");
4772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for(int i=0; i<LVM_MAX_SESSIONS; i++){
4782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBundledEffectsEnabled   = LVM_FALSE;
4792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVolumeInstantiated      = LVM_FALSE;
4802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bEqualizerInstantiated   = LVM_FALSE;
4812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBassInstantiated        = LVM_FALSE;
4822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE;
4832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].pBundledContext          = LVM_NULL;
484c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
485e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        SessionIndex[i] = LVM_UNUSED_SESSION;
4862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
4882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
4892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_init()
4912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
4922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Initialize engine with default configuration, creates instance
4932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// with all effects disabled.
4942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
4962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
4972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
4982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
4992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
5002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
5012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_init(EffectContext *pContext){
5032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status;
5042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init start");
5062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
508e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.inputCfg.channels                      = AUDIO_CHANNEL_OUT_STEREO;
509e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.inputCfg.format                        = AUDIO_FORMAT_PCM_16_BIT;
510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
511163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
512163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
514163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
516e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.outputCfg.channels                     = AUDIO_CHANNEL_OUT_STEREO;
517e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.outputCfg.format                       = AUDIO_FORMAT_PCM_16_BIT;
518163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
519163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
520163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
521163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
522163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
5232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
5252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext->pBundledContext->hInstance != NULL){
5273856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
5282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Calling pContext->pBassBoost->free()");
5292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmEffect_free(pContext);
5312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
5332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Called pContext->pBassBoost->free()");
5342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;          /* Function call status */
5372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                         /* Control Parameters */
5382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_InstParams_t        InstParams;                     /* Instance parameters */
5392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_EQNB_BandDef_t      BandDefs[MAX_NUM_BANDS];        /* Equaliser band definitions */
5402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomParams_t    HeadroomParams;                 /* Headroom parameters */
5412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomBandDef_t   HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS];
5422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;                         /* Memory allocation table */
5432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    bool                    bMallocFailure = LVM_FALSE;
5442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the capabilities */
546163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    InstParams.BufferMode       = LVM_UNMANAGED_BUFFERS;
5472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.MaxBlockSize     = MAX_CALL_SIZE;
5482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.EQNB_NumBands    = MAX_NUM_BANDS;
5492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.PSA_Included     = LVM_PSA_ON;
5502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory, forcing alignment */
5522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(LVM_NULL,
5532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &MemTab,
5542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &InstParams);
5552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init")
5572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
5602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory */
5622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
5642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
5652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
5677b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %" PRIu32
5687b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                        " bytes for region %u\n", MemTab.Region[i].Size, i );
5692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                bMallocFailure = LVM_TRUE;
5702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
5717b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLvmBundle_init CreateInstance allocated %" PRIu32
5727b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                        " bytes for region %u at %p\n",
5732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
5792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     * succesfully allocated and return with an error
5802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     */
5812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(bMallocFailure == LVM_TRUE){
5822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
5832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
5847b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %" PRIu32
5857b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                        " bytes for region %u Not freeing\n", MemTab.Region[i].Size, i );
5862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
5877b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %" PRIu32
5887b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                     " bytes for region %u at %p- free\n",
589163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
5902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
5912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
5922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
5932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
5942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n");
5962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Initialise */
598163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->hInstance = LVM_NULL;
5992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Init sets the instance handle */
601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,
6022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &MemTab,
6032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &InstParams);
6042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init")
6062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
6092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the initial process parameters */
6112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* General parameters */
6122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.OperatingMode          = LVM_MODE_ON;
6132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SampleRate             = LVM_FS_44100;
6142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SourceFormat           = LVM_STEREO;
6152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SpeakerType            = LVM_HEADPHONES;
6162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->SampleRate = LVM_FS_44100;
618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Concert Sound parameters */
6202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerOperatingMode   = LVM_MODE_OFF;
6212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerType            = LVM_CONCERTSOUND;
6222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerReverbLevel     = 100;
623d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.CS_EffectLevel             = LVM_CS_EFFECT_NONE;
6242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* N-Band Equaliser parameters */
6262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_OperatingMode     = LVM_EQNB_OFF;
6272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_NBands            = FIVEBAND_NUMBANDS;
6282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.pEQNB_BandDefinition   = &BandDefs[0];
629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
6312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
6322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i];
6332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].QFactor   = EQNB_5BandPresetsQFactors[i];
634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        BandDefs[i].Gain      = EQNB_5BandSoftPresets[i];
6352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
6362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume Control parameters */
6382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_EffectLevel         = 0;
6392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_Balance             = 0;
6402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Treble Enhancement parameters */
6422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
6432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_EffectLevel         = 0;
6442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = (LVM_PSA_DecaySpeed_en)0;
6482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
6502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_OperatingMode       = LVM_BE_OFF;
6512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_EffectLevel         = 0;
6522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_CentreFreq          = LVM_BE_CENTRE_90Hz;
6532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_HPF                 = LVM_BE_HPF_ON;
6542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
6562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
6572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = LVM_PSA_SPEED_MEDIUM;
6582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
659d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    /* TE Control parameters */
660d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
661d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    params.TE_EffectLevel         = 0;
662d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
663163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance,
6652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &params);
6662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init")
6682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n");
6712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the headroom parameters */
6732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_Low          = 20;
6742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_High         = 4999;
675e44615ff6022239850a3ea459ad6e07b44c37544Eric Laurent    HeadroomBandDef[0].Headroom_Offset    = 0;
6762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_Low          = 5000;
6772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_High         = 24000;
678e44615ff6022239850a3ea459ad6e07b44c37544Eric Laurent    HeadroomBandDef[1].Headroom_Offset    = 0;
6792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.pHeadroomDefinition    = &HeadroomBandDef[0];
6802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
6812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.NHeadroomBands         = 2;
6822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance,
6842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &HeadroomParams);
6852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init")
6872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n");
6903856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tLvmBundle_init End");
6912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
6922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end LvmBundle_init */
6932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
694dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
6952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_process()
6972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
6992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply LVM Bundle effects
7002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pIn:        pointer to stereo 16 bit input data
7032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to stereo 16 bit output data
7042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  frameCount: Frames to process
7052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
7072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Outputs:
7092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to updated stereo 16 bit output data
7102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_process(LVM_INT16        *pIn,
714163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      LVM_INT16        *pOut,
715163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      int              frameCount,
716163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      EffectContext    *pContext){
7172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
720163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               *pOutTmp;
721dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
722163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){
723163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = pOut;
724163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
725dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        if (pContext->pBundledContext->frameCount != frameCount) {
726dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (pContext->pBundledContext->workBuffer != NULL) {
727dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                free(pContext->pBundledContext->workBuffer);
728dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
729dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->workBuffer =
730dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2);
731dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->frameCount = frameCount;
732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
733dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pOutTmp = pContext->pBundledContext->workBuffer;
734163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
7353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("LVM_ERROR : LvmBundle_process invalid access mode");
736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
737163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
739163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
740163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pIn, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmInPtr);
741163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmInPtr);
742163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
743163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("Calling LVM_Process");
745d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
746163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Process the samples */
7472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */
7482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pIn,                                  /* Input buffer */
7492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pOutTmp,                              /* Output buffer */
7502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            (LVM_UINT16)frameCount,               /* Number of samples to read */
7512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            0);                                   /* Audo Time */
752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process")
7542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
7552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
757163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pOutTmp, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmOutPtr);
758163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmOutPtr);
759163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
760163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
761163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
762163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        for (int i=0; i<frameCount*2; i++){
763dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pOut[i] = clamp16((LVM_INT32)pOut[i] + (LVM_INT32)pOutTmp[i]);
764163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
765163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
7662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmBundle_process */
7682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_enable()
7712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Enable the effect in the bundle
7732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_enable(EffectContext *pContext){
7823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable start");
783163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
7862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
787163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
788163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable")
7922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
7933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n");
7942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
7963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST");
7972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_ON;
7982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
8003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER");
8012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_ON;
8022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
8043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER");
8052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_ON;
8062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
8083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_enable : Enabling LVM_VOLUME");
809163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
810163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable")
8132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
814163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n");
8163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_enable end");
8172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_disable()
8222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Disable the effect in the bundle
8242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_disable(EffectContext *pContext){
8333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable start");
834163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
8362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
837163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
838163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
8392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
8402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable")
8422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
8433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n");
8442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
8463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST");
8472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_OFF;
8482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
8503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_VIRTUALIZER");
8512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_OFF;
8522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
8543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_EQUALIZER");
8552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_OFF;
8562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
8583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLvmEffect_disable : Disabling LVM_VOLUME");
859163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
860163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable")
8632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
864163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
8653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n");
8663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tLvmEffect_disable end");
8672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
8682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
8692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_free()
8722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Free all memory associated with the Bundle.
8742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free(EffectContext *pContext){
8832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;         /* Function call status */
8842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                        /* Control Parameters */
8852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;
8862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Free the algorithm memory */
8882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance,
8892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   &MemTab,
8902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   LVM_NULL);
8912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free")
8932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
8952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
8962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress != NULL){
8977b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLvmEffect_free - START freeing %" PRIu32 " bytes for region %u at %p\n",
8982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
9012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9027b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLvmEffect_free - END   freeing %" PRIu32 " bytes for region %u at %p\n",
9032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
9042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
9057b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLVM_ERROR : LvmEffect_free - trying to free with NULL pointer %" PRIu32
9067b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                        " bytes for region %u at %p ERROR\n",
9072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
9082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
9092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
9102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
9112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmEffect_free */
9122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9143d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Effect_setConfig()
9152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Set input and output audio configuration.
9172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
9212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//      configuration parameters
9222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
9242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9273d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentint Effect_setConfig(EffectContext *pContext, effect_config_t *pConfig){
928163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_Fs_en   SampleRate;
9293d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tEffect_setConfig start");
9302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
9322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig != NULL);
9332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
9352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels);
9362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
937e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    CHECK_ARG(pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO);
9382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
9392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
940e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    CHECK_ARG(pConfig->inputCfg.format == AUDIO_FORMAT_PCM_16_BIT);
9412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
942a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    pContext->config = *pConfig;
9432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    switch (pConfig->inputCfg.samplingRate) {
945163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 8000:
946163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_8000;
947c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 8000*2; // 2 secs Stereo
948163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
949163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 16000:
950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_16000;
951c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 16000*2; // 2 secs Stereo
952163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
953163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 22050:
954163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_22050;
955c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 22050*2; // 2 secs Stereo
956163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
957163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 32000:
958163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_32000;
959c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 32000*2; // 2 secs Stereo
960163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
961163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 44100:
962163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_44100;
963c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 44100*2; // 2 secs Stereo
964163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
965163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 48000:
966163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_48000;
967c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SamplesPerSecond = 48000*2; // 2 secs Stereo
968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
969163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    default:
9703d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig invalid sampling rate %d", pConfig->inputCfg.samplingRate);
971163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
972163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
974163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->SampleRate != SampleRate){
9752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
976163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ControlParams_t     ActiveParams;
977163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;
9782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9793d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig change sampling rate to %d", SampleRate);
9802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
981163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
982163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
983163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
9842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9853d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_setConfig")
986163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9889f6f0a7eb1d7f2c35f3547779364a1a8d6d4a24cEric Laurent        ActiveParams.SampleRate = SampleRate;
9899f6f0a7eb1d7f2c35f3547779364a1a8d6d4a24cEric Laurent
990163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9923d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_setConfig")
9933d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\tEffect_setConfig Succesfully called LVM_SetControlParameters\n");
994c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        pContext->pBundledContext->SampleRate = SampleRate;
9952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
996163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
9973d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        //ALOGV("\tEffect_setConfig keep sampling rate at %d", SampleRate);
998163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
9992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10003d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tEffect_setConfig End....");
1001163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
10023d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent}   /* end Effect_setConfig */
10033d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
10043d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
10053d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Effect_getConfig()
10063d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
10073d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Purpose: Get input and output audio configuration.
10083d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10093d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Inputs:
10103d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//  pContext:   effect engine context
10113d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
10123d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//      configuration parameters
10133d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10143d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Outputs:
10153d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
10163d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
10173d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
10183d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentvoid Effect_getConfig(EffectContext *pContext, effect_config_t *pConfig)
10193d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent{
1020a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pConfig = pContext->config;
10213d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent}   /* end Effect_getConfig */
10222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassGetStrength()
10252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
10282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
10292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the
10302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
10312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t BassGetStrength(EffectContext *pContext){
10383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved);
10392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
10412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1042163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1043163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength")
10472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
10482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n");
10502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Check that the strength returned matches the strength that was set earlier */
1052163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(ActiveParams.BE_EffectLevel !=
1053163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){
10543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n",
10552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved);
10562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
10572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
10582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassGetStrength() (saved)  -> %d\n", pContext->pBundledContext->BassStrengthSaved );
10612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return pContext->pBundledContext->BassStrengthSaved;
10622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassGetStrength */
10632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassSetStrength()
10662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15
10692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid BassSetStrength(EffectContext *pContext, uint32_t strength){
10773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength(%d)", strength);
10782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->BassStrengthSaved = (int)strength;
10802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
10862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
10872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength")
10893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n");
10902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
10922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_EffectLevel    = (LVM_INT16)((15*strength)/1000);
10932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_CentreFreq     = LVM_BE_CENTRE_90Hz;
10942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
10962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength")
11013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n");
11022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassSetStrength */
11032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerGetStrength()
11062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
11092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
1110163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the
11112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
11122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t VirtualizerGetStrength(EffectContext *pContext){
11193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved);
11202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
11222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
11232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength")
11272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
11282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n");
11303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerGetStrength() (0-100)   -> %d\n", ActiveParams.VirtualizerReverbLevel*10);
1131d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    return pContext->pBundledContext->VirtStrengthSaved;
11322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getStrength */
11332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerSetStrength()
11362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15
11392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
11432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
11473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength(%d)", strength);
11482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
11492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
11502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1151163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->VirtStrengthSaved = (int)strength;
1152163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
11532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
11552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength")
11573856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n");
11582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Virtualizer parameters */
1160d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    ActiveParams.CS_EffectLevel             = (int)((strength*32767)/1000);
11612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength() (0-1000)   -> %d\n", strength );
11633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength() (0- 100)   -> %d\n", ActiveParams.CS_EffectLevel );
11642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
11672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength")
11683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n\n");
11692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setStrength */
11702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1171333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1172333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// VirtualizerIsDeviceSupported()
1173333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1174333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Purpose:
1175333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Check if an audio device type is supported by this implementation
1176333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//
1177333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Inputs:
1178333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  deviceType   the type of device that affects the processing (e.g. for binaural vs transaural)
1179333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Output:
1180333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  -EINVAL      if the configuration is not supported or it is unknown
1181333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  0            if the configuration is supported
1182333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1183333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Triviint VirtualizerIsDeviceSupported(audio_devices_t deviceType) {
1184333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    switch (deviceType) {
1185333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    case AUDIO_DEVICE_OUT_WIRED_HEADSET:
1186333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    case AUDIO_DEVICE_OUT_WIRED_HEADPHONE:
1187333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES:
1188333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        return 0;
1189333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    default :
1190333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        return -EINVAL;
1191333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    }
1192333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi}
1193333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1194333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1195333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// VirtualizerIsConfigurationSupported()
1196333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1197333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Purpose:
1198333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Check if a channel mask + audio device type is supported by this implementation
1199333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//
1200333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Inputs:
1201333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  channelMask  the channel mask of the input to virtualize
1202333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  deviceType   the type of device that affects the processing (e.g. for binaural vs transaural)
1203333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Output:
1204333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  -EINVAL      if the configuration is not supported or it is unknown
1205333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  0            if the configuration is supported
1206333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1207333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Triviint VirtualizerIsConfigurationSupported(audio_channel_mask_t channelMask,
1208333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        audio_devices_t deviceType) {
1209333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    uint32_t channelCount = audio_channel_count_from_out_mask(channelMask);
1210333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    if ((channelCount == 0) || (channelCount > 2)) {
1211333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        return -EINVAL;
1212333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    }
1213333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1214333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    return VirtualizerIsDeviceSupported(deviceType);
1215333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi}
1216333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1217333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1218333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// VirtualizerForceVirtualizationMode()
1219333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1220333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Purpose:
1221333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Force the virtualization mode to that of the given audio device
1222333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//
1223333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Inputs:
1224333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  pContext     effect engine context
1225333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  forcedDevice the type of device whose virtualization mode we'll always use
1226333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Output:
1227333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  -EINVAL      if the device is not supported or is unknown
1228333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  0            if the device is supported and the virtualization mode forced
1229333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//
1230333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1231333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Triviint VirtualizerForceVirtualizationMode(EffectContext *pContext, audio_devices_t forcedDevice) {
1232333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    ALOGV("VirtualizerForceVirtualizationMode: forcedDev=0x%x enabled=%d tmpDisabled=%d",
1233333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            forcedDevice, pContext->pBundledContext->bVirtualizerEnabled,
1234333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            pContext->pBundledContext->bVirtualizerTempDisabled);
1235333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    int status = 0;
1236333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    bool useVirtualizer = false;
1237333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1238333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    if (VirtualizerIsDeviceSupported(forcedDevice) != 0) {
1239333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        // forced device is not supported, make it behave as a reset of forced mode
1240333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        forcedDevice = AUDIO_DEVICE_NONE;
1241333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        // but return an error
1242333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        status = -EINVAL;
1243333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    }
1244333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1245333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    if (forcedDevice == AUDIO_DEVICE_NONE) {
1246333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        // disabling forced virtualization mode:
1247333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        // verify whether the virtualization should be enabled or disabled
1248333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        if (VirtualizerIsDeviceSupported(pContext->pBundledContext->nOutputDevice) == 0) {
1249333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            useVirtualizer = (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE);
1250333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        }
1251333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        pContext->pBundledContext->nVirtualizerForcedDevice = AUDIO_DEVICE_NONE;
1252333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    } else {
1253333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        // forcing virtualization mode: here we already know the device is supported
1254333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        pContext->pBundledContext->nVirtualizerForcedDevice = AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
1255333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        // only enable for a supported mode, when the effect is enabled
1256333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        useVirtualizer = (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE);
1257333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    }
1258333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1259333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    if (useVirtualizer) {
1260333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        if (pContext->pBundledContext->bVirtualizerTempDisabled == LVM_TRUE) {
1261333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            ALOGV("\tVirtualizerForceVirtualizationMode re-enable LVM_VIRTUALIZER");
1262333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            android::LvmEffect_enable(pContext);
1263333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
1264333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        } else {
1265333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            ALOGV("\tVirtualizerForceVirtualizationMode leaving LVM_VIRTUALIZER enabled");
1266333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        }
1267333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    } else {
1268333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        if (pContext->pBundledContext->bVirtualizerTempDisabled == LVM_FALSE) {
1269333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            ALOGV("\tVirtualizerForceVirtualizationMode disable LVM_VIRTUALIZER");
1270333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            android::LvmEffect_disable(pContext);
1271333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
1272333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        } else {
1273333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            ALOGV("\tVirtualizerForceVirtualizationMode leaving LVM_VIRTUALIZER disabled");
1274333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        }
1275333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    }
1276333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1277333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    ALOGV("\tafter VirtualizerForceVirtualizationMode: enabled=%d tmpDisabled=%d",
1278333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            pContext->pBundledContext->bVirtualizerEnabled,
1279333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            pContext->pBundledContext->bVirtualizerTempDisabled);
1280333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1281333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    return status;
1282333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi}
1283333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1284333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// VirtualizerGetSpeakerAngles()
1285333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1286333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Purpose:
1287333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Get the virtual speaker angles for a channel mask + audio device type
1288333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// configuration which is guaranteed to be supported by this implementation
1289333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//
1290333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Inputs:
1291333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  channelMask:   the channel mask of the input to virtualize
1292333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  deviceType     the type of device that affects the processing (e.g. for binaural vs transaural)
1293333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Input/Output:
1294333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//  pSpeakerAngles the array of integer where each speaker angle is written as a triplet in the
1295333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//                 following format:
1296333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//                    int32_t a bit mask with a single value selected for each speaker, following
1297333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//                            the convention of the audio_channel_mask_t type
1298333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//                    int32_t a value in degrees expressing the speaker azimuth, where 0 is in front
1299333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//                            of the user, 180 behind, -90 to the left, 90 to the right of the user
1300333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//                    int32_t a value in degrees expressing the speaker elevation, where 0 is the
1301333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//                            horizontal plane, +90 is directly above the user, -90 below
1302333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//
1303333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1304333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivivoid VirtualizerGetSpeakerAngles(audio_channel_mask_t channelMask __unused,
1305333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        audio_devices_t deviceType __unused, int32_t *pSpeakerAngles) {
1306333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    // the channel count is guaranteed to be 1 or 2
1307333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    // the device is guaranteed to be of type headphone
1308333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    // this virtualizer is always 2in with speakers at -90 and 90deg of azimuth, 0deg of elevation
1309333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    *pSpeakerAngles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_LEFT;
1310333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    *pSpeakerAngles++ = -90; // azimuth
1311333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    *pSpeakerAngles++ = 0;   // elevation
1312333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    *pSpeakerAngles++ = (int32_t) AUDIO_CHANNEL_OUT_FRONT_RIGHT;
1313333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    *pSpeakerAngles++ = 90;  // azimuth
1314333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    *pSpeakerAngles   = 0;   // elevation
1315333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi}
1316333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
1317333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1318333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// VirtualizerGetVirtualizationMode()
1319333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1320333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Purpose:
1321333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Retrieve the current device whose processing mode is used by this effect
1322333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//
1323333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi// Output:
1324333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//   AUDIO_DEVICE_NONE if the effect is not virtualizing
1325333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//   or the device type if the effect is virtualizing
1326333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi//----------------------------------------------------------------------------
1327333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Triviaudio_devices_t VirtualizerGetVirtualizationMode(EffectContext *pContext) {
1328333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    audio_devices_t virtDevice = AUDIO_DEVICE_NONE;
1329333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE)
1330333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            && (pContext->pBundledContext->bVirtualizerTempDisabled == LVM_FALSE)) {
1331333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        if (pContext->pBundledContext->nVirtualizerForcedDevice != AUDIO_DEVICE_NONE) {
1332333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            // virtualization mode is forced, return that device
1333333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            virtDevice = pContext->pBundledContext->nVirtualizerForcedDevice;
1334333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        } else {
1335333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            // no forced mode, return the current device
1336333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            virtDevice = pContext->pBundledContext->nOutputDevice;
1337333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        }
1338333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    }
1339333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    ALOGV("VirtualizerGetVirtualizationMode() returning 0x%x", virtDevice);
1340333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    return virtDevice;
1341333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi}
13429b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
13432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13449b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// EqualizerLimitBandLevels()
13452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13460ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent// Purpose: limit all EQ band gains to a value less than 0 dB while
13479b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//          preserving the relative band levels.
13482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
13532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13559b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurentvoid EqualizerLimitBandLevels(EffectContext *pContext) {
13569b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13579b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13599b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    /* Get the current settings */
13609b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13619b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerLimitBandLevels")
13629b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels Succesfully returned from LVM_GetControlParameters\n");
13639b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels just Got -> %d\n",
13649b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //          ActiveParams.pEQNB_BandDefinition[band].Gain);
13659b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
13660ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // Apply a volume correction to avoid clipping in the EQ based on 2 factors:
13670ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // - the maximum EQ band gain: the volume correction is such that the total of volume + max
13680ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // band gain is <= 0 dB
13690ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    // - the average gain in all bands weighted by their proximity to max gain band.
13700ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int maxGain = 0;
13710ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int avgGain = 0;
13720ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int avgCount = 0;
13739b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
13740ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        if (pContext->pBundledContext->bandGaindB[i] >= maxGain) {
13750ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpMaxGain = pContext->pBundledContext->bandGaindB[i];
13760ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpAvgGain = 0;
13770ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            int tmpAvgCount = 0;
13780ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            for (int j = 0; j < FIVEBAND_NUMBANDS; j++) {
13790ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                int gain = pContext->pBundledContext->bandGaindB[j];
13800ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // skip current band and gains < 0 dB
13810ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (j == i || gain < 0)
13820ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    continue;
13830ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // no need to continue if one band not processed yet has a higher gain than current
13840ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                // max
13850ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (gain > tmpMaxGain) {
13860ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    // force skipping "if (tmpAvgGain >= avgGain)" below as tmpAvgGain is not
13870ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    // meaningful in this case
13880ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    tmpAvgGain = -1;
13890ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    break;
13900ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                }
13910ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
13920ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                int weight = 1;
13930ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                if (j < (i + 2) && j > (i - 2))
13940ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                    weight = 4;
13950ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                tmpAvgGain += weight * gain;
13960ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                tmpAvgCount += weight;
13970ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            }
13980ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            if (tmpAvgGain >= avgGain) {
13990ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                maxGain = tmpMaxGain;
14000ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                avgGain = tmpAvgGain;
14010ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent                avgCount = tmpAvgCount;
14029b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent            }
14039b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        }
14040ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
14050ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
14060ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.pEQNB_BandDefinition[i].Gain = pContext->pBundledContext->bandGaindB[i];
14079b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    }
14082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14090ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    int gainCorrection = 0;
14100ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (maxGain + pContext->pBundledContext->volume > 0) {
14110ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        gainCorrection = maxGain + pContext->pBundledContext->volume;
14120ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
14130ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (avgCount) {
14140ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        gainCorrection += avgGain/avgCount;
14150ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
14160ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
14170ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    ALOGV("EqualizerLimitBandLevels() gainCorrection %d maxGain %d avgGain %d avgCount %d",
14180ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent            gainCorrection, maxGain, avgGain, avgCount);
14190ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
14200ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    ActiveParams.VC_EffectLevel  = pContext->pBundledContext->volume - gainCorrection;
14210ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (ActiveParams.VC_EffectLevel < -96) {
14220ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ActiveParams.VC_EffectLevel = -96;
14239b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    }
14240ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
14259b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    /* Activate the initial settings */
14269b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14279b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerLimitBandLevels")
14289b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerLimitBandLevels just Set -> %d\n",
14299b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //          ActiveParams.pEQNB_BandDefinition[band].Gain);
14300ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent
14310ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    //ALOGV("\tEqualizerLimitBandLevels just set (-96dB -> 0dB)   -> %d\n",ActiveParams.VC_EffectLevel );
14320ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if(pContext->pBundledContext->firstVolume == LVM_TRUE){
14330ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams);
14340ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process")
14350ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        ALOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks");
14360ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->firstVolume = LVM_FALSE;
14370ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
14389b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent}
14392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14409b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14419b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
14429b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// EqualizerGetBandLevel()
14439b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
14449b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Purpose: Retrieve the gain currently being used for the band passed in
14459b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
14469b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Inputs:
14479b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//  band:       band number
14489b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//  pContext:   effect engine context
14499b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
14509b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent// Outputs:
14519b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//
14529b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent//----------------------------------------------------------------------------
14539b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurentint32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
14549b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    //ALOGV("\tEqualizerGetBandLevel -> %d\n", pContext->pBundledContext->bandGaindB[band] );
14559b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    return pContext->pBundledContext->bandGaindB[band] * 100;
14562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
14572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetBandLevel()
14602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Sets gain value for the given band.
14632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
14662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Gain:       Gain to be applied in millibels
14672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
14702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//---------------------------------------------------------------------------
1472d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurentvoid EqualizerSetBandLevel(EffectContext *pContext, int band, short Gain){
1473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int gainRounded;
1474163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(Gain > 0){
1475163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain+50)/100);
1476163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1477163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain-50)/100);
1478163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
14793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);
14809b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    pContext->pBundledContext->bandGaindB[band] = gainRounded;
14812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
14829b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14839b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
14842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
14859b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
14862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetCentreFrequency()
14882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the frequency being used for the band passed in
14902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
14932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
14962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){
1499163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Frequency =0;
15002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1501163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1502163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1503163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1504163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
15072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency")
15092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef   = ActiveParams.pEQNB_BandDefinition;
1511163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Frequency = (int32_t)BandDef[band].Frequency*1000;     // Convert to millibels
15122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency );
15143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n");
1515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Frequency;
15162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
15172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandFreqRange(
15202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets lower and upper boundaries of a band.
15242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the high shelf, the low bound is the band frequency and the high
15252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// bound is Nyquist.
15262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the peaking filters, they are the gain[dB]/2 points.
15272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
15302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
15312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
15332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
15342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
15352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15367618c5cb2fd60e944307e46afa051987d1e016c6Jean-Michel Triviint32_t EqualizerGetBandFreqRange(EffectContext *pContext __unused, int32_t band, uint32_t *pLow,
1537163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                  uint32_t *pHi){
1538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pLow = bandFreqRange[band][0];
1539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pHi  = bandFreqRange[band][1];
1540163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
15412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
15422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBand(
15452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Returns the band with the maximum influence on a given frequency.
15492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Result is unaffected by whether EQ is enabled or not, or by whether
15502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// changes have been committed or not.
15512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  targetFreq   The target frequency, in millihertz.
15542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
15552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
15572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
15582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
15592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15607618c5cb2fd60e944307e46afa051987d1e016c6Jean-Michel Triviint32_t EqualizerGetBand(EffectContext *pContext __unused, uint32_t targetFreq){
15612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int band = 0;
15622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1563163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(targetFreq < bandFreqRange[0][0]){
1564163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
1565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if(targetFreq == bandFreqRange[0][0]){
1566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
1567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1568163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for(int i=0; i<FIVEBAND_NUMBANDS;i++){
1569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){
1570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            band = i;
1571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1572163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
15732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return band;
15742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
15752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPreset(
15782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets the currently set preset ID.
15822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Will return PRESET_CUSTOM in case the EQ parameters have been modified
15832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// manually since a preset was set.
15842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
15862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
15872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetPreset(EffectContext *pContext){
1590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return pContext->pBundledContext->CurPreset;
15912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
15922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetPreset(
15952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
15982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Sets the current preset by ID.
15992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// All the band parameters will be overridden.
16002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
16032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  preset       The preset ID.
16042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetPreset(EffectContext *pContext, int preset){
16072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetPreset(%d)", preset);
16092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = preset;
16102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    //ActiveParams.pEQNB_BandDefinition = &BandDefs[0];
16122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
16132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
16149b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent        pContext->pBundledContext->bandGaindB[i] =
16159b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent                EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
16162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
16172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16189b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
16199b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
16203856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
16212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
16222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
1623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetNumPresets(){
1625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return sizeof(gEqualizerPresets) / sizeof(PresetConfig);
16262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
16272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPresetName(
16302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
16322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets a human-readable name for a preset ID. Will return "Custom" if
16332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// PRESET_CUSTOM is passed.
16342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// preset       The preset ID. Must be less than number of presets.
16372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//-------------------------------------------------------------------------
16392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst char * EqualizerGetPresetName(int32_t preset){
16403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetPresetName start(%d)", preset);
16412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (preset == PRESET_CUSTOM) {
16422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return "Custom";
16432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
16442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return gEqualizerPresets[preset].name;
16452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
16463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizerGetPresetName end(%d)", preset);
1647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
16482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
16492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetVolumeLevel()
16522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
16542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
16572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  level       level to be applied
16582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
16622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16630ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (level > 0 || level < -9600) {
16640ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        return -EINVAL;
16650ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
1666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
16670ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (pContext->pBundledContext->bMuteEnabled == LVM_TRUE) {
16680ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->levelSaved = level / 100;
16690ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    } else {
16700ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = level / 100;
1671d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    }
16729b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
16739b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent    EqualizerLimitBandLevels(pContext);
16749b3c701bbdbf3e4655758e995d467b325f8f366dEric Laurent
16752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
167617a736c3e1d062d7fc916329eb32aef8935614afGlenn Kasten}    /* end VolumeSetVolumeLevel */
16772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeGetVolumeLevel()
16802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
16822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
16852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){
16892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16900ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    if (pContext->pBundledContext->bMuteEnabled == LVM_TRUE) {
16910ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        *level = pContext->pBundledContext->levelSaved * 100;
16920ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    } else {
16930ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        *level = pContext->pBundledContext->volume * 100;
16940ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    }
16952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
16962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end VolumeGetVolumeLevel */
16972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetMute()
17002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
17052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
17062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){
17103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetMute start(%d)", mute);
17112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->bMuteEnabled = mute;
17132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set appropriate volume level */
17152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){
17160ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->levelSaved = pContext->pBundledContext->volume;
17170ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = -96;
17182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
17190ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent        pContext->pBundledContext->volume = pContext->pBundledContext->levelSaved;
17202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17220ee916f1f69c2d69e02a8de1e5cd5a2e9d0a0782Eric Laurent    EqualizerLimitBandLevels(pContext);
17232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
17252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setMute */
17262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1728163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetMute()
17292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
17342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Ourputs:
17362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
17372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){
17403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetMute start");
1741163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||
1742163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){
1743163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        *mute = pContext->pBundledContext->bMuteEnabled;
1744163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
17452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
17463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d",
1747163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent              pContext->pBundledContext->bMuteEnabled);
1748163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
17492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetMute end");
17512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getMute */
17522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1753163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint16_t VolumeConvertStereoPosition(int16_t position){
1754163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t convertedPosition = 0;
1755163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    convertedPosition = (int16_t)(((float)position/1000)*96);
1757163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return convertedPosition;
1758163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1759163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
1760163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1761163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1762163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeSetStereoPosition()
1763163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1764163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1765163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1766163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1767163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1768163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1769163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1770163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1771163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1772163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1773163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint VolumeSetStereoPosition(EffectContext *pContext, int16_t position){
1774163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1775163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1776163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1777163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               Balance = 0;
1778163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1779c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1780163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1781163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->positionSaved = position;
1782163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1783163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
17843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1785d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1786163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1787163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1788163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
17893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance);
1790163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved = position;
1791163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1792163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1793163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1794163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
17953856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:"
1796163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     " %d\n", ActiveParams.VC_Balance);
1797163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1798163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Volume parameters */
1799163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  = Balance;
18003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB)   -> %d\n", ActiveParams.VC_Balance );
1801163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1802163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Activate the initial settings */
1803163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1804163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
1805163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1806163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
18073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n");
18082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1809163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1810163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1811163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1812163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
18133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: "
1814163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     "%d\n", ActiveParams.VC_Balance);
1815163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1816163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    else{
18173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n",
1818163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //position, Balance);
1819163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
18203856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n",
1821d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1822163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1823163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeSetStereoPosition */
18242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1826163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1827163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetStereoPosition()
1828163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1829163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1830163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1831163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1832163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1833163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1834163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1835163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1836163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
18372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1838163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){
18393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition start");
18402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1841163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1842163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1843163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               balance;
1844163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
18453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d",
1846d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1847163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1848163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1849163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
1850163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1851163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
18523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance);
18533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1854163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1855163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1856163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1857163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1858163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(balance != ActiveParams.VC_Balance){
1859163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
1860163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1861163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1862163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *position = (LVM_INT16)pContext->pBundledContext->positionSaved;     // Convert dB to millibels
18633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved =%d\n",
1864d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //pContext->pBundledContext->positionSaved);
1865163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1866163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeGetStereoPosition */
18672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1868163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1869163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeEnableStereoPosition()
1870163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1871163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1872163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1873163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1874163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:   effect engine context
1875163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  mute:       enable/disable flag
1876163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1877163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
18782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1879163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){
18803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition start()");
18812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1882163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->bStereoPositionEnabled = enabled;
18832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1884163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1885163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
18862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1887163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1888163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1889163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition")
1890163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
18912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n");
18933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition to %d, position was %d\n",
1894163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //     enabled, ActiveParams.VC_Balance );
18952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1896163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Set appropriate stereo position */
1897163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){
1898163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance = 0;
1899163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1900163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  =
1901163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                            VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1902163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
19032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1904163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
1905163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1906163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition")
1907163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
19082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n");
19103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolumeEnableStereoPosition end()\n");
1911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1912163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeEnableStereoPosition */
19132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_getParameter()
19162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a BassBoost parameter
19192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
19212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
19222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
19232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
19242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
19252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
19272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
19282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
19292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
19322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_getParameter(EffectContext     *pContext,
1936c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
1937377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                           uint32_t          *pValueSize,
1938163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           void              *pValue){
19392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
1940c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1941c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
19422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
19432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
19442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_getParameter start");
19462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
194823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
19497fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
19503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize1 %d", *pValueSize);
19517fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
19527fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
19537fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
19547fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
19552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
19562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
19573856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize2 %d", *pValueSize);
19582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
19592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
19602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
19612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
19643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
19652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
19662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
196923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
19702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
19712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d",
1973163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
19742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
19772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = BassGetStrength(pContext);
19782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d",
1980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
19812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
19843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
19852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
19862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_getParameter end");
19902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
19912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_getParameter */
19922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_setParameter()
19952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
19962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
19972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a BassBoost parameter
19982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
19992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
20002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
20012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
20022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
20032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
20052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2008c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint BassBoost_setParameter (EffectContext *pContext, void *pParam, void *pValue){
20092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
20102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
2011c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
20122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_setParameter start");
20142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2015c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (*pParamTemp){
20162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
20172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
20183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength);
20193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength");
20202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            BassSetStrength(pContext, (int32_t)strength);
20213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength");
20222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
20232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
20243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParamTemp);
20252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tBassBoost_setParameter end");
20292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
20302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_setParameter */
20312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_getParameter()
20342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
20362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Virtualizer parameter
20372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
20392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
20402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
20412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
20422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
20432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
20452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
20462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
20472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
20502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_getParameter(EffectContext        *pContext,
2054c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void                 *pParam,
2055377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                             uint32_t             *pValueSize,
20562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             void                 *pValue){
20572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
2058c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2059c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
20602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
20612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_getParameter start");
20632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
206523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
20667fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
20673856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
20687fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
20697fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
20707fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
20717fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
20722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
20732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
20743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize2 %d",*pValueSize);
20752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
20762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
20772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
20782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2079333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES:
2080333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            // return value size can only be interpreted as relative to input value,
2081333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            // deferring validity check to below
2082333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            break;
2083333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
2084333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            if (*pValueSize != sizeof(uint32_t)){
2085333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
2086333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                return -EINVAL;
2087333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            }
2088333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            *pValueSize = sizeof(uint32_t);
2089333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            break;
20902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
20913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
20922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
20932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
209623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
20972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
20982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d",
2100163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
21012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
21042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = VirtualizerGetStrength(pContext);
21052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d",
2107163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
21082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2110333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        case VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES: {
2111333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            const audio_channel_mask_t channelMask = (audio_channel_mask_t) *pParamTemp++;
2112333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            const audio_devices_t deviceType = (audio_devices_t) *pParamTemp;
2113333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            uint32_t nbChannels = audio_channel_count_from_out_mask(channelMask);
2114333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            if (*pValueSize < 3 * nbChannels * sizeof(int32_t)){
2115333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
2116333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                return -EINVAL;
2117333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            }
2118333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            // verify the configuration is supported
2119333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            status = VirtualizerIsConfigurationSupported(channelMask, deviceType);
2120333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            if (status == 0) {
2121333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                ALOGV("VIRTUALIZER_PARAM_VIRTUAL_SPEAKER_ANGLES supports mask=0x%x device=0x%x",
2122333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        channelMask, deviceType);
2123333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                // configuration is supported, get the angles
2124333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                VirtualizerGetSpeakerAngles(channelMask, deviceType, (int32_t *)pValue);
2125333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            }
2126333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            }
2127333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            break;
2128333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
2129333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        case VIRTUALIZER_PARAM_VIRTUALIZATION_MODE:
2130333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            *(uint32_t *)pValue  = (uint32_t) VirtualizerGetVirtualizationMode(pContext);
2131333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            break;
2132333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
21332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
21343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
21352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2139333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi    ALOGV("\tVirtualizer_getParameter end returning status=%d", status);
21402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_getParameter */
21422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_setParameter()
21452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Virtualizer parameter
21482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
21512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
21522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
21532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2158c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Virtualizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
21592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
2161c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2162c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
21632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_setParameter start");
21652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2166c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
21672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
21682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
21693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength);
21703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength");
21712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            VirtualizerSetStrength(pContext, (int32_t)strength);
21723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength");
21732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
2174333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
2175333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi        case VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE: {
2176333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            const audio_devices_t deviceType = *(audio_devices_t *) pValue;
2177333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            status = VirtualizerForceVirtualizationMode(pContext, deviceType);
2178333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            //ALOGV("VIRTUALIZER_PARAM_FORCE_VIRTUALIZATION_MODE device=0x%x result=%d",
2179333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            //        deviceType, status);
2180333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            }
2181333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            break;
2182333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
21832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
21843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", param);
21852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVirtualizer_setParameter end");
21892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_setParameter */
21912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_getParameter()
21942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Equalizer parameter
21972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer       - handle to instance data
22002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
22012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
22022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
22032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
22052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
22062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
22072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
22102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
22112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
22122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_getParameter(EffectContext     *pContext,
2213c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                           void              *pParam,
2214377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                           uint32_t          *pValueSize,
22152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           void              *pValue){
22162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
22172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2218c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2219c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
22202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
22212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
22222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_getParameter start");
22242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
22262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
22272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
22282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
22293be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_BAND_LEVEL:
22303be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_GET_BAND:
22312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int16_t)) {
22323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
22332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
22352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int16_t);
22362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
22393be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (*pValueSize < 2 * sizeof(int16_t)) {
22403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
22413be9523784cc4038f601e510faee595117cdacb3Eric Laurent            return -EINVAL;
22423be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
22433be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *pValueSize = 2 * sizeof(int16_t);
22443be9523784cc4038f601e510faee595117cdacb3Eric Laurent        break;
22452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
22462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < 2 * sizeof(int32_t)) {
22473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 3  %d", *pValueSize);
22482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
22502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = 2 * sizeof(int32_t);
22512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22523be9523784cc4038f601e510faee595117cdacb3Eric Laurent
22532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
22542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int32_t)) {
22553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 5  %d", *pValueSize);
22562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
22572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
22582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int32_t);
22592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
22622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
226423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES:
226523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) {
22663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
226723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            return -EINVAL;
226823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
226923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t);
227023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        break;
227123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
22722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
22733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param);
22742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
22752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
22782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
22793be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS;
22803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue);
22812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
22843be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = -1500;
22853be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *((int16_t *)pValue + 1) = 1500;
22863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d",
2287d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      *(int16_t *)pValue, *((int16_t *)pValue + 1));
22882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
22892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2291c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
22922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
22932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
22942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
22963be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2);
22973856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d",
2298163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
22992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
23002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
2302c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
23032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
23042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
23052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
23072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2);
23083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d",
2309163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
23102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
23112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
2313c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
23142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
23152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
23162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
23182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1));
23193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d",
2320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue, *((int32_t *)pValue + 1));
23212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
23222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_BAND:
2324c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
23253be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2);
23263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d",
2327d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        //      param2, *(uint16_t *)pValue);
23282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
23292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
23313be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext);
23323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue);
23332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
23342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
23363be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets();
23373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue);
23382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
23392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
2341c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        param2 = *pParamTemp;
23422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= EqualizerGetNumPresets()) {
23432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        //if (param2 >= 20) {     // AGO FIX
23442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
23452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
23462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
23472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name = (char *)pValue;
23482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1);
23492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name[*pValueSize - 1] = 0;
23502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = strlen(name) + 1;
23513856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d",
2352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, gEqualizerPresets[param2].name, *pValueSize);
23532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
23542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
235523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES: {
23563be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
23573856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES");
23583be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[0] = (int16_t)EqualizerGetPreset(pContext);
23593be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[1] = (int16_t)FIVEBAND_NUMBANDS;
236023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
23613be9523784cc4038f601e510faee595117cdacb3Eric Laurent            p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i);
236223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
236323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    } break;
236423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
23652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
23663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param);
23672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        status = -EINVAL;
23682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
23692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2371d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    //GV("\tEqualizer_getParameter end\n");
23722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_getParameter */
23742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_setParameter()
23772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
23782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
23792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Equalizer parameter
23802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
23822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer    - handle to instance data
23832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
23842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
23852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
23872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
23882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
2389c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Equalizer_setParameter (EffectContext *pContext, void *pParam, void *pValue){
23902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
23912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t preset;
23922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t band;
23932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t level;
2394c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2395c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
2396c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
23972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_setParameter start");
23992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
24002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
24013be9523784cc4038f601e510faee595117cdacb3Eric Laurent        preset = (int32_t)(*(uint16_t *)pValue);
24022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset);
24042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if ((preset >= EqualizerGetNumPresets())||(preset < 0)) {
24052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
24062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
24072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
24082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetPreset(pContext, preset);
24092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
24102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
2411c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        band =  *pParamTemp;
24123be9523784cc4038f601e510faee595117cdacb3Eric Laurent        level = (int32_t)(*(int16_t *)pValue);
24133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level);
24142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (band >= FIVEBAND_NUMBANDS) {
24152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
24162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
24172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
24182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetBandLevel(pContext, band, level);
24192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
24203be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_PROPERTIES: {
24213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES");
24223be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
24233be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if ((int)p[0] >= EqualizerGetNumPresets()) {
24243be9523784cc4038f601e510faee595117cdacb3Eric Laurent            status = -EINVAL;
24253be9523784cc4038f601e510faee595117cdacb3Eric Laurent            break;
24263be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
24273be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (p[0] >= 0) {
24283be9523784cc4038f601e510faee595117cdacb3Eric Laurent            EqualizerSetPreset(pContext, (int)p[0]);
24293be9523784cc4038f601e510faee595117cdacb3Eric Laurent        } else {
24303be9523784cc4038f601e510faee595117cdacb3Eric Laurent            if ((int)p[1] != FIVEBAND_NUMBANDS) {
24313be9523784cc4038f601e510faee595117cdacb3Eric Laurent                status = -EINVAL;
24323be9523784cc4038f601e510faee595117cdacb3Eric Laurent                break;
24333be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
24343be9523784cc4038f601e510faee595117cdacb3Eric Laurent            for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
24353be9523784cc4038f601e510faee595117cdacb3Eric Laurent                EqualizerSetBandLevel(pContext, i, (int)p[2 + i]);
24363be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
24373be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
24383be9523784cc4038f601e510faee595117cdacb3Eric Laurent    } break;
24392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
24403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Equalizer_setParameter() invalid param %d", param);
24413be9523784cc4038f601e510faee595117cdacb3Eric Laurent        status = -EINVAL;
24422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
24432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
24442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEqualizer_setParameter end");
24462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
24472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_setParameter */
24482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
24502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_getParameter()
24512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
24522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
24532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Volume parameter
24542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
24552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
24562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume          - handle to instance data
24572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
24582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
24592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
24602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
24612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
24622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
24632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
24642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
24652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
24662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
24672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
24682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
24692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_getParameter(EffectContext     *pContext,
2471c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void              *pParam,
2472377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                        uint32_t          *pValueSize,
24732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        void              *pValue){
24742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
24752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
2476c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2477c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;;
24782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
24792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_getParameter start");
24812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
24832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
24842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
24852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2486163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if (*pValueSize != sizeof(int16_t)){
24873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1  %d", *pValueSize);
24882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
24892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
24902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
24912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
24922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
24942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
24952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize < sizeof(int32_t)){
24963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2  %d", *pValueSize);
24972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
24982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
24992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int32_t);
25002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
25033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param);
25042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
25052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
25062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
25082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
25092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue));
25103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d",
2511d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
25122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
25152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = 0;
25163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d",
2517d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
25182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2521163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            VolumeGetStereoPosition(pContext, (int16_t *)pValue);
25223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d",
2523d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(int16_t *)pValue);
25242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2527163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeGetMute(pContext, (uint32_t *)pValue);
25283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d",
2529163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(uint32_t *)pValue);
25302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2533163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled;
25343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d",
2535d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent            //        *(uint32_t *)pValue);
25362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
25393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param);
25402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
25412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
25432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_getParameter end");
25452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
25462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_getParameter */
25472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
25502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_setParameter()
25512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
25522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
25532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Volume parameter
25542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
25552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
25562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume       - handle to instance data
25572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
25582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
25592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
25602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
25612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
25622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
25632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2564c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Volume_setParameter (EffectContext *pContext, void *pParam, void *pValue){
25652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int      status = 0;
25662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t  level;
2567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t  position;
25682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    uint32_t mute;
2569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    uint32_t positionEnabled;
2570c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
2571c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
25722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_setParameter start");
25742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2575c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
25762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
25772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            level = *(int16_t *)pValue;
25783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level);
25793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel");
25802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeSetVolumeLevel(pContext, (int16_t)level);
25813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel");
25822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
25832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            mute = *(uint32_t *)pValue;
25863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute);
25873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->setMute");
2588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetMute(pContext, mute);
25893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->setMute");
2590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
25912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            positionEnabled = *(uint32_t *)pValue;
2594163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeEnableStereoPosition(pContext, positionEnabled);
2595163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved);
25963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called");
2597163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
25982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            position = *(int16_t *)pValue;
26013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position);
26023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition");
2603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, (int16_t)position);
26043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition");
2605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
26062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
26083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", param);
26092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
26102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
26112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tVolume_setParameter end");
26132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
26142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_setParameter */
26152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent/****************************************************************************************
2617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent * Name : LVC_ToDB_s32Tos16()
2618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Input       : Signed 32-bit integer
2619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Output      : Signed 16-bit integer
2620163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  MSB (16) = sign bit
2621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (15->05) = integer part
2622163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (04->01) = decimal part
2623163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Returns     : Db value with respect to full scale
2624163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Description :
2625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Remarks     :
2626163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent ****************************************************************************************/
2627163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2628163fbcf84010b98e0374110454d85b804bc8d13bEric LaurentLVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix)
2629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent{
2630163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   db_fix;
2631163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   Shift;
2632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   SmallRemainder;
2633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_UINT32  Remainder = (LVM_UINT32)Lin_fix;
2634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Count leading bits, 1 cycle in assembly*/
2636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for (Shift = 0; Shift<32; Shift++)
2637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
2638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if ((Remainder & 0x80000000U)!=0)
2639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2640163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        Remainder = Remainder << 1;
2643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
26442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2645163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /*
2646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * Based on the approximation equation (for Q11.4 format):
2647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     *
2648163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2)
2649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     */
2650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix    = (LVM_INT16)(-96 * Shift);               /* Six dB steps in Q11.4 format*/
2651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24);
2652163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix + SmallRemainder );
2653163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder);
2654163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9));
26552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Correct for small offset */
2657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - 5);
26582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return db_fix;
2660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
26612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
266229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
266329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Effect_setEnabled()
266429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
266529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Purpose:
266629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Enable or disable effect
266729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
266829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Inputs:
266929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//  pContext      - pointer to effect context
267029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//  enabled       - true if enabling the effect, false otherwise
267129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
267229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent// Outputs:
267329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//
267429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent//----------------------------------------------------------------------------
267529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
267629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurentint Effect_setEnabled(EffectContext *pContext, bool enabled)
267729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent{
26783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffect_setEnabled() type %d, enabled %d", pContext->EffectType, enabled);
267929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
268029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    if (enabled) {
2681b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        // Bass boost or Virtualizer can be temporarily disabled if playing over device speaker due
2682b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        // to their nature.
2683b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        bool tempDisabled = false;
268429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        switch (pContext->EffectType) {
268529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_BASS_BOOST:
268629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
26873856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                     ALOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already enabled");
268829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     return -EINVAL;
268929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2690dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountBb <= 0){
2691dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2692dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
269329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountBb =
269429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
269529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bBassEnabled = LVM_TRUE;
2696b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                tempDisabled = pContext->pBundledContext->bBassTempDisabled;
269729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
269829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_EQUALIZER:
269929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE) {
27003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_EQUALIZER is already enabled");
270129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
270229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2703dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountEq <= 0){
2704dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2705dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
270629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountEq =
270729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
270829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE;
270929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
271029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VIRTUALIZER:
271129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) {
27123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already enabled");
271329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
271429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2715dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                if(pContext->pBundledContext->SamplesToExitCountVirt <= 0){
2716dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                    pContext->pBundledContext->NumberEffectsEnabled++;
2717dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                }
271829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->SamplesToExitCountVirt =
271929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                     (LVM_INT32)(pContext->pBundledContext->SamplesPerSecond*0.1);
272029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE;
2721b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                tempDisabled = pContext->pBundledContext->bVirtualizerTempDisabled;
272229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
272329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VOLUME:
272429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVolumeEnabled == LVM_TRUE) {
27253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VOLUME is already enabled");
272629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
272729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
2728dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                pContext->pBundledContext->NumberEffectsEnabled++;
272929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVolumeEnabled = LVM_TRUE;
273029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
273129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            default:
27323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffect_setEnabled() invalid effect type");
273329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                return -EINVAL;
273429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        }
2735b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        if (!tempDisabled) {
2736b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            LvmEffect_enable(pContext);
2737b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent        }
273829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    } else {
273929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        switch (pContext->EffectType) {
274029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_BASS_BOOST:
274129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bBassEnabled == LVM_FALSE) {
27423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_BASS_BOOST is already disabled");
274329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
274429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
274529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bBassEnabled = LVM_FALSE;
274629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
274729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_EQUALIZER:
274829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE) {
27493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_EQUALIZER is already disabled");
275029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
275129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
275229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE;
275329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
275429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VIRTUALIZER:
275529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE) {
27563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VIRTUALIZER is already disabled");
275729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
275829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
275929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE;
276029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
276129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            case LVM_VOLUME:
276229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                if (pContext->pBundledContext->bVolumeEnabled == LVM_FALSE) {
27633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEffect_setEnabled() LVM_VOLUME is already disabled");
276429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                    return -EINVAL;
276529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                }
276629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                pContext->pBundledContext->bVolumeEnabled = LVM_FALSE;
276729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                break;
276829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            default:
27693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tEffect_setEnabled() invalid effect type");
277029cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent                return -EINVAL;
277129cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        }
277229cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent        LvmEffect_disable(pContext);
277329cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    }
277429cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
277529cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent    return 0;
277629cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent}
277729cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
2778dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//----------------------------------------------------------------------------
2779dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// LVC_Convert_VolToDb()
2780dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//----------------------------------------------------------------------------
2781dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Purpose:
2782dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Convery volume in Q24 to dB
2783dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//
2784dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent// Inputs:
2785dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//  vol:   Q.24 volume dB
2786dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//
2787dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//-----------------------------------------------------------------------
2788dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2789dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurentint16_t LVC_Convert_VolToDb(uint32_t vol){
2790dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    int16_t  dB;
2791dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2792dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = LVC_ToDB_s32Tos16(vol <<7);
2793dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = (dB +8)>>4;
2794dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    dB = (dB <-96) ? -96 : dB ;
2795dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2796dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    return dB;
2797dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent}
2798dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2799163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
2800163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
28012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2802e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentextern "C" {
28032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Process */
2804e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_process(effect_handle_t     self,
2805163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *inBuffer,
2806163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *outBuffer){
28072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
2808c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
28092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int    status = 0;
2810163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int    lvmStatus = 0;
2811163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *in  = (LVM_INT16 *)inBuffer->raw;
2812163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *out = (LVM_INT16 *)outBuffer->raw;
28132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block//ALOGV("\tEffect_process Start : Enabled = %d     Called = %d (%8d %8d %8d)",
2815dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent//pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled,
2816c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountBb,
2817c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountVirt,
2818c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//    pContext->pBundledContext->SamplesToExitCountEq);
2819c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
28202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
28213856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL");
28222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
28232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2824dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
2825dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //if(pContext->EffectType == LVM_BASS_BOOST){
28263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is BASS_BOOST");
2827dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}else if(pContext->EffectType == LVM_EQUALIZER){
28283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is LVM_EQUALIZER");
2829dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}else if(pContext->EffectType == LVM_VIRTUALIZER){
28303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //  ALOGV("\tEffect_process: Effect type is LVM_VIRTUALIZER");
2831dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    //}
2832dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
28332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
28342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
28352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            inBuffer->frameCount != outBuffer->frameCount){
28363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
28372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
28382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2839163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&
2840163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_BASS_BOOST)){
28413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_BASS_BOOST Effect is not enabled");
2842c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb > 0){
2843c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountBb -= outBuffer->frameCount * 2; // STEREO
28443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting to turn off BASS_BOOST, %d samples left",
2845c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountBb);
2846d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2847d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountBb <= 0) {
284829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            status = -ENODATA;
2849dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
28503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_BASS_BOOST");
2851c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
2852163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2853163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&
2854163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VOLUME)){
28553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_VOLUME Effect is not enabled");
2856163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2857dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent        pContext->pBundledContext->NumberEffectsEnabled--;
2858163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2859163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&
2860163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_EQUALIZER)){
28613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_EQUALIZER Effect is not enabled");
2862c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq > 0){
2863c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountEq -= outBuffer->frameCount * 2; // STEREO
28643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting to turn off EQUALIZER, %d samples left",
2865c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountEq);
2866d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2867d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountEq <= 0) {
2868c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2869dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
28703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_EQUALIZER");
2871c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
28722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2873163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&
2874163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VIRTUALIZER)){
28753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process() LVM_VIRTUALIZER Effect is not enabled");
2876c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt > 0){
2877c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->pBundledContext->SamplesToExitCountVirt -= outBuffer->frameCount * 2;// STEREO
28783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_process: Waiting for to turn off VIRTUALIZER, %d samples left",
2879c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //    pContext->pBundledContext->SamplesToExitCountVirt);
2880d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        }
2881d71a0e1ac517cf312b9a96fe5ba9de04f2b9ffd4Eric Laurent        if(pContext->pBundledContext->SamplesToExitCountVirt <= 0) {
2882c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -ENODATA;
2883dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
28843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() this is the last frame for LVM_VIRTUALIZER");
2885c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
28862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2887163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2888dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent    if(status != -ENODATA){
2889163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled++;
28902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
28912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2892163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->NumberEffectsCalled ==
2893163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       pContext->pBundledContext->NumberEffectsEnabled){
28943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process     Calling process with %d effects enabled, %d called: Effect %d",
2895163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2896163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
28972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2898163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(status == -ENODATA){
28993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_process() processing last frame");
2900163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
29012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext->NumberEffectsCalled = 0;
2902163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Process all the available frames, block processing is
2903163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           handled internalLY by the LVM bundle */
2904163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        lvmStatus = android::LvmBundle_process(    (LVM_INT16 *)inBuffer->raw,
29052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                (LVM_INT16 *)outBuffer->raw,
29062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                outBuffer->frameCount,
29072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                pContext);
2908163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(lvmStatus != LVM_SUCCESS){
29093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
2910163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return lvmStatus;
2911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
29125dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent    } else {
29133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
2914163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2915163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
2916163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        // 2 is for stereo input
29175dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
29185dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            for (size_t i=0; i < outBuffer->frameCount*2; i++){
29195dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent                outBuffer->s16[i] =
29205dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent                        clamp16((LVM_INT32)outBuffer->s16[i] + (LVM_INT32)inBuffer->s16[i]);
29215dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            }
292297bb6e89845cb6d85f4d34a4efcc1de2ce585336Marco Nelissen        } else if (outBuffer->raw != inBuffer->raw) {
29235dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent            memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
29245dc65e2ce92c7364da60bdff5f345daf145c2c0fEric Laurent        }
29252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2926163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
29272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
29282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end Effect_process */
29292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Command */
2931e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_command(effect_handle_t  self,
293225f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdCode,
293325f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdSize,
2934163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pCmdData,
293525f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            *replySize,
2936163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pReplyData){
29372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
29382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int retsize;
29392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\t\nEffect_command start");
29412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST){
29433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_BASS_BOOST");
29442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
29452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER){
29463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_VIRTUALIZER");
2947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
29482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER){
29493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_EQUALIZER");
2950163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
29512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME){
29523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tEffect_command setting command for LVM_VOLUME");
2953163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
29542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
29563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL");
29572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
29582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
29592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
29612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2962163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // Incase we disable an effect, next time process is
2963163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // called the number of effect called could be greater
2964163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // pContext->pBundledContext->NumberEffectsCalled = 0;
29652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d",
2967163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsCalled,
2968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsEnabled);
29692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (cmdCode){
29712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_INIT:
2972010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
29733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d",
2974010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                        pContext->EffectType);
2975010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                return -EINVAL;
2976010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            }
2977010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            *(int *) pReplyData = 0;
29783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start");
29792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
29803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST");
29812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                android::BassSetStrength(pContext, 0);
29822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
29832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
29843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER");
2985163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::VirtualizerSetStrength(pContext, 0);
2986163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
29883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER");
2989163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::EqualizerSetPreset(pContext, 0);
2990163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
29923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VOLUME");
2993010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0);
2994163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2996163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
29973d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        case EFFECT_CMD_SET_CONFIG:
29983d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_CONFIG start");
29992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pCmdData    == NULL||
30002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                cmdSize     != sizeof(effect_config_t)||
30012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                pReplyData  == NULL||
30022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize  != sizeof(int)){
30033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
30043d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                        "EFFECT_CMD_SET_CONFIG: ERROR");
30053d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                return -EINVAL;
30063d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            }
30073d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            *(int *) pReplyData = android::Effect_setConfig(pContext, (effect_config_t *) pCmdData);
30083d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_CONFIG end");
30093d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            break;
30103d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
30113d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        case EFFECT_CMD_GET_CONFIG:
30123d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            if (pReplyData == NULL ||
30133d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                *replySize != sizeof(effect_config_t)) {
30143d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
30153d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                        "EFFECT_CMD_GET_CONFIG: ERROR");
30162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
30172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
30183d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
30193d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            android::Effect_getConfig(pContext, (effect_config_t *)pReplyData);
30202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
30212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_RESET:
30233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start");
30243d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            android::Effect_setConfig(pContext, &pContext->config);
30253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end");
30262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
30272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_GET_PARAM:{
30293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
3030163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
30312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
3032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
3033b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                        cmdSize < (sizeof(effect_param_t) + sizeof(int32_t)) ||
3034163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
3035b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                        *replySize < (sizeof(effect_param_t) + sizeof(int32_t))){
30363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
30372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
30382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
30392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
30402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
30412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
30432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
30452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
30472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::BassBoost_getParameter(pContext,
3049c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
3050377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                                                            &p->vsize,
30512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            p->data + voffset);
30522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
30542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM "
3056163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
3057163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3058163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
3059163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
30602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
3061163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
30622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
3063163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
3064b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                        cmdSize < (sizeof(effect_param_t) + sizeof(int32_t)) ||
3065163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
3066b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                        *replySize < (sizeof(effect_param_t) + sizeof(int32_t))){
30673856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
30682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
30692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
30702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
30712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
30722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
30742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
30762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
30782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Virtualizer_getParameter(pContext,
3080377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                                                              (void *)p->data,
3081377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                                                              &p->vsize,
30822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                              p->data + voffset);
30832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
30842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
30853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM "
3086163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
3087163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3088163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
3089163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
30902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
30912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
30923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEqualizer_command cmdCode Case: "
3093163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
3094163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
3095b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                    cmdSize < (sizeof(effect_param_t) + sizeof(int32_t)) ||
3096163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL ||
3097163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) {
30983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
30992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM");
31002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
31012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
31022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
3103163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
31042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
3105163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
31062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
3107163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
31082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
3109163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3110c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                p->status = android::Equalizer_getParameter(pContext,
3111c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data,
3112c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            &p->vsize,
3113c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                            p->data + voffset);
3114163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
31152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
3116163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
31173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, "
3118163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //       "*pReplyData %08x %08x",
3119163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize,
3120163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset),
3121163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset +
3122163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        sizeof(int32_t)));
31232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
31242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
31253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
3126163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
3127b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                        cmdSize < (sizeof(effect_param_t) + sizeof(int32_t)) ||
3128163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
3129163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
31303856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
31312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
31322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
31332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
31342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
31352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
31372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
31392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
31412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Volume_getParameter(pContext,
3143c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                         (void *)p->data,
3144377b2ec9a2885f9b6405b07ba900a9e3f4349c38Kévin PETIT                                                         &p->vsize,
31452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         p->data + voffset);
31462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
31482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command EFFECT_CMD_GET_PARAM "
3150163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
3151163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3152163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
3153163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
3154163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
31553856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end");
31562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
31572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_PARAM:{
31583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
31592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
31603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
3161dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3162dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *replySize,
3163dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                //       *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
3164163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3165163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
3166b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                    cmdSize    != (sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
3167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
3168163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
31693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
31702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
31712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
31722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
31732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
31742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
31763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
31772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
31782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
31792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
31802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tnBassBoost_command cmdSize is %d\n"
3182163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
3183163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
3184163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
3185163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
3186163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
31872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
31882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::BassBoost_setParameter(pContext,
3189c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
31902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    p->data + p->psize);
31912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
31922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
3193333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi              // Warning this log will fail to properly read an int32_t value, assumes int16_t
31943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block              //ALOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
3195d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3196d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *replySize,
3197d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent              //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
3198163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3199333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                if (pCmdData   == NULL ||
3200333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                    // legal parameters are int16_t or int32_t
3201333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                    cmdSize    > (sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int32_t)) ||
3202333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                    cmdSize    < (sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t)) ||
3203333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                    pReplyData == NULL ||
3204163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
32053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
32062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
32072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
32082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
32092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
32102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
32123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
32132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
32142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
32152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
32162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tnVirtualizer_command cmdSize is %d\n"
3218163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
3219163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
3220163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
3221163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
3222163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
32232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Virtualizer_setParameter(pContext,
3225c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                      (void *)p->data,
3226163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                       p->data + p->psize);
32272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
32282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
32293856b090cd04ba5dd4a59a12430ed724d5995909Steve Block               //ALOGV("\tEqualizer_command cmdCode Case: "
3230d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        "EFFECT_CMD_SET_PARAM start");
32313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block               //ALOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
3232d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3233d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *replySize,
3234d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent               //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
32352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3236b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                if (pCmdData == NULL || cmdSize < (sizeof(effect_param_t) + sizeof(int32_t)) ||
32372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pReplyData == NULL || *replySize != sizeof(int32_t)) {
32383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
32392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
32402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
32412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
32422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
32432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Equalizer_setParameter(pContext,
3245c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                    (void *)p->data,
3246163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                     p->data + p->psize);
32472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
32482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
32493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
32503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                //ALOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
3251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
3252163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
3253d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) +sizeof(int32_t)));
32542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (    pCmdData   == NULL||
3256b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                        cmdSize    < (sizeof(effect_param_t) + sizeof(int32_t))||
32572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        pReplyData == NULL||
32582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        *replySize != sizeof(int32_t)){
32593856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
32602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
32612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
32622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
32632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
32642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Volume_setParameter(pContext,
3266c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                                 (void *)p->data,
3267163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                 p->data + p->psize);
3268163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
32693856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end");
32702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
32712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_ENABLE:
32733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start");
32742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
32753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
32762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
3277163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
327829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent
327929cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_TRUE);
32802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
32822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_DISABLE:
32833856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start");
32842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
32853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
32862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
3287163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
328829cc743e57f2a1701a0a0d3a0e5406ed0f2e8a89Eric Laurent            *(int *)pReplyData = android::Effect_setEnabled(pContext, LVM_FALSE);
32892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
32902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
32912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_DEVICE:
3292163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
32933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start");
3294e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            uint32_t device = *(uint32_t *)pCmdData;
3295333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi            pContext->pBundledContext->nOutputDevice = (audio_devices_t) device;
3296163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3297b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            if (pContext->EffectType == LVM_BASS_BOOST) {
3298b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                if((device == AUDIO_DEVICE_OUT_SPEAKER) ||
3299b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) ||
3300b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                        (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
33013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d",
3302163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
33033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST");
3304163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3305163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device doesnt support bassboost the effect must be temporarily disabled
3306163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
3307163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
3308163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3309b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
33103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d",
3311163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3312163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
3313163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3314b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bBassTempDisabled = LVM_TRUE;
3315b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                } else {
33163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                    ALOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d",
3317163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                         *(int32_t *)pCmdData);
3318163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3319163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports bassboost and the effect has been temporarily disabled
3320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
3321163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3322b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    if (pContext->pBundledContext->bBassEnabled == LVM_TRUE) {
33233856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                        ALOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d",
3324163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
3325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
3326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3327b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent                    pContext->pBundledContext->bBassTempDisabled = LVM_FALSE;
3328163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
3329163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3330b6431802fc6cff501a4311de288ba469839fbf86Eric Laurent            if (pContext->EffectType == LVM_VIRTUALIZER) {
3331333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                if (pContext->pBundledContext->nVirtualizerForcedDevice == AUDIO_DEVICE_NONE) {
3332333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                    // default case unless configuration is forced
3333333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                    if (android::VirtualizerIsDeviceSupported(device) != 0) {
3334333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        ALOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d",
3335333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                                *(int32_t *)pCmdData);
3336333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        ALOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER");
3337333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
3338333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        //If a device doesnt support virtualizer the effect must be temporarily
3339333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        // disabled the effect must still report its original state as this can
3340333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        // only be changed by the ENABLE/DISABLE command
3341333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
3342333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        if (pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE) {
3343333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                            ALOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d",
3344333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                                    *(int32_t *)pCmdData);
3345333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                            android::LvmEffect_disable(pContext);
3346333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        }
3347333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
3348333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                    } else {
3349333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        ALOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d",
3350333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                                *(int32_t *)pCmdData);
3351333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
3352333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        // If a device supports virtualizer and the effect has been temporarily
3353333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        // disabled previously then re-enable it
3354333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi
3355333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
3356333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                            ALOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d",
3357333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                                    *(int32_t *)pCmdData);
3358333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                            android::LvmEffect_enable(pContext);
3359333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        }
3360333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
3361163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
3362333f66d4642ddd36b42668da2767551ba25f0248Jean-Michel Trivi                } // else virtualization mode is forced to a certain device, nothing to do
3363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
33643856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end");
33652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
3366163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
3367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_VOLUME:
3368163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
3369dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            uint32_t leftVolume, rightVolume;
3370dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int16_t  leftdB, rightdB;
3371dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int16_t  maxdB, pandB;
3372dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int32_t  vol_ret[2] = {1<<24,1<<24}; // Apply no volume
3373dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            int      status = 0;
3374dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ControlParams_t     ActiveParams;           /* Current control Parameters */
3375dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;  /* Function call status */
3376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // if pReplyData is NULL, VOL_CTRL is delegated to another effect
3378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pReplyData == LVM_NULL){
3379163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                break;
3380163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
33812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3382dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if (pCmdData == NULL ||
3383dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                cmdSize != 2 * sizeof(uint32_t)) {
33843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
3385dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                        "EFFECT_CMD_SET_VOLUME: ERROR");
3386dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                return -EINVAL;
3387163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
3388163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3389dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            leftVolume  = ((*(uint32_t *)pCmdData));
3390dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            rightVolume = ((*((uint32_t *)pCmdData + 1)));
3391dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3392dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(leftVolume == 0x1000000){
3393dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                leftVolume -= 1;
3394dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3395dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(rightVolume == 0x1000000){
3396dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                rightVolume -= 1;
3397dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
3398dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3399dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            // Convert volume to dB
3400dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            leftdB  = android::LVC_Convert_VolToDb(leftVolume);
3401dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            rightdB = android::LVC_Convert_VolToDb(rightVolume);
3402dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3403dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            pandB = rightdB - leftdB;
3404dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3405dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            // Calculate max volume in dB
3406dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            maxdB = leftdB;
3407dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(rightdB > maxdB){
3408dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent                maxdB = rightdB;
3409dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            }
34103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME Session: %d, SessionID: %d VOLUME is %d dB (%d), "
3411dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //      "effect is %d",
3412dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //pContext->pBundledContext->SessionNo, pContext->pBundledContext->SessionId,
3413dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //(int32_t)maxdB, maxVol<<7, pContext->EffectType);
34143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME: Left is %d, Right is %d", leftVolume, rightVolume);
34153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_SET_VOLUME: Left %ddB, Right %ddB, Position %ddB",
3416dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            //        leftdB, rightdB, pandB);
3417d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
3418163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            memcpy(pReplyData, vol_ret, sizeof(int32_t)*2);
3419dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            android::VolumeSetVolumeLevel(pContext, (int16_t)(maxdB*100));
3420dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3421dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Get the current settings */
3422dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LvmStatus =LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
3423dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
3424dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(LvmStatus != LVM_SUCCESS) return -EINVAL;
3425dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3426dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Volume parameters */
3427dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            ActiveParams.VC_Balance  = pandB;
34283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\t\tVolumeSetStereoPosition() (-96dB -> +96dB)-> %d\n", ActiveParams.VC_Balance );
3429dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent
3430dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            /* Activate the initial settings */
3431dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LvmStatus =LVM_SetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
3432dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
3433dac69110ed1073bf0a9827a3f78698896dd05d97Eric Laurent            if(LvmStatus != LVM_SUCCESS) return -EINVAL;
3434163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
3435163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent         }
3436163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
3437163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
34382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
34392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
34402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
34412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
34423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tEffect_command end...\n\n");
34432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
34442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end Effect_command */
34452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3446e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent/* Effect Control Interface Implementation: get_descriptor */
3447e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Effect_getDescriptor(effect_handle_t   self,
3448e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                                    effect_descriptor_t *pDescriptor)
3449e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent{
3450e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    EffectContext * pContext = (EffectContext *) self;
3451e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    const effect_descriptor_t *desc;
3452e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3453e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pContext == NULL || pDescriptor == NULL) {
34543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("Effect_getDescriptor() invalid param");
3455e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return -EINVAL;
3456e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
3457e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3458e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    switch(pContext->EffectType) {
3459e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_BASS_BOOST:
3460e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gBassBoostDescriptor;
3461e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3462e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_VIRTUALIZER:
3463e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gVirtualizerDescriptor;
3464e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3465e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_EQUALIZER:
3466e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gEqualizerDescriptor;
3467e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3468e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        case LVM_VOLUME:
3469e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gVolumeDescriptor;
3470e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            break;
3471e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        default:
3472e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            return -EINVAL;
3473e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
3474e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3475a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pDescriptor = *desc;
3476e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3477e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    return 0;
3478e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent}   /* end Effect_getDescriptor */
3479e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3480e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent// effect_handle_t interface implementation for effect
34812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst struct effect_interface_s gLvmEffectInterface = {
34822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_process,
3483e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    Effect_command,
3484ba7b8f881a9b6b21803752326d2932a3bd42d7cfEric Laurent    Effect_getDescriptor,
3485ba7b8f881a9b6b21803752326d2932a3bd42d7cfEric Laurent    NULL,
34862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};    /* end gLvmEffectInterface */
34872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
34887f16b197c76fbae9399242f055a7ee16dcd0fd6dMarco Nelissen// This is the only symbol that needs to be exported
34897f16b197c76fbae9399242f055a7ee16dcd0fd6dMarco Nelissen__attribute__ ((visibility ("default")))
3490e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentaudio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
3491c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .tag = AUDIO_EFFECT_LIBRARY_TAG,
3492c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .version = EFFECT_LIBRARY_API_VERSION,
3493c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .name = "Effect Bundle Library",
3494c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .implementor = "NXP Software Ltd.",
3495c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .create_effect = android::EffectCreate,
3496c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .release_effect = android::EffectRelease,
3497c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .get_descriptor = android::EffectGetDescriptor,
3498e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent};
3499e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
3500e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent}
3501