blob: 1825aabcba7ea56e9e0d530eb0041a863bcb0051 [file] [log] [blame]
Eric Laurenta1a96f32010-08-04 06:33:52 -07001/*
2 * Copyright (C) 2010-2010 NXP Software
3 * Copyright (C) 2009 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#define LOG_TAG "Reverb"
19#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
Eric Laurenta7e56482010-08-24 14:21:57 -070020//#define LOG_NDEBUG 0
Eric Laurenta1a96f32010-08-04 06:33:52 -070021
22#include <cutils/log.h>
23#include <assert.h>
24#include <stdlib.h>
25#include <string.h>
26#include <new>
27#include <EffectReverb.h>
28#include <LVREV.h>
29
Eric Laurent0fb66c22011-05-17 19:16:02 -070030// effect_handle_t interface implementation for reverb
Eric Laurenta1a96f32010-08-04 06:33:52 -070031extern "C" const struct effect_interface_s gReverbInterface;
32
33#define LVM_ERROR_CHECK(LvmStatus, callingFunc, calledFunc){\
34 if (LvmStatus == LVREV_NULLADDRESS){\
Steve Block06ade6a2011-10-20 11:56:00 +010035 ALOGV("\tLVREV_ERROR : Parameter error - "\
Eric Laurenta1a96f32010-08-04 06:33:52 -070036 "null pointer returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
37 }\
38 if (LvmStatus == LVREV_INVALIDNUMSAMPLES){\
Steve Block06ade6a2011-10-20 11:56:00 +010039 ALOGV("\tLVREV_ERROR : Parameter error - "\
Eric Laurenta1a96f32010-08-04 06:33:52 -070040 "bad number of samples returned by %s in %s\n\n\n\n", callingFunc, calledFunc);\
41 }\
42 if (LvmStatus == LVREV_OUTOFRANGE){\
Steve Block06ade6a2011-10-20 11:56:00 +010043 ALOGV("\tLVREV_ERROR : Parameter error - "\
Eric Laurenta1a96f32010-08-04 06:33:52 -070044 "out of range returned by %s in %s\n", callingFunc, calledFunc);\
45 }\
46 }
47
48// Namespaces
49namespace android {
50namespace {
51
52/************************************************************************************/
53/* */
54/* Preset definitions */
55/* */
56/************************************************************************************/
Eric Laurenta1a96f32010-08-04 06:33:52 -070057
Eric Laurenta7e56482010-08-24 14:21:57 -070058const static t_reverb_settings sReverbPresets[] = {
59 // REVERB_PRESET_NONE: values are unused
60 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
61 // REVERB_PRESET_SMALLROOM
Eric Laurent27a2fdf2010-09-10 17:44:44 -070062 {-400, -600, 1100, 830, -400, 5, 500, 10, 1000, 1000},
Eric Laurenta7e56482010-08-24 14:21:57 -070063 // REVERB_PRESET_MEDIUMROOM
Eric Laurent27a2fdf2010-09-10 17:44:44 -070064 {-400, -600, 1300, 830, -1000, 20, -200, 20, 1000, 1000},
Eric Laurenta7e56482010-08-24 14:21:57 -070065 // REVERB_PRESET_LARGEROOM
Eric Laurent27a2fdf2010-09-10 17:44:44 -070066 {-400, -600, 1500, 830, -1600, 5, -1000, 40, 1000, 1000},
Eric Laurenta7e56482010-08-24 14:21:57 -070067 // REVERB_PRESET_MEDIUMHALL
Eric Laurent27a2fdf2010-09-10 17:44:44 -070068 {-400, -600, 1800, 700, -1300, 15, -800, 30, 1000, 1000},
Eric Laurenta7e56482010-08-24 14:21:57 -070069 // REVERB_PRESET_LARGEHALL
Eric Laurent27a2fdf2010-09-10 17:44:44 -070070 {-400, -600, 1800, 700, -2000, 30, -1400, 60, 1000, 1000},
Eric Laurenta7e56482010-08-24 14:21:57 -070071 // REVERB_PRESET_PLATE
Eric Laurent27a2fdf2010-09-10 17:44:44 -070072 {-400, -200, 1300, 900, 0, 2, 0, 10, 1000, 750},
Eric Laurenta7e56482010-08-24 14:21:57 -070073};
Eric Laurenta1a96f32010-08-04 06:33:52 -070074
Eric Laurenta7e56482010-08-24 14:21:57 -070075
76// NXP SW auxiliary environmental reverb
77const effect_descriptor_t gAuxEnvReverbDescriptor = {
Eric Laurenta1a96f32010-08-04 06:33:52 -070078 { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e } },
79 { 0x4a387fc0, 0x8ab3, 0x11df, 0x8bad, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } },
Eric Laurent0fb66c22011-05-17 19:16:02 -070080 EFFECT_CONTROL_API_VERSION,
Eric Laurenta7e56482010-08-24 14:21:57 -070081 EFFECT_FLAG_TYPE_AUXILIARY,
Eric Laurentadecf1c2010-08-27 10:52:56 -070082 LVREV_CUP_LOAD_ARM9E,
83 LVREV_MEM_USAGE,
Eric Laurenta7e56482010-08-24 14:21:57 -070084 "Auxiliary Environmental Reverb",
Eric Laurenta1a96f32010-08-04 06:33:52 -070085 "NXP Software Ltd.",
86};
87
Eric Laurenta7e56482010-08-24 14:21:57 -070088// NXP SW insert environmental reverb
89static const effect_descriptor_t gInsertEnvReverbDescriptor = {
90 {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}},
91 {0xc7a511a0, 0xa3bb, 0x11df, 0x860e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
Eric Laurent0fb66c22011-05-17 19:16:02 -070092 EFFECT_CONTROL_API_VERSION,
Eric Laurent27a2fdf2010-09-10 17:44:44 -070093 EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_VOLUME_CTRL,
Eric Laurentadecf1c2010-08-27 10:52:56 -070094 LVREV_CUP_LOAD_ARM9E,
95 LVREV_MEM_USAGE,
Eric Laurenta7e56482010-08-24 14:21:57 -070096 "Insert Environmental Reverb",
97 "NXP Software Ltd.",
98};
99
100// NXP SW auxiliary preset reverb
101static const effect_descriptor_t gAuxPresetReverbDescriptor = {
102 {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
103 {0xf29a1400, 0xa3bb, 0x11df, 0x8ddc, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
Eric Laurent0fb66c22011-05-17 19:16:02 -0700104 EFFECT_CONTROL_API_VERSION,
Eric Laurenta7e56482010-08-24 14:21:57 -0700105 EFFECT_FLAG_TYPE_AUXILIARY,
Eric Laurentadecf1c2010-08-27 10:52:56 -0700106 LVREV_CUP_LOAD_ARM9E,
107 LVREV_MEM_USAGE,
Eric Laurenta7e56482010-08-24 14:21:57 -0700108 "Auxiliary Preset Reverb",
109 "NXP Software Ltd.",
110};
111
112// NXP SW insert preset reverb
113static const effect_descriptor_t gInsertPresetReverbDescriptor = {
114 {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
115 {0x172cdf00, 0xa3bc, 0x11df, 0xa72f, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
Eric Laurent0fb66c22011-05-17 19:16:02 -0700116 EFFECT_CONTROL_API_VERSION,
Eric Laurent27a2fdf2010-09-10 17:44:44 -0700117 EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_VOLUME_CTRL,
Eric Laurentadecf1c2010-08-27 10:52:56 -0700118 LVREV_CUP_LOAD_ARM9E,
119 LVREV_MEM_USAGE,
Eric Laurenta7e56482010-08-24 14:21:57 -0700120 "Insert Preset Reverb",
121 "NXP Software Ltd.",
122};
123
124// gDescriptors contains pointers to all defined effect descriptor in this library
125static const effect_descriptor_t * const gDescriptors[] = {
126 &gAuxEnvReverbDescriptor,
127 &gInsertEnvReverbDescriptor,
128 &gAuxPresetReverbDescriptor,
129 &gInsertPresetReverbDescriptor
130};
131
Eric Laurenta1a96f32010-08-04 06:33:52 -0700132struct ReverbContext{
133 const struct effect_interface_s *itfe;
134 effect_config_t config;
135 LVREV_Handle_t hInstance;
136 int16_t SavedRoomLevel;
137 int16_t SavedHfLevel;
138 int16_t SavedDecayTime;
139 int16_t SavedDecayHfRatio;
140 int16_t SavedReverbLevel;
141 int16_t SavedDiffusion;
142 int16_t SavedDensity;
143 bool bEnabled;
144 #ifdef LVM_PCM
145 FILE *PcmInPtr;
146 FILE *PcmOutPtr;
147 #endif
148 LVM_Fs_en SampleRate;
Eric Laurentadecf1c2010-08-27 10:52:56 -0700149 LVM_INT32 *InFrames32;
150 LVM_INT32 *OutFrames32;
Eric Laurenta7e56482010-08-24 14:21:57 -0700151 bool auxiliary;
152 bool preset;
153 uint16_t curPreset;
154 uint16_t nextPreset;
Eric Laurent5fa6df62010-09-02 17:18:20 -0700155 int SamplesToExitCount;
Eric Laurent27a2fdf2010-09-10 17:44:44 -0700156 LVM_INT16 leftVolume;
157 LVM_INT16 rightVolume;
158 LVM_INT16 prevLeftVolume;
159 LVM_INT16 prevRightVolume;
160 int volumeMode;
161};
162
163enum {
164 REVERB_VOLUME_OFF,
165 REVERB_VOLUME_FLAT,
166 REVERB_VOLUME_RAMP,
Eric Laurenta1a96f32010-08-04 06:33:52 -0700167};
168
Glenn Kasten161fb372011-01-25 10:53:40 -0800169#define REVERB_DEFAULT_PRESET REVERB_PRESET_NONE
Eric Laurenta7e56482010-08-24 14:21:57 -0700170
Eric Laurent27a2fdf2010-09-10 17:44:44 -0700171
172#define REVERB_SEND_LEVEL (0x0C00) // 0.75 in 4.12 format
173#define REVERB_UNIT_VOLUME (0x1000) // 1.0 in 4.12 format
174
Eric Laurenta1a96f32010-08-04 06:33:52 -0700175//--- local function prototypes
176int Reverb_init (ReverbContext *pContext);
177void Reverb_free (ReverbContext *pContext);
178int Reverb_configure (ReverbContext *pContext, effect_config_t *pConfig);
179int Reverb_setParameter (ReverbContext *pContext, void *pParam, void *pValue);
180int Reverb_getParameter (ReverbContext *pContext,
181 void *pParam,
182 size_t *pValueSize,
183 void *pValue);
Eric Laurenta7e56482010-08-24 14:21:57 -0700184int Reverb_LoadPreset (ReverbContext *pContext);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700185
186/* Effect Library Interface Implementation */
187extern "C" int EffectQueryNumberEffects(uint32_t *pNumEffects){
Steve Block06ade6a2011-10-20 11:56:00 +0100188 ALOGV("\n\tEffectQueryNumberEffects start");
Eric Laurenta7e56482010-08-24 14:21:57 -0700189 *pNumEffects = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *);
Steve Block06ade6a2011-10-20 11:56:00 +0100190 ALOGV("\tEffectQueryNumberEffects creating %d effects", *pNumEffects);
191 ALOGV("\tEffectQueryNumberEffects end\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700192 return 0;
193} /* end EffectQueryNumberEffects */
194
Eric Laurent0fb66c22011-05-17 19:16:02 -0700195extern "C" int EffectQueryEffect(uint32_t index,
196 effect_descriptor_t *pDescriptor){
Steve Block06ade6a2011-10-20 11:56:00 +0100197 ALOGV("\n\tEffectQueryEffect start");
198 ALOGV("\tEffectQueryEffect processing index %d", index);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700199 if (pDescriptor == NULL){
Steve Block06ade6a2011-10-20 11:56:00 +0100200 ALOGV("\tLVM_ERROR : EffectQueryEffect was passed NULL pointer");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700201 return -EINVAL;
202 }
Eric Laurenta7e56482010-08-24 14:21:57 -0700203 if (index >= sizeof(gDescriptors) / sizeof(const effect_descriptor_t *)) {
Steve Block06ade6a2011-10-20 11:56:00 +0100204 ALOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700205 return -ENOENT;
206 }
Eric Laurenta7e56482010-08-24 14:21:57 -0700207 memcpy(pDescriptor, gDescriptors[index], sizeof(effect_descriptor_t));
Steve Block06ade6a2011-10-20 11:56:00 +0100208 ALOGV("\tEffectQueryEffect end\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700209 return 0;
210} /* end EffectQueryEffect */
211
212extern "C" int EffectCreate(effect_uuid_t *uuid,
213 int32_t sessionId,
214 int32_t ioId,
Eric Laurent0fb66c22011-05-17 19:16:02 -0700215 effect_handle_t *pHandle){
Eric Laurenta1a96f32010-08-04 06:33:52 -0700216 int ret;
217 int i;
Eric Laurenta7e56482010-08-24 14:21:57 -0700218 int length = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *);
219 const effect_descriptor_t *desc;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700220
Steve Block06ade6a2011-10-20 11:56:00 +0100221 ALOGV("\t\nEffectCreate start");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700222
Eric Laurent0fb66c22011-05-17 19:16:02 -0700223 if (pHandle == NULL || uuid == NULL){
Steve Block06ade6a2011-10-20 11:56:00 +0100224 ALOGV("\tLVM_ERROR : EffectCreate() called with NULL pointer");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700225 return -EINVAL;
226 }
227
Eric Laurenta7e56482010-08-24 14:21:57 -0700228 for (i = 0; i < length; i++) {
229 desc = gDescriptors[i];
230 if (memcmp(uuid, &desc->uuid, sizeof(effect_uuid_t))
231 == 0) {
Steve Block06ade6a2011-10-20 11:56:00 +0100232 ALOGV("\tEffectCreate - UUID matched Reverb type %d, UUID = %x", i, desc->uuid.timeLow);
Eric Laurenta7e56482010-08-24 14:21:57 -0700233 break;
234 }
235 }
236
237 if (i == length) {
238 return -ENOENT;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700239 }
240
241 ReverbContext *pContext = new ReverbContext;
242
243 pContext->itfe = &gReverbInterface;
244 pContext->hInstance = NULL;
245
Eric Laurenta7e56482010-08-24 14:21:57 -0700246 pContext->auxiliary = false;
247 if ((desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY){
248 pContext->auxiliary = true;
Steve Block06ade6a2011-10-20 11:56:00 +0100249 ALOGV("\tEffectCreate - AUX");
Eric Laurent5fa6df62010-09-02 17:18:20 -0700250 }else{
Steve Block06ade6a2011-10-20 11:56:00 +0100251 ALOGV("\tEffectCreate - INS");
Eric Laurenta7e56482010-08-24 14:21:57 -0700252 }
253
254 pContext->preset = false;
255 if (memcmp(&desc->type, SL_IID_PRESETREVERB, sizeof(effect_uuid_t)) == 0) {
256 pContext->preset = true;
257 // force reloading preset at first call to process()
258 pContext->curPreset = REVERB_PRESET_LAST + 1;
259 pContext->nextPreset = REVERB_DEFAULT_PRESET;
Steve Block06ade6a2011-10-20 11:56:00 +0100260 ALOGV("\tEffectCreate - PRESET");
Eric Laurent5fa6df62010-09-02 17:18:20 -0700261 }else{
Steve Block06ade6a2011-10-20 11:56:00 +0100262 ALOGV("\tEffectCreate - ENVIRONMENTAL");
Eric Laurenta7e56482010-08-24 14:21:57 -0700263 }
264
Steve Block06ade6a2011-10-20 11:56:00 +0100265 ALOGV("\tEffectCreate - Calling Reverb_init");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700266 ret = Reverb_init(pContext);
267
268 if (ret < 0){
Steve Block06ade6a2011-10-20 11:56:00 +0100269 ALOGV("\tLVM_ERROR : EffectCreate() init failed");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700270 delete pContext;
271 return ret;
272 }
273
Eric Laurent0fb66c22011-05-17 19:16:02 -0700274 *pHandle = (effect_handle_t)pContext;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700275
276 #ifdef LVM_PCM
277 pContext->PcmInPtr = NULL;
278 pContext->PcmOutPtr = NULL;
279
280 pContext->PcmInPtr = fopen("/data/tmp/reverb_pcm_in.pcm", "w");
281 pContext->PcmOutPtr = fopen("/data/tmp/reverb_pcm_out.pcm", "w");
282
283 if((pContext->PcmInPtr == NULL)||
284 (pContext->PcmOutPtr == NULL)){
285 return -EINVAL;
286 }
287 #endif
288
Eric Laurentadecf1c2010-08-27 10:52:56 -0700289
290 // Allocate memory for reverb process (*2 is for STEREO)
291 pContext->InFrames32 = (LVM_INT32 *)malloc(LVREV_MAX_FRAME_SIZE * sizeof(LVM_INT32) * 2);
292 pContext->OutFrames32 = (LVM_INT32 *)malloc(LVREV_MAX_FRAME_SIZE * sizeof(LVM_INT32) * 2);
293
Steve Block06ade6a2011-10-20 11:56:00 +0100294 ALOGV("\tEffectCreate %p, size %d", pContext, sizeof(ReverbContext));
295 ALOGV("\tEffectCreate end\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700296 return 0;
297} /* end EffectCreate */
298
Eric Laurent0fb66c22011-05-17 19:16:02 -0700299extern "C" int EffectRelease(effect_handle_t handle){
300 ReverbContext * pContext = (ReverbContext *)handle;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700301
Steve Block06ade6a2011-10-20 11:56:00 +0100302 ALOGV("\tEffectRelease %p", handle);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700303 if (pContext == NULL){
Steve Block06ade6a2011-10-20 11:56:00 +0100304 ALOGV("\tLVM_ERROR : EffectRelease called with NULL pointer");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700305 return -EINVAL;
306 }
307
308 #ifdef LVM_PCM
309 fclose(pContext->PcmInPtr);
310 fclose(pContext->PcmOutPtr);
311 #endif
Eric Laurentadecf1c2010-08-27 10:52:56 -0700312 free(pContext->InFrames32);
313 free(pContext->OutFrames32);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700314 Reverb_free(pContext);
315 delete pContext;
316 return 0;
317} /* end EffectRelease */
318
Eric Laurent0fb66c22011-05-17 19:16:02 -0700319extern "C" int EffectGetDescriptor(effect_uuid_t *uuid,
320 effect_descriptor_t *pDescriptor) {
321 int i;
322 int length = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *);
323
324 if (pDescriptor == NULL || uuid == NULL){
Steve Block06ade6a2011-10-20 11:56:00 +0100325 ALOGV("EffectGetDescriptor() called with NULL pointer");
Eric Laurent0fb66c22011-05-17 19:16:02 -0700326 return -EINVAL;
327 }
328
329 for (i = 0; i < length; i++) {
330 if (memcmp(uuid, &gDescriptors[i]->uuid, sizeof(effect_uuid_t)) == 0) {
331 memcpy(pDescriptor, gDescriptors[i], sizeof(effect_descriptor_t));
Steve Block06ade6a2011-10-20 11:56:00 +0100332 ALOGV("EffectGetDescriptor - UUID matched Reverb type %d, UUID = %x",
Eric Laurent0fb66c22011-05-17 19:16:02 -0700333 i, gDescriptors[i]->uuid.timeLow);
334 return 0;
335 }
336 }
337
338 return -EINVAL;
339} /* end EffectGetDescriptor */
340
Eric Laurenta1a96f32010-08-04 06:33:52 -0700341/* local functions */
342#define CHECK_ARG(cond) { \
343 if (!(cond)) { \
Steve Block06ade6a2011-10-20 11:56:00 +0100344 ALOGV("\tLVM_ERROR : Invalid argument: "#cond); \
Eric Laurenta1a96f32010-08-04 06:33:52 -0700345 return -EINVAL; \
346 } \
347}
348
349//----------------------------------------------------------------------------
350// MonoTo2I_32()
351//----------------------------------------------------------------------------
352// Purpose:
353// Convert MONO to STEREO
354//
355//----------------------------------------------------------------------------
356
357void MonoTo2I_32( const LVM_INT32 *src,
358 LVM_INT32 *dst,
359 LVM_INT16 n)
360{
361 LVM_INT16 ii;
362 src += (n-1);
363 dst += ((n*2)-1);
364
365 for (ii = n; ii != 0; ii--)
366 {
367 *dst = *src;
368 dst--;
369
370 *dst = *src;
371 dst--;
372 src--;
373 }
374
375 return;
376}
377
378//----------------------------------------------------------------------------
379// From2iToMono_32()
380//----------------------------------------------------------------------------
381// Purpose:
382// Convert STEREO to MONO
383//
384//----------------------------------------------------------------------------
385
386void From2iToMono_32( const LVM_INT32 *src,
387 LVM_INT32 *dst,
388 LVM_INT16 n)
389{
390 LVM_INT16 ii;
391 LVM_INT32 Temp;
392
393 for (ii = n; ii != 0; ii--)
394 {
395 Temp = (*src>>1);
396 src++;
397
398 Temp +=(*src>>1);
399 src++;
400
401 *dst = Temp;
402 dst++;
403 }
404
405 return;
406}
Eric Laurenta7e56482010-08-24 14:21:57 -0700407
408static inline int16_t clamp16(int32_t sample)
409{
410 if ((sample>>15) ^ (sample>>31))
411 sample = 0x7FFF ^ (sample>>31);
412 return sample;
413}
414
Eric Laurenta1a96f32010-08-04 06:33:52 -0700415//----------------------------------------------------------------------------
416// process()
417//----------------------------------------------------------------------------
418// Purpose:
419// Apply the Reverb
420//
421// Inputs:
422// pIn: pointer to stereo/mono 16 bit input data
423// pOut: pointer to stereo 16 bit output data
424// frameCount: Frames to process
425// pContext: effect engine context
426// strength strength to be applied
427//
428// Outputs:
429// pOut: pointer to updated stereo 16 bit output data
430//
431//----------------------------------------------------------------------------
432
433int process( LVM_INT16 *pIn,
434 LVM_INT16 *pOut,
435 int frameCount,
436 ReverbContext *pContext){
437
Eric Laurent5fa6df62010-09-02 17:18:20 -0700438 LVM_INT16 samplesPerFrame = 1;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700439 LVREV_ReturnStatus_en LvmStatus = LVREV_SUCCESS; /* Function call status */
Eric Laurenta1a96f32010-08-04 06:33:52 -0700440 LVM_INT16 *OutFrames16;
441
442
443 // Check that the input is either mono or stereo
Eric Laurent0fb66c22011-05-17 19:16:02 -0700444 if (pContext->config.inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO) {
Eric Laurenta1a96f32010-08-04 06:33:52 -0700445 samplesPerFrame = 2;
Eric Laurent0fb66c22011-05-17 19:16:02 -0700446 } else if (pContext->config.inputCfg.channels != AUDIO_CHANNEL_OUT_MONO) {
Steve Block06ade6a2011-10-20 11:56:00 +0100447 ALOGV("\tLVREV_ERROR : process invalid PCM format");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700448 return -EINVAL;
449 }
450
Eric Laurentadecf1c2010-08-27 10:52:56 -0700451 OutFrames16 = (LVM_INT16 *)pContext->OutFrames32;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700452
453 // Check for NULL pointers
Eric Laurentadecf1c2010-08-27 10:52:56 -0700454 if((pContext->InFrames32 == NULL)||(pContext->OutFrames32 == NULL)){
Steve Block06ade6a2011-10-20 11:56:00 +0100455 ALOGV("\tLVREV_ERROR : process failed to allocate memory for temporary buffers ");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700456 return -EINVAL;
457 }
458
459 #ifdef LVM_PCM
460 fwrite(pIn, frameCount*sizeof(LVM_INT16)*samplesPerFrame, 1, pContext->PcmInPtr);
461 fflush(pContext->PcmInPtr);
462 #endif
463
Eric Laurenta7e56482010-08-24 14:21:57 -0700464 if (pContext->preset && pContext->nextPreset != pContext->curPreset) {
465 Reverb_LoadPreset(pContext);
466 }
Eric Laurent27a2fdf2010-09-10 17:44:44 -0700467
468
469
Eric Laurenta1a96f32010-08-04 06:33:52 -0700470 // Convert to Input 32 bits
Eric Laurent27a2fdf2010-09-10 17:44:44 -0700471 if (pContext->auxiliary) {
472 for(int i=0; i<frameCount*samplesPerFrame; i++){
473 pContext->InFrames32[i] = (LVM_INT32)pIn[i]<<8;
474 }
475 } else {
476 // insert reverb input is always stereo
477 for (int i = 0; i < frameCount; i++) {
478 pContext->InFrames32[2*i] = (pIn[2*i] * REVERB_SEND_LEVEL) >> 4; // <<8 + >>12
479 pContext->InFrames32[2*i+1] = (pIn[2*i+1] * REVERB_SEND_LEVEL) >> 4; // <<8 + >>12
480 }
Eric Laurenta1a96f32010-08-04 06:33:52 -0700481 }
482
Eric Laurenta7e56482010-08-24 14:21:57 -0700483 if (pContext->preset && pContext->curPreset == REVERB_PRESET_NONE) {
Eric Laurent5fa6df62010-09-02 17:18:20 -0700484 memset(pContext->OutFrames32, 0, frameCount * sizeof(LVM_INT32) * 2); //always stereo here
Eric Laurenta7e56482010-08-24 14:21:57 -0700485 } else {
Eric Laurent5fa6df62010-09-02 17:18:20 -0700486 if(pContext->bEnabled == LVM_FALSE && pContext->SamplesToExitCount > 0) {
Eric Laurent305443c2010-09-09 12:01:11 -0700487 memset(pContext->InFrames32,0,frameCount * sizeof(LVM_INT32) * samplesPerFrame);
Steve Block06ade6a2011-10-20 11:56:00 +0100488 ALOGV("\tZeroing %d samples per frame at the end of call", samplesPerFrame);
Eric Laurenta7e56482010-08-24 14:21:57 -0700489 }
Eric Laurent5fa6df62010-09-02 17:18:20 -0700490
Eric Laurent305443c2010-09-09 12:01:11 -0700491 /* Process the samples, producing a stereo output */
Eric Laurent5fa6df62010-09-02 17:18:20 -0700492 LvmStatus = LVREV_Process(pContext->hInstance, /* Instance handle */
493 pContext->InFrames32, /* Input buffer */
494 pContext->OutFrames32, /* Output buffer */
495 frameCount); /* Number of samples to read */
Eric Laurenta7e56482010-08-24 14:21:57 -0700496 }
Eric Laurenta1a96f32010-08-04 06:33:52 -0700497
498 LVM_ERROR_CHECK(LvmStatus, "LVREV_Process", "process")
499 if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
500
501 // Convert to 16 bits
Eric Laurent5fa6df62010-09-02 17:18:20 -0700502 if (pContext->auxiliary) {
503 for (int i=0; i < frameCount*2; i++) { //always stereo here
504 OutFrames16[i] = clamp16(pContext->OutFrames32[i]>>8);
505 }
506 } else {
507 for (int i=0; i < frameCount*2; i++) { //always stereo here
508 OutFrames16[i] = clamp16((pContext->OutFrames32[i]>>8) + (LVM_INT32)pIn[i]);
509 }
Eric Laurent27a2fdf2010-09-10 17:44:44 -0700510
511 // apply volume with ramp if needed
512 if ((pContext->leftVolume != pContext->prevLeftVolume ||
513 pContext->rightVolume != pContext->prevRightVolume) &&
514 pContext->volumeMode == REVERB_VOLUME_RAMP) {
515 LVM_INT32 vl = (LVM_INT32)pContext->prevLeftVolume << 16;
516 LVM_INT32 incl = (((LVM_INT32)pContext->leftVolume << 16) - vl) / frameCount;
517 LVM_INT32 vr = (LVM_INT32)pContext->prevRightVolume << 16;
518 LVM_INT32 incr = (((LVM_INT32)pContext->rightVolume << 16) - vr) / frameCount;
519
520 for (int i = 0; i < frameCount; i++) {
521 OutFrames16[2*i] =
522 clamp16((LVM_INT32)((vl >> 16) * OutFrames16[2*i]) >> 12);
523 OutFrames16[2*i+1] =
524 clamp16((LVM_INT32)((vr >> 16) * OutFrames16[2*i+1]) >> 12);
525
526 vl += incl;
527 vr += incr;
528 }
529
530 pContext->prevLeftVolume = pContext->leftVolume;
531 pContext->prevRightVolume = pContext->rightVolume;
532 } else if (pContext->volumeMode != REVERB_VOLUME_OFF) {
533 if (pContext->leftVolume != REVERB_UNIT_VOLUME ||
534 pContext->rightVolume != REVERB_UNIT_VOLUME) {
535 for (int i = 0; i < frameCount; i++) {
536 OutFrames16[2*i] =
537 clamp16((LVM_INT32)(pContext->leftVolume * OutFrames16[2*i]) >> 12);
538 OutFrames16[2*i+1] =
539 clamp16((LVM_INT32)(pContext->rightVolume * OutFrames16[2*i+1]) >> 12);
540 }
541 }
542 pContext->prevLeftVolume = pContext->leftVolume;
543 pContext->prevRightVolume = pContext->rightVolume;
544 pContext->volumeMode = REVERB_VOLUME_RAMP;
545 }
Eric Laurenta1a96f32010-08-04 06:33:52 -0700546 }
547
548 #ifdef LVM_PCM
Eric Laurent5fa6df62010-09-02 17:18:20 -0700549 fwrite(OutFrames16, frameCount*sizeof(LVM_INT16)*2, 1, pContext->PcmOutPtr);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700550 fflush(pContext->PcmOutPtr);
551 #endif
552
553 // Accumulate if required
554 if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE){
Steve Block06ade6a2011-10-20 11:56:00 +0100555 //ALOGV("\tBuffer access is ACCUMULATE");
Eric Laurent5fa6df62010-09-02 17:18:20 -0700556 for (int i=0; i<frameCount*2; i++){ //always stereo here
Eric Laurenta7e56482010-08-24 14:21:57 -0700557 pOut[i] = clamp16((int32_t)pOut[i] + (int32_t)OutFrames16[i]);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700558 }
559 }else{
Steve Block06ade6a2011-10-20 11:56:00 +0100560 //ALOGV("\tBuffer access is WRITE");
Eric Laurent5fa6df62010-09-02 17:18:20 -0700561 memcpy(pOut, OutFrames16, frameCount*sizeof(LVM_INT16)*2);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700562 }
563
Eric Laurenta1a96f32010-08-04 06:33:52 -0700564 return 0;
565} /* end process */
566
567//----------------------------------------------------------------------------
568// Reverb_free()
569//----------------------------------------------------------------------------
570// Purpose: Free all memory associated with the Bundle.
571//
572// Inputs:
573// pContext: effect engine context
574//
575// Outputs:
576//
577//----------------------------------------------------------------------------
578
579void Reverb_free(ReverbContext *pContext){
580
581 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
582 LVREV_ControlParams_st params; /* Control Parameters */
583 LVREV_MemoryTable_st MemTab;
584
585 /* Free the algorithm memory */
586 LvmStatus = LVREV_GetMemoryTable(pContext->hInstance,
587 &MemTab,
588 LVM_NULL);
589
590 LVM_ERROR_CHECK(LvmStatus, "LVM_GetMemoryTable", "Reverb_free")
591
592 for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
593 if (MemTab.Region[i].Size != 0){
594 if (MemTab.Region[i].pBaseAddress != NULL){
Steve Block06ade6a2011-10-20 11:56:00 +0100595 ALOGV("\tfree() - START freeing %ld bytes for region %u at %p\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -0700596 MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
597
598 free(MemTab.Region[i].pBaseAddress);
599
Steve Block06ade6a2011-10-20 11:56:00 +0100600 ALOGV("\tfree() - END freeing %ld bytes for region %u at %p\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -0700601 MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
602 }else{
Steve Block06ade6a2011-10-20 11:56:00 +0100603 ALOGV("\tLVM_ERROR : free() - trying to free with NULL pointer %ld bytes "
Eric Laurenta1a96f32010-08-04 06:33:52 -0700604 "for region %u at %p ERROR\n",
605 MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
606 }
607 }
608 }
609} /* end Reverb_free */
610
611//----------------------------------------------------------------------------
612// Reverb_configure()
613//----------------------------------------------------------------------------
614// Purpose: Set input and output audio configuration.
615//
616// Inputs:
617// pContext: effect engine context
618// pConfig: pointer to effect_config_t structure holding input and output
619// configuration parameters
620//
621// Outputs:
622//
623//----------------------------------------------------------------------------
624
625int Reverb_configure(ReverbContext *pContext, effect_config_t *pConfig){
626 LVM_Fs_en SampleRate;
Steve Block06ade6a2011-10-20 11:56:00 +0100627 //ALOGV("\tReverb_configure start");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700628
629 CHECK_ARG(pContext != NULL);
630 CHECK_ARG(pConfig != NULL);
631
632 CHECK_ARG(pConfig->inputCfg.samplingRate == pConfig->outputCfg.samplingRate);
633 CHECK_ARG(pConfig->inputCfg.format == pConfig->outputCfg.format);
Eric Laurent0fb66c22011-05-17 19:16:02 -0700634 CHECK_ARG((pContext->auxiliary && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_MONO) ||
635 ((!pContext->auxiliary) && pConfig->inputCfg.channels == AUDIO_CHANNEL_OUT_STEREO));
636 CHECK_ARG(pConfig->outputCfg.channels == AUDIO_CHANNEL_OUT_STEREO);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700637 CHECK_ARG(pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_WRITE
638 || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE);
Eric Laurent0fb66c22011-05-17 19:16:02 -0700639 CHECK_ARG(pConfig->inputCfg.format == AUDIO_FORMAT_PCM_16_BIT);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700640
641 if(pConfig->inputCfg.samplingRate != 44100){
642 return -EINVAL;
643 }
644
Steve Block06ade6a2011-10-20 11:56:00 +0100645 //ALOGV("\tReverb_configure calling memcpy");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700646 memcpy(&pContext->config, pConfig, sizeof(effect_config_t));
647
Eric Laurent5fa6df62010-09-02 17:18:20 -0700648
Eric Laurenta1a96f32010-08-04 06:33:52 -0700649 switch (pConfig->inputCfg.samplingRate) {
650 case 8000:
651 SampleRate = LVM_FS_8000;
652 break;
653 case 16000:
654 SampleRate = LVM_FS_16000;
655 break;
656 case 22050:
657 SampleRate = LVM_FS_22050;
658 break;
659 case 32000:
660 SampleRate = LVM_FS_32000;
661 break;
662 case 44100:
663 SampleRate = LVM_FS_44100;
664 break;
665 case 48000:
666 SampleRate = LVM_FS_48000;
667 break;
668 default:
Steve Block06ade6a2011-10-20 11:56:00 +0100669 ALOGV("\rReverb_Configure invalid sampling rate %d", pConfig->inputCfg.samplingRate);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700670 return -EINVAL;
671 }
672
673 if(pContext->SampleRate != SampleRate){
674
675 LVREV_ControlParams_st ActiveParams;
676 LVREV_ReturnStatus_en LvmStatus = LVREV_SUCCESS;
677
Steve Block06ade6a2011-10-20 11:56:00 +0100678 //ALOGV("\tReverb_configure change sampling rate to %d", SampleRate);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700679
680 /* Get the current settings */
681 LvmStatus = LVREV_GetControlParameters(pContext->hInstance,
682 &ActiveParams);
683
684 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "Reverb_configure")
685 if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
686
687 LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
688
689 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "Reverb_configure")
Steve Block06ade6a2011-10-20 11:56:00 +0100690 //ALOGV("\tReverb_configure Succesfully called LVREV_SetControlParameters\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700691
692 }else{
Steve Block06ade6a2011-10-20 11:56:00 +0100693 //ALOGV("\tReverb_configure keep sampling rate at %d", SampleRate);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700694 }
695
Steve Block06ade6a2011-10-20 11:56:00 +0100696 //ALOGV("\tReverb_configure End");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700697 return 0;
698} /* end Reverb_configure */
699
700
701//----------------------------------------------------------------------------
702// Reverb_init()
703//----------------------------------------------------------------------------
704// Purpose: Initialize engine with default configuration
705//
706// Inputs:
707// pContext: effect engine context
708//
709// Outputs:
710//
711//----------------------------------------------------------------------------
712
713int Reverb_init(ReverbContext *pContext){
714 int status;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700715
Steve Block06ade6a2011-10-20 11:56:00 +0100716 ALOGV("\tReverb_init start");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700717
718 CHECK_ARG(pContext != NULL);
719
720 if (pContext->hInstance != NULL){
721 Reverb_free(pContext);
722 }
723
724 pContext->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
Eric Laurenta7e56482010-08-24 14:21:57 -0700725 if (pContext->auxiliary) {
Eric Laurent0fb66c22011-05-17 19:16:02 -0700726 pContext->config.inputCfg.channels = AUDIO_CHANNEL_OUT_MONO;
Eric Laurenta7e56482010-08-24 14:21:57 -0700727 } else {
Eric Laurent0fb66c22011-05-17 19:16:02 -0700728 pContext->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
Eric Laurenta7e56482010-08-24 14:21:57 -0700729 }
730
Eric Laurent0fb66c22011-05-17 19:16:02 -0700731 pContext->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700732 pContext->config.inputCfg.samplingRate = 44100;
733 pContext->config.inputCfg.bufferProvider.getBuffer = NULL;
734 pContext->config.inputCfg.bufferProvider.releaseBuffer = NULL;
735 pContext->config.inputCfg.bufferProvider.cookie = NULL;
736 pContext->config.inputCfg.mask = EFFECT_CONFIG_ALL;
737 pContext->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
Eric Laurent0fb66c22011-05-17 19:16:02 -0700738 pContext->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
739 pContext->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700740 pContext->config.outputCfg.samplingRate = 44100;
741 pContext->config.outputCfg.bufferProvider.getBuffer = NULL;
742 pContext->config.outputCfg.bufferProvider.releaseBuffer = NULL;
743 pContext->config.outputCfg.bufferProvider.cookie = NULL;
744 pContext->config.outputCfg.mask = EFFECT_CONFIG_ALL;
745
Eric Laurent27a2fdf2010-09-10 17:44:44 -0700746 pContext->leftVolume = REVERB_UNIT_VOLUME;
747 pContext->rightVolume = REVERB_UNIT_VOLUME;
748 pContext->prevLeftVolume = REVERB_UNIT_VOLUME;
749 pContext->prevRightVolume = REVERB_UNIT_VOLUME;
750 pContext->volumeMode = REVERB_VOLUME_FLAT;
751
Eric Laurenta1a96f32010-08-04 06:33:52 -0700752 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
753 LVREV_ControlParams_st params; /* Control Parameters */
754 LVREV_InstanceParams_st InstParams; /* Instance parameters */
755 LVREV_MemoryTable_st MemTab; /* Memory allocation table */
756 bool bMallocFailure = LVM_FALSE;
757
758 /* Set the capabilities */
759 InstParams.MaxBlockSize = MAX_CALL_SIZE;
Eric Laurent305443c2010-09-09 12:01:11 -0700760 InstParams.SourceFormat = LVM_STEREO; // Max format, could be mono during process
Eric Laurenta1a96f32010-08-04 06:33:52 -0700761 InstParams.NumDelays = LVREV_DELAYLINES_4;
762
763 /* Allocate memory, forcing alignment */
764 LvmStatus = LVREV_GetMemoryTable(LVM_NULL,
765 &MemTab,
766 &InstParams);
767
768 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetMemoryTable", "Reverb_init")
769 if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
770
Steve Block06ade6a2011-10-20 11:56:00 +0100771 ALOGV("\tCreateInstance Succesfully called LVM_GetMemoryTable\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700772
773 /* Allocate memory */
774 for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
775 if (MemTab.Region[i].Size != 0){
776 MemTab.Region[i].pBaseAddress = malloc(MemTab.Region[i].Size);
777
778 if (MemTab.Region[i].pBaseAddress == LVM_NULL){
Steve Block06ade6a2011-10-20 11:56:00 +0100779 ALOGV("\tLVREV_ERROR :Reverb_init CreateInstance Failed to allocate %ld "
Eric Laurentadecf1c2010-08-27 10:52:56 -0700780 "bytes for region %u\n", MemTab.Region[i].Size, i );
Eric Laurenta1a96f32010-08-04 06:33:52 -0700781 bMallocFailure = LVM_TRUE;
782 }else{
Steve Block06ade6a2011-10-20 11:56:00 +0100783 ALOGV("\tReverb_init CreateInstance allocate %ld bytes for region %u at %p\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -0700784 MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
785 }
786 }
787 }
788
789 /* If one or more of the memory regions failed to allocate, free the regions that were
790 * succesfully allocated and return with an error
791 */
792 if(bMallocFailure == LVM_TRUE){
793 for (int i=0; i<LVM_NR_MEMORY_REGIONS; i++){
794 if (MemTab.Region[i].pBaseAddress == LVM_NULL){
Steve Block06ade6a2011-10-20 11:56:00 +0100795 ALOGV("\tLVM_ERROR :Reverb_init CreateInstance Failed to allocate %ld bytes "
Eric Laurentadecf1c2010-08-27 10:52:56 -0700796 "for region %u - Not freeing\n", MemTab.Region[i].Size, i );
Eric Laurenta1a96f32010-08-04 06:33:52 -0700797 }else{
Steve Block06ade6a2011-10-20 11:56:00 +0100798 ALOGV("\tLVM_ERROR :Reverb_init CreateInstance Failed: but allocated %ld bytes "
Eric Laurentadecf1c2010-08-27 10:52:56 -0700799 "for region %u at %p- free\n",
800 MemTab.Region[i].Size, i, MemTab.Region[i].pBaseAddress);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700801 free(MemTab.Region[i].pBaseAddress);
802 }
803 }
804 return -EINVAL;
805 }
Steve Block06ade6a2011-10-20 11:56:00 +0100806 ALOGV("\tReverb_init CreateInstance Succesfully malloc'd memory\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700807
808 /* Initialise */
809 pContext->hInstance = LVM_NULL;
810
811 /* Init sets the instance handle */
812 LvmStatus = LVREV_GetInstanceHandle(&pContext->hInstance,
813 &MemTab,
814 &InstParams);
815
816 LVM_ERROR_CHECK(LvmStatus, "LVM_GetInstanceHandle", "Reverb_init")
817 if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
818
Steve Block06ade6a2011-10-20 11:56:00 +0100819 ALOGV("\tReverb_init CreateInstance Succesfully called LVM_GetInstanceHandle\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700820
821 /* Set the initial process parameters */
822 /* General parameters */
823 params.OperatingMode = LVM_MODE_ON;
824 params.SampleRate = LVM_FS_44100;
Eric Laurent305443c2010-09-09 12:01:11 -0700825
Eric Laurent0fb66c22011-05-17 19:16:02 -0700826 if(pContext->config.inputCfg.channels == AUDIO_CHANNEL_OUT_MONO){
Eric Laurent305443c2010-09-09 12:01:11 -0700827 params.SourceFormat = LVM_MONO;
828 } else {
829 params.SourceFormat = LVM_STEREO;
830 }
Eric Laurenta1a96f32010-08-04 06:33:52 -0700831
832 /* Reverb parameters */
833 params.Level = 0;
834 params.LPF = 23999;
Eric Laurenta7e56482010-08-24 14:21:57 -0700835 params.HPF = 50;
836 params.T60 = 1490;
837 params.Density = 100;
838 params.Damping = 21;
839 params.RoomSize = 100;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700840
Eric Laurent5fa6df62010-09-02 17:18:20 -0700841 pContext->SamplesToExitCount = (params.T60 * pContext->config.inputCfg.samplingRate)/1000;
842
Eric Laurenta1a96f32010-08-04 06:33:52 -0700843 /* Saved strength is used to return the exact strength that was used in the set to the get
844 * because we map the original strength range of 0:1000 to 1:15, and this will avoid
845 * quantisation like effect when returning
846 */
847 pContext->SavedRoomLevel = -6000;
848 pContext->SavedHfLevel = 0;
849 pContext->bEnabled = LVM_FALSE;
850 pContext->SavedDecayTime = params.T60;
Eric Laurentadecf1c2010-08-27 10:52:56 -0700851 pContext->SavedDecayHfRatio = params.Damping*20;
Eric Laurenta1a96f32010-08-04 06:33:52 -0700852 pContext->SavedDensity = params.RoomSize*10;
853 pContext->SavedDiffusion = params.Density*10;
854 pContext->SavedReverbLevel = -6000;
855
856 /* Activate the initial settings */
857 LvmStatus = LVREV_SetControlParameters(pContext->hInstance,
858 &params);
859
860 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "Reverb_init")
861 if(LvmStatus != LVREV_SUCCESS) return -EINVAL;
862
Steve Block06ade6a2011-10-20 11:56:00 +0100863 ALOGV("\tReverb_init CreateInstance Succesfully called LVREV_SetControlParameters\n");
864 ALOGV("\tReverb_init End");
Eric Laurenta1a96f32010-08-04 06:33:52 -0700865 return 0;
866} /* end Reverb_init */
867
868//----------------------------------------------------------------------------
869// ReverbConvertLevel()
870//----------------------------------------------------------------------------
871// Purpose:
872// Convert level from OpenSL ES format to LVM format
873//
874// Inputs:
875// level level to be applied
876//
877//----------------------------------------------------------------------------
878
879int16_t ReverbConvertLevel(int16_t level){
880 static int16_t LevelArray[101] =
881 {
882 -12000, -4000, -3398, -3046, -2796, -2603, -2444, -2310, -2194, -2092,
883 -2000, -1918, -1842, -1773, -1708, -1648, -1592, -1540, -1490, -1443,
884 -1398, -1356, -1316, -1277, -1240, -1205, -1171, -1138, -1106, -1076,
885 -1046, -1018, -990, -963, -938, -912, -888, -864, -841, -818,
886 -796, -775, -754, -734, -714, -694, -675, -656, -638, -620,
887 -603, -585, -568, -552, -536, -520, -504, -489, -474, -459,
888 -444, -430, -416, -402, -388, -375, -361, -348, -335, -323,
889 -310, -298, -286, -274, -262, -250, -239, -228, -216, -205,
890 -194, -184, -173, -162, -152, -142, -132, -121, -112, -102,
891 -92, -82, -73, -64, -54, -45, -36, -27, -18, -9,
892 0
893 };
894 int16_t i;
895
896 for(i = 0; i < 101; i++)
897 {
898 if(level <= LevelArray[i])
899 break;
900 }
901 return i;
902}
903
904//----------------------------------------------------------------------------
905// ReverbConvertHFLevel()
906//----------------------------------------------------------------------------
907// Purpose:
908// Convert level from OpenSL ES format to LVM format
909//
910// Inputs:
911// level level to be applied
912//
913//----------------------------------------------------------------------------
914
915int16_t ReverbConvertHfLevel(int16_t Hflevel){
916 int16_t i;
917
918 static LPFPair_t LPFArray[97] =
919 { // Limit range to 50 for LVREV parameter range
920 {-10000, 50}, { -5000, 50 }, { -4000, 50}, { -3000, 158}, { -2000, 502},
921 {-1000, 1666},{ -900, 1897}, { -800, 2169}, { -700, 2496}, { -600, 2895},
922 {-500, 3400}, { -400, 4066}, { -300, 5011}, { -200, 6537}, { -100, 9826},
923 {-99, 9881 }, { -98, 9937 }, { -97, 9994 }, { -96, 10052}, { -95, 10111},
924 {-94, 10171}, { -93, 10231}, { -92, 10293}, { -91, 10356}, { -90, 10419},
925 {-89, 10484}, { -88, 10549}, { -87, 10616}, { -86, 10684}, { -85, 10753},
926 {-84, 10823}, { -83, 10895}, { -82, 10968}, { -81, 11042}, { -80, 11117},
927 {-79, 11194}, { -78, 11272}, { -77, 11352}, { -76, 11433}, { -75, 11516},
928 {-74, 11600}, { -73, 11686}, { -72, 11774}, { -71, 11864}, { -70, 11955},
929 {-69, 12049}, { -68, 12144}, { -67, 12242}, { -66, 12341}, { -65, 12443},
930 {-64, 12548}, { -63, 12654}, { -62, 12763}, { -61, 12875}, { -60, 12990},
931 {-59, 13107}, { -58, 13227}, { -57, 13351}, { -56, 13477}, { -55, 13607},
932 {-54, 13741}, { -53, 13878}, { -52, 14019}, { -51, 14164}, { -50, 14313},
933 {-49, 14467}, { -48, 14626}, { -47, 14789}, { -46, 14958}, { -45, 15132},
934 {-44, 15312}, { -43, 15498}, { -42, 15691}, { -41, 15890}, { -40, 16097},
935 {-39, 16311}, { -38, 16534}, { -37, 16766}, { -36, 17007}, { -35, 17259},
936 {-34, 17521}, { -33, 17795}, { -32, 18081}, { -31, 18381}, { -30, 18696},
937 {-29, 19027}, { -28, 19375}, { -27, 19742}, { -26, 20129}, { -25, 20540},
938 {-24, 20976}, { -23, 21439}, { -22, 21934}, { -21, 22463}, { -20, 23031},
939 {-19, 23643}, { -18, 23999}
940 };
941
942 for(i = 0; i < 96; i++)
943 {
944 if(Hflevel <= LPFArray[i].Room_HF)
945 break;
946 }
947 return LPFArray[i].LPF;
948}
949
950//----------------------------------------------------------------------------
951// ReverbSetRoomHfLevel()
952//----------------------------------------------------------------------------
953// Purpose:
954// Apply the HF level to the Reverb. Must first be converted to LVM format
955//
956// Inputs:
957// pContext: effect engine context
958// level level to be applied
959//
960//----------------------------------------------------------------------------
961
962void ReverbSetRoomHfLevel(ReverbContext *pContext, int16_t level){
Steve Block06ade6a2011-10-20 11:56:00 +0100963 //ALOGV("\tReverbSetRoomHfLevel start (%d)", level);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700964
965 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
966 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
967
968 /* Get the current settings */
969 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
970 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetRoomHfLevel")
Steve Block06ade6a2011-10-20 11:56:00 +0100971 //ALOGV("\tReverbSetRoomHfLevel Succesfully returned from LVM_GetControlParameters\n");
972 //ALOGV("\tReverbSetRoomHfLevel() just Got -> %d\n", ActiveParams.LPF);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700973
974 ActiveParams.LPF = ReverbConvertHfLevel(level);
975
976 /* Activate the initial settings */
977 LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
978 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetRoomHfLevel")
Steve Block06ade6a2011-10-20 11:56:00 +0100979 //ALOGV("\tReverbSetRoomhfLevel() just Set -> %d\n", ActiveParams.LPF);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700980 pContext->SavedHfLevel = level;
Steve Block06ade6a2011-10-20 11:56:00 +0100981 //ALOGV("\tReverbSetHfRoomLevel end.. saving %d", pContext->SavedHfLevel);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700982 return;
983}
984
985//----------------------------------------------------------------------------
986// ReverbGetRoomHfLevel()
987//----------------------------------------------------------------------------
988// Purpose:
989// Get the level applied to the Revervb. Must first be converted to LVM format
990//
991// Inputs:
992// pContext: effect engine context
993//
994//----------------------------------------------------------------------------
995
996int16_t ReverbGetRoomHfLevel(ReverbContext *pContext){
997 int16_t level;
Steve Block06ade6a2011-10-20 11:56:00 +0100998 //ALOGV("\tReverbGetRoomHfLevel start, saved level is %d", pContext->SavedHfLevel);
Eric Laurenta1a96f32010-08-04 06:33:52 -0700999
1000 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1001 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1002
1003 /* Get the current settings */
1004 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1005 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetRoomHfLevel")
Steve Block06ade6a2011-10-20 11:56:00 +01001006 //ALOGV("\tReverbGetRoomHfLevel Succesfully returned from LVM_GetControlParameters\n");
1007 //ALOGV("\tReverbGetRoomHfLevel() just Got -> %d\n", ActiveParams.LPF);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001008
1009 level = ReverbConvertHfLevel(pContext->SavedHfLevel);
1010
Steve Block06ade6a2011-10-20 11:56:00 +01001011 //ALOGV("\tReverbGetRoomHfLevel() ActiveParams.LPFL %d, pContext->SavedHfLevel: %d, "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001012 // "converted level: %d\n", ActiveParams.LPF, pContext->SavedHfLevel, level);
1013
1014 if(ActiveParams.LPF != level){
Steve Block06ade6a2011-10-20 11:56:00 +01001015 ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetRoomHfLevel() has wrong level -> %d %d\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001016 ActiveParams.Level, level);
1017 }
1018
Steve Block06ade6a2011-10-20 11:56:00 +01001019 //ALOGV("\tReverbGetRoomHfLevel end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001020 return pContext->SavedHfLevel;
1021}
1022
1023//----------------------------------------------------------------------------
1024// ReverbSetReverbLevel()
1025//----------------------------------------------------------------------------
1026// Purpose:
1027// Apply the level to the Reverb. Must first be converted to LVM format
1028//
1029// Inputs:
1030// pContext: effect engine context
1031// level level to be applied
1032//
1033//----------------------------------------------------------------------------
1034
1035void ReverbSetReverbLevel(ReverbContext *pContext, int16_t level){
Steve Block06ade6a2011-10-20 11:56:00 +01001036 //ALOGV("\n\tReverbSetReverbLevel start (%d)", level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001037
1038 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1039 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1040 LVM_INT32 CombinedLevel; // Sum of room and reverb level controls
1041
1042 /* Get the current settings */
1043 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1044 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetReverbLevel")
Steve Block06ade6a2011-10-20 11:56:00 +01001045 //ALOGV("\tReverbSetReverbLevel Succesfully returned from LVM_GetControlParameters\n");
1046 //ALOGV("\tReverbSetReverbLevel just Got -> %d\n", ActiveParams.Level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001047
1048 // needs to subtract max levels for both RoomLevel and ReverbLevel
1049 CombinedLevel = (level + pContext->SavedRoomLevel)-LVREV_MAX_REVERB_LEVEL;
Steve Block06ade6a2011-10-20 11:56:00 +01001050 //ALOGV("\tReverbSetReverbLevel() CombinedLevel is %d = %d + %d\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001051 // CombinedLevel, level, pContext->SavedRoomLevel);
1052
1053 ActiveParams.Level = ReverbConvertLevel(CombinedLevel);
1054
Steve Block06ade6a2011-10-20 11:56:00 +01001055 //ALOGV("\tReverbSetReverbLevel() Trying to set -> %d\n", ActiveParams.Level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001056
1057 /* Activate the initial settings */
1058 LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1059 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetReverbLevel")
Steve Block06ade6a2011-10-20 11:56:00 +01001060 //ALOGV("\tReverbSetReverbLevel() just Set -> %d\n", ActiveParams.Level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001061
1062 pContext->SavedReverbLevel = level;
Steve Block06ade6a2011-10-20 11:56:00 +01001063 //ALOGV("\tReverbSetReverbLevel end pContext->SavedReverbLevel is %d\n\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001064 // pContext->SavedReverbLevel);
1065 return;
1066}
1067
1068//----------------------------------------------------------------------------
1069// ReverbGetReverbLevel()
1070//----------------------------------------------------------------------------
1071// Purpose:
1072// Get the level applied to the Revervb. Must first be converted to LVM format
1073//
1074// Inputs:
1075// pContext: effect engine context
1076//
1077//----------------------------------------------------------------------------
1078
1079int16_t ReverbGetReverbLevel(ReverbContext *pContext){
1080 int16_t level;
Steve Block06ade6a2011-10-20 11:56:00 +01001081 //ALOGV("\tReverbGetReverbLevel start");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001082
1083 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1084 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1085 LVM_INT32 CombinedLevel; // Sum of room and reverb level controls
1086
1087 /* Get the current settings */
1088 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1089 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetReverbLevel")
Steve Block06ade6a2011-10-20 11:56:00 +01001090 //ALOGV("\tReverbGetReverbLevel Succesfully returned from LVM_GetControlParameters\n");
1091 //ALOGV("\tReverbGetReverbLevel() just Got -> %d\n", ActiveParams.Level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001092
1093 // needs to subtract max levels for both RoomLevel and ReverbLevel
1094 CombinedLevel = (pContext->SavedReverbLevel + pContext->SavedRoomLevel)-LVREV_MAX_REVERB_LEVEL;
1095
Steve Block06ade6a2011-10-20 11:56:00 +01001096 //ALOGV("\tReverbGetReverbLevel() CombinedLevel is %d = %d + %d\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001097 //CombinedLevel, pContext->SavedReverbLevel, pContext->SavedRoomLevel);
1098 level = ReverbConvertLevel(CombinedLevel);
1099
Steve Block06ade6a2011-10-20 11:56:00 +01001100 //ALOGV("\tReverbGetReverbLevel(): ActiveParams.Level: %d, pContext->SavedReverbLevel: %d, "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001101 //"pContext->SavedRoomLevel: %d, CombinedLevel: %d, converted level: %d\n",
1102 //ActiveParams.Level, pContext->SavedReverbLevel,pContext->SavedRoomLevel, CombinedLevel,level);
1103
1104 if(ActiveParams.Level != level){
Steve Block06ade6a2011-10-20 11:56:00 +01001105 ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetReverbLevel() has wrong level -> %d %d\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001106 ActiveParams.Level, level);
1107 }
1108
Steve Block06ade6a2011-10-20 11:56:00 +01001109 //ALOGV("\tReverbGetReverbLevel end\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001110
1111 return pContext->SavedReverbLevel;
1112}
1113
1114//----------------------------------------------------------------------------
1115// ReverbSetRoomLevel()
1116//----------------------------------------------------------------------------
1117// Purpose:
1118// Apply the level to the Reverb. Must first be converted to LVM format
1119//
1120// Inputs:
1121// pContext: effect engine context
1122// level level to be applied
1123//
1124//----------------------------------------------------------------------------
1125
1126void ReverbSetRoomLevel(ReverbContext *pContext, int16_t level){
Steve Block06ade6a2011-10-20 11:56:00 +01001127 //ALOGV("\tReverbSetRoomLevel start (%d)", level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001128
1129 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1130 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1131 LVM_INT32 CombinedLevel; // Sum of room and reverb level controls
1132
1133 /* Get the current settings */
1134 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1135 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetRoomLevel")
Steve Block06ade6a2011-10-20 11:56:00 +01001136 //ALOGV("\tReverbSetRoomLevel Succesfully returned from LVM_GetControlParameters\n");
1137 //ALOGV("\tReverbSetRoomLevel() just Got -> %d\n", ActiveParams.Level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001138
1139 // needs to subtract max levels for both RoomLevel and ReverbLevel
1140 CombinedLevel = (level + pContext->SavedReverbLevel)-LVREV_MAX_REVERB_LEVEL;
1141 ActiveParams.Level = ReverbConvertLevel(CombinedLevel);
1142
1143 /* Activate the initial settings */
1144 LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1145 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetRoomLevel")
Steve Block06ade6a2011-10-20 11:56:00 +01001146 //ALOGV("\tReverbSetRoomLevel() just Set -> %d\n", ActiveParams.Level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001147
1148 pContext->SavedRoomLevel = level;
Steve Block06ade6a2011-10-20 11:56:00 +01001149 //ALOGV("\tReverbSetRoomLevel end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001150 return;
1151}
1152
1153//----------------------------------------------------------------------------
1154// ReverbGetRoomLevel()
1155//----------------------------------------------------------------------------
1156// Purpose:
1157// Get the level applied to the Revervb. Must first be converted to LVM format
1158//
1159// Inputs:
1160// pContext: effect engine context
1161//
1162//----------------------------------------------------------------------------
1163
1164int16_t ReverbGetRoomLevel(ReverbContext *pContext){
1165 int16_t level;
Steve Block06ade6a2011-10-20 11:56:00 +01001166 //ALOGV("\tReverbGetRoomLevel start");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001167
1168 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1169 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1170 LVM_INT32 CombinedLevel; // Sum of room and reverb level controls
1171
1172 /* Get the current settings */
1173 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1174 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetRoomLevel")
Steve Block06ade6a2011-10-20 11:56:00 +01001175 //ALOGV("\tReverbGetRoomLevel Succesfully returned from LVM_GetControlParameters\n");
1176 //ALOGV("\tReverbGetRoomLevel() just Got -> %d\n", ActiveParams.Level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001177
1178 // needs to subtract max levels for both RoomLevel and ReverbLevel
1179 CombinedLevel = (pContext->SavedRoomLevel + pContext->SavedReverbLevel-LVREV_MAX_REVERB_LEVEL);
1180 level = ReverbConvertLevel(CombinedLevel);
1181
Steve Block06ade6a2011-10-20 11:56:00 +01001182 //ALOGV("\tReverbGetRoomLevel, Level = %d, pContext->SavedRoomLevel = %d, "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001183 // "pContext->SavedReverbLevel = %d, CombinedLevel = %d, level = %d",
Eric Laurent5fa6df62010-09-02 17:18:20 -07001184 // ActiveParams.Level, pContext->SavedRoomLevel,
1185 // pContext->SavedReverbLevel, CombinedLevel, level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001186
1187 if(ActiveParams.Level != level){
Steve Block06ade6a2011-10-20 11:56:00 +01001188 ALOGV("\tLVM_ERROR : (ignore at start up) ReverbGetRoomLevel() has wrong level -> %d %d\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001189 ActiveParams.Level, level);
1190 }
1191
Steve Block06ade6a2011-10-20 11:56:00 +01001192 //ALOGV("\tReverbGetRoomLevel end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001193 return pContext->SavedRoomLevel;
1194}
1195
1196//----------------------------------------------------------------------------
1197// ReverbSetDecayTime()
1198//----------------------------------------------------------------------------
1199// Purpose:
1200// Apply the decay time to the Reverb.
1201//
1202// Inputs:
1203// pContext: effect engine context
1204// time decay to be applied
1205//
1206//----------------------------------------------------------------------------
1207
1208void ReverbSetDecayTime(ReverbContext *pContext, uint32_t time){
Steve Block06ade6a2011-10-20 11:56:00 +01001209 //ALOGV("\tReverbSetDecayTime start (%d)", time);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001210
1211 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1212 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1213
1214 /* Get the current settings */
1215 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1216 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDecayTime")
Steve Block06ade6a2011-10-20 11:56:00 +01001217 //ALOGV("\tReverbSetDecayTime Succesfully returned from LVM_GetControlParameters\n");
1218 //ALOGV("\tReverbSetDecayTime() just Got -> %d\n", ActiveParams.T60);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001219
1220 if (time <= LVREV_MAX_T60) {
Eric Laurent95d5de02010-09-08 16:06:18 -07001221 ActiveParams.T60 = (LVM_UINT16)time;
Eric Laurenta1a96f32010-08-04 06:33:52 -07001222 }
1223 else {
1224 ActiveParams.T60 = LVREV_MAX_T60;
1225 }
1226
1227 /* Activate the initial settings */
1228 LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1229 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDecayTime")
Steve Block06ade6a2011-10-20 11:56:00 +01001230 //ALOGV("\tReverbSetDecayTime() just Set -> %d\n", ActiveParams.T60);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001231
Eric Laurent5fa6df62010-09-02 17:18:20 -07001232 pContext->SamplesToExitCount = (ActiveParams.T60 * pContext->config.inputCfg.samplingRate)/1000;
Steve Block06ade6a2011-10-20 11:56:00 +01001233 //ALOGV("\tReverbSetDecayTime() just Set SamplesToExitCount-> %d\n",pContext->SamplesToExitCount);
Eric Laurent95d5de02010-09-08 16:06:18 -07001234 pContext->SavedDecayTime = (int16_t)time;
Steve Block06ade6a2011-10-20 11:56:00 +01001235 //ALOGV("\tReverbSetDecayTime end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001236 return;
1237}
1238
1239//----------------------------------------------------------------------------
1240// ReverbGetDecayTime()
1241//----------------------------------------------------------------------------
1242// Purpose:
1243// Get the decay time applied to the Revervb.
1244//
1245// Inputs:
1246// pContext: effect engine context
1247//
1248//----------------------------------------------------------------------------
1249
Eric Laurent95d5de02010-09-08 16:06:18 -07001250uint32_t ReverbGetDecayTime(ReverbContext *pContext){
Steve Block06ade6a2011-10-20 11:56:00 +01001251 //ALOGV("\tReverbGetDecayTime start");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001252
1253 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1254 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1255
1256 /* Get the current settings */
1257 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1258 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDecayTime")
Steve Block06ade6a2011-10-20 11:56:00 +01001259 //ALOGV("\tReverbGetDecayTime Succesfully returned from LVM_GetControlParameters\n");
1260 //ALOGV("\tReverbGetDecayTime() just Got -> %d\n", ActiveParams.T60);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001261
1262 if(ActiveParams.T60 != pContext->SavedDecayTime){
1263 // This will fail if the decay time is set to more than 7000
Steve Block06ade6a2011-10-20 11:56:00 +01001264 ALOGV("\tLVM_ERROR : ReverbGetDecayTime() has wrong level -> %d %d\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001265 ActiveParams.T60, pContext->SavedDecayTime);
1266 }
1267
Steve Block06ade6a2011-10-20 11:56:00 +01001268 //ALOGV("\tReverbGetDecayTime end");
Eric Laurent95d5de02010-09-08 16:06:18 -07001269 return (uint32_t)ActiveParams.T60;
Eric Laurenta1a96f32010-08-04 06:33:52 -07001270}
1271
1272//----------------------------------------------------------------------------
1273// ReverbSetDecayHfRatio()
1274//----------------------------------------------------------------------------
1275// Purpose:
1276// Apply the HF decay ratio to the Reverb.
1277//
1278// Inputs:
1279// pContext: effect engine context
1280// ratio ratio to be applied
1281//
1282//----------------------------------------------------------------------------
1283
1284void ReverbSetDecayHfRatio(ReverbContext *pContext, int16_t ratio){
Steve Block06ade6a2011-10-20 11:56:00 +01001285 //ALOGV("\tReverbSetDecayHfRatioe start (%d)", ratio);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001286
1287 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1288 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1289
1290 /* Get the current settings */
1291 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1292 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDecayHfRatio")
Steve Block06ade6a2011-10-20 11:56:00 +01001293 //ALOGV("\tReverbSetDecayHfRatio Succesfully returned from LVM_GetControlParameters\n");
1294 //ALOGV("\tReverbSetDecayHfRatio() just Got -> %d\n", ActiveParams.Damping);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001295
Eric Laurentadecf1c2010-08-27 10:52:56 -07001296 ActiveParams.Damping = (LVM_INT16)(ratio/20);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001297
1298 /* Activate the initial settings */
1299 LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1300 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDecayHfRatio")
Steve Block06ade6a2011-10-20 11:56:00 +01001301 //ALOGV("\tReverbSetDecayHfRatio() just Set -> %d\n", ActiveParams.Damping);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001302
1303 pContext->SavedDecayHfRatio = ratio;
Steve Block06ade6a2011-10-20 11:56:00 +01001304 //ALOGV("\tReverbSetDecayHfRatio end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001305 return;
1306}
1307
1308//----------------------------------------------------------------------------
1309// ReverbGetDecayHfRatio()
1310//----------------------------------------------------------------------------
1311// Purpose:
1312// Get the HF decay ratio applied to the Revervb.
1313//
1314// Inputs:
1315// pContext: effect engine context
1316//
1317//----------------------------------------------------------------------------
1318
1319int32_t ReverbGetDecayHfRatio(ReverbContext *pContext){
Steve Block06ade6a2011-10-20 11:56:00 +01001320 //ALOGV("\tReverbGetDecayHfRatio start");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001321
1322 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1323 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1324
1325 /* Get the current settings */
1326 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1327 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDecayHfRatio")
Steve Block06ade6a2011-10-20 11:56:00 +01001328 //ALOGV("\tReverbGetDecayHfRatio Succesfully returned from LVM_GetControlParameters\n");
1329 //ALOGV("\tReverbGetDecayHfRatio() just Got -> %d\n", ActiveParams.Damping);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001330
Eric Laurentadecf1c2010-08-27 10:52:56 -07001331 if(ActiveParams.Damping != (LVM_INT16)(pContext->SavedDecayHfRatio / 20)){
Steve Block06ade6a2011-10-20 11:56:00 +01001332 ALOGV("\tLVM_ERROR : ReverbGetDecayHfRatio() has wrong level -> %d %d\n",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001333 ActiveParams.Damping, pContext->SavedDecayHfRatio);
1334 }
1335
Steve Block06ade6a2011-10-20 11:56:00 +01001336 //ALOGV("\tReverbGetDecayHfRatio end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001337 return pContext->SavedDecayHfRatio;
1338}
1339
1340//----------------------------------------------------------------------------
1341// ReverbSetDiffusion()
1342//----------------------------------------------------------------------------
1343// Purpose:
1344// Apply the diffusion to the Reverb.
1345//
1346// Inputs:
1347// pContext: effect engine context
1348// level decay to be applied
1349//
1350//----------------------------------------------------------------------------
1351
1352void ReverbSetDiffusion(ReverbContext *pContext, int16_t level){
Steve Block06ade6a2011-10-20 11:56:00 +01001353 //ALOGV("\tReverbSetDiffusion start (%d)", level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001354
1355 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1356 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1357
1358 /* Get the current settings */
1359 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1360 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDiffusion")
Steve Block06ade6a2011-10-20 11:56:00 +01001361 //ALOGV("\tReverbSetDiffusion Succesfully returned from LVM_GetControlParameters\n");
1362 //ALOGV("\tReverbSetDiffusion() just Got -> %d\n", ActiveParams.Density);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001363
1364 ActiveParams.Density = (LVM_INT16)(level/10);
1365
1366 /* Activate the initial settings */
1367 LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1368 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDiffusion")
Steve Block06ade6a2011-10-20 11:56:00 +01001369 //ALOGV("\tReverbSetDiffusion() just Set -> %d\n", ActiveParams.Density);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001370
1371 pContext->SavedDiffusion = level;
Steve Block06ade6a2011-10-20 11:56:00 +01001372 //ALOGV("\tReverbSetDiffusion end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001373 return;
1374}
1375
1376//----------------------------------------------------------------------------
1377// ReverbGetDiffusion()
1378//----------------------------------------------------------------------------
1379// Purpose:
1380// Get the decay time applied to the Revervb.
1381//
1382// Inputs:
1383// pContext: effect engine context
1384//
1385//----------------------------------------------------------------------------
1386
1387int32_t ReverbGetDiffusion(ReverbContext *pContext){
Steve Block06ade6a2011-10-20 11:56:00 +01001388 //ALOGV("\tReverbGetDiffusion start");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001389
1390 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1391 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1392 LVM_INT16 Temp;
1393
1394 /* Get the current settings */
1395 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1396 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDiffusion")
Steve Block06ade6a2011-10-20 11:56:00 +01001397 //ALOGV("\tReverbGetDiffusion Succesfully returned from LVM_GetControlParameters\n");
1398 //ALOGV("\tReverbGetDiffusion just Got -> %d\n", ActiveParams.Density);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001399
1400 Temp = (LVM_INT16)(pContext->SavedDiffusion/10);
1401
1402 if(ActiveParams.Density != Temp){
Steve Block06ade6a2011-10-20 11:56:00 +01001403 ALOGV("\tLVM_ERROR : ReverbGetDiffusion invalid value %d %d", Temp, ActiveParams.Density);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001404 }
1405
Steve Block06ade6a2011-10-20 11:56:00 +01001406 //ALOGV("\tReverbGetDiffusion end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001407 return pContext->SavedDiffusion;
1408}
1409
1410//----------------------------------------------------------------------------
1411// ReverbSetDensity()
1412//----------------------------------------------------------------------------
1413// Purpose:
1414// Apply the density level the Reverb.
1415//
1416// Inputs:
1417// pContext: effect engine context
1418// level decay to be applied
1419//
1420//----------------------------------------------------------------------------
1421
1422void ReverbSetDensity(ReverbContext *pContext, int16_t level){
Steve Block06ade6a2011-10-20 11:56:00 +01001423 //ALOGV("\tReverbSetDensity start (%d)", level);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001424
1425 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1426 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1427
1428 /* Get the current settings */
1429 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1430 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbSetDensity")
Steve Block06ade6a2011-10-20 11:56:00 +01001431 //ALOGV("\tReverbSetDensity Succesfully returned from LVM_GetControlParameters\n");
1432 //ALOGV("\tReverbSetDensity just Got -> %d\n", ActiveParams.RoomSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001433
1434 ActiveParams.RoomSize = (LVM_INT16)(((level * 99) / 1000) + 1);
1435
1436 /* Activate the initial settings */
1437 LvmStatus = LVREV_SetControlParameters(pContext->hInstance, &ActiveParams);
1438 LVM_ERROR_CHECK(LvmStatus, "LVREV_SetControlParameters", "ReverbSetDensity")
Steve Block06ade6a2011-10-20 11:56:00 +01001439 //ALOGV("\tReverbSetDensity just Set -> %d\n", ActiveParams.RoomSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001440
1441 pContext->SavedDensity = level;
Steve Block06ade6a2011-10-20 11:56:00 +01001442 //ALOGV("\tReverbSetDensity end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001443 return;
1444}
1445
1446//----------------------------------------------------------------------------
1447// ReverbGetDensity()
1448//----------------------------------------------------------------------------
1449// Purpose:
1450// Get the density level applied to the Revervb.
1451//
1452// Inputs:
1453// pContext: effect engine context
1454//
1455//----------------------------------------------------------------------------
1456
1457int32_t ReverbGetDensity(ReverbContext *pContext){
Steve Block06ade6a2011-10-20 11:56:00 +01001458 //ALOGV("\tReverbGetDensity start");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001459
1460 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1461 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1462 LVM_INT16 Temp;
1463 /* Get the current settings */
1464 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
1465 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "ReverbGetDensity")
Steve Block06ade6a2011-10-20 11:56:00 +01001466 //ALOGV("\tReverbGetDensity Succesfully returned from LVM_GetControlParameters\n");
1467 //ALOGV("\tReverbGetDensity() just Got -> %d\n", ActiveParams.RoomSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001468
1469
1470 Temp = (LVM_INT16)(((pContext->SavedDensity * 99) / 1000) + 1);
1471
1472 if(Temp != ActiveParams.RoomSize){
Steve Block06ade6a2011-10-20 11:56:00 +01001473 ALOGV("\tLVM_ERROR : ReverbGetDensity invalid value %d %d", Temp, ActiveParams.RoomSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001474 }
1475
Steve Block06ade6a2011-10-20 11:56:00 +01001476 //ALOGV("\tReverbGetDensity end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001477 return pContext->SavedDensity;
1478}
1479
1480//----------------------------------------------------------------------------
Eric Laurenta7e56482010-08-24 14:21:57 -07001481// Reverb_LoadPreset()
1482//----------------------------------------------------------------------------
1483// Purpose:
1484// Load a the next preset
1485//
1486// Inputs:
1487// pContext - handle to instance data
1488//
1489// Outputs:
1490//
1491// Side Effects:
1492//
1493//----------------------------------------------------------------------------
1494int Reverb_LoadPreset(ReverbContext *pContext)
1495{
1496 //TODO: add reflections delay, level and reverb delay when early reflections are
1497 // implemented
1498 pContext->curPreset = pContext->nextPreset;
1499
1500 if (pContext->curPreset != REVERB_PRESET_NONE) {
1501 const t_reverb_settings *preset = &sReverbPresets[pContext->curPreset];
1502 ReverbSetRoomLevel(pContext, preset->roomLevel);
1503 ReverbSetRoomHfLevel(pContext, preset->roomHFLevel);
1504 ReverbSetDecayTime(pContext, preset->decayTime);
1505 ReverbSetDecayHfRatio(pContext, preset->decayHFRatio);
1506 //reflectionsLevel
1507 //reflectionsDelay
1508 ReverbSetReverbLevel(pContext, preset->reverbLevel);
1509 // reverbDelay
1510 ReverbSetDiffusion(pContext, preset->diffusion);
1511 ReverbSetDensity(pContext, preset->density);
1512 }
1513
1514 return 0;
1515}
1516
1517
1518//----------------------------------------------------------------------------
Eric Laurenta1a96f32010-08-04 06:33:52 -07001519// Reverb_getParameter()
1520//----------------------------------------------------------------------------
1521// Purpose:
1522// Get a Reverb parameter
1523//
1524// Inputs:
1525// pContext - handle to instance data
1526// pParam - pointer to parameter
1527// pValue - pointer to variable to hold retrieved value
1528// pValueSize - pointer to value size: maximum size as input
1529//
1530// Outputs:
1531// *pValue updated with parameter value
1532// *pValueSize updated with actual value size
1533//
1534//
1535// Side Effects:
1536//
1537//----------------------------------------------------------------------------
1538
1539int Reverb_getParameter(ReverbContext *pContext,
1540 void *pParam,
1541 size_t *pValueSize,
1542 void *pValue){
1543 int status = 0;
1544 int32_t *pParamTemp = (int32_t *)pParam;
1545 int32_t param = *pParamTemp++;
1546 char *name;
1547 t_reverb_settings *pProperties;
1548
Steve Block06ade6a2011-10-20 11:56:00 +01001549 //ALOGV("\tReverb_getParameter start");
Eric Laurenta7e56482010-08-24 14:21:57 -07001550 if (pContext->preset) {
1551 if (param != REVERB_PARAM_PRESET || *pValueSize < sizeof(uint16_t)) {
1552 return -EINVAL;
1553 }
1554
1555 *(uint16_t *)pValue = pContext->nextPreset;
Steve Block06ade6a2011-10-20 11:56:00 +01001556 ALOGV("get REVERB_PARAM_PRESET, preset %d", pContext->nextPreset);
Eric Laurenta7e56482010-08-24 14:21:57 -07001557 return 0;
1558 }
Eric Laurenta1a96f32010-08-04 06:33:52 -07001559
1560 switch (param){
1561 case REVERB_PARAM_ROOM_LEVEL:
1562 if (*pValueSize != sizeof(int16_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001563 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize1 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001564 return -EINVAL;
1565 }
1566 *pValueSize = sizeof(int16_t);
1567 break;
1568 case REVERB_PARAM_ROOM_HF_LEVEL:
1569 if (*pValueSize != sizeof(int16_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001570 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize12 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001571 return -EINVAL;
1572 }
1573 *pValueSize = sizeof(int16_t);
1574 break;
1575 case REVERB_PARAM_DECAY_TIME:
1576 if (*pValueSize != sizeof(uint32_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001577 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize3 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001578 return -EINVAL;
1579 }
1580 *pValueSize = sizeof(uint32_t);
1581 break;
1582 case REVERB_PARAM_DECAY_HF_RATIO:
1583 if (*pValueSize != sizeof(int16_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001584 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize4 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001585 return -EINVAL;
1586 }
1587 *pValueSize = sizeof(int16_t);
1588 break;
1589 case REVERB_PARAM_REFLECTIONS_LEVEL:
1590 if (*pValueSize != sizeof(int16_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001591 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize5 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001592 return -EINVAL;
1593 }
1594 *pValueSize = sizeof(int16_t);
1595 break;
1596 case REVERB_PARAM_REFLECTIONS_DELAY:
1597 if (*pValueSize != sizeof(uint32_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001598 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize6 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001599 return -EINVAL;
1600 }
1601 *pValueSize = sizeof(uint32_t);
1602 break;
1603 case REVERB_PARAM_REVERB_LEVEL:
1604 if (*pValueSize != sizeof(int16_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001605 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize7 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001606 return -EINVAL;
1607 }
1608 *pValueSize = sizeof(int16_t);
1609 break;
1610 case REVERB_PARAM_REVERB_DELAY:
1611 if (*pValueSize != sizeof(uint32_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001612 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize8 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001613 return -EINVAL;
1614 }
1615 *pValueSize = sizeof(uint32_t);
1616 break;
1617 case REVERB_PARAM_DIFFUSION:
1618 if (*pValueSize != sizeof(int16_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001619 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize9 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001620 return -EINVAL;
1621 }
1622 *pValueSize = sizeof(int16_t);
1623 break;
1624 case REVERB_PARAM_DENSITY:
1625 if (*pValueSize != sizeof(int16_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001626 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize10 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001627 return -EINVAL;
1628 }
1629 *pValueSize = sizeof(int16_t);
1630 break;
1631 case REVERB_PARAM_PROPERTIES:
1632 if (*pValueSize != sizeof(t_reverb_settings)){
Steve Block06ade6a2011-10-20 11:56:00 +01001633 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid pValueSize11 %d", *pValueSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001634 return -EINVAL;
1635 }
1636 *pValueSize = sizeof(t_reverb_settings);
1637 break;
1638
1639 default:
Steve Block06ade6a2011-10-20 11:56:00 +01001640 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid param %d", param);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001641 return -EINVAL;
1642 }
1643
1644 pProperties = (t_reverb_settings *) pValue;
1645
1646 switch (param){
1647 case REVERB_PARAM_PROPERTIES:
1648 pProperties->roomLevel = ReverbGetRoomLevel(pContext);
1649 pProperties->roomHFLevel = ReverbGetRoomHfLevel(pContext);
1650 pProperties->decayTime = ReverbGetDecayTime(pContext);
1651 pProperties->decayHFRatio = ReverbGetDecayHfRatio(pContext);
1652 pProperties->reflectionsLevel = 0;
1653 pProperties->reflectionsDelay = 0;
1654 pProperties->reverbDelay = 0;
1655 pProperties->reverbLevel = ReverbGetReverbLevel(pContext);
1656 pProperties->diffusion = ReverbGetDiffusion(pContext);
1657 pProperties->density = ReverbGetDensity(pContext);
1658
Steve Block06ade6a2011-10-20 11:56:00 +01001659 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is roomLevel %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001660 pProperties->roomLevel);
Steve Block06ade6a2011-10-20 11:56:00 +01001661 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is roomHFLevel %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001662 pProperties->roomHFLevel);
Steve Block06ade6a2011-10-20 11:56:00 +01001663 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is decayTime %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001664 pProperties->decayTime);
Steve Block06ade6a2011-10-20 11:56:00 +01001665 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is decayHFRatio %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001666 pProperties->decayHFRatio);
Steve Block06ade6a2011-10-20 11:56:00 +01001667 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reflectionsLevel %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001668 pProperties->reflectionsLevel);
Steve Block06ade6a2011-10-20 11:56:00 +01001669 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reflectionsDelay %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001670 pProperties->reflectionsDelay);
Steve Block06ade6a2011-10-20 11:56:00 +01001671 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reverbDelay %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001672 pProperties->reverbDelay);
Steve Block06ade6a2011-10-20 11:56:00 +01001673 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is reverbLevel %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001674 pProperties->reverbLevel);
Steve Block06ade6a2011-10-20 11:56:00 +01001675 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is diffusion %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001676 pProperties->diffusion);
Steve Block06ade6a2011-10-20 11:56:00 +01001677 ALOGV("\tReverb_getParameter() REVERB_PARAM_PROPERTIES Value is density %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001678 pProperties->density);
1679 break;
1680
1681 case REVERB_PARAM_ROOM_LEVEL:
1682 *(int16_t *)pValue = ReverbGetRoomLevel(pContext);
1683
Steve Block06ade6a2011-10-20 11:56:00 +01001684 //ALOGV("\tReverb_getParameter() REVERB_PARAM_ROOM_LEVEL Value is %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001685 // *(int16_t *)pValue);
1686 break;
1687 case REVERB_PARAM_ROOM_HF_LEVEL:
1688 *(int16_t *)pValue = ReverbGetRoomHfLevel(pContext);
1689
Steve Block06ade6a2011-10-20 11:56:00 +01001690 //ALOGV("\tReverb_getParameter() REVERB_PARAM_ROOM_HF_LEVEL Value is %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001691 // *(int16_t *)pValue);
1692 break;
1693 case REVERB_PARAM_DECAY_TIME:
Eric Laurent95d5de02010-09-08 16:06:18 -07001694 *(uint32_t *)pValue = ReverbGetDecayTime(pContext);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001695
Steve Block06ade6a2011-10-20 11:56:00 +01001696 //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_TIME Value is %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001697 // *(int32_t *)pValue);
1698 break;
1699 case REVERB_PARAM_DECAY_HF_RATIO:
1700 *(int16_t *)pValue = ReverbGetDecayHfRatio(pContext);
1701
Steve Block06ade6a2011-10-20 11:56:00 +01001702 //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_HF_RATION Value is %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001703 // *(int16_t *)pValue);
1704 break;
1705 case REVERB_PARAM_REVERB_LEVEL:
1706 *(int16_t *)pValue = ReverbGetReverbLevel(pContext);
1707
Steve Block06ade6a2011-10-20 11:56:00 +01001708 //ALOGV("\tReverb_getParameter() REVERB_PARAM_REVERB_LEVEL Value is %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001709 // *(int16_t *)pValue);
1710 break;
1711 case REVERB_PARAM_DIFFUSION:
1712 *(int16_t *)pValue = ReverbGetDiffusion(pContext);
1713
Steve Block06ade6a2011-10-20 11:56:00 +01001714 //ALOGV("\tReverb_getParameter() REVERB_PARAM_DECAY_DIFFUSION Value is %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001715 // *(int16_t *)pValue);
1716 break;
1717 case REVERB_PARAM_DENSITY:
1718 *(uint16_t *)pValue = 0;
1719 *(int16_t *)pValue = ReverbGetDensity(pContext);
Steve Block06ade6a2011-10-20 11:56:00 +01001720 //ALOGV("\tReverb_getParameter() REVERB_PARAM_DENSITY Value is %d",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001721 // *(uint32_t *)pValue);
1722 break;
1723 case REVERB_PARAM_REFLECTIONS_LEVEL:
1724 *(uint16_t *)pValue = 0;
1725 case REVERB_PARAM_REFLECTIONS_DELAY:
1726 *(uint32_t *)pValue = 0;
1727 case REVERB_PARAM_REVERB_DELAY:
1728 *(uint32_t *)pValue = 0;
1729 break;
1730
1731 default:
Steve Block06ade6a2011-10-20 11:56:00 +01001732 ALOGV("\tLVM_ERROR : Reverb_getParameter() invalid param %d", param);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001733 status = -EINVAL;
1734 break;
1735 }
1736
Steve Block06ade6a2011-10-20 11:56:00 +01001737 //ALOGV("\tReverb_getParameter end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001738 return status;
1739} /* end Reverb_getParameter */
1740
1741//----------------------------------------------------------------------------
1742// Reverb_setParameter()
1743//----------------------------------------------------------------------------
1744// Purpose:
1745// Set a Reverb parameter
1746//
1747// Inputs:
1748// pContext - handle to instance data
1749// pParam - pointer to parameter
1750// pValue - pointer to value
1751//
1752// Outputs:
1753//
1754//----------------------------------------------------------------------------
1755
1756int Reverb_setParameter (ReverbContext *pContext, void *pParam, void *pValue){
1757 int status = 0;
1758 int16_t level;
Eric Laurent95d5de02010-09-08 16:06:18 -07001759 int16_t ratio;
Eric Laurenta1a96f32010-08-04 06:33:52 -07001760 uint32_t time;
1761 t_reverb_settings *pProperties;
1762 int32_t *pParamTemp = (int32_t *)pParam;
1763 int32_t param = *pParamTemp++;
1764
Steve Block06ade6a2011-10-20 11:56:00 +01001765 //ALOGV("\tReverb_setParameter start");
Eric Laurenta7e56482010-08-24 14:21:57 -07001766 if (pContext->preset) {
1767 if (param != REVERB_PARAM_PRESET) {
1768 return -EINVAL;
1769 }
1770
1771 uint16_t preset = *(uint16_t *)pValue;
Steve Block06ade6a2011-10-20 11:56:00 +01001772 ALOGV("set REVERB_PARAM_PRESET, preset %d", preset);
Eric Laurenta7e56482010-08-24 14:21:57 -07001773 if (preset > REVERB_PRESET_LAST) {
1774 return -EINVAL;
1775 }
1776 pContext->nextPreset = preset;
Eric Laurent95d5de02010-09-08 16:06:18 -07001777 return 0;
Eric Laurenta7e56482010-08-24 14:21:57 -07001778 }
Eric Laurenta1a96f32010-08-04 06:33:52 -07001779
1780 switch (param){
1781 case REVERB_PARAM_PROPERTIES:
Steve Block06ade6a2011-10-20 11:56:00 +01001782 ALOGV("\tReverb_setParameter() REVERB_PARAM_PROPERTIES");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001783 pProperties = (t_reverb_settings *) pValue;
1784 ReverbSetRoomLevel(pContext, pProperties->roomLevel);
1785 ReverbSetRoomHfLevel(pContext, pProperties->roomHFLevel);
1786 ReverbSetDecayTime(pContext, pProperties->decayTime);
1787 ReverbSetDecayHfRatio(pContext, pProperties->decayHFRatio);
1788 ReverbSetReverbLevel(pContext, pProperties->reverbLevel);
1789 ReverbSetDiffusion(pContext, pProperties->diffusion);
1790 ReverbSetDensity(pContext, pProperties->density);
1791 break;
1792 case REVERB_PARAM_ROOM_LEVEL:
1793 level = *(int16_t *)pValue;
Steve Block06ade6a2011-10-20 11:56:00 +01001794 //ALOGV("\tReverb_setParameter() REVERB_PARAM_ROOM_LEVEL value is %d", level);
1795 //ALOGV("\tReverb_setParameter() Calling ReverbSetRoomLevel");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001796 ReverbSetRoomLevel(pContext, level);
Steve Block06ade6a2011-10-20 11:56:00 +01001797 //ALOGV("\tReverb_setParameter() Called ReverbSetRoomLevel");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001798 break;
1799 case REVERB_PARAM_ROOM_HF_LEVEL:
1800 level = *(int16_t *)pValue;
Steve Block06ade6a2011-10-20 11:56:00 +01001801 //ALOGV("\tReverb_setParameter() REVERB_PARAM_ROOM_HF_LEVEL value is %d", level);
1802 //ALOGV("\tReverb_setParameter() Calling ReverbSetRoomHfLevel");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001803 ReverbSetRoomHfLevel(pContext, level);
Steve Block06ade6a2011-10-20 11:56:00 +01001804 //ALOGV("\tReverb_setParameter() Called ReverbSetRoomHfLevel");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001805 break;
1806 case REVERB_PARAM_DECAY_TIME:
1807 time = *(uint32_t *)pValue;
Steve Block06ade6a2011-10-20 11:56:00 +01001808 //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_TIME value is %d", time);
1809 //ALOGV("\tReverb_setParameter() Calling ReverbSetDecayTime");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001810 ReverbSetDecayTime(pContext, time);
Steve Block06ade6a2011-10-20 11:56:00 +01001811 //ALOGV("\tReverb_setParameter() Called ReverbSetDecayTime");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001812 break;
1813 case REVERB_PARAM_DECAY_HF_RATIO:
Eric Laurent95d5de02010-09-08 16:06:18 -07001814 ratio = *(int16_t *)pValue;
Steve Block06ade6a2011-10-20 11:56:00 +01001815 //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_HF_RATIO value is %d", ratio);
1816 //ALOGV("\tReverb_setParameter() Calling ReverbSetDecayHfRatio");
Eric Laurent95d5de02010-09-08 16:06:18 -07001817 ReverbSetDecayHfRatio(pContext, ratio);
Steve Block06ade6a2011-10-20 11:56:00 +01001818 //ALOGV("\tReverb_setParameter() Called ReverbSetDecayHfRatio");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001819 break;
1820 case REVERB_PARAM_REVERB_LEVEL:
1821 level = *(int16_t *)pValue;
Steve Block06ade6a2011-10-20 11:56:00 +01001822 //ALOGV("\tReverb_setParameter() REVERB_PARAM_REVERB_LEVEL value is %d", level);
1823 //ALOGV("\tReverb_setParameter() Calling ReverbSetReverbLevel");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001824 ReverbSetReverbLevel(pContext, level);
Steve Block06ade6a2011-10-20 11:56:00 +01001825 //ALOGV("\tReverb_setParameter() Called ReverbSetReverbLevel");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001826 break;
1827 case REVERB_PARAM_DIFFUSION:
Eric Laurent95d5de02010-09-08 16:06:18 -07001828 ratio = *(int16_t *)pValue;
Steve Block06ade6a2011-10-20 11:56:00 +01001829 //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_DIFFUSION value is %d", ratio);
1830 //ALOGV("\tReverb_setParameter() Calling ReverbSetDiffusion");
Eric Laurent95d5de02010-09-08 16:06:18 -07001831 ReverbSetDiffusion(pContext, ratio);
Steve Block06ade6a2011-10-20 11:56:00 +01001832 //ALOGV("\tReverb_setParameter() Called ReverbSetDiffusion");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001833 break;
1834 case REVERB_PARAM_DENSITY:
Eric Laurent95d5de02010-09-08 16:06:18 -07001835 ratio = *(int16_t *)pValue;
Steve Block06ade6a2011-10-20 11:56:00 +01001836 //ALOGV("\tReverb_setParameter() REVERB_PARAM_DECAY_DENSITY value is %d", ratio);
1837 //ALOGV("\tReverb_setParameter() Calling ReverbSetDensity");
Eric Laurent95d5de02010-09-08 16:06:18 -07001838 ReverbSetDensity(pContext, ratio);
Steve Block06ade6a2011-10-20 11:56:00 +01001839 //ALOGV("\tReverb_setParameter() Called ReverbSetDensity");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001840 break;
1841 break;
1842 case REVERB_PARAM_REFLECTIONS_LEVEL:
1843 case REVERB_PARAM_REFLECTIONS_DELAY:
1844 case REVERB_PARAM_REVERB_DELAY:
1845 break;
1846 default:
Steve Block06ade6a2011-10-20 11:56:00 +01001847 ALOGV("\tLVM_ERROR : Reverb_setParameter() invalid param %d", param);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001848 break;
1849 }
1850
Steve Block06ade6a2011-10-20 11:56:00 +01001851 //ALOGV("\tReverb_setParameter end");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001852 return status;
1853} /* end Reverb_setParameter */
1854
1855} // namespace
1856} // namespace
1857
Eric Laurent0fb66c22011-05-17 19:16:02 -07001858extern "C" {
Eric Laurenta1a96f32010-08-04 06:33:52 -07001859/* Effect Control Interface Implementation: Process */
Eric Laurent0fb66c22011-05-17 19:16:02 -07001860int Reverb_process(effect_handle_t self,
Eric Laurenta1a96f32010-08-04 06:33:52 -07001861 audio_buffer_t *inBuffer,
1862 audio_buffer_t *outBuffer){
1863 android::ReverbContext * pContext = (android::ReverbContext *) self;
1864 int status = 0;
1865
1866 if (pContext == NULL){
Steve Block06ade6a2011-10-20 11:56:00 +01001867 ALOGV("\tLVM_ERROR : Reverb_process() ERROR pContext == NULL");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001868 return -EINVAL;
1869 }
1870 if (inBuffer == NULL || inBuffer->raw == NULL ||
1871 outBuffer == NULL || outBuffer->raw == NULL ||
1872 inBuffer->frameCount != outBuffer->frameCount){
Steve Block06ade6a2011-10-20 11:56:00 +01001873 ALOGV("\tLVM_ERROR : Reverb_process() ERROR NULL INPUT POINTER OR FRAME COUNT IS WRONG");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001874 return -EINVAL;
1875 }
Steve Block06ade6a2011-10-20 11:56:00 +01001876 //ALOGV("\tReverb_process() Calling process with %d frames", outBuffer->frameCount);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001877 /* Process all the available frames, block processing is handled internalLY by the LVM bundle */
1878 status = process( (LVM_INT16 *)inBuffer->raw,
1879 (LVM_INT16 *)outBuffer->raw,
1880 outBuffer->frameCount,
1881 pContext);
1882
Eric Laurent27a2fdf2010-09-10 17:44:44 -07001883 if (pContext->bEnabled == LVM_FALSE) {
1884 if (pContext->SamplesToExitCount > 0) {
1885 pContext->SamplesToExitCount -= outBuffer->frameCount;
1886 } else {
1887 status = -ENODATA;
1888 }
1889 }
1890
Eric Laurenta1a96f32010-08-04 06:33:52 -07001891 return status;
1892} /* end Reverb_process */
1893
1894/* Effect Control Interface Implementation: Command */
Eric Laurent0fb66c22011-05-17 19:16:02 -07001895int Reverb_command(effect_handle_t self,
Eric Laurenta1a96f32010-08-04 06:33:52 -07001896 uint32_t cmdCode,
1897 uint32_t cmdSize,
1898 void *pCmdData,
1899 uint32_t *replySize,
1900 void *pReplyData){
1901 android::ReverbContext * pContext = (android::ReverbContext *) self;
1902 int retsize;
Eric Laurent5fa6df62010-09-02 17:18:20 -07001903 LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
1904 LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
1905
Eric Laurenta1a96f32010-08-04 06:33:52 -07001906
1907 if (pContext == NULL){
Steve Block06ade6a2011-10-20 11:56:00 +01001908 ALOGV("\tLVM_ERROR : Reverb_command ERROR pContext == NULL");
Eric Laurenta1a96f32010-08-04 06:33:52 -07001909 return -EINVAL;
1910 }
1911
Steve Block06ade6a2011-10-20 11:56:00 +01001912 //ALOGV("\tReverb_command INPUTS are: command %d cmdSize %d",cmdCode, cmdSize);
Eric Laurenta1a96f32010-08-04 06:33:52 -07001913
1914 switch (cmdCode){
1915 case EFFECT_CMD_INIT:
Steve Block06ade6a2011-10-20 11:56:00 +01001916 //ALOGV("\tReverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001917 // "EFFECT_CMD_INIT start");
1918
1919 if (pReplyData == NULL || *replySize != sizeof(int)){
Steve Block06ade6a2011-10-20 11:56:00 +01001920 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001921 "EFFECT_CMD_INIT: ERROR");
1922 return -EINVAL;
1923 }
1924 *(int *) pReplyData = 0;
1925 break;
1926
1927 case EFFECT_CMD_CONFIGURE:
Steve Block06ade6a2011-10-20 11:56:00 +01001928 //ALOGV("\tReverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001929 // "EFFECT_CMD_CONFIGURE start");
1930 if (pCmdData == NULL||
1931 cmdSize != sizeof(effect_config_t)||
1932 pReplyData == NULL||
1933 *replySize != sizeof(int)){
Steve Block06ade6a2011-10-20 11:56:00 +01001934 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001935 "EFFECT_CMD_CONFIGURE: ERROR");
1936 return -EINVAL;
1937 }
1938 *(int *) pReplyData = Reverb_configure(pContext, (effect_config_t *) pCmdData);
1939 break;
1940
1941 case EFFECT_CMD_RESET:
Steve Block06ade6a2011-10-20 11:56:00 +01001942 //ALOGV("\tReverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001943 // "EFFECT_CMD_RESET start");
1944 Reverb_configure(pContext, &pContext->config);
1945 break;
1946
1947 case EFFECT_CMD_GET_PARAM:{
Steve Block06ade6a2011-10-20 11:56:00 +01001948 //ALOGV("\tReverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001949 // "EFFECT_CMD_GET_PARAM start");
1950 if (pCmdData == NULL ||
1951 cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
1952 pReplyData == NULL ||
1953 *replySize < (int) (sizeof(effect_param_t) + sizeof(int32_t))){
Steve Block06ade6a2011-10-20 11:56:00 +01001954 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001955 "EFFECT_CMD_GET_PARAM: ERROR");
1956 return -EINVAL;
1957 }
1958 effect_param_t *p = (effect_param_t *)pCmdData;
1959
1960 memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + p->psize);
1961
1962 p = (effect_param_t *)pReplyData;
1963
1964 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
1965
1966 p->status = android::Reverb_getParameter(pContext,
1967 (void *)p->data,
1968 (size_t *)&p->vsize,
1969 p->data + voffset);
1970
1971 *replySize = sizeof(effect_param_t) + voffset + p->vsize;
1972
Steve Block06ade6a2011-10-20 11:56:00 +01001973 //ALOGV("\tReverb_command EFFECT_CMD_GET_PARAM "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001974 // "*pCmdData %d, *replySize %d, *pReplyData %d ",
1975 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
1976 // *replySize,
1977 // *(int16_t *)((char *)pReplyData + sizeof(effect_param_t) + voffset));
1978
1979 } break;
1980 case EFFECT_CMD_SET_PARAM:{
1981
Steve Block06ade6a2011-10-20 11:56:00 +01001982 //ALOGV("\tReverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001983 // "EFFECT_CMD_SET_PARAM start");
Steve Block06ade6a2011-10-20 11:56:00 +01001984 //ALOGV("\tReverb_command EFFECT_CMD_SET_PARAM param %d, *replySize %d, value %d ",
Eric Laurenta1a96f32010-08-04 06:33:52 -07001985 // *(int32_t *)((char *)pCmdData + sizeof(effect_param_t)),
1986 // *replySize,
1987 // *(int16_t *)((char *)pCmdData + sizeof(effect_param_t) + sizeof(int32_t)));
1988
1989 if (pCmdData == NULL || (cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)))
1990 || pReplyData == NULL || *replySize != (int)sizeof(int32_t)) {
Steve Block06ade6a2011-10-20 11:56:00 +01001991 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07001992 "EFFECT_CMD_SET_PARAM: ERROR");
1993 return -EINVAL;
1994 }
1995
1996 effect_param_t *p = (effect_param_t *) pCmdData;
1997
1998 if (p->psize != sizeof(int32_t)){
Steve Block06ade6a2011-10-20 11:56:00 +01001999 ALOGV("\t4LVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07002000 "EFFECT_CMD_SET_PARAM: ERROR, psize is not sizeof(int32_t)");
2001 return -EINVAL;
2002 }
2003
Steve Block06ade6a2011-10-20 11:56:00 +01002004 //ALOGV("\tn5Reverb_command cmdSize is %d\n"
Eric Laurenta1a96f32010-08-04 06:33:52 -07002005 // "\tsizeof(effect_param_t) is %d\n"
2006 // "\tp->psize is %d\n"
2007 // "\tp->vsize is %d"
2008 // "\n",
2009 // cmdSize, sizeof(effect_param_t), p->psize, p->vsize );
2010
2011 *(int *)pReplyData = android::Reverb_setParameter(pContext,
2012 (void *)p->data,
2013 p->data + p->psize);
2014 } break;
2015
2016 case EFFECT_CMD_ENABLE:
Steve Block06ade6a2011-10-20 11:56:00 +01002017 //ALOGV("\tReverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07002018 // "EFFECT_CMD_ENABLE start");
2019
2020 if (pReplyData == NULL || *replySize != sizeof(int)){
Steve Block06ade6a2011-10-20 11:56:00 +01002021 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07002022 "EFFECT_CMD_ENABLE: ERROR");
2023 return -EINVAL;
2024 }
2025 if(pContext->bEnabled == LVM_TRUE){
Steve Block06ade6a2011-10-20 11:56:00 +01002026 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07002027 "EFFECT_CMD_ENABLE: ERROR-Effect is already enabled");
2028 return -EINVAL;
2029 }
2030 *(int *)pReplyData = 0;
2031 pContext->bEnabled = LVM_TRUE;
Eric Laurent5fa6df62010-09-02 17:18:20 -07002032 /* Get the current settings */
2033 LvmStatus = LVREV_GetControlParameters(pContext->hInstance, &ActiveParams);
2034 LVM_ERROR_CHECK(LvmStatus, "LVREV_GetControlParameters", "EFFECT_CMD_ENABLE")
2035 pContext->SamplesToExitCount =
2036 (ActiveParams.T60 * pContext->config.inputCfg.samplingRate)/1000;
Eric Laurent27a2fdf2010-09-10 17:44:44 -07002037 // force no volume ramp for first buffer processed after enabling the effect
2038 pContext->volumeMode = android::REVERB_VOLUME_FLAT;
Steve Block06ade6a2011-10-20 11:56:00 +01002039 //ALOGV("\tEFFECT_CMD_ENABLE SamplesToExitCount = %d", pContext->SamplesToExitCount);
Eric Laurenta1a96f32010-08-04 06:33:52 -07002040 break;
2041 case EFFECT_CMD_DISABLE:
Steve Block06ade6a2011-10-20 11:56:00 +01002042 //ALOGV("\tReverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07002043 // "EFFECT_CMD_DISABLE start");
2044
2045 if (pReplyData == NULL || *replySize != sizeof(int)){
Steve Block06ade6a2011-10-20 11:56:00 +01002046 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07002047 "EFFECT_CMD_DISABLE: ERROR");
2048 return -EINVAL;
2049 }
2050 if(pContext->bEnabled == LVM_FALSE){
Steve Block06ade6a2011-10-20 11:56:00 +01002051 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07002052 "EFFECT_CMD_DISABLE: ERROR-Effect is not yet enabled");
2053 return -EINVAL;
2054 }
2055 *(int *)pReplyData = 0;
2056 pContext->bEnabled = LVM_FALSE;
2057 break;
2058
Eric Laurenta1a96f32010-08-04 06:33:52 -07002059 case EFFECT_CMD_SET_VOLUME:
Eric Laurent27a2fdf2010-09-10 17:44:44 -07002060 if (pCmdData == NULL ||
2061 cmdSize != 2 * sizeof(uint32_t)) {
Steve Block06ade6a2011-10-20 11:56:00 +01002062 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurent27a2fdf2010-09-10 17:44:44 -07002063 "EFFECT_CMD_SET_VOLUME: ERROR");
2064 return -EINVAL;
2065 }
2066
2067
2068 if (pReplyData != NULL) { // we have volume control
2069 pContext->leftVolume = (LVM_INT16)((*(uint32_t *)pCmdData + (1 << 11)) >> 12);
2070 pContext->rightVolume = (LVM_INT16)((*((uint32_t *)pCmdData + 1) + (1 << 11)) >> 12);
2071 *(uint32_t *)pReplyData = (1 << 24);
2072 *((uint32_t *)pReplyData + 1) = (1 << 24);
2073 if (pContext->volumeMode == android::REVERB_VOLUME_OFF) {
2074 // force no volume ramp for first buffer processed after getting volume control
2075 pContext->volumeMode = android::REVERB_VOLUME_FLAT;
2076 }
2077 } else { // we don't have volume control
2078 pContext->leftVolume = REVERB_UNIT_VOLUME;
2079 pContext->rightVolume = REVERB_UNIT_VOLUME;
2080 pContext->volumeMode = android::REVERB_VOLUME_OFF;
2081 }
Steve Block06ade6a2011-10-20 11:56:00 +01002082 ALOGV("EFFECT_CMD_SET_VOLUME left %d, right %d mode %d",
Eric Laurent27a2fdf2010-09-10 17:44:44 -07002083 pContext->leftVolume, pContext->rightVolume, pContext->volumeMode);
2084 break;
2085
2086 case EFFECT_CMD_SET_DEVICE:
Eric Laurenta1a96f32010-08-04 06:33:52 -07002087 case EFFECT_CMD_SET_AUDIO_MODE:
Steve Block06ade6a2011-10-20 11:56:00 +01002088 //ALOGV("\tReverb_command cmdCode Case: "
Eric Laurent5fa6df62010-09-02 17:18:20 -07002089 // "EFFECT_CMD_SET_DEVICE/EFFECT_CMD_SET_VOLUME/EFFECT_CMD_SET_AUDIO_MODE start");
Eric Laurenta1a96f32010-08-04 06:33:52 -07002090 break;
2091
2092 default:
Steve Block06ade6a2011-10-20 11:56:00 +01002093 ALOGV("\tLVM_ERROR : Reverb_command cmdCode Case: "
Eric Laurenta1a96f32010-08-04 06:33:52 -07002094 "DEFAULT start %d ERROR",cmdCode);
2095 return -EINVAL;
2096 }
2097
Steve Block06ade6a2011-10-20 11:56:00 +01002098 //ALOGV("\tReverb_command end\n\n");
Eric Laurenta1a96f32010-08-04 06:33:52 -07002099 return 0;
2100} /* end Reverb_command */
2101
Eric Laurent0fb66c22011-05-17 19:16:02 -07002102/* Effect Control Interface Implementation: get_descriptor */
2103int Reverb_getDescriptor(effect_handle_t self,
2104 effect_descriptor_t *pDescriptor)
2105{
2106 android::ReverbContext * pContext = (android::ReverbContext *)self;
2107 const effect_descriptor_t *desc;
2108
2109 if (pContext == NULL || pDescriptor == NULL) {
Steve Block06ade6a2011-10-20 11:56:00 +01002110 ALOGV("Reverb_getDescriptor() invalid param");
Eric Laurent0fb66c22011-05-17 19:16:02 -07002111 return -EINVAL;
2112 }
2113
2114 if (pContext->auxiliary) {
2115 if (pContext->preset) {
2116 desc = &android::gAuxPresetReverbDescriptor;
2117 } else {
2118 desc = &android::gAuxEnvReverbDescriptor;
2119 }
2120 } else {
2121 if (pContext->preset) {
2122 desc = &android::gInsertPresetReverbDescriptor;
2123 } else {
2124 desc = &android::gInsertEnvReverbDescriptor;
2125 }
2126 }
2127
2128 memcpy(pDescriptor, desc, sizeof(effect_descriptor_t));
2129
2130 return 0;
2131} /* end Reverb_getDescriptor */
2132
2133// effect_handle_t interface implementation for Reverb effect
Eric Laurenta1a96f32010-08-04 06:33:52 -07002134const struct effect_interface_s gReverbInterface = {
2135 Reverb_process,
Eric Laurent0fb66c22011-05-17 19:16:02 -07002136 Reverb_command,
Eric Laurent325b8e82011-06-17 18:54:16 -07002137 Reverb_getDescriptor,
2138 NULL,
Eric Laurenta1a96f32010-08-04 06:33:52 -07002139}; /* end gReverbInterface */
2140
Eric Laurent0fb66c22011-05-17 19:16:02 -07002141audio_effect_library_t AUDIO_EFFECT_LIBRARY_INFO_SYM = {
2142 tag : AUDIO_EFFECT_LIBRARY_TAG,
2143 version : EFFECT_LIBRARY_API_VERSION,
2144 name : "Reverb Library",
2145 implementor : "NXP Software Ltd.",
2146 query_num_effects : android::EffectQueryNumberEffects,
2147 query_effect : android::EffectQueryEffect,
2148 create_effect : android::EffectCreate,
2149 release_effect : android::EffectRelease,
2150 get_descriptor : android::EffectGetDescriptor,
2151};
2152
2153}