blob: 2fb79ed0c687917caf17c2b1c681ca65d9896b9d [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +08002 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08003
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080028 *
29 * This file was modified by DTS, Inc. The portions of the
30 * code modified by DTS, Inc are copyrighted and
31 * licensed separately, as follows:
32 *
33 * (C) 2014 DTS, Inc.
34 *
35 * Licensed under the Apache License, Version 2.0 (the "License");
36 * you may not use this file except in compliance with the License.
37 * You may obtain a copy of the License at
38 *
39 * http://www.apache.org/licenses/LICENSE-2.0
40 *
41 * Unless required by applicable law or agreed to in writing, software
42 * distributed under the License is distributed on an "AS IS" BASIS,
43 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44 * See the License for the specific language governing permissions and
45 * limitations under the License.
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080046 */
47
48#define LOG_TAG "offload_effect_api"
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070049//#define LOG_NDEBUG 0
Dhananjay Kumar574f3922014-03-25 17:41:44 +053050//#define VERY_VERY_VERBOSE_LOGGING
51#ifdef VERY_VERY_VERBOSE_LOGGING
52#define ALOGVV ALOGV
53#else
54#define ALOGVV(a...) do { } while(0)
55#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080056
57#include <stdbool.h>
58#include <cutils/log.h>
59#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080060#include <sound/audio_effects.h>
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080061#include <sound/devdep_params.h>
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070062#include <linux/msm_audio.h>
63
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080064#include "effect_api.h"
65
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080066#ifdef DTS_EAGLE
67#include "effect_util.h"
68#endif
69
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080070#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070071typedef enum eff_mode {
72 OFFLOAD,
73 HW_ACCELERATOR
74} eff_mode_t;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080075
76#define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19
77const int map_eq_opensl_preset_2_offload_preset[] = {
78 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */
79 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */
80 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */
81 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */
82 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */
83 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */
84 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */
85 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */
86 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */
87 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */
88 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */
89};
90
91const int map_reverb_opensl_preset_2_offload_preset
92 [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = {
93 {1, 15},
94 {2, 16},
95 {3, 17},
96 {4, 18},
97 {5, 3},
98 {6, 20}
99};
100
101int offload_update_mixer_and_effects_ctl(int card, int device_id,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700102 struct mixer **mixer,
103 struct mixer_ctl **ctl)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800104{
105 char mixer_string[128];
106
107 snprintf(mixer_string, sizeof(mixer_string),
108 "%s %d", "Audio Effects Config", device_id);
109 ALOGV("%s: mixer_string: %s", __func__, mixer_string);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700110 *mixer = mixer_open(card);
111 if (!(*mixer)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800112 ALOGE("Failed to open mixer");
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800113 *ctl = NULL;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800114 return -EINVAL;
115 } else {
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700116 *ctl = mixer_get_ctl_by_name(*mixer, mixer_string);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800117 if (!*ctl) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800118 ALOGE("mixer_get_ctl_by_name failed");
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700119 mixer_close(*mixer);
120 *mixer = NULL;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800121 return -EINVAL;
122 }
123 }
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700124 ALOGV("mixer: %p, ctl: %p", *mixer, *ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800125 return 0;
126}
127
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700128void offload_close_mixer(struct mixer **mixer)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800129{
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700130 mixer_close(*mixer);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800131}
132
133void offload_bassboost_set_device(struct bass_boost_params *bassboost,
134 uint32_t device)
135{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530136 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800137 bassboost->device = device;
138}
139
140void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
141 bool enable)
142{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530143 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800144 bassboost->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800145
146#ifdef DTS_EAGLE
147 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
148#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800149}
150
151int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
152{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530153 ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800154 return bassboost->enable_flag;
155}
156
157void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
158 int strength)
159{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530160 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800161 bassboost->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800162
163#ifdef DTS_EAGLE
164 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
165#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800166}
167
168void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
169 int mode)
170{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530171 ALOGVV("%s: mode %d", __func__, mode);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800172 bassboost->mode = mode;
173}
174
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700175static int bassboost_send_params(eff_mode_t mode, void *ctl,
176 struct bass_boost_params *bassboost,
177 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800178{
179 int param_values[128] = {0};
180 int *p_param_values = param_values;
181
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530182 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800183 *p_param_values++ = BASS_BOOST_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700184 *p_param_values++ = bassboost->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800185 *p_param_values++ = 0; /* num of commands*/
186 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
187 *p_param_values++ = BASS_BOOST_ENABLE;
188 *p_param_values++ = CONFIG_SET;
189 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
190 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700191 *p_param_values++ = bassboost->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800192 param_values[2] += 1;
193 }
194 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
195 *p_param_values++ = BASS_BOOST_STRENGTH;
196 *p_param_values++ = CONFIG_SET;
197 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
198 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700199 *p_param_values++ = bassboost->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800200 param_values[2] += 1;
201 }
202 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
203 *p_param_values++ = BASS_BOOST_MODE;
204 *p_param_values++ = CONFIG_SET;
205 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
206 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700207 *p_param_values++ = bassboost->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800208 param_values[2] += 1;
209 }
210
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700211 if ((mode == OFFLOAD) && param_values[2] && ctl) {
212 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
213 ARRAY_SIZE(param_values));
214 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
215 ctl && *(int *)ctl) {
216 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
217 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
218 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800219
220 return 0;
221}
222
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700223int offload_bassboost_send_params(struct mixer_ctl *ctl,
224 struct bass_boost_params *bassboost,
225 unsigned param_send_flags)
226{
227 return bassboost_send_params(OFFLOAD, (void *)ctl, bassboost,
228 param_send_flags);
229}
230
231int hw_acc_bassboost_send_params(int fd, struct bass_boost_params *bassboost,
232 unsigned param_send_flags)
233{
234 return bassboost_send_params(HW_ACCELERATOR, (void *)&fd,
235 bassboost, param_send_flags);
236}
237
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800238void offload_pbe_set_device(struct pbe_params *pbe,
239 uint32_t device)
240{
241 ALOGV("%s: device=%d", __func__, device);
242 pbe->device = device;
243}
244
245void offload_pbe_set_enable_flag(struct pbe_params *pbe,
246 bool enable)
247{
248 ALOGV("%s: enable=%d", __func__, enable);
249 pbe->enable_flag = enable;
250}
251
252int offload_pbe_get_enable_flag(struct pbe_params *pbe)
253{
254 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
255 return pbe->enable_flag;
256}
257
258static int pbe_send_params(eff_mode_t mode, void *ctl,
259 struct pbe_params *pbe,
260 unsigned param_send_flags)
261{
262 int param_values[128] = {0};
263 int i, *p_param_values = param_values, *cfg = NULL;
264
265 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
266 *p_param_values++ = PBE_MODULE;
267 *p_param_values++ = pbe->device;
268 *p_param_values++ = 0; /* num of commands*/
269 if (param_send_flags & OFFLOAD_SEND_PBE_ENABLE_FLAG) {
270 *p_param_values++ = PBE_ENABLE;
271 *p_param_values++ = CONFIG_SET;
272 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
273 *p_param_values++ = PBE_ENABLE_PARAM_LEN;
274 *p_param_values++ = pbe->enable_flag;
275 param_values[2] += 1;
276 }
277 if (param_send_flags & OFFLOAD_SEND_PBE_CONFIG) {
278 *p_param_values++ = PBE_CONFIG;
279 *p_param_values++ = CONFIG_SET;
280 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
281 *p_param_values++ = pbe->cfg_len;
282 cfg = (int *)&pbe->config;
283 for (i = 0; i < (int)pbe->cfg_len ; i+= sizeof(*p_param_values))
284 *p_param_values++ = *cfg++;
285 param_values[2] += 1;
286 }
287
288 if ((mode == OFFLOAD) && param_values[2] && ctl) {
289 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
290 ARRAY_SIZE(param_values));
291 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
292 ctl && *(int *)ctl) {
293 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
294 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
295 }
296
297 return 0;
298}
299
300int offload_pbe_send_params(struct mixer_ctl *ctl,
301 struct pbe_params *pbe,
302 unsigned param_send_flags)
303{
304 return pbe_send_params(OFFLOAD, (void *)ctl, pbe,
305 param_send_flags);
306}
307
308int hw_acc_pbe_send_params(int fd, struct pbe_params *pbe,
309 unsigned param_send_flags)
310{
311 return pbe_send_params(HW_ACCELERATOR, (void *)&fd,
312 pbe, param_send_flags);
313}
314
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800315void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
316 uint32_t device)
317{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530318 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800319 virtualizer->device = device;
320}
321
322void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
323 bool enable)
324{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530325 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800326 virtualizer->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800327
328#ifdef DTS_EAGLE
329 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
330#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800331}
332
333int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
334{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530335 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800336 return virtualizer->enable_flag;
337}
338
339void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
340 int strength)
341{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530342 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800343 virtualizer->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800344
345#ifdef DTS_EAGLE
346 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
347#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800348}
349
350void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
351 int out_type)
352{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530353 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800354 virtualizer->out_type = out_type;
355}
356
357void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
358 int gain_adjust)
359{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530360 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800361 virtualizer->gain_adjust = gain_adjust;
362}
363
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700364static int virtualizer_send_params(eff_mode_t mode, void *ctl,
365 struct virtualizer_params *virtualizer,
366 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800367{
368 int param_values[128] = {0};
369 int *p_param_values = param_values;
370
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530371 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800372 *p_param_values++ = VIRTUALIZER_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700373 *p_param_values++ = virtualizer->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800374 *p_param_values++ = 0; /* num of commands*/
375 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
376 *p_param_values++ = VIRTUALIZER_ENABLE;
377 *p_param_values++ = CONFIG_SET;
378 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
379 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700380 *p_param_values++ = virtualizer->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800381 param_values[2] += 1;
382 }
383 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
384 *p_param_values++ = VIRTUALIZER_STRENGTH;
385 *p_param_values++ = CONFIG_SET;
386 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
387 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700388 *p_param_values++ = virtualizer->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800389 param_values[2] += 1;
390 }
391 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
392 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
393 *p_param_values++ = CONFIG_SET;
394 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
395 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700396 *p_param_values++ = virtualizer->out_type;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800397 param_values[2] += 1;
398 }
399 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
400 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
401 *p_param_values++ = CONFIG_SET;
402 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
403 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700404 *p_param_values++ = virtualizer->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800405 param_values[2] += 1;
406 }
407
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700408 if ((mode == OFFLOAD) && param_values[2] && ctl) {
409 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
410 ARRAY_SIZE(param_values));
411 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
412 ctl && *(int *)ctl) {
413 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
414 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
415 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800416
417 return 0;
418}
419
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700420int offload_virtualizer_send_params(struct mixer_ctl *ctl,
421 struct virtualizer_params *virtualizer,
422 unsigned param_send_flags)
423{
424 return virtualizer_send_params(OFFLOAD, (void *)ctl, virtualizer,
425 param_send_flags);
426}
427
428int hw_acc_virtualizer_send_params(int fd,
429 struct virtualizer_params *virtualizer,
430 unsigned param_send_flags)
431{
432 return virtualizer_send_params(HW_ACCELERATOR, (void *)&fd,
433 virtualizer, param_send_flags);
434}
435
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800436void offload_eq_set_device(struct eq_params *eq, uint32_t device)
437{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530438 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800439 eq->device = device;
440}
441
442void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
443{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530444 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800445 eq->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800446
447#ifdef DTS_EAGLE
448 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
449#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800450}
451
452int offload_eq_get_enable_flag(struct eq_params *eq)
453{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530454 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800455 return eq->enable_flag;
456}
457
458void offload_eq_set_preset(struct eq_params *eq, int preset)
459{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530460 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800461 eq->config.preset_id = preset;
462 eq->config.eq_pregain = Q27_UNITY;
463}
464
465void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
466 const uint16_t *band_freq_list,
467 int *band_gain_list)
468{
469 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530470 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800471 eq->config.num_bands = num_bands;
472 for (i=0; i<num_bands; i++) {
473 eq->per_band_cfg[i].band_idx = i;
474 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
475 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
476 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
477 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
478 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800479
480#ifdef DTS_EAGLE
481 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_SET_PARAM, EFFECT_NO_OP, EFFECT_NO_OP, i, band_gain_list[i] * 100);
482#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800483}
484
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700485static int eq_send_params(eff_mode_t mode, void *ctl, struct eq_params *eq,
486 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800487{
488 int param_values[128] = {0};
489 int *p_param_values = param_values;
490 uint32_t i;
491
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530492 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700493 if ((eq->config.preset_id < -1) ||
494 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq->config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800495 ALOGV("No Valid preset to set");
496 return 0;
497 }
498 *p_param_values++ = EQ_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700499 *p_param_values++ = eq->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800500 *p_param_values++ = 0; /* num of commands*/
501 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
502 *p_param_values++ = EQ_ENABLE;
503 *p_param_values++ = CONFIG_SET;
504 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
505 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700506 *p_param_values++ = eq->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800507 param_values[2] += 1;
508 }
509 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
510 *p_param_values++ = EQ_CONFIG;
511 *p_param_values++ = CONFIG_SET;
512 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
513 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700514 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800515 *p_param_values++ =
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700516 map_eq_opensl_preset_2_offload_preset[eq->config.preset_id];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800517 *p_param_values++ = 0;
518 param_values[2] += 1;
519 }
520 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
521 *p_param_values++ = EQ_CONFIG;
522 *p_param_values++ = CONFIG_SET;
523 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
524 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700525 eq->config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
526 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800527 *p_param_values++ = CUSTOM_OPENSL_PRESET;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700528 *p_param_values++ = eq->config.num_bands;
529 for (i=0; i<eq->config.num_bands; i++) {
530 *p_param_values++ = eq->per_band_cfg[i].band_idx;
531 *p_param_values++ = eq->per_band_cfg[i].filter_type;
532 *p_param_values++ = eq->per_band_cfg[i].freq_millihertz;
533 *p_param_values++ = eq->per_band_cfg[i].gain_millibels;
534 *p_param_values++ = eq->per_band_cfg[i].quality_factor;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800535 }
536 param_values[2] += 1;
537 }
538
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700539 if ((mode == OFFLOAD) && param_values[2] && ctl) {
540 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
541 ARRAY_SIZE(param_values));
542 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
543 ctl && *(int *)ctl) {
544 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
545 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
546 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800547
548 return 0;
549}
550
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700551int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params *eq,
552 unsigned param_send_flags)
553{
554 return eq_send_params(OFFLOAD, (void *)ctl, eq, param_send_flags);
555}
556
557int hw_acc_eq_send_params(int fd, struct eq_params *eq,
558 unsigned param_send_flags)
559{
560 return eq_send_params(HW_ACCELERATOR, (void *)&fd, eq,
561 param_send_flags);
562}
563
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800564void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
565{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530566 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800567 reverb->device = device;
568}
569
570void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
571{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530572 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800573 reverb->enable_flag = enable;
574}
575
576int offload_reverb_get_enable_flag(struct reverb_params *reverb)
577{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530578 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800579 return reverb->enable_flag;
580}
581
582void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
583{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530584 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800585 reverb->mode = mode;
586}
587
588void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
589{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530590 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800591 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800592 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800593}
594
595void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
596{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530597 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800598 reverb->wet_mix = wet_mix;
599}
600
601void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
602 int gain_adjust)
603{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530604 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800605 reverb->gain_adjust = gain_adjust;
606}
607
608void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
609{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530610 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800611 reverb->room_level = room_level;
612}
613
614void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
615 int room_hf_level)
616{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530617 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800618 reverb->room_hf_level = room_hf_level;
619}
620
621void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
622{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530623 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800624 reverb->decay_time = decay_time;
625}
626
627void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
628 int decay_hf_ratio)
629{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530630 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800631 reverb->decay_hf_ratio = decay_hf_ratio;
632}
633
634void offload_reverb_set_reflections_level(struct reverb_params *reverb,
635 int reflections_level)
636{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530637 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800638 reverb->reflections_level = reflections_level;
639}
640
641void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
642 int reflections_delay)
643{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530644 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800645 reverb->reflections_delay = reflections_delay;
646}
647
648void offload_reverb_set_reverb_level(struct reverb_params *reverb,
649 int reverb_level)
650{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530651 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800652 reverb->level = reverb_level;
653}
654
655void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
656{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530657 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800658 reverb->delay = delay;
659}
660
661void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
662{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530663 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800664 reverb->diffusion = diffusion;
665}
666
667void offload_reverb_set_density(struct reverb_params *reverb, int density)
668{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530669 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800670 reverb->density = density;
671}
672
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700673static int reverb_send_params(eff_mode_t mode, void *ctl,
674 struct reverb_params *reverb,
675 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800676{
677 int param_values[128] = {0};
678 int *p_param_values = param_values;
679
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530680 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800681 *p_param_values++ = REVERB_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700682 *p_param_values++ = reverb->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800683 *p_param_values++ = 0; /* num of commands*/
684
685 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
686 *p_param_values++ = REVERB_ENABLE;
687 *p_param_values++ = CONFIG_SET;
688 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
689 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700690 *p_param_values++ = reverb->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800691 param_values[2] += 1;
692 }
693 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
694 *p_param_values++ = REVERB_MODE;
695 *p_param_values++ = CONFIG_SET;
696 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
697 *p_param_values++ = REVERB_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700698 *p_param_values++ = reverb->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800699 param_values[2] += 1;
700 }
701 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
702 *p_param_values++ = REVERB_PRESET;
703 *p_param_values++ = CONFIG_SET;
704 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
705 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700706 *p_param_values++ = reverb->preset;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800707 param_values[2] += 1;
708 }
709 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
710 *p_param_values++ = REVERB_WET_MIX;
711 *p_param_values++ = CONFIG_SET;
712 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
713 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700714 *p_param_values++ = reverb->wet_mix;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800715 param_values[2] += 1;
716 }
717 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
718 *p_param_values++ = REVERB_GAIN_ADJUST;
719 *p_param_values++ = CONFIG_SET;
720 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
721 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700722 *p_param_values++ = reverb->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800723 param_values[2] += 1;
724 }
725 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
726 *p_param_values++ = REVERB_ROOM_LEVEL;
727 *p_param_values++ = CONFIG_SET;
728 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
729 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700730 *p_param_values++ = reverb->room_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800731 param_values[2] += 1;
732 }
733 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
734 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
735 *p_param_values++ = CONFIG_SET;
736 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
737 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700738 *p_param_values++ = reverb->room_hf_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800739 param_values[2] += 1;
740 }
741 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
742 *p_param_values++ = REVERB_DECAY_TIME;
743 *p_param_values++ = CONFIG_SET;
744 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
745 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700746 *p_param_values++ = reverb->decay_time;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800747 param_values[2] += 1;
748 }
749 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
750 *p_param_values++ = REVERB_DECAY_HF_RATIO;
751 *p_param_values++ = CONFIG_SET;
752 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
753 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700754 *p_param_values++ = reverb->decay_hf_ratio;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800755 param_values[2] += 1;
756 }
757 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
758 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
759 *p_param_values++ = CONFIG_SET;
760 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
761 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700762 *p_param_values++ = reverb->reflections_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800763 param_values[2] += 1;
764 }
765 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
766 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
767 *p_param_values++ = CONFIG_SET;
768 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
769 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700770 *p_param_values++ = reverb->reflections_delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800771 param_values[2] += 1;
772 }
773 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
774 *p_param_values++ = REVERB_LEVEL;
775 *p_param_values++ = CONFIG_SET;
776 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
777 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700778 *p_param_values++ = reverb->level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800779 param_values[2] += 1;
780 }
781 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
782 *p_param_values++ = REVERB_DELAY;
783 *p_param_values++ = CONFIG_SET;
784 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
785 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700786 *p_param_values++ = reverb->delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800787 param_values[2] += 1;
788 }
789 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
790 *p_param_values++ = REVERB_DIFFUSION;
791 *p_param_values++ = CONFIG_SET;
792 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
793 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700794 *p_param_values++ = reverb->diffusion;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800795 param_values[2] += 1;
796 }
797 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
798 *p_param_values++ = REVERB_DENSITY;
799 *p_param_values++ = CONFIG_SET;
800 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
801 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700802 *p_param_values++ = reverb->density;
803 param_values[2] += 1;
804 }
805
806 if ((mode == OFFLOAD) && param_values[2] && ctl) {
807 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
808 ARRAY_SIZE(param_values));
809 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
810 ctl && *(int *)ctl) {
811 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
812 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
813 }
814
815 return 0;
816}
817
818int offload_reverb_send_params(struct mixer_ctl *ctl,
819 struct reverb_params *reverb,
820 unsigned param_send_flags)
821{
822 return reverb_send_params(OFFLOAD, (void *)ctl, reverb,
823 param_send_flags);
824}
825
826int hw_acc_reverb_send_params(int fd, struct reverb_params *reverb,
827 unsigned param_send_flags)
828{
829 return reverb_send_params(HW_ACCELERATOR, (void *)&fd,
830 reverb, param_send_flags);
831}
832
833void offload_soft_volume_set_enable(struct soft_volume_params *vol, bool enable)
834{
835 ALOGV("%s", __func__);
836 vol->enable_flag = enable;
837}
838
839void offload_soft_volume_set_gain_master(struct soft_volume_params *vol, int gain)
840{
841 ALOGV("%s", __func__);
842 vol->master_gain = gain;
843}
844
845void offload_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
846 int l_gain, int r_gain)
847{
848 ALOGV("%s", __func__);
849 vol->left_gain = l_gain;
850 vol->right_gain = r_gain;
851}
852
853int offload_soft_volume_send_params(struct mixer_ctl *ctl,
854 struct soft_volume_params vol,
855 unsigned param_send_flags)
856{
857 int param_values[128] = {0};
858 int *p_param_values = param_values;
859 uint32_t i;
860
861 ALOGV("%s", __func__);
862 *p_param_values++ = SOFT_VOLUME_MODULE;
863 *p_param_values++ = 0;
864 *p_param_values++ = 0; /* num of commands*/
865 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_ENABLE_FLAG) {
866 *p_param_values++ = SOFT_VOLUME_ENABLE;
867 *p_param_values++ = CONFIG_SET;
868 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
869 *p_param_values++ = SOFT_VOLUME_ENABLE_PARAM_LEN;
870 *p_param_values++ = vol.enable_flag;
871 param_values[2] += 1;
872 }
873 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_MASTER) {
874 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER;
875 *p_param_values++ = CONFIG_SET;
876 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
877 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER_PARAM_LEN;
878 *p_param_values++ = vol.master_gain;
879 param_values[2] += 1;
880 }
881 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_2CH) {
882 *p_param_values++ = SOFT_VOLUME_GAIN_2CH;
883 *p_param_values++ = CONFIG_SET;
884 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
885 *p_param_values++ = SOFT_VOLUME_GAIN_2CH_PARAM_LEN;
886 *p_param_values++ = vol.left_gain;
887 *p_param_values++ = vol.right_gain;
888 param_values[2] += 1;
889 }
890
891 if (param_values[2] && ctl)
892 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
893
894 return 0;
895}
896
897void offload_transition_soft_volume_set_enable(struct soft_volume_params *vol,
898 bool enable)
899{
900 ALOGV("%s", __func__);
901 vol->enable_flag = enable;
902}
903
904void offload_transition_soft_volume_set_gain_master(struct soft_volume_params *vol,
905 int gain)
906{
907 ALOGV("%s", __func__);
908 vol->master_gain = gain;
909}
910
911void offload_transition_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
912 int l_gain, int r_gain)
913{
914 ALOGV("%s", __func__);
915 vol->left_gain = l_gain;
916 vol->right_gain = r_gain;
917}
918
919int offload_transition_soft_volume_send_params(struct mixer_ctl *ctl,
920 struct soft_volume_params vol,
921 unsigned param_send_flags)
922{
923 int param_values[128] = {0};
924 int *p_param_values = param_values;
925 uint32_t i;
926
927 ALOGV("%s", __func__);
928 *p_param_values++ = SOFT_VOLUME2_MODULE;
929 *p_param_values++ = 0;
930 *p_param_values++ = 0; /* num of commands*/
931 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_ENABLE_FLAG) {
932 *p_param_values++ = SOFT_VOLUME2_ENABLE;
933 *p_param_values++ = CONFIG_SET;
934 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
935 *p_param_values++ = SOFT_VOLUME2_ENABLE_PARAM_LEN;
936 *p_param_values++ = vol.enable_flag;
937 param_values[2] += 1;
938 }
939 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_MASTER) {
940 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER;
941 *p_param_values++ = CONFIG_SET;
942 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
943 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER_PARAM_LEN;
944 *p_param_values++ = vol.master_gain;
945 param_values[2] += 1;
946 }
947 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_2CH) {
948 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH;
949 *p_param_values++ = CONFIG_SET;
950 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
951 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH_PARAM_LEN;
952 *p_param_values++ = vol.left_gain;
953 *p_param_values++ = vol.right_gain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800954 param_values[2] += 1;
955 }
956
957 if (param_values[2] && ctl)
958 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
959
960 return 0;
961}
Alexy Josephd464f3b2014-11-18 16:14:41 -0800962
963static int hpx_send_params(eff_mode_t mode, void *ctl,
964 unsigned param_send_flags)
965{
966 int param_values[128] = {0};
967 int *p_param_values = param_values;
968 uint32_t i;
969
970 ALOGV("%s", __func__);
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +0530971 if (!ctl) {
972 ALOGE("%s: ctl is NULL, return invalid", __func__);
973 return -EINVAL;
974 }
975
Alexy Josephd464f3b2014-11-18 16:14:41 -0800976 if (param_send_flags & OFFLOAD_SEND_HPX_STATE_OFF) {
977 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
978 *p_param_values++ = 0; /* hpx off*/
979 } else if (param_send_flags & OFFLOAD_SEND_HPX_STATE_ON) {
980 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
981 *p_param_values++ = 1; /* hpx on*/
982 }
983
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +0530984 if (mode == OFFLOAD)
Alexy Josephd464f3b2014-11-18 16:14:41 -0800985 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
986 else {
987 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
988 ALOGE("%s: sending h/w acc hpx state params fail[%d]", __func__, errno);
989 }
990 return 0;
991}
992
993int offload_hpx_send_params(struct mixer_ctl *ctl, unsigned param_send_flags)
994{
995 return hpx_send_params(OFFLOAD, (void *)ctl, param_send_flags);
996}
997
998int hw_acc_hpx_send_params(int fd, unsigned param_send_flags)
999{
1000 return hpx_send_params(HW_ACCELERATOR, (void *)&fd, param_send_flags);
1001}