blob: 16c370b82d522a462be695201f0879370dc40b10 [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>
Mingming Yin497419f2015-07-01 16:57:32 -070058#include <errno.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080059#include <cutils/log.h>
60#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080061#include <sound/audio_effects.h>
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080062#include <sound/devdep_params.h>
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070063#include <linux/msm_audio.h>
64
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080065#include "effect_api.h"
66
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080067#ifdef DTS_EAGLE
68#include "effect_util.h"
69#endif
70
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080071#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070072typedef enum eff_mode {
73 OFFLOAD,
74 HW_ACCELERATOR
75} eff_mode_t;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080076
77#define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19
78const int map_eq_opensl_preset_2_offload_preset[] = {
79 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */
80 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */
81 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */
82 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */
83 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */
84 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */
85 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */
86 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */
87 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */
88 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */
89 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */
90};
91
92const int map_reverb_opensl_preset_2_offload_preset
93 [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = {
94 {1, 15},
95 {2, 16},
96 {3, 17},
97 {4, 18},
98 {5, 3},
99 {6, 20}
100};
101
102int offload_update_mixer_and_effects_ctl(int card, int device_id,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700103 struct mixer **mixer,
104 struct mixer_ctl **ctl)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800105{
106 char mixer_string[128];
107
108 snprintf(mixer_string, sizeof(mixer_string),
109 "%s %d", "Audio Effects Config", device_id);
110 ALOGV("%s: mixer_string: %s", __func__, mixer_string);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700111 *mixer = mixer_open(card);
112 if (!(*mixer)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800113 ALOGE("Failed to open mixer");
114 ctl = NULL;
115 return -EINVAL;
116 } else {
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700117 *ctl = mixer_get_ctl_by_name(*mixer, mixer_string);
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +0530118 if (!(*ctl)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800119 ALOGE("mixer_get_ctl_by_name failed");
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700120 mixer_close(*mixer);
121 *mixer = NULL;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800122 return -EINVAL;
123 }
124 }
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700125 ALOGV("mixer: %p, ctl: %p", *mixer, *ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800126 return 0;
127}
128
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700129void offload_close_mixer(struct mixer **mixer)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800130{
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700131 mixer_close(*mixer);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800132}
133
134void offload_bassboost_set_device(struct bass_boost_params *bassboost,
135 uint32_t device)
136{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530137 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800138 bassboost->device = device;
139}
140
141void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
142 bool enable)
143{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530144 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800145 bassboost->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800146
147#ifdef DTS_EAGLE
148 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
149#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800150}
151
152int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
153{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530154 ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800155 return bassboost->enable_flag;
156}
157
158void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
159 int strength)
160{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530161 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800162 bassboost->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800163
164#ifdef DTS_EAGLE
165 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
166#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800167}
168
169void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
170 int mode)
171{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530172 ALOGVV("%s: mode %d", __func__, mode);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800173 bassboost->mode = mode;
174}
175
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700176static int bassboost_send_params(eff_mode_t mode, void *ctl,
177 struct bass_boost_params *bassboost,
178 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800179{
180 int param_values[128] = {0};
181 int *p_param_values = param_values;
182
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530183 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800184 *p_param_values++ = BASS_BOOST_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700185 *p_param_values++ = bassboost->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800186 *p_param_values++ = 0; /* num of commands*/
187 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
188 *p_param_values++ = BASS_BOOST_ENABLE;
189 *p_param_values++ = CONFIG_SET;
190 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
191 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700192 *p_param_values++ = bassboost->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800193 param_values[2] += 1;
194 }
195 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
196 *p_param_values++ = BASS_BOOST_STRENGTH;
197 *p_param_values++ = CONFIG_SET;
198 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
199 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700200 *p_param_values++ = bassboost->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800201 param_values[2] += 1;
202 }
203 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
204 *p_param_values++ = BASS_BOOST_MODE;
205 *p_param_values++ = CONFIG_SET;
206 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
207 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700208 *p_param_values++ = bassboost->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800209 param_values[2] += 1;
210 }
211
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700212 if ((mode == OFFLOAD) && param_values[2] && ctl) {
213 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
214 ARRAY_SIZE(param_values));
215 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
216 ctl && *(int *)ctl) {
217 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
218 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
219 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800220
221 return 0;
222}
223
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700224int offload_bassboost_send_params(struct mixer_ctl *ctl,
225 struct bass_boost_params *bassboost,
226 unsigned param_send_flags)
227{
228 return bassboost_send_params(OFFLOAD, (void *)ctl, bassboost,
229 param_send_flags);
230}
231
232int hw_acc_bassboost_send_params(int fd, struct bass_boost_params *bassboost,
233 unsigned param_send_flags)
234{
235 return bassboost_send_params(HW_ACCELERATOR, (void *)&fd,
236 bassboost, param_send_flags);
237}
238
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800239void offload_pbe_set_device(struct pbe_params *pbe,
240 uint32_t device)
241{
242 ALOGV("%s: device=%d", __func__, device);
243 pbe->device = device;
244}
245
246void offload_pbe_set_enable_flag(struct pbe_params *pbe,
247 bool enable)
248{
249 ALOGV("%s: enable=%d", __func__, enable);
250 pbe->enable_flag = enable;
251}
252
253int offload_pbe_get_enable_flag(struct pbe_params *pbe)
254{
255 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
256 return pbe->enable_flag;
257}
258
259static int pbe_send_params(eff_mode_t mode, void *ctl,
260 struct pbe_params *pbe,
261 unsigned param_send_flags)
262{
263 int param_values[128] = {0};
264 int i, *p_param_values = param_values, *cfg = NULL;
265
266 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
267 *p_param_values++ = PBE_MODULE;
268 *p_param_values++ = pbe->device;
269 *p_param_values++ = 0; /* num of commands*/
270 if (param_send_flags & OFFLOAD_SEND_PBE_ENABLE_FLAG) {
271 *p_param_values++ = PBE_ENABLE;
272 *p_param_values++ = CONFIG_SET;
273 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
274 *p_param_values++ = PBE_ENABLE_PARAM_LEN;
275 *p_param_values++ = pbe->enable_flag;
276 param_values[2] += 1;
277 }
278 if (param_send_flags & OFFLOAD_SEND_PBE_CONFIG) {
279 *p_param_values++ = PBE_CONFIG;
280 *p_param_values++ = CONFIG_SET;
281 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
282 *p_param_values++ = pbe->cfg_len;
283 cfg = (int *)&pbe->config;
284 for (i = 0; i < (int)pbe->cfg_len ; i+= sizeof(*p_param_values))
285 *p_param_values++ = *cfg++;
286 param_values[2] += 1;
287 }
288
289 if ((mode == OFFLOAD) && param_values[2] && ctl) {
290 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
291 ARRAY_SIZE(param_values));
292 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
293 ctl && *(int *)ctl) {
294 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
295 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
296 }
297
298 return 0;
299}
300
301int offload_pbe_send_params(struct mixer_ctl *ctl,
302 struct pbe_params *pbe,
303 unsigned param_send_flags)
304{
305 return pbe_send_params(OFFLOAD, (void *)ctl, pbe,
306 param_send_flags);
307}
308
309int hw_acc_pbe_send_params(int fd, struct pbe_params *pbe,
310 unsigned param_send_flags)
311{
312 return pbe_send_params(HW_ACCELERATOR, (void *)&fd,
313 pbe, param_send_flags);
314}
315
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800316void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
317 uint32_t device)
318{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530319 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800320 virtualizer->device = device;
321}
322
323void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
324 bool enable)
325{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530326 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800327 virtualizer->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800328
329#ifdef DTS_EAGLE
330 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
331#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800332}
333
334int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
335{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530336 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800337 return virtualizer->enable_flag;
338}
339
340void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
341 int strength)
342{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530343 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800344 virtualizer->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800345
346#ifdef DTS_EAGLE
347 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
348#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800349}
350
351void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
352 int out_type)
353{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530354 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800355 virtualizer->out_type = out_type;
356}
357
358void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
359 int gain_adjust)
360{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530361 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800362 virtualizer->gain_adjust = gain_adjust;
363}
364
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700365static int virtualizer_send_params(eff_mode_t mode, void *ctl,
366 struct virtualizer_params *virtualizer,
367 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800368{
369 int param_values[128] = {0};
370 int *p_param_values = param_values;
371
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530372 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800373 *p_param_values++ = VIRTUALIZER_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700374 *p_param_values++ = virtualizer->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800375 *p_param_values++ = 0; /* num of commands*/
376 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
377 *p_param_values++ = VIRTUALIZER_ENABLE;
378 *p_param_values++ = CONFIG_SET;
379 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
380 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700381 *p_param_values++ = virtualizer->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800382 param_values[2] += 1;
383 }
384 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
385 *p_param_values++ = VIRTUALIZER_STRENGTH;
386 *p_param_values++ = CONFIG_SET;
387 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
388 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700389 *p_param_values++ = virtualizer->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800390 param_values[2] += 1;
391 }
392 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
393 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
394 *p_param_values++ = CONFIG_SET;
395 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
396 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700397 *p_param_values++ = virtualizer->out_type;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800398 param_values[2] += 1;
399 }
400 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
401 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
402 *p_param_values++ = CONFIG_SET;
403 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
404 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700405 *p_param_values++ = virtualizer->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800406 param_values[2] += 1;
407 }
408
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700409 if ((mode == OFFLOAD) && param_values[2] && ctl) {
410 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
411 ARRAY_SIZE(param_values));
412 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
413 ctl && *(int *)ctl) {
414 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
415 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
416 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800417
418 return 0;
419}
420
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700421int offload_virtualizer_send_params(struct mixer_ctl *ctl,
422 struct virtualizer_params *virtualizer,
423 unsigned param_send_flags)
424{
425 return virtualizer_send_params(OFFLOAD, (void *)ctl, virtualizer,
426 param_send_flags);
427}
428
429int hw_acc_virtualizer_send_params(int fd,
430 struct virtualizer_params *virtualizer,
431 unsigned param_send_flags)
432{
433 return virtualizer_send_params(HW_ACCELERATOR, (void *)&fd,
434 virtualizer, param_send_flags);
435}
436
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800437void offload_eq_set_device(struct eq_params *eq, uint32_t device)
438{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530439 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800440 eq->device = device;
441}
442
443void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
444{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530445 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800446 eq->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800447
448#ifdef DTS_EAGLE
449 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
450#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800451}
452
453int offload_eq_get_enable_flag(struct eq_params *eq)
454{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530455 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800456 return eq->enable_flag;
457}
458
459void offload_eq_set_preset(struct eq_params *eq, int preset)
460{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530461 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800462 eq->config.preset_id = preset;
463 eq->config.eq_pregain = Q27_UNITY;
464}
465
466void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
467 const uint16_t *band_freq_list,
468 int *band_gain_list)
469{
470 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530471 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800472 eq->config.num_bands = num_bands;
473 for (i=0; i<num_bands; i++) {
474 eq->per_band_cfg[i].band_idx = i;
475 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
476 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
477 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
478 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
479 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800480
481#ifdef DTS_EAGLE
482 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_SET_PARAM, EFFECT_NO_OP, EFFECT_NO_OP, i, band_gain_list[i] * 100);
483#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800484}
485
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700486static int eq_send_params(eff_mode_t mode, void *ctl, struct eq_params *eq,
487 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800488{
489 int param_values[128] = {0};
490 int *p_param_values = param_values;
491 uint32_t i;
492
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530493 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700494 if ((eq->config.preset_id < -1) ||
495 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq->config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800496 ALOGV("No Valid preset to set");
497 return 0;
498 }
499 *p_param_values++ = EQ_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700500 *p_param_values++ = eq->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800501 *p_param_values++ = 0; /* num of commands*/
502 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
503 *p_param_values++ = EQ_ENABLE;
504 *p_param_values++ = CONFIG_SET;
505 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
506 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700507 *p_param_values++ = eq->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800508 param_values[2] += 1;
509 }
510 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
511 *p_param_values++ = EQ_CONFIG;
512 *p_param_values++ = CONFIG_SET;
513 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
514 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700515 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800516 *p_param_values++ =
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700517 map_eq_opensl_preset_2_offload_preset[eq->config.preset_id];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800518 *p_param_values++ = 0;
519 param_values[2] += 1;
520 }
521 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
522 *p_param_values++ = EQ_CONFIG;
523 *p_param_values++ = CONFIG_SET;
524 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
525 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700526 eq->config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
527 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800528 *p_param_values++ = CUSTOM_OPENSL_PRESET;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700529 *p_param_values++ = eq->config.num_bands;
530 for (i=0; i<eq->config.num_bands; i++) {
531 *p_param_values++ = eq->per_band_cfg[i].band_idx;
532 *p_param_values++ = eq->per_band_cfg[i].filter_type;
533 *p_param_values++ = eq->per_band_cfg[i].freq_millihertz;
534 *p_param_values++ = eq->per_band_cfg[i].gain_millibels;
535 *p_param_values++ = eq->per_band_cfg[i].quality_factor;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800536 }
537 param_values[2] += 1;
538 }
539
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700540 if ((mode == OFFLOAD) && param_values[2] && ctl) {
541 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
542 ARRAY_SIZE(param_values));
543 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
544 ctl && *(int *)ctl) {
545 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
546 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
547 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800548
549 return 0;
550}
551
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700552int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params *eq,
553 unsigned param_send_flags)
554{
555 return eq_send_params(OFFLOAD, (void *)ctl, eq, param_send_flags);
556}
557
558int hw_acc_eq_send_params(int fd, struct eq_params *eq,
559 unsigned param_send_flags)
560{
561 return eq_send_params(HW_ACCELERATOR, (void *)&fd, eq,
562 param_send_flags);
563}
564
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800565void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
566{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530567 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800568 reverb->device = device;
569}
570
571void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
572{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530573 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800574 reverb->enable_flag = enable;
575}
576
577int offload_reverb_get_enable_flag(struct reverb_params *reverb)
578{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530579 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800580 return reverb->enable_flag;
581}
582
583void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
584{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530585 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800586 reverb->mode = mode;
587}
588
589void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
590{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530591 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800592 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800593 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800594}
595
596void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
597{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530598 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800599 reverb->wet_mix = wet_mix;
600}
601
602void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
603 int gain_adjust)
604{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530605 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800606 reverb->gain_adjust = gain_adjust;
607}
608
609void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
610{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530611 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800612 reverb->room_level = room_level;
613}
614
615void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
616 int room_hf_level)
617{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530618 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800619 reverb->room_hf_level = room_hf_level;
620}
621
622void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
623{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530624 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800625 reverb->decay_time = decay_time;
626}
627
628void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
629 int decay_hf_ratio)
630{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530631 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800632 reverb->decay_hf_ratio = decay_hf_ratio;
633}
634
635void offload_reverb_set_reflections_level(struct reverb_params *reverb,
636 int reflections_level)
637{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530638 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800639 reverb->reflections_level = reflections_level;
640}
641
642void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
643 int reflections_delay)
644{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530645 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800646 reverb->reflections_delay = reflections_delay;
647}
648
649void offload_reverb_set_reverb_level(struct reverb_params *reverb,
650 int reverb_level)
651{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530652 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800653 reverb->level = reverb_level;
654}
655
656void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
657{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530658 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800659 reverb->delay = delay;
660}
661
662void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
663{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530664 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800665 reverb->diffusion = diffusion;
666}
667
668void offload_reverb_set_density(struct reverb_params *reverb, int density)
669{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530670 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800671 reverb->density = density;
672}
673
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700674static int reverb_send_params(eff_mode_t mode, void *ctl,
675 struct reverb_params *reverb,
676 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800677{
678 int param_values[128] = {0};
679 int *p_param_values = param_values;
680
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530681 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800682 *p_param_values++ = REVERB_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700683 *p_param_values++ = reverb->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800684 *p_param_values++ = 0; /* num of commands*/
685
686 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
687 *p_param_values++ = REVERB_ENABLE;
688 *p_param_values++ = CONFIG_SET;
689 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
690 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700691 *p_param_values++ = reverb->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800692 param_values[2] += 1;
693 }
694 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
695 *p_param_values++ = REVERB_MODE;
696 *p_param_values++ = CONFIG_SET;
697 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
698 *p_param_values++ = REVERB_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700699 *p_param_values++ = reverb->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800700 param_values[2] += 1;
701 }
702 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
703 *p_param_values++ = REVERB_PRESET;
704 *p_param_values++ = CONFIG_SET;
705 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
706 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700707 *p_param_values++ = reverb->preset;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800708 param_values[2] += 1;
709 }
710 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
711 *p_param_values++ = REVERB_WET_MIX;
712 *p_param_values++ = CONFIG_SET;
713 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
714 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700715 *p_param_values++ = reverb->wet_mix;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800716 param_values[2] += 1;
717 }
718 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
719 *p_param_values++ = REVERB_GAIN_ADJUST;
720 *p_param_values++ = CONFIG_SET;
721 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
722 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700723 *p_param_values++ = reverb->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800724 param_values[2] += 1;
725 }
726 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
727 *p_param_values++ = REVERB_ROOM_LEVEL;
728 *p_param_values++ = CONFIG_SET;
729 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
730 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700731 *p_param_values++ = reverb->room_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800732 param_values[2] += 1;
733 }
734 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
735 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
736 *p_param_values++ = CONFIG_SET;
737 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
738 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700739 *p_param_values++ = reverb->room_hf_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800740 param_values[2] += 1;
741 }
742 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
743 *p_param_values++ = REVERB_DECAY_TIME;
744 *p_param_values++ = CONFIG_SET;
745 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
746 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700747 *p_param_values++ = reverb->decay_time;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800748 param_values[2] += 1;
749 }
750 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
751 *p_param_values++ = REVERB_DECAY_HF_RATIO;
752 *p_param_values++ = CONFIG_SET;
753 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
754 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700755 *p_param_values++ = reverb->decay_hf_ratio;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800756 param_values[2] += 1;
757 }
758 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
759 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
760 *p_param_values++ = CONFIG_SET;
761 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
762 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700763 *p_param_values++ = reverb->reflections_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800764 param_values[2] += 1;
765 }
766 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
767 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
768 *p_param_values++ = CONFIG_SET;
769 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
770 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700771 *p_param_values++ = reverb->reflections_delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800772 param_values[2] += 1;
773 }
774 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
775 *p_param_values++ = REVERB_LEVEL;
776 *p_param_values++ = CONFIG_SET;
777 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
778 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700779 *p_param_values++ = reverb->level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800780 param_values[2] += 1;
781 }
782 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
783 *p_param_values++ = REVERB_DELAY;
784 *p_param_values++ = CONFIG_SET;
785 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
786 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700787 *p_param_values++ = reverb->delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800788 param_values[2] += 1;
789 }
790 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
791 *p_param_values++ = REVERB_DIFFUSION;
792 *p_param_values++ = CONFIG_SET;
793 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
794 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700795 *p_param_values++ = reverb->diffusion;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800796 param_values[2] += 1;
797 }
798 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
799 *p_param_values++ = REVERB_DENSITY;
800 *p_param_values++ = CONFIG_SET;
801 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
802 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700803 *p_param_values++ = reverb->density;
804 param_values[2] += 1;
805 }
806
807 if ((mode == OFFLOAD) && param_values[2] && ctl) {
808 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
809 ARRAY_SIZE(param_values));
810 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
811 ctl && *(int *)ctl) {
812 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
813 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
814 }
815
816 return 0;
817}
818
819int offload_reverb_send_params(struct mixer_ctl *ctl,
820 struct reverb_params *reverb,
821 unsigned param_send_flags)
822{
823 return reverb_send_params(OFFLOAD, (void *)ctl, reverb,
824 param_send_flags);
825}
826
827int hw_acc_reverb_send_params(int fd, struct reverb_params *reverb,
828 unsigned param_send_flags)
829{
830 return reverb_send_params(HW_ACCELERATOR, (void *)&fd,
831 reverb, param_send_flags);
832}
833
834void offload_soft_volume_set_enable(struct soft_volume_params *vol, bool enable)
835{
836 ALOGV("%s", __func__);
837 vol->enable_flag = enable;
838}
839
840void offload_soft_volume_set_gain_master(struct soft_volume_params *vol, int gain)
841{
842 ALOGV("%s", __func__);
843 vol->master_gain = gain;
844}
845
846void offload_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
847 int l_gain, int r_gain)
848{
849 ALOGV("%s", __func__);
850 vol->left_gain = l_gain;
851 vol->right_gain = r_gain;
852}
853
854int offload_soft_volume_send_params(struct mixer_ctl *ctl,
855 struct soft_volume_params vol,
856 unsigned param_send_flags)
857{
858 int param_values[128] = {0};
859 int *p_param_values = param_values;
860 uint32_t i;
861
862 ALOGV("%s", __func__);
863 *p_param_values++ = SOFT_VOLUME_MODULE;
864 *p_param_values++ = 0;
865 *p_param_values++ = 0; /* num of commands*/
866 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_ENABLE_FLAG) {
867 *p_param_values++ = SOFT_VOLUME_ENABLE;
868 *p_param_values++ = CONFIG_SET;
869 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
870 *p_param_values++ = SOFT_VOLUME_ENABLE_PARAM_LEN;
871 *p_param_values++ = vol.enable_flag;
872 param_values[2] += 1;
873 }
874 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_MASTER) {
875 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER;
876 *p_param_values++ = CONFIG_SET;
877 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
878 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER_PARAM_LEN;
879 *p_param_values++ = vol.master_gain;
880 param_values[2] += 1;
881 }
882 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_2CH) {
883 *p_param_values++ = SOFT_VOLUME_GAIN_2CH;
884 *p_param_values++ = CONFIG_SET;
885 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
886 *p_param_values++ = SOFT_VOLUME_GAIN_2CH_PARAM_LEN;
887 *p_param_values++ = vol.left_gain;
888 *p_param_values++ = vol.right_gain;
889 param_values[2] += 1;
890 }
891
892 if (param_values[2] && ctl)
893 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
894
895 return 0;
896}
897
898void offload_transition_soft_volume_set_enable(struct soft_volume_params *vol,
899 bool enable)
900{
901 ALOGV("%s", __func__);
902 vol->enable_flag = enable;
903}
904
905void offload_transition_soft_volume_set_gain_master(struct soft_volume_params *vol,
906 int gain)
907{
908 ALOGV("%s", __func__);
909 vol->master_gain = gain;
910}
911
912void offload_transition_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
913 int l_gain, int r_gain)
914{
915 ALOGV("%s", __func__);
916 vol->left_gain = l_gain;
917 vol->right_gain = r_gain;
918}
919
920int offload_transition_soft_volume_send_params(struct mixer_ctl *ctl,
921 struct soft_volume_params vol,
922 unsigned param_send_flags)
923{
924 int param_values[128] = {0};
925 int *p_param_values = param_values;
926 uint32_t i;
927
928 ALOGV("%s", __func__);
929 *p_param_values++ = SOFT_VOLUME2_MODULE;
930 *p_param_values++ = 0;
931 *p_param_values++ = 0; /* num of commands*/
932 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_ENABLE_FLAG) {
933 *p_param_values++ = SOFT_VOLUME2_ENABLE;
934 *p_param_values++ = CONFIG_SET;
935 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
936 *p_param_values++ = SOFT_VOLUME2_ENABLE_PARAM_LEN;
937 *p_param_values++ = vol.enable_flag;
938 param_values[2] += 1;
939 }
940 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_MASTER) {
941 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER;
942 *p_param_values++ = CONFIG_SET;
943 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
944 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER_PARAM_LEN;
945 *p_param_values++ = vol.master_gain;
946 param_values[2] += 1;
947 }
948 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_2CH) {
949 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH;
950 *p_param_values++ = CONFIG_SET;
951 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
952 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH_PARAM_LEN;
953 *p_param_values++ = vol.left_gain;
954 *p_param_values++ = vol.right_gain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800955 param_values[2] += 1;
956 }
957
958 if (param_values[2] && ctl)
959 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
960
961 return 0;
962}
Alexy Josephd464f3b2014-11-18 16:14:41 -0800963
964static int hpx_send_params(eff_mode_t mode, void *ctl,
965 unsigned param_send_flags)
966{
967 int param_values[128] = {0};
968 int *p_param_values = param_values;
969 uint32_t i;
970
971 ALOGV("%s", __func__);
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +0530972 if (!ctl) {
973 ALOGE("%s: ctl is NULL, return invalid", __func__);
974 return -EINVAL;
975 }
976
Alexy Josephd464f3b2014-11-18 16:14:41 -0800977 if (param_send_flags & OFFLOAD_SEND_HPX_STATE_OFF) {
978 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
979 *p_param_values++ = 0; /* hpx off*/
980 } else if (param_send_flags & OFFLOAD_SEND_HPX_STATE_ON) {
981 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
982 *p_param_values++ = 1; /* hpx on*/
983 }
984
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +0530985 if (mode == OFFLOAD)
Alexy Josephd464f3b2014-11-18 16:14:41 -0800986 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
987 else {
988 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
989 ALOGE("%s: sending h/w acc hpx state params fail[%d]", __func__, errno);
990 }
991 return 0;
992}
993
994int offload_hpx_send_params(struct mixer_ctl *ctl, unsigned param_send_flags)
995{
996 return hpx_send_params(OFFLOAD, (void *)ctl, param_send_flags);
997}
998
999int hw_acc_hpx_send_params(int fd, unsigned param_send_flags)
1000{
1001 return hpx_send_params(HW_ACCELERATOR, (void *)&fd, param_send_flags);
1002}