blob: 3096eb92707e8032a976492f3bd963ca7e07bd39 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Trinath Thammishetty765efd22018-08-20 13:23:24 +05302 * Copyright (c) 2013-2014, 2017-2018, 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
Trinath Thammishetty765efd22018-08-20 13:23:24 +053032#define EQUALIZER_MAX_LATENCY 0
33
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080034/* Offload equalizer UUID: a0dac280-401c-11e3-9379-0002a5d5c51b */
35const effect_descriptor_t equalizer_descriptor = {
36 {0x0bed4300, 0xddd6, 0x11db, 0x8f34, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // type
37 {0xa0dac280, 0x401c, 0x11e3, 0x9379, {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
38 EFFECT_CONTROL_API_VERSION,
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +080039 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_HW_ACC_TUNNEL | EFFECT_FLAG_VOLUME_CTRL),
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080040 0, /* TODO */
41 1,
42 "MSM offload equalizer",
43 "The Android Open Source Project",
44};
45
Vatsal Buchac09ae062018-11-14 13:25:08 +053046#ifdef AUDIO_FEATURE_ENABLED_GCOV
47extern void __gcov_flush();
48void enable_gcov()
49{
50 __gcov_flush();
51}
52#else
53void enable_gcov()
54{
55}
56#endif
57
58
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080059static const char *equalizer_preset_names[] = {
60 "Normal",
61 "Classical",
62 "Dance",
63 "Flat",
64 "Folk",
65 "Heavy Metal",
66 "Hip Hop",
67 "Jazz",
68 "Pop",
69 "Rock"
wjiang1eae6252014-07-19 21:46:46 +080070};
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080071
72static const uint32_t equalizer_band_freq_range[NUM_EQ_BANDS][2] = {
73 {30000, 120000},
74 {120001, 460000},
75 {460001, 1800000},
76 {1800001, 7000000},
77 {7000001, 20000000}};
78
wjiang1eae6252014-07-19 21:46:46 +080079static const int16_t equalizer_band_presets_level[] = {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080080 3, 0, 0, 0, 3, /* Normal Preset */
81 5, 3, -2, 4, 4, /* Classical Preset */
82 6, 0, 2, 4, 1, /* Dance Preset */
83 0, 0, 0, 0, 0, /* Flat Preset */
84 3, 0, 0, 2, -1, /* Folk Preset */
85 4, 1, 9, 3, 0, /* Heavy Metal Preset */
86 5, 3, 0, 1, 3, /* Hip Hop Preset */
87 4, 2, -2, 2, 5, /* Jazz Preset */
88 -1, 2, 5, 1, -2, /* Pop Preset */
89 5, 3, -1, 3, 5}; /* Rock Preset */
90
91const uint16_t equalizer_band_presets_freq[NUM_EQ_BANDS] = {
92 60, /* Frequencies in Hz */
93 230,
94 910,
95 3600,
96 14000
97};
98
99/*
100 * Equalizer operations
101 */
102
103int equalizer_get_band_level(equalizer_context_t *context, int32_t band)
104{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530105 ALOGV("%s: ctxt %p, band: %d level: %d", __func__, context, band,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800106 context->band_levels[band] * 100);
107 return context->band_levels[band] * 100;
108}
109
110int equalizer_set_band_level(equalizer_context_t *context, int32_t band,
111 int32_t level)
112{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530113 ALOGV("%s: ctxt %p, band: %d, level: %d", __func__, context, band, level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800114 if (level > 0) {
115 level = (int)((level+50)/100);
116 } else {
117 level = (int)((level-50)/100);
118 }
119 context->band_levels[band] = level;
120 context->preset = PRESET_CUSTOM;
121
122 offload_eq_set_preset(&(context->offload_eq), PRESET_CUSTOM);
123 offload_eq_set_bands_level(&(context->offload_eq),
124 NUM_EQ_BANDS,
125 equalizer_band_presets_freq,
126 context->band_levels);
127 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700128 offload_eq_send_params(context->ctl, &context->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800129 OFFLOAD_SEND_EQ_ENABLE_FLAG |
130 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700131 if (context->hw_acc_fd > 0)
132 hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq,
133 OFFLOAD_SEND_EQ_ENABLE_FLAG |
134 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800135 return 0;
136}
137
138int equalizer_get_center_frequency(equalizer_context_t *context, int32_t band)
139{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530140 ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800141 return (equalizer_band_freq_range[band][0] +
142 equalizer_band_freq_range[band][1]) / 2;
143}
144
145int equalizer_get_band_freq_range(equalizer_context_t *context, int32_t band,
146 uint32_t *low, uint32_t *high)
147{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530148 ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800149 *low = equalizer_band_freq_range[band][0];
150 *high = equalizer_band_freq_range[band][1];
151 return 0;
152}
153
154int equalizer_get_band(equalizer_context_t *context, uint32_t freq)
155{
156 int i;
157
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530158 ALOGV("%s: ctxt %p, freq: %d", __func__, context, freq);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800159 for(i = 0; i < NUM_EQ_BANDS; i++) {
160 if (freq <= equalizer_band_freq_range[i][1]) {
161 return i;
162 }
163 }
164 return NUM_EQ_BANDS - 1;
165}
166
167int equalizer_get_preset(equalizer_context_t *context)
168{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530169 ALOGV("%s: ctxt %p, preset: %d", __func__, context, context->preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800170 return context->preset;
171}
172
173int equalizer_set_preset(equalizer_context_t *context, int preset)
174{
175 int i;
176
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530177 ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800178 context->preset = preset;
179 for (i=0; i<NUM_EQ_BANDS; i++)
180 context->band_levels[i] =
181 equalizer_band_presets_level[i + preset * NUM_EQ_BANDS];
182
183 offload_eq_set_preset(&(context->offload_eq), preset);
184 offload_eq_set_bands_level(&(context->offload_eq),
185 NUM_EQ_BANDS,
186 equalizer_band_presets_freq,
187 context->band_levels);
188 if(context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700189 offload_eq_send_params(context->ctl, &context->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800190 OFFLOAD_SEND_EQ_ENABLE_FLAG |
191 OFFLOAD_SEND_EQ_PRESET);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700192 if(context->hw_acc_fd > 0)
193 hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq,
194 OFFLOAD_SEND_EQ_ENABLE_FLAG |
195 OFFLOAD_SEND_EQ_PRESET);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800196 return 0;
197}
198
199const char * equalizer_get_preset_name(equalizer_context_t *context,
200 int32_t preset)
201{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530202 ALOGV("%s: ctxt %p, preset: %s", __func__, context,
203 equalizer_preset_names[preset]);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800204 if (preset == PRESET_CUSTOM) {
205 return "Custom";
206 } else {
207 return equalizer_preset_names[preset];
208 }
209}
210
211int equalizer_get_num_presets(equalizer_context_t *context)
212{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530213 ALOGV("%s: ctxt %p, presets_num: %d", __func__, context,
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +0800214 (int)(sizeof(equalizer_preset_names)/sizeof(char *)));
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800215 return sizeof(equalizer_preset_names)/sizeof(char *);
216}
217
218int equalizer_get_parameter(effect_context_t *context, effect_param_t *p,
219 uint32_t *size)
220{
221 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
222 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
223 int32_t *param_tmp = (int32_t *)p->data;
224 int32_t param = *param_tmp++;
225 int32_t param2;
226 char *name;
227 void *value = p->data + voffset;
228 int i;
229
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530230 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800231
232 p->status = 0;
233
234 switch (param) {
235 case EQ_PARAM_NUM_BANDS:
236 case EQ_PARAM_CUR_PRESET:
237 case EQ_PARAM_GET_NUM_OF_PRESETS:
238 case EQ_PARAM_BAND_LEVEL:
239 case EQ_PARAM_GET_BAND:
240 if (p->vsize < sizeof(int16_t))
241 p->status = -EINVAL;
242 p->vsize = sizeof(int16_t);
243 break;
244
245 case EQ_PARAM_LEVEL_RANGE:
246 if (p->vsize < 2 * sizeof(int16_t))
247 p->status = -EINVAL;
248 p->vsize = 2 * sizeof(int16_t);
249 break;
250 case EQ_PARAM_BAND_FREQ_RANGE:
251 if (p->vsize < 2 * sizeof(int32_t))
252 p->status = -EINVAL;
253 p->vsize = 2 * sizeof(int32_t);
254 break;
255
256 case EQ_PARAM_CENTER_FREQ:
257 if (p->vsize < sizeof(int32_t))
258 p->status = -EINVAL;
259 p->vsize = sizeof(int32_t);
260 break;
261
262 case EQ_PARAM_GET_PRESET_NAME:
263 break;
264
265 case EQ_PARAM_PROPERTIES:
266 if (p->vsize < (2 + NUM_EQ_BANDS) * sizeof(uint16_t))
267 p->status = -EINVAL;
268 p->vsize = (2 + NUM_EQ_BANDS) * sizeof(uint16_t);
269 break;
270
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530271 case EQ_PARAM_LATENCY:
272 if (p->vsize < sizeof(uint32_t))
273 p->status = -EINVAL;
274 p->vsize = sizeof(uint32_t);
275 break;
276
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800277 default:
278 p->status = -EINVAL;
279 }
280
281 *size = sizeof(effect_param_t) + voffset + p->vsize;
282
283 if (p->status != 0)
284 return 0;
285
286 switch (param) {
287 case EQ_PARAM_NUM_BANDS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800288 *(uint16_t *)value = (uint16_t)NUM_EQ_BANDS;
289 break;
290
291 case EQ_PARAM_LEVEL_RANGE:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800292 *(int16_t *)value = -1500;
293 *((int16_t *)value + 1) = 1500;
294 break;
295
296 case EQ_PARAM_BAND_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800297 param2 = *param_tmp;
rago3ef61e22016-10-31 12:42:15 -0700298 if (param2 < 0 || param2 >= NUM_EQ_BANDS) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800299 p->status = -EINVAL;
rago3ef61e22016-10-31 12:42:15 -0700300 if (param2 < 0) {
301 android_errorWriteLog(0x534e4554, "32438598");
302 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", param2);
303 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800304 break;
305 }
306 *(int16_t *)value = (int16_t)equalizer_get_band_level(eq_ctxt, param2);
307 break;
308
309 case EQ_PARAM_CENTER_FREQ:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800310 param2 = *param_tmp;
rago3ef61e22016-10-31 12:42:15 -0700311 if (param2 < 0 || param2 >= NUM_EQ_BANDS) {
312 p->status = -EINVAL;
313 if (param2 < 0) {
314 android_errorWriteLog(0x534e4554, "32436341");
315 ALOGW("\tERROR EQ_PARAM_CENTER_FREQ band %d", param2);
316 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800317 break;
318 }
319 *(int32_t *)value = equalizer_get_center_frequency(eq_ctxt, param2);
320 break;
321
322 case EQ_PARAM_BAND_FREQ_RANGE:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800323 param2 = *param_tmp;
rago3ef61e22016-10-31 12:42:15 -0700324 if (param2 < 0 || param2 >= NUM_EQ_BANDS) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800325 p->status = -EINVAL;
rago3ef61e22016-10-31 12:42:15 -0700326 if (param2 < 0) {
327 android_errorWriteLog(0x534e4554, "32247948");
328 ALOGW("\tERROR EQ_PARAM_BAND_FREQ_RANGE band %d", param2);
329 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800330 break;
331 }
332 equalizer_get_band_freq_range(eq_ctxt, param2, (uint32_t *)value,
333 ((uint32_t *)value + 1));
334 break;
335
336 case EQ_PARAM_GET_BAND:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800337 param2 = *param_tmp;
338 *(uint16_t *)value = (uint16_t)equalizer_get_band(eq_ctxt, param2);
339 break;
340
341 case EQ_PARAM_CUR_PRESET:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800342 *(uint16_t *)value = (uint16_t)equalizer_get_preset(eq_ctxt);
343 break;
344
345 case EQ_PARAM_GET_NUM_OF_PRESETS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800346 *(uint16_t *)value = (uint16_t)equalizer_get_num_presets(eq_ctxt);
347 break;
348
349 case EQ_PARAM_GET_PRESET_NAME:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800350 param2 = *param_tmp;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530351 ALOGV("%s: EQ_PARAM_GET_PRESET_NAME: param2: %d", __func__, param2);
rago0b386402016-11-15 13:00:50 -0800352 if ((param2 < 0 && param2 != PRESET_CUSTOM) ||
353 param2 >= equalizer_get_num_presets(eq_ctxt)) {
354 p->status = -EINVAL;
355 if (param2 < 0) {
356 android_errorWriteLog(0x534e4554, "32588016");
357 ALOGW("\tERROR EQ_PARAM_GET_PRESET_NAME preset %d", param2);
358 }
359 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800360 }
361 name = (char *)value;
362 strlcpy(name, equalizer_get_preset_name(eq_ctxt, param2), p->vsize - 1);
363 name[p->vsize - 1] = 0;
364 p->vsize = strlen(name) + 1;
365 break;
366
367 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800368 int16_t *prop = (int16_t *)value;
369 prop[0] = (int16_t)equalizer_get_preset(eq_ctxt);
370 prop[1] = (int16_t)NUM_EQ_BANDS;
371 for (i = 0; i < NUM_EQ_BANDS; i++) {
372 prop[2 + i] = (int16_t)equalizer_get_band_level(eq_ctxt, i);
373 }
374 } break;
375
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530376 case EQ_PARAM_LATENCY:
377 *(uint32_t *)value = EQUALIZER_MAX_LATENCY;
378 break;
379
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800380 default:
381 p->status = -EINVAL;
382 break;
383 }
384
385 return 0;
386}
387
388int equalizer_set_parameter(effect_context_t *context, effect_param_t *p,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700389 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800390{
391 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
392 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
393 void *value = p->data + voffset;
ragod8912a62017-06-06 15:02:43 -0700394 int32_t vsize = (int32_t) p->vsize;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800395 int32_t *param_tmp = (int32_t *)p->data;
396 int32_t param = *param_tmp++;
397 int32_t preset;
398 int32_t band;
399 int32_t level;
400 int i;
401
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530402 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800403
404 p->status = 0;
405
406 switch (param) {
407 case EQ_PARAM_CUR_PRESET:
ragod8912a62017-06-06 15:02:43 -0700408 if (vsize < sizeof(int16_t)) {
409 p->status = -EINVAL;
410 break;
411 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800412 preset = (int32_t)(*(uint16_t *)value);
413
414 if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) {
415 p->status = -EINVAL;
416 break;
417 }
418 equalizer_set_preset(eq_ctxt, preset);
419 break;
420 case EQ_PARAM_BAND_LEVEL:
ragod8912a62017-06-06 15:02:43 -0700421 if (vsize < sizeof(int16_t)) {
422 p->status = -EINVAL;
423 break;
424 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800425 band = *param_tmp;
426 level = (int32_t)(*(int16_t *)value);
rago0b386402016-11-15 13:00:50 -0800427 if (band < 0 || band >= NUM_EQ_BANDS) {
428 p->status = -EINVAL;
429 if (band < 0) {
430 android_errorWriteLog(0x534e4554, "32585400");
431 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", band);
432 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800433 break;
434 }
435 equalizer_set_band_level(eq_ctxt, band, level);
436 break;
437 case EQ_PARAM_PROPERTIES: {
ragod8912a62017-06-06 15:02:43 -0700438 if (vsize < sizeof(int16_t)) {
439 p->status = -EINVAL;
440 break;
441 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800442 int16_t *prop = (int16_t *)value;
443 if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) {
444 p->status = -EINVAL;
445 break;
446 }
447 if (prop[0] >= 0) {
448 equalizer_set_preset(eq_ctxt, (int)prop[0]);
449 } else {
ragod8912a62017-06-06 15:02:43 -0700450 if (vsize < (2 + NUM_EQ_BANDS) * sizeof(int16_t)) {
451 android_errorWriteLog(0x534e4554, "37563371");
452 ALOGE("\tERROR EQ_PARAM_PROPERTIES valueSize %d < %d",
453 vsize, (2 + NUM_EQ_BANDS) * sizeof(int16_t));
454 p->status = -EINVAL;
455 break;
456 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800457 if ((int)prop[1] != NUM_EQ_BANDS) {
458 p->status = -EINVAL;
459 break;
460 }
461 for (i = 0; i < NUM_EQ_BANDS; i++) {
462 equalizer_set_band_level(eq_ctxt, i, (int)prop[2 + i]);
463 }
464 }
465 } break;
466 default:
467 p->status = -EINVAL;
468 break;
469 }
470
471 return 0;
472}
473
474int equalizer_set_device(effect_context_t *context, uint32_t device)
475{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530476 ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800477 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
478 eq_ctxt->device = device;
479 offload_eq_set_device(&(eq_ctxt->offload_eq), device);
480 return 0;
481}
482
483int equalizer_reset(effect_context_t *context)
484{
485 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
486
487 return 0;
488}
489
490int equalizer_init(effect_context_t *context)
491{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530492 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800493 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
494
495 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
496 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
497 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
498 context->config.inputCfg.samplingRate = 44100;
499 context->config.inputCfg.bufferProvider.getBuffer = NULL;
500 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
501 context->config.inputCfg.bufferProvider.cookie = NULL;
502 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
503 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
504 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
505 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
506 context->config.outputCfg.samplingRate = 44100;
507 context->config.outputCfg.bufferProvider.getBuffer = NULL;
508 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
509 context->config.outputCfg.bufferProvider.cookie = NULL;
510 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
511
512 set_config(context, &context->config);
513
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700514 eq_ctxt->hw_acc_fd = -1;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800515 memset(&(eq_ctxt->offload_eq), 0, sizeof(struct eq_params));
516 offload_eq_set_preset(&(eq_ctxt->offload_eq), INVALID_PRESET);
Vatsal Buchac09ae062018-11-14 13:25:08 +0530517 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800518 return 0;
519}
520
521int equalizer_enable(effect_context_t *context)
522{
523 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
524
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530525 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800526
527 if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
528 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true);
529 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700530 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800531 OFFLOAD_SEND_EQ_ENABLE_FLAG |
532 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700533 if (eq_ctxt->hw_acc_fd > 0)
534 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
535 OFFLOAD_SEND_EQ_ENABLE_FLAG |
536 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800537 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530538 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800539 return 0;
540}
541
542int equalizer_disable(effect_context_t *context)
543{
544 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
545
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530546 ALOGV("%s:ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800547 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
548 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false);
549 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700550 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800551 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700552 if (eq_ctxt->hw_acc_fd > 0)
553 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
554 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800555 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530556 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800557 return 0;
558}
559
560int equalizer_start(effect_context_t *context, output_context_t *output)
561{
562 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
563
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530564 ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800565 eq_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700566 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800567 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700568 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800569 OFFLOAD_SEND_EQ_ENABLE_FLAG |
570 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700571 if (eq_ctxt->hw_acc_fd > 0)
572 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
573 OFFLOAD_SEND_EQ_ENABLE_FLAG |
574 OFFLOAD_SEND_EQ_BANDS_LEVEL);
575 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530576 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800577 return 0;
578}
579
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700580int equalizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800581{
582 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
583
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530584 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700585 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)) &&
586 eq_ctxt->ctl) {
587 struct eq_params eq;
588 eq.enable_flag = false;
589 offload_eq_send_params(eq_ctxt->ctl, &eq, OFFLOAD_SEND_EQ_ENABLE_FLAG);
590 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800591 eq_ctxt->ctl = NULL;
Vatsal Buchac09ae062018-11-14 13:25:08 +0530592 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800593 return 0;
594}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700595
596int equalizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
597{
598 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
599
600 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
601 eq_ctxt->hw_acc_fd = hw_acc_fd;
602 if ((eq_ctxt->hw_acc_fd > 0) &&
603 (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))))
604 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
605 OFFLOAD_SEND_EQ_ENABLE_FLAG |
606 OFFLOAD_SEND_EQ_BANDS_LEVEL);
607 return 0;
608}