blob: 45f8eb845ff97a656c0d4ecbe43a53ac52da23e8 [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
44static const char *equalizer_preset_names[] = {
45 "Normal",
46 "Classical",
47 "Dance",
48 "Flat",
49 "Folk",
50 "Heavy Metal",
51 "Hip Hop",
52 "Jazz",
53 "Pop",
54 "Rock"
wjiang1eae6252014-07-19 21:46:46 +080055};
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080056
57static const uint32_t equalizer_band_freq_range[NUM_EQ_BANDS][2] = {
58 {30000, 120000},
59 {120001, 460000},
60 {460001, 1800000},
61 {1800001, 7000000},
62 {7000001, 20000000}};
63
wjiang1eae6252014-07-19 21:46:46 +080064static const int16_t equalizer_band_presets_level[] = {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080065 3, 0, 0, 0, 3, /* Normal Preset */
66 5, 3, -2, 4, 4, /* Classical Preset */
67 6, 0, 2, 4, 1, /* Dance Preset */
68 0, 0, 0, 0, 0, /* Flat Preset */
69 3, 0, 0, 2, -1, /* Folk Preset */
70 4, 1, 9, 3, 0, /* Heavy Metal Preset */
71 5, 3, 0, 1, 3, /* Hip Hop Preset */
72 4, 2, -2, 2, 5, /* Jazz Preset */
73 -1, 2, 5, 1, -2, /* Pop Preset */
74 5, 3, -1, 3, 5}; /* Rock Preset */
75
76const uint16_t equalizer_band_presets_freq[NUM_EQ_BANDS] = {
77 60, /* Frequencies in Hz */
78 230,
79 910,
80 3600,
81 14000
82};
83
84/*
85 * Equalizer operations
86 */
87
88int equalizer_get_band_level(equalizer_context_t *context, int32_t band)
89{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053090 ALOGV("%s: ctxt %p, band: %d level: %d", __func__, context, band,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080091 context->band_levels[band] * 100);
92 return context->band_levels[band] * 100;
93}
94
95int equalizer_set_band_level(equalizer_context_t *context, int32_t band,
96 int32_t level)
97{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053098 ALOGV("%s: ctxt %p, band: %d, level: %d", __func__, context, band, level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080099 if (level > 0) {
100 level = (int)((level+50)/100);
101 } else {
102 level = (int)((level-50)/100);
103 }
104 context->band_levels[band] = level;
105 context->preset = PRESET_CUSTOM;
106
107 offload_eq_set_preset(&(context->offload_eq), PRESET_CUSTOM);
108 offload_eq_set_bands_level(&(context->offload_eq),
109 NUM_EQ_BANDS,
110 equalizer_band_presets_freq,
111 context->band_levels);
112 if (context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700113 offload_eq_send_params(context->ctl, &context->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800114 OFFLOAD_SEND_EQ_ENABLE_FLAG |
115 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700116 if (context->hw_acc_fd > 0)
117 hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq,
118 OFFLOAD_SEND_EQ_ENABLE_FLAG |
119 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800120 return 0;
121}
122
123int equalizer_get_center_frequency(equalizer_context_t *context, int32_t band)
124{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530125 ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800126 return (equalizer_band_freq_range[band][0] +
127 equalizer_band_freq_range[band][1]) / 2;
128}
129
130int equalizer_get_band_freq_range(equalizer_context_t *context, int32_t band,
131 uint32_t *low, uint32_t *high)
132{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530133 ALOGV("%s: ctxt %p, band: %d", __func__, context, band);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800134 *low = equalizer_band_freq_range[band][0];
135 *high = equalizer_band_freq_range[band][1];
136 return 0;
137}
138
139int equalizer_get_band(equalizer_context_t *context, uint32_t freq)
140{
141 int i;
142
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530143 ALOGV("%s: ctxt %p, freq: %d", __func__, context, freq);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800144 for(i = 0; i < NUM_EQ_BANDS; i++) {
145 if (freq <= equalizer_band_freq_range[i][1]) {
146 return i;
147 }
148 }
149 return NUM_EQ_BANDS - 1;
150}
151
152int equalizer_get_preset(equalizer_context_t *context)
153{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530154 ALOGV("%s: ctxt %p, preset: %d", __func__, context, context->preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800155 return context->preset;
156}
157
158int equalizer_set_preset(equalizer_context_t *context, int preset)
159{
160 int i;
161
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530162 ALOGV("%s: ctxt %p, preset: %d", __func__, context, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800163 context->preset = preset;
164 for (i=0; i<NUM_EQ_BANDS; i++)
165 context->band_levels[i] =
166 equalizer_band_presets_level[i + preset * NUM_EQ_BANDS];
167
168 offload_eq_set_preset(&(context->offload_eq), preset);
169 offload_eq_set_bands_level(&(context->offload_eq),
170 NUM_EQ_BANDS,
171 equalizer_band_presets_freq,
172 context->band_levels);
173 if(context->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700174 offload_eq_send_params(context->ctl, &context->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800175 OFFLOAD_SEND_EQ_ENABLE_FLAG |
176 OFFLOAD_SEND_EQ_PRESET);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700177 if(context->hw_acc_fd > 0)
178 hw_acc_eq_send_params(context->hw_acc_fd, &context->offload_eq,
179 OFFLOAD_SEND_EQ_ENABLE_FLAG |
180 OFFLOAD_SEND_EQ_PRESET);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800181 return 0;
182}
183
184const char * equalizer_get_preset_name(equalizer_context_t *context,
185 int32_t preset)
186{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530187 ALOGV("%s: ctxt %p, preset: %s", __func__, context,
188 equalizer_preset_names[preset]);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800189 if (preset == PRESET_CUSTOM) {
190 return "Custom";
191 } else {
192 return equalizer_preset_names[preset];
193 }
194}
195
196int equalizer_get_num_presets(equalizer_context_t *context)
197{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530198 ALOGV("%s: ctxt %p, presets_num: %d", __func__, context,
Weiyin Jiang90ac1ea2017-04-13 14:18:23 +0800199 (int)(sizeof(equalizer_preset_names)/sizeof(char *)));
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800200 return sizeof(equalizer_preset_names)/sizeof(char *);
201}
202
203int equalizer_get_parameter(effect_context_t *context, effect_param_t *p,
204 uint32_t *size)
205{
206 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
207 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
208 int32_t *param_tmp = (int32_t *)p->data;
209 int32_t param = *param_tmp++;
210 int32_t param2;
211 char *name;
212 void *value = p->data + voffset;
213 int i;
214
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530215 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800216
217 p->status = 0;
218
219 switch (param) {
220 case EQ_PARAM_NUM_BANDS:
221 case EQ_PARAM_CUR_PRESET:
222 case EQ_PARAM_GET_NUM_OF_PRESETS:
223 case EQ_PARAM_BAND_LEVEL:
224 case EQ_PARAM_GET_BAND:
225 if (p->vsize < sizeof(int16_t))
226 p->status = -EINVAL;
227 p->vsize = sizeof(int16_t);
228 break;
229
230 case EQ_PARAM_LEVEL_RANGE:
231 if (p->vsize < 2 * sizeof(int16_t))
232 p->status = -EINVAL;
233 p->vsize = 2 * sizeof(int16_t);
234 break;
235 case EQ_PARAM_BAND_FREQ_RANGE:
236 if (p->vsize < 2 * sizeof(int32_t))
237 p->status = -EINVAL;
238 p->vsize = 2 * sizeof(int32_t);
239 break;
240
241 case EQ_PARAM_CENTER_FREQ:
242 if (p->vsize < sizeof(int32_t))
243 p->status = -EINVAL;
244 p->vsize = sizeof(int32_t);
245 break;
246
247 case EQ_PARAM_GET_PRESET_NAME:
248 break;
249
250 case EQ_PARAM_PROPERTIES:
251 if (p->vsize < (2 + NUM_EQ_BANDS) * sizeof(uint16_t))
252 p->status = -EINVAL;
253 p->vsize = (2 + NUM_EQ_BANDS) * sizeof(uint16_t);
254 break;
255
256 default:
257 p->status = -EINVAL;
258 }
259
260 *size = sizeof(effect_param_t) + voffset + p->vsize;
261
262 if (p->status != 0)
263 return 0;
264
265 switch (param) {
266 case EQ_PARAM_NUM_BANDS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800267 *(uint16_t *)value = (uint16_t)NUM_EQ_BANDS;
268 break;
269
270 case EQ_PARAM_LEVEL_RANGE:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800271 *(int16_t *)value = -1500;
272 *((int16_t *)value + 1) = 1500;
273 break;
274
275 case EQ_PARAM_BAND_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800276 param2 = *param_tmp;
rago3ef61e22016-10-31 12:42:15 -0700277 if (param2 < 0 || param2 >= NUM_EQ_BANDS) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800278 p->status = -EINVAL;
rago3ef61e22016-10-31 12:42:15 -0700279 if (param2 < 0) {
280 android_errorWriteLog(0x534e4554, "32438598");
281 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", param2);
282 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800283 break;
284 }
285 *(int16_t *)value = (int16_t)equalizer_get_band_level(eq_ctxt, param2);
286 break;
287
288 case EQ_PARAM_CENTER_FREQ:
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) {
291 p->status = -EINVAL;
292 if (param2 < 0) {
293 android_errorWriteLog(0x534e4554, "32436341");
294 ALOGW("\tERROR EQ_PARAM_CENTER_FREQ band %d", param2);
295 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800296 break;
297 }
298 *(int32_t *)value = equalizer_get_center_frequency(eq_ctxt, param2);
299 break;
300
301 case EQ_PARAM_BAND_FREQ_RANGE:
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) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800304 p->status = -EINVAL;
rago3ef61e22016-10-31 12:42:15 -0700305 if (param2 < 0) {
306 android_errorWriteLog(0x534e4554, "32247948");
307 ALOGW("\tERROR EQ_PARAM_BAND_FREQ_RANGE band %d", param2);
308 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800309 break;
310 }
311 equalizer_get_band_freq_range(eq_ctxt, param2, (uint32_t *)value,
312 ((uint32_t *)value + 1));
313 break;
314
315 case EQ_PARAM_GET_BAND:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800316 param2 = *param_tmp;
317 *(uint16_t *)value = (uint16_t)equalizer_get_band(eq_ctxt, param2);
318 break;
319
320 case EQ_PARAM_CUR_PRESET:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800321 *(uint16_t *)value = (uint16_t)equalizer_get_preset(eq_ctxt);
322 break;
323
324 case EQ_PARAM_GET_NUM_OF_PRESETS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800325 *(uint16_t *)value = (uint16_t)equalizer_get_num_presets(eq_ctxt);
326 break;
327
328 case EQ_PARAM_GET_PRESET_NAME:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800329 param2 = *param_tmp;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530330 ALOGV("%s: EQ_PARAM_GET_PRESET_NAME: param2: %d", __func__, param2);
rago0b386402016-11-15 13:00:50 -0800331 if ((param2 < 0 && param2 != PRESET_CUSTOM) ||
332 param2 >= equalizer_get_num_presets(eq_ctxt)) {
333 p->status = -EINVAL;
334 if (param2 < 0) {
335 android_errorWriteLog(0x534e4554, "32588016");
336 ALOGW("\tERROR EQ_PARAM_GET_PRESET_NAME preset %d", param2);
337 }
338 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800339 }
340 name = (char *)value;
341 strlcpy(name, equalizer_get_preset_name(eq_ctxt, param2), p->vsize - 1);
342 name[p->vsize - 1] = 0;
343 p->vsize = strlen(name) + 1;
344 break;
345
346 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800347 int16_t *prop = (int16_t *)value;
348 prop[0] = (int16_t)equalizer_get_preset(eq_ctxt);
349 prop[1] = (int16_t)NUM_EQ_BANDS;
350 for (i = 0; i < NUM_EQ_BANDS; i++) {
351 prop[2 + i] = (int16_t)equalizer_get_band_level(eq_ctxt, i);
352 }
353 } break;
354
355 default:
356 p->status = -EINVAL;
357 break;
358 }
359
360 return 0;
361}
362
363int equalizer_set_parameter(effect_context_t *context, effect_param_t *p,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700364 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800365{
366 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
367 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
368 void *value = p->data + voffset;
369 int32_t *param_tmp = (int32_t *)p->data;
370 int32_t param = *param_tmp++;
371 int32_t preset;
372 int32_t band;
373 int32_t level;
374 int i;
375
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530376 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800377
378 p->status = 0;
379
380 switch (param) {
381 case EQ_PARAM_CUR_PRESET:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800382 preset = (int32_t)(*(uint16_t *)value);
383
384 if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) {
385 p->status = -EINVAL;
386 break;
387 }
388 equalizer_set_preset(eq_ctxt, preset);
389 break;
390 case EQ_PARAM_BAND_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800391 band = *param_tmp;
392 level = (int32_t)(*(int16_t *)value);
rago0b386402016-11-15 13:00:50 -0800393 if (band < 0 || band >= NUM_EQ_BANDS) {
394 p->status = -EINVAL;
395 if (band < 0) {
396 android_errorWriteLog(0x534e4554, "32585400");
397 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", band);
398 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800399 break;
400 }
401 equalizer_set_band_level(eq_ctxt, band, level);
402 break;
403 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800404 int16_t *prop = (int16_t *)value;
405 if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) {
406 p->status = -EINVAL;
407 break;
408 }
409 if (prop[0] >= 0) {
410 equalizer_set_preset(eq_ctxt, (int)prop[0]);
411 } else {
412 if ((int)prop[1] != NUM_EQ_BANDS) {
413 p->status = -EINVAL;
414 break;
415 }
416 for (i = 0; i < NUM_EQ_BANDS; i++) {
417 equalizer_set_band_level(eq_ctxt, i, (int)prop[2 + i]);
418 }
419 }
420 } break;
421 default:
422 p->status = -EINVAL;
423 break;
424 }
425
426 return 0;
427}
428
429int equalizer_set_device(effect_context_t *context, uint32_t device)
430{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530431 ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800432 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
433 eq_ctxt->device = device;
434 offload_eq_set_device(&(eq_ctxt->offload_eq), device);
435 return 0;
436}
437
438int equalizer_reset(effect_context_t *context)
439{
440 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
441
442 return 0;
443}
444
445int equalizer_init(effect_context_t *context)
446{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530447 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800448 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
449
450 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
451 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
452 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
453 context->config.inputCfg.samplingRate = 44100;
454 context->config.inputCfg.bufferProvider.getBuffer = NULL;
455 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
456 context->config.inputCfg.bufferProvider.cookie = NULL;
457 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
458 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
459 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
460 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
461 context->config.outputCfg.samplingRate = 44100;
462 context->config.outputCfg.bufferProvider.getBuffer = NULL;
463 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
464 context->config.outputCfg.bufferProvider.cookie = NULL;
465 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
466
467 set_config(context, &context->config);
468
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700469 eq_ctxt->hw_acc_fd = -1;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800470 memset(&(eq_ctxt->offload_eq), 0, sizeof(struct eq_params));
471 offload_eq_set_preset(&(eq_ctxt->offload_eq), INVALID_PRESET);
472
473 return 0;
474}
475
476int equalizer_enable(effect_context_t *context)
477{
478 equalizer_context_t *eq_ctxt = (equalizer_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
482 if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
483 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true);
484 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700485 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800486 OFFLOAD_SEND_EQ_ENABLE_FLAG |
487 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700488 if (eq_ctxt->hw_acc_fd > 0)
489 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
490 OFFLOAD_SEND_EQ_ENABLE_FLAG |
491 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800492 }
493 return 0;
494}
495
496int equalizer_disable(effect_context_t *context)
497{
498 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
499
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530500 ALOGV("%s:ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800501 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
502 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false);
503 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700504 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800505 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700506 if (eq_ctxt->hw_acc_fd > 0)
507 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
508 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800509 }
510 return 0;
511}
512
513int equalizer_start(effect_context_t *context, output_context_t *output)
514{
515 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
516
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530517 ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800518 eq_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700519 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800520 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700521 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800522 OFFLOAD_SEND_EQ_ENABLE_FLAG |
523 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700524 if (eq_ctxt->hw_acc_fd > 0)
525 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
526 OFFLOAD_SEND_EQ_ENABLE_FLAG |
527 OFFLOAD_SEND_EQ_BANDS_LEVEL);
528 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800529 return 0;
530}
531
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700532int equalizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800533{
534 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
535
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530536 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700537 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)) &&
538 eq_ctxt->ctl) {
539 struct eq_params eq;
540 eq.enable_flag = false;
541 offload_eq_send_params(eq_ctxt->ctl, &eq, OFFLOAD_SEND_EQ_ENABLE_FLAG);
542 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800543 eq_ctxt->ctl = NULL;
544 return 0;
545}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700546
547int equalizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
548{
549 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
550
551 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
552 eq_ctxt->hw_acc_fd = hw_acc_fd;
553 if ((eq_ctxt->hw_acc_fd > 0) &&
554 (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))))
555 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
556 OFFLOAD_SEND_EQ_ENABLE_FLAG |
557 OFFLOAD_SEND_EQ_BANDS_LEVEL);
558 return 0;
559}