EffectBundle.cpp revision 7fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0
12c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/*
22c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Copyright (C) 2010-2010 NXP Software
32c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Copyright (C) 2009 The Android Open Source Project
42c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
52c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
62c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * you may not use this file except in compliance with the License.
72c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * You may obtain a copy of the License at
82c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
92c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent *
112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * Unless required by applicable law or agreed to in writing, software
122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * See the License for the specific language governing permissions and
152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent * limitations under the License.
162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent */
172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LOG_TAG "Bundle"
192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
20163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent#define LOG_NDEBUG 0
212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <cutils/log.h>
232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <assert.h>
242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <stdlib.h>
252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <string.h>
262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <new>
272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#include <EffectBundle.h>
282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LVM_MAX_SESSIONS        32
302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define MAX_NUM_BANDS           5
312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define MAX_CALL_SIZE           256
322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for bass boost
342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" const struct effect_interface_s gLvmEffectInterface;
352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_NULLADDRESS){\
382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_ALIGNMENTERROR){\
422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad alignment returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_INVALIDNUMSAMPLES){\
462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (LvmStatus == LVM_OUTOFRANGE){\
502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Parameter error - "\
512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    "out of range returned by %s in %s\n", callingFunc, calledFunc);\
522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }\
532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Namespaces
562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace android {
572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentnamespace {
582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* local functions */
602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent#define CHECK_ARG(cond) {                     \
612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (!(cond)) {                            \
622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Invalid argument: "#cond);      \
632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;                       \
642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }                                         \
652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
67163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Flag to allow a one time init of global memory, only happens on first call ever
682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmInitFlag = LVM_FALSE;
692c8e5cab3faa6d360e222b7a6c40a80083d021acEric LaurentSessionContext GlobalSessionMemory[32];
702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW BassBoost UUID
722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gBassBoostDescriptor = {
732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x8631f300, 0x72e2, 0x11df, 0xb57e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
76163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
77163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        0, // TODO
792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        1,
802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Dynamic Bass Boost",
812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Virtualizer UUID
852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVirtualizerDescriptor = {
86163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x37cc2c00, 0xdddd, 0x11db, 0x8577, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
87163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {0x1d4033c0, 0x8557, 0x11df, 0x9f2d, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
89163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_DEVICE_IND
90163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        | EFFECT_FLAG_VOLUME_CTRL),
912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        0, // TODO
922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        1,
932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Virtualizer",
942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Equalizer UUID
982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gEqualizerDescriptor = {
992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
1002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0xce772f20, 0x847d, 0x11df, 0xbb17, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid Eq NXP
1012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
102163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
1032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        0, // TODO
1042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        1,
1052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Equalizer",
1062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// NXP SW Volume UUID
1102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst effect_descriptor_t gVolumeDescriptor = {
1112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x09e8ede0, 0xddde, 0x11db, 0xb4f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
1122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        {0x119341a0, 0x8469, 0x11df, 0x81f9, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }}, //uuid VOL NXP
1132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EFFECT_API_VERSION,
114163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_LAST | EFFECT_FLAG_VOLUME_CTRL),
1152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        0, // TODO
1162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        1,
1172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "Volume",
1182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        "NXP Software Ltd.",
1192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};
1202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//--- local function prototypes
1222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init      (void);
1232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmBundle_init            (EffectContext *pContext);
1242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_enable          (EffectContext *pContext);
1252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  LvmEffect_disable         (EffectContext *pContext);
1262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free            (EffectContext *pContext);
127163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  Effect_configure          (EffectContext *pContext, effect_config_t *pConfig);
1282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  BassBoost_setParameter    (EffectContext *pContext, int32_t *pParam, void *pValue);
129163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint  BassBoost_getParameter    (EffectContext *pContext,
1302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               int32_t        *pParam,
1312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
1322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               void           *pValue);
1332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Virtualizer_setParameter  (EffectContext *pContext, int32_t *pParam, void *pValue);
1342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Virtualizer_getParameter  (EffectContext *pContext,
1352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               int32_t        *pParam,
1362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                               size_t         *pValueSize,
137163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                               void           *pValue);
1382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Equalizer_setParameter    (EffectContext *pContext, int32_t *pParam, void *pValue);
1392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Equalizer_getParameter    (EffectContext *pContext,
1402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                int32_t       *pParam,
1412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
1432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Volume_setParameter       (EffectContext *pContext, int32_t *pParam, void *pValue);
1442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint  Volume_getParameter       (EffectContext *pContext,
1452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                int32_t       *pParam,
1462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                size_t        *pValueSize,
1472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                void          *pValue);
1482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Library Interface Implementation */
1502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){
1512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryNumberEffects start");
1522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pNumEffects = 4;
153163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects);
154163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectQueryNumberEffects end\n");
1552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryNumberEffects */
1572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor){
1592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectQueryEffect start");
1602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect processing index %d", index);
161163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pDescriptor == NULL){
163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer");
1642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
1652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (index > 3){
167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index);
1682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -ENOENT;
1692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(index == LVM_BASS_BOOST){
1712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_BASS_BOOST");
1722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gBassBoostDescriptor,   sizeof(effect_descriptor_t));
1732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else if(index == LVM_VIRTUALIZER){
1742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VIRTUALIZER");
1752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVirtualizerDescriptor, sizeof(effect_descriptor_t));
1762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_EQUALIZER){
1772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_EQUALIZER");
1782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gEqualizerDescriptor,   sizeof(effect_descriptor_t));
1792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(index == LVM_VOLUME){
1802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectQueryEffect processing LVM_VOLUME");
1812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        memcpy(pDescriptor, &gVolumeDescriptor, sizeof(effect_descriptor_t));
182163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectQueryEffect end\n");
1842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
1852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}     /* end EffectQueryEffect */
1862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectCreate(effect_uuid_t       *uuid,
1882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             sessionId,
1892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            int32_t             ioId,
1902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            effect_interface_t  *pInterface){
1912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int ret;
1922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int i;
1932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext *pContext = new EffectContext;
1942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectCreate start session %d", sessionId);
1962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pInterface == NULL || uuid == NULL){
198163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer");
1992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
2002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if((sessionId < 0)||(sessionId >= LVM_MAX_SESSIONS)){
2032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : EffectCreate sessionId is less than 0");
204163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
2052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmInitFlag == LVM_FALSE){
2082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmInitFlag = LVM_TRUE;
2092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Initializing all global memory");
2102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmGlobalBundle_init();
2112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // If this is the first create in this session
2142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(GlobalSessionMemory[sessionId].bBundledEffectsEnabled == LVM_FALSE){
2152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - This is the first effect in current session %d", sessionId);
2162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Setting up Bundled Effects Instance for session %d", sessionId);
217163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[sessionId].bBundledEffectsEnabled = LVM_TRUE;
2192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[sessionId].pBundledContext        = new BundledEffectContext;
2202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext = GlobalSessionMemory[sessionId].pBundledContext;
222163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->SessionNo                = sessionId;
223163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->hInstance                = NULL;
224163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVolumeEnabled           = LVM_FALSE;
225163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bEqualizerEnabled        = LVM_FALSE;
226163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassEnabled             = LVM_FALSE;
227163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bBassTempDisabled        = LVM_FALSE;
228163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerEnabled      = LVM_FALSE;
229163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
230163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsEnabled     = 0;
231163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled      = 0;
232163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->frameCount               = 0;
233163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
234163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
235163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->PcmInPtr  = NULL;
236163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->PcmOutPtr = NULL;
237163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
238163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->PcmInPtr  = fopen("/data/tmp/bundle_pcm_in.pcm", "w");
239163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->PcmOutPtr = fopen("/data/tmp/bundle_pcm_out.pcm", "w");
240163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
241163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((pContext->pBundledContext->PcmInPtr  == NULL)||
242163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           (pContext->pBundledContext->PcmOutPtr == NULL)){
243163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           return -EINVAL;
244163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
245163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
246163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        /* Saved strength is used to return the exact strength that was used in the set to the get
2482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * because we map the original strength range of 0:1000 to 1:15, and this will avoid
2492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         * quantisation like effect when returning
2502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent         */
251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->BassStrengthSaved        = 0;
252163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->VirtStrengthSaved        = 0;
253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->CurPreset                = PRESET_CUSTOM;
254163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved               = 0;
255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bMuteEnabled             = LVM_FALSE;
256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->bStereoPositionEnabled   = LVM_FALSE;
257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved            = 0;
258163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Calling LvmBundle_init");
2602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ret = LvmBundle_init(pContext);
2612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (ret < 0){
2632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : EffectCreate() Bundle init failed");
2642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            delete pContext->pBundledContext;
2652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            delete pContext;
2662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return ret;
2672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
2682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
2702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext = GlobalSessionMemory[sessionId].pBundledContext;
2712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
272163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectCreate - pBundledContext is %p", pContext->pBundledContext);
2742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Create each Effect
2762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (memcmp(uuid, &gBassBoostDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Bass Boost
2782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_BASS_BOOST");
2792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[sessionId].bBassInstantiated = LVM_TRUE;
280163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->itfe       = &gLvmEffectInterface;
2822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_BASS_BOOST;
2832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVirtualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Virtualizer
285163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VIRTUALIZER");
2862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[sessionId].bVirtualizerInstantiated = LVM_TRUE;
287163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
2892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VIRTUALIZER;
2902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Equalizer
292163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_EQUALIZER");
2932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[sessionId].bEqualizerInstantiated = LVM_TRUE;
294163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
2962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_EQUALIZER;
2972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if (memcmp(uuid, &gVolumeDescriptor.uuid, sizeof(effect_uuid_t)) == 0){
2982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        // Create Volume
299163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectCreate - Effect to be created is LVM_VOLUME");
3002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[sessionId].bVolumeInstantiated = LVM_TRUE;
301163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->itfe       = &gLvmEffectInterface;
3032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->EffectType = LVM_VOLUME;
304163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    else{
306163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectCreate() invalid UUID");
307163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
3082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *pInterface = (effect_interface_t)pContext;
311163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tEffectCreate end..\n\n");
3122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
3132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectCreate */
3142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int EffectRelease(effect_interface_t interface){
3162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\n\tEffectRelease start %p", interface);
3172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *)interface;
3182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
3212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
322163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
3232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // Clear the instantiated flag for the effect
3252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
3262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_BASS_BOOST Clearing global intstantiated flag");
327163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated = LVM_FALSE;
3282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VIRTUALIZER) {
3292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VIRTUALIZER Clearing global intstantiated flag");
330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated
331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            = LVM_FALSE;
3322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_EQUALIZER) {
3332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_EQUALIZER Clearing global intstantiated flag");
334163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated =LVM_FALSE;
3352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else if(pContext->EffectType == LVM_VOLUME) {
3362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tEffectRelease LVM_VOLUME Clearing global intstantiated flag");
337163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated = LVM_FALSE;
3382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
3392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : EffectRelease : Unsupported effect\n\n\n\n\n\n\n");
3402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
341163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
3422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // if all effects are no longer instantiaed free the lvm memory and delete BundledEffectContext
3432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if((GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBassInstantiated == LVM_FALSE)&&
344163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVolumeInstantiated == LVM_FALSE)&&
345163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bEqualizerInstantiated ==LVM_FALSE)&&
346163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    (GlobalSessionMemory[pContext->pBundledContext->SessionNo].bVirtualizerInstantiated==LVM_FALSE))
3472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
348163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #ifdef LVM_PCM
349163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        fclose(pContext->pBundledContext->PcmInPtr);
350163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        fclose(pContext->pBundledContext->PcmOutPtr);
351163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        #endif
352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: All effects are no longer instantiated\n");
353163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].bBundledEffectsEnabled =LVM_FALSE;
354163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        GlobalSessionMemory[pContext->pBundledContext->SessionNo].pBundledContext = LVM_NULL;
355163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: Freeing LVM Bundle memory\n");
356163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmEffect_free(pContext);
357163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffectRelease: Deleting LVM Bundle context\n");
358163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        delete pContext->pBundledContext;
3592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    // free the effect context for current effect
3612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    delete pContext;
3622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tEffectRelease end\n");
3642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
3652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end EffectRelease */
3672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmGlobalBundle_init(){
3692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmGlobalBundle_init start");
3702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for(int i=0; i<LVM_MAX_SESSIONS; i++){
3712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBundledEffectsEnabled   = LVM_FALSE;
3722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVolumeInstantiated      = LVM_FALSE;
3732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bEqualizerInstantiated   = LVM_FALSE;
3742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bBassInstantiated        = LVM_FALSE;
3752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].bVirtualizerInstantiated = LVM_FALSE;
3762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        GlobalSessionMemory[i].pBundledContext          = LVM_NULL;
3772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
3782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
3792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
3802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
3812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_init()
3822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
3832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Initialize engine with default configuration, creates instance
3842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// with all effects disabled.
3852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
3862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
3872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
3882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
3892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
3902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
3912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
3922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_init(EffectContext *pContext){
3942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status;
3952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
3962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init start");
3972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
398163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
399163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.channels                      = CHANNEL_STEREO;
400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.format                        = SAMPLE_FORMAT_PCM_S15;
401163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
402163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
403163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
404163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
405163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
406163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
407163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.channels                     = CHANNEL_STEREO;
408163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.format                       = SAMPLE_FORMAT_PCM_S15;
409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
410163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
411163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
412163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
4142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
4162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext->pBundledContext->hInstance != NULL){
4182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
4192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Calling pContext->pBassBoost->free()");
4202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LvmEffect_free(pContext);
4222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLvmBundle_init pContext->pBassBoost != NULL "
4242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                "-> Called pContext->pBassBoost->free()");
4252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;          /* Function call status */
4282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                         /* Control Parameters */
4292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_InstParams_t        InstParams;                     /* Instance parameters */
4302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_EQNB_BandDef_t      BandDefs[MAX_NUM_BANDS];        /* Equaliser band definitions */
4312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomParams_t    HeadroomParams;                 /* Headroom parameters */
4322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_HeadroomBandDef_t   HeadroomBandDef[LVM_HEADROOM_MAX_NBANDS];
4332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;                         /* Memory allocation table */
4342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    bool                    bMallocFailure = LVM_FALSE;
4352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the capabilities */
437163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    InstParams.BufferMode       = LVM_UNMANAGED_BUFFERS;
4382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.MaxBlockSize     = MAX_CALL_SIZE;
4392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.EQNB_NumBands    = MAX_NUM_BANDS;
4402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    InstParams.PSA_Included     = LVM_PSA_ON;
4412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory, forcing alignment */
4432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(LVM_NULL,
4442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &MemTab,
4452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                  &InstParams);
4462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmBundle_init")
4482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
4492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
4512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Allocate memory */
4532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
4542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
4552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
4562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
458163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes for region %u\n",
4592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i );
4602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                bMallocFailure = LVM_TRUE;
4612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
462163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmBundle_init CreateInstance allocated %ld bytes for region %u at %p\n",
4632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
4642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
4652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
4662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
4672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
4692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     * succesfully allocated and return with an error
4702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent     */
4712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(bMallocFailure == LVM_TRUE){
4722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
4732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
474163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed to allocate %ld bytes for region %u - +"
475163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "Not freeing\n", MemTab.Region[i].Size, i );
4762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
477163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR :LvmBundle_init CreateInstance Failed: but allocated %ld bytes "
478163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     "for region %u at %p- free\n",
479163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                     MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
4802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
4812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
4822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
4832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
4842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
485163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully malloc'd memory\n");
4862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Initialise */
488163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->hInstance = LVM_NULL;
4892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
490163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Init sets the instance handle */
491163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetInstanceHandle(&pContext->pBundledContext->hInstance,
4922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &MemTab,
4932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &InstParams);
4942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
4952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "LvmBundle_init")
4962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
4972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
498163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
4992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the initial process parameters */
5012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* General parameters */
5022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.OperatingMode          = LVM_MODE_ON;
5032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SampleRate             = LVM_FS_44100;
5042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SourceFormat           = LVM_STEREO;
5052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.SpeakerType            = LVM_HEADPHONES;
5062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->SampleRate = LVM_FS_44100;
508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
5092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Concert Sound parameters */
5102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerOperatingMode   = LVM_MODE_OFF;
5112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerType            = LVM_CONCERTSOUND;
5122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VirtualizerReverbLevel     = 100;
5132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.CS_EffectLevel             = LVM_CS_EFFECT_HIGH;
5142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* N-Band Equaliser parameters */
5162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_OperatingMode     = LVM_EQNB_OFF;
5172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.EQNB_NBands            = FIVEBAND_NUMBANDS;
5182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.pEQNB_BandDefinition   = &BandDefs[0];
519163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
5202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
5212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
5222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].Frequency = EQNB_5BandPresetsFrequencies[i];
5232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        BandDefs[i].QFactor   = EQNB_5BandPresetsQFactors[i];
524163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        BandDefs[i].Gain      = EQNB_5BandSoftPresets[i];
5252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
5262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume Control parameters */
5282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_EffectLevel         = 0;
5292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.VC_Balance             = 0;
5302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Treble Enhancement parameters */
5322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_OperatingMode       = LVM_TE_OFF;
5332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.TE_EffectLevel         = 0;
5342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
5362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
5372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = (LVM_PSA_DecaySpeed_en)0;
5382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
5402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_OperatingMode       = LVM_BE_OFF;
5412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_EffectLevel         = 0;
5422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_CentreFreq          = LVM_BE_CENTRE_90Hz;
5432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.BE_HPF                 = LVM_BE_HPF_ON;
5442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* PSA Control parameters */
5462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_Enable             = LVM_PSA_OFF;
5472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    params.PSA_PeakDecayRate      = LVM_PSA_SPEED_MEDIUM;
5482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
550163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance,
5512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &params);
5522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmBundle_init")
5542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetControlParameters\n");
5572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set the headroom parameters */
5592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_Low          = 20;
5602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Limit_High         = 4999;
5612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[0].Headroom_Offset    = 3;
5622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_Low          = 5000;
5632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Limit_High         = 24000;
5642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomBandDef[1].Headroom_Offset    = 4;
5652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.pHeadroomDefinition    = &HeadroomBandDef[0];
5662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
5672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    HeadroomParams.NHeadroomBands         = 2;
5682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetHeadroomParams(pContext->pBundledContext->hInstance,
5702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                      &HeadroomParams);
5712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetHeadroomParams", "LvmBundle_init")
5732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
5742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LOGV("\tLvmBundle_init CreateInstance Succesfully called LVM_SetHeadroomParams\n");
5762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tLvmBundle_init End");
5772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
5782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end LvmBundle_init */
5792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
5812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmBundle_process()
5822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
5832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
5842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply LVM Bundle effects
5852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
5862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
5872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pIn:        pointer to stereo 16 bit input data
5882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to stereo 16 bit output data
5892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  frameCount: Frames to process
5902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
5912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
5922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
5932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Outputs:
5942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pOut:       pointer to updated stereo 16 bit output data
5952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
5962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
5972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
5982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmBundle_process(LVM_INT16        *pIn,
599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      LVM_INT16        *pOut,
600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      int              frameCount,
601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                      EffectContext    *pContext){
6022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
6042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
6052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
606163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               *pOutTmp;
607163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE){
608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = pOut;
609163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pOutTmp = (LVM_INT16 *)malloc(frameCount * sizeof(LVM_INT16) * 2);
611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(pOutTmp == NULL){
612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process failed to allocate memory for "
613163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            "EFFECT_BUFFER_ACCESS_ACCUMULATE mode");
614163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
615163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("LVM_ERROR : LvmBundle_process invalid access mode");
618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
6202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
621163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
622163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
6232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
6242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmBundle_process")
6262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
628163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->frameCount++;
629163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->frameCount == 100)
630163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
631163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tBB: %d VIRT: %d EQ: %d, session (%d), context is %p\n",
632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //ActiveParams.BE_OperatingMode,
633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //ActiveParams.VirtualizerOperatingMode, ActiveParams.EQNB_OperatingMode,
634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->SessionNo, pContext->pBundledContext);
635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->frameCount = 0;
636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
637163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
638163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
639163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pIn, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmInPtr);
640163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmInPtr);
641163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
642163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Process the samples */
6442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_Process(pContext->pBundledContext->hInstance, /* Instance handle */
6452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pIn,                                  /* Input buffer */
6462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            pOutTmp,                              /* Output buffer */
6472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            (LVM_UINT16)frameCount,               /* Number of samples to read */
6482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            0);                                   /* Audo Time */
649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_Process", "LvmBundle_process")
6512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
6522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
653163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #ifdef LVM_PCM
654163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fwrite(pOutTmp, frameCount*sizeof(LVM_INT16)*2, 1, pContext->pBundledContext->PcmOutPtr);
655163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    fflush(pContext->pBundledContext->PcmOutPtr);
656163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    #endif
657163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
658163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        for (int i=0; i<frameCount*2; i++){
660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            pOut[i] +=  pOutTmp[i];
661163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
662163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        free(pOutTmp);
663163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
6642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
6652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmBundle_process */
6662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_enable()
6692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Enable the effect in the bundle
6712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
6732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
6742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
6762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
6772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
6782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_enable(EffectContext *pContext){
680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable start");
681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
6822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
6832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
6842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
685163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
686163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
6872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
6882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_enable")
6902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
691163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_GetControlParameters\n");
6922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
6932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
694163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_BASS_BOOST");
6952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_ON;
6962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
6972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VIRTUALIZER");
6992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_ON;
7002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
702163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_EQUALIZER");
7032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_ON;
7042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
706163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_enable : Enabling LVM_VOLUME");
707163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
708163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
7102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_enable")
7112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
712163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
713163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable Succesfully called LVM_SetControlParameters\n");
714163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_enable end");
7152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
7172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_disable()
7202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Disable the effect in the bundle
7222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint LvmEffect_disable(EffectContext *pContext){
731163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable start");
732163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
7342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
735163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
736163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
7372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
7382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "LvmEffect_disable")
7402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
741163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_GetControlParameters\n");
7422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST) {
744163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Disabling LVM_BASS_BOOST");
7452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.BE_OperatingMode       = LVM_BE_OFF;
7462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER) {
748163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_VIRTUALIZER");
7492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.VirtualizerOperatingMode   = LVM_MODE_OFF;
7502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER) {
752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_EQUALIZER");
7532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        ActiveParams.EQNB_OperatingMode     = LVM_EQNB_OFF;
7542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
7552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME) {
756163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLvmEffect_disable : Enabling LVM_VOLUME");
757163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
758163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
7592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
7602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "LvmEffect_disable")
7612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
762163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
763163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable Succesfully called LVM_SetControlParameters\n");
764163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tLvmEffect_disable end");
7652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
7662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
7672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// LvmEffect_free()
7702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Free all memory associated with the Bundle.
7722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
7742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
7752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
7772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
7782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
7792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid LvmEffect_free(EffectContext *pContext){
7812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;         /* Function call status */
7822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     params;                        /* Control Parameters */
7832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_MemTab_t            MemTab;
7842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Free the algorithm memory */
7862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetMemoryTable(pContext->pBundledContext->hInstance,
7872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   &MemTab,
7882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                   LVM_NULL);
7892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "LvmEffect_free")
7912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
7932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (MemTab.Region[i].Size != 0){
7942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (MemTab.Region[i].pBaseAddress != NULL){
795163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - START freeing %ld bytes for region %u at %p\n",
7962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
7972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
7982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                free(MemTab.Region[i].pBaseAddress);
7992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
800163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLvmEffect_free - END   freeing %ld bytes for region %u at %p\n",
8012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }else{
803163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                LOGV("\tLVM_ERROR : LvmEffect_free - trying to free with NULL pointer %ld bytes "
8042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "for region %u at %p ERROR\n",
8052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
8062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
8072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
8082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
8092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end LvmEffect_free */
8102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Effect_configure()
8132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Set input and output audio configuration.
8152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
8172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
8182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
8192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//      configuration parameters
8202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
8222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
8232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Effect_configure(EffectContext *pContext, effect_config_t *pConfig){
826163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_Fs_en   SampleRate;
827163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure start");
8282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pContext != NULL);
8302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig != NULL);
8312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
8332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == pConfig->outputCfg.channels);
8342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
8352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.channels == CHANNEL_STEREO);
8362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
8372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
8382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    CHECK_ARG(pConfig->inputCfg.format == SAMPLE_FORMAT_PCM_S15);
8392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    memcpy(&pContext->config, pConfig, sizeof(effect_config_t));
8412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
842163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    switch (pConfig->inputCfg.samplingRate) {
843163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 8000:
844163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_8000;
845163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
846163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 16000:
847163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_16000;
848163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
849163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 22050:
850163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_22050;
851163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
852163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 32000:
853163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_32000;
854163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
855163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 44100:
856163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_44100;
857163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
858163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    case 48000:
859163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        SampleRate = LVM_FS_48000;
860163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        break;
861163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    default:
862163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_Configure invalid sampling rate %d", pConfig->inputCfg.samplingRate);
863163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
864163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
8652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
866163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->SampleRate != SampleRate){
8672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
868163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ControlParams_t     ActiveParams;
869163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;
8702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
871163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure change sampling rate to %d", SampleRate);
8722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
873163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
874163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
875163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
8762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
877163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_configure")
878163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
8792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
880163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
8812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
882163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_configure")
883163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_configure Succesfully called LVM_SetControlParameters\n");
8842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
885163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
886163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_configure keep sampling rate at %d", SampleRate);
887163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
8882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
889163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_configure End....");
890163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
891163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}   /* end Effect_configure */
8922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
8932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassGetStrength()
8952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
8962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
8972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
8982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
8992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// the bassboost uses 1-15, so to avoid a quantisation the original set value is used. However the
9002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
9012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t BassGetStrength(EffectContext *pContext){
908163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-1000) -> %d\n", pContext->pBundledContext->BassStrengthSaved);
9092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
9112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
912163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
9142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
9152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassGetStrength")
9172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
919163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength Succesfully returned from LVM_GetControlParameters\n");
9202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Check that the strength returned matches the strength that was set earlier */
922163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(ActiveParams.BE_EffectLevel !=
923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (LVM_INT16)((15*pContext->pBundledContext->BassStrengthSaved)/1000)){
9242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : BassGetStrength module strength does not match savedStrength %d %d\n",
9252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                ActiveParams.BE_EffectLevel, pContext->pBundledContext->BassStrengthSaved);
9262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
9272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
9282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
929163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
930163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassGetStrength() (saved)  -> %d\n", pContext->pBundledContext->BassStrengthSaved );
9312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return pContext->pBundledContext->BassStrengthSaved;
9322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassGetStrength */
9332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassSetStrength()
9362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
9382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the BassBosst. Must first be converted from the range 0-1000 to 1-15
9392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
9432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid BassSetStrength(EffectContext *pContext, uint32_t strength){
947163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength(%d)", strength);
9482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->BassStrengthSaved = (int)strength;
9502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
9522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
9532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
9552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
9562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                         &ActiveParams);
9572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "BassSetStrength")
959163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully returned from LVM_GetControlParameters\n");
9602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Bass Enhancement parameters */
9622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_EffectLevel    = (LVM_INT16)((15*strength)/1000);
9632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.BE_CentreFreq     = LVM_BE_CENTRE_90Hz;
9642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
965163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength() (0-15)   -> %d\n", ActiveParams.BE_EffectLevel );
9662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
9682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "BassSetStrength")
971163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassSetStrength Succesfully called LVM_SetControlParameters\n");
9722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end BassSetStrength */
9732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerGetStrength()
9762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
9782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// get the effect strength currently being used, what is actually returned is the strengh that was
9792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// previously used in the set, this is because the app uses a strength in the range 0-1000 while
980163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// the Virtualizer uses 1-100, so to avoid a quantisation the original set value is used.However the
9812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// actual used value is checked to make sure it corresponds to the one being returned
9822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
9842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
9852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
9862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
9872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentuint32_t VirtualizerGetStrength(EffectContext *pContext){
989163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength (0-1000) -> %d\n",pContext->pBundledContext->VirtStrengthSaved);
9902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
9922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
9932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
9952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
9962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerGetStrength")
9972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
9982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
999163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength Succesfully returned from LVM_GetControlParameters\n");
1000163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerGetStrength() (0-100)   -> %d\n", ActiveParams.VirtualizerReverbLevel*10);
10012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return ActiveParams.VirtualizerReverbLevel*10;
10022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getStrength */
10032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VirtualizerSetStrength()
10062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Apply the strength to the Virtualizer. Must first be converted from the range 0-1000 to 1-15
10092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  strength    strength to be applied
10132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
1017163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength(%d)", strength);
10182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
10202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1021163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->VirtStrengthSaved = (int)strength;
1022163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
10232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
10242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,&ActiveParams);
10252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VirtualizerSetStrength")
1027163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully returned from LVM_GetControlParameters\n");
10282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Virtualizer parameters */
10302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.VirtualizerReverbLevel    = (LVM_INT16)(strength/10);
10312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength() (0-1000)   -> %d\n", strength );
1033163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength() (0- 100)   -> %d\n", ActiveParams.VirtualizerReverbLevel );
10342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
10362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
10372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VirtualizerSetStrength")
1038163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n");
10392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setStrength */
10402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandLevel()
10432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the gain currently being used for the band passed in
10452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
10482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
10512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
10542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1055163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Gain =0;
1056163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1057163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1058163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1059163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1060163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1061163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
10622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1063163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel")
10642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1065163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1066163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Gain    = (int32_t)BandDef[band].Gain*100;    // Convert to millibels
10672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1068163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel -> %d\n", Gain );
1069163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1070163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Gain;
10712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
10722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
10732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetBandLevel()
10752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
10762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
10772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Sets gain value for the given band.
10782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
10802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
10812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  Gain:       Gain to be applied in millibels
10822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
10832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
10852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
10862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//---------------------------------------------------------------------------
10872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetBandLevel(EffectContext *pContext, int band, int Gain){
1088163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int gainRounded;
1089163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(Gain > 0){
1090163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain+50)/100);
1091163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1092163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        gainRounded = (int)((Gain-50)/100);
1093163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1094163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);
1095163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1096163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
10972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
10982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1099163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
11002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
11022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1103163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetBandLevel")
1104163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel Succesfully returned from LVM_GetControlParameters\n");
1105163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel just Got -> %d\n", ActiveParams.pEQNB_BandDefinition[band].Gain);
11062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set local EQ parameters */
1108163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef = ActiveParams.pEQNB_BandDefinition;
1109163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    ActiveParams.pEQNB_BandDefinition[band].Gain = gainRounded;
11102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
11122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1113163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetBandLevel")
1114163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetBandLevel just Set -> %d\n", ActiveParams.pEQNB_BandDefinition[band].Gain);
11152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
11172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
11182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetCentreFrequency()
11212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose: Retrieve the frequency being used for the band passed in
11232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetCentreFrequency(EffectContext *pContext, int32_t band){
1132163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int32_t Frequency =0;
11332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1134163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1135163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1136163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_EQNB_BandDef_t      *BandDef;
1137163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1138163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
1139163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                         &ActiveParams);
11402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1141163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetCentreFrequency")
11422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1143163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    BandDef   = ActiveParams.pEQNB_BandDefinition;
1144163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Frequency = (int32_t)BandDef[band].Frequency*1000;     // Convert to millibels
11452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1146163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency -> %d\n", Frequency );
1147163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetCentreFrequency Succesfully returned from LVM_GetControlParameters\n");
1148163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return Frequency;
11492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBandFreqRange(
11532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets lower and upper boundaries of a band.
11572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the high shelf, the low bound is the band frequency and the high
11582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// bound is Nyquist.
11592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// For the peaking filters, they are the gain[dB]/2 points.
11602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  band:       band number
11632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
11642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
11672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
11682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1169163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t EqualizerGetBandFreqRange(EffectContext *pContext, int32_t band, uint32_t *pLow,
1170163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                  uint32_t *pHi){
1171163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pLow = bandFreqRange[band][0];
1172163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *pHi  = bandFreqRange[band][1];
1173163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
11742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
11752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
11762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetBand(
11782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
11802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Returns the band with the maximum influence on a given frequency.
11822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Result is unaffected by whether EQ is enabled or not, or by whether
11832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// changes have been committed or not.
11842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
11862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  targetFreq   The target frequency, in millihertz.
11872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
11882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
11892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
11902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       lower band range
11912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pLow:       upper band range
11922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
11932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetBand(EffectContext *pContext, uint32_t targetFreq){
11942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int band = 0;
11952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1196163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(targetFreq < bandFreqRange[0][0]){
1197163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
1198163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else if(targetFreq == bandFreqRange[0][0]){
1199163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
1200163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1201163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for(int i=0; i<FIVEBAND_NUMBANDS;i++){
1202163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if((targetFreq > bandFreqRange[i][0])&&(targetFreq <= bandFreqRange[i][1])){
1203163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            band = i;
1204163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1205163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
12062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return band;
12072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPreset(
12112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets the currently set preset ID.
12152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Will return PRESET_CUSTOM in case the EQ parameters have been modified
12162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// manually since a preset was set.
12172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetPreset(EffectContext *pContext){
1223163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return pContext->pBundledContext->CurPreset;
12242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerSetPreset(
12282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Sets the current preset by ID.
12322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// All the band parameters will be overridden.
12332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:    effect engine context
12362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  preset       The preset ID.
12372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentvoid EqualizerSetPreset(EffectContext *pContext, int preset){
12402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1241163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset(%d)", preset);
12422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->CurPreset = preset;
12432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
12452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
12462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
12482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1249163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetPreset")
1250163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully returned from LVM_GetControlParameters\n");
12512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    //ActiveParams.pEQNB_BandDefinition = &BandDefs[0];
12532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    for (int i=0; i<FIVEBAND_NUMBANDS; i++)
12542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    {
1255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
1256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
1257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.pEQNB_BandDefinition[i].Gain
1258163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        = EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
12592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
12602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the new settings */
12612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1262163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetPreset")
12632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1264163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
12652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return;
12662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
1267163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
12682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t EqualizerGetNumPresets(){
1269163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return sizeof(gEqualizerPresets) / sizeof(PresetConfig);
12702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// EqualizerGetPresetName(
12742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Gets a human-readable name for a preset ID. Will return "Custom" if
12772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// PRESET_CUSTOM is passed.
12782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
12802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// preset       The preset ID. Must be less than number of presets.
12812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//-------------------------------------------------------------------------
12832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst char * EqualizerGetPresetName(int32_t preset){
1284163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName start(%d)", preset);
12852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (preset == PRESET_CUSTOM) {
12862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return "Custom";
12872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    } else {
12882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return gEqualizerPresets[preset].name;
12892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1290163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizerGetPresetName end(%d)", preset);
1291163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
12922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}
12932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
12942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetVolumeLevel()
12962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
12972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
12982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
12992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  level       level to be applied
13022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
13062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1310163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Level to be set is %d %d\n", level, (LVM_INT16)(level/100));
13112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
13142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1315163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully returned from LVM_GetControlParameters got: %d\n",
1316163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //ActiveParams.VC_EffectLevel);
13172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Volume parameters */
13192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    ActiveParams.VC_EffectLevel  = (LVM_INT16)(level/100);
1320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel() (-96dB -> 0dB)   -> %d\n", ActiveParams.VC_EffectLevel );
13212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
13232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetVolumeLevel")
13252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
13262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1327163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel Succesfully called LVM_SetControlParameters\n");
1328163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1329163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel")
1332163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1333163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1334163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetVolumeLevel just set (-96dB -> 0dB)   -> %d\n", ActiveParams.VC_EffectLevel );
13352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
13362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setVolumeLevel */
13372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeGetVolumeLevel()
13402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){
13492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1350163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel start");
1351163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
13522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
13532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
13542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetVolumeLevel")
13572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
13582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel );
1360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel Succesfully returned from LVM_GetControlParameters\n");
13612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    *level = ActiveParams.VC_EffectLevel*100;     // Convert dB to millibels
1363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetVolumeLevel end");
13642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
13652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end VolumeGetVolumeLevel */
13662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// VolumeSetMute()
13692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
13712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
13732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
13742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
13752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
13762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
13772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){
1379163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute start(%d)", mute);
13802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    pContext->pBundledContext->bMuteEnabled = mute;
13822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
13842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
13852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Get the current settings */
13872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
13882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetMute")
13892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
13902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1391163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully returned from LVM_GetControlParameters\n");
1392163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute to %d, level was %d\n", mute, ActiveParams.VC_EffectLevel );
13932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
13942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Set appropriate volume level */
13952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){
1396163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->levelSaved = ActiveParams.VC_EffectLevel;
1397163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel           = -96;
13982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1399163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_EffectLevel  = pContext->pBundledContext->levelSaved;
14002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
14012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    /* Activate the initial settings */
14032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
14042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetMute")
14052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
14062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1407163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute Succesfully called LVM_SetControlParameters\n");
1408163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetMute end");
14092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
14102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end setMute */
14112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
1413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetMute()
14142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
14162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
14182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pContext:   effect engine context
14192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
14202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Ourputs:
14212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  mute:       enable/disable flag
14222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
14232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
14242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint32_t VolumeGetMute(EffectContext *pContext, uint32_t *mute){
1425163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute start");
1426163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if((pContext->pBundledContext->bMuteEnabled == LVM_FALSE)||
1427163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       (pContext->pBundledContext->bMuteEnabled == LVM_TRUE)){
1428163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        *mute = pContext->pBundledContext->bMuteEnabled;
1429163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return 0;
14302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
1431163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : VolumeGetMute read an invalid value from context %d",
1432163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent              pContext->pBundledContext->bMuteEnabled);
1433163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        return -EINVAL;
14342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
1435163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetMute end");
14362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end getMute */
14372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1438163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint16_t VolumeConvertStereoPosition(int16_t position){
1439163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t convertedPosition = 0;
1440163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1441163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    convertedPosition = (int16_t)(((float)position/1000)*96);
1442163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return convertedPosition;
1443163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1444163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
1445163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1446163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1447163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeSetStereoPosition()
1448163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1449163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1450163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1451163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1452163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1453163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1454163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1455163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1456163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1457163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1458163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint VolumeSetStereoPosition(EffectContext *pContext, int16_t position){
1459163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1460163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1461163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
1462163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               Balance = 0;
1463163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1464163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1465163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1466163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->positionSaved = position;
1467163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    Balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1468163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1469163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetStereoPosition start pContext->pBundledContext->positionSaved = %d", pContext->pBundledContext->positionSaved);
1470163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1471163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1472163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position to be set is %d %d\n", position, Balance);
1474163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->positionSaved = position;
1475163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1476163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1477163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1478163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1479163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got:"
1480163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     " %d\n", ActiveParams.VC_Balance);
1481163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1482163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Volume parameters */
1483163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  = Balance;
1484163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition() (-96dB -> +96dB)   -> %d\n", ActiveParams.VC_Balance );
1485163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1486163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Activate the initial settings */
1487163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1488163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetStereoPosition")
1489163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1490163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1491163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully called LVM_SetControlParameters\n");
14922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1493163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Get the current settings */
1494163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1495163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetStereoPosition")
1496163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1497163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Succesfully returned from LVM_GetControlParameters got: "
1498163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //     "%d\n", ActiveParams.VC_Balance);
1499163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1500163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    else{
1501163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tVolumeSetStereoPosition Position attempting to set, but not enabled %d %d\n",
1502163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //position, Balance);
1503163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1504163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeSetStereoPosition end pContext->pBundledContext->positionSaved = %d\n", pContext->pBundledContext->positionSaved);
1505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeSetStereoPosition */
15072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1510163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeGetStereoPosition()
1511163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1512163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1514163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:       effect engine context
1516163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1517163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Outputs:
1518163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  position:       stereo position
1519163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
15202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1521163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeGetStereoPosition(EffectContext *pContext, int16_t *position){
1522163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition start");
15232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1524163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;                           /* Current control Parameters */
1525163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus = LVM_SUCCESS;                /* Function call status */
1526163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16               balance;
1527163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1528163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition start pContext->pBundledContext->positionSaved = %d", pContext->pBundledContext->positionSaved);
1529163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1530163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1531163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetStereoPosition")
1532163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
1533163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1534163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition -> %d\n", ActiveParams.VC_Balance);
1535163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1536163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1537163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    balance = VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
1539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_TRUE){
1540163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(balance != ActiveParams.VC_Balance){
1541163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return -EINVAL;
1542163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
1543163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
1544163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    *position = (LVM_INT16)pContext->pBundledContext->positionSaved;     // Convert dB to millibels
1545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeGetStereoPosition end returning pContext->pBundledContext->positionSaved = %d\n", pContext->pBundledContext->positionSaved);
1546163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1547163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeGetStereoPosition */
15482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1549163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1550163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// VolumeEnableStereoPosition()
1551163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
1552163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Purpose:
1553163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1554163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent// Inputs:
1555163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  pContext:   effect engine context
1556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//  mute:       enable/disable flag
1557163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//
1558163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent//----------------------------------------------------------------------------
15592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1560163fbcf84010b98e0374110454d85b804bc8d13bEric Laurentint32_t VolumeEnableStereoPosition(EffectContext *pContext, uint32_t enabled){
1561163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition start()");
15622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1563163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    pContext->pBundledContext->bStereoPositionEnabled = enabled;
15642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
1566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
15672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1568163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Get the current settings */
1569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeEnableStereoPosition")
1571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
15722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1573163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully returned from LVM_GetControlParameters\n");
1574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition to %d, position was %d\n",
1575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //     enabled, ActiveParams.VC_Balance );
15762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Set appropriate stereo position */
1578163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->bStereoPositionEnabled == LVM_FALSE){
1579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance = 0;
1580163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }else{
1581163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        ActiveParams.VC_Balance  =
1582163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                            VolumeConvertStereoPosition(pContext->pBundledContext->positionSaved);
1583163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
15842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1585163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Activate the initial settings */
1586163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
1587163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeEnableStereoPosition")
1588163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(LvmStatus != LVM_SUCCESS) return -EINVAL;
15892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1590163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition Succesfully called LVM_SetControlParameters\n");
1591163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolumeEnableStereoPosition end()\n");
1592163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return 0;
1593163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}    /* end VolumeEnableStereoPosition */
15942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
15952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_getParameter()
15972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
15982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
15992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a BassBoost parameter
16002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
16032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
16042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
16052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
16062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
16082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
16092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
16102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
16132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_getParameter(EffectContext     *pContext,
1617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           int32_t           *pParam,
1618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           size_t            *pValueSize,
1619163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                           void              *pValue){
16202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
16212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param = *pParam++;
16222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
16232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
16242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1625163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter start");
16262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
162823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
16297fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
16307fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize %d", *pValueSize);
16317fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
16327fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
16337fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
16347fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
16352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
16362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
16377fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid pValueSize %d", *pValueSize);
16382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
16392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
16402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
16412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
16422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
1644163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
16452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
16462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
16472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
164923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
16502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
16512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
165223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH_SUPPORTED Value is %d",
1653163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
16542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
16552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
16572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = BassGetStrength(pContext);
16582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1659163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_getParameter() BASSBOOST_PARAM_STRENGTH Value is %d",
1660163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
16612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
16622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
16642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : BassBoost_getParameter() invalid param %d", param);
16652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
16662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
16672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
16682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1669163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_getParameter end");
16702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
16712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_getParameter */
16722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// BassBoost_setParameter()
16752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
16772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a BassBoost parameter
16782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
16802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pBassBoost       - handle to instance data
16812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
16822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
16832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
16852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
16862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
16872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint BassBoost_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){
16892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
16902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
16912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1692163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter start");
16932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
16942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (*pParam){
16952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case BASSBOOST_PARAM_STRENGTH:
16962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() BASSBOOST_PARAM_STRENGTH value is %d", strength);
1698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Calling pBassBoost->BassSetStrength");
16992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            BassSetStrength(pContext, (int32_t)strength);
1700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tBassBoost_setParameter() Called pBassBoost->BassSetStrength");
17012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
17022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : BassBoost_setParameter() invalid param %d", *pParam);
17042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1707163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tBassBoost_setParameter end");
17082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end BassBoost_setParameter */
17102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_getParameter()
17132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Virtualizer parameter
17162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
17192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
17212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
17222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
17242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
17252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
17262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
17292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_getParameter(EffectContext        *pContext,
17332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             int32_t              *pParam,
17342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             size_t               *pValueSize,
17352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                             void                 *pValue){
17362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
17372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param = *pParam++;
17382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
17392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
17402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1741163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter start");
17422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
174423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
17457fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
17467fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
17477fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                return -EINVAL;
17487fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            }
17497fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            *pValueSize = sizeof(uint32_t);
17507fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent            break;
17517fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent
17522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
17532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize != sizeof(int16_t)){
17547fa8a0ec14781a50695cf8c9dd2a85a5e8a3c3f0Eric Laurent                LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid pValueSize %d",*pValueSize);
17552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
17562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
17572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
17582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
17622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
17632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
176623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        case VIRTUALIZER_PARAM_STRENGTH_SUPPORTED:
17672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(uint32_t *)pValue = 1;
17682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
176923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH_SUPPORTED Value is %d",
1770163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(uint32_t *)pValue);
17712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
17742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = VirtualizerGetStrength(pContext);
17752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1776163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_getParameter() VIRTUALIZER_PARAM_STRENGTH Value is %d",
1777163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        *(int16_t *)pValue);
17782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
17812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_getParameter() invalid param %d", param);
17822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
17832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
17842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
17852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1786163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_getParameter end");
17872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
17882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_getParameter */
17892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
17902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Virtualizer_setParameter()
17922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
17932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
17942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Virtualizer parameter
17952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
17962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
17972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVirtualizer     - handle to instance data
17982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
17992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to value
18002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Virtualizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){
18062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
18072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t strength;
18082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1809163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter start");
18102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (*pParam){
18122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VIRTUALIZER_PARAM_STRENGTH:
18132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            strength = *(int16_t *)pValue;
1814163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() VIRTUALIZER_PARAM_STRENGTH value is %d", strength);
1815163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Calling pVirtualizer->setStrength");
18162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            VirtualizerSetStrength(pContext, (int32_t)strength);
1817163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tVirtualizer_setParameter() Called pVirtualizer->setStrength");
18182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent           break;
18192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
18202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Virtualizer_setParameter() invalid param %d", *pParam);
18212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
18222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
18232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1824163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVirtualizer_setParameter end");
18252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
18262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Virtualizer_setParameter */
18272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_getParameter()
18302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
18322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Equalizer parameter
18332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
18352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer       - handle to instance data
18362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
18372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
18382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
18392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
18412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
18422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
18432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
18462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
18472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
18482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_getParameter(EffectContext     *pContext,
18492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           int32_t           *pParam,
18502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           size_t            *pValueSize,
18512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                           void              *pValue){
18522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
18532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
18542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param = *pParam++;
18552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
18562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
18572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
1858163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_getParameter start");
18592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
18612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
18622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
18632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
18643be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_BAND_LEVEL:
18653be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_GET_BAND:
18662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int16_t)) {
1867163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
18682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
18692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
18702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int16_t);
18712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
18722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
18743be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (*pValueSize < 2 * sizeof(int16_t)) {
18753be9523784cc4038f601e510faee595117cdacb3Eric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
18763be9523784cc4038f601e510faee595117cdacb3Eric Laurent            return -EINVAL;
18773be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
18783be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *pValueSize = 2 * sizeof(int16_t);
18793be9523784cc4038f601e510faee595117cdacb3Eric Laurent        break;
18803be9523784cc4038f601e510faee595117cdacb3Eric Laurent
18812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
18822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < 2 * sizeof(int32_t)) {
1883163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 2  %d", *pValueSize);
18842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
18852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
18862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = 2 * sizeof(int32_t);
18872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
18883be9523784cc4038f601e510faee595117cdacb3Eric Laurent
18892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
18902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (*pValueSize < sizeof(int32_t)) {
1891163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
18922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
18932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
18942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = sizeof(int32_t);
18952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
18962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
18972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
18982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
18992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
190023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES:
190123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        if (*pValueSize < (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t)) {
190223e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid pValueSize 1  %d", *pValueSize);
190323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent            return -EINVAL;
190423e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
190523e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        *pValueSize = (2 + FIVEBAND_NUMBANDS) * sizeof(uint16_t);
190623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        break;
190723e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
19082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
1909163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter unknown param %d", param);
19102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
19112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
19122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
19142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_NUM_BANDS:
19153be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)FIVEBAND_NUMBANDS;
1916163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_NUM_BANDS %d", *(int16_t *)pValue);
19172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_LEVEL_RANGE:
19203be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = -1500;
19213be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *((int16_t *)pValue + 1) = 1500;
1922163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_LEVEL_RANGE min %d, max %d",
1923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      *(int32_t *)pValue, *((int32_t *)pValue + 1));
19242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
19272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        param2 = *pParam;
19282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
19292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
19302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19323be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(int16_t *)pValue = (int16_t)EqualizerGetBandLevel(pContext, param2);
1933163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_LEVEL band %d, level %d",
1934163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
19352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CENTER_FREQ:
19382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        param2 = *pParam;
19392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
19402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
19412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *(int32_t *)pValue = EqualizerGetCentreFrequency(pContext, param2);
1944163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CENTER_FREQ band %d, frequency %d",
1945163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
19462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_FREQ_RANGE:
19492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        param2 = *pParam;
19502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= FIVEBAND_NUMBANDS) {
19512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
19522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerGetBandFreqRange(pContext, param2, (uint32_t *)pValue, ((uint32_t *)pValue + 1));
1955163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_BAND_FREQ_RANGE band %d, min %d, max %d",
1956163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue, *((int32_t *)pValue + 1));
19572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_BAND:
19602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        param2 = *pParam;
19613be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetBand(pContext, param2);
1962163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_BAND frequency %d, band %d",
1963163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, *(int32_t *)pValue);
19642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
19673be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetPreset(pContext);
1968163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_CUR_PRESET %d", *(int32_t *)pValue);
19692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_NUM_OF_PRESETS:
19723be9523784cc4038f601e510faee595117cdacb3Eric Laurent        *(uint16_t *)pValue = (uint16_t)EqualizerGetNumPresets();
1973163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_NUM_OF_PRESETS %d", *(int16_t *)pValue);
19742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
19762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_GET_PRESET_NAME:
19772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        param2 = *pParam;
19782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (param2 >= EqualizerGetNumPresets()) {
19792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        //if (param2 >= 20) {     // AGO FIX
19802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
19812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
19822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
19832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name = (char *)pValue;
19842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        strncpy(name, EqualizerGetPresetName(param2), *pValueSize - 1);
19852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        name[*pValueSize - 1] = 0;
19862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        *pValueSize = strlen(name) + 1;
1987163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_getParameter() EQ_PARAM_GET_PRESET_NAME preset %d, name %s len %d",
1988163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //      param2, gEqualizerPresets[param2].name, *pValueSize);
19892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
19902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
199123e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    case EQ_PARAM_PROPERTIES: {
19923be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
199323e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        LOGV("\tEqualizer_getParameter() EQ_PARAM_PROPERTIES");
19943be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[0] = (int16_t)EqualizerGetPreset(pContext);
19953be9523784cc4038f601e510faee595117cdacb3Eric Laurent        p[1] = (int16_t)FIVEBAND_NUMBANDS;
199623e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
19973be9523784cc4038f601e510faee595117cdacb3Eric Laurent            p[2 + i] = (int16_t)EqualizerGetBandLevel(pContext, i);
199823e1de74359f4bb1763aef0adfebe073122b032cEric Laurent        }
199923e1de74359f4bb1763aef0adfebe073122b032cEric Laurent    } break;
200023e1de74359f4bb1763aef0adfebe073122b032cEric Laurent
20012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
20022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Equalizer_getParameter() invalid param %d", param);
20032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        status = -EINVAL;
20042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2007163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_getParameter end");
20082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
20092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_getParameter */
20102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Equalizer_setParameter()
20132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
20152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Equalizer parameter
20162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
20182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pEqualizer    - handle to instance data
20192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
20202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
20212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
20232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Equalizer_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){
20262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
20272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t preset;
20282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t band;
20292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t level;
20302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param = *pParam++;
20312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2032163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter start");
20332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param) {
20342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_CUR_PRESET:
20353be9523784cc4038f601e510faee595117cdacb3Eric Laurent        preset = (int32_t)(*(uint16_t *)pValue);
20362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2037163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_CUR_PRESET %d", preset);
20382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if ((preset >= EqualizerGetNumPresets())||(preset < 0)) {
20392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetPreset(pContext, preset);
20432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    case EQ_PARAM_BAND_LEVEL:
20452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        band =  *pParam;
20463be9523784cc4038f601e510faee595117cdacb3Eric Laurent        level = (int32_t)(*(int16_t *)pValue);
2047163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_BAND_LEVEL band %d, level %d", band, level);
20482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        if (band >= FIVEBAND_NUMBANDS) {
20492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
20502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
20512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        }
20522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        EqualizerSetBandLevel(pContext, band, level);
20532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20543be9523784cc4038f601e510faee595117cdacb3Eric Laurent    case EQ_PARAM_PROPERTIES: {
20553be9523784cc4038f601e510faee595117cdacb3Eric Laurent        //LOGV("\tEqualizer_setParameter() EQ_PARAM_PROPERTIES");
20563be9523784cc4038f601e510faee595117cdacb3Eric Laurent        int16_t *p = (int16_t *)pValue;
20573be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if ((int)p[0] >= EqualizerGetNumPresets()) {
20583be9523784cc4038f601e510faee595117cdacb3Eric Laurent            status = -EINVAL;
20593be9523784cc4038f601e510faee595117cdacb3Eric Laurent            break;
20603be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
20613be9523784cc4038f601e510faee595117cdacb3Eric Laurent        if (p[0] >= 0) {
20623be9523784cc4038f601e510faee595117cdacb3Eric Laurent            EqualizerSetPreset(pContext, (int)p[0]);
20633be9523784cc4038f601e510faee595117cdacb3Eric Laurent        } else {
20643be9523784cc4038f601e510faee595117cdacb3Eric Laurent            if ((int)p[1] != FIVEBAND_NUMBANDS) {
20653be9523784cc4038f601e510faee595117cdacb3Eric Laurent                status = -EINVAL;
20663be9523784cc4038f601e510faee595117cdacb3Eric Laurent                break;
20673be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
20683be9523784cc4038f601e510faee595117cdacb3Eric Laurent            for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
20693be9523784cc4038f601e510faee595117cdacb3Eric Laurent                EqualizerSetBandLevel(pContext, i, (int)p[2 + i]);
20703be9523784cc4038f601e510faee595117cdacb3Eric Laurent            }
20713be9523784cc4038f601e510faee595117cdacb3Eric Laurent        }
20723be9523784cc4038f601e510faee595117cdacb3Eric Laurent    } break;
20732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    default:
20742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : setParameter() invalid param %d", param);
20753be9523784cc4038f601e510faee595117cdacb3Eric Laurent        status = -EINVAL;
20762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        break;
20772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
20782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2079163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEqualizer_setParameter end");
20802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
20812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Equalizer_setParameter */
20822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
20832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_getParameter()
20852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
20862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
20872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Get a Volume parameter
20882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
20902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume          - handle to instance data
20912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam           - pointer to parameter
20922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue           - pointer to variable to hold retrieved value
20932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValueSize       - pointer to value size: maximum size as input
20942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
20962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValue updated with parameter value
20972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  *pValueSize updated with actual value size
20982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
20992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Side Effects:
21012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_getParameter(EffectContext     *pContext,
21052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        int32_t           *pParam,
21062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        size_t            *pValueSize,
21072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        void              *pValue){
21082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int status = 0;
21092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int bMute = 0;
21102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param = *pParam++;
21112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int32_t param2;
21122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    char *name;
21132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tVolume_getParameter start");
21152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
21172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
21182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
21192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2120163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if (*pValueSize != sizeof(int16_t)){
21212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 1  %d", *pValueSize);
21222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
21232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
21242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int16_t);
21252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
21282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
21292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (*pValueSize < sizeof(int32_t)){
21302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Volume_getParameter() invalid pValueSize 2  %d", *pValueSize);
21312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
21322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
21332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *pValueSize = sizeof(int32_t);
21342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
2137163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter unknown param %d", param);
21382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
21392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (param){
21422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
21432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeGetVolumeLevel(pContext, (int16_t *)(pValue));
2144163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_LEVEL Value is %d",
2145163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(int16_t *)pValue);
21462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MAXLEVEL:
21492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int16_t *)pValue = 0;
21502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_MAXLEVEL Value is %d",
21512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    *(int16_t *)pValue);
21522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2155163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            VolumeGetStereoPosition(pContext, (int16_t *)pValue);
21562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_STEREOPOSITION Value is %d",
21572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    *(int16_t *)pValue);
21582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2161163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeGetMute(pContext, (uint32_t *)pValue);
2162163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_MUTE Value is %d",
2163163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *(uint32_t *)pValue);
21642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2167163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            *(int32_t *)pValue = pContext->pBundledContext->bStereoPositionEnabled;
21682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_getParameter() VOLUME_PARAM_ENABLESTEREOPOSITION Value is %d",
21692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    *(uint32_t *)pValue);
21702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
21732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Volume_getParameter() invalid param %d", param);
21742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = -EINVAL;
21752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
21762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
21772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2178163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_getParameter end");
21792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
21802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_getParameter */
21812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Volume_setParameter()
21852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Purpose:
21872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Set a Volume parameter
21882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Inputs:
21902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pVolume       - handle to instance data
21912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pParam        - pointer to parameter
21922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//  pValue        - pointer to value
21932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// Outputs:
21952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//
21962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent//----------------------------------------------------------------------------
21972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
21982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentint Volume_setParameter (EffectContext *pContext, int32_t *pParam, void *pValue){
21992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int      status = 0;
22002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int16_t  level;
2201163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int16_t  position;
22022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    uint32_t mute;
2203163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    uint32_t positionEnabled;
22042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    LOGV("\tVolume_setParameter start");
22062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (*pParam){
22082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_LEVEL:
22092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            level = *(int16_t *)pValue;
22102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_setParameter() VOLUME_PARAM_LEVEL value is %d", level);
22112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_setParameter() Calling pVolume->setVolumeLevel");
22122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            status = VolumeSetVolumeLevel(pContext, (int16_t)level);
22132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tVolume_setParameter() Called pVolume->setVolumeLevel");
22142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_MUTE:
2217163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            mute = *(uint32_t *)pValue;
2218163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Calling pVolume->setMute, mute is %d", mute);
2219163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Calling pVolume->setMute");
2220163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetMute(pContext, mute);
2221163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Called pVolume->setMute");
2222163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
22232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_ENABLESTEREOPOSITION:
2225163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            positionEnabled = *(uint32_t *)pValue;
2226163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeEnableStereoPosition(pContext, positionEnabled);
2227163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, pContext->pBundledContext->positionSaved);
2228163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() VOLUME_PARAM_ENABLESTEREOPOSITION called");
2229163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
22302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case VOLUME_PARAM_STEREOPOSITION:
2232163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            position = *(int16_t *)pValue;
2233163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() VOLUME_PARAM_STEREOPOSITION value is %d", position);
2234163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Calling pVolume->VolumeSetStereoPosition");
2235163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            status = VolumeSetStereoPosition(pContext, (int16_t)position);
2236163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tVolume_setParameter() Called pVolume->VolumeSetStereoPosition");
2237163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
22382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
22402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            LOGV("\tLVM_ERROR : Volume_setParameter() invalid param %d", *pParam);
22412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
22422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
22432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2244163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tVolume_setParameter end");
22452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
22462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent} /* end Volume_setParameter */
22472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2248163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent/****************************************************************************************
2249163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent * Name : LVC_ToDB_s32Tos16()
2250163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Input       : Signed 32-bit integer
2251163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Output      : Signed 16-bit integer
2252163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  MSB (16) = sign bit
2253163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (15->05) = integer part
2254163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *                  (04->01) = decimal part
2255163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Returns     : Db value with respect to full scale
2256163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Description :
2257163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent *  Remarks     :
2258163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent ****************************************************************************************/
2259163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2260163fbcf84010b98e0374110454d85b804bc8d13bEric LaurentLVM_INT16 LVC_ToDB_s32Tos16(LVM_INT32 Lin_fix)
2261163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent{
2262163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   db_fix;
2263163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   Shift;
2264163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   SmallRemainder;
2265163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_UINT32  Remainder = (LVM_UINT32)Lin_fix;
2266163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2267163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Count leading bits, 1 cycle in assembly*/
2268163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    for (Shift = 0; Shift<32; Shift++)
2269163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    {
2270163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if ((Remainder & 0x80000000U)!=0)
2271163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2272163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2273163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2274163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        Remainder = Remainder << 1;
2275163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
22762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2277163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /*
2278163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * Based on the approximation equation (for Q11.4 format):
2279163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     *
2280163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     * dB = -96 * Shift + 16 * (8 * Remainder - 2 * Remainder^2)
2281163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent     */
2282163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix    = (LVM_INT16)(-96 * Shift);               /* Six dB steps in Q11.4 format*/
2283163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)((Remainder & 0x7fffffff) >> 24);
2284163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix + SmallRemainder );
2285163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    SmallRemainder = (LVM_INT16)(SmallRemainder * SmallRemainder);
2286163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - (LVM_INT16)((LVM_UINT16)SmallRemainder >> 9));
22872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2288163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    /* Correct for small offset */
2289163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    db_fix = (LVM_INT16)(db_fix - 5);
22902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2291163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    return db_fix;
2292163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent}
22932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2294163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
2295163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent} // namespace
22962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
22972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Process */
22982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_process(effect_interface_t     self,
2299163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *inBuffer,
2300163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              audio_buffer_t         *outBuffer){
23012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
23022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int    status = 0;
2303163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    int    lvmStatus = 0;
2304163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *in  = (LVM_INT16 *)inBuffer->raw;
2305163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    LVM_INT16   *out = (LVM_INT16 *)outBuffer->raw;
23062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2307163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_process Start : Enabled = %d     Called = %d",
2308163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled);
23092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
23112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR pContext == NULL");
23122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
23132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
23152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
23162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            inBuffer->frameCount != outBuffer->frameCount){
23172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
23182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
23192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2320163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bBassEnabled == LVM_FALSE)&&
2321163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_BASS_BOOST)){
2322163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_process() ERROR LVM_BASS_BOOST Effect is not enabled");
2323163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2324163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2325163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVolumeEnabled == LVM_FALSE)&&
2326163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VOLUME)){
2327163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_process() ERROR LVM_VOLUME Effect is not enabled");
2328163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
2329163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
2330163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE)&&
2331163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_EQUALIZER)){
2332163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_process() ERROR LVM_EQUALIZER Effect is not enabled");
2333163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
23342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2335163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if ((pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE)&&
2336163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        (pContext->EffectType == LVM_VIRTUALIZER)){
2337163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        LOGV("\tEffect_process() ERROR LVM_VIRTUALIZER Effect is not enabled");
2338163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        status = -ENODATA;
23392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2340163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2341163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // If this is the last frame of an effect process its output with no effect
2342163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(status == -ENODATA){
2343163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
2344163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() accumulating last frame into output buffer");
2345163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() trying copying last frame into output buffer");
2346163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Enabled = %d     Called = %d",
2347163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->NumberEffectsEnabled,
2348163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->NumberEffectsCalled);
2349163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2350163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }else{
2351163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() copying last frame into output buffer");
2352163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
23532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2354163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2355163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(status != -ENODATA){
2356163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        pContext->pBundledContext->NumberEffectsCalled++;
23572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
23582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2359163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    if(pContext->pBundledContext->NumberEffectsCalled ==
2360163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent       pContext->pBundledContext->NumberEffectsEnabled){
2361163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Calling process with %d effects enabled, %d called: Effect %d",
2362163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2363163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
23642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2365163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(status == -ENODATA){
2366163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tLVM_ERROR : Effect_process() actually processing last frame");
2367163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
23682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        pContext->pBundledContext->NumberEffectsCalled = 0;
2369163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        /* Process all the available frames, block processing is
2370163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent           handled internalLY by the LVM bundle */
2371163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        lvmStatus = android::LvmBundle_process(    (LVM_INT16 *)inBuffer->raw,
23722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                (LVM_INT16 *)outBuffer->raw,
23732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                outBuffer->frameCount,
23742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                pContext);
2375163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        if(lvmStatus != LVM_SUCCESS){
2376163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
2377163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            return lvmStatus;
2378163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
23792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }else{
2380163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
2381163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsEnabled,
2382163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
2383163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        // 2 is for stereo input
2384163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
23852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
2386163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
23872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return status;
23882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}   /* end Effect_process */
23892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
23902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent/* Effect Control Interface Implementation: Command */
23912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentextern "C" int Effect_command(effect_interface_t  self,
239225f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdCode,
239325f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            cmdSize,
2394163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pCmdData,
239525f4395b932fa9859a6e91ba77c5d20d009da64aEric Laurent                              uint32_t            *replySize,
2396163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              void                *pReplyData){
23972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    EffectContext * pContext = (EffectContext *) self;
23982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    int retsize;
23992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2400163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\t\nEffect_command start");
24012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_BASS_BOOST){
2403163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_BASS_BOOST");
24042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
24052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VIRTUALIZER){
2406163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VIRTUALIZER");
2407163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
24082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_EQUALIZER){
2409163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_EQUALIZER");
2410163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
24112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if(pContext->EffectType == LVM_VOLUME){
2412163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        //LOGV("\tEffect_command setting command for LVM_VOLUME");
2413163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    }
24142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    if (pContext == NULL){
24162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        LOGV("\tLVM_ERROR : Effect_command ERROR pContext == NULL");
24172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        return -EINVAL;
24182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
24192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2420163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
24212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2422163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // Incase we disable an effect, next time process is
2423163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // called the number of effect called could be greater
2424163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    // pContext->pBundledContext->NumberEffectsCalled = 0;
24252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2426163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command NumberEffectsCalled = %d, NumberEffectsEnabled = %d",
2427163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsCalled,
2428163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //        pContext->pBundledContext->NumberEffectsEnabled);
24292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    switch (cmdCode){
24312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_INIT:
2432010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
2433010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                LOGV("\tLVM_ERROR, EFFECT_CMD_INIT: ERROR for effect type %d",
2434010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                        pContext->EffectType);
2435010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                return -EINVAL;
2436010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            }
2437010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent            *(int *) pReplyData = 0;
2438163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT start");
24392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2440163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_BASS_BOOST");
24412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                android::BassSetStrength(pContext, 0);
24422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
24432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2444163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_VIRTUALIZER");
2445163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::VirtualizerSetStrength(pContext, 0);
2446163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
24472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2448163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_INIT for LVM_EQUALIZER");
2449163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                android::EqualizerSetPreset(pContext, 0);
2450163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
24512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2452163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEffect_command cmdCode Case: "
2453163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_INIT start");
2454010ae0dd9eab40a49a840388230d8bb2f97c530eEric Laurent                *(int *) pReplyData = android::VolumeSetVolumeLevel(pContext, 0);
2455163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
24562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2457163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
24582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_CONFIGURE:
2459163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE start");
24602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pCmdData    == NULL||
24612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                cmdSize     != sizeof(effect_config_t)||
24622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                pReplyData  == NULL||
24632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize  != sizeof(int)){
24642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
24652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_CONFIGURE: ERROR");
24662c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
24672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
24682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *) pReplyData = android::Effect_configure(pContext, (effect_config_t *) pCmdData);
2469163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_CONFIGURE end");
24702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
24712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_RESET:
2473163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET start");
24742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            android::Effect_configure(pContext, &pContext->config);
2475163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_RESET end");
24762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
24772c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_GET_PARAM:{
2479163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM start");
2480163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
24812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2482163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2483163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2484163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2485163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
24862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
24872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
24882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
24892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
24902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
24912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
24932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
24952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
24972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
24982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::BassBoost_getParameter(pContext,
24992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            (int32_t *)p->data,
25002c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            (size_t  *)&p->vsize,
25012c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                            p->data + voffset);
25022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
25042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2505163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_GET_PARAM "
2506163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2507163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2508163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2509163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
25102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
2511163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2513163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2514163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2515163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2516163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
25172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
25182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
25192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
25202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
25212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
25222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
25242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
25262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
25282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Virtualizer_getParameter(pContext,
25302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                             (int32_t *)p->data,
25312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                             (size_t  *)&p->vsize,
25322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                              p->data + voffset);
25332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
25352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2536163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVirtualizer_command EFFECT_CMD_GET_PARAM "
2537163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2538163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2539163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2540163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
25412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
25422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2543163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command cmdCode Case: "
2544163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2545163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2546163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2547163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL ||
2548163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))) {
25492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
25502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM");
25512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
25522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
25532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
2554163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
2556163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
2558163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
2560163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Equalizer_getParameter(pContext, (int32_t *)p->data, &p->vsize,
25622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        p->data + voffset);
2563163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
25642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
2565163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2566163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command EFFECT_CMD_GET_PARAM *pCmdData %d, *replySize %d, "
2567163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //       "*pReplyData %08x %08x",
2568163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)), *replySize,
2569163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset),
2570163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset +
2571163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        sizeof(int32_t)));
25722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
25732c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2574163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command cmdCode Case: "
2575163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_GET_PARAM start");
2576163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData == NULL ||
2577163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
2578163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pReplyData == NULL ||
2579163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
25802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
25812c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_GET_PARAM: ERROR");
25822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
25832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
25842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *)pCmdData;
25852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
25872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p = (effect_param_t *)pReplyData;
25892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
25912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                p->status = android::Volume_getParameter(pContext,
25932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         (int32_t *)p->data,
25942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         (size_t  *)&p->vsize,
25952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                         p->data + voffset);
25962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
25972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *replySize = sizeof(effect_param_t) + voffset + p->vsize;
25982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2599163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_GET_PARAM "
2600163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2601163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2602163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2603163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
2604163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2605163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_GET_PARAM end");
26062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
26072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_PARAM:{
2608163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM start");
26092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2610163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tBassBoost_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2611163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2612163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2613163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2614163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2615163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2616163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2617163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2618163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
26192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
26202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
26212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
26242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26252c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
26262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
26272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
26282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2631163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnBassBoost_command cmdSize is %d\n"
2632163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2633163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2634163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2635163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2636163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
26372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::BassBoost_setParameter(pContext,
26392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    (int32_t *)p->data,
26402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    p->data + p->psize);
26412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
26422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2643163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVirtualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d",
2644163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2645163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2646163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2647163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2648163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if (pCmdData   == NULL||
2649163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    cmdSize    != (int)(sizeof(effect_param_t) + sizeof(int32_t) +sizeof(int16_t))||
2650163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pReplyData == NULL||
2651163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    *replySize != sizeof(int32_t)){
26522c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
26532c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
26542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
26572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (p->psize != sizeof(int32_t)){
26592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
26602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
26612c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2664163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tnVirtualizer_command cmdSize is %d\n"
2665163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tsizeof(effect_param_t) is  %d\n"
2666163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->psize is %d\n"
2667163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\tp->vsize is %d"
2668163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "\n",
2669163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
26702c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26712c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Virtualizer_setParameter(pContext,
26722c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                      (int32_t *)p->data,
2673163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                       p->data + p->psize);
26742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
26752c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_EQUALIZER){
2676163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command cmdCode Case: "
2677163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_SET_PARAM start");
2678163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tEqualizer_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2679163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2680163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2681163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
26822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
26842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pReplyData == NULL || *replySize != sizeof(int32_t)) {
26852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
26862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
26872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
26882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
26892c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
26902c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
26912c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Equalizer_setParameter(pContext,
26922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                    (int32_t *)p->data,
2693163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                     p->data + p->psize);
26942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
26952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if(pContext->EffectType == LVM_VOLUME){
2696163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command cmdCode Case: "
2697163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        "EFFECT_CMD_SET_PARAM start");
2698163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //LOGV("\tVolume_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2699163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2700163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *replySize,
2701163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
27022c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                if (    pCmdData   == NULL||
27042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        cmdSize    < (int)(sizeof(effect_param_t) + sizeof(int32_t))||
27052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        pReplyData == NULL||
27062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        *replySize != sizeof(int32_t)){
27072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
27082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                            "EFFECT_CMD_SET_PARAM: ERROR");
27092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    return -EINVAL;
27102c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                }
27112c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                effect_param_t *p = (effect_param_t *) pCmdData;
27122c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                *(int *)pReplyData = android::Volume_setParameter(pContext,
27142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                                                 (int32_t *)p->data,
2715163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                                                                 p->data + p->psize);
2716163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2717163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_PARAM end");
27182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        } break;
27192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
27202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_ENABLE:
2721163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE start");
27222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
27232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_ENABLE: ERROR");
27242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
2725163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27262c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            switch (pContext->EffectType){
27272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_BASS_BOOST:
27282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
27292c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27302c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
27312c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
27322c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
27332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bBassEnabled = LVM_TRUE;
2734163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_BASS_BOOST enabled");
27352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
27362c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_EQUALIZER:
27372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bEqualizerEnabled == LVM_TRUE){
27382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
27392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
27402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
27412c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
27422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bEqualizerEnabled = LVM_TRUE;
2743163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_EQUALIZER enabled");
2744163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
27452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VIRTUALIZER:
27462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
27472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
27482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
27492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
27502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
27512c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVirtualizerEnabled = LVM_TRUE;
2752163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case:EFFECT_CMD_ENABLE LVM_VIRTUALIZER enabled");
2753163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
27542c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VOLUME:
27552c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVolumeEnabled == LVM_TRUE){
27562c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
27572c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
27582c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
27592c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
27602c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVolumeEnabled = LVM_TRUE;
2761163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE LVM_VOLUME enabled");
27622c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
27632c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                default:
27642c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
27652c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_ENABLE: ERROR, invalid Effect Type");
2766163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    return -EINVAL;
27672c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            }
27682c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *)pReplyData = 0;
27692c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            pContext->pBundledContext->NumberEffectsEnabled++;
2770163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::LvmEffect_enable(pContext);
2771163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE NumberEffectsEnabled = %d",
2772163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        pContext->pBundledContext->NumberEffectsEnabled);
2773163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_ENABLE end");
27742c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2775163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
27762c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_DISABLE:
2777163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE start");
27782c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
27792c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                LOGV("\tLVM_ERROR : Effect_command cmdCode Case: EFFECT_CMD_DISABLE: ERROR");
27802c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                return -EINVAL;
2781163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
27822c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            switch (pContext->EffectType){
27832c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_BASS_BOOST:
27842c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_FALSE){
27852c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : BassBoost_command cmdCode Case: "
27862c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
27872c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
27882c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
2789163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    pContext->pBundledContext->bBassEnabled      = LVM_FALSE;
2790163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2791163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //       "EFFECT_CMD_DISABLE LVM_BASS_BOOST disabled");
27922c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
27932c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_EQUALIZER:
27942c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bEqualizerEnabled == LVM_FALSE){
27952c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Equalizer_command cmdCode Case: "
27962c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
27972c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
27982c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
27992c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bEqualizerEnabled = LVM_FALSE;
2800163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2801163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //       "EFFECT_CMD_DISABLE LVM_EQUALIZER disabled");
2802163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
28032c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VIRTUALIZER:
28042c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_FALSE){
28052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Virtualizer_command cmdCode Case: "
28062c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
28072c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28082c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28092c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVirtualizerEnabled = LVM_FALSE;
2810163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: "
2811163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //     "EFFECT_CMD_DISABLE LVM_VIRTUALIZER disabled");
2812163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    break;
28132c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                case LVM_VOLUME:
28142c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    if(pContext->pBundledContext->bVolumeEnabled == LVM_FALSE){
28152c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         LOGV("\tLVM_ERROR : Volume_command cmdCode Case: "
28162c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                                 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
28172c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                         return -EINVAL;
28182c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    }
28192c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    pContext->pBundledContext->bVolumeEnabled = LVM_FALSE;
2820163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE LVM_VOLUME disabled");
28212c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    break;
28222c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                default:
28232c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                    LOGV("\tLVM_ERROR : Effect_command cmdCode Case: "
28242c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent                        "EFFECT_CMD_DISABLE: ERROR, invalid Effect Type");
2825163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    return -EINVAL;
2826163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
28272c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            *(int *)pReplyData = 0;
28282c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            pContext->pBundledContext->NumberEffectsEnabled--;
2829163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::LvmEffect_disable(pContext);
2830163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE NumberEffectsEnabled = %d",
2831163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //        pContext->pBundledContext->NumberEffectsEnabled);
2832163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_DISABLE end");
28332c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
28342c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
28352c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        case EFFECT_CMD_SET_DEVICE:
2836163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2837163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start");
2838163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            audio_device_e device = *(audio_device_e *)pCmdData;
2839163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2840163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_BASS_BOOST){
2841163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
2842163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
2843163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d",
2844163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
2845163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST");
2846163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2847163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device doesnt support bassboost the effect must be temporarily disabled
2848163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
2849163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
2850163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2851163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassEnabled == LVM_TRUE){
2852163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d",
2853163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
2854163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
2855163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_TRUE;
2856163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2857163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
2858163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d",
2859163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                         *(int32_t *)pCmdData);
2860163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2861163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports bassboost and the effect has been temporarily disabled
2862163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
2863163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2864163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bBassTempDisabled == LVM_TRUE){
2865163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d",
2866163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                             *(int32_t *)pCmdData);
2867163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
2868163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bBassTempDisabled = LVM_FALSE;
2869163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2870163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
2871163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2872163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pContext->EffectType == LVM_VIRTUALIZER){
2873163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                if((device == DEVICE_SPEAKER)||(device == DEVICE_BLUETOOTH_SCO_CARKIT)||
2874163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                   (device == DEVICE_BLUETOOTH_A2DP_SPEAKER)){
2875163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d",
2876163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
2877163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER");
2878163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2879163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    //If a device doesnt support virtualizer the effect must be temporarily disabled
2880163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // the effect must still report its original state as this can only be changed
2881163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // by the ENABLE/DISABLE command
2882163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2883163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerEnabled == LVM_TRUE){
2884163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d",
2885163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
2886163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_disable(pContext);
2887163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_TRUE;
2888163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2889163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }else{
2890163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    LOGV("\tEFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d",
2891163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                          *(int32_t *)pCmdData);
2892163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2893163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // If a device supports virtualizer and the effect has been temporarily disabled
2894163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    // previously then re-enable it
2895163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2896163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    if(pContext->pBundledContext->bVirtualizerTempDisabled == LVM_TRUE){
2897163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        LOGV("\tEFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d",
2898163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                              *(int32_t *)pCmdData);
2899163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        android::LvmEffect_enable(pContext);
2900163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                        pContext->pBundledContext->bVirtualizerTempDisabled = LVM_FALSE;
2901163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                    }
2902163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                }
2903163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2904163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            LOGV("\tEffect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end");
29052c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            break;
2906163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        }
2907163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_VOLUME:
2908163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        {
2909163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t channels = cmdSize/sizeof(int32_t);
2910163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t vol     = *(int32_t *)pCmdData;
2911163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int16_t vol_db;
2912163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int16_t dB;
2913163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int16_t vol_db_rnd;
2914163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            int32_t vol_ret[2] = {1<<24,1<<24}; // Apply no volume
2915163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2916163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // if pReplyData is NULL, VOL_CTRL is delegated to another effect
2917163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(pReplyData == LVM_NULL){
2918163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                break;
2919163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
29202c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2921163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            if(vol==0x1000000){
2922163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent                vol -= 1;
2923163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            }
2924163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            // Convert volume linear (Q8.24) to volume dB (0->-96)
2925163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = android::LVC_ToDB_s32Tos16(vol <<7);
2926163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = (dB +8)>>4;
2927163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            dB = (dB <-96) ? -96 : dB ;
2928163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent
2929163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //LOGV("\tSession: %d, VOLUME is %d dB (%d), effect is %d",
2930163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            //pContext->pBundledContext->SessionNo, (int32_t)dB, vol<<7, pContext->EffectType);
2931163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            memcpy(pReplyData, vol_ret, sizeof(int32_t)*2);
2932163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            android::VolumeSetVolumeLevel(pContext, (int16_t)(dB*100));
2933163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
2934163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent         }
2935163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
2936163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent            break;
29372c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent        default:
29382c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent            return -EINVAL;
29392c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    }
29402c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2941163fbcf84010b98e0374110454d85b804bc8d13bEric Laurent    //LOGV("\tEffect_command end...\n\n");
29422c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    return 0;
29432c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent}    /* end Effect_command */
29442c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
29452c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent// effect_interface_t interface implementation for effect
29462c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurentconst struct effect_interface_s gLvmEffectInterface = {
29472c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_process,
29482c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent    Effect_command
29492c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent};    /* end gLvmEffectInterface */
29502c8e5cab3faa6d360e222b7a6c40a80083d021acEric Laurent
2951