1 /*
2 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
3 * Not a Contribution.
4 *
5 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20 #define LOG_TAG "offload_effect_reverb"
21 #define LOG_NDEBUG 0
22
23 #include <cutils/list.h>
24 #include <cutils/log.h>
25 #include <tinyalsa/asoundlib.h>
26 #include <sound/audio_effects.h>
27 #include <audio_effects/effect_environmentalreverb.h>
28 #include <audio_effects/effect_presetreverb.h>
29
30 #include "effect_api.h"
31 #include "reverb.h"
32
33 /* Offload auxiliary environmental reverb UUID: 79a18026-18fd-4185-8233-0002a5d5c51b */
34 const effect_descriptor_t aux_env_reverb_descriptor = {
35 { 0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, { 0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e } },
36 { 0x79a18026, 0x18fd, 0x4185, 0x8233, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b } },
37 EFFECT_CONTROL_API_VERSION,
38 (EFFECT_FLAG_TYPE_AUXILIARY | EFFECT_FLAG_HW_ACC_TUNNEL),
39 0, /* TODO */
40 1,
41 "MSM offload Auxiliary Environmental Reverb",
42 "The Android Open Source Project",
43 };
44
45 /* Offload insert environmental reverb UUID: eb64ea04-973b-43d2-8f5e-0002a5d5c51b */
46 const effect_descriptor_t ins_env_reverb_descriptor = {
47 {0xc2e5d5f0, 0x94bd, 0x4763, 0x9cac, {0x4e, 0x23, 0x4d, 0x06, 0x83, 0x9e}},
48 {0xeb64ea04, 0x973b, 0x43d2, 0x8f5e, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
49 EFFECT_CONTROL_API_VERSION,
50 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_HW_ACC_TUNNEL),
51 0, /* TODO */
52 1,
53 "MSM offload Insert Environmental Reverb",
54 "The Android Open Source Project",
55 };
56
57 // Offload auxiliary preset reverb UUID: 6987be09-b142-4b41-9056-0002a5d5c51b */
58 const effect_descriptor_t aux_preset_reverb_descriptor = {
59 {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
60 {0x6987be09, 0xb142, 0x4b41, 0x9056, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
61 EFFECT_CONTROL_API_VERSION,
62 (EFFECT_FLAG_TYPE_AUXILIARY | EFFECT_FLAG_HW_ACC_TUNNEL),
63 0, /* TODO */
64 1,
65 "MSM offload Auxiliary Preset Reverb",
66 "The Android Open Source Project",
67 };
68
69 // Offload insert preset reverb UUID: aa2bebf6-47cf-4613-9bca-0002a5d5c51b */
70 const effect_descriptor_t ins_preset_reverb_descriptor = {
71 {0x47382d60, 0xddd8, 0x11db, 0xbf3a, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
72 {0xaa2bebf6, 0x47cf, 0x4613, 0x9bca, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}},
73 EFFECT_CONTROL_API_VERSION,
74 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_INSERT_FIRST | EFFECT_FLAG_HW_ACC_TUNNEL),
75 0, /* TODO */
76 1,
77 "MSM offload Insert Preset Reverb",
78 "The Android Open Source Project",
79 };
80
81 static const reverb_settings_t reverb_presets[] = {
82 // REVERB_PRESET_NONE: values are unused
83 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
84 // REVERB_PRESET_SMALLROOM
85 {-400, -600, 1100, 830, -400, 5, 500, 10, 1000, 1000},
86 // REVERB_PRESET_MEDIUMROOM
87 {-400, -600, 1300, 830, -1000, 20, -200, 20, 1000, 1000},
88 // REVERB_PRESET_LARGEROOM
89 {-400, -600, 1500, 830, -1600, 5, -1000, 40, 1000, 1000},
90 // REVERB_PRESET_MEDIUMHALL
91 {-400, -600, 1800, 700, -1300, 15, -800, 30, 1000, 1000},
92 // REVERB_PRESET_LARGEHALL
93 {-400, -600, 1800, 700, -2000, 30, -1400, 60, 1000, 1000},
94 // REVERB_PRESET_PLATE
95 {-400, -200, 1300, 900, 0, 2, 0, 10, 1000, 750},
96 };
97
98
reverb_auxiliary_init(reverb_context_t * context)99 void reverb_auxiliary_init(reverb_context_t *context)
100 {
101 context->auxiliary = true;
102 context->preset = false;
103 }
104
reverb_preset_init(reverb_context_t * context)105 void reverb_preset_init(reverb_context_t *context)
106 {
107 context->auxiliary = false;
108 context->preset = true;
109 context->cur_preset = REVERB_PRESET_LAST + 1;
110 context->next_preset = REVERB_DEFAULT_PRESET;
111 }
112
113 /*
114 * Reverb operations
115 */
reverb_get_room_level(reverb_context_t * context)116 int16_t reverb_get_room_level(reverb_context_t *context)
117 {
118 ALOGV("%s: ctxt %p, room level: %d", __func__, context, context->reverb_settings.roomLevel);
119 return context->reverb_settings.roomLevel;
120 }
121
reverb_set_room_level(reverb_context_t * context,int16_t room_level)122 void reverb_set_room_level(reverb_context_t *context, int16_t room_level)
123 {
124 ALOGV("%s: ctxt %p, room level: %d", __func__, context, room_level);
125 context->reverb_settings.roomLevel = room_level;
126 offload_reverb_set_room_level(&(context->offload_reverb), room_level);
127 if (context->ctl)
128 offload_reverb_send_params(context->ctl, context->offload_reverb,
129 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
130 OFFLOAD_SEND_REVERB_ROOM_LEVEL);
131 }
132
reverb_get_room_hf_level(reverb_context_t * context)133 int16_t reverb_get_room_hf_level(reverb_context_t *context)
134 {
135 ALOGV("%s: ctxt %p, room hf level: %d", __func__, context,
136 context->reverb_settings.roomHFLevel);
137 return context->reverb_settings.roomHFLevel;
138 }
139
reverb_set_room_hf_level(reverb_context_t * context,int16_t room_hf_level)140 void reverb_set_room_hf_level(reverb_context_t *context, int16_t room_hf_level)
141 {
142 ALOGV("%s: ctxt %p, room hf level: %d", __func__, context, room_hf_level);
143 context->reverb_settings.roomHFLevel = room_hf_level;
144 offload_reverb_set_room_hf_level(&(context->offload_reverb), room_hf_level);
145 if (context->ctl)
146 offload_reverb_send_params(context->ctl, context->offload_reverb,
147 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
148 OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL);
149 }
150
reverb_get_decay_time(reverb_context_t * context)151 uint32_t reverb_get_decay_time(reverb_context_t *context)
152 {
153 ALOGV("%s: ctxt %p, decay time: %d", __func__, context,
154 context->reverb_settings.decayTime);
155 return context->reverb_settings.decayTime;
156 }
157
reverb_set_decay_time(reverb_context_t * context,uint32_t decay_time)158 void reverb_set_decay_time(reverb_context_t *context, uint32_t decay_time)
159 {
160 ALOGV("%s: ctxt %p, decay_time: %d", __func__, context, decay_time);
161 context->reverb_settings.decayTime = decay_time;
162 offload_reverb_set_decay_time(&(context->offload_reverb), decay_time);
163 if (context->ctl)
164 offload_reverb_send_params(context->ctl, context->offload_reverb,
165 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
166 OFFLOAD_SEND_REVERB_DECAY_TIME);
167 }
168
reverb_get_decay_hf_ratio(reverb_context_t * context)169 int16_t reverb_get_decay_hf_ratio(reverb_context_t *context)
170 {
171 ALOGV("%s: ctxt %p, decay hf ratio: %d", __func__, context,
172 context->reverb_settings.decayHFRatio);
173 return context->reverb_settings.decayHFRatio;
174 }
175
reverb_set_decay_hf_ratio(reverb_context_t * context,int16_t decay_hf_ratio)176 void reverb_set_decay_hf_ratio(reverb_context_t *context, int16_t decay_hf_ratio)
177 {
178 ALOGV("%s: ctxt %p, decay_hf_ratio: %d", __func__, context, decay_hf_ratio);
179 context->reverb_settings.decayHFRatio = decay_hf_ratio;
180 offload_reverb_set_decay_hf_ratio(&(context->offload_reverb), decay_hf_ratio);
181 if (context->ctl)
182 offload_reverb_send_params(context->ctl, context->offload_reverb,
183 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
184 OFFLOAD_SEND_REVERB_DECAY_HF_RATIO);
185 }
186
reverb_get_reverb_level(reverb_context_t * context)187 int16_t reverb_get_reverb_level(reverb_context_t *context)
188 {
189 ALOGV("%s: ctxt %p, reverb level: %d", __func__, context,
190 context->reverb_settings.reverbLevel);
191 return context->reverb_settings.reverbLevel;
192 }
193
reverb_set_reverb_level(reverb_context_t * context,int16_t reverb_level)194 void reverb_set_reverb_level(reverb_context_t *context, int16_t reverb_level)
195 {
196 ALOGV("%s: ctxt %p, reverb level: %d", __func__, context, reverb_level);
197 context->reverb_settings.reverbLevel = reverb_level;
198 offload_reverb_set_reverb_level(&(context->offload_reverb), reverb_level);
199 if (context->ctl)
200 offload_reverb_send_params(context->ctl, context->offload_reverb,
201 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
202 OFFLOAD_SEND_REVERB_LEVEL);
203 }
204
reverb_get_diffusion(reverb_context_t * context)205 int16_t reverb_get_diffusion(reverb_context_t *context)
206 {
207 ALOGV("%s: ctxt %p, diffusion: %d", __func__, context,
208 context->reverb_settings.diffusion);
209 return context->reverb_settings.diffusion;
210 }
211
reverb_set_diffusion(reverb_context_t * context,int16_t diffusion)212 void reverb_set_diffusion(reverb_context_t *context, int16_t diffusion)
213 {
214 ALOGV("%s: ctxt %p, diffusion: %d", __func__, context, diffusion);
215 context->reverb_settings.diffusion = diffusion;
216 offload_reverb_set_diffusion(&(context->offload_reverb), diffusion);
217 if (context->ctl)
218 offload_reverb_send_params(context->ctl, context->offload_reverb,
219 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
220 OFFLOAD_SEND_REVERB_DIFFUSION);
221 }
222
reverb_get_density(reverb_context_t * context)223 int16_t reverb_get_density(reverb_context_t *context)
224 {
225 ALOGV("%s: ctxt %p, density: %d", __func__, context,
226 context->reverb_settings.density);
227 return context->reverb_settings.density;
228 }
229
reverb_set_density(reverb_context_t * context,int16_t density)230 void reverb_set_density(reverb_context_t *context, int16_t density)
231 {
232 ALOGV("%s: ctxt %p, density: %d", __func__, context, density);
233 context->reverb_settings.density = density;
234 offload_reverb_set_density(&(context->offload_reverb), density);
235 if (context->ctl)
236 offload_reverb_send_params(context->ctl, context->offload_reverb,
237 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
238 OFFLOAD_SEND_REVERB_DENSITY);
239 }
240
reverb_set_preset(reverb_context_t * context,int16_t preset)241 void reverb_set_preset(reverb_context_t *context, int16_t preset)
242 {
243 bool enable;
244 ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset);
245 context->next_preset = preset;
246 offload_reverb_set_preset(&(context->offload_reverb), preset);
247
248 enable = (preset == REVERB_PRESET_NONE) ? false: true;
249 offload_reverb_set_enable_flag(&(context->offload_reverb), enable);
250
251 if (context->ctl)
252 offload_reverb_send_params(context->ctl, context->offload_reverb,
253 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
254 OFFLOAD_SEND_REVERB_PRESET);
255 }
256
reverb_set_all_properties(reverb_context_t * context,reverb_settings_t * reverb_settings)257 void reverb_set_all_properties(reverb_context_t *context,
258 reverb_settings_t *reverb_settings)
259 {
260 ALOGV("%s: ctxt %p", __func__, context);
261 context->reverb_settings.roomLevel = reverb_settings->roomLevel;
262 context->reverb_settings.roomHFLevel = reverb_settings->roomHFLevel;
263 context->reverb_settings.decayTime = reverb_settings->decayTime;
264 context->reverb_settings.decayHFRatio = reverb_settings->decayHFRatio;
265 context->reverb_settings.reverbLevel = reverb_settings->reverbLevel;
266 context->reverb_settings.diffusion = reverb_settings->diffusion;
267 context->reverb_settings.density = reverb_settings->density;
268 if (context->ctl)
269 offload_reverb_send_params(context->ctl, context->offload_reverb,
270 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
271 OFFLOAD_SEND_REVERB_ROOM_LEVEL |
272 OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL |
273 OFFLOAD_SEND_REVERB_DECAY_TIME |
274 OFFLOAD_SEND_REVERB_DECAY_HF_RATIO |
275 OFFLOAD_SEND_REVERB_LEVEL |
276 OFFLOAD_SEND_REVERB_DIFFUSION |
277 OFFLOAD_SEND_REVERB_DENSITY);
278 }
279
reverb_load_preset(reverb_context_t * context)280 void reverb_load_preset(reverb_context_t *context)
281 {
282 context->cur_preset = context->next_preset;
283
284 if (context->cur_preset != REVERB_PRESET_NONE) {
285 const reverb_settings_t *preset = &reverb_presets[context->cur_preset];
286 reverb_set_room_level(context, preset->roomLevel);
287 reverb_set_room_hf_level(context, preset->roomHFLevel);
288 reverb_set_decay_time(context, preset->decayTime);
289 reverb_set_decay_hf_ratio(context, preset->decayHFRatio);
290 reverb_set_reverb_level(context, preset->reverbLevel);
291 reverb_set_diffusion(context, preset->diffusion);
292 reverb_set_density(context, preset->density);
293 }
294 }
295
reverb_get_parameter(effect_context_t * context,effect_param_t * p,uint32_t * size)296 int reverb_get_parameter(effect_context_t *context, effect_param_t *p,
297 uint32_t *size)
298 {
299 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
300 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
301 int32_t *param_tmp = (int32_t *)p->data;
302 int32_t param = *param_tmp++;
303 void *value = p->data + voffset;
304 reverb_settings_t *reverb_settings;
305 int i;
306
307 ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param);
308
309 p->status = 0;
310
311 if (reverb_ctxt->preset) {
312 if (param != REVERB_PARAM_PRESET || p->vsize < sizeof(uint16_t))
313 return -EINVAL;
314 *(uint16_t *)value = reverb_ctxt->next_preset;
315 ALOGV("get REVERB_PARAM_PRESET, preset %d", reverb_ctxt->next_preset);
316 return 0;
317 }
318 switch (param) {
319 case REVERB_PARAM_ROOM_LEVEL:
320 if (p->vsize < sizeof(uint16_t))
321 p->status = -EINVAL;
322 p->vsize = sizeof(uint16_t);
323 break;
324 case REVERB_PARAM_ROOM_HF_LEVEL:
325 if (p->vsize < sizeof(uint16_t))
326 p->status = -EINVAL;
327 p->vsize = sizeof(uint16_t);
328 break;
329 case REVERB_PARAM_DECAY_TIME:
330 if (p->vsize < sizeof(uint32_t))
331 p->status = -EINVAL;
332 p->vsize = sizeof(uint32_t);
333 break;
334 case REVERB_PARAM_DECAY_HF_RATIO:
335 if (p->vsize < sizeof(uint16_t))
336 p->status = -EINVAL;
337 p->vsize = sizeof(uint16_t);
338 break;
339 case REVERB_PARAM_REFLECTIONS_LEVEL:
340 if (p->vsize < sizeof(uint16_t))
341 p->status = -EINVAL;
342 p->vsize = sizeof(uint16_t);
343 break;
344 case REVERB_PARAM_REFLECTIONS_DELAY:
345 if (p->vsize < sizeof(uint32_t))
346 p->status = -EINVAL;
347 p->vsize = sizeof(uint32_t);
348 break;
349 case REVERB_PARAM_REVERB_LEVEL:
350 if (p->vsize < sizeof(uint16_t))
351 p->status = -EINVAL;
352 p->vsize = sizeof(uint16_t);
353 break;
354 case REVERB_PARAM_REVERB_DELAY:
355 if (p->vsize < sizeof(uint32_t))
356 p->status = -EINVAL;
357 p->vsize = sizeof(uint32_t);
358 break;
359 case REVERB_PARAM_DIFFUSION:
360 if (p->vsize < sizeof(uint16_t))
361 p->status = -EINVAL;
362 p->vsize = sizeof(uint16_t);
363 break;
364 case REVERB_PARAM_DENSITY:
365 if (p->vsize < sizeof(uint16_t))
366 p->status = -EINVAL;
367 p->vsize = sizeof(uint16_t);
368 break;
369 case REVERB_PARAM_PROPERTIES:
370 if (p->vsize < sizeof(reverb_settings_t))
371 p->status = -EINVAL;
372 p->vsize = sizeof(reverb_settings_t);
373 break;
374 default:
375 p->status = -EINVAL;
376 }
377
378 *size = sizeof(effect_param_t) + voffset + p->vsize;
379
380 if (p->status != 0)
381 return 0;
382
383 switch (param) {
384 case REVERB_PARAM_PROPERTIES:
385 reverb_settings = (reverb_settings_t *)value;
386 reverb_settings->roomLevel = reverb_get_room_level(reverb_ctxt);
387 reverb_settings->roomHFLevel = reverb_get_room_hf_level(reverb_ctxt);
388 reverb_settings->decayTime = reverb_get_decay_time(reverb_ctxt);
389 reverb_settings->decayHFRatio = reverb_get_decay_hf_ratio(reverb_ctxt);
390 reverb_settings->reflectionsLevel = 0;
391 reverb_settings->reflectionsDelay = 0;
392 reverb_settings->reverbDelay = 0;
393 reverb_settings->reverbLevel = reverb_get_reverb_level(reverb_ctxt);
394 reverb_settings->diffusion = reverb_get_diffusion(reverb_ctxt);
395 reverb_settings->density = reverb_get_density(reverb_ctxt);
396 break;
397 case REVERB_PARAM_ROOM_LEVEL:
398 *(int16_t *)value = reverb_get_room_level(reverb_ctxt);
399 break;
400 case REVERB_PARAM_ROOM_HF_LEVEL:
401 *(int16_t *)value = reverb_get_room_hf_level(reverb_ctxt);
402 break;
403 case REVERB_PARAM_DECAY_TIME:
404 *(uint32_t *)value = reverb_get_decay_time(reverb_ctxt);
405 break;
406 case REVERB_PARAM_DECAY_HF_RATIO:
407 *(int16_t *)value = reverb_get_decay_hf_ratio(reverb_ctxt);
408 break;
409 case REVERB_PARAM_REVERB_LEVEL:
410 *(int16_t *)value = reverb_get_reverb_level(reverb_ctxt);
411 break;
412 case REVERB_PARAM_DIFFUSION:
413 *(int16_t *)value = reverb_get_diffusion(reverb_ctxt);
414 break;
415 case REVERB_PARAM_DENSITY:
416 *(int16_t *)value = reverb_get_density(reverb_ctxt);
417 break;
418 case REVERB_PARAM_REFLECTIONS_LEVEL:
419 *(uint16_t *)value = 0;
420 break;
421 case REVERB_PARAM_REFLECTIONS_DELAY:
422 *(uint32_t *)value = 0;
423 break;
424 case REVERB_PARAM_REVERB_DELAY:
425 *(uint32_t *)value = 0;
426 break;
427 default:
428 p->status = -EINVAL;
429 break;
430 }
431
432 return 0;
433 }
434
reverb_set_parameter(effect_context_t * context,effect_param_t * p,uint32_t size __unused)435 int reverb_set_parameter(effect_context_t *context, effect_param_t *p,
436 uint32_t size __unused)
437 {
438 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
439 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
440 void *value = p->data + voffset;
441 int32_t *param_tmp = (int32_t *)p->data;
442 int32_t param = *param_tmp++;
443 reverb_settings_t *reverb_settings;
444 int16_t level;
445 int16_t ratio;
446 uint32_t time;
447
448 ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param);
449
450 p->status = 0;
451
452 if (reverb_ctxt->preset) {
453 if (param != REVERB_PARAM_PRESET)
454 return -EINVAL;
455 uint16_t preset = *(uint16_t *)value;
456 ALOGV("set REVERB_PARAM_PRESET, preset %d", preset);
457 if (preset > REVERB_PRESET_LAST) {
458 return -EINVAL;
459 }
460 reverb_set_preset(reverb_ctxt, preset);
461 return 0;
462 }
463 switch (param) {
464 case REVERB_PARAM_PROPERTIES:
465 reverb_settings = (reverb_settings_t *)value;
466 break;
467 case REVERB_PARAM_ROOM_LEVEL:
468 level = *(int16_t *)value;
469 reverb_set_room_level(reverb_ctxt, level);
470 break;
471 case REVERB_PARAM_ROOM_HF_LEVEL:
472 level = *(int16_t *)value;
473 reverb_set_room_hf_level(reverb_ctxt, level);
474 break;
475 case REVERB_PARAM_DECAY_TIME:
476 time = *(uint32_t *)value;
477 reverb_set_decay_time(reverb_ctxt, time);
478 break;
479 case REVERB_PARAM_DECAY_HF_RATIO:
480 ratio = *(int16_t *)value;
481 reverb_set_decay_hf_ratio(reverb_ctxt, ratio);
482 break;
483 case REVERB_PARAM_REVERB_LEVEL:
484 level = *(int16_t *)value;
485 reverb_set_reverb_level(reverb_ctxt, level);
486 break;
487 case REVERB_PARAM_DIFFUSION:
488 ratio = *(int16_t *)value;
489 reverb_set_diffusion(reverb_ctxt, ratio);
490 break;
491 case REVERB_PARAM_DENSITY:
492 ratio = *(int16_t *)value;
493 reverb_set_density(reverb_ctxt, ratio);
494 break;
495 case REVERB_PARAM_REFLECTIONS_LEVEL:
496 case REVERB_PARAM_REFLECTIONS_DELAY:
497 case REVERB_PARAM_REVERB_DELAY:
498 break;
499 default:
500 p->status = -EINVAL;
501 break;
502 }
503
504 return 0;
505 }
506
reverb_set_device(effect_context_t * context,uint32_t device)507 int reverb_set_device(effect_context_t *context, uint32_t device)
508 {
509 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
510
511 ALOGV("%s: ctxt %p, device: 0x%x", __func__, reverb_ctxt, device);
512 reverb_ctxt->device = device;
513 offload_reverb_set_device(&(reverb_ctxt->offload_reverb), device);
514 return 0;
515 }
516
reverb_reset(effect_context_t * context)517 int reverb_reset(effect_context_t *context)
518 {
519 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
520
521 return 0;
522 }
523
reverb_init(effect_context_t * context)524 int reverb_init(effect_context_t *context)
525 {
526 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
527
528 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
529 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
530 /*
531 FIXME: channel mode is mono for auxiliary. is it needed for offload ?
532 If so, this set config needs to be updated accordingly
533 */
534 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
535 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
536 context->config.inputCfg.samplingRate = 44100;
537 context->config.inputCfg.bufferProvider.getBuffer = NULL;
538 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
539 context->config.inputCfg.bufferProvider.cookie = NULL;
540 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
541 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
542 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
543 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
544 context->config.outputCfg.samplingRate = 44100;
545 context->config.outputCfg.bufferProvider.getBuffer = NULL;
546 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
547 context->config.outputCfg.bufferProvider.cookie = NULL;
548 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
549
550 set_config(context, &context->config);
551
552 memset(&(reverb_ctxt->reverb_settings), 0, sizeof(reverb_settings_t));
553 memset(&(reverb_ctxt->offload_reverb), 0, sizeof(struct reverb_params));
554
555 if (reverb_ctxt->preset &&
556 reverb_ctxt->next_preset != reverb_ctxt->cur_preset)
557 reverb_load_preset(reverb_ctxt);
558
559 return 0;
560 }
561
reverb_enable(effect_context_t * context)562 int reverb_enable(effect_context_t *context)
563 {
564 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
565
566 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
567
568 if (!offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb)))
569 offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), true);
570 return 0;
571 }
572
reverb_disable(effect_context_t * context)573 int reverb_disable(effect_context_t *context)
574 {
575 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
576
577 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
578 if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) {
579 offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), false);
580 if (reverb_ctxt->ctl)
581 offload_reverb_send_params(reverb_ctxt->ctl,
582 reverb_ctxt->offload_reverb,
583 OFFLOAD_SEND_REVERB_ENABLE_FLAG);
584 }
585 return 0;
586 }
587
reverb_start(effect_context_t * context,output_context_t * output)588 int reverb_start(effect_context_t *context, output_context_t *output)
589 {
590 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
591
592 ALOGV("%s: ctxt %p, ctl %p", __func__, reverb_ctxt, output->ctl);
593 reverb_ctxt->ctl = output->ctl;
594 if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) {
595 if (reverb_ctxt->ctl && reverb_ctxt->preset) {
596 offload_reverb_send_params(reverb_ctxt->ctl, reverb_ctxt->offload_reverb,
597 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
598 OFFLOAD_SEND_REVERB_PRESET);
599 }
600 }
601
602 return 0;
603 }
604
reverb_stop(effect_context_t * context,output_context_t * output __unused)605 int reverb_stop(effect_context_t *context, output_context_t *output __unused)
606 {
607 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
608
609 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
610 reverb_ctxt->ctl = NULL;
611 return 0;
612 }
613
614