1c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/*
2c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * Copyright (C) 2010-2010 NXP Software
3c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * Copyright (C) 2009 The Android Open Source Project
4c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent *
5c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
6c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * you may not use this file except in compliance with the License.
7c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * You may obtain a copy of the License at
8c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent *
9c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
10c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent *
11c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * Unless required by applicable law or agreed to in writing, software
12c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
13c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * See the License for the specific language governing permissions and
15c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent * limitations under the License.
16c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent */
17d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#ifndef LVM_FLOAT
18d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuritypedef float LVM_FLOAT;
19d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#endif
20c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent#define LOG_TAG "Reverb"
21ee5863a537bc83a0a603de43e068bbaff850ec59Chih-Hung Hsieh#define ARRAY_SIZE(array) (sizeof (array) / sizeof (array)[0])
2297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//#define LOG_NDEBUG 0
23c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
24c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent#include <assert.h>
257b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn#include <inttypes.h>
267b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn#include <new>
27c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent#include <stdlib.h>
28c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent#include <string.h>
297b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn
3094a1ee822686e920a33e312f4032f991731aea07rago#include <audio_utils/primitives.h>
3160d02077d86d2d1092443519290101f503aa6f7aMark Salyzyn#include <log/log.h>
3260d02077d86d2d1092443519290101f503aa6f7aMark Salyzyn
33b4d307481960b6b348fae4b4e8edefd003c3d36cGlenn Kasten#include "EffectReverb.h"
34b4d307481960b6b348fae4b4e8edefd003c3d36cGlenn Kasten// from Reverb/lib
35b4d307481960b6b348fae4b4e8edefd003c3d36cGlenn Kasten#include "LVREV.h"
36c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
37e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent// effect_handle_t interface implementation for reverb
38c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentextern "C" const struct effect_interface_s gReverbInterface;
39c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
40c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent#define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
41ee5863a537bc83a0a603de43e068bbaff850ec59Chih-Hung Hsieh        if ((LvmStatus) == LVREV_NULLADDRESS){\
423856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVREV_ERROR : Parameter error - "\
43c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                    "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
44c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }\
45ee5863a537bc83a0a603de43e068bbaff850ec59Chih-Hung Hsieh        if ((LvmStatus) == LVREV_INVALIDNUMSAMPLES){\
463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVREV_ERROR : Parameter error - "\
47c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                    "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
48c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }\
49ee5863a537bc83a0a603de43e068bbaff850ec59Chih-Hung Hsieh        if ((LvmStatus) == LVREV_OUTOFRANGE){\
503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVREV_ERROR : Parameter error - "\
51c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                    "out of range returned by %s in %s\n", callingFunc, calledFunc);\
52c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }\
53c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
54c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
55c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Namespaces
56c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentnamespace android {
57c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentnamespace {
58c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
59c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/************************************************************************************/
60c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/*                                                                                  */
61c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/* Preset definitions                                                               */
62c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/*                                                                                  */
63c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/************************************************************************************/
64c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
6597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurentconst static t_reverb_settings sReverbPresets[] = {
6697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // REVERB_PRESET_NONE: values are unused
6797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
6897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // REVERB_PRESET_SMALLROOM
69e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        {-400, -600, 1100, 830, -400, 5, 500, 10, 1000, 1000},
7097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // REVERB_PRESET_MEDIUMROOM
71e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        {-400, -600, 1300, 830, -1000, 20, -200, 20, 1000, 1000},
7297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // REVERB_PRESET_LARGEROOM
73e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        {-400, -600, 1500, 830, -1600, 5, -1000, 40, 1000, 1000},
7497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // REVERB_PRESET_MEDIUMHALL
75e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        {-400, -600, 1800, 700, -1300, 15, -800, 30, 1000, 1000},
7697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // REVERB_PRESET_LARGEHALL
77e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        {-400, -600, 1800, 700, -2000, 30, -1400, 60, 1000, 1000},
7897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // REVERB_PRESET_PLATE
79e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        {-400, -200, 1300, 900, 0, 2, 0, 10, 1000, 750},
8097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent};
8197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
8297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
8397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// NXP SW auxiliary environmental reverb
8497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurentconst effect_descriptor_t gAuxEnvReverbDescriptor = {
85c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e } },
86c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        { 0x4a387fc0, 0x8ab3, 0x11df, 0x8bad, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } },
87e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
8897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        EFFECT_FLAG_TYPE_AUXILIARY,
89d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVREV_CUP_LOAD_ARM9E,
90d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVREV_MEM_USAGE,
9197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        "Auxiliary Environmental Reverb",
9297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        "NXP Software Ltd.",
9397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent};
9497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
9597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// NXP SW insert environmental reverb
9697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurentstatic const effect_descriptor_t gInsertEnvReverbDescriptor = {
9797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}},
9897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        {0xc7a511a0, 0xa3bb, 0x11df, 0x860e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
99e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
100e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_VOLUME_CTRL,
101d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVREV_CUP_LOAD_ARM9E,
102d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVREV_MEM_USAGE,
10397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        "Insert Environmental Reverb",
104c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        "NXP Software Ltd.",
105c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent};
106c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
10797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// NXP SW auxiliary preset reverb
10897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurentstatic const effect_descriptor_t gAuxPresetReverbDescriptor = {
10997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
11097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        {0xf29a1400, 0xa3bb, 0x11df, 0x8ddc, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
111e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
11297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        EFFECT_FLAG_TYPE_AUXILIARY,
113d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVREV_CUP_LOAD_ARM9E,
114d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVREV_MEM_USAGE,
11597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        "Auxiliary Preset Reverb",
11697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        "NXP Software Ltd.",
11797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent};
11897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
11997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// NXP SW insert preset reverb
12097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurentstatic const effect_descriptor_t gInsertPresetReverbDescriptor = {
12197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
12297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        {0x172cdf00, 0xa3bc, 0x11df, 0xa72f, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
123e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        EFFECT_CONTROL_API_VERSION,
124e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_VOLUME_CTRL,
125d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVREV_CUP_LOAD_ARM9E,
126d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent        LVREV_MEM_USAGE,
12797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        "Insert Preset Reverb",
12897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        "NXP Software Ltd.",
12997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent};
13097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
13197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// gDescriptors contains pointers to all defined effect descriptor in this library
13297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurentstatic const effect_descriptor_t * const gDescriptors[] = {
13397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        &gAuxEnvReverbDescriptor,
13497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        &gInsertEnvReverbDescriptor,
13597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        &gAuxPresetReverbDescriptor,
13697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        &gInsertPresetReverbDescriptor
13797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent};
13897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
13994a1ee822686e920a33e312f4032f991731aea07rago#ifdef BUILD_FLOAT
14094a1ee822686e920a33e312f4032f991731aea07ragotypedef     float               process_buffer_t; // process in float
14194a1ee822686e920a33e312f4032f991731aea07rago#else
14294a1ee822686e920a33e312f4032f991731aea07ragotypedef     int32_t             process_buffer_t; // process in Q4_27
14394a1ee822686e920a33e312f4032f991731aea07rago#endif // BUILD_FLOAT
14494a1ee822686e920a33e312f4032f991731aea07rago
145c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentstruct ReverbContext{
146c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    const struct effect_interface_s *itfe;
147c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    effect_config_t                 config;
148c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_Handle_t                  hInstance;
149c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t                         SavedRoomLevel;
150c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t                         SavedHfLevel;
151c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t                         SavedDecayTime;
152c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t                         SavedDecayHfRatio;
153c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t                         SavedReverbLevel;
154c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t                         SavedDiffusion;
155c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t                         SavedDensity;
156c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    bool                            bEnabled;
157c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    #ifdef LVM_PCM
158c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    FILE                            *PcmInPtr;
159c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    FILE                            *PcmOutPtr;
160c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    #endif
161c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_Fs_en                       SampleRate;
16294a1ee822686e920a33e312f4032f991731aea07rago    process_buffer_t                *InFrames;
16394a1ee822686e920a33e312f4032f991731aea07rago    process_buffer_t                *OutFrames;
164d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri    size_t                          bufferSizeIn;
165d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri    size_t                          bufferSizeOut;
16697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    bool                            auxiliary;
16797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    bool                            preset;
16897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    uint16_t                        curPreset;
16997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    uint16_t                        nextPreset;
1702d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    int                             SamplesToExitCount;
171e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    LVM_INT16                       leftVolume;
172e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    LVM_INT16                       rightVolume;
173e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    LVM_INT16                       prevLeftVolume;
174e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    LVM_INT16                       prevRightVolume;
175e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    int                             volumeMode;
176e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent};
177e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
178e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurentenum {
179e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    REVERB_VOLUME_OFF,
180e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    REVERB_VOLUME_FLAT,
181e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    REVERB_VOLUME_RAMP,
182c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent};
183c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
184df489b929115ea93a0cf689830fe44400ce3c00fGlenn Kasten#define REVERB_DEFAULT_PRESET REVERB_PRESET_NONE
18597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
186d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#ifdef BUILD_FLOAT
187d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#define REVERB_SEND_LEVEL   0.75f // 0.75 in 4.12 format
188d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#else
189e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent#define REVERB_SEND_LEVEL   (0x0C00) // 0.75 in 4.12 format
190d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#endif
191e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent#define REVERB_UNIT_VOLUME  (0x1000) // 1.0 in 4.12 format
192e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
193c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//--- local function prototypes
194c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Reverb_init            (ReverbContext *pContext);
195c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid Reverb_free            (ReverbContext *pContext);
1963d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentint  Reverb_setConfig       (ReverbContext *pContext, effect_config_t *pConfig);
1973d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentvoid Reverb_getConfig       (ReverbContext *pContext, effect_config_t *pConfig);
198804632afcdda6e80945bf27c384757bda50560cbMikhail Naganovint  Reverb_setParameter    (ReverbContext *pContext, void *pParam, void *pValue, int vsize);
199c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint  Reverb_getParameter    (ReverbContext *pContext,
200c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void          *pParam,
201b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                             uint32_t      *pValueSize,
202c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                             void          *pValue);
20397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurentint Reverb_LoadPreset       (ReverbContext   *pContext);
204804632afcdda6e80945bf27c384757bda50560cbMikhail Naganovint Reverb_paramValueSize   (int32_t param);
205c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
206c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/* Effect Library Interface Implementation */
207c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2085e92a7861196ddae14638d4b7a63fc4892b7ef59Glenn Kastenextern "C" int EffectCreate(const effect_uuid_t *uuid,
2096368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent                            int32_t             sessionId __unused,
2106368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent                            int32_t             ioId __unused,
211e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                            effect_handle_t  *pHandle){
212c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int ret;
213c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int i;
21497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    int length = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *);
21597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    const effect_descriptor_t *desc;
216c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\t\nEffectCreate start");
218c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
219e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pHandle == NULL || uuid == NULL){
2203856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer");
221c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
222c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
223c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
22497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    for (i = 0; i < length; i++) {
22597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        desc = gDescriptors[i];
22697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        if (memcmp(uuid, &desc->uuid, sizeof(effect_uuid_t))
22797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent                == 0) {
2283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tEffectCreate - UUID matched Reverb type %d, UUID = %x", i, desc->uuid.timeLow);
22997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent            break;
23097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        }
23197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    }
23297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
23397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if (i == length) {
23497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        return -ENOENT;
235c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
236c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
237c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    ReverbContext *pContext = new ReverbContext;
238c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
239c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->itfe      = &gReverbInterface;
240c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->hInstance = NULL;
241c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
24297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    pContext->auxiliary = false;
24397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if ((desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY){
24497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        pContext->auxiliary = true;
2453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - AUX");
2462d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    }else{
2473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - INS");
24897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    }
24997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
25097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    pContext->preset = false;
25197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if (memcmp(&desc->type, SL_IID_PRESETREVERB, sizeof(effect_uuid_t)) == 0) {
25297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        pContext->preset = true;
25397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // force reloading preset at first call to process()
25497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        pContext->curPreset = REVERB_PRESET_LAST + 1;
25597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        pContext->nextPreset = REVERB_DEFAULT_PRESET;
2563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - PRESET");
2572d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    }else{
2583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tEffectCreate - ENVIRONMENTAL");
25997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    }
26097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
2613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectCreate - Calling Reverb_init");
262c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    ret = Reverb_init(pContext);
263c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
264c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (ret < 0){
2653856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectCreate() init failed");
266c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        delete pContext;
267c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return ret;
268c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
269c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
270e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    *pHandle = (effect_handle_t)pContext;
271c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
27294a1ee822686e920a33e312f4032f991731aea07rago#ifdef LVM_PCM
273c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->PcmInPtr = NULL;
274c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->PcmOutPtr = NULL;
275c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
276c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->PcmInPtr  = fopen("/data/tmp/reverb_pcm_in.pcm", "w");
277c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->PcmOutPtr = fopen("/data/tmp/reverb_pcm_out.pcm", "w");
278c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
279c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if((pContext->PcmInPtr  == NULL)||
280c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       (pContext->PcmOutPtr == NULL)){
281c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       return -EINVAL;
282c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
28394a1ee822686e920a33e312f4032f991731aea07rago#endif
284c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
28594a1ee822686e920a33e312f4032f991731aea07rago    int channels = audio_channel_count_from_out_mask(pContext->config.inputCfg.channels);
286d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
287d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    // Allocate memory for reverb process (*2 is for STEREO)
28894a1ee822686e920a33e312f4032f991731aea07rago    pContext->bufferSizeIn = LVREV_MAX_FRAME_SIZE * sizeof(process_buffer_t) * channels;
28994a1ee822686e920a33e312f4032f991731aea07rago    pContext->bufferSizeOut = LVREV_MAX_FRAME_SIZE * sizeof(process_buffer_t) * FCC_2;
29094a1ee822686e920a33e312f4032f991731aea07rago    pContext->InFrames  = (process_buffer_t *)calloc(pContext->bufferSizeIn, 1 /* size */);
29194a1ee822686e920a33e312f4032f991731aea07rago    pContext->OutFrames = (process_buffer_t *)calloc(pContext->bufferSizeOut, 1 /* size */);
292d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent
2937b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn    ALOGV("\tEffectCreate %p, size %zu", pContext, sizeof(ReverbContext));
2943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectCreate end\n");
295c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return 0;
296c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent} /* end EffectCreate */
297c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
298e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentextern "C" int EffectRelease(effect_handle_t handle){
299e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    ReverbContext * pContext = (ReverbContext *)handle;
300c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
3013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tEffectRelease %p", handle);
302c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (pContext == NULL){
3033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
304c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
305c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
306c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
307c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    #ifdef LVM_PCM
308c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    fclose(pContext->PcmInPtr);
309c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    fclose(pContext->PcmOutPtr);
310c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    #endif
31194a1ee822686e920a33e312f4032f991731aea07rago    free(pContext->InFrames);
31294a1ee822686e920a33e312f4032f991731aea07rago    free(pContext->OutFrames);
313d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri    pContext->bufferSizeIn = 0;
314d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri    pContext->bufferSizeOut = 0;
315c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    Reverb_free(pContext);
316c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    delete pContext;
317c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return 0;
318c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent} /* end EffectRelease */
319c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
3205e92a7861196ddae14638d4b7a63fc4892b7ef59Glenn Kastenextern "C" int EffectGetDescriptor(const effect_uuid_t *uuid,
321e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                                   effect_descriptor_t *pDescriptor) {
322e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    int i;
323e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    int length = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *);
324e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
325e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pDescriptor == NULL || uuid == NULL){
3263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("EffectGetDescriptor() called with NULL pointer");
327e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return -EINVAL;
328e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
329e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
330e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    for (i = 0; i < length; i++) {
331e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        if (memcmp(uuid, &gDescriptors[i]->uuid, sizeof(effect_uuid_t)) == 0) {
332a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten            *pDescriptor = *gDescriptors[i];
3333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("EffectGetDescriptor - UUID matched Reverb type %d, UUID = %x",
334e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                 i, gDescriptors[i]->uuid.timeLow);
335e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            return 0;
336e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        }
337e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
338e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
339e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    return -EINVAL;
340e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent} /* end EffectGetDescriptor */
341e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
342c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/* local functions */
343c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent#define CHECK_ARG(cond) {                     \
344c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (!(cond)) {                            \
3453856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Invalid argument: "#cond);      \
346c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;                       \
347c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }                                         \
348c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
349c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
350c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
351c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// process()
352c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
353c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
354c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Apply the Reverb
355c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
356c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
35794a1ee822686e920a33e312f4032f991731aea07rago//  pIn:        pointer to stereo/mono float or 16 bit input data
35894a1ee822686e920a33e312f4032f991731aea07rago//  pOut:       pointer to stereo float or 16 bit output data
359c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  frameCount: Frames to process
360c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
361c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  strength    strength to be applied
362c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
363c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  Outputs:
364c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pOut:       pointer to updated stereo 16 bit output data
365c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
366c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
36794a1ee822686e920a33e312f4032f991731aea07ragoint process( effect_buffer_t   *pIn,
36894a1ee822686e920a33e312f4032f991731aea07rago             effect_buffer_t   *pOut,
369c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent             int           frameCount,
370c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent             ReverbContext *pContext){
371c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
37294a1ee822686e920a33e312f4032f991731aea07rago    int channels = audio_channel_count_from_out_mask(pContext->config.inputCfg.channels);
373c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en   LvmStatus = LVREV_SUCCESS;              /* Function call status */
374c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
375c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Check that the input is either mono or stereo
37694a1ee822686e920a33e312f4032f991731aea07rago    if (!(channels == 1 || channels == FCC_2) ) {
37794a1ee822686e920a33e312f4032f991731aea07rago        ALOGE("\tLVREV_ERROR : process invalid PCM format");
378c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
379c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
380c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
38194a1ee822686e920a33e312f4032f991731aea07rago#ifdef BUILD_FLOAT
38294a1ee822686e920a33e312f4032f991731aea07rago    size_t inSize = frameCount * sizeof(process_buffer_t) * channels;
38394a1ee822686e920a33e312f4032f991731aea07rago    size_t outSize = frameCount * sizeof(process_buffer_t) * FCC_2;
38494a1ee822686e920a33e312f4032f991731aea07rago    if (pContext->InFrames == NULL ||
38594a1ee822686e920a33e312f4032f991731aea07rago            pContext->bufferSizeIn < inSize) {
38694a1ee822686e920a33e312f4032f991731aea07rago        free(pContext->InFrames);
38794a1ee822686e920a33e312f4032f991731aea07rago        pContext->bufferSizeIn = inSize;
38894a1ee822686e920a33e312f4032f991731aea07rago        pContext->InFrames = (process_buffer_t *)calloc(1, pContext->bufferSizeIn);
38994a1ee822686e920a33e312f4032f991731aea07rago    }
39094a1ee822686e920a33e312f4032f991731aea07rago    if (pContext->OutFrames == NULL ||
39194a1ee822686e920a33e312f4032f991731aea07rago            pContext->bufferSizeOut < outSize) {
39294a1ee822686e920a33e312f4032f991731aea07rago        free(pContext->OutFrames);
39394a1ee822686e920a33e312f4032f991731aea07rago        pContext->bufferSizeOut = outSize;
39494a1ee822686e920a33e312f4032f991731aea07rago        pContext->OutFrames = (process_buffer_t *)calloc(1, pContext->bufferSizeOut);
39594a1ee822686e920a33e312f4032f991731aea07rago    }
39694a1ee822686e920a33e312f4032f991731aea07rago
39794a1ee822686e920a33e312f4032f991731aea07rago#ifndef NATIVE_FLOAT_BUFFER
39894a1ee822686e920a33e312f4032f991731aea07rago    effect_buffer_t * const OutFrames16 = (effect_buffer_t *)pContext->OutFrames;
39994a1ee822686e920a33e312f4032f991731aea07rago#endif
40094a1ee822686e920a33e312f4032f991731aea07rago#endif
401c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
402c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Check for NULL pointers
40394a1ee822686e920a33e312f4032f991731aea07rago    if ((pContext->InFrames == NULL) || (pContext->OutFrames == NULL)) {
40494a1ee822686e920a33e312f4032f991731aea07rago        ALOGE("\tLVREV_ERROR : process failed to allocate memory for temporary buffers ");
405c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
406c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
407c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
40894a1ee822686e920a33e312f4032f991731aea07rago#ifdef LVM_PCM
40994a1ee822686e920a33e312f4032f991731aea07rago    fwrite(pIn, frameCount * sizeof(*pIn) * channels, 1 /* nmemb */, pContext->PcmInPtr);
410c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    fflush(pContext->PcmInPtr);
41194a1ee822686e920a33e312f4032f991731aea07rago#endif
412c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
41397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if (pContext->preset && pContext->nextPreset != pContext->curPreset) {
41497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        Reverb_LoadPreset(pContext);
41597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    }
416e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
417e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    if (pContext->auxiliary) {
418d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#ifdef BUILD_FLOAT
41994a1ee822686e920a33e312f4032f991731aea07rago#ifdef NATIVE_FLOAT_BUFFER
42094a1ee822686e920a33e312f4032f991731aea07rago        static_assert(std::is_same<decltype(*pIn), decltype(*pContext->InFrames)>::value,
42194a1ee822686e920a33e312f4032f991731aea07rago                "pIn and InFrames must be same type");
42294a1ee822686e920a33e312f4032f991731aea07rago        memcpy(pContext->InFrames, pIn, frameCount * channels * sizeof(*pIn));
423d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#else
42494a1ee822686e920a33e312f4032f991731aea07rago        memcpy_to_float_from_i16(
42594a1ee822686e920a33e312f4032f991731aea07rago                pContext->InFrames, pIn, frameCount * channels);
42694a1ee822686e920a33e312f4032f991731aea07rago#endif
42794a1ee822686e920a33e312f4032f991731aea07rago#else //no BUILD_FLOAT
42894a1ee822686e920a33e312f4032f991731aea07rago        for (int i = 0; i < frameCount * channels; i++) {
42994a1ee822686e920a33e312f4032f991731aea07rago            pContext->InFrames[i] = (process_buffer_t)pIn[i]<<8;
430e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        }
431d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#endif
432d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri        } else {
433e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        // insert reverb input is always stereo
434e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        for (int i = 0; i < frameCount; i++) {
43594a1ee822686e920a33e312f4032f991731aea07rago#ifdef BUILD_FLOAT
43694a1ee822686e920a33e312f4032f991731aea07rago#ifdef NATIVE_FLOAT_BUFFER
43794a1ee822686e920a33e312f4032f991731aea07rago            pContext->InFrames[2 * i] = (process_buffer_t)pIn[2 * i] * REVERB_SEND_LEVEL;
43894a1ee822686e920a33e312f4032f991731aea07rago            pContext->InFrames[2 * i + 1] = (process_buffer_t)pIn[2 * i + 1] * REVERB_SEND_LEVEL;
439d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#else
44094a1ee822686e920a33e312f4032f991731aea07rago            pContext->InFrames[2 * i] =
44194a1ee822686e920a33e312f4032f991731aea07rago                    (process_buffer_t)pIn[2 * i] * REVERB_SEND_LEVEL / 32768.0f;
44294a1ee822686e920a33e312f4032f991731aea07rago            pContext->InFrames[2 * i + 1] =
44394a1ee822686e920a33e312f4032f991731aea07rago                    (process_buffer_t)pIn[2 * i + 1] * REVERB_SEND_LEVEL / 32768.0f;
44494a1ee822686e920a33e312f4032f991731aea07rago#endif
44594a1ee822686e920a33e312f4032f991731aea07rago#else
44694a1ee822686e920a33e312f4032f991731aea07rago            pContext->InFrames[2*i] = (pIn[2*i] * REVERB_SEND_LEVEL) >> 4; // <<8 + >>12
44794a1ee822686e920a33e312f4032f991731aea07rago            pContext->InFrames[2*i+1] = (pIn[2*i+1] * REVERB_SEND_LEVEL) >> 4; // <<8 + >>12
448d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#endif
449e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        }
450c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
451c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
45297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if (pContext->preset && pContext->curPreset == REVERB_PRESET_NONE) {
45394a1ee822686e920a33e312f4032f991731aea07rago        memset(pContext->OutFrames, 0,
45494a1ee822686e920a33e312f4032f991731aea07rago                frameCount * sizeof(*pContext->OutFrames) * FCC_2); //always stereo here
45597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    } else {
4562d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent        if(pContext->bEnabled == LVM_FALSE && pContext->SamplesToExitCount > 0) {
45794a1ee822686e920a33e312f4032f991731aea07rago            memset(pContext->InFrames, 0,
45894a1ee822686e920a33e312f4032f991731aea07rago                    frameCount * sizeof(*pContext->OutFrames) * channels);
45994a1ee822686e920a33e312f4032f991731aea07rago            ALOGV("\tZeroing %d samples per frame at the end of call", channels);
46097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        }
4612d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent
4625185b0138aaeffeecc93b958cb9cd9821f260fafEric Laurent        /* Process the samples, producing a stereo output */
4632d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent        LvmStatus = LVREV_Process(pContext->hInstance,      /* Instance handle */
46494a1ee822686e920a33e312f4032f991731aea07rago                                  pContext->InFrames,     /* Input buffer */
46594a1ee822686e920a33e312f4032f991731aea07rago                                  pContext->OutFrames,    /* Output buffer */
4662d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent                                  frameCount);              /* Number of samples to read */
46794a1ee822686e920a33e312f4032f991731aea07rago    }
468c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
469c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_Process", "process")
470c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
471c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
472c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Convert to 16 bits
4732d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    if (pContext->auxiliary) {
474d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#ifdef BUILD_FLOAT
47594a1ee822686e920a33e312f4032f991731aea07rago        // nothing to do here
47694a1ee822686e920a33e312f4032f991731aea07rago#ifndef NATIVE_FLOAT_BUFFER
47794a1ee822686e920a33e312f4032f991731aea07rago        // pContext->OutFrames and OutFrames16 point to the same buffer
47894a1ee822686e920a33e312f4032f991731aea07rago        // make sure the float to int conversion happens in the right order.
47994a1ee822686e920a33e312f4032f991731aea07rago        memcpy_to_i16_from_float(OutFrames16, pContext->OutFrames,
48094a1ee822686e920a33e312f4032f991731aea07rago                (size_t)frameCount * FCC_2);
48194a1ee822686e920a33e312f4032f991731aea07rago#endif
482d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#else
4835effdf6d9ed17b4ff67a7e1adc56996c01c43383Andy Hung        memcpy_to_i16_from_q4_27(OutFrames16, pContext->OutFrames, (size_t)frameCount * FCC_2);
484d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#endif
48594a1ee822686e920a33e312f4032f991731aea07rago    } else {
486d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#ifdef BUILD_FLOAT
48794a1ee822686e920a33e312f4032f991731aea07rago#ifdef NATIVE_FLOAT_BUFFER
48894a1ee822686e920a33e312f4032f991731aea07rago        for (int i = 0; i < frameCount * FCC_2; i++) { // always stereo here
48994a1ee822686e920a33e312f4032f991731aea07rago            // Mix with dry input
49094a1ee822686e920a33e312f4032f991731aea07rago            pContext->OutFrames[i] += pIn[i];
49194a1ee822686e920a33e312f4032f991731aea07rago        }
492d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#else
49394a1ee822686e920a33e312f4032f991731aea07rago        for (int i = 0; i < frameCount * FCC_2; i++) { // always stereo here
49494a1ee822686e920a33e312f4032f991731aea07rago            // pOutputBuff and OutFrames16 point to the same buffer
49594a1ee822686e920a33e312f4032f991731aea07rago            // make sure the float to int conversion happens in the right order.
49694a1ee822686e920a33e312f4032f991731aea07rago            pContext->OutFrames[i] += (process_buffer_t)pIn[i] / 32768.0f;
49794a1ee822686e920a33e312f4032f991731aea07rago        }
49894a1ee822686e920a33e312f4032f991731aea07rago        memcpy_to_i16_from_float(OutFrames16, pContext->OutFrames,
49994a1ee822686e920a33e312f4032f991731aea07rago                (size_t)frameCount * FCC_2);
50094a1ee822686e920a33e312f4032f991731aea07rago#endif
50194a1ee822686e920a33e312f4032f991731aea07rago#else
50294a1ee822686e920a33e312f4032f991731aea07rago        for (int i=0; i < frameCount * FCC_2; i++) { // always stereo here
50394a1ee822686e920a33e312f4032f991731aea07rago            OutFrames16[i] = clamp16((pContext->OutFrames[i]>>8) + (process_buffer_t)pIn[i]);
50494a1ee822686e920a33e312f4032f991731aea07rago        }
505d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#endif
506e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        // apply volume with ramp if needed
507e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        if ((pContext->leftVolume != pContext->prevLeftVolume ||
508e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                pContext->rightVolume != pContext->prevRightVolume) &&
509e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                pContext->volumeMode == REVERB_VOLUME_RAMP) {
51094a1ee822686e920a33e312f4032f991731aea07rago#if defined (BUILD_FLOAT) && defined (NATIVE_FLOAT_BUFFER)
51194a1ee822686e920a33e312f4032f991731aea07rago            // FIXME: still using int16 volumes.
51294a1ee822686e920a33e312f4032f991731aea07rago            // For reference: REVERB_UNIT_VOLUME  (0x1000) // 1.0 in 4.12 format
51394a1ee822686e920a33e312f4032f991731aea07rago            float vl = (float)pContext->prevLeftVolume / 4096;
51494a1ee822686e920a33e312f4032f991731aea07rago            float incl = (((float)pContext->leftVolume / 4096) - vl) / frameCount;
51594a1ee822686e920a33e312f4032f991731aea07rago            float vr = (float)pContext->prevRightVolume / 4096;
51694a1ee822686e920a33e312f4032f991731aea07rago            float incr = (((float)pContext->rightVolume / 4096) - vr) / frameCount;
51794a1ee822686e920a33e312f4032f991731aea07rago
51894a1ee822686e920a33e312f4032f991731aea07rago            for (int i = 0; i < frameCount; i++) {
51994a1ee822686e920a33e312f4032f991731aea07rago                pContext->OutFrames[FCC_2 * i] *= vl;
52094a1ee822686e920a33e312f4032f991731aea07rago                pContext->OutFrames[FCC_2 * i + 1] *= vr;
52194a1ee822686e920a33e312f4032f991731aea07rago
52294a1ee822686e920a33e312f4032f991731aea07rago                vl += incl;
52394a1ee822686e920a33e312f4032f991731aea07rago                vr += incr;
52494a1ee822686e920a33e312f4032f991731aea07rago            }
52594a1ee822686e920a33e312f4032f991731aea07rago#else
526e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            LVM_INT32 vl = (LVM_INT32)pContext->prevLeftVolume << 16;
527e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            LVM_INT32 incl = (((LVM_INT32)pContext->leftVolume << 16) - vl) / frameCount;
528e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            LVM_INT32 vr = (LVM_INT32)pContext->prevRightVolume << 16;
529e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            LVM_INT32 incr = (((LVM_INT32)pContext->rightVolume << 16) - vr) / frameCount;
530e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
531e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            for (int i = 0; i < frameCount; i++) {
53294a1ee822686e920a33e312f4032f991731aea07rago                OutFrames16[FCC_2 * i] =
533e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                        clamp16((LVM_INT32)((vl >> 16) * OutFrames16[2*i]) >> 12);
53494a1ee822686e920a33e312f4032f991731aea07rago                OutFrames16[FCC_2 * i + 1] =
535e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                        clamp16((LVM_INT32)((vr >> 16) * OutFrames16[2*i+1]) >> 12);
536e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
537e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                vl += incl;
538e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                vr += incr;
539e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            }
54094a1ee822686e920a33e312f4032f991731aea07rago#endif
541e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            pContext->prevLeftVolume = pContext->leftVolume;
542e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            pContext->prevRightVolume = pContext->rightVolume;
543e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        } else if (pContext->volumeMode != REVERB_VOLUME_OFF) {
544e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            if (pContext->leftVolume != REVERB_UNIT_VOLUME ||
545e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                pContext->rightVolume != REVERB_UNIT_VOLUME) {
546e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                for (int i = 0; i < frameCount; i++) {
54794a1ee822686e920a33e312f4032f991731aea07rago#if defined(BUILD_FLOAT) && defined(NATIVE_FLOAT_BUFFER)
54894a1ee822686e920a33e312f4032f991731aea07rago                    pContext->OutFrames[FCC_2 * i] *= ((float)pContext->leftVolume / 4096);
54994a1ee822686e920a33e312f4032f991731aea07rago                    pContext->OutFrames[FCC_2 * i + 1] *= ((float)pContext->rightVolume / 4096);
55094a1ee822686e920a33e312f4032f991731aea07rago#else
55194a1ee822686e920a33e312f4032f991731aea07rago                    OutFrames16[FCC_2 * i] =
552e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                            clamp16((LVM_INT32)(pContext->leftVolume * OutFrames16[2*i]) >> 12);
55394a1ee822686e920a33e312f4032f991731aea07rago                    OutFrames16[FCC_2 * i + 1] =
554e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                            clamp16((LVM_INT32)(pContext->rightVolume * OutFrames16[2*i+1]) >> 12);
55594a1ee822686e920a33e312f4032f991731aea07rago#endif
556e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                }
557e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            }
558e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            pContext->prevLeftVolume = pContext->leftVolume;
559e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            pContext->prevRightVolume = pContext->rightVolume;
560e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            pContext->volumeMode = REVERB_VOLUME_RAMP;
561e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        }
562c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
563c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
56494a1ee822686e920a33e312f4032f991731aea07rago#ifdef LVM_PCM
56594a1ee822686e920a33e312f4032f991731aea07rago    fwrite(pContext->OutFrames, frameCount * sizeof(*pContext->OutFrames) * FCC_2,
56694a1ee822686e920a33e312f4032f991731aea07rago            1 /* nmemb */, pContext->PcmOutPtr);
567c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    fflush(pContext->PcmOutPtr);
56894a1ee822686e920a33e312f4032f991731aea07rago#endif
569c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
570c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // Accumulate if required
571c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
5723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tBuffer access is ACCUMULATE");
57394a1ee822686e920a33e312f4032f991731aea07rago        for (int i = 0; i < frameCount * FCC_2; i++) { // always stereo here
57494a1ee822686e920a33e312f4032f991731aea07rago#ifndef NATIVE_FLOAT_BUFFER
57597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent            pOut[i] = clamp16((int32_t)pOut[i] + (int32_t)OutFrames16[i]);
57694a1ee822686e920a33e312f4032f991731aea07rago#else
57794a1ee822686e920a33e312f4032f991731aea07rago            pOut[i] += pContext->OutFrames[i];
57894a1ee822686e920a33e312f4032f991731aea07rago#endif
579c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
580c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }else{
5813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tBuffer access is WRITE");
58294a1ee822686e920a33e312f4032f991731aea07rago        memcpy(pOut, pContext->OutFrames, frameCount * sizeof(*pOut) * FCC_2);
583c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
584c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
585c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return 0;
586c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}    /* end process */
587c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
588c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
589c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Reverb_free()
590c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
591c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose: Free all memory associated with the Bundle.
592c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
593c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
594c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
595c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
596c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Outputs:
597c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
598c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
599c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
600c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid Reverb_free(ReverbContext *pContext){
601c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
602c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;         /* Function call status */
603c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_MemoryTable_st      MemTab;
604c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
605c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Free the algorithm memory */
606c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetMemoryTable(pContext->hInstance,
607c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                   &MemTab,
608c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                   LVM_NULL);
609c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
610c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "Reverb_free")
611c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
612c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
613c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if (MemTab.Region[i].Size != 0){
614c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (MemTab.Region[i].pBaseAddress != NULL){
6157b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tfree() - START freeing %" PRIu32 " bytes for region %u at %p\n",
616c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
617c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
618c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                free(MemTab.Region[i].pBaseAddress);
619c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
6207b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tfree() - END   freeing %" PRIu32 " bytes for region %u at %p\n",
621c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
622c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }else{
6237b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLVM_ERROR : free() - trying to free with NULL pointer %" PRIu32 " bytes "
624c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        "for region %u at %p ERROR\n",
625c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
626c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
627c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
628c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
629c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}    /* end Reverb_free */
630c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
631c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
6323d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Reverb_setConfig()
633c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
634c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose: Set input and output audio configuration.
635c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
636c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
637c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
638c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
639c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//      configuration parameters
640c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
641c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Outputs:
642c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
643c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
644c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
6453d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentint Reverb_setConfig(ReverbContext *pContext, effect_config_t *pConfig){
646c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_Fs_en   SampleRate;
6473d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tReverb_setConfig start");
648c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
649c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CHECK_ARG(pContext != NULL);
650c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CHECK_ARG(pConfig != NULL);
651c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
652c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
653c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
654e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    CHECK_ARG((pContext->auxiliary && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_MONO) ||
655e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent              ((!pContext->auxiliary) && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO));
656e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    CHECK_ARG(pConfig->outputCfg.channels == AUDIO_CHANNEL_OUT_STEREO);
657c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
658c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent              || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
65994a1ee822686e920a33e312f4032f991731aea07rago    CHECK_ARG(pConfig->inputCfg.format == EFFECT_BUFFER_FORMAT);
6603d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tReverb_setConfig calling memcpy");
661a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    pContext->config = *pConfig;
662c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
6632d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent
664c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (pConfig->inputCfg.samplingRate) {
665c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    case 8000:
666c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        SampleRate = LVM_FS_8000;
667c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        break;
668c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    case 16000:
669c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        SampleRate = LVM_FS_16000;
670c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        break;
671c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    case 22050:
672c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        SampleRate = LVM_FS_22050;
673c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        break;
674c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    case 32000:
675c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        SampleRate = LVM_FS_32000;
676c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        break;
677c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    case 44100:
678c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        SampleRate = LVM_FS_44100;
679c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        break;
680c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    case 48000:
681c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        SampleRate = LVM_FS_48000;
682c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        break;
683d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#if defined(BUILD_FLOAT) && defined(HIGHER_FS)
684d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri    case 96000:
685d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri        SampleRate = LVM_FS_96000;
686d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri        break;
687d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri    case 192000:
688d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri        SampleRate = LVM_FS_192000;
689d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri        break;
690d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri#endif
691c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    default:
6923d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        ALOGV("\rReverb_setConfig invalid sampling rate %d", pConfig->inputCfg.samplingRate);
693c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
694c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
695c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
6965875516ea11f77438f2ed23334fc490a706edd56Eric Laurent    if (pContext->SampleRate != SampleRate) {
697c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
698c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LVREV_ControlParams_st    ActiveParams;
699c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LVREV_ReturnStatus_en     LvmStatus = LVREV_SUCCESS;
700c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
7013d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        //ALOGV("\tReverb_setConfig change sampling rate to %d", SampleRate);
702c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
703c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        /* Get the current settings */
704c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LvmStatus = LVREV_GetControlParameters(pContext->hInstance,
705c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                         &ActiveParams);
706c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
7073d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "Reverb_setConfig")
708c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
709c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
7105875516ea11f77438f2ed23334fc490a706edd56Eric Laurent        ActiveParams.SampleRate = SampleRate;
7115875516ea11f77438f2ed23334fc490a706edd56Eric Laurent
712c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
713c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
7143d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "Reverb_setConfig")
7155875516ea11f77438f2ed23334fc490a706edd56Eric Laurent        if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
7163d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        //ALOGV("\tReverb_setConfig Succesfully called LVREV_SetControlParameters\n");
7175875516ea11f77438f2ed23334fc490a706edd56Eric Laurent        pContext->SampleRate = SampleRate;
718c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }else{
7193d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        //ALOGV("\tReverb_setConfig keep sampling rate at %d", SampleRate);
720c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
721c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
7223d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent    //ALOGV("\tReverb_setConfig End");
723c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return 0;
7243d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent}   /* end Reverb_setConfig */
725c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
7263d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
7273d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Reverb_getConfig()
7283d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
7293d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Purpose: Get input and output audio configuration.
7303d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
7313d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Inputs:
7323d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//  pContext:   effect engine context
7333d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//  pConfig:    pointer to effect_config_t structure holding input and output
7343d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//      configuration parameters
7353d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
7363d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent// Outputs:
7373d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//
7383d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent//----------------------------------------------------------------------------
7393d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
7403d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurentvoid Reverb_getConfig(ReverbContext *pContext, effect_config_t *pConfig)
7413d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent{
742a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pConfig = pContext->config;
7433d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent}   /* end Reverb_getConfig */
744c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
745c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
746c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Reverb_init()
747c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
748c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose: Initialize engine with default configuration
749c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
750c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
751c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
752c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
753c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Outputs:
754c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
755c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
756c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
757c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Reverb_init(ReverbContext *pContext){
7583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tReverb_init start");
759c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
760c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CHECK_ARG(pContext != NULL);
761c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
762c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (pContext->hInstance != NULL){
763c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        Reverb_free(pContext);
764c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
765c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
766c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.inputCfg.accessMode                    = EFFECT_BUFFER_ACCESS_READ;
76797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if (pContext->auxiliary) {
768e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        pContext->config.inputCfg.channels                  = AUDIO_CHANNEL_OUT_MONO;
76997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    } else {
770e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        pContext->config.inputCfg.channels                  = AUDIO_CHANNEL_OUT_STEREO;
77197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    }
77294a1ee822686e920a33e312f4032f991731aea07rago    pContext->config.inputCfg.format                        = EFFECT_BUFFER_FORMAT;
773c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.inputCfg.samplingRate                  = 44100;
774c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.inputCfg.bufferProvider.getBuffer      = NULL;
775c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.inputCfg.bufferProvider.releaseBuffer  = NULL;
776c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.inputCfg.bufferProvider.cookie         = NULL;
777c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.inputCfg.mask                          = EFFECT_CONFIG_ALL;
778c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.outputCfg.accessMode                   = EFFECT_BUFFER_ACCESS_ACCUMULATE;
779e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    pContext->config.outputCfg.channels                     = AUDIO_CHANNEL_OUT_STEREO;
78094a1ee822686e920a33e312f4032f991731aea07rago    pContext->config.outputCfg.format                       = EFFECT_BUFFER_FORMAT;
781c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.outputCfg.samplingRate                 = 44100;
782c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.outputCfg.bufferProvider.getBuffer     = NULL;
783c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
784c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.outputCfg.bufferProvider.cookie        = NULL;
785c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->config.outputCfg.mask                         = EFFECT_CONFIG_ALL;
786c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
787e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    pContext->leftVolume = REVERB_UNIT_VOLUME;
788e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    pContext->rightVolume = REVERB_UNIT_VOLUME;
789e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    pContext->prevLeftVolume = REVERB_UNIT_VOLUME;
790e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    pContext->prevRightVolume = REVERB_UNIT_VOLUME;
791e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    pContext->volumeMode = REVERB_VOLUME_FLAT;
792e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
793c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;        /* Function call status */
794c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    params;                         /* Control Parameters */
795c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_InstanceParams_st   InstParams;                     /* Instance parameters */
796c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_MemoryTable_st      MemTab;                         /* Memory allocation table */
797c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    bool                      bMallocFailure = LVM_FALSE;
798c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
799c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Set the capabilities */
800c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    InstParams.MaxBlockSize  = MAX_CALL_SIZE;
8015185b0138aaeffeecc93b958cb9cd9821f260fafEric Laurent    InstParams.SourceFormat  = LVM_STEREO;          // Max format, could be mono during process
802c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    InstParams.NumDelays     = LVREV_DELAYLINES_4;
803c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
804c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Allocate memory, forcing alignment */
805c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetMemoryTable(LVM_NULL,
806c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                  &MemTab,
807c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                  &InstParams);
808c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
809c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetMemoryTable", "Reverb_init")
810c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
811c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
8123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
813c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
814c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Allocate memory */
815c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
816c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if (MemTab.Region[i].Size != 0){
817c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
818c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
819c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
8207b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLVREV_ERROR :Reverb_init CreateInstance Failed to allocate %" PRIu32
8217b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                        " bytes for region %u\n", MemTab.Region[i].Size, i );
822c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                bMallocFailure = LVM_TRUE;
823c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }else{
8247b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tReverb_init CreateInstance allocate %" PRIu32
8257b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                        " bytes for region %u at %p\n",
826c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
827c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
828c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
829c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
830c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
831c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* If one or more of the memory regions failed to allocate, free the regions that were
832c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent     * succesfully allocated and return with an error
833c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent     */
834c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(bMallocFailure == LVM_TRUE){
835c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
836c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (MemTab.Region[i].pBaseAddress == LVM_NULL){
8377b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLVM_ERROR :Reverb_init CreateInstance Failed to allocate %" PRIu32
8387b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                        " bytes for region %u - Not freeing\n", MemTab.Region[i].Size, i );
839c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }else{
8407b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                ALOGV("\tLVM_ERROR :Reverb_init CreateInstance Failed: but allocated %" PRIu32
8417b6c7b89241397261d52602cbeaa559962efbfecMark Salyzyn                        " bytes for region %u at %p- free\n",
842d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent                        MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
843c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                free(MemTab.Region[i].pBaseAddress);
844c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
845c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        }
846c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
847c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
8483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tReverb_init CreateInstance Succesfully malloc'd memory\n");
849c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
850c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Initialise */
851c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->hInstance = LVM_NULL;
852c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
853c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Init sets the instance handle */
854c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetInstanceHandle(&pContext->hInstance,
855c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                        &MemTab,
856c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                        &InstParams);
857c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
858c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "Reverb_init")
859c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
860c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
8613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tReverb_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
862c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
863c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Set the initial process parameters */
864c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* General parameters */
865c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    params.OperatingMode  = LVM_MODE_ON;
866c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    params.SampleRate     = LVM_FS_44100;
8675875516ea11f77438f2ed23334fc490a706edd56Eric Laurent    pContext->SampleRate  = LVM_FS_44100;
8685185b0138aaeffeecc93b958cb9cd9821f260fafEric Laurent
869e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if(pContext->config.inputCfg.channels == AUDIO_CHANNEL_OUT_MONO){
8705185b0138aaeffeecc93b958cb9cd9821f260fafEric Laurent        params.SourceFormat   = LVM_MONO;
8715185b0138aaeffeecc93b958cb9cd9821f260fafEric Laurent    } else {
8725185b0138aaeffeecc93b958cb9cd9821f260fafEric Laurent        params.SourceFormat   = LVM_STEREO;
8735185b0138aaeffeecc93b958cb9cd9821f260fafEric Laurent    }
874c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
875c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Reverb parameters */
876c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    params.Level          = 0;
877c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    params.LPF            = 23999;
87897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    params.HPF            = 50;
87997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    params.T60            = 1490;
88097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    params.Density        = 100;
88197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    params.Damping        = 21;
88297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    params.RoomSize       = 100;
883c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
8842d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    pContext->SamplesToExitCount = (params.T60 * pContext->config.inputCfg.samplingRate)/1000;
8852d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent
886c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Saved strength is used to return the exact strength that was used in the set to the get
887c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent     * because we map the original strength range of 0:1000 to 1:15, and this will avoid
888c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent     * quantisation like effect when returning
889c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent     */
890c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedRoomLevel    = -6000;
891c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedHfLevel      = 0;
892c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->bEnabled          = LVM_FALSE;
893c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedDecayTime    = params.T60;
894d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    pContext->SavedDecayHfRatio = params.Damping*20;
895c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedDensity      = params.RoomSize*10;
896c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedDiffusion    = params.Density*10;
897c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedReverbLevel  = -6000;
898c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
899c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Activate the initial settings */
900c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_SetControlParameters(pContext->hInstance,
901c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                         &params);
902c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
903c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "Reverb_init")
904c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
905c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
9063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tReverb_init CreateInstance Succesfully called LVREV_SetControlParameters\n");
9073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    ALOGV("\tReverb_init End");
908c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return 0;
909c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}   /* end Reverb_init */
910c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
911c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
912c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbConvertLevel()
913c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
914c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
915c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Convert level from OpenSL ES format to LVM format
916c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
917c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
918c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  level       level to be applied
919c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
920c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
921c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
922c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint16_t ReverbConvertLevel(int16_t level){
923c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    static int16_t LevelArray[101] =
924c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    {
925c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -12000, -4000,  -3398,  -3046,  -2796,  -2603,  -2444,  -2310,  -2194,  -2092,
926c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -2000,  -1918,  -1842,  -1773,  -1708,  -1648,  -1592,  -1540,  -1490,  -1443,
927c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -1398,  -1356,  -1316,  -1277,  -1240,  -1205,  -1171,  -1138,  -1106,  -1076,
928c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -1046,  -1018,  -990,   -963,   -938,   -912,   -888,   -864,   -841,   -818,
929c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -796,   -775,   -754,   -734,   -714,   -694,   -675,   -656,   -638,   -620,
930c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -603,   -585,   -568,   -552,   -536,   -520,   -504,   -489,   -474,   -459,
931c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -444,   -430,   -416,   -402,   -388,   -375,   -361,   -348,   -335,   -323,
932c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -310,   -298,   -286,   -274,   -262,   -250,   -239,   -228,   -216,   -205,
933c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -194,   -184,   -173,   -162,   -152,   -142,   -132,   -121,   -112,   -102,
934c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       -92,    -82,    -73,    -64,    -54,    -45,    -36,    -27,    -18,    -9,
935c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       0
936c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    };
937c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t i;
938c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
939c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for(i = 0; i < 101; i++)
940c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    {
941c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent       if(level <= LevelArray[i])
942c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent           break;
943c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
944c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return i;
945c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
946c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
947c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
948c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbConvertHFLevel()
949c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
950c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
951c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Convert level from OpenSL ES format to LVM format
952c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
953c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
954c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  level       level to be applied
955c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
956c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
957c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
958c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint16_t ReverbConvertHfLevel(int16_t Hflevel){
959c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t i;
960c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
961c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    static LPFPair_t LPFArray[97] =
962c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    {   // Limit range to 50 for LVREV parameter range
963c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-10000, 50}, { -5000, 50 }, { -4000, 50},  { -3000, 158}, { -2000, 502},
964c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-1000, 1666},{ -900, 1897}, { -800, 2169}, { -700, 2496}, { -600, 2895},
965c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-500, 3400}, { -400, 4066}, { -300, 5011}, { -200, 6537}, { -100,  9826},
966c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-99, 9881 }, { -98, 9937 }, { -97, 9994 }, { -96, 10052}, { -95, 10111},
967c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-94, 10171}, { -93, 10231}, { -92, 10293}, { -91, 10356}, { -90, 10419},
968c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-89, 10484}, { -88, 10549}, { -87, 10616}, { -86, 10684}, { -85, 10753},
969c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-84, 10823}, { -83, 10895}, { -82, 10968}, { -81, 11042}, { -80, 11117},
970c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-79, 11194}, { -78, 11272}, { -77, 11352}, { -76, 11433}, { -75, 11516},
971c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-74, 11600}, { -73, 11686}, { -72, 11774}, { -71, 11864}, { -70, 11955},
972c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-69, 12049}, { -68, 12144}, { -67, 12242}, { -66, 12341}, { -65, 12443},
973c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-64, 12548}, { -63, 12654}, { -62, 12763}, { -61, 12875}, { -60, 12990},
974c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-59, 13107}, { -58, 13227}, { -57, 13351}, { -56, 13477}, { -55, 13607},
975c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-54, 13741}, { -53, 13878}, { -52, 14019}, { -51, 14164}, { -50, 14313},
976c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-49, 14467}, { -48, 14626}, { -47, 14789}, { -46, 14958}, { -45, 15132},
977c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-44, 15312}, { -43, 15498}, { -42, 15691}, { -41, 15890}, { -40, 16097},
978c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-39, 16311}, { -38, 16534}, { -37, 16766}, { -36, 17007}, { -35, 17259},
979c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-34, 17521}, { -33, 17795}, { -32, 18081}, { -31, 18381}, { -30, 18696},
980c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-29, 19027}, { -28, 19375}, { -27, 19742}, { -26, 20129}, { -25, 20540},
981c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-24, 20976}, { -23, 21439}, { -22, 21934}, { -21, 22463}, { -20, 23031},
982c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        {-19, 23643}, { -18, 23999}
983c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    };
984c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
985c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    for(i = 0; i < 96; i++)
986c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    {
987c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        if(Hflevel <= LPFArray[i].Room_HF)
988c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
989c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
990c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return LPFArray[i].LPF;
991c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
992c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
993c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
994c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbSetRoomHfLevel()
995c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
996c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
997c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Apply the HF level to the Reverb. Must first be converted to LVM format
998c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
999c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1000c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1001c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  level       level to be applied
1002c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1003c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1004c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1005c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid ReverbSetRoomHfLevel(ReverbContext *pContext, int16_t level){
10063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomHfLevel start (%d)", level);
1007c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1008c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1009c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1010c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1011c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1012c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1013c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetRoomHfLevel")
10143856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomHfLevel Succesfully returned from LVM_GetControlParameters\n");
10153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomHfLevel() just Got -> %d\n", ActiveParams.LPF);
1016c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1017c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    ActiveParams.LPF = ReverbConvertHfLevel(level);
1018c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1019c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Activate the initial settings */
1020c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1021c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetRoomHfLevel")
10223856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomhfLevel() just Set -> %d\n", ActiveParams.LPF);
1023c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedHfLevel = level;
10243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetHfRoomLevel end.. saving %d", pContext->SavedHfLevel);
1025c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return;
1026c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1027c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1028c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1029c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbGetRoomHfLevel()
1030c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1031c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1032c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Get the level applied to the Revervb. Must first be converted to LVM format
1033c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1034c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1035c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1036c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1037c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1038c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1039c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint16_t ReverbGetRoomHfLevel(ReverbContext *pContext){
1040c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t level;
10413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomHfLevel start, saved level is %d", pContext->SavedHfLevel);
1042c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1043c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1044c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1045c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1046c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1047c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1048c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetRoomHfLevel")
10493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomHfLevel Succesfully returned from LVM_GetControlParameters\n");
10503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomHfLevel() just Got -> %d\n", ActiveParams.LPF);
1051c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1052c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    level = ReverbConvertHfLevel(pContext->SavedHfLevel);
1053c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
10543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomHfLevel() ActiveParams.LPFL %d, pContext->SavedHfLevel: %d, "
1055c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    //     "converted level: %d\n", ActiveParams.LPF, pContext->SavedHfLevel, level);
1056c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1057d7d013446a64c6de9f0f2dfe098a721b140e0b48Ramesh Katuri    if((int16_t)ActiveParams.LPF != level){
10583856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetRoomHfLevel() has wrong level -> %d %d\n",
1059c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent               ActiveParams.Level, level);
1060c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1061c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
10623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomHfLevel end");
1063c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return pContext->SavedHfLevel;
1064c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1065c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1066c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1067c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbSetReverbLevel()
1068c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1069c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1070c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Apply the level to the Reverb. Must first be converted to LVM format
1071c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1072c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1073c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1074c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  level       level to be applied
1075c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1076c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1077c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1078c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid ReverbSetReverbLevel(ReverbContext *pContext, int16_t level){
10793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\n\tReverbSetReverbLevel start (%d)", level);
1080c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1081c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1082c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1083c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_INT32                 CombinedLevel;             // Sum of room and reverb level controls
1084c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1085c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1086c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1087c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetReverbLevel")
10883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetReverbLevel Succesfully returned from LVM_GetControlParameters\n");
10893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetReverbLevel just Got -> %d\n", ActiveParams.Level);
1090c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1091c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // needs to subtract max levels for both RoomLevel and ReverbLevel
1092c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CombinedLevel = (level + pContext->SavedRoomLevel)-LVREV_MAX_REVERB_LEVEL;
10933856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetReverbLevel() CombinedLevel is %d = %d + %d\n",
1094c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    //      CombinedLevel, level, pContext->SavedRoomLevel);
1095c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1096c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    ActiveParams.Level = ReverbConvertLevel(CombinedLevel);
1097c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
10983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetReverbLevel() Trying to set -> %d\n", ActiveParams.Level);
1099c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1100c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Activate the initial settings */
1101c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1102c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetReverbLevel")
11033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetReverbLevel() just Set -> %d\n", ActiveParams.Level);
1104c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1105c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedReverbLevel = level;
11063856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetReverbLevel end pContext->SavedReverbLevel is %d\n\n",
1107c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    //     pContext->SavedReverbLevel);
1108c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return;
1109c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1110c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1111c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1112c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbGetReverbLevel()
1113c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1114c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1115c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Get the level applied to the Revervb. Must first be converted to LVM format
1116c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1117c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1118c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1119c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1120c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1121c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1122c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint16_t ReverbGetReverbLevel(ReverbContext *pContext){
1123c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t level;
11243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetReverbLevel start");
1125c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1126c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1127c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1128c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_INT32                 CombinedLevel;             // Sum of room and reverb level controls
1129c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1130c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1131c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1132c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetReverbLevel")
11333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetReverbLevel Succesfully returned from LVM_GetControlParameters\n");
11343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetReverbLevel() just Got -> %d\n", ActiveParams.Level);
1135c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1136c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // needs to subtract max levels for both RoomLevel and ReverbLevel
1137c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CombinedLevel = (pContext->SavedReverbLevel + pContext->SavedRoomLevel)-LVREV_MAX_REVERB_LEVEL;
1138c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
11393856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetReverbLevel() CombinedLevel is %d = %d + %d\n",
1140c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    //CombinedLevel, pContext->SavedReverbLevel, pContext->SavedRoomLevel);
1141c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    level = ReverbConvertLevel(CombinedLevel);
1142c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
11433856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetReverbLevel(): ActiveParams.Level: %d, pContext->SavedReverbLevel: %d, "
1144c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    //"pContext->SavedRoomLevel: %d, CombinedLevel: %d, converted level: %d\n",
1145c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    //ActiveParams.Level, pContext->SavedReverbLevel,pContext->SavedRoomLevel, CombinedLevel,level);
1146c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1147c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(ActiveParams.Level != level){
11483856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetReverbLevel() has wrong level -> %d %d\n",
1149c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                ActiveParams.Level, level);
1150c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1151c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
11523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetReverbLevel end\n");
1153c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1154c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return pContext->SavedReverbLevel;
1155c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1156c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1157c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1158c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbSetRoomLevel()
1159c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1160c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1161c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Apply the level to the Reverb. Must first be converted to LVM format
1162c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1163c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1164c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1165c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  level       level to be applied
1166c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1167c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1168c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1169c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid ReverbSetRoomLevel(ReverbContext *pContext, int16_t level){
11703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomLevel start (%d)", level);
1171c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1172c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1173c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1174c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_INT32                 CombinedLevel;             // Sum of room and reverb level controls
1175c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1176c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1177c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1178c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetRoomLevel")
11793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomLevel Succesfully returned from LVM_GetControlParameters\n");
11803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomLevel() just Got -> %d\n", ActiveParams.Level);
1181c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1182c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // needs to subtract max levels for both RoomLevel and ReverbLevel
1183c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CombinedLevel = (level + pContext->SavedReverbLevel)-LVREV_MAX_REVERB_LEVEL;
1184c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    ActiveParams.Level = ReverbConvertLevel(CombinedLevel);
1185c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1186c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Activate the initial settings */
1187c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1188c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetRoomLevel")
11893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomLevel() just Set -> %d\n", ActiveParams.Level);
1190c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1191c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedRoomLevel = level;
11923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetRoomLevel end");
1193c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return;
1194c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1195c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1196c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1197c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbGetRoomLevel()
1198c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1199c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1200c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Get the level applied to the Revervb. Must first be converted to LVM format
1201c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1202c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1203c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1204c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1205c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1206c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1207c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint16_t ReverbGetRoomLevel(ReverbContext *pContext){
1208c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t level;
12093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomLevel start");
1210c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1211c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1212c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1213c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_INT32                 CombinedLevel;             // Sum of room and reverb level controls
1214c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1215c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1216c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1217c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetRoomLevel")
12183856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomLevel Succesfully returned from LVM_GetControlParameters\n");
12193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomLevel() just Got -> %d\n", ActiveParams.Level);
1220c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1221c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    // needs to subtract max levels for both RoomLevel and ReverbLevel
1222c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    CombinedLevel = (pContext->SavedRoomLevel + pContext->SavedReverbLevel-LVREV_MAX_REVERB_LEVEL);
1223c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    level = ReverbConvertLevel(CombinedLevel);
1224c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
12253856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomLevel, Level = %d, pContext->SavedRoomLevel = %d, "
1226c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    //     "pContext->SavedReverbLevel = %d, CombinedLevel = %d, level = %d",
12272d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    //     ActiveParams.Level, pContext->SavedRoomLevel,
12282d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    //     pContext->SavedReverbLevel, CombinedLevel, level);
1229c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1230c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(ActiveParams.Level != level){
12313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetRoomLevel() has wrong level -> %d %d\n",
1232c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent              ActiveParams.Level, level);
1233c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1234c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
12353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetRoomLevel end");
1236c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return pContext->SavedRoomLevel;
1237c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1238c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1239c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1240c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbSetDecayTime()
1241c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1242c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1243c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Apply the decay time to the Reverb.
1244c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1245c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1246c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1247c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  time        decay to be applied
1248c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1249c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1250c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1251c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid ReverbSetDecayTime(ReverbContext *pContext, uint32_t time){
12523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayTime start (%d)", time);
1253c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1254c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1255c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1256c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1257c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1258c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1259c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDecayTime")
12603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayTime Succesfully returned from LVM_GetControlParameters\n");
12613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayTime() just Got -> %d\n", ActiveParams.T60);
1262c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1263c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (time <= LVREV_MAX_T60) {
126454c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent        ActiveParams.T60 = (LVM_UINT16)time;
1265c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1266c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    else {
1267c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        ActiveParams.T60 = LVREV_MAX_T60;
1268c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1269c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1270c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Activate the initial settings */
1271c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1272c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDecayTime")
12733856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayTime() just Set -> %d\n", ActiveParams.T60);
1274c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
12752d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    pContext->SamplesToExitCount = (ActiveParams.T60 * pContext->config.inputCfg.samplingRate)/1000;
12763856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayTime() just Set SamplesToExitCount-> %d\n",pContext->SamplesToExitCount);
127754c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent    pContext->SavedDecayTime = (int16_t)time;
12783856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayTime end");
1279c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return;
1280c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1281c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1282c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1283c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbGetDecayTime()
1284c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1285c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1286c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Get the decay time applied to the Revervb.
1287c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1288c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1289c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1290c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1291c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1292c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
129354c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurentuint32_t ReverbGetDecayTime(ReverbContext *pContext){
12943856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDecayTime start");
1295c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1296c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1297c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1298c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1299c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1300c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1301c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDecayTime")
13023856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDecayTime Succesfully returned from LVM_GetControlParameters\n");
13033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDecayTime() just Got -> %d\n", ActiveParams.T60);
1304c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1305c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(ActiveParams.T60 != pContext->SavedDecayTime){
1306c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        // This will fail if the decay time is set to more than 7000
13073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : ReverbGetDecayTime() has wrong level -> %d %d\n",
1308c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent         ActiveParams.T60, pContext->SavedDecayTime);
1309c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1310c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
13113856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDecayTime end");
131254c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent    return (uint32_t)ActiveParams.T60;
1313c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1314c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1315c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1316c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbSetDecayHfRatio()
1317c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1318c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1319c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Apply the HF decay ratio to the Reverb.
1320c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1321c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1322c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1323c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  ratio       ratio to be applied
1324c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1325c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1326c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1327c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid ReverbSetDecayHfRatio(ReverbContext *pContext, int16_t ratio){
13283856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayHfRatioe start (%d)", ratio);
1329c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1330c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1331c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;   /* Function call status */
1332c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1333c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1334c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1335c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDecayHfRatio")
13363856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayHfRatio Succesfully returned from LVM_GetControlParameters\n");
13373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayHfRatio() just Got -> %d\n", ActiveParams.Damping);
1338c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1339d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    ActiveParams.Damping = (LVM_INT16)(ratio/20);
1340c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1341c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Activate the initial settings */
1342c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1343c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDecayHfRatio")
13443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayHfRatio() just Set -> %d\n", ActiveParams.Damping);
1345c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1346c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedDecayHfRatio = ratio;
13473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDecayHfRatio end");
1348c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return;
1349c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1350c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1351c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1352c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbGetDecayHfRatio()
1353c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1354c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1355c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Get the HF decay ratio applied to the Revervb.
1356c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1357c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1358c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1359c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1360c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1361c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1362c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint32_t ReverbGetDecayHfRatio(ReverbContext *pContext){
13633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDecayHfRatio start");
1364c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1365c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1366c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;   /* Function call status */
1367c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1368c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1369c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1370c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDecayHfRatio")
13713856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDecayHfRatio Succesfully returned from LVM_GetControlParameters\n");
13723856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDecayHfRatio() just Got -> %d\n", ActiveParams.Damping);
1373c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1374d918324d44aa48b3b064ea9b87d0c520c38f15a9Eric Laurent    if(ActiveParams.Damping != (LVM_INT16)(pContext->SavedDecayHfRatio / 20)){
13753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : ReverbGetDecayHfRatio() has wrong level -> %d %d\n",
1376c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent         ActiveParams.Damping, pContext->SavedDecayHfRatio);
1377c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1378c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
13793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDecayHfRatio end");
1380c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return pContext->SavedDecayHfRatio;
1381c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1382c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1383c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1384c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbSetDiffusion()
1385c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1386c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1387c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Apply the diffusion to the Reverb.
1388c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1389c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1390c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1391c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  level        decay to be applied
1392c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1393c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1394c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1395c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid ReverbSetDiffusion(ReverbContext *pContext, int16_t level){
13963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDiffusion start (%d)", level);
1397c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1398c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1399c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1400c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1401c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1402c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1403c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDiffusion")
14043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDiffusion Succesfully returned from LVM_GetControlParameters\n");
14053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDiffusion() just Got -> %d\n", ActiveParams.Density);
1406c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1407c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    ActiveParams.Density = (LVM_INT16)(level/10);
1408c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1409c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Activate the initial settings */
1410c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1411c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDiffusion")
14123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDiffusion() just Set -> %d\n", ActiveParams.Density);
1413c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1414c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedDiffusion = level;
14153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDiffusion end");
1416c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return;
1417c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1418c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1419c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1420c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbGetDiffusion()
1421c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1422c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1423c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Get the decay time applied to the Revervb.
1424c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1425c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1426c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1427c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1428c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1429c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1430c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint32_t ReverbGetDiffusion(ReverbContext *pContext){
14313856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDiffusion start");
1432c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1433c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1434c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1435c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_INT16                 Temp;
1436c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1437c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1438c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1439c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDiffusion")
14403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDiffusion Succesfully returned from LVM_GetControlParameters\n");
14413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDiffusion just Got -> %d\n", ActiveParams.Density);
1442c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1443c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    Temp = (LVM_INT16)(pContext->SavedDiffusion/10);
1444c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1445c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(ActiveParams.Density != Temp){
14463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : ReverbGetDiffusion invalid value %d %d", Temp, ActiveParams.Density);
1447c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1448c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
14493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDiffusion end");
1450c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return pContext->SavedDiffusion;
1451c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1452c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1453c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1454c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbSetDensity()
1455c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1456c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1457c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Apply the density level the Reverb.
1458c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1459c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1460c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1461c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  level        decay to be applied
1462c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1463c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1464c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1465c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentvoid ReverbSetDensity(ReverbContext *pContext, int16_t level){
14663856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDensity start (%d)", level);
1467c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1468c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1469c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1470c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1471c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1472c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1473c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDensity")
14743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDensity Succesfully returned from LVM_GetControlParameters\n");
14753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDensity just Got -> %d\n", ActiveParams.RoomSize);
1476c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1477c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    ActiveParams.RoomSize = (LVM_INT16)(((level * 99) / 1000) + 1);
1478c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1479c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Activate the initial settings */
1480c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1481c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDensity")
14823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDensity just Set -> %d\n", ActiveParams.RoomSize);
1483c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1484c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pContext->SavedDensity = level;
14853856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbSetDensity end");
1486c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return;
1487c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1488c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1489c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1490c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// ReverbGetDensity()
1491c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1492c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1493c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Get the density level applied to the Revervb.
1494c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1495c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1496c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext:   effect engine context
1497c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1498c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1499c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1500c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint32_t ReverbGetDensity(ReverbContext *pContext){
15013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDensity start");
1502c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1503c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
1504c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
1505c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_INT16                 Temp;
1506c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Get the current settings */
1507c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1508c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDensity")
15093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDensity Succesfully returned from LVM_GetControlParameters\n");
15103856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDensity() just Got -> %d\n", ActiveParams.RoomSize);
1511c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1512c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1513c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    Temp = (LVM_INT16)(((pContext->SavedDensity * 99) / 1000) + 1);
1514c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1515c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if(Temp != ActiveParams.RoomSize){
15163856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : ReverbGetDensity invalid value %d %d", Temp, ActiveParams.RoomSize);
1517c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1518c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
15193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverbGetDensity end");
1520c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return pContext->SavedDensity;
1521c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}
1522c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1523c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
152497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// Reverb_LoadPreset()
152597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//----------------------------------------------------------------------------
152697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// Purpose:
152797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// Load a the next preset
152897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//
152997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// Inputs:
153097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//  pContext         - handle to instance data
153197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//
153297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// Outputs:
153397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//
153497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent// Side Effects:
153597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//
153697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//----------------------------------------------------------------------------
153797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurentint Reverb_LoadPreset(ReverbContext   *pContext)
153897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent{
153997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    //TODO: add reflections delay, level and reverb delay when early reflections are
154097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    // implemented
154197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    pContext->curPreset = pContext->nextPreset;
154297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
154397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if (pContext->curPreset != REVERB_PRESET_NONE) {
154497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        const t_reverb_settings *preset = &sReverbPresets[pContext->curPreset];
154597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        ReverbSetRoomLevel(pContext, preset->roomLevel);
154697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        ReverbSetRoomHfLevel(pContext, preset->roomHFLevel);
154797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        ReverbSetDecayTime(pContext, preset->decayTime);
154897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        ReverbSetDecayHfRatio(pContext, preset->decayHFRatio);
154997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        //reflectionsLevel
155097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        //reflectionsDelay
155197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        ReverbSetReverbLevel(pContext, preset->reverbLevel);
155297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        // reverbDelay
155397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        ReverbSetDiffusion(pContext, preset->diffusion);
155497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        ReverbSetDensity(pContext, preset->density);
155597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    }
155697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
155797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    return 0;
155897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent}
155997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
156097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
156197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent//----------------------------------------------------------------------------
1562c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Reverb_getParameter()
1563c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1564c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1565c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Get a Reverb parameter
1566c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1567c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1568c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext         - handle to instance data
1569c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pParam           - pointer to parameter
1570c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pValue           - pointer to variable to hold retrieved value
1571c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pValueSize       - pointer to value size: maximum size as input
1572c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1573c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Outputs:
1574c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  *pValue updated with parameter value
1575c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  *pValueSize updated with actual value size
1576c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1577c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1578c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Side Effects:
1579c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1580c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1581c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1582c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentint Reverb_getParameter(ReverbContext *pContext,
1583c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void          *pParam,
1584b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                        uint32_t      *pValueSize,
1585c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        void          *pValue){
1586c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int status = 0;
1587c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1588c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
1589c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    t_reverb_settings *pProperties;
1590c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
15913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverb_getParameter start");
159297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if (pContext->preset) {
159397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        if (param != REVERB_PARAM_PRESET || *pValueSize < sizeof(uint16_t)) {
159497344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent            return -EINVAL;
159597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        }
159697344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
159797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        *(uint16_t *)pValue = pContext->nextPreset;
15983856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("get REVERB_PARAM_PRESET, preset %d", pContext->nextPreset);
159997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        return 0;
160097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    }
1601c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1602c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
1603c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_ROOM_LEVEL:
1604c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(int16_t)){
16053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize1 %d", *pValueSize);
1606c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1607c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1608c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(int16_t);
1609c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1610c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_ROOM_HF_LEVEL:
1611c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(int16_t)){
16123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize12 %d", *pValueSize);
1613c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1614c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1615c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(int16_t);
1616c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1617c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DECAY_TIME:
1618c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
16193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize3 %d", *pValueSize);
1620c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1621c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1622c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(uint32_t);
1623c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1624c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DECAY_HF_RATIO:
1625c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(int16_t)){
16263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize4 %d", *pValueSize);
1627c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1628c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1629c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(int16_t);
1630c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1631c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REFLECTIONS_LEVEL:
1632c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(int16_t)){
16333856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize5 %d", *pValueSize);
1634c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1635c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1636c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(int16_t);
1637c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1638c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REFLECTIONS_DELAY:
1639c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
16403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize6 %d", *pValueSize);
1641c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1642c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1643c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(uint32_t);
1644c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1645c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REVERB_LEVEL:
1646c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(int16_t)){
16473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize7 %d", *pValueSize);
1648c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1649c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1650c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(int16_t);
1651c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1652c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REVERB_DELAY:
1653c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(uint32_t)){
16543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize8 %d", *pValueSize);
1655c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1656c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1657c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(uint32_t);
1658c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1659c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DIFFUSION:
1660c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(int16_t)){
16613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize9 %d", *pValueSize);
1662c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1663c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1664c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(int16_t);
1665c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1666c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DENSITY:
1667c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(int16_t)){
16683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize10 %d", *pValueSize);
1669c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1670c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1671c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(int16_t);
1672c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1673c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_PROPERTIES:
1674c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (*pValueSize != sizeof(t_reverb_settings)){
16753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize11 %d", *pValueSize);
1676c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
1677c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
1678c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *pValueSize = sizeof(t_reverb_settings);
1679c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1680c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1681c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        default:
16823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid param %d", param);
1683c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            return -EINVAL;
1684c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1685c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1686c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    pProperties = (t_reverb_settings *) pValue;
1687c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1688c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
1689c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_PROPERTIES:
1690c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->roomLevel = ReverbGetRoomLevel(pContext);
1691c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->roomHFLevel = ReverbGetRoomHfLevel(pContext);
1692c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->decayTime = ReverbGetDecayTime(pContext);
1693c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->decayHFRatio = ReverbGetDecayHfRatio(pContext);
1694c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->reflectionsLevel = 0;
1695c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->reflectionsDelay = 0;
1696c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->reverbDelay = 0;
1697c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->reverbLevel = ReverbGetReverbLevel(pContext);
1698c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->diffusion = ReverbGetDiffusion(pContext);
1699c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties->density = ReverbGetDensity(pContext);
1700c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
17013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is roomLevel        %d",
1702c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->roomLevel);
17033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is roomHFLevel      %d",
1704c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->roomHFLevel);
17053856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is decayTime        %d",
1706c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->decayTime);
17073856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is decayHFRatio     %d",
1708c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->decayHFRatio);
17093856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reflectionsLevel %d",
1710c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->reflectionsLevel);
17113856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reflectionsDelay %d",
1712c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->reflectionsDelay);
17133856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reverbDelay      %d",
1714c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->reverbDelay);
17153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reverbLevel      %d",
1716c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->reverbLevel);
17173856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is diffusion        %d",
1718c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->diffusion);
17193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is density          %d",
1720c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                pProperties->density);
1721c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1722c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1723c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_ROOM_LEVEL:
1724c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int16_t *)pValue = ReverbGetRoomLevel(pContext);
1725c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
17263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_getParameter() REVERB_PARAM_ROOM_LEVEL Value is %d",
1727c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int16_t *)pValue);
1728c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1729c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_ROOM_HF_LEVEL:
1730c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int16_t *)pValue = ReverbGetRoomHfLevel(pContext);
1731c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
17323856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_getParameter() REVERB_PARAM_ROOM_HF_LEVEL Value is %d",
1733c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int16_t *)pValue);
1734c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1735c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DECAY_TIME:
173654c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent            *(uint32_t *)pValue = ReverbGetDecayTime(pContext);
1737c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
17383856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_TIME Value is %d",
1739c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int32_t *)pValue);
1740c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1741c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DECAY_HF_RATIO:
1742c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int16_t *)pValue = ReverbGetDecayHfRatio(pContext);
1743c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
17443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_HF_RATION Value is %d",
1745c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int16_t *)pValue);
1746c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1747c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REVERB_LEVEL:
1748c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent             *(int16_t *)pValue = ReverbGetReverbLevel(pContext);
1749c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
17503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_getParameter() REVERB_PARAM_REVERB_LEVEL Value is %d",
1751c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int16_t *)pValue);
1752c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1753c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DIFFUSION:
1754c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int16_t *)pValue = ReverbGetDiffusion(pContext);
1755c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
17563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_DIFFUSION Value is %d",
1757c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int16_t *)pValue);
1758c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1759c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DENSITY:
1760c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(uint16_t *)pValue = 0;
1761c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int16_t *)pValue = ReverbGetDensity(pContext);
17623856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_getParameter() REVERB_PARAM_DENSITY Value is %d",
1763c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(uint32_t *)pValue);
1764c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1765c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REFLECTIONS_LEVEL:
1766c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(uint16_t *)pValue = 0;
1767c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REFLECTIONS_DELAY:
1768c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(uint32_t *)pValue = 0;
1769c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REVERB_DELAY:
1770c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(uint32_t *)pValue = 0;
1771c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1772c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1773c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        default:
17743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid param %d", param);
1775c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            status = -EINVAL;
1776c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1777c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1778c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
17793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverb_getParameter end");
1780c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return status;
1781c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent} /* end Reverb_getParameter */
1782c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1783c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1784c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Reverb_setParameter()
1785c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1786c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Purpose:
1787c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Set a Reverb parameter
1788c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1789c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Inputs:
1790c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pContext         - handle to instance data
1791c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pParam           - pointer to parameter
1792c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//  pValue           - pointer to value
1793804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov//  vsize            - value size
1794c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1795c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent// Outputs:
1796c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//
1797c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent//----------------------------------------------------------------------------
1798c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1799804632afcdda6e80945bf27c384757bda50560cbMikhail Naganovint Reverb_setParameter (ReverbContext *pContext, void *pParam, void *pValue, int vsize){
1800c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int status = 0;
1801c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int16_t level;
180254c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent    int16_t ratio;
1803c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    uint32_t time;
1804c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    t_reverb_settings *pProperties;
1805c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t *pParamTemp = (int32_t *)pParam;
1806c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int32_t param = *pParamTemp++;
1807c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
18083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverb_setParameter start");
180997344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    if (pContext->preset) {
181097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        if (param != REVERB_PARAM_PRESET) {
181197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent            return -EINVAL;
181297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        }
1813ee804dfa15cc2d34e5d67a9b437cd023349d633bMikhail Naganov        if (vsize < (int)sizeof(uint16_t)) {
1814ee804dfa15cc2d34e5d67a9b437cd023349d633bMikhail Naganov            android_errorWriteLog(0x534e4554, "67647856");
1815ee804dfa15cc2d34e5d67a9b437cd023349d633bMikhail Naganov            return -EINVAL;
1816ee804dfa15cc2d34e5d67a9b437cd023349d633bMikhail Naganov        }
181797344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent
181897344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        uint16_t preset = *(uint16_t *)pValue;
18193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("set REVERB_PARAM_PRESET, preset %d", preset);
182097344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        if (preset > REVERB_PRESET_LAST) {
182197344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent            return -EINVAL;
182297344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        }
182397344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent        pContext->nextPreset = preset;
182454c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent        return 0;
182597344f1d8e8e95fd07d5deee2ae2492a7e4c24b0Eric Laurent    }
1826c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1827804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    if (vsize < Reverb_paramValueSize(param)) {
1828804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov        android_errorWriteLog(0x534e4554, "63526567");
1829804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov        return -EINVAL;
1830804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    }
1831804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov
1832c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (param){
1833c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_PROPERTIES:
18343856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tReverb_setParameter() REVERB_PARAM_PROPERTIES");
1835c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pProperties = (t_reverb_settings *) pValue;
1836c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetRoomLevel(pContext, pProperties->roomLevel);
1837c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetRoomHfLevel(pContext, pProperties->roomHFLevel);
1838c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetDecayTime(pContext, pProperties->decayTime);
1839c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetDecayHfRatio(pContext, pProperties->decayHFRatio);
1840c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetReverbLevel(pContext, pProperties->reverbLevel);
1841c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetDiffusion(pContext, pProperties->diffusion);
1842c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetDensity(pContext, pProperties->density);
1843c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1844c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_ROOM_LEVEL:
1845c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            level = *(int16_t *)pValue;
18463856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() REVERB_PARAM_ROOM_LEVEL value is %d", level);
18473856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Calling ReverbSetRoomLevel");
1848c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetRoomLevel(pContext, level);
18493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Called ReverbSetRoomLevel");
1850c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent           break;
1851c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_ROOM_HF_LEVEL:
1852c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            level = *(int16_t *)pValue;
18533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() REVERB_PARAM_ROOM_HF_LEVEL value is %d", level);
18543856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Calling ReverbSetRoomHfLevel");
1855c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetRoomHfLevel(pContext, level);
18563856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Called ReverbSetRoomHfLevel");
1857c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent           break;
1858c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DECAY_TIME:
1859c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            time = *(uint32_t *)pValue;
18603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_TIME value is %d", time);
18613856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Calling ReverbSetDecayTime");
1862c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetDecayTime(pContext, time);
18633856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Called ReverbSetDecayTime");
1864c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent           break;
1865c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DECAY_HF_RATIO:
186654c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent            ratio = *(int16_t *)pValue;
18673856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_HF_RATIO value is %d", ratio);
18683856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Calling ReverbSetDecayHfRatio");
186954c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent            ReverbSetDecayHfRatio(pContext, ratio);
18703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Called ReverbSetDecayHfRatio");
1871c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1872c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent         case REVERB_PARAM_REVERB_LEVEL:
1873c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            level = *(int16_t *)pValue;
18743856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() REVERB_PARAM_REVERB_LEVEL value is %d", level);
18753856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Calling ReverbSetReverbLevel");
1876c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            ReverbSetReverbLevel(pContext, level);
18773856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Called ReverbSetReverbLevel");
1878c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent           break;
1879c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DIFFUSION:
188054c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent            ratio = *(int16_t *)pValue;
18813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_DIFFUSION value is %d", ratio);
18823856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Calling ReverbSetDiffusion");
188354c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent            ReverbSetDiffusion(pContext, ratio);
18843856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Called ReverbSetDiffusion");
1885c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1886c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_DENSITY:
188754c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent            ratio = *(int16_t *)pValue;
18883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_DENSITY value is %d", ratio);
18893856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Calling ReverbSetDensity");
189054c38fdcff502ab3502c55dd314a954dd60c0183Eric Laurent            ReverbSetDensity(pContext, ratio);
18913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_setParameter() Called ReverbSetDensity");
1892c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1893c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent           break;
1894c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REFLECTIONS_LEVEL:
1895c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REFLECTIONS_DELAY:
1896c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case REVERB_PARAM_REVERB_DELAY:
1897c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1898c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        default:
18993856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Reverb_setParameter() invalid param %d", param);
1900c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
1901c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1902c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
19033856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverb_setParameter end");
1904c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return status;
1905c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent} /* end Reverb_setParameter */
1906c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1907804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov
1908804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov/**
1909804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov * returns the size in bytes of the value of each environmental reverb parameter
1910804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov */
1911804632afcdda6e80945bf27c384757bda50560cbMikhail Naganovint Reverb_paramValueSize(int32_t param) {
1912804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    switch (param) {
1913804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_ROOM_LEVEL:
1914804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_ROOM_HF_LEVEL:
1915804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_REFLECTIONS_LEVEL:
1916804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_REVERB_LEVEL:
1917804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov        return sizeof(int16_t); // millibel
1918804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_DECAY_TIME:
1919804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_REFLECTIONS_DELAY:
1920804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_REVERB_DELAY:
1921804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov        return sizeof(uint32_t); // milliseconds
1922804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_DECAY_HF_RATIO:
1923804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_DIFFUSION:
1924804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_DENSITY:
1925804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov        return sizeof(int16_t); // permille
1926804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    case REVERB_PARAM_PROPERTIES:
1927804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov        return sizeof(s_reverb_settings); // struct of all reverb properties
1928804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    }
1929804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov    return sizeof(int32_t);
1930804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov}
1931804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov
1932c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent} // namespace
1933c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent} // namespace
1934c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1935e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentextern "C" {
1936c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/* Effect Control Interface Implementation: Process */
1937e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Reverb_process(effect_handle_t   self,
1938c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                 audio_buffer_t         *inBuffer,
1939c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                 audio_buffer_t         *outBuffer){
1940c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    android::ReverbContext * pContext = (android::ReverbContext *) self;
1941c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    int    status = 0;
1942c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1943c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (pContext == NULL){
19443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Reverb_process() ERROR pContext == NULL");
1945c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
1946c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1947c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (inBuffer == NULL  || inBuffer->raw == NULL  ||
1948c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            outBuffer == NULL || outBuffer->raw == NULL ||
1949c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            inBuffer->frameCount != outBuffer->frameCount){
19503856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Reverb_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
1951c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
1952c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
19533856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverb_process() Calling process with %d frames", outBuffer->frameCount);
1954c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    /* Process all the available frames, block processing is handled internalLY by the LVM bundle */
195594a1ee822686e920a33e312f4032f991731aea07rago#if defined (BUILD_FLOAT) && defined (NATIVE_FLOAT_BUFFER)
195694a1ee822686e920a33e312f4032f991731aea07rago    status = process(    inBuffer->f32,
195794a1ee822686e920a33e312f4032f991731aea07rago                         outBuffer->f32,
195894a1ee822686e920a33e312f4032f991731aea07rago                         outBuffer->frameCount,
195994a1ee822686e920a33e312f4032f991731aea07rago                         pContext);
196094a1ee822686e920a33e312f4032f991731aea07rago#else
196194a1ee822686e920a33e312f4032f991731aea07rago    status = process(    inBuffer->s16,
196294a1ee822686e920a33e312f4032f991731aea07rago                         outBuffer->s16,
196394a1ee822686e920a33e312f4032f991731aea07rago                         outBuffer->frameCount,
196494a1ee822686e920a33e312f4032f991731aea07rago                         pContext);
196594a1ee822686e920a33e312f4032f991731aea07rago#endif
1966c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1967e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    if (pContext->bEnabled == LVM_FALSE) {
1968e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        if (pContext->SamplesToExitCount > 0) {
1969361155ac670d6e528309525e7737e9e2da4046ffAndy Hung            // signed - unsigned will trigger integer overflow if result becomes negative.
1970361155ac670d6e528309525e7737e9e2da4046ffAndy Hung            pContext->SamplesToExitCount -= (ssize_t)outBuffer->frameCount;
1971e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        } else {
1972e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            status = -ENODATA;
1973e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        }
1974e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent    }
1975e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
1976c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return status;
1977c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}   /* end Reverb_process */
1978c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1979c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent/* Effect Control Interface Implementation: Command */
1980e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Reverb_command(effect_handle_t  self,
1981c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                              uint32_t            cmdCode,
1982c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                              uint32_t            cmdSize,
1983c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                              void                *pCmdData,
1984c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                              uint32_t            *replySize,
1985c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                              void                *pReplyData){
1986c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    android::ReverbContext * pContext = (android::ReverbContext *) self;
19872d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    LVREV_ControlParams_st    ActiveParams;              /* Current control Parameters */
19882d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent    LVREV_ReturnStatus_en     LvmStatus=LVREV_SUCCESS;     /* Function call status */
19892d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent
1990c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1991c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    if (pContext == NULL){
19923856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("\tLVM_ERROR : Reverb_command ERROR pContext == NULL");
1993c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        return -EINVAL;
1994c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
1995c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
19963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverb_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
1997c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
1998c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    switch (cmdCode){
1999c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case EFFECT_CMD_INIT:
20003856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command cmdCode Case: "
2001c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "EFFECT_CMD_INIT start");
2002c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
20036368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent            if (pReplyData == NULL || replySize == NULL || *replySize != sizeof(int)){
20043856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2005c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        "EFFECT_CMD_INIT: ERROR");
2006c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
2007c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
2008c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int *) pReplyData = 0;
2009c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
2010c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
20113d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        case EFFECT_CMD_SET_CONFIG:
20123856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command cmdCode Case: "
20133d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            //        "EFFECT_CMD_SET_CONFIG start");
20146368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent            if (pCmdData == NULL || cmdSize != sizeof(effect_config_t) ||
20156368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent                    pReplyData == NULL || replySize == NULL || *replySize != sizeof(int)) {
20163d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
20173d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                        "EFFECT_CMD_SET_CONFIG: ERROR");
20183d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                return -EINVAL;
20193d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            }
20203d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            *(int *) pReplyData = android::Reverb_setConfig(pContext,
20213d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                                                            (effect_config_t *) pCmdData);
20223d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            break;
20233d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
20243d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent        case EFFECT_CMD_GET_CONFIG:
20256368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent            if (pReplyData == NULL || replySize == NULL || *replySize != sizeof(effect_config_t)) {
20263856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
20273d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent                        "EFFECT_CMD_GET_CONFIG: ERROR");
2028c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
2029c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
20303d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent
20313d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            android::Reverb_getConfig(pContext, (effect_config_t *)pReplyData);
2032c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
2033c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2034c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case EFFECT_CMD_RESET:
20353856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command cmdCode Case: "
2036c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "EFFECT_CMD_RESET start");
20373d5188bd6abe55898f10a0edf3c05aff8aa2ef67Eric Laurent            Reverb_setConfig(pContext, &pContext->config);
2038c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
2039c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2040c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case EFFECT_CMD_GET_PARAM:{
20413856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command cmdCode Case: "
2042c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "EFFECT_CMD_GET_PARAM start");
20436368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent            effect_param_t *p = (effect_param_t *)pCmdData;
20449e29523b9537983b4c4b205ff868d0b3bca0383bEric Laurent            if (SIZE_MAX - sizeof(effect_param_t) < (size_t)p->psize) {
20459e29523b9537983b4c4b205ff868d0b3bca0383bEric Laurent                android_errorWriteLog(0x534e4554, "26347509");
20469e29523b9537983b4c4b205ff868d0b3bca0383bEric Laurent                return -EINVAL;
20479e29523b9537983b4c4b205ff868d0b3bca0383bEric Laurent            }
20486368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent            if (pCmdData == NULL || cmdSize < sizeof(effect_param_t) ||
20496368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent                    cmdSize < (sizeof(effect_param_t) + p->psize) ||
20506368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent                    pReplyData == NULL || replySize == NULL ||
20516368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent                    *replySize < (sizeof(effect_param_t) + p->psize)) {
20523856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2053c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        "EFFECT_CMD_GET_PARAM: ERROR");
2054c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
2055c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
2056c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2057c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
2058c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2059c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            p = (effect_param_t *)pReplyData;
2060c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2061c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
2062c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2063c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            p->status = android::Reverb_getParameter(pContext,
2064c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                         (void *)p->data,
2065b302bd5d288be2d3363b80053ca2392560b00b25Ashok Bhat                                                          &p->vsize,
2066c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                          p->data + voffset);
2067c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2068c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *replySize = sizeof(effect_param_t) + voffset + p->vsize;
2069c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
20703856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command EFFECT_CMD_GET_PARAM "
2071c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "*pCmdData %d, *replySize %d, *pReplyData %d ",
2072c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2073c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *replySize,
2074c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
2075c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2076c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } break;
2077c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case EFFECT_CMD_SET_PARAM:{
2078c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
20793856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command cmdCode Case: "
2080c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "EFFECT_CMD_SET_PARAM start");
20813856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
2082c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
2083c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *replySize,
2084c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
2085c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
20866368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent            if (pCmdData == NULL || (cmdSize < (sizeof(effect_param_t) + sizeof(int32_t))) ||
20876368e6d23ca27cd59a9a1876d6b5a2301a8657edEric Laurent                    pReplyData == NULL ||  replySize == NULL || *replySize != sizeof(int32_t)) {
20883856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2089c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        "EFFECT_CMD_SET_PARAM: ERROR");
2090c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
2091c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
2092c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2093c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            effect_param_t *p = (effect_param_t *) pCmdData;
2094c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2095c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (p->psize != sizeof(int32_t)){
20963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\t4LVM_ERROR : Reverb_command cmdCode Case: "
2097c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
2098c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
2099c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
2100c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
21013856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tn5Reverb_command cmdSize is %d\n"
2102c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "\tsizeof(effect_param_t) is  %d\n"
2103c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "\tp->psize is %d\n"
2104c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "\tp->vsize is %d"
2105c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "\n",
2106c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
2107c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2108c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int *)pReplyData = android::Reverb_setParameter(pContext,
2109c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                                                             (void *)p->data,
2110804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov                                                              p->data + p->psize,
2111804632afcdda6e80945bf27c384757bda50560cbMikhail Naganov                                                              p->vsize);
2112c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        } break;
2113c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2114c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case EFFECT_CMD_ENABLE:
21153856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command cmdCode Case: "
2116c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "EFFECT_CMD_ENABLE start");
2117c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2118c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
21193856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2120c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        "EFFECT_CMD_ENABLE: ERROR");
2121c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
2122c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
2123c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(pContext->bEnabled == LVM_TRUE){
21243856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2125c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                         "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
2126c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                 return -EINVAL;
2127c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent             }
2128c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int *)pReplyData = 0;
2129c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->bEnabled = LVM_TRUE;
21302d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent            /* Get the current settings */
21312d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent            LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
21322d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent            LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "EFFECT_CMD_ENABLE")
21332d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent            pContext->SamplesToExitCount =
21342d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent                    (ActiveParams.T60 * pContext->config.inputCfg.samplingRate)/1000;
2135e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            // force no volume ramp for first buffer processed after enabling the effect
2136e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            pContext->volumeMode = android::REVERB_VOLUME_FLAT;
21373856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tEFFECT_CMD_ENABLE SamplesToExitCount = %d", pContext->SamplesToExitCount);
2138c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
2139c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case EFFECT_CMD_DISABLE:
21403856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            //ALOGV("\tReverb_command cmdCode Case: "
2141c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            //        "EFFECT_CMD_DISABLE start");
2142c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2143c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if (pReplyData == NULL || *replySize != sizeof(int)){
21443856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2145c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                        "EFFECT_CMD_DISABLE: ERROR");
2146c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                return -EINVAL;
2147c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            }
2148c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            if(pContext->bEnabled == LVM_FALSE){
21493856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2150c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                         "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
2151c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                 return -EINVAL;
2152c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent             }
2153c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            *(int *)pReplyData = 0;
2154c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            pContext->bEnabled = LVM_FALSE;
2155c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
2156c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2157c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case EFFECT_CMD_SET_VOLUME:
2158e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            if (pCmdData == NULL ||
2159e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                cmdSize != 2 * sizeof(uint32_t)) {
21603856b090cd04ba5dd4a59a12430ed724d5995909Steve Block                ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2161e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                        "EFFECT_CMD_SET_VOLUME: ERROR");
2162e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                return -EINVAL;
2163e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            }
2164e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
2165e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
2166e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            if (pReplyData != NULL) { // we have volume control
2167e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                pContext->leftVolume = (LVM_INT16)((*(uint32_t *)pCmdData + (1 << 11)) >> 12);
2168e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                pContext->rightVolume = (LVM_INT16)((*((uint32_t *)pCmdData + 1) + (1 << 11)) >> 12);
2169e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                *(uint32_t *)pReplyData = (1 << 24);
2170e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                *((uint32_t *)pReplyData + 1) = (1 << 24);
2171e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                if (pContext->volumeMode == android::REVERB_VOLUME_OFF) {
2172e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                    // force no volume ramp for first buffer processed after getting volume control
2173e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                    pContext->volumeMode = android::REVERB_VOLUME_FLAT;
2174e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                }
2175e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            } else { // we don't have volume control
2176e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                pContext->leftVolume = REVERB_UNIT_VOLUME;
2177e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                pContext->rightVolume = REVERB_UNIT_VOLUME;
2178e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                pContext->volumeMode = android::REVERB_VOLUME_OFF;
2179e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            }
21803856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("EFFECT_CMD_SET_VOLUME left %d, right %d mode %d",
2181e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent                    pContext->leftVolume, pContext->rightVolume,  pContext->volumeMode);
2182e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent            break;
2183e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent
2184e0aed6ddcb4e3c301b80aa26706b6052dab42c41Eric Laurent        case EFFECT_CMD_SET_DEVICE:
2185c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        case EFFECT_CMD_SET_AUDIO_MODE:
21863856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        //ALOGV("\tReverb_command cmdCode Case: "
21872d3bf535004f7310fe04a4b5f46b6747cdb3c93fEric Laurent        //        "EFFECT_CMD_SET_DEVICE/EFFECT_CMD_SET_VOLUME/EFFECT_CMD_SET_AUDIO_MODE start");
2188c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            break;
2189c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2190c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent        default:
21913856b090cd04ba5dd4a59a12430ed724d5995909Steve Block            ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
2192c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent                    "DEFAULT start %d ERROR",cmdCode);
2193c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent            return -EINVAL;
2194c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    }
2195c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
21963856b090cd04ba5dd4a59a12430ed724d5995909Steve Block    //ALOGV("\tReverb_command end\n\n");
2197c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    return 0;
2198c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent}    /* end Reverb_command */
2199c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
2200e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent/* Effect Control Interface Implementation: get_descriptor */
2201e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentint Reverb_getDescriptor(effect_handle_t   self,
2202e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent                                    effect_descriptor_t *pDescriptor)
2203e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent{
2204e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    android::ReverbContext * pContext = (android::ReverbContext *)self;
2205e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    const effect_descriptor_t *desc;
2206e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
2207e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pContext == NULL || pDescriptor == NULL) {
22083856b090cd04ba5dd4a59a12430ed724d5995909Steve Block        ALOGV("Reverb_getDescriptor() invalid param");
2209e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        return -EINVAL;
2210e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
2211e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
2212e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    if (pContext->auxiliary) {
2213e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        if (pContext->preset) {
2214e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gAuxPresetReverbDescriptor;
2215e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        } else {
2216e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gAuxEnvReverbDescriptor;
2217e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        }
2218e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    } else {
2219e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        if (pContext->preset) {
2220e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gInsertPresetReverbDescriptor;
2221e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        } else {
2222e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent            desc = &android::gInsertEnvReverbDescriptor;
2223e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent        }
2224e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    }
2225e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
2226a189a6883ee55cf62da1d7bf5bf5a8ab501938a4Glenn Kasten    *pDescriptor = *desc;
2227e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
2228e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    return 0;
2229e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent}   /* end Reverb_getDescriptor */
2230e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
2231e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent// effect_handle_t interface implementation for Reverb effect
2232c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurentconst struct effect_interface_s gReverbInterface = {
2233c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent    Reverb_process,
2234e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent    Reverb_command,
2235ba7b8f881a9b6b21803752326d2932a3bd42d7cfEric Laurent    Reverb_getDescriptor,
2236ba7b8f881a9b6b21803752326d2932a3bd42d7cfEric Laurent    NULL,
2237c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent};    /* end gReverbInterface */
2238c59c6fd7f859b4010d788db89b8d4d76bbb70e57Eric Laurent
22397f16b197c76fbae9399242f055a7ee16dcd0fd6dMarco Nelissen// This is the only symbol that needs to be exported
22407f16b197c76fbae9399242f055a7ee16dcd0fd6dMarco Nelissen__attribute__ ((visibility ("default")))
2241e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurentaudio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
2242c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .tag = AUDIO_EFFECT_LIBRARY_TAG,
2243c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .version = EFFECT_LIBRARY_API_VERSION,
2244c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .name = "Reverb Library",
2245c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .implementor = "NXP Software Ltd.",
2246c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .create_effect = android::EffectCreate,
2247c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .release_effect = android::EffectRelease,
2248c9d8ea7f8f9a1ca8ecd266695e3cac423790b2f9synergydev    .get_descriptor = android::EffectGetDescriptor,
2249e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent};
2250e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent
2251e1315cf0b63b4c14a77046519e6b01f6f60d74b0Eric Laurent}
2252