blob: 3660e84c77ab73b7b2987c0790547c1c6176acc0 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -07002 * Copyright (c) 2013-2014, 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,
37 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_HW_ACC_TUNNEL),
38 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,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800199 sizeof(equalizer_preset_names)/sizeof(char *));
200 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;
277 if (param2 >= NUM_EQ_BANDS) {
278 p->status = -EINVAL;
279 break;
280 }
281 *(int16_t *)value = (int16_t)equalizer_get_band_level(eq_ctxt, param2);
282 break;
283
284 case EQ_PARAM_CENTER_FREQ:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800285 param2 = *param_tmp;
286 if (param2 >= NUM_EQ_BANDS) {
287 p->status = -EINVAL;
288 break;
289 }
290 *(int32_t *)value = equalizer_get_center_frequency(eq_ctxt, param2);
291 break;
292
293 case EQ_PARAM_BAND_FREQ_RANGE:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800294 param2 = *param_tmp;
295 if (param2 >= NUM_EQ_BANDS) {
296 p->status = -EINVAL;
297 break;
298 }
299 equalizer_get_band_freq_range(eq_ctxt, param2, (uint32_t *)value,
300 ((uint32_t *)value + 1));
301 break;
302
303 case EQ_PARAM_GET_BAND:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800304 param2 = *param_tmp;
305 *(uint16_t *)value = (uint16_t)equalizer_get_band(eq_ctxt, param2);
306 break;
307
308 case EQ_PARAM_CUR_PRESET:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800309 *(uint16_t *)value = (uint16_t)equalizer_get_preset(eq_ctxt);
310 break;
311
312 case EQ_PARAM_GET_NUM_OF_PRESETS:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800313 *(uint16_t *)value = (uint16_t)equalizer_get_num_presets(eq_ctxt);
314 break;
315
316 case EQ_PARAM_GET_PRESET_NAME:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800317 param2 = *param_tmp;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530318 ALOGV("%s: EQ_PARAM_GET_PRESET_NAME: param2: %d", __func__, param2);
rago0b386402016-11-15 13:00:50 -0800319 if ((param2 < 0 && param2 != PRESET_CUSTOM) ||
320 param2 >= equalizer_get_num_presets(eq_ctxt)) {
321 p->status = -EINVAL;
322 if (param2 < 0) {
323 android_errorWriteLog(0x534e4554, "32588016");
324 ALOGW("\tERROR EQ_PARAM_GET_PRESET_NAME preset %d", param2);
325 }
326 break;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800327 }
328 name = (char *)value;
329 strlcpy(name, equalizer_get_preset_name(eq_ctxt, param2), p->vsize - 1);
330 name[p->vsize - 1] = 0;
331 p->vsize = strlen(name) + 1;
332 break;
333
334 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800335 int16_t *prop = (int16_t *)value;
336 prop[0] = (int16_t)equalizer_get_preset(eq_ctxt);
337 prop[1] = (int16_t)NUM_EQ_BANDS;
338 for (i = 0; i < NUM_EQ_BANDS; i++) {
339 prop[2 + i] = (int16_t)equalizer_get_band_level(eq_ctxt, i);
340 }
341 } break;
342
343 default:
344 p->status = -EINVAL;
345 break;
346 }
347
348 return 0;
349}
350
351int equalizer_set_parameter(effect_context_t *context, effect_param_t *p,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700352 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800353{
354 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
355 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
356 void *value = p->data + voffset;
357 int32_t *param_tmp = (int32_t *)p->data;
358 int32_t param = *param_tmp++;
359 int32_t preset;
360 int32_t band;
361 int32_t level;
362 int i;
363
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530364 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800365
366 p->status = 0;
367
368 switch (param) {
369 case EQ_PARAM_CUR_PRESET:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800370 preset = (int32_t)(*(uint16_t *)value);
371
372 if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) {
373 p->status = -EINVAL;
374 break;
375 }
376 equalizer_set_preset(eq_ctxt, preset);
377 break;
378 case EQ_PARAM_BAND_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800379 band = *param_tmp;
380 level = (int32_t)(*(int16_t *)value);
rago0b386402016-11-15 13:00:50 -0800381 if (band < 0 || band >= NUM_EQ_BANDS) {
382 p->status = -EINVAL;
383 if (band < 0) {
384 android_errorWriteLog(0x534e4554, "32585400");
385 ALOGW("\tERROR EQ_PARAM_BAND_LEVEL band %d", band);
386 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800387 break;
388 }
389 equalizer_set_band_level(eq_ctxt, band, level);
390 break;
391 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800392 int16_t *prop = (int16_t *)value;
393 if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) {
394 p->status = -EINVAL;
395 break;
396 }
397 if (prop[0] >= 0) {
398 equalizer_set_preset(eq_ctxt, (int)prop[0]);
399 } else {
400 if ((int)prop[1] != NUM_EQ_BANDS) {
401 p->status = -EINVAL;
402 break;
403 }
404 for (i = 0; i < NUM_EQ_BANDS; i++) {
405 equalizer_set_band_level(eq_ctxt, i, (int)prop[2 + i]);
406 }
407 }
408 } break;
409 default:
410 p->status = -EINVAL;
411 break;
412 }
413
414 return 0;
415}
416
417int equalizer_set_device(effect_context_t *context, uint32_t device)
418{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530419 ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800420 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
421 eq_ctxt->device = device;
422 offload_eq_set_device(&(eq_ctxt->offload_eq), device);
423 return 0;
424}
425
426int equalizer_reset(effect_context_t *context)
427{
428 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
429
430 return 0;
431}
432
433int equalizer_init(effect_context_t *context)
434{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530435 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800436 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
437
438 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
439 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
440 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
441 context->config.inputCfg.samplingRate = 44100;
442 context->config.inputCfg.bufferProvider.getBuffer = NULL;
443 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
444 context->config.inputCfg.bufferProvider.cookie = NULL;
445 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
446 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
447 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
448 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
449 context->config.outputCfg.samplingRate = 44100;
450 context->config.outputCfg.bufferProvider.getBuffer = NULL;
451 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
452 context->config.outputCfg.bufferProvider.cookie = NULL;
453 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
454
455 set_config(context, &context->config);
456
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700457 eq_ctxt->hw_acc_fd = -1;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800458 memset(&(eq_ctxt->offload_eq), 0, sizeof(struct eq_params));
459 offload_eq_set_preset(&(eq_ctxt->offload_eq), INVALID_PRESET);
460
461 return 0;
462}
463
464int equalizer_enable(effect_context_t *context)
465{
466 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
467
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530468 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800469
470 if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
471 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true);
472 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700473 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800474 OFFLOAD_SEND_EQ_ENABLE_FLAG |
475 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700476 if (eq_ctxt->hw_acc_fd > 0)
477 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
478 OFFLOAD_SEND_EQ_ENABLE_FLAG |
479 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800480 }
481 return 0;
482}
483
484int equalizer_disable(effect_context_t *context)
485{
486 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
487
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530488 ALOGV("%s:ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800489 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
490 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false);
491 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700492 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800493 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700494 if (eq_ctxt->hw_acc_fd > 0)
495 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
496 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800497 }
498 return 0;
499}
500
501int equalizer_start(effect_context_t *context, output_context_t *output)
502{
503 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
504
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530505 ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800506 eq_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700507 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800508 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700509 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800510 OFFLOAD_SEND_EQ_ENABLE_FLAG |
511 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700512 if (eq_ctxt->hw_acc_fd > 0)
513 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
514 OFFLOAD_SEND_EQ_ENABLE_FLAG |
515 OFFLOAD_SEND_EQ_BANDS_LEVEL);
516 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800517 return 0;
518}
519
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700520int equalizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800521{
522 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
523
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530524 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700525 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)) &&
526 eq_ctxt->ctl) {
527 struct eq_params eq;
528 eq.enable_flag = false;
529 offload_eq_send_params(eq_ctxt->ctl, &eq, OFFLOAD_SEND_EQ_ENABLE_FLAG);
530 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800531 eq_ctxt->ctl = NULL;
532 return 0;
533}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700534
535int equalizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
536{
537 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
538
539 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
540 eq_ctxt->hw_acc_fd = hw_acc_fd;
541 if ((eq_ctxt->hw_acc_fd > 0) &&
542 (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))))
543 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
544 OFFLOAD_SEND_EQ_ENABLE_FLAG |
545 OFFLOAD_SEND_EQ_BANDS_LEVEL);
546 return 0;
547}