blob: eddaca1c74e30d4ffd51e81024c4629f5a50ce46 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +08002 * Copyright (c) 2013-2014, 2017, 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_equalizer"
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_equalizer.h>
28
29#include "effect_api.h"
30#include "equalizer.h"
31
32/* Offload equalizer UUID: a0dac280-401c-11e3-9379-0002a5d5c51b */
33const effect_descriptor_t equalizer_descriptor = {
34 {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
35 {0xa0dac280, 0x401c, 0x11e3, 0x9379, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
36 EFFECT_CONTROL_API_VERSION,
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +080037 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_HW_ACC_TUNNEL | EFFECT_FLAG_VOLUME_CTRL),
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080038 0, /* TODO */
39 1,
40 "MSM offload equalizer",
41 "The Android Open Source Project",
42};
43
Vatsal Buchaa1358992018-11-14 13:25:08 +053044#ifdef AUDIO_FEATURE_ENABLED_GCOV
45extern void __gcov_flush();
46void enable_gcov()
47{
48 __gcov_flush();
49}
50#else
51void enable_gcov()
52{
53}
54#endif
55
56
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080057static const char *equalizer_preset_names[] = {
58 "Normal",
59 "Classical",
60 "Dance",
61 "Flat",
62 "Folk",
63 "Heavy Metal",
64 "Hip Hop",
65 "Jazz",
66 "Pop",
67 "Rock"
wjiang1eae6252014-07-19 21:46:46 +080068};
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080069
70static const uint32_t equalizer_band_freq_range[NUM_EQ_BANDS][2] = {
71 {30000, 120000},
72 {120001, 460000},
73 {460001, 1800000},
74 {1800001, 7000000},
75 {7000001, 20000000}};
76
wjiang1eae6252014-07-19 21:46:46 +080077static const int16_t equalizer_band_presets_level[] = {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080078 3, 0, 0, 0, 3, /* Normal Preset */
79 5, 3, -2, 4, 4, /* Classical Preset */
80 6, 0, 2, 4, 1, /* Dance Preset */
81 0, 0, 0, 0, 0, /* Flat Preset */
82 3, 0, 0, 2, -1, /* Folk Preset */
83 4, 1, 9, 3, 0, /* Heavy Metal Preset */
84 5, 3, 0, 1, 3, /* Hip Hop Preset */
85 4, 2, -2, 2, 5, /* Jazz Preset */
86 -1, 2, 5, 1, -2, /* Pop Preset */
87 5, 3, -1, 3, 5}; /* Rock Preset */
88
89const uint16_t equalizer_band_presets_freq[NUM_EQ_BANDS] = {
90 60, /* Frequencies in Hz */
91 230,
92 910,
93 3600,
94 14000
95};
96
97/*
98 * Equalizer operations
99 */
100
101int equalizer_get_band_level(equalizer_context_t *context, int32_t band)
102{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530103 ALOGV("%s: ctxt %p, band: %d level: %d", __func__, context, band,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800104 context->band_levels[band] * 100);
105 return context->band_levels[band] * 100;
106}
107
108int equalizer_set_band_level(equalizer_context_t *context, int32_t band,
109 int32_t level)
110{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530111 ALOGV("%s: ctxt %p, band: %d, level: %d", __func__, context, band, level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800112 if (level > 0) {
113 level = (int)((level+50)/100);
114 } else {
115 level = (int)((level-50)/100);
116 }
117 context->band_levels[band] = level;
118 context->preset = PRESET_CUSTOM;
119
120 offload_eq_set_preset(&(context->offload_eq), PRESET_CUSTOM);
121 offload_eq_set_bands_level(&(context->offload_eq),
122 NUM_EQ_BANDS,
123 equalizer_band_presets_freq,
124 context->band_levels);
125 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700126 offload_eq_send_params(context->ctl, &context->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800127 OFFLOAD_SEND_EQ_ENABLE_FLAG |
128 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700129 if (context->hw_acc_fd > 0)
130 hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq,
131 OFFLOAD_SEND_EQ_ENABLE_FLAG |
132 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800133 return 0;
134}
135
136int equalizer_get_center_frequency(equalizer_context_t *context, int32_t band)
137{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530138 ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800139 return (equalizer_band_freq_range[band][0] +
140 equalizer_band_freq_range[band][1]) / 2;
141}
142
143int equalizer_get_band_freq_range(equalizer_context_t *context, int32_t band,
144 uint32_t *low, uint32_t *high)
145{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530146 ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800147 *low = equalizer_band_freq_range[band][0];
148 *high = equalizer_band_freq_range[band][1];
149 return 0;
150}
151
152int equalizer_get_band(equalizer_context_t *context, uint32_t freq)
153{
154 int i;
155
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530156 ALOGV("%s: ctxt %p, freq: %d", __func__, context, freq);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800157 for(i = 0; i < NUM_EQ_BANDS; i++) {
158 if (freq <= equalizer_band_freq_range[i][1]) {
159 return i;
160 }
161 }
162 return NUM_EQ_BANDS - 1;
163}
164
165int equalizer_get_preset(equalizer_context_t *context)
166{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530167 ALOGV("%s: ctxt %p, preset: %d", __func__, context, context->preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800168 return context->preset;
169}
170
171int equalizer_set_preset(equalizer_context_t *context, int preset)
172{
173 int i;
174
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530175 ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800176 context->preset = preset;
177 for (i=0; i<NUM_EQ_BANDS; i++)
178 context->band_levels[i] =
179 equalizer_band_presets_level[i + preset * NUM_EQ_BANDS];
180
181 offload_eq_set_preset(&(context->offload_eq), preset);
182 offload_eq_set_bands_level(&(context->offload_eq),
183 NUM_EQ_BANDS,
184 equalizer_band_presets_freq,
185 context->band_levels);
186 if(context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700187 offload_eq_send_params(context->ctl, &context->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800188 OFFLOAD_SEND_EQ_ENABLE_FLAG |
189 OFFLOAD_SEND_EQ_PRESET);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700190 if(context->hw_acc_fd > 0)
191 hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq,
192 OFFLOAD_SEND_EQ_ENABLE_FLAG |
193 OFFLOAD_SEND_EQ_PRESET);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800194 return 0;
195}
196
197const char * equalizer_get_preset_name(equalizer_context_t *context,
198 int32_t preset)
199{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530200 ALOGV("%s: ctxt %p, preset: %s", __func__, context,
201 equalizer_preset_names[preset]);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800202 if (preset == PRESET_CUSTOM) {
203 return "Custom";
204 } else {
205 return equalizer_preset_names[preset];
206 }
207}
208
209int equalizer_get_num_presets(equalizer_context_t *context)
210{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530211 ALOGV("%s: ctxt %p, presets_num: %d", __func__, context,
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +0800212 (int)(sizeof(equalizer_preset_names)/sizeof(char *)));
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800213 return sizeof(equalizer_preset_names)/sizeof(char *);
214}
215
216int equalizer_get_parameter(effect_context_t *context, effect_param_t *p,
217 uint32_t *size)
218{
219 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
220 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
221 int32_t *param_tmp = (int32_t *)p->data;
222 int32_t param = *param_tmp++;
223 int32_t param2;
224 char *name;
225 void *value = p->data + voffset;
226 int i;
227
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530228 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800229
230 p->status = 0;
231
232 switch (param) {
233 case EQ_PARAM_NUM_BANDS:
234 case EQ_PARAM_CUR_PRESET:
235 case EQ_PARAM_GET_NUM_OF_PRESETS:
236 case EQ_PARAM_BAND_LEVEL:
237 case EQ_PARAM_GET_BAND:
238 if (p->vsize < sizeof(int16_t))
239 p->status = -EINVAL;
240 p->vsize = sizeof(int16_t);
241 break;
242
243 case EQ_PARAM_LEVEL_RANGE:
244 if (p->vsize < 2 * sizeof(int16_t))
245 p->status = -EINVAL;
246 p->vsize = 2 * sizeof(int16_t);
247 break;
248 case EQ_PARAM_BAND_FREQ_RANGE:
249 if (p->vsize < 2 * sizeof(int32_t))
250 p->status = -EINVAL;
251 p->vsize = 2 * sizeof(int32_t);
252 break;
253
254 case EQ_PARAM_CENTER_FREQ:
255 if (p->vsize < sizeof(int32_t))
256 p->status = -EINVAL;
257 p->vsize = sizeof(int32_t);
258 break;
259
260 case EQ_PARAM_GET_PRESET_NAME:
261 break;
262
263 case EQ_PARAM_PROPERTIES:
264 if (p->vsize < (2 + NUM_EQ_BANDS) * sizeof(uint16_t))
265 p->status = -EINVAL;
266 p->vsize = (2 + NUM_EQ_BANDS) * sizeof(uint16_t);
267 break;
268
269 default:
270 p->status = -EINVAL;
271 }
272
273 *size = sizeof(effect_param_t) + voffset + p->vsize;
274
275 if (p->status != 0)
276 return 0;
277
278 switch (param) {
279 case EQ_PARAM_NUM_BANDS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800280 *(uint16_t *)value = (uint16_t)NUM_EQ_BANDS;
281 break;
282
283 case EQ_PARAM_LEVEL_RANGE:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800284 *(int16_t *)value = -1500;
285 *((int16_t *)value + 1) = 1500;
286 break;
287
288 case EQ_PARAM_BAND_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800289 param2 = *param_tmp;
rago3ef61e22016-10-31 12:42:15 -0700290 if (param2 < 0 || param2 >= NUM_EQ_BANDS) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800291 p->status = -EINVAL;
rago3ef61e22016-10-31 12:42:15 -0700292 if (param2 < 0) {
293 android_errorWriteLog(0x534e4554, "32438598");
294 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", param2);
295 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800296 break;
297 }
298 *(int16_t *)value = (int16_t)equalizer_get_band_level(eq_ctxt, param2);
299 break;
300
301 case EQ_PARAM_CENTER_FREQ:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800302 param2 = *param_tmp;
rago3ef61e22016-10-31 12:42:15 -0700303 if (param2 < 0 || param2 >= NUM_EQ_BANDS) {
304 p->status = -EINVAL;
305 if (param2 < 0) {
306 android_errorWriteLog(0x534e4554, "32436341");
307 ALOGW("\tERROR EQ_PARAM_CENTER_FREQ band %d", param2);
308 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800309 break;
310 }
311 *(int32_t *)value = equalizer_get_center_frequency(eq_ctxt, param2);
312 break;
313
314 case EQ_PARAM_BAND_FREQ_RANGE:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800315 param2 = *param_tmp;
rago3ef61e22016-10-31 12:42:15 -0700316 if (param2 < 0 || param2 >= NUM_EQ_BANDS) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800317 p->status = -EINVAL;
rago3ef61e22016-10-31 12:42:15 -0700318 if (param2 < 0) {
319 android_errorWriteLog(0x534e4554, "32247948");
320 ALOGW("\tERROR EQ_PARAM_BAND_FREQ_RANGE band %d", param2);
321 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800322 break;
323 }
324 equalizer_get_band_freq_range(eq_ctxt, param2, (uint32_t *)value,
325 ((uint32_t *)value + 1));
326 break;
327
328 case EQ_PARAM_GET_BAND:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800329 param2 = *param_tmp;
330 *(uint16_t *)value = (uint16_t)equalizer_get_band(eq_ctxt, param2);
331 break;
332
333 case EQ_PARAM_CUR_PRESET:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800334 *(uint16_t *)value = (uint16_t)equalizer_get_preset(eq_ctxt);
335 break;
336
337 case EQ_PARAM_GET_NUM_OF_PRESETS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800338 *(uint16_t *)value = (uint16_t)equalizer_get_num_presets(eq_ctxt);
339 break;
340
341 case EQ_PARAM_GET_PRESET_NAME:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800342 param2 = *param_tmp;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530343 ALOGV("%s: EQ_PARAM_GET_PRESET_NAME: param2: %d", __func__, param2);
rago0b386402016-11-15 13:00:50 -0800344 if ((param2 < 0 && param2 != PRESET_CUSTOM) ||
345 param2 >= equalizer_get_num_presets(eq_ctxt)) {
346 p->status = -EINVAL;
347 if (param2 < 0) {
348 android_errorWriteLog(0x534e4554, "32588016");
349 ALOGW("\tERROR EQ_PARAM_GET_PRESET_NAME preset %d", param2);
350 }
351 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800352 }
353 name = (char *)value;
354 strlcpy(name, equalizer_get_preset_name(eq_ctxt, param2), p->vsize - 1);
355 name[p->vsize - 1] = 0;
356 p->vsize = strlen(name) + 1;
357 break;
358
359 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800360 int16_t *prop = (int16_t *)value;
361 prop[0] = (int16_t)equalizer_get_preset(eq_ctxt);
362 prop[1] = (int16_t)NUM_EQ_BANDS;
363 for (i = 0; i < NUM_EQ_BANDS; i++) {
364 prop[2 + i] = (int16_t)equalizer_get_band_level(eq_ctxt, i);
365 }
366 } break;
367
368 default:
369 p->status = -EINVAL;
370 break;
371 }
372
373 return 0;
374}
375
376int equalizer_set_parameter(effect_context_t *context, effect_param_t *p,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700377 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800378{
379 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
380 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
381 void *value = p->data + voffset;
ragod8912a62017-06-06 15:02:43 -0700382 int32_t vsize = (int32_t) p->vsize;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800383 int32_t *param_tmp = (int32_t *)p->data;
384 int32_t param = *param_tmp++;
385 int32_t preset;
386 int32_t band;
387 int32_t level;
388 int i;
389
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530390 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800391
392 p->status = 0;
393
394 switch (param) {
395 case EQ_PARAM_CUR_PRESET:
ragod8912a62017-06-06 15:02:43 -0700396 if (vsize < sizeof(int16_t)) {
397 p->status = -EINVAL;
398 break;
399 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800400 preset = (int32_t)(*(uint16_t *)value);
401
402 if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) {
403 p->status = -EINVAL;
404 break;
405 }
406 equalizer_set_preset(eq_ctxt, preset);
407 break;
408 case EQ_PARAM_BAND_LEVEL:
ragod8912a62017-06-06 15:02:43 -0700409 if (vsize < sizeof(int16_t)) {
410 p->status = -EINVAL;
411 break;
412 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800413 band = *param_tmp;
414 level = (int32_t)(*(int16_t *)value);
rago0b386402016-11-15 13:00:50 -0800415 if (band < 0 || band >= NUM_EQ_BANDS) {
416 p->status = -EINVAL;
417 if (band < 0) {
418 android_errorWriteLog(0x534e4554, "32585400");
419 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", band);
420 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800421 break;
422 }
423 equalizer_set_band_level(eq_ctxt, band, level);
424 break;
425 case EQ_PARAM_PROPERTIES: {
ragod8912a62017-06-06 15:02:43 -0700426 if (vsize < sizeof(int16_t)) {
427 p->status = -EINVAL;
428 break;
429 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800430 int16_t *prop = (int16_t *)value;
431 if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) {
432 p->status = -EINVAL;
433 break;
434 }
435 if (prop[0] >= 0) {
436 equalizer_set_preset(eq_ctxt, (int)prop[0]);
437 } else {
ragod8912a62017-06-06 15:02:43 -0700438 if (vsize < (2 + NUM_EQ_BANDS) * sizeof(int16_t)) {
439 android_errorWriteLog(0x534e4554, "37563371");
440 ALOGE("\tERROR EQ_PARAM_PROPERTIES valueSize %d < %d",
441 vsize, (2 + NUM_EQ_BANDS) * sizeof(int16_t));
442 p->status = -EINVAL;
443 break;
444 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800445 if ((int)prop[1] != NUM_EQ_BANDS) {
446 p->status = -EINVAL;
447 break;
448 }
449 for (i = 0; i < NUM_EQ_BANDS; i++) {
450 equalizer_set_band_level(eq_ctxt, i, (int)prop[2 + i]);
451 }
452 }
453 } break;
454 default:
455 p->status = -EINVAL;
456 break;
457 }
458
459 return 0;
460}
461
462int equalizer_set_device(effect_context_t *context, uint32_t device)
463{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530464 ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800465 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
466 eq_ctxt->device = device;
467 offload_eq_set_device(&(eq_ctxt->offload_eq), device);
468 return 0;
469}
470
471int equalizer_reset(effect_context_t *context)
472{
473 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
474
475 return 0;
476}
477
478int equalizer_init(effect_context_t *context)
479{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530480 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800481 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
482
483 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
484 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
485 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
486 context->config.inputCfg.samplingRate = 44100;
487 context->config.inputCfg.bufferProvider.getBuffer = NULL;
488 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
489 context->config.inputCfg.bufferProvider.cookie = NULL;
490 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
491 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
492 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
493 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
494 context->config.outputCfg.samplingRate = 44100;
495 context->config.outputCfg.bufferProvider.getBuffer = NULL;
496 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
497 context->config.outputCfg.bufferProvider.cookie = NULL;
498 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
499
500 set_config(context, &context->config);
501
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700502 eq_ctxt->hw_acc_fd = -1;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800503 memset(&(eq_ctxt->offload_eq), 0, sizeof(struct eq_params));
504 offload_eq_set_preset(&(eq_ctxt->offload_eq), INVALID_PRESET);
Vatsal Buchaa1358992018-11-14 13:25:08 +0530505 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800506 return 0;
507}
508
509int equalizer_enable(effect_context_t *context)
510{
511 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
512
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530513 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800514
515 if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
516 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true);
517 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700518 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800519 OFFLOAD_SEND_EQ_ENABLE_FLAG |
520 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700521 if (eq_ctxt->hw_acc_fd > 0)
522 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
523 OFFLOAD_SEND_EQ_ENABLE_FLAG |
524 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800525 }
Vatsal Buchaa1358992018-11-14 13:25:08 +0530526 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800527 return 0;
528}
529
530int equalizer_disable(effect_context_t *context)
531{
532 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
533
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530534 ALOGV("%s:ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800535 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
536 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false);
537 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700538 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800539 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700540 if (eq_ctxt->hw_acc_fd > 0)
541 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
542 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800543 }
Vatsal Buchaa1358992018-11-14 13:25:08 +0530544 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800545 return 0;
546}
547
548int equalizer_start(effect_context_t *context, output_context_t *output)
549{
550 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
551
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530552 ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800553 eq_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700554 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800555 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700556 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800557 OFFLOAD_SEND_EQ_ENABLE_FLAG |
558 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700559 if (eq_ctxt->hw_acc_fd > 0)
560 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
561 OFFLOAD_SEND_EQ_ENABLE_FLAG |
562 OFFLOAD_SEND_EQ_BANDS_LEVEL);
563 }
Vatsal Buchaa1358992018-11-14 13:25:08 +0530564 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800565 return 0;
566}
567
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700568int equalizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800569{
570 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
571
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530572 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700573 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)) &&
574 eq_ctxt->ctl) {
575 struct eq_params eq;
576 eq.enable_flag = false;
577 offload_eq_send_params(eq_ctxt->ctl, &eq, OFFLOAD_SEND_EQ_ENABLE_FLAG);
578 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800579 eq_ctxt->ctl = NULL;
Vatsal Buchaa1358992018-11-14 13:25:08 +0530580 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800581 return 0;
582}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700583
584int equalizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
585{
586 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
587
588 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
589 eq_ctxt->hw_acc_fd = hw_acc_fd;
590 if ((eq_ctxt->hw_acc_fd > 0) &&
591 (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))))
592 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
593 OFFLOAD_SEND_EQ_ENABLE_FLAG |
594 OFFLOAD_SEND_EQ_BANDS_LEVEL);
595 return 0;
596}