blob: b256e538b44640d0d405264a552419cb939a4444 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -07002 * Copyright (c) 2013 - 2014, The Linux Foundation. All rights reserved.
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08003 * 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"
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070021//#define LOG_NDEBUG 0
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080022
23#include <cutils/list.h>
24#include <cutils/log.h>
25#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080026#include <sound/audio_effects.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080027#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 */
34const 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 */
46const 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 */
58const 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 */
70const 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
81static 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
99void reverb_auxiliary_init(reverb_context_t *context)
100{
101 context->auxiliary = true;
102 context->preset = false;
103}
104
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700105void reverb_insert_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
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800113void reverb_preset_init(reverb_context_t *context)
114{
115 context->auxiliary = false;
116 context->preset = true;
117 context->cur_preset = REVERB_PRESET_LAST + 1;
118 context->next_preset = REVERB_DEFAULT_PRESET;
119}
120
121/*
122 * Reverb operations
123 */
124int16_t reverb_get_room_level(reverb_context_t *context)
125{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530126 ALOGV("%s: ctxt %p, room level: %d", __func__, context, context->reverb_settings.roomLevel);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800127 return context->reverb_settings.roomLevel;
128}
129
130void reverb_set_room_level(reverb_context_t *context, int16_t room_level)
131{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530132 ALOGV("%s: ctxt %p, room level: %d", __func__, context, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800133 context->reverb_settings.roomLevel = room_level;
134 offload_reverb_set_room_level(&(context->offload_reverb), room_level);
135 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700136 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800137 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
138 OFFLOAD_SEND_REVERB_ROOM_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700139 if (context->hw_acc_fd > 0)
140 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
141 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
142 OFFLOAD_SEND_REVERB_ROOM_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800143}
144
145int16_t reverb_get_room_hf_level(reverb_context_t *context)
146{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530147 ALOGV("%s: ctxt %p, room hf level: %d", __func__, context,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800148 context->reverb_settings.roomHFLevel);
149 return context->reverb_settings.roomHFLevel;
150}
151
152void reverb_set_room_hf_level(reverb_context_t *context, int16_t room_hf_level)
153{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530154 ALOGV("%s: ctxt %p, room hf level: %d", __func__, context, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800155 context->reverb_settings.roomHFLevel = room_hf_level;
156 offload_reverb_set_room_hf_level(&(context->offload_reverb), room_hf_level);
157 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700158 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800159 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
160 OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700161 if (context->hw_acc_fd > 0)
162 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
163 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
164 OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800165}
166
167uint32_t reverb_get_decay_time(reverb_context_t *context)
168{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530169 ALOGV("%s: ctxt %p, decay time: %d", __func__, context,
170 context->reverb_settings.decayTime);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800171 return context->reverb_settings.decayTime;
172}
173
174void reverb_set_decay_time(reverb_context_t *context, uint32_t decay_time)
175{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530176 ALOGV("%s: ctxt %p, decay_time: %d", __func__, context, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800177 context->reverb_settings.decayTime = decay_time;
178 offload_reverb_set_decay_time(&(context->offload_reverb), decay_time);
179 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700180 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800181 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
182 OFFLOAD_SEND_REVERB_DECAY_TIME);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700183 if (context->hw_acc_fd > 0)
184 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
185 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
186 OFFLOAD_SEND_REVERB_DECAY_TIME);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800187}
188
189int16_t reverb_get_decay_hf_ratio(reverb_context_t *context)
190{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530191 ALOGV("%s: ctxt %p, decay hf ratio: %d", __func__, context,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800192 context->reverb_settings.decayHFRatio);
193 return context->reverb_settings.decayHFRatio;
194}
195
196void reverb_set_decay_hf_ratio(reverb_context_t *context, int16_t decay_hf_ratio)
197{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530198 ALOGV("%s: ctxt %p, decay_hf_ratio: %d", __func__, context, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800199 context->reverb_settings.decayHFRatio = decay_hf_ratio;
200 offload_reverb_set_decay_hf_ratio(&(context->offload_reverb), decay_hf_ratio);
201 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700202 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800203 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
204 OFFLOAD_SEND_REVERB_DECAY_HF_RATIO);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700205 if (context->hw_acc_fd > 0)
206 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
207 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
208 OFFLOAD_SEND_REVERB_DECAY_HF_RATIO);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800209}
210
211int16_t reverb_get_reverb_level(reverb_context_t *context)
212{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530213 ALOGV("%s: ctxt %p, reverb level: %d", __func__, context,
214 context->reverb_settings.reverbLevel);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800215 return context->reverb_settings.reverbLevel;
216}
217
218void reverb_set_reverb_level(reverb_context_t *context, int16_t reverb_level)
219{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530220 ALOGV("%s: ctxt %p, reverb level: %d", __func__, context, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800221 context->reverb_settings.reverbLevel = reverb_level;
222 offload_reverb_set_reverb_level(&(context->offload_reverb), reverb_level);
223 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700224 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800225 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
226 OFFLOAD_SEND_REVERB_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700227 if (context->hw_acc_fd > 0)
228 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
229 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
230 OFFLOAD_SEND_REVERB_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800231}
232
233int16_t reverb_get_diffusion(reverb_context_t *context)
234{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530235 ALOGV("%s: ctxt %p, diffusion: %d", __func__, context,
236 context->reverb_settings.diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800237 return context->reverb_settings.diffusion;
238}
239
240void reverb_set_diffusion(reverb_context_t *context, int16_t diffusion)
241{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530242 ALOGV("%s: ctxt %p, diffusion: %d", __func__, context, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800243 context->reverb_settings.diffusion = diffusion;
244 offload_reverb_set_diffusion(&(context->offload_reverb), diffusion);
245 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700246 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800247 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
248 OFFLOAD_SEND_REVERB_DIFFUSION);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700249 if (context->hw_acc_fd > 0)
250 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
251 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
252 OFFLOAD_SEND_REVERB_DIFFUSION);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800253}
254
255int16_t reverb_get_density(reverb_context_t *context)
256{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530257 ALOGV("%s: ctxt %p, density: %d", __func__, context,
258 context->reverb_settings.density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800259 return context->reverb_settings.density;
260}
261
262void reverb_set_density(reverb_context_t *context, int16_t density)
263{
wjiang50b81f42014-08-06 08:03:14 +0800264 ALOGV("%s: ctxt %p, density: %d", __func__, context, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800265 context->reverb_settings.density = density;
266 offload_reverb_set_density(&(context->offload_reverb), density);
267 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700268 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800269 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
270 OFFLOAD_SEND_REVERB_DENSITY);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700271 if (context->hw_acc_fd > 0)
272 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
273 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
274 OFFLOAD_SEND_REVERB_DENSITY);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800275}
276
277void reverb_set_preset(reverb_context_t *context, int16_t preset)
278{
wjiangb27e25f2014-01-22 13:24:26 +0800279 bool enable;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530280 ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800281 context->next_preset = preset;
282 offload_reverb_set_preset(&(context->offload_reverb), preset);
wjiangb27e25f2014-01-22 13:24:26 +0800283
284 enable = (preset == REVERB_PRESET_NONE) ? false: true;
285 offload_reverb_set_enable_flag(&(context->offload_reverb), enable);
286
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800287 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700288 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800289 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
290 OFFLOAD_SEND_REVERB_PRESET);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700291 if (context->hw_acc_fd > 0)
292 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
293 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
294 OFFLOAD_SEND_REVERB_PRESET);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800295}
296
297void reverb_set_all_properties(reverb_context_t *context,
298 reverb_settings_t *reverb_settings)
299{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530300 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800301 context->reverb_settings.roomLevel = reverb_settings->roomLevel;
302 context->reverb_settings.roomHFLevel = reverb_settings->roomHFLevel;
303 context->reverb_settings.decayTime = reverb_settings->decayTime;
304 context->reverb_settings.decayHFRatio = reverb_settings->decayHFRatio;
305 context->reverb_settings.reverbLevel = reverb_settings->reverbLevel;
306 context->reverb_settings.diffusion = reverb_settings->diffusion;
307 context->reverb_settings.density = reverb_settings->density;
308 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700309 offload_reverb_send_params(context->ctl, &context->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800310 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
311 OFFLOAD_SEND_REVERB_ROOM_LEVEL |
312 OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL |
313 OFFLOAD_SEND_REVERB_DECAY_TIME |
314 OFFLOAD_SEND_REVERB_DECAY_HF_RATIO |
315 OFFLOAD_SEND_REVERB_LEVEL |
316 OFFLOAD_SEND_REVERB_DIFFUSION |
317 OFFLOAD_SEND_REVERB_DENSITY);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700318 if (context->hw_acc_fd > 0)
319 hw_acc_reverb_send_params(context->hw_acc_fd, &context->offload_reverb,
320 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
321 OFFLOAD_SEND_REVERB_ROOM_LEVEL |
322 OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL |
323 OFFLOAD_SEND_REVERB_DECAY_TIME |
324 OFFLOAD_SEND_REVERB_DECAY_HF_RATIO |
325 OFFLOAD_SEND_REVERB_LEVEL |
326 OFFLOAD_SEND_REVERB_DIFFUSION |
327 OFFLOAD_SEND_REVERB_DENSITY);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800328}
329
330void reverb_load_preset(reverb_context_t *context)
331{
332 context->cur_preset = context->next_preset;
333
334 if (context->cur_preset != REVERB_PRESET_NONE) {
335 const reverb_settings_t *preset = &reverb_presets[context->cur_preset];
336 reverb_set_room_level(context, preset->roomLevel);
337 reverb_set_room_hf_level(context, preset->roomHFLevel);
338 reverb_set_decay_time(context, preset->decayTime);
339 reverb_set_decay_hf_ratio(context, preset->decayHFRatio);
340 reverb_set_reverb_level(context, preset->reverbLevel);
341 reverb_set_diffusion(context, preset->diffusion);
342 reverb_set_density(context, preset->density);
343 }
344}
345
346int reverb_get_parameter(effect_context_t *context, effect_param_t *p,
347 uint32_t *size)
348{
349 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
350 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
351 int32_t *param_tmp = (int32_t *)p->data;
352 int32_t param = *param_tmp++;
353 void *value = p->data + voffset;
354 reverb_settings_t *reverb_settings;
355 int i;
356
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530357 ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800358
359 p->status = 0;
360
361 if (reverb_ctxt->preset) {
362 if (param != REVERB_PARAM_PRESET || p->vsize < sizeof(uint16_t))
363 return -EINVAL;
364 *(uint16_t *)value = reverb_ctxt->next_preset;
365 ALOGV("get REVERB_PARAM_PRESET, preset %d", reverb_ctxt->next_preset);
wjiangc37c2602014-03-24 23:43:09 +0800366 return 0;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800367 }
368 switch (param) {
369 case REVERB_PARAM_ROOM_LEVEL:
370 if (p->vsize < sizeof(uint16_t))
371 p->status = -EINVAL;
372 p->vsize = sizeof(uint16_t);
373 break;
374 case REVERB_PARAM_ROOM_HF_LEVEL:
375 if (p->vsize < sizeof(uint16_t))
376 p->status = -EINVAL;
377 p->vsize = sizeof(uint16_t);
378 break;
379 case REVERB_PARAM_DECAY_TIME:
380 if (p->vsize < sizeof(uint32_t))
381 p->status = -EINVAL;
382 p->vsize = sizeof(uint32_t);
383 break;
384 case REVERB_PARAM_DECAY_HF_RATIO:
385 if (p->vsize < sizeof(uint16_t))
386 p->status = -EINVAL;
387 p->vsize = sizeof(uint16_t);
388 break;
389 case REVERB_PARAM_REFLECTIONS_LEVEL:
390 if (p->vsize < sizeof(uint16_t))
391 p->status = -EINVAL;
392 p->vsize = sizeof(uint16_t);
393 break;
394 case REVERB_PARAM_REFLECTIONS_DELAY:
395 if (p->vsize < sizeof(uint32_t))
396 p->status = -EINVAL;
397 p->vsize = sizeof(uint32_t);
398 break;
399 case REVERB_PARAM_REVERB_LEVEL:
400 if (p->vsize < sizeof(uint16_t))
401 p->status = -EINVAL;
402 p->vsize = sizeof(uint16_t);
403 break;
404 case REVERB_PARAM_REVERB_DELAY:
405 if (p->vsize < sizeof(uint32_t))
406 p->status = -EINVAL;
407 p->vsize = sizeof(uint32_t);
408 break;
409 case REVERB_PARAM_DIFFUSION:
410 if (p->vsize < sizeof(uint16_t))
411 p->status = -EINVAL;
412 p->vsize = sizeof(uint16_t);
413 break;
414 case REVERB_PARAM_DENSITY:
415 if (p->vsize < sizeof(uint16_t))
416 p->status = -EINVAL;
417 p->vsize = sizeof(uint16_t);
418 break;
419 case REVERB_PARAM_PROPERTIES:
420 if (p->vsize < sizeof(reverb_settings_t))
421 p->status = -EINVAL;
422 p->vsize = sizeof(reverb_settings_t);
423 break;
424 default:
425 p->status = -EINVAL;
426 }
427
428 *size = sizeof(effect_param_t) + voffset + p->vsize;
429
430 if (p->status != 0)
431 return 0;
432
433 switch (param) {
434 case REVERB_PARAM_PROPERTIES:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800435 reverb_settings = (reverb_settings_t *)value;
436 reverb_settings->roomLevel = reverb_get_room_level(reverb_ctxt);
437 reverb_settings->roomHFLevel = reverb_get_room_hf_level(reverb_ctxt);
438 reverb_settings->decayTime = reverb_get_decay_time(reverb_ctxt);
439 reverb_settings->decayHFRatio = reverb_get_decay_hf_ratio(reverb_ctxt);
440 reverb_settings->reflectionsLevel = 0;
441 reverb_settings->reflectionsDelay = 0;
442 reverb_settings->reverbDelay = 0;
443 reverb_settings->reverbLevel = reverb_get_reverb_level(reverb_ctxt);
444 reverb_settings->diffusion = reverb_get_diffusion(reverb_ctxt);
445 reverb_settings->density = reverb_get_density(reverb_ctxt);
446 break;
447 case REVERB_PARAM_ROOM_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800448 *(int16_t *)value = reverb_get_room_level(reverb_ctxt);
449 break;
450 case REVERB_PARAM_ROOM_HF_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800451 *(int16_t *)value = reverb_get_room_hf_level(reverb_ctxt);
452 break;
453 case REVERB_PARAM_DECAY_TIME:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800454 *(uint32_t *)value = reverb_get_decay_time(reverb_ctxt);
455 break;
456 case REVERB_PARAM_DECAY_HF_RATIO:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800457 *(int16_t *)value = reverb_get_decay_hf_ratio(reverb_ctxt);
458 break;
459 case REVERB_PARAM_REVERB_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800460 *(int16_t *)value = reverb_get_reverb_level(reverb_ctxt);
461 break;
462 case REVERB_PARAM_DIFFUSION:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800463 *(int16_t *)value = reverb_get_diffusion(reverb_ctxt);
464 break;
465 case REVERB_PARAM_DENSITY:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800466 *(int16_t *)value = reverb_get_density(reverb_ctxt);
467 break;
468 case REVERB_PARAM_REFLECTIONS_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800469 *(uint16_t *)value = 0;
470 break;
471 case REVERB_PARAM_REFLECTIONS_DELAY:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800472 *(uint32_t *)value = 0;
473 break;
474 case REVERB_PARAM_REVERB_DELAY:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800475 *(uint32_t *)value = 0;
476 break;
477 default:
478 p->status = -EINVAL;
479 break;
480 }
481
482 return 0;
483}
484
485int reverb_set_parameter(effect_context_t *context, effect_param_t *p,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700486 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800487{
488 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
489 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
490 void *value = p->data + voffset;
491 int32_t *param_tmp = (int32_t *)p->data;
492 int32_t param = *param_tmp++;
493 reverb_settings_t *reverb_settings;
494 int16_t level;
495 int16_t ratio;
496 uint32_t time;
497
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530498 ALOGV("%s: ctxt %p, param %d", __func__, reverb_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800499
500 p->status = 0;
501
502 if (reverb_ctxt->preset) {
503 if (param != REVERB_PARAM_PRESET)
504 return -EINVAL;
505 uint16_t preset = *(uint16_t *)value;
506 ALOGV("set REVERB_PARAM_PRESET, preset %d", preset);
507 if (preset > REVERB_PRESET_LAST) {
508 return -EINVAL;
509 }
510 reverb_set_preset(reverb_ctxt, preset);
wjiangc37c2602014-03-24 23:43:09 +0800511 return 0;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800512 }
513 switch (param) {
514 case REVERB_PARAM_PROPERTIES:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800515 reverb_settings = (reverb_settings_t *)value;
516 break;
517 case REVERB_PARAM_ROOM_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800518 level = *(int16_t *)value;
519 reverb_set_room_level(reverb_ctxt, level);
520 break;
521 case REVERB_PARAM_ROOM_HF_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800522 level = *(int16_t *)value;
523 reverb_set_room_hf_level(reverb_ctxt, level);
524 break;
525 case REVERB_PARAM_DECAY_TIME:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800526 time = *(uint32_t *)value;
527 reverb_set_decay_time(reverb_ctxt, time);
528 break;
529 case REVERB_PARAM_DECAY_HF_RATIO:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800530 ratio = *(int16_t *)value;
531 reverb_set_decay_hf_ratio(reverb_ctxt, ratio);
532 break;
533 case REVERB_PARAM_REVERB_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800534 level = *(int16_t *)value;
535 reverb_set_reverb_level(reverb_ctxt, level);
536 break;
537 case REVERB_PARAM_DIFFUSION:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800538 ratio = *(int16_t *)value;
539 reverb_set_diffusion(reverb_ctxt, ratio);
540 break;
541 case REVERB_PARAM_DENSITY:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800542 ratio = *(int16_t *)value;
543 reverb_set_density(reverb_ctxt, ratio);
544 break;
545 case REVERB_PARAM_REFLECTIONS_LEVEL:
546 case REVERB_PARAM_REFLECTIONS_DELAY:
547 case REVERB_PARAM_REVERB_DELAY:
548 break;
549 default:
550 p->status = -EINVAL;
551 break;
552 }
553
554 return 0;
555}
556
557int reverb_set_device(effect_context_t *context, uint32_t device)
558{
559 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
560
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530561 ALOGV("%s: ctxt %p, device: 0x%x", __func__, reverb_ctxt, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800562 reverb_ctxt->device = device;
563 offload_reverb_set_device(&(reverb_ctxt->offload_reverb), device);
564 return 0;
565}
566
567int reverb_reset(effect_context_t *context)
568{
569 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
570
571 return 0;
572}
573
574int reverb_init(effect_context_t *context)
575{
576 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
577
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530578 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800579 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
580 /*
581 FIXME: channel mode is mono for auxiliary. is it needed for offload ?
582 If so, this set config needs to be updated accordingly
583 */
584 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
585 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
586 context->config.inputCfg.samplingRate = 44100;
587 context->config.inputCfg.bufferProvider.getBuffer = NULL;
588 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
589 context->config.inputCfg.bufferProvider.cookie = NULL;
590 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
591 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
592 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
593 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
594 context->config.outputCfg.samplingRate = 44100;
595 context->config.outputCfg.bufferProvider.getBuffer = NULL;
596 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
597 context->config.outputCfg.bufferProvider.cookie = NULL;
598 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
599
600 set_config(context, &context->config);
601
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700602 reverb_ctxt->hw_acc_fd = -1;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800603 memset(&(reverb_ctxt->reverb_settings), 0, sizeof(reverb_settings_t));
604 memset(&(reverb_ctxt->offload_reverb), 0, sizeof(struct reverb_params));
605
606 if (reverb_ctxt->preset &&
607 reverb_ctxt->next_preset != reverb_ctxt->cur_preset)
608 reverb_load_preset(reverb_ctxt);
609
610 return 0;
611}
612
613int reverb_enable(effect_context_t *context)
614{
615 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
616
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530617 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800618
619 if (!offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb)))
620 offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), true);
621 return 0;
622}
623
624int reverb_disable(effect_context_t *context)
625{
626 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
627
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530628 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800629 if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) {
630 offload_reverb_set_enable_flag(&(reverb_ctxt->offload_reverb), false);
631 if (reverb_ctxt->ctl)
632 offload_reverb_send_params(reverb_ctxt->ctl,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700633 &reverb_ctxt->offload_reverb,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800634 OFFLOAD_SEND_REVERB_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700635 if (reverb_ctxt->hw_acc_fd > 0)
636 hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd,
637 &reverb_ctxt->offload_reverb,
638 OFFLOAD_SEND_REVERB_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800639 }
640 return 0;
641}
642
643int reverb_start(effect_context_t *context, output_context_t *output)
644{
645 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
646
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530647 ALOGV("%s: ctxt %p, ctl %p", __func__, reverb_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800648 reverb_ctxt->ctl = output->ctl;
wjiangc37c2602014-03-24 23:43:09 +0800649 if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))) {
650 if (reverb_ctxt->ctl && reverb_ctxt->preset) {
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700651 offload_reverb_send_params(reverb_ctxt->ctl, &reverb_ctxt->offload_reverb,
wjiangc37c2602014-03-24 23:43:09 +0800652 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
653 OFFLOAD_SEND_REVERB_PRESET);
654 }
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700655 if ((reverb_ctxt->hw_acc_fd > 0) && reverb_ctxt->preset) {
656 hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd,
657 &reverb_ctxt->offload_reverb,
658 OFFLOAD_SEND_REVERB_ENABLE_FLAG |
659 OFFLOAD_SEND_REVERB_PRESET);
660 }
wjiangc37c2602014-03-24 23:43:09 +0800661 }
662
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800663 return 0;
664}
665
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700666int reverb_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800667{
668 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
669
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530670 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700671 if (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb)) &&
672 reverb_ctxt->ctl) {
673 struct reverb_params reverb;
674 reverb.enable_flag = false;
675 offload_reverb_send_params(reverb_ctxt->ctl, &reverb,
676 OFFLOAD_SEND_REVERB_ENABLE_FLAG);
677 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800678 reverb_ctxt->ctl = NULL;
679 return 0;
680}
681
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700682int reverb_set_mode(effect_context_t *context, int32_t hw_acc_fd)
683{
684 reverb_context_t *reverb_ctxt = (reverb_context_t *)context;
685
686 ALOGV("%s: ctxt %p", __func__, reverb_ctxt);
687 reverb_ctxt->hw_acc_fd = hw_acc_fd;
688 if ((reverb_ctxt->hw_acc_fd > 0) &&
689 (offload_reverb_get_enable_flag(&(reverb_ctxt->offload_reverb))))
690 hw_acc_reverb_send_params(reverb_ctxt->hw_acc_fd,
691 &reverb_ctxt->offload_reverb,
692 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG |
693 OFFLOAD_SEND_BASSBOOST_STRENGTH);
694 return 0;
695}