blob: c2ae326e27180a5f8d0754ba172bb925f8455ab9 [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);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800319 if (param2 >= equalizer_get_num_presets(eq_ctxt)) {
320 p->status = -EINVAL;
321 break;
322 }
323 name = (char *)value;
324 strlcpy(name, equalizer_get_preset_name(eq_ctxt, param2), p->vsize - 1);
325 name[p->vsize - 1] = 0;
326 p->vsize = strlen(name) + 1;
327 break;
328
329 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800330 int16_t *prop = (int16_t *)value;
331 prop[0] = (int16_t)equalizer_get_preset(eq_ctxt);
332 prop[1] = (int16_t)NUM_EQ_BANDS;
333 for (i = 0; i < NUM_EQ_BANDS; i++) {
334 prop[2 + i] = (int16_t)equalizer_get_band_level(eq_ctxt, i);
335 }
336 } break;
337
338 default:
339 p->status = -EINVAL;
340 break;
341 }
342
343 return 0;
344}
345
346int equalizer_set_parameter(effect_context_t *context, effect_param_t *p,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700347 uint32_t size __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800348{
349 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
350 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
351 void *value = p->data + voffset;
352 int32_t *param_tmp = (int32_t *)p->data;
353 int32_t param = *param_tmp++;
354 int32_t preset;
355 int32_t band;
356 int32_t level;
357 int i;
358
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530359 ALOGV("%s: ctxt %p, param %d", __func__, eq_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800360
361 p->status = 0;
362
363 switch (param) {
364 case EQ_PARAM_CUR_PRESET:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800365 preset = (int32_t)(*(uint16_t *)value);
366
367 if ((preset >= equalizer_get_num_presets(eq_ctxt)) || (preset < 0)) {
368 p->status = -EINVAL;
369 break;
370 }
371 equalizer_set_preset(eq_ctxt, preset);
372 break;
373 case EQ_PARAM_BAND_LEVEL:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800374 band = *param_tmp;
375 level = (int32_t)(*(int16_t *)value);
376 if (band >= NUM_EQ_BANDS) {
377 p->status = -EINVAL;
378 break;
379 }
380 equalizer_set_band_level(eq_ctxt, band, level);
381 break;
382 case EQ_PARAM_PROPERTIES: {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800383 int16_t *prop = (int16_t *)value;
384 if ((int)prop[0] >= equalizer_get_num_presets(eq_ctxt)) {
385 p->status = -EINVAL;
386 break;
387 }
388 if (prop[0] >= 0) {
389 equalizer_set_preset(eq_ctxt, (int)prop[0]);
390 } else {
391 if ((int)prop[1] != NUM_EQ_BANDS) {
392 p->status = -EINVAL;
393 break;
394 }
395 for (i = 0; i < NUM_EQ_BANDS; i++) {
396 equalizer_set_band_level(eq_ctxt, i, (int)prop[2 + i]);
397 }
398 }
399 } break;
400 default:
401 p->status = -EINVAL;
402 break;
403 }
404
405 return 0;
406}
407
408int equalizer_set_device(effect_context_t *context, uint32_t device)
409{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530410 ALOGV("%s: ctxt %p, device: 0x%x", __func__, context, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800411 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
412 eq_ctxt->device = device;
413 offload_eq_set_device(&(eq_ctxt->offload_eq), device);
414 return 0;
415}
416
417int equalizer_reset(effect_context_t *context)
418{
419 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
420
421 return 0;
422}
423
424int equalizer_init(effect_context_t *context)
425{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530426 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800427 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
428
429 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
430 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
431 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
432 context->config.inputCfg.samplingRate = 44100;
433 context->config.inputCfg.bufferProvider.getBuffer = NULL;
434 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
435 context->config.inputCfg.bufferProvider.cookie = NULL;
436 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
437 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
438 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
439 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
440 context->config.outputCfg.samplingRate = 44100;
441 context->config.outputCfg.bufferProvider.getBuffer = NULL;
442 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
443 context->config.outputCfg.bufferProvider.cookie = NULL;
444 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
445
446 set_config(context, &context->config);
447
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700448 eq_ctxt->hw_acc_fd = -1;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800449 memset(&(eq_ctxt->offload_eq), 0, sizeof(struct eq_params));
450 offload_eq_set_preset(&(eq_ctxt->offload_eq), INVALID_PRESET);
451
452 return 0;
453}
454
455int equalizer_enable(effect_context_t *context)
456{
457 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
458
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530459 ALOGV("%s: ctxt %p", __func__, context);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800460
461 if (!offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
462 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), true);
463 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700464 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800465 OFFLOAD_SEND_EQ_ENABLE_FLAG |
466 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700467 if (eq_ctxt->hw_acc_fd > 0)
468 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
469 OFFLOAD_SEND_EQ_ENABLE_FLAG |
470 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800471 }
472 return 0;
473}
474
475int equalizer_disable(effect_context_t *context)
476{
477 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
478
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530479 ALOGV("%s:ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800480 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
481 offload_eq_set_enable_flag(&(eq_ctxt->offload_eq), false);
482 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700483 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800484 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700485 if (eq_ctxt->hw_acc_fd > 0)
486 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
487 OFFLOAD_SEND_EQ_ENABLE_FLAG);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800488 }
489 return 0;
490}
491
492int equalizer_start(effect_context_t *context, output_context_t *output)
493{
494 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
495
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530496 ALOGV("%s: ctxt %p, ctl %p", __func__, eq_ctxt, output->ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800497 eq_ctxt->ctl = output->ctl;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700498 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))) {
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800499 if (eq_ctxt->ctl)
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700500 offload_eq_send_params(eq_ctxt->ctl, &eq_ctxt->offload_eq,
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800501 OFFLOAD_SEND_EQ_ENABLE_FLAG |
502 OFFLOAD_SEND_EQ_BANDS_LEVEL);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700503 if (eq_ctxt->hw_acc_fd > 0)
504 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
505 OFFLOAD_SEND_EQ_ENABLE_FLAG |
506 OFFLOAD_SEND_EQ_BANDS_LEVEL);
507 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800508 return 0;
509}
510
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700511int equalizer_stop(effect_context_t *context, output_context_t *output __unused)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800512{
513 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
514
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530515 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700516 if (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq)) &&
517 eq_ctxt->ctl) {
518 struct eq_params eq;
519 eq.enable_flag = false;
520 offload_eq_send_params(eq_ctxt->ctl, &eq, OFFLOAD_SEND_EQ_ENABLE_FLAG);
521 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800522 eq_ctxt->ctl = NULL;
523 return 0;
524}
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700525
526int equalizer_set_mode(effect_context_t *context, int32_t hw_acc_fd)
527{
528 equalizer_context_t *eq_ctxt = (equalizer_context_t *)context;
529
530 ALOGV("%s: ctxt %p", __func__, eq_ctxt);
531 eq_ctxt->hw_acc_fd = hw_acc_fd;
532 if ((eq_ctxt->hw_acc_fd > 0) &&
533 (offload_eq_get_enable_flag(&(eq_ctxt->offload_eq))))
534 hw_acc_eq_send_params(eq_ctxt->hw_acc_fd, &eq_ctxt->offload_eq,
535 OFFLOAD_SEND_EQ_ENABLE_FLAG |
536 OFFLOAD_SEND_EQ_BANDS_LEVEL);
537 return 0;
538}