blob: 479f8481a429f28d37a1575cafa9e96969536ffc [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
46static const char *equalizer_preset_names[] = {
47 "Normal",
48 "Classical",
49 "Dance",
50 "Flat",
51 "Folk",
52 "Heavy Metal",
53 "Hip Hop",
54 "Jazz",
55 "Pop",
56 "Rock"
wjiang1eae6252014-07-19 21:46:46 +080057};
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080058
59static const uint32_t equalizer_band_freq_range[NUM_EQ_BANDS][2] = {
60 {30000, 120000},
61 {120001, 460000},
62 {460001, 1800000},
63 {1800001, 7000000},
64 {7000001, 20000000}};
65
wjiang1eae6252014-07-19 21:46:46 +080066static const int16_t equalizer_band_presets_level[] = {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080067 3, 0, 0, 0, 3, /* Normal Preset */
68 5, 3, -2, 4, 4, /* Classical Preset */
69 6, 0, 2, 4, 1, /* Dance Preset */
70 0, 0, 0, 0, 0, /* Flat Preset */
71 3, 0, 0, 2, -1, /* Folk Preset */
72 4, 1, 9, 3, 0, /* Heavy Metal Preset */
73 5, 3, 0, 1, 3, /* Hip Hop Preset */
74 4, 2, -2, 2, 5, /* Jazz Preset */
75 -1, 2, 5, 1, -2, /* Pop Preset */
76 5, 3, -1, 3, 5}; /* Rock Preset */
77
78const uint16_t equalizer_band_presets_freq[NUM_EQ_BANDS] = {
79 60, /* Frequencies in Hz */
80 230,
81 910,
82 3600,
83 14000
84};
85
86/*
87 * Equalizer operations
88 */
89
90int equalizer_get_band_level(equalizer_context_t *context, int32_t band)
91{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053092 ALOGV("%s: ctxt %p, band: %d level: %d", __func__, context, band,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080093 context->band_levels[band] * 100);
94 return context->band_levels[band] * 100;
95}
96
97int equalizer_set_band_level(equalizer_context_t *context, int32_t band,
98 int32_t level)
99{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530100 ALOGV("%s: ctxt %p, band: %d, level: %d", __func__, context, band, level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800101 if (level > 0) {
102 level = (int)((level+50)/100);
103 } else {
104 level = (int)((level-50)/100);
105 }
106 context->band_levels[band] = level;
107 context->preset = PRESET_CUSTOM;
108
109 offload_eq_set_preset(&(context->offload_eq), PRESET_CUSTOM);
110 offload_eq_set_bands_level(&(context->offload_eq),
111 NUM_EQ_BANDS,
112 equalizer_band_presets_freq,
113 context->band_levels);
114 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700115 offload_eq_send_params(context->ctl, &context->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800116 OFFLOAD_SEND_EQ_ENABLE_FLAG |
117 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700118 if (context->hw_acc_fd > 0)
119 hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq,
120 OFFLOAD_SEND_EQ_ENABLE_FLAG |
121 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800122 return 0;
123}
124
125int equalizer_get_center_frequency(equalizer_context_t *context, int32_t band)
126{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530127 ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800128 return (equalizer_band_freq_range[band][0] +
129 equalizer_band_freq_range[band][1]) / 2;
130}
131
132int equalizer_get_band_freq_range(equalizer_context_t *context, int32_t band,
133 uint32_t *low, uint32_t *high)
134{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530135 ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800136 *low = equalizer_band_freq_range[band][0];
137 *high = equalizer_band_freq_range[band][1];
138 return 0;
139}
140
141int equalizer_get_band(equalizer_context_t *context, uint32_t freq)
142{
143 int i;
144
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530145 ALOGV("%s: ctxt %p, freq: %d", __func__, context, freq);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800146 for(i = 0; i < NUM_EQ_BANDS; i++) {
147 if (freq <= equalizer_band_freq_range[i][1]) {
148 return i;
149 }
150 }
151 return NUM_EQ_BANDS - 1;
152}
153
154int equalizer_get_preset(equalizer_context_t *context)
155{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530156 ALOGV("%s: ctxt %p, preset: %d", __func__, context, context->preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800157 return context->preset;
158}
159
160int equalizer_set_preset(equalizer_context_t *context, int preset)
161{
162 int i;
163
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530164 ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800165 context->preset = preset;
166 for (i=0; i<NUM_EQ_BANDS; i++)
167 context->band_levels[i] =
168 equalizer_band_presets_level[i + preset * NUM_EQ_BANDS];
169
170 offload_eq_set_preset(&(context->offload_eq), preset);
171 offload_eq_set_bands_level(&(context->offload_eq),
172 NUM_EQ_BANDS,
173 equalizer_band_presets_freq,
174 context->band_levels);
175 if(context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700176 offload_eq_send_params(context->ctl, &context->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800177 OFFLOAD_SEND_EQ_ENABLE_FLAG |
178 OFFLOAD_SEND_EQ_PRESET);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700179 if(context->hw_acc_fd > 0)
180 hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq,
181 OFFLOAD_SEND_EQ_ENABLE_FLAG |
182 OFFLOAD_SEND_EQ_PRESET);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800183 return 0;
184}
185
186const char * equalizer_get_preset_name(equalizer_context_t *context,
187 int32_t preset)
188{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530189 ALOGV("%s: ctxt %p, preset: %s", __func__, context,
190 equalizer_preset_names[preset]);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800191 if (preset == PRESET_CUSTOM) {
192 return "Custom";
193 } else {
194 return equalizer_preset_names[preset];
195 }
196}
197
198int equalizer_get_num_presets(equalizer_context_t *context)
199{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530200 ALOGV("%s: ctxt %p, presets_num: %d", __func__, context,
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +0800201 (int)(sizeof(equalizer_preset_names)/sizeof(char *)));
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800202 return sizeof(equalizer_preset_names)/sizeof(char *);
203}
204
205int equalizer_get_parameter(effect_context_t *context, effect_param_t *p,
206 uint32_t *size)
207{
208 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
209 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
210 int32_t *param_tmp = (int32_t *)p->data;
211 int32_t param = *param_tmp++;
212 int32_t param2;
213 char *name;
214 void *value = p->data + voffset;
215 int i;
216
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530217 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800218
219 p->status = 0;
220
221 switch (param) {
222 case EQ_PARAM_NUM_BANDS:
223 case EQ_PARAM_CUR_PRESET:
224 case EQ_PARAM_GET_NUM_OF_PRESETS:
225 case EQ_PARAM_BAND_LEVEL:
226 case EQ_PARAM_GET_BAND:
227 if (p->vsize < sizeof(int16_t))
228 p->status = -EINVAL;
229 p->vsize = sizeof(int16_t);
230 break;
231
232 case EQ_PARAM_LEVEL_RANGE:
233 if (p->vsize < 2 * sizeof(int16_t))
234 p->status = -EINVAL;
235 p->vsize = 2 * sizeof(int16_t);
236 break;
237 case EQ_PARAM_BAND_FREQ_RANGE:
238 if (p->vsize < 2 * sizeof(int32_t))
239 p->status = -EINVAL;
240 p->vsize = 2 * sizeof(int32_t);
241 break;
242
243 case EQ_PARAM_CENTER_FREQ:
244 if (p->vsize < sizeof(int32_t))
245 p->status = -EINVAL;
246 p->vsize = sizeof(int32_t);
247 break;
248
249 case EQ_PARAM_GET_PRESET_NAME:
250 break;
251
252 case EQ_PARAM_PROPERTIES:
253 if (p->vsize < (2 + NUM_EQ_BANDS) * sizeof(uint16_t))
254 p->status = -EINVAL;
255 p->vsize = (2 + NUM_EQ_BANDS) * sizeof(uint16_t);
256 break;
257
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530258 case EQ_PARAM_LATENCY:
259 if (p->vsize < sizeof(uint32_t))
260 p->status = -EINVAL;
261 p->vsize = sizeof(uint32_t);
262 break;
263
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800264 default:
265 p->status = -EINVAL;
266 }
267
268 *size = sizeof(effect_param_t) + voffset + p->vsize;
269
270 if (p->status != 0)
271 return 0;
272
273 switch (param) {
274 case EQ_PARAM_NUM_BANDS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800275 *(uint16_t *)value = (uint16_t)NUM_EQ_BANDS;
276 break;
277
278 case EQ_PARAM_LEVEL_RANGE:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800279 *(int16_t *)value = -1500;
280 *((int16_t *)value + 1) = 1500;
281 break;
282
283 case EQ_PARAM_BAND_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800284 param2 = *param_tmp;
rago3ef61e22016-10-31 12:42:15 -0700285 if (param2 < 0 || param2 >= NUM_EQ_BANDS) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800286 p->status = -EINVAL;
rago3ef61e22016-10-31 12:42:15 -0700287 if (param2 < 0) {
288 android_errorWriteLog(0x534e4554, "32438598");
289 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", param2);
290 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800291 break;
292 }
293 *(int16_t *)value = (int16_t)equalizer_get_band_level(eq_ctxt, param2);
294 break;
295
296 case EQ_PARAM_CENTER_FREQ:
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) {
299 p->status = -EINVAL;
300 if (param2 < 0) {
301 android_errorWriteLog(0x534e4554, "32436341");
302 ALOGW("\tERROR EQ_PARAM_CENTER_FREQ band %d", param2);
303 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800304 break;
305 }
306 *(int32_t *)value = equalizer_get_center_frequency(eq_ctxt, param2);
307 break;
308
309 case EQ_PARAM_BAND_FREQ_RANGE:
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) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800312 p->status = -EINVAL;
rago3ef61e22016-10-31 12:42:15 -0700313 if (param2 < 0) {
314 android_errorWriteLog(0x534e4554, "32247948");
315 ALOGW("\tERROR EQ_PARAM_BAND_FREQ_RANGE band %d", param2);
316 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800317 break;
318 }
319 equalizer_get_band_freq_range(eq_ctxt, param2, (uint32_t *)value,
320 ((uint32_t *)value + 1));
321 break;
322
323 case EQ_PARAM_GET_BAND:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800324 param2 = *param_tmp;
325 *(uint16_t *)value = (uint16_t)equalizer_get_band(eq_ctxt, param2);
326 break;
327
328 case EQ_PARAM_CUR_PRESET:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800329 *(uint16_t *)value = (uint16_t)equalizer_get_preset(eq_ctxt);
330 break;
331
332 case EQ_PARAM_GET_NUM_OF_PRESETS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800333 *(uint16_t *)value = (uint16_t)equalizer_get_num_presets(eq_ctxt);
334 break;
335
336 case EQ_PARAM_GET_PRESET_NAME:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800337 param2 = *param_tmp;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530338 ALOGV("%s: EQ_PARAM_GET_PRESET_NAME: param2: %d", __func__, param2);
rago0b386402016-11-15 13:00:50 -0800339 if ((param2 < 0 && param2 != PRESET_CUSTOM) ||
340 param2 >= equalizer_get_num_presets(eq_ctxt)) {
341 p->status = -EINVAL;
342 if (param2 < 0) {
343 android_errorWriteLog(0x534e4554, "32588016");
344 ALOGW("\tERROR EQ_PARAM_GET_PRESET_NAME preset %d", param2);
345 }
346 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800347 }
348 name = (char *)value;
349 strlcpy(name, equalizer_get_preset_name(eq_ctxt, param2), p->vsize - 1);
350 name[p->vsize - 1] = 0;
351 p->vsize = strlen(name) + 1;
352 break;
353
354 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800355 int16_t *prop = (int16_t *)value;
356 prop[0] = (int16_t)equalizer_get_preset(eq_ctxt);
357 prop[1] = (int16_t)NUM_EQ_BANDS;
358 for (i = 0; i < NUM_EQ_BANDS; i++) {
359 prop[2 + i] = (int16_t)equalizer_get_band_level(eq_ctxt, i);
360 }
361 } break;
362
Trinath Thammishetty765efd22018-08-20 13:23:24 +0530363 case EQ_PARAM_LATENCY:
364 *(uint32_t *)value = EQUALIZER_MAX_LATENCY;
365 break;
366
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800367 default:
368 p->status = -EINVAL;
369 break;
370 }
371
372 return 0;
373}
374
375int equalizer_set_parameter(effect_context_t *context, effect_param_t *p,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700376 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800377{
378 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
379 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
380 void *value = p->data + voffset;
ragod8912a62017-06-06 15:02:43 -0700381 int32_t vsize = (int32_t) p->vsize;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800382 int32_t *param_tmp = (int32_t *)p->data;
383 int32_t param = *param_tmp++;
384 int32_t preset;
385 int32_t band;
386 int32_t level;
387 int i;
388
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530389 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800390
391 p->status = 0;
392
393 switch (param) {
394 case EQ_PARAM_CUR_PRESET:
ragod8912a62017-06-06 15:02:43 -0700395 if (vsize < sizeof(int16_t)) {
396 p->status = -EINVAL;
397 break;
398 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800399 preset = (int32_t)(*(uint16_t *)value);
400
401 if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) {
402 p->status = -EINVAL;
403 break;
404 }
405 equalizer_set_preset(eq_ctxt, preset);
406 break;
407 case EQ_PARAM_BAND_LEVEL:
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 band = *param_tmp;
413 level = (int32_t)(*(int16_t *)value);
rago0b386402016-11-15 13:00:50 -0800414 if (band < 0 || band >= NUM_EQ_BANDS) {
415 p->status = -EINVAL;
416 if (band < 0) {
417 android_errorWriteLog(0x534e4554, "32585400");
418 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", band);
419 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800420 break;
421 }
422 equalizer_set_band_level(eq_ctxt, band, level);
423 break;
424 case EQ_PARAM_PROPERTIES: {
ragod8912a62017-06-06 15:02:43 -0700425 if (vsize < sizeof(int16_t)) {
426 p->status = -EINVAL;
427 break;
428 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800429 int16_t *prop = (int16_t *)value;
430 if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) {
431 p->status = -EINVAL;
432 break;
433 }
434 if (prop[0] >= 0) {
435 equalizer_set_preset(eq_ctxt, (int)prop[0]);
436 } else {
ragod8912a62017-06-06 15:02:43 -0700437 if (vsize < (2 + NUM_EQ_BANDS) * sizeof(int16_t)) {
438 android_errorWriteLog(0x534e4554, "37563371");
439 ALOGE("\tERROR EQ_PARAM_PROPERTIES valueSize %d < %d",
440 vsize, (2 + NUM_EQ_BANDS) * sizeof(int16_t));
441 p->status = -EINVAL;
442 break;
443 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800444 if ((int)prop[1] != NUM_EQ_BANDS) {
445 p->status = -EINVAL;
446 break;
447 }
448 for (i = 0; i < NUM_EQ_BANDS; i++) {
449 equalizer_set_band_level(eq_ctxt, i, (int)prop[2 + i]);
450 }
451 }
452 } break;
453 default:
454 p->status = -EINVAL;
455 break;
456 }
457
458 return 0;
459}
460
461int equalizer_set_device(effect_context_t *context, uint32_t device)
462{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530463 ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800464 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
465 eq_ctxt->device = device;
466 offload_eq_set_device(&(eq_ctxt->offload_eq), device);
467 return 0;
468}
469
470int equalizer_reset(effect_context_t *context)
471{
472 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
473
474 return 0;
475}
476
477int equalizer_init(effect_context_t *context)
478{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530479 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800480 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
481
482 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
483 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
484 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
485 context->config.inputCfg.samplingRate = 44100;
486 context->config.inputCfg.bufferProvider.getBuffer = NULL;
487 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
488 context->config.inputCfg.bufferProvider.cookie = NULL;
489 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
490 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
491 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
492 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
493 context->config.outputCfg.samplingRate = 44100;
494 context->config.outputCfg.bufferProvider.getBuffer = NULL;
495 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
496 context->config.outputCfg.bufferProvider.cookie = NULL;
497 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
498
499 set_config(context, &context->config);
500
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700501 eq_ctxt->hw_acc_fd = -1;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800502 memset(&(eq_ctxt->offload_eq), 0, sizeof(struct eq_params));
503 offload_eq_set_preset(&(eq_ctxt->offload_eq), INVALID_PRESET);
504
505 return 0;
506}
507
508int equalizer_enable(effect_context_t *context)
509{
510 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
511
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530512 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800513
514 if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
515 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true);
516 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700517 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800518 OFFLOAD_SEND_EQ_ENABLE_FLAG |
519 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700520 if (eq_ctxt->hw_acc_fd > 0)
521 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
522 OFFLOAD_SEND_EQ_ENABLE_FLAG |
523 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800524 }
525 return 0;
526}
527
528int equalizer_disable(effect_context_t *context)
529{
530 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
531
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530532 ALOGV("%s:ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800533 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
534 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false);
535 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700536 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800537 OFFLOAD_SEND_EQ_ENABLE_FLAG);
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);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800541 }
542 return 0;
543}
544
545int equalizer_start(effect_context_t *context, output_context_t *output)
546{
547 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
548
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530549 ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800550 eq_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700551 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800552 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700553 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800554 OFFLOAD_SEND_EQ_ENABLE_FLAG |
555 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700556 if (eq_ctxt->hw_acc_fd > 0)
557 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
558 OFFLOAD_SEND_EQ_ENABLE_FLAG |
559 OFFLOAD_SEND_EQ_BANDS_LEVEL);
560 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800561 return 0;
562}
563
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700564int equalizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800565{
566 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
567
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530568 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700569 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)) &&
570 eq_ctxt->ctl) {
571 struct eq_params eq;
572 eq.enable_flag = false;
573 offload_eq_send_params(eq_ctxt->ctl, &eq, OFFLOAD_SEND_EQ_ENABLE_FLAG);
574 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800575 eq_ctxt->ctl = NULL;
576 return 0;
577}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700578
579int equalizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
580{
581 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
582
583 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
584 eq_ctxt->hw_acc_fd = hw_acc_fd;
585 if ((eq_ctxt->hw_acc_fd > 0) &&
586 (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))))
587 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
588 OFFLOAD_SEND_EQ_ENABLE_FLAG |
589 OFFLOAD_SEND_EQ_BANDS_LEVEL);
590 return 0;
591}