blob: cff4be32d9338a5d2dda36a64fed22c04e7e91f4 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Aalique Grahame22e49102018-12-18 14:23:57 -08002 * Copyright (c) 2013-2015, 2019 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>
Aalique Grahame22e49102018-12-18 14:23:57 -080059#include <log/log.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080060#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>
Sharad Sangleb27354b2015-06-18 15:58:55 +053064#include <errno.h>
Vinay Vermaaddfa4a2018-04-29 14:03:38 +053065#include <unistd.h>
66#include <stdio.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080067#include "effect_api.h"
68
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080069#ifdef DTS_EAGLE
70#include "effect_util.h"
71#endif
72
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080073#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070074typedef enum eff_mode {
75 OFFLOAD,
76 HW_ACCELERATOR
77} eff_mode_t;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080078
79#define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19
80const int map_eq_opensl_preset_2_offload_preset[] = {
81 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */
82 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */
83 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */
84 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */
85 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */
86 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */
87 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */
88 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */
89 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */
90 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */
91 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */
92};
93
94const int map_reverb_opensl_preset_2_offload_preset
95 [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = {
96 {1, 15},
97 {2, 16},
98 {3, 17},
99 {4, 18},
100 {5, 3},
101 {6, 20}
102};
103
104int offload_update_mixer_and_effects_ctl(int card, int device_id,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700105 struct mixer **mixer,
106 struct mixer_ctl **ctl)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800107{
108 char mixer_string[128];
109
110 snprintf(mixer_string, sizeof(mixer_string),
111 "%s %d", "Audio Effects Config", device_id);
112 ALOGV("%s: mixer_string: %s", __func__, mixer_string);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700113 *mixer = mixer_open(card);
114 if (!(*mixer)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800115 ALOGE("Failed to open mixer");
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800116 *ctl = NULL;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800117 return -EINVAL;
118 } else {
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700119 *ctl = mixer_get_ctl_by_name(*mixer, mixer_string);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800120 if (!*ctl) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800121 ALOGE("mixer_get_ctl_by_name failed");
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700122 mixer_close(*mixer);
123 *mixer = NULL;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800124 return -EINVAL;
125 }
126 }
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700127 ALOGV("mixer: %p, ctl: %p", *mixer, *ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800128 return 0;
129}
130
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700131void offload_close_mixer(struct mixer **mixer)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800132{
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700133 mixer_close(*mixer);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800134}
135
136void offload_bassboost_set_device(struct bass_boost_params *bassboost,
137 uint32_t device)
138{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530139 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800140 bassboost->device = device;
141}
142
143void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
144 bool enable)
145{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530146 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800147 bassboost->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800148
149#ifdef DTS_EAGLE
150 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
151#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800152}
153
154int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
155{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530156 ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800157 return bassboost->enable_flag;
158}
159
160void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
161 int strength)
162{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530163 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800164 bassboost->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800165
166#ifdef DTS_EAGLE
167 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
168#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800169}
170
171void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
172 int mode)
173{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530174 ALOGVV("%s: mode %d", __func__, mode);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800175 bassboost->mode = mode;
176}
177
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700178static int bassboost_send_params(eff_mode_t mode, void *ctl,
179 struct bass_boost_params *bassboost,
180 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800181{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530182 long param_values[128] = {0};
183 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800184
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530185 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800186 *p_param_values++ = BASS_BOOST_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700187 *p_param_values++ = bassboost->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800188 *p_param_values++ = 0; /* num of commands*/
189 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
190 *p_param_values++ = BASS_BOOST_ENABLE;
191 *p_param_values++ = CONFIG_SET;
192 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
193 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700194 *p_param_values++ = bassboost->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800195 param_values[2] += 1;
196 }
197 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
198 *p_param_values++ = BASS_BOOST_STRENGTH;
199 *p_param_values++ = CONFIG_SET;
200 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
201 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700202 *p_param_values++ = bassboost->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800203 param_values[2] += 1;
204 }
205 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
206 *p_param_values++ = BASS_BOOST_MODE;
207 *p_param_values++ = CONFIG_SET;
208 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
209 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700210 *p_param_values++ = bassboost->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800211 param_values[2] += 1;
212 }
213
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700214 if ((mode == OFFLOAD) && param_values[2] && ctl) {
215 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
216 ARRAY_SIZE(param_values));
217 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
218 ctl && *(int *)ctl) {
219 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
220 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
221 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800222
223 return 0;
224}
225
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700226int offload_bassboost_send_params(struct mixer_ctl *ctl,
227 struct bass_boost_params *bassboost,
228 unsigned param_send_flags)
229{
230 return bassboost_send_params(OFFLOAD, (void *)ctl, bassboost,
231 param_send_flags);
232}
233
234int hw_acc_bassboost_send_params(int fd, struct bass_boost_params *bassboost,
235 unsigned param_send_flags)
236{
237 return bassboost_send_params(HW_ACCELERATOR, (void *)&fd,
238 bassboost, param_send_flags);
239}
240
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800241void offload_pbe_set_device(struct pbe_params *pbe,
242 uint32_t device)
243{
244 ALOGV("%s: device=%d", __func__, device);
245 pbe->device = device;
246}
247
248void offload_pbe_set_enable_flag(struct pbe_params *pbe,
249 bool enable)
250{
251 ALOGV("%s: enable=%d", __func__, enable);
252 pbe->enable_flag = enable;
253}
254
255int offload_pbe_get_enable_flag(struct pbe_params *pbe)
256{
257 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
258 return pbe->enable_flag;
259}
260
261static int pbe_send_params(eff_mode_t mode, void *ctl,
262 struct pbe_params *pbe,
263 unsigned param_send_flags)
264{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530265 long param_values[128] = {0};
266 long *p_param_values = param_values;
267 int i, *cfg = NULL;
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800268
269 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
270 *p_param_values++ = PBE_MODULE;
271 *p_param_values++ = pbe->device;
272 *p_param_values++ = 0; /* num of commands*/
273 if (param_send_flags & OFFLOAD_SEND_PBE_ENABLE_FLAG) {
274 *p_param_values++ = PBE_ENABLE;
275 *p_param_values++ = CONFIG_SET;
276 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
277 *p_param_values++ = PBE_ENABLE_PARAM_LEN;
278 *p_param_values++ = pbe->enable_flag;
279 param_values[2] += 1;
280 }
281 if (param_send_flags & OFFLOAD_SEND_PBE_CONFIG) {
282 *p_param_values++ = PBE_CONFIG;
283 *p_param_values++ = CONFIG_SET;
284 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
285 *p_param_values++ = pbe->cfg_len;
286 cfg = (int *)&pbe->config;
287 for (i = 0; i < (int)pbe->cfg_len ; i+= sizeof(*p_param_values))
288 *p_param_values++ = *cfg++;
289 param_values[2] += 1;
290 }
291
292 if ((mode == OFFLOAD) && param_values[2] && ctl) {
293 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
294 ARRAY_SIZE(param_values));
295 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
296 ctl && *(int *)ctl) {
297 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
298 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
299 }
300
301 return 0;
302}
303
304int offload_pbe_send_params(struct mixer_ctl *ctl,
305 struct pbe_params *pbe,
306 unsigned param_send_flags)
307{
308 return pbe_send_params(OFFLOAD, (void *)ctl, pbe,
309 param_send_flags);
310}
311
312int hw_acc_pbe_send_params(int fd, struct pbe_params *pbe,
313 unsigned param_send_flags)
314{
315 return pbe_send_params(HW_ACCELERATOR, (void *)&fd,
316 pbe, param_send_flags);
317}
318
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800319void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
320 uint32_t device)
321{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530322 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800323 virtualizer->device = device;
324}
325
326void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
327 bool enable)
328{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530329 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800330 virtualizer->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800331
332#ifdef DTS_EAGLE
333 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
334#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800335}
336
337int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
338{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530339 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800340 return virtualizer->enable_flag;
341}
342
343void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
344 int strength)
345{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530346 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800347 virtualizer->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800348
349#ifdef DTS_EAGLE
350 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
351#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800352}
353
354void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
355 int out_type)
356{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530357 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800358 virtualizer->out_type = out_type;
359}
360
361void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
362 int gain_adjust)
363{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530364 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800365 virtualizer->gain_adjust = gain_adjust;
366}
367
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700368static int virtualizer_send_params(eff_mode_t mode, void *ctl,
369 struct virtualizer_params *virtualizer,
370 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800371{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530372 long param_values[128] = {0};
373 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800374
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530375 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800376 *p_param_values++ = VIRTUALIZER_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700377 *p_param_values++ = virtualizer->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800378 *p_param_values++ = 0; /* num of commands*/
379 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
380 *p_param_values++ = VIRTUALIZER_ENABLE;
381 *p_param_values++ = CONFIG_SET;
382 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
383 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700384 *p_param_values++ = virtualizer->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800385 param_values[2] += 1;
386 }
387 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
388 *p_param_values++ = VIRTUALIZER_STRENGTH;
389 *p_param_values++ = CONFIG_SET;
390 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
391 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700392 *p_param_values++ = virtualizer->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800393 param_values[2] += 1;
394 }
395 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
396 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
397 *p_param_values++ = CONFIG_SET;
398 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
399 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700400 *p_param_values++ = virtualizer->out_type;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800401 param_values[2] += 1;
402 }
403 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
404 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
405 *p_param_values++ = CONFIG_SET;
406 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
407 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700408 *p_param_values++ = virtualizer->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800409 param_values[2] += 1;
410 }
411
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700412 if ((mode == OFFLOAD) && param_values[2] && ctl) {
413 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
414 ARRAY_SIZE(param_values));
415 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
416 ctl && *(int *)ctl) {
417 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
418 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
419 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800420
421 return 0;
422}
423
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700424int offload_virtualizer_send_params(struct mixer_ctl *ctl,
425 struct virtualizer_params *virtualizer,
426 unsigned param_send_flags)
427{
428 return virtualizer_send_params(OFFLOAD, (void *)ctl, virtualizer,
429 param_send_flags);
430}
431
432int hw_acc_virtualizer_send_params(int fd,
433 struct virtualizer_params *virtualizer,
434 unsigned param_send_flags)
435{
436 return virtualizer_send_params(HW_ACCELERATOR, (void *)&fd,
437 virtualizer, param_send_flags);
438}
439
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800440void offload_eq_set_device(struct eq_params *eq, uint32_t device)
441{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530442 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800443 eq->device = device;
444}
445
446void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
447{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530448 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800449 eq->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800450
451#ifdef DTS_EAGLE
452 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
453#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800454}
455
456int offload_eq_get_enable_flag(struct eq_params *eq)
457{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530458 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800459 return eq->enable_flag;
460}
461
462void offload_eq_set_preset(struct eq_params *eq, int preset)
463{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530464 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800465 eq->config.preset_id = preset;
466 eq->config.eq_pregain = Q27_UNITY;
467}
468
469void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
470 const uint16_t *band_freq_list,
471 int *band_gain_list)
472{
473 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530474 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800475 eq->config.num_bands = num_bands;
476 for (i=0; i<num_bands; i++) {
477 eq->per_band_cfg[i].band_idx = i;
478 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
479 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
480 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
481 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
482 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800483
484#ifdef DTS_EAGLE
485 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_SET_PARAM, EFFECT_NO_OP, EFFECT_NO_OP, i, band_gain_list[i] * 100);
486#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800487}
488
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700489static int eq_send_params(eff_mode_t mode, void *ctl, struct eq_params *eq,
490 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800491{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530492 long param_values[128] = {0};
493 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800494 uint32_t i;
495
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530496 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700497 if ((eq->config.preset_id < -1) ||
498 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq->config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800499 ALOGV("No Valid preset to set");
500 return 0;
501 }
502 *p_param_values++ = EQ_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700503 *p_param_values++ = eq->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800504 *p_param_values++ = 0; /* num of commands*/
505 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
506 *p_param_values++ = EQ_ENABLE;
507 *p_param_values++ = CONFIG_SET;
508 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
509 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700510 *p_param_values++ = eq->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800511 param_values[2] += 1;
512 }
513 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
514 *p_param_values++ = EQ_CONFIG;
515 *p_param_values++ = CONFIG_SET;
516 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
517 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700518 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800519 *p_param_values++ =
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700520 map_eq_opensl_preset_2_offload_preset[eq->config.preset_id];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800521 *p_param_values++ = 0;
522 param_values[2] += 1;
523 }
524 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
525 *p_param_values++ = EQ_CONFIG;
526 *p_param_values++ = CONFIG_SET;
527 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
528 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700529 eq->config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
530 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800531 *p_param_values++ = CUSTOM_OPENSL_PRESET;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700532 *p_param_values++ = eq->config.num_bands;
533 for (i=0; i<eq->config.num_bands; i++) {
534 *p_param_values++ = eq->per_band_cfg[i].band_idx;
535 *p_param_values++ = eq->per_band_cfg[i].filter_type;
536 *p_param_values++ = eq->per_band_cfg[i].freq_millihertz;
537 *p_param_values++ = eq->per_band_cfg[i].gain_millibels;
538 *p_param_values++ = eq->per_band_cfg[i].quality_factor;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800539 }
540 param_values[2] += 1;
541 }
542
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700543 if ((mode == OFFLOAD) && param_values[2] && ctl) {
544 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
545 ARRAY_SIZE(param_values));
546 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
547 ctl && *(int *)ctl) {
548 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
549 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
550 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800551
552 return 0;
553}
554
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700555int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params *eq,
556 unsigned param_send_flags)
557{
558 return eq_send_params(OFFLOAD, (void *)ctl, eq, param_send_flags);
559}
560
561int hw_acc_eq_send_params(int fd, struct eq_params *eq,
562 unsigned param_send_flags)
563{
564 return eq_send_params(HW_ACCELERATOR, (void *)&fd, eq,
565 param_send_flags);
566}
567
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800568void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
569{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530570 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800571 reverb->device = device;
572}
573
574void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
575{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530576 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800577 reverb->enable_flag = enable;
578}
579
580int offload_reverb_get_enable_flag(struct reverb_params *reverb)
581{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530582 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800583 return reverb->enable_flag;
584}
585
586void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
587{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530588 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800589 reverb->mode = mode;
590}
591
592void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
593{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530594 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800595 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800596 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800597}
598
599void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
600{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530601 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800602 reverb->wet_mix = wet_mix;
603}
604
605void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
606 int gain_adjust)
607{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530608 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800609 reverb->gain_adjust = gain_adjust;
610}
611
612void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
613{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530614 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800615 reverb->room_level = room_level;
616}
617
618void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
619 int room_hf_level)
620{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530621 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800622 reverb->room_hf_level = room_hf_level;
623}
624
625void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
626{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530627 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800628 reverb->decay_time = decay_time;
629}
630
631void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
632 int decay_hf_ratio)
633{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530634 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800635 reverb->decay_hf_ratio = decay_hf_ratio;
636}
637
638void offload_reverb_set_reflections_level(struct reverb_params *reverb,
639 int reflections_level)
640{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530641 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800642 reverb->reflections_level = reflections_level;
643}
644
645void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
646 int reflections_delay)
647{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530648 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800649 reverb->reflections_delay = reflections_delay;
650}
651
652void offload_reverb_set_reverb_level(struct reverb_params *reverb,
653 int reverb_level)
654{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530655 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800656 reverb->level = reverb_level;
657}
658
659void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
660{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530661 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800662 reverb->delay = delay;
663}
664
665void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
666{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530667 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800668 reverb->diffusion = diffusion;
669}
670
671void offload_reverb_set_density(struct reverb_params *reverb, int density)
672{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530673 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800674 reverb->density = density;
675}
676
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700677static int reverb_send_params(eff_mode_t mode, void *ctl,
678 struct reverb_params *reverb,
679 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800680{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530681 long param_values[128] = {0};
682 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800683
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530684 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800685 *p_param_values++ = REVERB_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700686 *p_param_values++ = reverb->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800687 *p_param_values++ = 0; /* num of commands*/
688
689 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
690 *p_param_values++ = REVERB_ENABLE;
691 *p_param_values++ = CONFIG_SET;
692 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
693 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700694 *p_param_values++ = reverb->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800695 param_values[2] += 1;
696 }
697 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
698 *p_param_values++ = REVERB_MODE;
699 *p_param_values++ = CONFIG_SET;
700 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
701 *p_param_values++ = REVERB_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700702 *p_param_values++ = reverb->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800703 param_values[2] += 1;
704 }
705 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
706 *p_param_values++ = REVERB_PRESET;
707 *p_param_values++ = CONFIG_SET;
708 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
709 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700710 *p_param_values++ = reverb->preset;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800711 param_values[2] += 1;
712 }
713 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
714 *p_param_values++ = REVERB_WET_MIX;
715 *p_param_values++ = CONFIG_SET;
716 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
717 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700718 *p_param_values++ = reverb->wet_mix;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800719 param_values[2] += 1;
720 }
721 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
722 *p_param_values++ = REVERB_GAIN_ADJUST;
723 *p_param_values++ = CONFIG_SET;
724 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
725 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700726 *p_param_values++ = reverb->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800727 param_values[2] += 1;
728 }
729 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
730 *p_param_values++ = REVERB_ROOM_LEVEL;
731 *p_param_values++ = CONFIG_SET;
732 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
733 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700734 *p_param_values++ = reverb->room_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800735 param_values[2] += 1;
736 }
737 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
738 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
739 *p_param_values++ = CONFIG_SET;
740 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
741 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700742 *p_param_values++ = reverb->room_hf_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800743 param_values[2] += 1;
744 }
745 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
746 *p_param_values++ = REVERB_DECAY_TIME;
747 *p_param_values++ = CONFIG_SET;
748 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
749 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700750 *p_param_values++ = reverb->decay_time;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800751 param_values[2] += 1;
752 }
753 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
754 *p_param_values++ = REVERB_DECAY_HF_RATIO;
755 *p_param_values++ = CONFIG_SET;
756 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
757 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700758 *p_param_values++ = reverb->decay_hf_ratio;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800759 param_values[2] += 1;
760 }
761 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
762 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
763 *p_param_values++ = CONFIG_SET;
764 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
765 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700766 *p_param_values++ = reverb->reflections_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800767 param_values[2] += 1;
768 }
769 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
770 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
771 *p_param_values++ = CONFIG_SET;
772 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
773 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700774 *p_param_values++ = reverb->reflections_delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800775 param_values[2] += 1;
776 }
777 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
778 *p_param_values++ = REVERB_LEVEL;
779 *p_param_values++ = CONFIG_SET;
780 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
781 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700782 *p_param_values++ = reverb->level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800783 param_values[2] += 1;
784 }
785 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
786 *p_param_values++ = REVERB_DELAY;
787 *p_param_values++ = CONFIG_SET;
788 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
789 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700790 *p_param_values++ = reverb->delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800791 param_values[2] += 1;
792 }
793 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
794 *p_param_values++ = REVERB_DIFFUSION;
795 *p_param_values++ = CONFIG_SET;
796 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
797 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700798 *p_param_values++ = reverb->diffusion;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800799 param_values[2] += 1;
800 }
801 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
802 *p_param_values++ = REVERB_DENSITY;
803 *p_param_values++ = CONFIG_SET;
804 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
805 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700806 *p_param_values++ = reverb->density;
807 param_values[2] += 1;
808 }
809
810 if ((mode == OFFLOAD) && param_values[2] && ctl) {
811 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
812 ARRAY_SIZE(param_values));
813 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
814 ctl && *(int *)ctl) {
815 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
816 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
817 }
818
819 return 0;
820}
821
822int offload_reverb_send_params(struct mixer_ctl *ctl,
823 struct reverb_params *reverb,
824 unsigned param_send_flags)
825{
826 return reverb_send_params(OFFLOAD, (void *)ctl, reverb,
827 param_send_flags);
828}
829
830int hw_acc_reverb_send_params(int fd, struct reverb_params *reverb,
831 unsigned param_send_flags)
832{
833 return reverb_send_params(HW_ACCELERATOR, (void *)&fd,
834 reverb, param_send_flags);
835}
836
837void offload_soft_volume_set_enable(struct soft_volume_params *vol, bool enable)
838{
839 ALOGV("%s", __func__);
840 vol->enable_flag = enable;
841}
842
843void offload_soft_volume_set_gain_master(struct soft_volume_params *vol, int gain)
844{
845 ALOGV("%s", __func__);
846 vol->master_gain = gain;
847}
848
849void offload_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
850 int l_gain, int r_gain)
851{
852 ALOGV("%s", __func__);
853 vol->left_gain = l_gain;
854 vol->right_gain = r_gain;
855}
856
857int offload_soft_volume_send_params(struct mixer_ctl *ctl,
858 struct soft_volume_params vol,
859 unsigned param_send_flags)
860{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530861 long param_values[128] = {0};
862 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700863
864 ALOGV("%s", __func__);
865 *p_param_values++ = SOFT_VOLUME_MODULE;
866 *p_param_values++ = 0;
867 *p_param_values++ = 0; /* num of commands*/
868 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_ENABLE_FLAG) {
869 *p_param_values++ = SOFT_VOLUME_ENABLE;
870 *p_param_values++ = CONFIG_SET;
871 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
872 *p_param_values++ = SOFT_VOLUME_ENABLE_PARAM_LEN;
873 *p_param_values++ = vol.enable_flag;
874 param_values[2] += 1;
875 }
876 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_MASTER) {
877 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER;
878 *p_param_values++ = CONFIG_SET;
879 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
880 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER_PARAM_LEN;
881 *p_param_values++ = vol.master_gain;
882 param_values[2] += 1;
883 }
884 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_2CH) {
885 *p_param_values++ = SOFT_VOLUME_GAIN_2CH;
886 *p_param_values++ = CONFIG_SET;
887 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
888 *p_param_values++ = SOFT_VOLUME_GAIN_2CH_PARAM_LEN;
889 *p_param_values++ = vol.left_gain;
890 *p_param_values++ = vol.right_gain;
891 param_values[2] += 1;
892 }
893
894 if (param_values[2] && ctl)
895 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
896
897 return 0;
898}
899
900void offload_transition_soft_volume_set_enable(struct soft_volume_params *vol,
901 bool enable)
902{
903 ALOGV("%s", __func__);
904 vol->enable_flag = enable;
905}
906
907void offload_transition_soft_volume_set_gain_master(struct soft_volume_params *vol,
908 int gain)
909{
910 ALOGV("%s", __func__);
911 vol->master_gain = gain;
912}
913
914void offload_transition_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
915 int l_gain, int r_gain)
916{
917 ALOGV("%s", __func__);
918 vol->left_gain = l_gain;
919 vol->right_gain = r_gain;
920}
921
922int offload_transition_soft_volume_send_params(struct mixer_ctl *ctl,
923 struct soft_volume_params vol,
924 unsigned param_send_flags)
925{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530926 long param_values[128] = {0};
927 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700928
929 ALOGV("%s", __func__);
930 *p_param_values++ = SOFT_VOLUME2_MODULE;
931 *p_param_values++ = 0;
932 *p_param_values++ = 0; /* num of commands*/
933 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_ENABLE_FLAG) {
934 *p_param_values++ = SOFT_VOLUME2_ENABLE;
935 *p_param_values++ = CONFIG_SET;
936 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
937 *p_param_values++ = SOFT_VOLUME2_ENABLE_PARAM_LEN;
938 *p_param_values++ = vol.enable_flag;
939 param_values[2] += 1;
940 }
941 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_MASTER) {
942 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER;
943 *p_param_values++ = CONFIG_SET;
944 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
945 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER_PARAM_LEN;
946 *p_param_values++ = vol.master_gain;
947 param_values[2] += 1;
948 }
949 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_2CH) {
950 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH;
951 *p_param_values++ = CONFIG_SET;
952 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
953 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH_PARAM_LEN;
954 *p_param_values++ = vol.left_gain;
955 *p_param_values++ = vol.right_gain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800956 param_values[2] += 1;
957 }
958
959 if (param_values[2] && ctl)
960 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
961
962 return 0;
963}
Alexy Josephd464f3b2014-11-18 16:14:41 -0800964
965static int hpx_send_params(eff_mode_t mode, void *ctl,
966 unsigned param_send_flags)
967{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530968 long param_values[128] = {0};
969 long *p_param_values = param_values;
Alexy Josephd464f3b2014-11-18 16:14:41 -0800970
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}