blob: ed16f1234890edf77b20ef5e9410e96ce8da208a [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2013-2014, 2017-2019, 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>
Aalique Grahame22e49102018-12-18 14:23:57 -080024#include <log/log.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080025#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 }
Aalique Grahame22e49102018-12-18 14:23:57 -0800361
362 if (p->vsize < 1) {
363 p->status = -EINVAL;
364 android_errorWriteLog(0x534e4554, "37536407");
365 break;
366 }
367
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800368 name = (char *)value;
369 strlcpy(name, equalizer_get_preset_name(eq_ctxt, param2), p->vsize - 1);
370 name[p->vsize - 1] = 0;
371 p->vsize = strlen(name) + 1;
372 break;
373
374 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800375 int16_t *prop = (int16_t *)value;
376 prop[0] = (int16_t)equalizer_get_preset(eq_ctxt);
377 prop[1] = (int16_t)NUM_EQ_BANDS;
378 for (i = 0; i < NUM_EQ_BANDS; i++) {
379 prop[2 + i] = (int16_t)equalizer_get_band_level(eq_ctxt, i);
380 }
381 } break;
382
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530383 case EQ_PARAM_LATENCY:
384 *(uint32_t *)value = EQUALIZER_MAX_LATENCY;
385 break;
386
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800387 default:
388 p->status = -EINVAL;
389 break;
390 }
391
392 return 0;
393}
394
395int equalizer_set_parameter(effect_context_t *context, effect_param_t *p,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700396 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800397{
398 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
399 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
400 void *value = p->data + voffset;
ragod8912a62017-06-06 15:02:43 -0700401 int32_t vsize = (int32_t) p->vsize;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800402 int32_t *param_tmp = (int32_t *)p->data;
403 int32_t param = *param_tmp++;
404 int32_t preset;
405 int32_t band;
406 int32_t level;
407 int i;
408
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530409 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800410
411 p->status = 0;
412
413 switch (param) {
414 case EQ_PARAM_CUR_PRESET:
ragod8912a62017-06-06 15:02:43 -0700415 if (vsize < sizeof(int16_t)) {
416 p->status = -EINVAL;
417 break;
418 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800419 preset = (int32_t)(*(uint16_t *)value);
420
421 if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) {
422 p->status = -EINVAL;
423 break;
424 }
425 equalizer_set_preset(eq_ctxt, preset);
426 break;
427 case EQ_PARAM_BAND_LEVEL:
ragod8912a62017-06-06 15:02:43 -0700428 if (vsize < sizeof(int16_t)) {
429 p->status = -EINVAL;
430 break;
431 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800432 band = *param_tmp;
433 level = (int32_t)(*(int16_t *)value);
rago0b386402016-11-15 13:00:50 -0800434 if (band < 0 || band >= NUM_EQ_BANDS) {
435 p->status = -EINVAL;
436 if (band < 0) {
437 android_errorWriteLog(0x534e4554, "32585400");
438 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", band);
439 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800440 break;
441 }
442 equalizer_set_band_level(eq_ctxt, band, level);
443 break;
444 case EQ_PARAM_PROPERTIES: {
ragod8912a62017-06-06 15:02:43 -0700445 if (vsize < sizeof(int16_t)) {
446 p->status = -EINVAL;
447 break;
448 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800449 int16_t *prop = (int16_t *)value;
450 if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) {
451 p->status = -EINVAL;
452 break;
453 }
454 if (prop[0] >= 0) {
455 equalizer_set_preset(eq_ctxt, (int)prop[0]);
456 } else {
ragod8912a62017-06-06 15:02:43 -0700457 if (vsize < (2 + NUM_EQ_BANDS) * sizeof(int16_t)) {
458 android_errorWriteLog(0x534e4554, "37563371");
459 ALOGE("\tERROR EQ_PARAM_PROPERTIES valueSize %d < %d",
Aalique Grahame22e49102018-12-18 14:23:57 -0800460 vsize, (int) ((2 + NUM_EQ_BANDS) * sizeof(int16_t)));
ragod8912a62017-06-06 15:02:43 -0700461 p->status = -EINVAL;
462 break;
463 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800464 if ((int)prop[1] != NUM_EQ_BANDS) {
465 p->status = -EINVAL;
466 break;
467 }
468 for (i = 0; i < NUM_EQ_BANDS; i++) {
469 equalizer_set_band_level(eq_ctxt, i, (int)prop[2 + i]);
470 }
471 }
472 } break;
473 default:
474 p->status = -EINVAL;
475 break;
476 }
477
478 return 0;
479}
480
481int equalizer_set_device(effect_context_t *context, uint32_t device)
482{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530483 ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800484 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
485 eq_ctxt->device = device;
486 offload_eq_set_device(&(eq_ctxt->offload_eq), device);
487 return 0;
488}
489
Aalique Grahame22e49102018-12-18 14:23:57 -0800490int equalizer_reset(effect_context_t *context __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800491{
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800492 return 0;
493}
494
495int equalizer_init(effect_context_t *context)
496{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530497 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800498 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
499
500 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
501 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
502 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
503 context->config.inputCfg.samplingRate = 44100;
504 context->config.inputCfg.bufferProvider.getBuffer = NULL;
505 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
506 context->config.inputCfg.bufferProvider.cookie = NULL;
507 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
508 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
509 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
510 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
511 context->config.outputCfg.samplingRate = 44100;
512 context->config.outputCfg.bufferProvider.getBuffer = NULL;
513 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
514 context->config.outputCfg.bufferProvider.cookie = NULL;
515 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
516
517 set_config(context, &context->config);
518
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700519 eq_ctxt->hw_acc_fd = -1;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800520 memset(&(eq_ctxt->offload_eq), 0, sizeof(struct eq_params));
521 offload_eq_set_preset(&(eq_ctxt->offload_eq), INVALID_PRESET);
Vatsal Buchac09ae062018-11-14 13:25:08 +0530522 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800523 return 0;
524}
525
526int equalizer_enable(effect_context_t *context)
527{
528 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
529
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530530 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800531
532 if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
533 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true);
534 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700535 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800536 OFFLOAD_SEND_EQ_ENABLE_FLAG |
537 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700538 if (eq_ctxt->hw_acc_fd > 0)
539 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
540 OFFLOAD_SEND_EQ_ENABLE_FLAG |
541 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800542 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530543 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800544 return 0;
545}
546
547int equalizer_disable(effect_context_t *context)
548{
549 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
550
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530551 ALOGV("%s:ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800552 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
553 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false);
554 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700555 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800556 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700557 if (eq_ctxt->hw_acc_fd > 0)
558 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
559 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800560 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530561 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800562 return 0;
563}
564
565int equalizer_start(effect_context_t *context, output_context_t *output)
566{
567 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
568
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530569 ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800570 eq_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700571 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800572 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700573 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800574 OFFLOAD_SEND_EQ_ENABLE_FLAG |
575 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700576 if (eq_ctxt->hw_acc_fd > 0)
577 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
578 OFFLOAD_SEND_EQ_ENABLE_FLAG |
579 OFFLOAD_SEND_EQ_BANDS_LEVEL);
580 }
Vatsal Buchac09ae062018-11-14 13:25:08 +0530581 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800582 return 0;
583}
584
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700585int equalizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800586{
587 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
588
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530589 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700590 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)) &&
591 eq_ctxt->ctl) {
592 struct eq_params eq;
593 eq.enable_flag = false;
594 offload_eq_send_params(eq_ctxt->ctl, &eq, OFFLOAD_SEND_EQ_ENABLE_FLAG);
595 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800596 eq_ctxt->ctl = NULL;
Vatsal Buchac09ae062018-11-14 13:25:08 +0530597 enable_gcov();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800598 return 0;
599}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700600
601int equalizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
602{
603 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
604
605 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
606 eq_ctxt->hw_acc_fd = hw_acc_fd;
607 if ((eq_ctxt->hw_acc_fd > 0) &&
608 (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))))
609 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
610 OFFLOAD_SEND_EQ_ENABLE_FLAG |
611 OFFLOAD_SEND_EQ_BANDS_LEVEL);
612 return 0;
613}