blob: ada252c917ecbab2c12285590bb96eaf6c211f95 [file] [log] [blame]
Eric Laurent135ad072010-05-21 06:05:13 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "EffectReverb"
18//
19#define LOG_NDEBUG 0
20#include <cutils/log.h>
Eric Laurentbe916aa2010-06-01 23:49:17 -070021#include <stdlib.h>
22#include <string.h>
Eric Laurent135ad072010-05-21 06:05:13 -070023#include <stdbool.h>
24#include "EffectReverb.h"
25#include "EffectsMath.h"
26
Eric Laurent135ad072010-05-21 06:05:13 -070027// effect_interface_t interface implementation for reverb effect
28const struct effect_interface_s gReverbInterface = {
29 Reverb_Process,
30 Reverb_Command
31};
32
33// Google auxiliary environmental reverb UUID: 1f0ae2e0-4ef7-11df-bc09-0002a5d5c51b
34static const effect_descriptor_t gAuxEnvReverbDescriptor = {
35 {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}},
36 {0x1f0ae2e0, 0x4ef7, 0x11df, 0xbc09, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
37 EFFECT_API_VERSION,
Eric Laurentffe9c252010-06-23 17:38:20 -070038 // flags other than EFFECT_FLAG_TYPE_AUXILIARY set for test purpose
39 EFFECT_FLAG_TYPE_AUXILIARY | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_AUDIO_MODE_IND,
40 0, // TODO
41 33,
Eric Laurent135ad072010-05-21 06:05:13 -070042 "Aux Environmental Reverb",
43 "Google Inc."
44};
45
46// Google insert environmental reverb UUID: aa476040-6342-11df-91a4-0002a5d5c51b
47static const effect_descriptor_t gInsertEnvReverbDescriptor = {
48 {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}},
49 {0xaa476040, 0x6342, 0x11df, 0x91a4, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
50 EFFECT_API_VERSION,
51 EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST,
Eric Laurentffe9c252010-06-23 17:38:20 -070052 0, // TODO
53 33,
Eric Laurent135ad072010-05-21 06:05:13 -070054 "Insert Environmental reverb",
55 "Google Inc."
56};
57
58// Google auxiliary preset reverb UUID: 63909320-53a6-11df-bdbd-0002a5d5c51b
59static const effect_descriptor_t gAuxPresetReverbDescriptor = {
60 {0x47382d60, 0xddd8, 0x4763, 0x11db, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
61 {0x63909320, 0x53a6, 0x11df, 0xbdbd, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
62 EFFECT_API_VERSION,
63 EFFECT_FLAG_TYPE_AUXILIARY,
Eric Laurentffe9c252010-06-23 17:38:20 -070064 0, // TODO
65 33,
Eric Laurent135ad072010-05-21 06:05:13 -070066 "Aux Preset Reverb",
67 "Google Inc."
68};
69
70// Google insert preset reverb UUID: d93dc6a0-6342-11df-b128-0002a5d5c51b
71static const effect_descriptor_t gInsertPresetReverbDescriptor = {
72 {0x47382d60, 0xddd8, 0x4763, 0x11db, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
73 {0xd93dc6a0, 0x6342, 0x11df, 0xb128, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
74 EFFECT_API_VERSION,
75 EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST,
Eric Laurentffe9c252010-06-23 17:38:20 -070076 0, // TODO
77 33,
Eric Laurent135ad072010-05-21 06:05:13 -070078 "Insert Preset Reverb",
79 "Google Inc."
80};
81
82// gDescriptors contains pointers to all defined effect descriptor in this library
83static const effect_descriptor_t * const gDescriptors[] = {
84 &gAuxEnvReverbDescriptor,
85 &gInsertEnvReverbDescriptor,
86 &gAuxPresetReverbDescriptor,
Eric Laurentffe9c252010-06-23 17:38:20 -070087 &gInsertPresetReverbDescriptor
Eric Laurent135ad072010-05-21 06:05:13 -070088};
89
90/*----------------------------------------------------------------------------
91 * Effect API implementation
92 *--------------------------------------------------------------------------*/
93
94/*--- Effect Library Interface Implementation ---*/
95
Eric Laurentbe916aa2010-06-01 23:49:17 -070096int EffectQueryNumberEffects(uint32_t *pNumEffects) {
Eric Laurentffe9c252010-06-23 17:38:20 -070097 *pNumEffects = sizeof(gDescriptors) / sizeof(const effect_descriptor_t *);
Eric Laurent135ad072010-05-21 06:05:13 -070098 return 0;
99}
100
Eric Laurentffe9c252010-06-23 17:38:20 -0700101int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) {
Eric Laurent135ad072010-05-21 06:05:13 -0700102 if (pDescriptor == NULL) {
103 return -EINVAL;
104 }
Eric Laurentffe9c252010-06-23 17:38:20 -0700105 if (index >= sizeof(gDescriptors) / sizeof(const effect_descriptor_t *)) {
106 return -EINVAL;
Eric Laurent135ad072010-05-21 06:05:13 -0700107 }
Eric Laurentffe9c252010-06-23 17:38:20 -0700108 memcpy(pDescriptor, gDescriptors[index],
Eric Laurent135ad072010-05-21 06:05:13 -0700109 sizeof(effect_descriptor_t));
110 return 0;
111}
112
113int EffectCreate(effect_uuid_t *uuid,
Eric Laurentffe9c252010-06-23 17:38:20 -0700114 int32_t sessionId,
115 int32_t ioId,
Eric Laurent135ad072010-05-21 06:05:13 -0700116 effect_interface_t *pInterface) {
117 int ret;
118 int i;
119 reverb_module_t *module;
120 const effect_descriptor_t *desc;
121 int aux = 0;
122 int preset = 0;
123
124 LOGV("EffectLibCreateEffect start");
125
126 if (pInterface == NULL || uuid == NULL) {
127 return -EINVAL;
128 }
129
130 for (i = 0; gDescriptors[i] != NULL; i++) {
131 desc = gDescriptors[i];
132 if (memcmp(uuid, &desc->uuid, sizeof(effect_uuid_t))
133 == 0) {
134 break;
135 }
136 }
137
138 if (gDescriptors[i] == NULL) {
139 return -ENOENT;
140 }
141
142 module = malloc(sizeof(reverb_module_t));
143
144 module->itfe = &gReverbInterface;
145
146 if (memcmp(&desc->type, SL_IID_PRESETREVERB, sizeof(effect_uuid_t)) == 0) {
147 preset = 1;
148 }
149 if ((desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) {
150 aux = 1;
151 }
152 ret = Reverb_Init(module, aux, preset);
153 if (ret < 0) {
154 LOGW("EffectLibCreateEffect() init failed");
155 free(module);
156 return ret;
157 }
158
159 *pInterface = (effect_interface_t) module;
160
Eric Laurentffe9c252010-06-23 17:38:20 -0700161 LOGV("EffectLibCreateEffect %p ,size %d", module, sizeof(reverb_module_t));
Eric Laurent135ad072010-05-21 06:05:13 -0700162
163 return 0;
164}
165
166int EffectRelease(effect_interface_t interface) {
167 reverb_module_t *pRvbModule = (reverb_module_t *)interface;
168
169 LOGV("EffectLibReleaseEffect %p", interface);
170 if (interface == NULL) {
171 return -EINVAL;
172 }
173
174 free(pRvbModule);
175 return 0;
176}
177
178
179/*--- Effect Control Interface Implementation ---*/
180
181static int Reverb_Process(effect_interface_t self, audio_buffer_t *inBuffer, audio_buffer_t *outBuffer) {
182 reverb_object_t *pReverb;
183 int16_t *pSrc, *pDst;
184 reverb_module_t *pRvbModule = (reverb_module_t *)self;
185
186 if (pRvbModule == NULL) {
187 return -EINVAL;
188 }
189
190 if (inBuffer == NULL || inBuffer->raw == NULL ||
191 outBuffer == NULL || outBuffer->raw == NULL ||
192 inBuffer->frameCount != outBuffer->frameCount) {
193 return -EINVAL;
194 }
195
196 pReverb = (reverb_object_t*) &pRvbModule->context;
197
198 //if bypassed or the preset forces the signal to be completely dry
199 if (pReverb->m_bBypass) {
Eric Laurentffe9c252010-06-23 17:38:20 -0700200 if (inBuffer->raw != outBuffer->raw) {
201 int16_t smp;
202 pSrc = inBuffer->s16;
203 pDst = outBuffer->s16;
204 size_t count = inBuffer->frameCount;
205 if (pRvbModule->config.inputCfg.channels == pRvbModule->config.outputCfg.channels) {
206 count *= 2;
207 while (count--) {
208 *pDst++ = *pSrc++;
209 }
210 } else {
211 while (count--) {
212 smp = *pSrc++;
213 *pDst++ = smp;
214 *pDst++ = smp;
215 }
216 }
Eric Laurent135ad072010-05-21 06:05:13 -0700217 }
218 return 0;
219 }
220
221 if (pReverb->m_nNextRoom != pReverb->m_nCurrentRoom) {
222 ReverbUpdateRoom(pReverb, true);
223 }
224
225 pSrc = inBuffer->s16;
226 pDst = outBuffer->s16;
227 size_t numSamples = outBuffer->frameCount;
228 while (numSamples) {
229 uint32_t processedSamples;
230 if (numSamples > (uint32_t) pReverb->m_nUpdatePeriodInSamples) {
231 processedSamples = (uint32_t) pReverb->m_nUpdatePeriodInSamples;
232 } else {
233 processedSamples = numSamples;
234 }
235
236 /* increment update counter */
237 pReverb->m_nUpdateCounter += (int16_t) processedSamples;
238 /* check if update counter needs to be reset */
239 if (pReverb->m_nUpdateCounter >= pReverb->m_nUpdatePeriodInSamples) {
240 /* update interval has elapsed, so reset counter */
241 pReverb->m_nUpdateCounter -= pReverb->m_nUpdatePeriodInSamples;
242 ReverbUpdateXfade(pReverb, pReverb->m_nUpdatePeriodInSamples);
243
244 } /* end if m_nUpdateCounter >= update interval */
245
246 Reverb(pReverb, processedSamples, pDst, pSrc);
247
248 numSamples -= processedSamples;
249 if (pReverb->m_Aux) {
Eric Laurentffe9c252010-06-23 17:38:20 -0700250 pSrc += processedSamples;
Eric Laurent135ad072010-05-21 06:05:13 -0700251 } else {
252 pSrc += processedSamples * NUM_OUTPUT_CHANNELS;
253 }
Eric Laurentffe9c252010-06-23 17:38:20 -0700254 pDst += processedSamples * NUM_OUTPUT_CHANNELS;
Eric Laurent135ad072010-05-21 06:05:13 -0700255 }
256
257 return 0;
258}
259
260static int Reverb_Command(effect_interface_t self, int cmdCode, int cmdSize,
261 void *pCmdData, int *replySize, void *pReplyData) {
262 reverb_module_t *pRvbModule = (reverb_module_t *) self;
263 reverb_object_t *pReverb;
264 int retsize;
265
266 if (pRvbModule == NULL) {
267 return -EINVAL;
268 }
269
270 pReverb = (reverb_object_t*) &pRvbModule->context;
271
272 LOGV("Reverb_Command command %d cmdSize %d",cmdCode, cmdSize);
273
274 switch (cmdCode) {
275 case EFFECT_CMD_INIT:
276 if (pReplyData == NULL || *replySize != sizeof(int)) {
277 return -EINVAL;
278 }
279 *(int *) pReplyData = Reverb_Init(pRvbModule, pReverb->m_Aux, pReverb->m_Preset);
280 break;
281 case EFFECT_CMD_CONFIGURE:
282 if (pCmdData == NULL || cmdSize != sizeof(effect_config_t)
283 || pReplyData == NULL || *replySize != sizeof(int)) {
284 return -EINVAL;
285 }
286 *(int *) pReplyData = Reverb_Configure(pRvbModule,
287 (effect_config_t *)pCmdData, false);
288 break;
289 case EFFECT_CMD_RESET:
290 Reverb_Reset(pReverb, false);
291 break;
292 case EFFECT_CMD_GET_PARAM:
293 LOGV("Reverb_Command EFFECT_CMD_GET_PARAM pCmdData %p, *replySize %d, pReplyData: %p",pCmdData, *replySize, pReplyData);
294
295 if (pCmdData == NULL || cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)) ||
296 pReplyData == NULL || *replySize < (int) sizeof(effect_param_t)) {
297 return -EINVAL;
298 }
299 effect_param_t *rep = (effect_param_t *) pReplyData;
300 memcpy(pReplyData, pCmdData, sizeof(effect_param_t) + sizeof(int32_t));
301 LOGV("Reverb_Command EFFECT_CMD_GET_PARAM param %d, replySize %d",*(int32_t *)rep->data, rep->vsize);
302 rep->status = Reverb_getParameter(pReverb, *(int32_t *)rep->data, &rep->vsize,
303 rep->data + sizeof(int32_t));
304 *replySize = sizeof(effect_param_t) + sizeof(int32_t) + rep->vsize;
305 break;
306 case EFFECT_CMD_SET_PARAM:
307 LOGV("Reverb_Command EFFECT_CMD_SET_PARAM cmdSize %d pCmdData %p, *replySize %d, pReplyData %p",
308 cmdSize, pCmdData, *replySize, pReplyData);
309 if (pCmdData == NULL || (cmdSize < (int)(sizeof(effect_param_t) + sizeof(int32_t)))
310 || pReplyData == NULL || *replySize != (int)sizeof(int32_t)) {
311 return -EINVAL;
312 }
313 effect_param_t *cmd = (effect_param_t *) pCmdData;
314 *(int *)pReplyData = Reverb_setParameter(pReverb, *(int32_t *)cmd->data,
315 cmd->vsize, cmd->data + sizeof(int32_t));
316 break;
Eric Laurentffe9c252010-06-23 17:38:20 -0700317 case EFFECT_CMD_ENABLE:
318 case EFFECT_CMD_DISABLE:
319 if (pReplyData == NULL || *replySize != sizeof(int)) {
320 return -EINVAL;
321 }
322 *(int *)pReplyData = 0;
323 break;
324 case EFFECT_CMD_SET_DEVICE:
325 if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t)) {
326 return -EINVAL;
327 }
328 LOGV("Reverb_Command EFFECT_CMD_SET_DEVICE: 0x%08x", *(uint32_t *)pCmdData);
329 break;
330 case EFFECT_CMD_SET_VOLUME: {
331 // audio output is always stereo => 2 channel volumes
332 if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t) * 2) {
333 return -EINVAL;
334 }
335 float left = (float)(*(uint32_t *)pCmdData) / (1 << 24);
336 float right = (float)(*((uint32_t *)pCmdData + 1)) / (1 << 24);
337 LOGV("Reverb_Command EFFECT_CMD_SET_VOLUME: left %f, right %f ", left, right);
338 break;
339 }
340 case EFFECT_CMD_SET_AUDIO_MODE:
341 if (pCmdData == NULL || cmdSize != (int)sizeof(uint32_t)) {
342 return -EINVAL;
343 }
344 LOGV("Reverb_Command EFFECT_CMD_SET_AUDIO_MODE: %d", *(uint32_t *)pCmdData);
345 break;
Eric Laurent135ad072010-05-21 06:05:13 -0700346 default:
347 LOGW("Reverb_Command invalid command %d",cmdCode);
348 return -EINVAL;
349 }
350
351 return 0;
352}
353
354
355/*----------------------------------------------------------------------------
356 * Reverb internal functions
357 *--------------------------------------------------------------------------*/
358
359/*----------------------------------------------------------------------------
360 * Reverb_Init()
361 *----------------------------------------------------------------------------
362 * Purpose:
363 * Initialize reverb context and apply default parameters
364 *
365 * Inputs:
366 * pRvbModule - pointer to reverb effect module
367 * aux - indicates if the reverb is used as auxiliary (1) or insert (0)
368 * preset - indicates if the reverb is used in preset (1) or environmental (0) mode
369 *
370 * Outputs:
371 *
372 * Side Effects:
373 *
374 *----------------------------------------------------------------------------
375 */
376
377int Reverb_Init(reverb_module_t *pRvbModule, int aux, int preset) {
378 int ret;
379
380 LOGV("Reverb_Init module %p, aux: %d, preset: %d", pRvbModule,aux, preset);
381
382 memset(&pRvbModule->context, 0, sizeof(reverb_object_t));
383
384 pRvbModule->context.m_Aux = (uint16_t)aux;
385 pRvbModule->context.m_Preset = (uint16_t)preset;
386
387 pRvbModule->config.inputCfg.samplingRate = 44100;
388 if (aux) {
389 pRvbModule->config.inputCfg.channels = CHANNEL_MONO;
390 } else {
391 pRvbModule->config.inputCfg.channels = CHANNEL_STEREO;
392 }
Eric Laurentffe9c252010-06-23 17:38:20 -0700393 pRvbModule->config.inputCfg.format = SAMPLE_FORMAT_PCM_S15;
Eric Laurent135ad072010-05-21 06:05:13 -0700394 pRvbModule->config.inputCfg.bufferProvider.getBuffer = NULL;
395 pRvbModule->config.inputCfg.bufferProvider.releaseBuffer = NULL;
396 pRvbModule->config.inputCfg.bufferProvider.cookie = NULL;
397 pRvbModule->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
398 pRvbModule->config.inputCfg.mask = EFFECT_CONFIG_ALL;
399 pRvbModule->config.outputCfg.samplingRate = 44100;
400 pRvbModule->config.outputCfg.channels = CHANNEL_STEREO;
Eric Laurentffe9c252010-06-23 17:38:20 -0700401 pRvbModule->config.outputCfg.format = SAMPLE_FORMAT_PCM_S15;
Eric Laurent135ad072010-05-21 06:05:13 -0700402 pRvbModule->config.outputCfg.bufferProvider.getBuffer = NULL;
403 pRvbModule->config.outputCfg.bufferProvider.releaseBuffer = NULL;
404 pRvbModule->config.outputCfg.bufferProvider.cookie = NULL;
405 pRvbModule->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
406 pRvbModule->config.outputCfg.mask = EFFECT_CONFIG_ALL;
407
408 ret = Reverb_Configure(pRvbModule, &pRvbModule->config, true);
409 if (ret < 0) {
410 LOGV("Reverb_Init error %d on module %p", ret, pRvbModule);
411 }
412
413 return ret;
414}
415
416/*----------------------------------------------------------------------------
417 * Reverb_Init()
418 *----------------------------------------------------------------------------
419 * Purpose:
420 * Set input and output audio configuration.
421 *
422 * Inputs:
423 * pRvbModule - pointer to reverb effect module
424 * pConfig - pointer to effect_config_t structure containing input
425 * and output audio parameters configuration
426 * init - true if called from init function
427 * Outputs:
428 *
429 * Side Effects:
430 *
431 *----------------------------------------------------------------------------
432 */
433
434int Reverb_Configure(reverb_module_t *pRvbModule, effect_config_t *pConfig,
435 bool init) {
436 reverb_object_t *pReverb = &pRvbModule->context;
437 int bufferSizeInSamples;
438 int updatePeriodInSamples;
439 int xfadePeriodInSamples;
440
441 // Check configuration compatibility with build options
442 if (pConfig->inputCfg.samplingRate
443 != pConfig->outputCfg.samplingRate
444 || pConfig->outputCfg.channels != OUTPUT_CHANNELS
Eric Laurentffe9c252010-06-23 17:38:20 -0700445 || pConfig->inputCfg.format != SAMPLE_FORMAT_PCM_S15
446 || pConfig->outputCfg.format != SAMPLE_FORMAT_PCM_S15) {
Eric Laurent135ad072010-05-21 06:05:13 -0700447 LOGV("Reverb_Configure invalid config");
448 return -EINVAL;
449 }
450 if ((pReverb->m_Aux && (pConfig->inputCfg.channels != CHANNEL_MONO)) ||
451 (!pReverb->m_Aux && (pConfig->inputCfg.channels != CHANNEL_STEREO))) {
452 LOGV("Reverb_Configure invalid config");
453 return -EINVAL;
454 }
455
456 memcpy(&pRvbModule->config, pConfig, sizeof(effect_config_t));
457
458 pReverb->m_nSamplingRate = pRvbModule->config.outputCfg.samplingRate;
459
460 switch (pReverb->m_nSamplingRate) {
461 case 8000:
462 pReverb->m_nUpdatePeriodInBits = 5;
463 bufferSizeInSamples = 4096;
464 pReverb->m_nCosWT_5KHz = -23170;
465 break;
466 case 16000:
467 pReverb->m_nUpdatePeriodInBits = 6;
468 bufferSizeInSamples = 8192;
469 pReverb->m_nCosWT_5KHz = -12540;
470 break;
471 case 22050:
472 pReverb->m_nUpdatePeriodInBits = 7;
473 bufferSizeInSamples = 8192;
474 pReverb->m_nCosWT_5KHz = 4768;
475 break;
476 case 32000:
477 pReverb->m_nUpdatePeriodInBits = 7;
478 bufferSizeInSamples = 16384;
479 pReverb->m_nCosWT_5KHz = 18205;
480 break;
481 case 44100:
482 pReverb->m_nUpdatePeriodInBits = 8;
483 bufferSizeInSamples = 16384;
484 pReverb->m_nCosWT_5KHz = 24799;
485 break;
486 case 48000:
487 pReverb->m_nUpdatePeriodInBits = 8;
488 bufferSizeInSamples = 16384;
489 pReverb->m_nCosWT_5KHz = 25997;
490 break;
491 default:
492 LOGV("Reverb_Configure invalid sampling rate %d", pReverb->m_nSamplingRate);
493 return -EINVAL;
494 }
495
496 // Define a mask for circular addressing, so that array index
497 // can wraparound and stay in array boundary of 0, 1, ..., (buffer size -1)
498 // The buffer size MUST be a power of two
499 pReverb->m_nBufferMask = (int32_t) (bufferSizeInSamples - 1);
500 /* reverb parameters are updated every 2^(pReverb->m_nUpdatePeriodInBits) samples */
501 updatePeriodInSamples = (int32_t) (0x1L << pReverb->m_nUpdatePeriodInBits);
502 /*
503 calculate the update counter by bitwise ANDING with this value to
504 generate a 2^n modulo value
505 */
506 pReverb->m_nUpdatePeriodInSamples = (int32_t) updatePeriodInSamples;
507
508 xfadePeriodInSamples = (int32_t) (REVERB_XFADE_PERIOD_IN_SECONDS
509 * (double) pReverb->m_nSamplingRate);
510
511 // set xfade parameters
512 pReverb->m_nPhaseIncrement
513 = (int16_t) (65536 / ((int16_t) xfadePeriodInSamples
514 / (int16_t) updatePeriodInSamples));
515
516 if (init) {
517 ReverbReadInPresets(pReverb);
518
519 // for debugging purposes, allow noise generator
520 pReverb->m_bUseNoise = true;
521
522 // for debugging purposes, allow bypass
523 pReverb->m_bBypass = false;
524
525 pReverb->m_nNextRoom = 1;
526
527 pReverb->m_nNoise = (int16_t) 0xABCD;
528 }
529
530 Reverb_Reset(pReverb, init);
531
532 return 0;
533}
534
535/*----------------------------------------------------------------------------
536 * Reverb_Reset()
537 *----------------------------------------------------------------------------
538 * Purpose:
539 * Reset internal states and clear delay lines.
540 *
541 * Inputs:
542 * pReverb - pointer to reverb context
543 * init - true if called from init function
544 *
545 * Outputs:
546 *
547 * Side Effects:
548 *
549 *----------------------------------------------------------------------------
550 */
551
552void Reverb_Reset(reverb_object_t *pReverb, bool init) {
553 int bufferSizeInSamples = (int32_t) (pReverb->m_nBufferMask + 1);
554 int maxApSamples;
555 int maxDelaySamples;
556 int maxEarlySamples;
557 int ap1In;
558 int delay0In;
559 int delay1In;
560 int32_t i;
561 uint16_t nOffset;
562
563 maxApSamples = ((int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16);
564 maxDelaySamples = ((int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate)
565 >> 16);
566 maxEarlySamples = ((int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate)
567 >> 16);
568
569 ap1In = (AP0_IN + maxApSamples + GUARD);
570 delay0In = (ap1In + maxApSamples + GUARD);
571 delay1In = (delay0In + maxDelaySamples + GUARD);
572 // Define the max offsets for the end points of each section
573 // i.e., we don't expect a given section's taps to go beyond
574 // the following limits
575
576 pReverb->m_nEarly0in = (delay1In + maxDelaySamples + GUARD);
577 pReverb->m_nEarly1in = (pReverb->m_nEarly0in + maxEarlySamples + GUARD);
578
579 pReverb->m_sAp0.m_zApIn = AP0_IN;
580
581 pReverb->m_zD0In = delay0In;
582
583 pReverb->m_sAp1.m_zApIn = ap1In;
584
585 pReverb->m_zD1In = delay1In;
586
587 pReverb->m_zOutLpfL = 0;
588 pReverb->m_zOutLpfR = 0;
589
590 pReverb->m_nRevFbkR = 0;
591 pReverb->m_nRevFbkL = 0;
592
593 // set base index into circular buffer
594 pReverb->m_nBaseIndex = 0;
595
596 // clear the reverb delay line
597 for (i = 0; i < bufferSizeInSamples; i++) {
598 pReverb->m_nDelayLine[i] = 0;
599 }
600
601 ReverbUpdateRoom(pReverb, init);
602
603 pReverb->m_nUpdateCounter = 0;
604
605 pReverb->m_nPhase = -32768;
606
607 pReverb->m_nSin = 0;
608 pReverb->m_nCos = 0;
609 pReverb->m_nSinIncrement = 0;
610 pReverb->m_nCosIncrement = 0;
611
612 // set delay tap lengths
613 nOffset = ReverbCalculateNoise(pReverb);
614
615 pReverb->m_zD1Cross = pReverb->m_nDelay1Out - pReverb->m_nMaxExcursion
616 + nOffset;
617
618 nOffset = ReverbCalculateNoise(pReverb);
619
620 pReverb->m_zD0Cross = pReverb->m_nDelay0Out - pReverb->m_nMaxExcursion
621 - nOffset;
622
623 nOffset = ReverbCalculateNoise(pReverb);
624
625 pReverb->m_zD0Self = pReverb->m_nDelay0Out - pReverb->m_nMaxExcursion
626 - nOffset;
627
628 nOffset = ReverbCalculateNoise(pReverb);
629
630 pReverb->m_zD1Self = pReverb->m_nDelay1Out - pReverb->m_nMaxExcursion
631 + nOffset;
632}
633
634/*----------------------------------------------------------------------------
635 * Reverb_getParameter()
636 *----------------------------------------------------------------------------
637 * Purpose:
638 * Get a Reverb parameter
639 *
640 * Inputs:
641 * pReverb - handle to instance data
642 * param - parameter
643 * pValue - pointer to variable to hold retrieved value
644 * pSize - pointer to value size: maximum size as input
645 *
646 * Outputs:
647 * *pValue updated with parameter value
648 * *pSize updated with actual value size
649 *
650 *
651 * Side Effects:
652 *
653 *----------------------------------------------------------------------------
654 */
655int Reverb_getParameter(reverb_object_t *pReverb, int32_t param, size_t *pSize,
656 void *pValue) {
657 int32_t *pValue32;
658 int16_t *pValue16;
659 t_reverb_properties *pProperties;
660 int32_t i;
661 int32_t temp;
662 int32_t temp2;
663 size_t size;
664
665 if (pReverb->m_Preset && param != REVERB_PARAM_PRESET) {
666 return -EINVAL;
667 }
668 if (!pReverb->m_Preset && param == REVERB_PARAM_PRESET) {
669 return -EINVAL;
670 }
671
672 switch (param) {
673 case REVERB_PARAM_ROOM_LEVEL:
674 case REVERB_PARAM_ROOM_HF_LEVEL:
675 case REVERB_PARAM_DECAY_HF_RATIO:
676 case REVERB_PARAM_REFLECTIONS_LEVEL:
677 case REVERB_PARAM_REVERB_LEVEL:
678 case REVERB_PARAM_DIFFUSION:
679 case REVERB_PARAM_DENSITY:
680 size = sizeof(int16_t);
681 break;
682
683 case REVERB_PARAM_BYPASS:
684 case REVERB_PARAM_PRESET:
685 case REVERB_PARAM_DECAY_TIME:
686 case REVERB_PARAM_REFLECTIONS_DELAY:
687 case REVERB_PARAM_REVERB_DELAY:
688 size = sizeof(int32_t);
689 break;
690
691 case REVERB_PARAM_PROPERTIES:
692 size = sizeof(t_reverb_properties);
693 break;
694
695 default:
696 return -EINVAL;
697 }
698
699 if (*pSize < size) {
700 return -EINVAL;
701 }
702 *pSize = size;
703 pValue32 = (int32_t *) pValue;
704 pValue16 = (int16_t *) pValue;
705 pProperties = (t_reverb_properties *) pValue;
706
707 switch (param) {
708 case REVERB_PARAM_BYPASS:
709 *(int32_t *) pValue = (int32_t) pReverb->m_bBypass;
710 break;
711 case REVERB_PARAM_PRESET:
712 *(int32_t *) pValue = (int8_t) pReverb->m_nCurrentRoom;
713 break;
714
715 case REVERB_PARAM_PROPERTIES:
716 pValue16 = &pProperties->roomLevel;
717 /* FALL THROUGH */
718
719 case REVERB_PARAM_ROOM_LEVEL:
720 // Convert m_nRoomLpfFwd to millibels
721 temp = (pReverb->m_nRoomLpfFwd << 15)
722 / (32767 - pReverb->m_nRoomLpfFbk);
723 *pValue16 = Effects_Linear16ToMillibels(temp);
724
725 LOGV("get REVERB_PARAM_ROOM_LEVEL %d, gain %d, m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", *pValue16, temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk);
726
727 if (param == REVERB_PARAM_ROOM_LEVEL) {
728 break;
729 }
730 pValue16 = &pProperties->roomHFLevel;
731 /* FALL THROUGH */
732
733 case REVERB_PARAM_ROOM_HF_LEVEL:
734 // The ratio between linear gain at 0Hz and at 5000Hz for the room low pass is:
735 // (1 + a1) / sqrt(a1^2 + 2*C*a1 + 1) where:
736 // - a1 is minus the LP feedback gain: -pReverb->m_nRoomLpfFbk
737 // - C is cos(2piWT) @ 5000Hz: pReverb->m_nCosWT_5KHz
738
739 temp = MULT_EG1_EG1(pReverb->m_nRoomLpfFbk, pReverb->m_nRoomLpfFbk);
740 LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, a1^2 %d", temp);
741 temp2 = MULT_EG1_EG1(pReverb->m_nRoomLpfFbk, pReverb->m_nCosWT_5KHz)
742 << 1;
743 LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, 2 Cos a1 %d", temp2);
744 temp = 32767 + temp - temp2;
745 LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, a1^2 + 2 Cos a1 + 1 %d", temp);
746 temp = Effects_Sqrt(temp) * 181;
747 LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, SQRT(a1^2 + 2 Cos a1 + 1) %d", temp);
748 temp = ((32767 - pReverb->m_nRoomLpfFbk) << 15) / temp;
749
750 LOGV("get REVERB_PARAM_ROOM_HF_LEVEL, gain %d, m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk);
751
752 *pValue16 = Effects_Linear16ToMillibels(temp);
753
754 if (param == REVERB_PARAM_ROOM_HF_LEVEL) {
755 break;
756 }
757 pValue32 = &pProperties->decayTime;
758 /* FALL THROUGH */
759
760 case REVERB_PARAM_DECAY_TIME:
761 // Calculate reverb feedback path gain
762 temp = (pReverb->m_nRvbLpfFwd << 15) / (32767 - pReverb->m_nRvbLpfFbk);
763 temp = Effects_Linear16ToMillibels(temp);
764
765 // Calculate decay time: g = -6000 d/DT , g gain in millibels, d reverb delay, DT decay time
766 temp = (-6000 * pReverb->m_nLateDelay) / temp;
767
768 // Convert samples to ms
769 *pValue32 = (temp * 1000) / pReverb->m_nSamplingRate;
770
771 LOGV("get REVERB_PARAM_DECAY_TIME, samples %d, ms %d", temp, *pValue32);
772
773 if (param == REVERB_PARAM_DECAY_TIME) {
774 break;
775 }
776 pValue16 = &pProperties->decayHFRatio;
777 /* FALL THROUGH */
778
779 case REVERB_PARAM_DECAY_HF_RATIO:
780 // If r is the decay HF ratio (r = REVERB_PARAM_DECAY_HF_RATIO/1000) we have:
781 // DT_5000Hz = DT_0Hz * r
782 // and G_5000Hz = -6000 * d / DT_5000Hz and G_0Hz = -6000 * d / DT_0Hz in millibels so :
783 // r = G_0Hz/G_5000Hz in millibels
784 // The linear gain at 5000Hz is b0 / sqrt(a1^2 + 2*C*a1 + 1) where:
785 // - a1 is minus the LP feedback gain: -pReverb->m_nRvbLpfFbk
786 // - b0 is the LP forward gain: pReverb->m_nRvbLpfFwd
787 // - C is cos(2piWT) @ 5000Hz: pReverb->m_nCosWT_5KHz
788 if (pReverb->m_nRvbLpfFbk == 0) {
789 *pValue16 = 1000;
790 LOGV("get REVERB_PARAM_DECAY_HF_RATIO, pReverb->m_nRvbLpfFbk == 0, ratio %d", *pValue16);
791 } else {
792 temp = MULT_EG1_EG1(pReverb->m_nRvbLpfFbk, pReverb->m_nRvbLpfFbk);
793 temp2 = MULT_EG1_EG1(pReverb->m_nRvbLpfFbk, pReverb->m_nCosWT_5KHz)
794 << 1;
795 temp = 32767 + temp - temp2;
796 temp = Effects_Sqrt(temp) * 181;
797 temp = (pReverb->m_nRvbLpfFwd << 15) / temp;
798 // The linear gain at 0Hz is b0 / (a1 + 1)
799 temp2 = (pReverb->m_nRvbLpfFwd << 15) / (32767
800 - pReverb->m_nRvbLpfFbk);
801
802 temp = Effects_Linear16ToMillibels(temp);
803 temp2 = Effects_Linear16ToMillibels(temp2);
804 LOGV("get REVERB_PARAM_DECAY_HF_RATIO, gain 5KHz %d mB, gain DC %d mB", temp, temp2);
805
806 if (temp == 0)
807 temp = 1;
808 temp = (int16_t) ((1000 * temp2) / temp);
809 if (temp > 1000)
810 temp = 1000;
811
812 *pValue16 = temp;
813 LOGV("get REVERB_PARAM_DECAY_HF_RATIO, ratio %d", *pValue16);
814 }
815
816 if (param == REVERB_PARAM_DECAY_HF_RATIO) {
817 break;
818 }
819 pValue16 = &pProperties->reflectionsLevel;
820 /* FALL THROUGH */
821
822 case REVERB_PARAM_REFLECTIONS_LEVEL:
823 *pValue16 = Effects_Linear16ToMillibels(pReverb->m_nEarlyGain);
824
825 LOGV("get REVERB_PARAM_REFLECTIONS_LEVEL, %d", *pValue16);
826 if (param == REVERB_PARAM_REFLECTIONS_LEVEL) {
827 break;
828 }
829 pValue32 = &pProperties->reflectionsDelay;
830 /* FALL THROUGH */
831
832 case REVERB_PARAM_REFLECTIONS_DELAY:
833 // convert samples to ms
834 *pValue32 = (pReverb->m_nEarlyDelay * 1000) / pReverb->m_nSamplingRate;
835
836 LOGV("get REVERB_PARAM_REFLECTIONS_DELAY, samples %d, ms %d", pReverb->m_nEarlyDelay, *pValue32);
837
838 if (param == REVERB_PARAM_REFLECTIONS_DELAY) {
839 break;
840 }
841 pValue16 = &pProperties->reverbLevel;
842 /* FALL THROUGH */
843
844 case REVERB_PARAM_REVERB_LEVEL:
845 // Convert linear gain to millibels
846 *pValue16 = Effects_Linear16ToMillibels(pReverb->m_nLateGain << 2);
847
848 LOGV("get REVERB_PARAM_REVERB_LEVEL %d", *pValue16);
849
850 if (param == REVERB_PARAM_REVERB_LEVEL) {
851 break;
852 }
853 pValue32 = &pProperties->reverbDelay;
854 /* FALL THROUGH */
855
856 case REVERB_PARAM_REVERB_DELAY:
857 // convert samples to ms
858 *pValue32 = (pReverb->m_nLateDelay * 1000) / pReverb->m_nSamplingRate;
859
860 LOGV("get REVERB_PARAM_REVERB_DELAY, samples %d, ms %d", pReverb->m_nLateDelay, *pValue32);
861
862 if (param == REVERB_PARAM_REVERB_DELAY) {
863 break;
864 }
865 pValue16 = &pProperties->diffusion;
866 /* FALL THROUGH */
867
868 case REVERB_PARAM_DIFFUSION:
869 temp = (int16_t) ((1000 * (pReverb->m_sAp0.m_nApGain - AP0_GAIN_BASE))
870 / AP0_GAIN_RANGE);
871
872 if (temp < 0)
873 temp = 0;
874 if (temp > 1000)
875 temp = 1000;
876
877 *pValue16 = temp;
878 LOGV("get REVERB_PARAM_DIFFUSION, %d, AP0 gain %d", *pValue16, pReverb->m_sAp0.m_nApGain);
879
880 if (param == REVERB_PARAM_DIFFUSION) {
881 break;
882 }
883 pValue16 = &pProperties->density;
884 /* FALL THROUGH */
885
886 case REVERB_PARAM_DENSITY:
887 // Calculate AP delay in time units
888 temp = ((pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn) << 16)
889 / pReverb->m_nSamplingRate;
890
891 temp = (int16_t) ((1000 * (temp - AP0_TIME_BASE)) / AP0_TIME_RANGE);
892
893 if (temp < 0)
894 temp = 0;
895 if (temp > 1000)
896 temp = 1000;
897
898 *pValue16 = temp;
899
900 LOGV("get REVERB_PARAM_DENSITY, %d, AP0 delay smps %d", *pValue16, pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn);
901 break;
902
903 default:
904 break;
905 }
906
907 LOGV("Reverb_getParameter, context %p, param %d, value %d",
908 pReverb, param, *(int *)pValue);
909
910 return 0;
911} /* end Reverb_getParameter */
912
913/*----------------------------------------------------------------------------
914 * Reverb_setParameter()
915 *----------------------------------------------------------------------------
916 * Purpose:
917 * Set a Reverb parameter
918 *
919 * Inputs:
920 * pReverb - handle to instance data
921 * param - parameter
922 * pValue - pointer to parameter value
923 * size - value size
924 *
925 * Outputs:
926 *
927 *
928 * Side Effects:
929 *
930 *----------------------------------------------------------------------------
931 */
932int Reverb_setParameter(reverb_object_t *pReverb, int32_t param, size_t size,
933 void *pValue) {
934 int32_t value32;
935 int16_t value16;
936 t_reverb_properties *pProperties;
937 int32_t i;
938 int32_t temp;
939 int32_t temp2;
940 reverb_preset_t *pPreset;
941 int maxSamples;
942 int32_t averageDelay;
943 size_t paramSize;
944
945 LOGV("Reverb_setParameter, context %p, param %d, value16 %d, value32 %d",
946 pReverb, param, *(int16_t *)pValue, *(int32_t *)pValue);
947
948 if (pReverb->m_Preset && param != REVERB_PARAM_PRESET) {
949 return -EINVAL;
950 }
951 if (!pReverb->m_Preset && param == REVERB_PARAM_PRESET) {
952 return -EINVAL;
953 }
954
955 switch (param) {
956 case REVERB_PARAM_ROOM_LEVEL:
957 case REVERB_PARAM_ROOM_HF_LEVEL:
958 case REVERB_PARAM_DECAY_HF_RATIO:
959 case REVERB_PARAM_REFLECTIONS_LEVEL:
960 case REVERB_PARAM_REVERB_LEVEL:
961 case REVERB_PARAM_DIFFUSION:
962 case REVERB_PARAM_DENSITY:
963 paramSize = sizeof(int16_t);
964 break;
965
966 case REVERB_PARAM_BYPASS:
967 case REVERB_PARAM_PRESET:
968 case REVERB_PARAM_DECAY_TIME:
969 case REVERB_PARAM_REFLECTIONS_DELAY:
970 case REVERB_PARAM_REVERB_DELAY:
971 paramSize = sizeof(int32_t);
972 break;
973
974 case REVERB_PARAM_PROPERTIES:
975 paramSize = sizeof(t_reverb_properties);
976 break;
977
978 default:
979 return -EINVAL;
980 }
981
982 if (size != paramSize) {
983 return -EINVAL;
984 }
985
986 if (paramSize == sizeof(int16_t)) {
987 value16 = *(int16_t *) pValue;
988 } else if (paramSize == sizeof(int32_t)) {
989 value32 = *(int32_t *) pValue;
990 } else {
991 pProperties = (t_reverb_properties *) pValue;
992 }
993
994 pPreset = &pReverb->m_sPreset.m_sPreset[pReverb->m_nCurrentRoom];
995
996 switch (param) {
997 case REVERB_PARAM_BYPASS:
998 pReverb->m_bBypass = (uint16_t)value32;
999 break;
1000 case REVERB_PARAM_PRESET:
1001 if (value32 != REVERB_PRESET_LARGE_HALL && value32
1002 != REVERB_PRESET_HALL && value32 != REVERB_PRESET_CHAMBER
1003 && value32 != REVERB_PRESET_ROOM)
1004 return -EINVAL;
1005 pReverb->m_nNextRoom = (int16_t) value32;
1006 break;
1007
1008 case REVERB_PARAM_PROPERTIES:
1009 value16 = pProperties->roomLevel;
1010 /* FALL THROUGH */
1011
1012 case REVERB_PARAM_ROOM_LEVEL:
1013 // Convert millibels to linear 16 bit signed => m_nRoomLpfFwd
1014 if (value16 > 0)
1015 return -EINVAL;
1016
1017 temp = Effects_MillibelsToLinear16(value16);
1018
1019 pReverb->m_nRoomLpfFwd
1020 = MULT_EG1_EG1(temp, (32767 - pReverb->m_nRoomLpfFbk));
1021
1022 LOGV("REVERB_PARAM_ROOM_LEVEL, gain %d, new m_nRoomLpfFwd %d, m_nRoomLpfFbk %d", temp, pReverb->m_nRoomLpfFwd, pReverb->m_nRoomLpfFbk);
1023 if (param == REVERB_PARAM_ROOM_LEVEL)
1024 break;
1025 value16 = pProperties->roomHFLevel;
1026 /* FALL THROUGH */
1027
1028 case REVERB_PARAM_ROOM_HF_LEVEL:
1029
1030 // Limit to 0 , -40dB range because of low pass implementation
1031 if (value16 > 0 || value16 < -4000)
1032 return -EINVAL;
1033 // Convert attenuation @ 5000H expressed in millibels to => m_nRoomLpfFbk
1034 // m_nRoomLpfFbk is -a1 where a1 is the solution of:
1035 // a1^2 + 2*(C-dG^2)/(1-dG^2)*a1 + 1 = 0 where:
1036 // - C is cos(2*pi*5000/Fs) (pReverb->m_nCosWT_5KHz)
1037 // - dG is G0/Gf (G0 is the linear gain at DC and Gf is the wanted gain at 5000Hz)
1038
1039 // Save current DC gain m_nRoomLpfFwd / (32767 - m_nRoomLpfFbk) to keep it unchanged
1040 // while changing HF level
1041 temp2 = (pReverb->m_nRoomLpfFwd << 15) / (32767
1042 - pReverb->m_nRoomLpfFbk);
1043 if (value16 == 0) {
1044 pReverb->m_nRoomLpfFbk = 0;
1045 } else {
1046 int32_t dG2, b, delta;
1047
1048 // dG^2
1049 temp = Effects_MillibelsToLinear16(value16);
1050 LOGV("REVERB_PARAM_ROOM_HF_LEVEL, HF gain %d", temp);
1051 temp = (1 << 30) / temp;
1052 LOGV("REVERB_PARAM_ROOM_HF_LEVEL, 1/ HF gain %d", temp);
1053 dG2 = (int32_t) (((int64_t) temp * (int64_t) temp) >> 15);
1054 LOGV("REVERB_PARAM_ROOM_HF_LEVEL, 1/ HF gain ^ 2 %d", dG2);
1055 // b = 2*(C-dG^2)/(1-dG^2)
1056 b = (int32_t) ((((int64_t) 1 << (15 + 1))
1057 * ((int64_t) pReverb->m_nCosWT_5KHz - (int64_t) dG2))
1058 / ((int64_t) 32767 - (int64_t) dG2));
1059
1060 // delta = b^2 - 4
1061 delta = (int32_t) ((((int64_t) b * (int64_t) b) >> 15) - (1 << (15
1062 + 2)));
1063
1064 LOGV_IF(delta > (1<<30), " delta overflow %d", delta);
1065
1066 LOGV("REVERB_PARAM_ROOM_HF_LEVEL, dG2 %d, b %d, delta %d, m_nCosWT_5KHz %d", dG2, b, delta, pReverb->m_nCosWT_5KHz);
1067 // m_nRoomLpfFbk = -a1 = - (- b + sqrt(delta)) / 2
1068 pReverb->m_nRoomLpfFbk = (b - Effects_Sqrt(delta) * 181) >> 1;
1069 }
1070 LOGV("REVERB_PARAM_ROOM_HF_LEVEL, olg DC gain %d new m_nRoomLpfFbk %d, old m_nRoomLpfFwd %d",
1071 temp2, pReverb->m_nRoomLpfFbk, pReverb->m_nRoomLpfFwd);
1072
1073 pReverb->m_nRoomLpfFwd
1074 = MULT_EG1_EG1(temp2, (32767 - pReverb->m_nRoomLpfFbk));
1075 LOGV("REVERB_PARAM_ROOM_HF_LEVEL, new m_nRoomLpfFwd %d", pReverb->m_nRoomLpfFwd);
1076
1077 if (param == REVERB_PARAM_ROOM_HF_LEVEL)
1078 break;
1079 value32 = pProperties->decayTime;
1080 /* FALL THROUGH */
1081
1082 case REVERB_PARAM_DECAY_TIME:
1083
1084 // Convert milliseconds to => m_nRvbLpfFwd (function of m_nRvbLpfFbk)
1085 // convert ms to samples
1086 value32 = (value32 * pReverb->m_nSamplingRate) / 1000;
Eric Laurentffe9c252010-06-23 17:38:20 -07001087
Eric Laurent135ad072010-05-21 06:05:13 -07001088 // calculate valid decay time range as a function of current reverb delay and
1089 // max feed back gain. Min value <=> -40dB in one pass, Max value <=> feedback gain = -1 dB
1090 // Calculate attenuation for each round in late reverb given a total attenuation of -6000 millibels.
1091 // g = -6000 d/DT , g gain in millibels, d reverb delay, DT decay time
1092 averageDelay = pReverb->m_nLateDelay - pReverb->m_nMaxExcursion;
1093 averageDelay += ((pReverb->m_sAp0.m_zApOut - pReverb->m_sAp0.m_zApIn)
1094 + (pReverb->m_sAp1.m_zApOut - pReverb->m_sAp1.m_zApIn)) >> 1;
1095
1096 temp = (-6000 * averageDelay) / value32;
1097 LOGV("REVERB_PARAM_DECAY_TIME, delay smps %d, DT smps %d, gain mB %d",averageDelay, value32, temp);
1098 if (temp < -4000 || temp > -100)
1099 return -EINVAL;
1100
1101 // calculate low pass gain by adding reverb input attenuation (pReverb->m_nLateGain) and substrating output
1102 // xfade and sum gain (max +9dB)
1103 temp -= Effects_Linear16ToMillibels(pReverb->m_nLateGain) + 900;
1104 temp = Effects_MillibelsToLinear16(temp);
1105
1106 // DC gain (temp) = b0 / (1 + a1) = pReverb->m_nRvbLpfFwd / (32767 - pReverb->m_nRvbLpfFbk)
1107 pReverb->m_nRvbLpfFwd
1108 = MULT_EG1_EG1(temp, (32767 - pReverb->m_nRvbLpfFbk));
1109
1110 LOGV("REVERB_PARAM_DECAY_TIME, gain %d, new m_nRvbLpfFwd %d, old m_nRvbLpfFbk %d, reverb gain %d", temp, pReverb->m_nRvbLpfFwd, pReverb->m_nRvbLpfFbk, Effects_Linear16ToMillibels(pReverb->m_nLateGain));
1111
1112 if (param == REVERB_PARAM_DECAY_TIME)
1113 break;
1114 value16 = pProperties->decayHFRatio;
1115 /* FALL THROUGH */
1116
1117 case REVERB_PARAM_DECAY_HF_RATIO:
1118
1119 // We limit max value to 1000 because reverb filter is lowpass only
1120 if (value16 < 100 || value16 > 1000)
1121 return -EINVAL;
1122 // Convert per mille to => m_nLpfFwd, m_nLpfFbk
1123
1124 // Save current DC gain m_nRoomLpfFwd / (32767 - m_nRoomLpfFbk) to keep it unchanged
1125 // while changing HF level
1126 temp2 = (pReverb->m_nRvbLpfFwd << 15) / (32767 - pReverb->m_nRvbLpfFbk);
1127
1128 if (value16 == 1000) {
1129 pReverb->m_nRvbLpfFbk = 0;
1130 } else {
1131 int32_t dG2, b, delta;
1132
1133 temp = Effects_Linear16ToMillibels(temp2);
1134 // G_5000Hz = G_DC * (1000/REVERB_PARAM_DECAY_HF_RATIO) in millibels
1135
1136 value32 = ((int32_t) 1000 << 15) / (int32_t) value16;
1137 LOGV("REVERB_PARAM_DECAY_HF_RATIO, DC gain %d, DC gain mB %d, 1000/R %d", temp2, temp, value32);
1138
1139 temp = (int32_t) (((int64_t) temp * (int64_t) value32) >> 15);
1140
1141 if (temp < -4000) {
1142 LOGV("REVERB_PARAM_DECAY_HF_RATIO HF gain overflow %d mB", temp);
1143 temp = -4000;
1144 }
1145
1146 temp = Effects_MillibelsToLinear16(temp);
1147 LOGV("REVERB_PARAM_DECAY_HF_RATIO, HF gain %d", temp);
1148 // dG^2
1149 temp = (temp2 << 15) / temp;
1150 dG2 = (int32_t) (((int64_t) temp * (int64_t) temp) >> 15);
1151
1152 // b = 2*(C-dG^2)/(1-dG^2)
1153 b = (int32_t) ((((int64_t) 1 << (15 + 1))
1154 * ((int64_t) pReverb->m_nCosWT_5KHz - (int64_t) dG2))
1155 / ((int64_t) 32767 - (int64_t) dG2));
1156
1157 // delta = b^2 - 4
1158 delta = (int32_t) ((((int64_t) b * (int64_t) b) >> 15) - (1 << (15
1159 + 2)));
1160
1161 // m_nRoomLpfFbk = -a1 = - (- b + sqrt(delta)) / 2
1162 pReverb->m_nRvbLpfFbk = (b - Effects_Sqrt(delta) * 181) >> 1;
1163
1164 LOGV("REVERB_PARAM_DECAY_HF_RATIO, dG2 %d, b %d, delta %d", dG2, b, delta);
1165
1166 }
1167
1168 LOGV("REVERB_PARAM_DECAY_HF_RATIO, gain %d, m_nRvbLpfFbk %d, m_nRvbLpfFwd %d", temp2, pReverb->m_nRvbLpfFbk, pReverb->m_nRvbLpfFwd);
1169
1170 pReverb->m_nRvbLpfFwd
1171 = MULT_EG1_EG1(temp2, (32767 - pReverb->m_nRvbLpfFbk));
1172
1173 if (param == REVERB_PARAM_DECAY_HF_RATIO)
1174 break;
1175 value16 = pProperties->reflectionsLevel;
1176 /* FALL THROUGH */
1177
1178 case REVERB_PARAM_REFLECTIONS_LEVEL:
1179 // We limit max value to 0 because gain is limited to 0dB
1180 if (value16 > 0 || value16 < -6000)
1181 return -EINVAL;
1182
1183 // Convert millibels to linear 16 bit signed and recompute m_sEarlyL.m_nGain[i] and m_sEarlyR.m_nGain[i].
1184 value16 = Effects_MillibelsToLinear16(value16);
1185 for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) {
1186 pReverb->m_sEarlyL.m_nGain[i]
1187 = MULT_EG1_EG1(pPreset->m_sEarlyL.m_nGain[i],value16);
1188 pReverb->m_sEarlyR.m_nGain[i]
1189 = MULT_EG1_EG1(pPreset->m_sEarlyR.m_nGain[i],value16);
1190 }
1191 pReverb->m_nEarlyGain = value16;
1192 LOGV("REVERB_PARAM_REFLECTIONS_LEVEL, m_nEarlyGain %d", pReverb->m_nEarlyGain);
1193
1194 if (param == REVERB_PARAM_REFLECTIONS_LEVEL)
1195 break;
1196 value32 = pProperties->reflectionsDelay;
1197 /* FALL THROUGH */
1198
1199 case REVERB_PARAM_REFLECTIONS_DELAY:
1200 // We limit max value MAX_EARLY_TIME
1201 // convert ms to time units
1202 temp = (value32 * 65536) / 1000;
1203 if (temp < 0 || temp > MAX_EARLY_TIME)
1204 return -EINVAL;
1205
1206 maxSamples = (int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate)
1207 >> 16;
1208 temp = (temp * pReverb->m_nSamplingRate) >> 16;
1209 for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) {
1210 temp2 = temp + (((int32_t) pPreset->m_sEarlyL.m_zDelay[i]
1211 * pReverb->m_nSamplingRate) >> 16);
1212 if (temp2 > maxSamples)
1213 temp2 = maxSamples;
1214 pReverb->m_sEarlyL.m_zDelay[i] = pReverb->m_nEarly0in + temp2;
1215 temp2 = temp + (((int32_t) pPreset->m_sEarlyR.m_zDelay[i]
1216 * pReverb->m_nSamplingRate) >> 16);
1217 if (temp2 > maxSamples)
1218 temp2 = maxSamples;
1219 pReverb->m_sEarlyR.m_zDelay[i] = pReverb->m_nEarly1in + temp2;
1220 }
1221 pReverb->m_nEarlyDelay = temp;
1222
1223 LOGV("REVERB_PARAM_REFLECTIONS_DELAY, m_nEarlyDelay smps %d max smp delay %d", pReverb->m_nEarlyDelay, maxSamples);
1224
1225 // Convert milliseconds to sample count => m_nEarlyDelay
1226 if (param == REVERB_PARAM_REFLECTIONS_DELAY)
1227 break;
1228 value16 = pProperties->reverbLevel;
1229 /* FALL THROUGH */
1230
1231 case REVERB_PARAM_REVERB_LEVEL:
1232 // We limit max value to 0 because gain is limited to 0dB
1233 if (value16 > 0 || value16 < -6000)
1234 return -EINVAL;
1235 // Convert millibels to linear 16 bits (gange 0 - 8191) => m_nLateGain.
1236 pReverb->m_nLateGain = Effects_MillibelsToLinear16(value16) >> 2;
1237
1238 LOGV("REVERB_PARAM_REVERB_LEVEL, m_nLateGain %d", pReverb->m_nLateGain);
1239
1240 if (param == REVERB_PARAM_REVERB_LEVEL)
1241 break;
1242 value32 = pProperties->reverbDelay;
1243 /* FALL THROUGH */
1244
1245 case REVERB_PARAM_REVERB_DELAY:
1246 // We limit max value to MAX_DELAY_TIME
1247 // convert ms to time units
1248 temp = (value32 * 65536) / 1000;
1249 if (temp < 0 || temp > MAX_DELAY_TIME)
1250 return -EINVAL;
1251
1252 maxSamples = (int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate)
1253 >> 16;
1254 temp = (temp * pReverb->m_nSamplingRate) >> 16;
1255 if ((temp + pReverb->m_nMaxExcursion) > maxSamples) {
1256 temp = maxSamples - pReverb->m_nMaxExcursion;
1257 }
1258 if (temp < pReverb->m_nMaxExcursion) {
1259 temp = pReverb->m_nMaxExcursion;
1260 }
1261
1262 temp -= pReverb->m_nLateDelay;
1263 pReverb->m_nDelay0Out += temp;
1264 pReverb->m_nDelay1Out += temp;
1265 pReverb->m_nLateDelay += temp;
1266
1267 LOGV("REVERB_PARAM_REVERB_DELAY, m_nLateDelay smps %d max smp delay %d", pReverb->m_nLateDelay, maxSamples);
1268
1269 // Convert milliseconds to sample count => m_nDelay1Out + m_nMaxExcursion
1270 if (param == REVERB_PARAM_REVERB_DELAY)
1271 break;
1272
1273 value16 = pProperties->diffusion;
1274 /* FALL THROUGH */
1275
1276 case REVERB_PARAM_DIFFUSION:
1277 if (value16 < 0 || value16 > 1000)
1278 return -EINVAL;
1279
1280 // Convert per mille to m_sAp0.m_nApGain, m_sAp1.m_nApGain
1281 pReverb->m_sAp0.m_nApGain = AP0_GAIN_BASE + ((int32_t) value16
1282 * AP0_GAIN_RANGE) / 1000;
1283 pReverb->m_sAp1.m_nApGain = AP1_GAIN_BASE + ((int32_t) value16
1284 * AP1_GAIN_RANGE) / 1000;
1285
1286 LOGV("REVERB_PARAM_DIFFUSION, m_sAp0.m_nApGain %d m_sAp1.m_nApGain %d", pReverb->m_sAp0.m_nApGain, pReverb->m_sAp1.m_nApGain);
1287
1288 if (param == REVERB_PARAM_DIFFUSION)
1289 break;
1290
1291 value16 = pProperties->density;
1292 /* FALL THROUGH */
1293
1294 case REVERB_PARAM_DENSITY:
1295 if (value16 < 0 || value16 > 1000)
1296 return -EINVAL;
1297
1298 // Convert per mille to m_sAp0.m_zApOut, m_sAp1.m_zApOut
1299 maxSamples = (int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16;
1300
1301 temp = AP0_TIME_BASE + ((int32_t) value16 * AP0_TIME_RANGE) / 1000;
1302 /*lint -e{702} shift for performance */
1303 temp = (temp * pReverb->m_nSamplingRate) >> 16;
1304 if (temp > maxSamples)
1305 temp = maxSamples;
1306 pReverb->m_sAp0.m_zApOut = (uint16_t) (pReverb->m_sAp0.m_zApIn + temp);
1307
1308 LOGV("REVERB_PARAM_DENSITY, Ap0 delay smps %d", temp);
1309
1310 temp = AP1_TIME_BASE + ((int32_t) value16 * AP1_TIME_RANGE) / 1000;
1311 /*lint -e{702} shift for performance */
1312 temp = (temp * pReverb->m_nSamplingRate) >> 16;
1313 if (temp > maxSamples)
1314 temp = maxSamples;
1315 pReverb->m_sAp1.m_zApOut = (uint16_t) (pReverb->m_sAp1.m_zApIn + temp);
1316
1317 LOGV("Ap1 delay smps %d", temp);
1318
1319 break;
1320
1321 default:
1322 break;
1323 }
1324 return 0;
1325} /* end Reverb_setParameter */
1326
1327/*----------------------------------------------------------------------------
1328 * ReverbUpdateXfade
1329 *----------------------------------------------------------------------------
1330 * Purpose:
1331 * Update the xfade parameters as required
1332 *
1333 * Inputs:
1334 * nNumSamplesToAdd - number of samples to write to buffer
1335 *
1336 * Outputs:
1337 *
1338 *
1339 * Side Effects:
1340 * - xfade parameters will be changed
1341 *
1342 *----------------------------------------------------------------------------
1343 */
1344static int ReverbUpdateXfade(reverb_object_t *pReverb, int nNumSamplesToAdd) {
1345 uint16_t nOffset;
1346 int16_t tempCos;
1347 int16_t tempSin;
1348
1349 if (pReverb->m_nXfadeCounter >= pReverb->m_nXfadeInterval) {
1350 /* update interval has elapsed, so reset counter */
1351 pReverb->m_nXfadeCounter = 0;
1352
1353 // Pin the sin,cos values to min / max values to ensure that the
1354 // modulated taps' coefs are zero (thus no clicks)
1355 if (pReverb->m_nPhaseIncrement > 0) {
1356 // if phase increment > 0, then sin -> 1, cos -> 0
1357 pReverb->m_nSin = 32767;
1358 pReverb->m_nCos = 0;
1359
1360 // reset the phase to match the sin, cos values
1361 pReverb->m_nPhase = 32767;
1362
1363 // modulate the cross taps because their tap coefs are zero
1364 nOffset = ReverbCalculateNoise(pReverb);
1365
1366 pReverb->m_zD1Cross = pReverb->m_nDelay1Out
1367 - pReverb->m_nMaxExcursion + nOffset;
1368
1369 nOffset = ReverbCalculateNoise(pReverb);
1370
1371 pReverb->m_zD0Cross = pReverb->m_nDelay0Out
1372 - pReverb->m_nMaxExcursion - nOffset;
1373 } else {
1374 // if phase increment < 0, then sin -> 0, cos -> 1
1375 pReverb->m_nSin = 0;
1376 pReverb->m_nCos = 32767;
1377
1378 // reset the phase to match the sin, cos values
1379 pReverb->m_nPhase = -32768;
1380
1381 // modulate the self taps because their tap coefs are zero
1382 nOffset = ReverbCalculateNoise(pReverb);
1383
1384 pReverb->m_zD0Self = pReverb->m_nDelay0Out
1385 - pReverb->m_nMaxExcursion - nOffset;
1386
1387 nOffset = ReverbCalculateNoise(pReverb);
1388
1389 pReverb->m_zD1Self = pReverb->m_nDelay1Out
1390 - pReverb->m_nMaxExcursion + nOffset;
1391
1392 } // end if-else (pReverb->m_nPhaseIncrement > 0)
1393
1394 // Reverse the direction of the sin,cos so that the
1395 // tap whose coef was previously increasing now decreases
1396 // and vice versa
1397 pReverb->m_nPhaseIncrement = -pReverb->m_nPhaseIncrement;
1398
1399 } // end if counter >= update interval
1400
1401 //compute what phase will be next time
1402 pReverb->m_nPhase += pReverb->m_nPhaseIncrement;
1403
1404 //calculate what the new sin and cos need to reach by the next update
1405 ReverbCalculateSinCos(pReverb->m_nPhase, &tempSin, &tempCos);
1406
1407 //calculate the per-sample increment required to get there by the next update
1408 /*lint -e{702} shift for performance */
1409 pReverb->m_nSinIncrement = (tempSin - pReverb->m_nSin)
1410 >> pReverb->m_nUpdatePeriodInBits;
1411
1412 /*lint -e{702} shift for performance */
1413 pReverb->m_nCosIncrement = (tempCos - pReverb->m_nCos)
1414 >> pReverb->m_nUpdatePeriodInBits;
1415
1416 /* increment update counter */
1417 pReverb->m_nXfadeCounter += (uint16_t) nNumSamplesToAdd;
1418
1419 return 0;
1420
1421} /* end ReverbUpdateXfade */
1422
1423/*----------------------------------------------------------------------------
1424 * ReverbCalculateNoise
1425 *----------------------------------------------------------------------------
1426 * Purpose:
1427 * Calculate a noise sample and limit its value
1428 *
1429 * Inputs:
1430 * nMaxExcursion - noise value is limited to this value
1431 * pnNoise - return new noise sample in this (not limited)
1432 *
1433 * Outputs:
1434 * new limited noise value
1435 *
1436 * Side Effects:
1437 * - *pnNoise noise value is updated
1438 *
1439 *----------------------------------------------------------------------------
1440 */
1441static uint16_t ReverbCalculateNoise(reverb_object_t *pReverb) {
1442 int16_t nNoise = pReverb->m_nNoise;
1443
1444 // calculate new noise value
1445 if (pReverb->m_bUseNoise) {
1446 nNoise = (int16_t) (nNoise * 5 + 1);
1447 } else {
1448 nNoise = 0;
1449 }
1450
1451 pReverb->m_nNoise = nNoise;
1452 // return the limited noise value
1453 return (pReverb->m_nMaxExcursion & nNoise);
1454
1455} /* end ReverbCalculateNoise */
1456
1457/*----------------------------------------------------------------------------
1458 * ReverbCalculateSinCos
1459 *----------------------------------------------------------------------------
1460 * Purpose:
1461 * Calculate a new sin and cosine value based on the given phase
1462 *
1463 * Inputs:
1464 * nPhase - phase angle
1465 * pnSin - input old value, output new value
1466 * pnCos - input old value, output new value
1467 *
1468 * Outputs:
1469 *
1470 * Side Effects:
1471 * - *pnSin, *pnCos are updated
1472 *
1473 *----------------------------------------------------------------------------
1474 */
1475static int ReverbCalculateSinCos(int16_t nPhase, int16_t *pnSin, int16_t *pnCos) {
1476 int32_t nTemp;
1477 int32_t nNetAngle;
1478
1479 // -1 <= nPhase < 1
1480 // However, for the calculation, we need a value
1481 // that ranges from -1/2 to +1/2, so divide the phase by 2
1482 /*lint -e{702} shift for performance */
1483 nNetAngle = nPhase >> 1;
1484
1485 /*
1486 Implement the following
1487 sin(x) = (2-4*c)*x^2 + c + x
1488 cos(x) = (2-4*c)*x^2 + c - x
1489
1490 where c = 1/sqrt(2)
1491 using the a0 + x*(a1 + x*a2) approach
1492 */
1493
1494 /* limit the input "angle" to be between -0.5 and +0.5 */
1495 if (nNetAngle > EG1_HALF) {
1496 nNetAngle = EG1_HALF;
1497 } else if (nNetAngle < EG1_MINUS_HALF) {
1498 nNetAngle = EG1_MINUS_HALF;
1499 }
1500
1501 /* calculate sin */
1502 nTemp = EG1_ONE + MULT_EG1_EG1(REVERB_PAN_G2, nNetAngle);
1503 nTemp = REVERB_PAN_G0 + MULT_EG1_EG1(nTemp, nNetAngle);
1504 *pnSin = (int16_t) SATURATE_EG1(nTemp);
1505
1506 /* calculate cos */
1507 nTemp = -EG1_ONE + MULT_EG1_EG1(REVERB_PAN_G2, nNetAngle);
1508 nTemp = REVERB_PAN_G0 + MULT_EG1_EG1(nTemp, nNetAngle);
1509 *pnCos = (int16_t) SATURATE_EG1(nTemp);
1510
1511 return 0;
1512} /* end ReverbCalculateSinCos */
1513
1514/*----------------------------------------------------------------------------
1515 * Reverb
1516 *----------------------------------------------------------------------------
1517 * Purpose:
1518 * apply reverb to the given signal
1519 *
1520 * Inputs:
1521 * nNu
1522 * pnSin - input old value, output new value
1523 * pnCos - input old value, output new value
1524 *
1525 * Outputs:
1526 * number of samples actually reverberated
1527 *
1528 * Side Effects:
1529 *
1530 *----------------------------------------------------------------------------
1531 */
1532static int Reverb(reverb_object_t *pReverb, int nNumSamplesToAdd,
1533 short *pOutputBuffer, short *pInputBuffer) {
1534 int32_t i;
1535 int32_t nDelayOut0;
1536 int32_t nDelayOut1;
1537 uint16_t nBase;
1538
1539 uint32_t nAddr;
1540 int32_t nTemp1;
1541 int32_t nTemp2;
1542 int32_t nApIn;
1543 int32_t nApOut;
1544
1545 int32_t j;
1546 int32_t nEarlyOut;
1547
1548 int32_t tempValue;
1549
1550 // get the base address
1551 nBase = pReverb->m_nBaseIndex;
1552
1553 for (i = 0; i < nNumSamplesToAdd; i++) {
1554 // ********** Left Allpass - start
1555 nApIn = *pInputBuffer;
1556 if (!pReverb->m_Aux) {
1557 pInputBuffer++;
1558 }
1559 // store to early delay line
1560 nAddr = CIRCULAR(nBase, pReverb->m_nEarly0in, pReverb->m_nBufferMask);
1561 pReverb->m_nDelayLine[nAddr] = (short) nApIn;
1562
1563 // left input = (left dry * m_nLateGain) + right feedback from previous period
1564
1565 nApIn = SATURATE(nApIn + pReverb->m_nRevFbkR);
1566 nApIn = MULT_EG1_EG1(nApIn, pReverb->m_nLateGain);
1567
1568 // fetch allpass delay line out
1569 //nAddr = CIRCULAR(nBase, psAp0->m_zApOut, pReverb->m_nBufferMask);
1570 nAddr
1571 = CIRCULAR(nBase, pReverb->m_sAp0.m_zApOut, pReverb->m_nBufferMask);
1572 nDelayOut0 = pReverb->m_nDelayLine[nAddr];
1573
1574 // calculate allpass feedforward; subtract the feedforward result
1575 nTemp1 = MULT_EG1_EG1(nApIn, pReverb->m_sAp0.m_nApGain);
1576 nApOut = SATURATE(nDelayOut0 - nTemp1); // allpass output
1577
1578 // calculate allpass feedback; add the feedback result
1579 nTemp1 = MULT_EG1_EG1(nApOut, pReverb->m_sAp0.m_nApGain);
1580 nTemp1 = SATURATE(nApIn + nTemp1);
1581
1582 // inject into allpass delay
1583 nAddr
1584 = CIRCULAR(nBase, pReverb->m_sAp0.m_zApIn, pReverb->m_nBufferMask);
1585 pReverb->m_nDelayLine[nAddr] = (short) nTemp1;
1586
1587 // inject allpass output into delay line
1588 nAddr = CIRCULAR(nBase, pReverb->m_zD0In, pReverb->m_nBufferMask);
1589 pReverb->m_nDelayLine[nAddr] = (short) nApOut;
1590
1591 // ********** Left Allpass - end
1592
1593 // ********** Right Allpass - start
1594 nApIn = (*pInputBuffer++);
1595 // store to early delay line
1596 nAddr = CIRCULAR(nBase, pReverb->m_nEarly1in, pReverb->m_nBufferMask);
1597 pReverb->m_nDelayLine[nAddr] = (short) nApIn;
1598
1599 // right input = (right dry * m_nLateGain) + left feedback from previous period
1600 /*lint -e{702} use shift for performance */
1601 nApIn = SATURATE(nApIn + pReverb->m_nRevFbkL);
1602 nApIn = MULT_EG1_EG1(nApIn, pReverb->m_nLateGain);
1603
1604 // fetch allpass delay line out
1605 nAddr
1606 = CIRCULAR(nBase, pReverb->m_sAp1.m_zApOut, pReverb->m_nBufferMask);
1607 nDelayOut1 = pReverb->m_nDelayLine[nAddr];
1608
1609 // calculate allpass feedforward; subtract the feedforward result
1610 nTemp1 = MULT_EG1_EG1(nApIn, pReverb->m_sAp1.m_nApGain);
1611 nApOut = SATURATE(nDelayOut1 - nTemp1); // allpass output
1612
1613 // calculate allpass feedback; add the feedback result
1614 nTemp1 = MULT_EG1_EG1(nApOut, pReverb->m_sAp1.m_nApGain);
1615 nTemp1 = SATURATE(nApIn + nTemp1);
1616
1617 // inject into allpass delay
1618 nAddr
1619 = CIRCULAR(nBase, pReverb->m_sAp1.m_zApIn, pReverb->m_nBufferMask);
1620 pReverb->m_nDelayLine[nAddr] = (short) nTemp1;
1621
1622 // inject allpass output into delay line
1623 nAddr = CIRCULAR(nBase, pReverb->m_zD1In, pReverb->m_nBufferMask);
1624 pReverb->m_nDelayLine[nAddr] = (short) nApOut;
1625
1626 // ********** Right Allpass - end
1627
1628 // ********** D0 output - start
1629 // fetch delay line self out
1630 nAddr = CIRCULAR(nBase, pReverb->m_zD0Self, pReverb->m_nBufferMask);
1631 nDelayOut0 = pReverb->m_nDelayLine[nAddr];
1632
1633 // calculate delay line self out
1634 nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nSin);
1635
1636 // fetch delay line cross out
1637 nAddr = CIRCULAR(nBase, pReverb->m_zD1Cross, pReverb->m_nBufferMask);
1638 nDelayOut0 = pReverb->m_nDelayLine[nAddr];
1639
1640 // calculate delay line self out
1641 nTemp2 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nCos);
1642
1643 // calculate unfiltered delay out
1644 nDelayOut0 = SATURATE(nTemp1 + nTemp2);
1645
1646 // ********** D0 output - end
1647
1648 // ********** D1 output - start
1649 // fetch delay line self out
1650 nAddr = CIRCULAR(nBase, pReverb->m_zD1Self, pReverb->m_nBufferMask);
1651 nDelayOut1 = pReverb->m_nDelayLine[nAddr];
1652
1653 // calculate delay line self out
1654 nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nSin);
1655
1656 // fetch delay line cross out
1657 nAddr = CIRCULAR(nBase, pReverb->m_zD0Cross, pReverb->m_nBufferMask);
1658 nDelayOut1 = pReverb->m_nDelayLine[nAddr];
1659
1660 // calculate delay line self out
1661 nTemp2 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nCos);
1662
1663 // calculate unfiltered delay out
1664 nDelayOut1 = SATURATE(nTemp1 + nTemp2);
1665
1666 // ********** D1 output - end
1667
1668 // ********** mixer and feedback - start
1669 // sum is fedback to right input (R + L)
1670 nDelayOut0 = (short) SATURATE(nDelayOut0 + nDelayOut1);
1671
1672 // difference is feedback to left input (R - L)
1673 /*lint -e{685} lint complains that it can't saturate negative */
1674 nDelayOut1 = (short) SATURATE(nDelayOut1 - nDelayOut0);
1675
1676 // ********** mixer and feedback - end
1677
1678 // calculate lowpass filter (mixer scale factor included in LPF feedforward)
1679 nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nRvbLpfFwd);
1680
1681 nTemp2 = MULT_EG1_EG1(pReverb->m_nRevFbkL, pReverb->m_nRvbLpfFbk);
1682
1683 // calculate filtered delay out and simultaneously update LPF state variable
1684 // filtered delay output is stored in m_nRevFbkL
1685 pReverb->m_nRevFbkL = (short) SATURATE(nTemp1 + nTemp2);
1686
1687 // calculate lowpass filter (mixer scale factor included in LPF feedforward)
1688 nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nRvbLpfFwd);
1689
1690 nTemp2 = MULT_EG1_EG1(pReverb->m_nRevFbkR, pReverb->m_nRvbLpfFbk);
1691
1692 // calculate filtered delay out and simultaneously update LPF state variable
1693 // filtered delay output is stored in m_nRevFbkR
1694 pReverb->m_nRevFbkR = (short) SATURATE(nTemp1 + nTemp2);
1695
1696 // ********** start early reflection generator, left
1697 //psEarly = &(pReverb->m_sEarlyL);
1698
1699
1700 for (j = 0; j < REVERB_MAX_NUM_REFLECTIONS; j++) {
1701 // fetch delay line out
1702 //nAddr = CIRCULAR(nBase, psEarly->m_zDelay[j], pReverb->m_nBufferMask);
1703 nAddr
1704 = CIRCULAR(nBase, pReverb->m_sEarlyL.m_zDelay[j], pReverb->m_nBufferMask);
1705
1706 nTemp1 = pReverb->m_nDelayLine[nAddr];
1707
1708 // calculate reflection
1709 //nTemp1 = MULT_EG1_EG1(nDelayOut0, psEarly->m_nGain[j]);
1710 nTemp1 = MULT_EG1_EG1(nTemp1, pReverb->m_sEarlyL.m_nGain[j]);
1711
1712 nDelayOut0 = SATURATE(nDelayOut0 + nTemp1);
1713
1714 } // end for (j=0; j < REVERB_MAX_NUM_REFLECTIONS; j++)
1715
1716 // apply lowpass to early reflections and reverb output
1717 //nTemp1 = MULT_EG1_EG1(nEarlyOut, psEarly->m_nRvbLpfFwd);
1718 nTemp1 = MULT_EG1_EG1(nDelayOut0, pReverb->m_nRoomLpfFwd);
1719
1720 //nTemp2 = MULT_EG1_EG1(psEarly->m_zLpf, psEarly->m_nLpfFbk);
1721 nTemp2 = MULT_EG1_EG1(pReverb->m_zOutLpfL, pReverb->m_nRoomLpfFbk);
1722
1723 // calculate filtered out and simultaneously update LPF state variable
1724 // filtered output is stored in m_zOutLpfL
1725 pReverb->m_zOutLpfL = (short) SATURATE(nTemp1 + nTemp2);
1726
1727 //sum with output buffer
1728 tempValue = *pOutputBuffer;
1729 *pOutputBuffer++ = (short) SATURATE(tempValue+pReverb->m_zOutLpfL);
1730
1731 // ********** end early reflection generator, left
1732
1733 // ********** start early reflection generator, right
1734 //psEarly = &(pReverb->m_sEarlyR);
1735
1736 for (j = 0; j < REVERB_MAX_NUM_REFLECTIONS; j++) {
1737 // fetch delay line out
1738 nAddr
1739 = CIRCULAR(nBase, pReverb->m_sEarlyR.m_zDelay[j], pReverb->m_nBufferMask);
1740 nTemp1 = pReverb->m_nDelayLine[nAddr];
1741
1742 // calculate reflection
1743 nTemp1 = MULT_EG1_EG1(nTemp1, pReverb->m_sEarlyR.m_nGain[j]);
1744
1745 nDelayOut1 = SATURATE(nDelayOut1 + nTemp1);
1746
1747 } // end for (j=0; j < REVERB_MAX_NUM_REFLECTIONS; j++)
1748
1749 // apply lowpass to early reflections
1750 nTemp1 = MULT_EG1_EG1(nDelayOut1, pReverb->m_nRoomLpfFwd);
1751
1752 nTemp2 = MULT_EG1_EG1(pReverb->m_zOutLpfR, pReverb->m_nRoomLpfFbk);
1753
1754 // calculate filtered out and simultaneously update LPF state variable
1755 // filtered output is stored in m_zOutLpfR
1756 pReverb->m_zOutLpfR = (short) SATURATE(nTemp1 + nTemp2);
1757
1758 //sum with output buffer
1759 tempValue = *pOutputBuffer;
1760 *pOutputBuffer++ = (short) SATURATE(tempValue + pReverb->m_zOutLpfR);
1761
1762 // ********** end early reflection generator, right
1763
1764 // decrement base addr for next sample period
1765 nBase--;
1766
1767 pReverb->m_nSin += pReverb->m_nSinIncrement;
1768 pReverb->m_nCos += pReverb->m_nCosIncrement;
1769
1770 } // end for (i=0; i < nNumSamplesToAdd; i++)
1771
1772 // store the most up to date version
1773 pReverb->m_nBaseIndex = nBase;
1774
1775 return 0;
1776} /* end Reverb */
1777
1778/*----------------------------------------------------------------------------
1779 * ReverbUpdateRoom
1780 *----------------------------------------------------------------------------
1781 * Purpose:
1782 * Update the room's preset parameters as required
1783 *
1784 * Inputs:
1785 *
1786 * Outputs:
1787 *
1788 *
1789 * Side Effects:
1790 * - reverb paramters (fbk, fwd, etc) will be changed
1791 * - m_nCurrentRoom := m_nNextRoom
1792 *----------------------------------------------------------------------------
1793 */
1794static int ReverbUpdateRoom(reverb_object_t *pReverb, bool fullUpdate) {
1795 int temp;
1796 int i;
1797 int maxSamples;
1798 int earlyDelay;
1799 int earlyGain;
1800
1801 reverb_preset_t *pPreset =
1802 &pReverb->m_sPreset.m_sPreset[pReverb->m_nNextRoom];
1803
1804 if (fullUpdate) {
1805 pReverb->m_nRvbLpfFwd = pPreset->m_nRvbLpfFwd;
1806 pReverb->m_nRvbLpfFbk = pPreset->m_nRvbLpfFbk;
1807
1808 pReverb->m_nEarlyGain = pPreset->m_nEarlyGain;
1809 //stored as time based, convert to sample based
1810 pReverb->m_nLateGain = pPreset->m_nLateGain;
1811 pReverb->m_nRoomLpfFbk = pPreset->m_nRoomLpfFbk;
1812 pReverb->m_nRoomLpfFwd = pPreset->m_nRoomLpfFwd;
1813
1814 // set the early reflections gains
1815 earlyGain = pPreset->m_nEarlyGain;
1816 for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) {
1817 pReverb->m_sEarlyL.m_nGain[i]
1818 = MULT_EG1_EG1(pPreset->m_sEarlyL.m_nGain[i],earlyGain);
1819 pReverb->m_sEarlyR.m_nGain[i]
1820 = MULT_EG1_EG1(pPreset->m_sEarlyR.m_nGain[i],earlyGain);
1821 }
1822
1823 pReverb->m_nMaxExcursion = pPreset->m_nMaxExcursion;
1824
1825 pReverb->m_sAp0.m_nApGain = pPreset->m_nAp0_ApGain;
1826 pReverb->m_sAp1.m_nApGain = pPreset->m_nAp1_ApGain;
1827
1828 // set the early reflections delay
1829 earlyDelay = ((int) pPreset->m_nEarlyDelay * pReverb->m_nSamplingRate)
1830 >> 16;
1831 pReverb->m_nEarlyDelay = earlyDelay;
1832 maxSamples = (int32_t) (MAX_EARLY_TIME * pReverb->m_nSamplingRate)
1833 >> 16;
1834 for (i = 0; i < REVERB_MAX_NUM_REFLECTIONS; i++) {
1835 //stored as time based, convert to sample based
1836 temp = earlyDelay + (((int) pPreset->m_sEarlyL.m_zDelay[i]
1837 * pReverb->m_nSamplingRate) >> 16);
1838 if (temp > maxSamples)
1839 temp = maxSamples;
1840 pReverb->m_sEarlyL.m_zDelay[i] = pReverb->m_nEarly0in + temp;
1841 //stored as time based, convert to sample based
1842 temp = earlyDelay + (((int) pPreset->m_sEarlyR.m_zDelay[i]
1843 * pReverb->m_nSamplingRate) >> 16);
1844 if (temp > maxSamples)
1845 temp = maxSamples;
1846 pReverb->m_sEarlyR.m_zDelay[i] = pReverb->m_nEarly1in + temp;
1847 }
1848
1849 maxSamples = (int32_t) (MAX_DELAY_TIME * pReverb->m_nSamplingRate)
1850 >> 16;
1851 //stored as time based, convert to sample based
1852 /*lint -e{702} shift for performance */
1853 temp = (pPreset->m_nLateDelay * pReverb->m_nSamplingRate) >> 16;
1854 if ((temp + pReverb->m_nMaxExcursion) > maxSamples) {
1855 temp = maxSamples - pReverb->m_nMaxExcursion;
1856 }
1857 temp -= pReverb->m_nLateDelay;
1858 pReverb->m_nDelay0Out += temp;
1859 pReverb->m_nDelay1Out += temp;
1860 pReverb->m_nLateDelay += temp;
1861
1862 maxSamples = (int32_t) (MAX_AP_TIME * pReverb->m_nSamplingRate) >> 16;
1863 //stored as time based, convert to absolute sample value
1864 temp = pPreset->m_nAp0_ApOut;
1865 /*lint -e{702} shift for performance */
1866 temp = (temp * pReverb->m_nSamplingRate) >> 16;
1867 if (temp > maxSamples)
1868 temp = maxSamples;
1869 pReverb->m_sAp0.m_zApOut = (uint16_t) (pReverb->m_sAp0.m_zApIn + temp);
1870
1871 //stored as time based, convert to absolute sample value
1872 temp = pPreset->m_nAp1_ApOut;
1873 /*lint -e{702} shift for performance */
1874 temp = (temp * pReverb->m_nSamplingRate) >> 16;
1875 if (temp > maxSamples)
1876 temp = maxSamples;
1877 pReverb->m_sAp1.m_zApOut = (uint16_t) (pReverb->m_sAp1.m_zApIn + temp);
1878 //gpsReverbObject->m_sAp1.m_zApOut = pPreset->m_nAp1_ApOut;
1879 }
1880
1881 //stored as time based, convert to sample based
1882 temp = pPreset->m_nXfadeInterval;
1883 /*lint -e{702} shift for performance */
1884 temp = (temp * pReverb->m_nSamplingRate) >> 16;
1885 pReverb->m_nXfadeInterval = (uint16_t) temp;
1886 //gsReverbObject.m_nXfadeInterval = pPreset->m_nXfadeInterval;
1887 pReverb->m_nXfadeCounter = pReverb->m_nXfadeInterval + 1; // force update on first iteration
1888
Eric Laurent135ad072010-05-21 06:05:13 -07001889 pReverb->m_nCurrentRoom = pReverb->m_nNextRoom;
1890
1891 return 0;
1892
1893} /* end ReverbUpdateRoom */
1894
1895/*----------------------------------------------------------------------------
1896 * ReverbReadInPresets()
1897 *----------------------------------------------------------------------------
1898 * Purpose: sets global reverb preset bank to defaults
1899 *
1900 * Inputs:
1901 *
1902 * Outputs:
1903 *
1904 *----------------------------------------------------------------------------
1905 */
1906static int ReverbReadInPresets(reverb_object_t *pReverb) {
1907
1908 int preset = 0;
1909 int defaultPreset = 0;
1910
1911 //now init any remaining presets to defaults
1912 for (defaultPreset = preset; defaultPreset < REVERB_MAX_ROOM_TYPE; defaultPreset++) {
1913 reverb_preset_t *pPreset = &pReverb->m_sPreset.m_sPreset[defaultPreset];
1914 if (defaultPreset == 0 || defaultPreset > REVERB_MAX_ROOM_TYPE - 1) {
1915 pPreset->m_nRvbLpfFbk = 8307;
1916 pPreset->m_nRvbLpfFwd = 14768;
1917 pPreset->m_nEarlyGain = 27690;
1918 pPreset->m_nEarlyDelay = 1311;
1919 pPreset->m_nLateGain = 8191;
1920 pPreset->m_nLateDelay = 3932;
1921 pPreset->m_nRoomLpfFbk = 3692;
1922 pPreset->m_nRoomLpfFwd = 24569;
1923 pPreset->m_sEarlyL.m_zDelay[0] = 1376;
1924 pPreset->m_sEarlyL.m_nGain[0] = 22152;
1925 pPreset->m_sEarlyL.m_zDelay[1] = 2163;
1926 pPreset->m_sEarlyL.m_nGain[1] = 17537;
1927 pPreset->m_sEarlyL.m_zDelay[2] = 0;
1928 pPreset->m_sEarlyL.m_nGain[2] = 14768;
1929 pPreset->m_sEarlyL.m_zDelay[3] = 1835;
1930 pPreset->m_sEarlyL.m_nGain[3] = 14307;
1931 pPreset->m_sEarlyL.m_zDelay[4] = 0;
1932 pPreset->m_sEarlyL.m_nGain[4] = 13384;
1933 pPreset->m_sEarlyR.m_zDelay[0] = 721;
1934 pPreset->m_sEarlyR.m_nGain[0] = 20306;
1935 pPreset->m_sEarlyR.m_zDelay[1] = 2621;
1936 pPreset->m_sEarlyR.m_nGain[1] = 17537;
1937 pPreset->m_sEarlyR.m_zDelay[2] = 0;
1938 pPreset->m_sEarlyR.m_nGain[2] = 14768;
1939 pPreset->m_sEarlyR.m_zDelay[3] = 0;
1940 pPreset->m_sEarlyR.m_nGain[3] = 16153;
1941 pPreset->m_sEarlyR.m_zDelay[4] = 0;
1942 pPreset->m_sEarlyR.m_nGain[4] = 13384;
1943 pPreset->m_nMaxExcursion = 127;
1944 pPreset->m_nXfadeInterval = 6388;
1945 pPreset->m_nAp0_ApGain = 15691;
1946 pPreset->m_nAp0_ApOut = 711;
1947 pPreset->m_nAp1_ApGain = 16317;
1948 pPreset->m_nAp1_ApOut = 1029;
1949 pPreset->m_rfu4 = 0;
1950 pPreset->m_rfu5 = 0;
1951 pPreset->m_rfu6 = 0;
1952 pPreset->m_rfu7 = 0;
1953 pPreset->m_rfu8 = 0;
1954 pPreset->m_rfu9 = 0;
1955 pPreset->m_rfu10 = 0;
1956 } else if (defaultPreset == 1) {
1957 pPreset->m_nRvbLpfFbk = 6461;
1958 pPreset->m_nRvbLpfFwd = 14307;
1959 pPreset->m_nEarlyGain = 27690;
1960 pPreset->m_nEarlyDelay = 1311;
1961 pPreset->m_nLateGain = 8191;
1962 pPreset->m_nLateDelay = 3932;
1963 pPreset->m_nRoomLpfFbk = 3692;
1964 pPreset->m_nRoomLpfFwd = 24569;
1965 pPreset->m_sEarlyL.m_zDelay[0] = 1376;
1966 pPreset->m_sEarlyL.m_nGain[0] = 22152;
1967 pPreset->m_sEarlyL.m_zDelay[1] = 1462;
1968 pPreset->m_sEarlyL.m_nGain[1] = 17537;
1969 pPreset->m_sEarlyL.m_zDelay[2] = 0;
1970 pPreset->m_sEarlyL.m_nGain[2] = 14768;
1971 pPreset->m_sEarlyL.m_zDelay[3] = 1835;
1972 pPreset->m_sEarlyL.m_nGain[3] = 14307;
1973 pPreset->m_sEarlyL.m_zDelay[4] = 0;
1974 pPreset->m_sEarlyL.m_nGain[4] = 13384;
1975 pPreset->m_sEarlyR.m_zDelay[0] = 721;
1976 pPreset->m_sEarlyR.m_nGain[0] = 20306;
1977 pPreset->m_sEarlyR.m_zDelay[1] = 2621;
1978 pPreset->m_sEarlyR.m_nGain[1] = 17537;
1979 pPreset->m_sEarlyR.m_zDelay[2] = 0;
1980 pPreset->m_sEarlyR.m_nGain[2] = 14768;
1981 pPreset->m_sEarlyR.m_zDelay[3] = 0;
1982 pPreset->m_sEarlyR.m_nGain[3] = 16153;
1983 pPreset->m_sEarlyR.m_zDelay[4] = 0;
1984 pPreset->m_sEarlyR.m_nGain[4] = 13384;
1985 pPreset->m_nMaxExcursion = 127;
1986 pPreset->m_nXfadeInterval = 6391;
1987 pPreset->m_nAp0_ApGain = 15230;
1988 pPreset->m_nAp0_ApOut = 708;
1989 pPreset->m_nAp1_ApGain = 15547;
1990 pPreset->m_nAp1_ApOut = 1023;
1991 pPreset->m_rfu4 = 0;
1992 pPreset->m_rfu5 = 0;
1993 pPreset->m_rfu6 = 0;
1994 pPreset->m_rfu7 = 0;
1995 pPreset->m_rfu8 = 0;
1996 pPreset->m_rfu9 = 0;
1997 pPreset->m_rfu10 = 0;
1998 } else if (defaultPreset == 2) {
1999 pPreset->m_nRvbLpfFbk = 5077;
2000 pPreset->m_nRvbLpfFwd = 12922;
2001 pPreset->m_nEarlyGain = 27690;
2002 pPreset->m_nEarlyDelay = 1311;
2003 pPreset->m_nLateGain = 8191;
2004 pPreset->m_nLateDelay = 3932;
2005 pPreset->m_nRoomLpfFbk = 3692;
2006 pPreset->m_nRoomLpfFwd = 21703;
2007 pPreset->m_sEarlyL.m_zDelay[0] = 1376;
2008 pPreset->m_sEarlyL.m_nGain[0] = 22152;
2009 pPreset->m_sEarlyL.m_zDelay[1] = 1462;
2010 pPreset->m_sEarlyL.m_nGain[1] = 17537;
2011 pPreset->m_sEarlyL.m_zDelay[2] = 0;
2012 pPreset->m_sEarlyL.m_nGain[2] = 14768;
2013 pPreset->m_sEarlyL.m_zDelay[3] = 1835;
2014 pPreset->m_sEarlyL.m_nGain[3] = 14307;
2015 pPreset->m_sEarlyL.m_zDelay[4] = 0;
2016 pPreset->m_sEarlyL.m_nGain[4] = 13384;
2017 pPreset->m_sEarlyR.m_zDelay[0] = 721;
2018 pPreset->m_sEarlyR.m_nGain[0] = 20306;
2019 pPreset->m_sEarlyR.m_zDelay[1] = 2621;
2020 pPreset->m_sEarlyR.m_nGain[1] = 17537;
2021 pPreset->m_sEarlyR.m_zDelay[2] = 0;
2022 pPreset->m_sEarlyR.m_nGain[2] = 14768;
2023 pPreset->m_sEarlyR.m_zDelay[3] = 0;
2024 pPreset->m_sEarlyR.m_nGain[3] = 16153;
2025 pPreset->m_sEarlyR.m_zDelay[4] = 0;
2026 pPreset->m_sEarlyR.m_nGain[4] = 13384;
2027 pPreset->m_nMaxExcursion = 127;
2028 pPreset->m_nXfadeInterval = 6449;
2029 pPreset->m_nAp0_ApGain = 15691;
2030 pPreset->m_nAp0_ApOut = 774;
2031 pPreset->m_nAp1_ApGain = 16317;
2032 pPreset->m_nAp1_ApOut = 1155;
2033 pPreset->m_rfu4 = 0;
2034 pPreset->m_rfu5 = 0;
2035 pPreset->m_rfu6 = 0;
2036 pPreset->m_rfu7 = 0;
2037 pPreset->m_rfu8 = 0;
2038 pPreset->m_rfu9 = 0;
2039 pPreset->m_rfu10 = 0;
2040 } else if (defaultPreset == 3) {
2041 pPreset->m_nRvbLpfFbk = 5077;
2042 pPreset->m_nRvbLpfFwd = 11076;
2043 pPreset->m_nEarlyGain = 27690;
2044 pPreset->m_nEarlyDelay = 1311;
2045 pPreset->m_nLateGain = 8191;
2046 pPreset->m_nLateDelay = 3932;
2047 pPreset->m_nRoomLpfFbk = 3692;
2048 pPreset->m_nRoomLpfFwd = 20474;
2049 pPreset->m_sEarlyL.m_zDelay[0] = 1376;
2050 pPreset->m_sEarlyL.m_nGain[0] = 22152;
2051 pPreset->m_sEarlyL.m_zDelay[1] = 1462;
2052 pPreset->m_sEarlyL.m_nGain[1] = 17537;
2053 pPreset->m_sEarlyL.m_zDelay[2] = 0;
2054 pPreset->m_sEarlyL.m_nGain[2] = 14768;
2055 pPreset->m_sEarlyL.m_zDelay[3] = 1835;
2056 pPreset->m_sEarlyL.m_nGain[3] = 14307;
2057 pPreset->m_sEarlyL.m_zDelay[4] = 0;
2058 pPreset->m_sEarlyL.m_nGain[4] = 13384;
2059 pPreset->m_sEarlyR.m_zDelay[0] = 721;
2060 pPreset->m_sEarlyR.m_nGain[0] = 20306;
2061 pPreset->m_sEarlyR.m_zDelay[1] = 2621;
2062 pPreset->m_sEarlyR.m_nGain[1] = 17537;
2063 pPreset->m_sEarlyR.m_zDelay[2] = 0;
2064 pPreset->m_sEarlyR.m_nGain[2] = 14768;
2065 pPreset->m_sEarlyR.m_zDelay[3] = 0;
2066 pPreset->m_sEarlyR.m_nGain[3] = 16153;
2067 pPreset->m_sEarlyR.m_zDelay[4] = 0;
2068 pPreset->m_sEarlyR.m_nGain[4] = 13384;
2069 pPreset->m_nMaxExcursion = 127;
2070 pPreset->m_nXfadeInterval = 6470; //6483;
2071 pPreset->m_nAp0_ApGain = 14768;
2072 pPreset->m_nAp0_ApOut = 792;
2073 pPreset->m_nAp1_ApGain = 14777;
2074 pPreset->m_nAp1_ApOut = 1191;
2075 pPreset->m_rfu4 = 0;
2076 pPreset->m_rfu5 = 0;
2077 pPreset->m_rfu6 = 0;
2078 pPreset->m_rfu7 = 0;
2079 pPreset->m_rfu8 = 0;
2080 pPreset->m_rfu9 = 0;
2081 pPreset->m_rfu10 = 0;
2082 }
2083 }
2084
2085 return 0;
2086}