blob: 410164769857bce79dcc494b58c22f23fd839b9a [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;
Weiyin Jiang26c41bd2019-05-23 01:52:13 +0800267 int i;
268 int32_t *p_coeffs = NULL;
269 uint32_t lpf_len = 0, hpf_len = 0, bpf_len = 0;
270 uint32_t bsf_len = 0, tsf_len = 0, total_coeffs_len = 0;
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800271
272 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
273 *p_param_values++ = PBE_MODULE;
274 *p_param_values++ = pbe->device;
275 *p_param_values++ = 0; /* num of commands*/
276 if (param_send_flags & OFFLOAD_SEND_PBE_ENABLE_FLAG) {
277 *p_param_values++ = PBE_ENABLE;
278 *p_param_values++ = CONFIG_SET;
279 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
280 *p_param_values++ = PBE_ENABLE_PARAM_LEN;
281 *p_param_values++ = pbe->enable_flag;
282 param_values[2] += 1;
283 }
284 if (param_send_flags & OFFLOAD_SEND_PBE_CONFIG) {
285 *p_param_values++ = PBE_CONFIG;
286 *p_param_values++ = CONFIG_SET;
287 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
288 *p_param_values++ = pbe->cfg_len;
Weiyin Jiang26c41bd2019-05-23 01:52:13 +0800289 *p_param_values++ = pbe->config.real_bass_mix;
290 *p_param_values++ = pbe->config.bass_color_control;
291 *p_param_values++ = pbe->config.main_chain_delay;
292 *p_param_values++ = pbe->config.xover_filter_order;
293 *p_param_values++ = pbe->config.bandpass_filter_order;
294 *p_param_values++ = pbe->config.drc_delay;
295 *p_param_values++ = pbe->config.rms_tav;
296 *p_param_values++ = pbe->config.exp_threshold;
297 *p_param_values++ = pbe->config.exp_slope;
298 *p_param_values++ = pbe->config.comp_threshold;
299 *p_param_values++ = pbe->config.comp_slope;
300 *p_param_values++ = pbe->config.makeup_gain;
301 *p_param_values++ = pbe->config.comp_attack;
302 *p_param_values++ = pbe->config.comp_release;
303 *p_param_values++ = pbe->config.exp_attack;
304 *p_param_values++ = pbe->config.exp_release;
305 *p_param_values++ = pbe->config.limiter_bass_threshold;
306 *p_param_values++ = pbe->config.limiter_high_threshold;
307 *p_param_values++ = pbe->config.limiter_bass_makeup_gain;
308 *p_param_values++ = pbe->config.limiter_high_makeup_gain;
309 *p_param_values++ = pbe->config.limiter_bass_gc;
310 *p_param_values++ = pbe->config.limiter_high_gc;
311 *p_param_values++ = pbe->config.limiter_delay;
312 *p_param_values++ = pbe->config.reserved;
313
314 p_coeffs = &pbe->config.p1LowPassCoeffs[0];
315 lpf_len = (pbe->config.xover_filter_order == 3) ? 10 : 5;
316 hpf_len = (pbe->config.xover_filter_order == 3) ? 10 : 5;
317 bpf_len = pbe->config.bandpass_filter_order * 5;
318 bsf_len = 5;
319 tsf_len = 5;
320 total_coeffs_len = lpf_len + hpf_len + bpf_len + bsf_len + tsf_len;
321
322 for (i = 0; i < total_coeffs_len; i++) {
323 *p_param_values++ = *p_coeffs++;
324 }
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800325 param_values[2] += 1;
326 }
327
328 if ((mode == OFFLOAD) && param_values[2] && ctl) {
329 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
330 ARRAY_SIZE(param_values));
331 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
332 ctl && *(int *)ctl) {
333 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
334 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
335 }
336
337 return 0;
338}
339
340int offload_pbe_send_params(struct mixer_ctl *ctl,
341 struct pbe_params *pbe,
342 unsigned param_send_flags)
343{
344 return pbe_send_params(OFFLOAD, (void *)ctl, pbe,
345 param_send_flags);
346}
347
348int hw_acc_pbe_send_params(int fd, struct pbe_params *pbe,
349 unsigned param_send_flags)
350{
351 return pbe_send_params(HW_ACCELERATOR, (void *)&fd,
352 pbe, param_send_flags);
353}
354
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800355void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
356 uint32_t device)
357{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530358 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800359 virtualizer->device = device;
360}
361
362void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
363 bool enable)
364{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530365 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800366 virtualizer->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800367
368#ifdef DTS_EAGLE
369 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
370#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800371}
372
373int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
374{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530375 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800376 return virtualizer->enable_flag;
377}
378
379void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
380 int strength)
381{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530382 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800383 virtualizer->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800384
385#ifdef DTS_EAGLE
386 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
387#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800388}
389
390void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
391 int out_type)
392{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530393 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800394 virtualizer->out_type = out_type;
395}
396
397void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
398 int gain_adjust)
399{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530400 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800401 virtualizer->gain_adjust = gain_adjust;
402}
403
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700404static int virtualizer_send_params(eff_mode_t mode, void *ctl,
405 struct virtualizer_params *virtualizer,
406 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800407{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530408 long param_values[128] = {0};
409 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800410
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530411 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800412 *p_param_values++ = VIRTUALIZER_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700413 *p_param_values++ = virtualizer->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800414 *p_param_values++ = 0; /* num of commands*/
415 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
416 *p_param_values++ = VIRTUALIZER_ENABLE;
417 *p_param_values++ = CONFIG_SET;
418 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
419 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700420 *p_param_values++ = virtualizer->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800421 param_values[2] += 1;
422 }
423 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
424 *p_param_values++ = VIRTUALIZER_STRENGTH;
425 *p_param_values++ = CONFIG_SET;
426 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
427 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700428 *p_param_values++ = virtualizer->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800429 param_values[2] += 1;
430 }
431 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
432 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
433 *p_param_values++ = CONFIG_SET;
434 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
435 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700436 *p_param_values++ = virtualizer->out_type;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800437 param_values[2] += 1;
438 }
439 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
440 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
441 *p_param_values++ = CONFIG_SET;
442 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
443 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700444 *p_param_values++ = virtualizer->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800445 param_values[2] += 1;
446 }
447
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700448 if ((mode == OFFLOAD) && param_values[2] && ctl) {
449 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
450 ARRAY_SIZE(param_values));
451 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
452 ctl && *(int *)ctl) {
453 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
454 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
455 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800456
457 return 0;
458}
459
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700460int offload_virtualizer_send_params(struct mixer_ctl *ctl,
461 struct virtualizer_params *virtualizer,
462 unsigned param_send_flags)
463{
464 return virtualizer_send_params(OFFLOAD, (void *)ctl, virtualizer,
465 param_send_flags);
466}
467
468int hw_acc_virtualizer_send_params(int fd,
469 struct virtualizer_params *virtualizer,
470 unsigned param_send_flags)
471{
472 return virtualizer_send_params(HW_ACCELERATOR, (void *)&fd,
473 virtualizer, param_send_flags);
474}
475
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800476void offload_eq_set_device(struct eq_params *eq, uint32_t device)
477{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530478 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800479 eq->device = device;
480}
481
482void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
483{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530484 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800485 eq->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800486
487#ifdef DTS_EAGLE
488 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
489#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800490}
491
492int offload_eq_get_enable_flag(struct eq_params *eq)
493{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530494 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800495 return eq->enable_flag;
496}
497
498void offload_eq_set_preset(struct eq_params *eq, int preset)
499{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530500 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800501 eq->config.preset_id = preset;
502 eq->config.eq_pregain = Q27_UNITY;
503}
504
505void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
506 const uint16_t *band_freq_list,
507 int *band_gain_list)
508{
509 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530510 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800511 eq->config.num_bands = num_bands;
512 for (i=0; i<num_bands; i++) {
513 eq->per_band_cfg[i].band_idx = i;
514 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
515 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
516 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
517 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
518 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800519
520#ifdef DTS_EAGLE
521 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_SET_PARAM, EFFECT_NO_OP, EFFECT_NO_OP, i, band_gain_list[i] * 100);
522#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800523}
524
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700525static int eq_send_params(eff_mode_t mode, void *ctl, struct eq_params *eq,
526 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800527{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530528 long param_values[128] = {0};
529 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800530 uint32_t i;
531
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530532 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700533 if ((eq->config.preset_id < -1) ||
534 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq->config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800535 ALOGV("No Valid preset to set");
536 return 0;
537 }
538 *p_param_values++ = EQ_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700539 *p_param_values++ = eq->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800540 *p_param_values++ = 0; /* num of commands*/
541 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
542 *p_param_values++ = EQ_ENABLE;
543 *p_param_values++ = CONFIG_SET;
544 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
545 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700546 *p_param_values++ = eq->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800547 param_values[2] += 1;
548 }
549 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
550 *p_param_values++ = EQ_CONFIG;
551 *p_param_values++ = CONFIG_SET;
552 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
553 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700554 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800555 *p_param_values++ =
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700556 map_eq_opensl_preset_2_offload_preset[eq->config.preset_id];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800557 *p_param_values++ = 0;
558 param_values[2] += 1;
559 }
560 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
561 *p_param_values++ = EQ_CONFIG;
562 *p_param_values++ = CONFIG_SET;
563 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
564 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700565 eq->config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
566 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800567 *p_param_values++ = CUSTOM_OPENSL_PRESET;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700568 *p_param_values++ = eq->config.num_bands;
569 for (i=0; i<eq->config.num_bands; i++) {
570 *p_param_values++ = eq->per_band_cfg[i].band_idx;
571 *p_param_values++ = eq->per_band_cfg[i].filter_type;
Weiyin Jiang26c41bd2019-05-23 01:52:13 +0800572 *p_param_values++ = eq->per_band_cfg[i].freq_millihertz;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700573 *p_param_values++ = eq->per_band_cfg[i].gain_millibels;
574 *p_param_values++ = eq->per_band_cfg[i].quality_factor;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800575 }
576 param_values[2] += 1;
577 }
578
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700579 if ((mode == OFFLOAD) && param_values[2] && ctl) {
580 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
581 ARRAY_SIZE(param_values));
582 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
583 ctl && *(int *)ctl) {
584 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
585 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
586 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800587
588 return 0;
589}
590
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700591int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params *eq,
592 unsigned param_send_flags)
593{
594 return eq_send_params(OFFLOAD, (void *)ctl, eq, param_send_flags);
595}
596
597int hw_acc_eq_send_params(int fd, struct eq_params *eq,
598 unsigned param_send_flags)
599{
600 return eq_send_params(HW_ACCELERATOR, (void *)&fd, eq,
601 param_send_flags);
602}
603
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800604void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
605{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530606 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800607 reverb->device = device;
608}
609
610void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
611{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530612 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800613 reverb->enable_flag = enable;
614}
615
616int offload_reverb_get_enable_flag(struct reverb_params *reverb)
617{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530618 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800619 return reverb->enable_flag;
620}
621
622void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
623{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530624 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800625 reverb->mode = mode;
626}
627
628void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
629{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530630 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800631 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800632 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800633}
634
635void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
636{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530637 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800638 reverb->wet_mix = wet_mix;
639}
640
641void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
642 int gain_adjust)
643{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530644 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800645 reverb->gain_adjust = gain_adjust;
646}
647
648void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
649{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530650 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800651 reverb->room_level = room_level;
652}
653
654void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
655 int room_hf_level)
656{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530657 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800658 reverb->room_hf_level = room_hf_level;
659}
660
661void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
662{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530663 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800664 reverb->decay_time = decay_time;
665}
666
667void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
668 int decay_hf_ratio)
669{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530670 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800671 reverb->decay_hf_ratio = decay_hf_ratio;
672}
673
674void offload_reverb_set_reflections_level(struct reverb_params *reverb,
675 int reflections_level)
676{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530677 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800678 reverb->reflections_level = reflections_level;
679}
680
681void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
682 int reflections_delay)
683{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530684 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800685 reverb->reflections_delay = reflections_delay;
686}
687
688void offload_reverb_set_reverb_level(struct reverb_params *reverb,
689 int reverb_level)
690{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530691 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800692 reverb->level = reverb_level;
693}
694
695void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
696{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530697 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800698 reverb->delay = delay;
699}
700
701void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
702{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530703 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800704 reverb->diffusion = diffusion;
705}
706
707void offload_reverb_set_density(struct reverb_params *reverb, int density)
708{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530709 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800710 reverb->density = density;
711}
712
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700713static int reverb_send_params(eff_mode_t mode, void *ctl,
714 struct reverb_params *reverb,
715 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800716{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530717 long param_values[128] = {0};
718 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800719
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530720 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800721 *p_param_values++ = REVERB_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700722 *p_param_values++ = reverb->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800723 *p_param_values++ = 0; /* num of commands*/
724
725 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
726 *p_param_values++ = REVERB_ENABLE;
727 *p_param_values++ = CONFIG_SET;
728 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
729 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700730 *p_param_values++ = reverb->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800731 param_values[2] += 1;
732 }
733 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
734 *p_param_values++ = REVERB_MODE;
735 *p_param_values++ = CONFIG_SET;
736 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
737 *p_param_values++ = REVERB_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700738 *p_param_values++ = reverb->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800739 param_values[2] += 1;
740 }
741 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
742 *p_param_values++ = REVERB_PRESET;
743 *p_param_values++ = CONFIG_SET;
744 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
745 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700746 *p_param_values++ = reverb->preset;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800747 param_values[2] += 1;
748 }
749 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
750 *p_param_values++ = REVERB_WET_MIX;
751 *p_param_values++ = CONFIG_SET;
752 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
753 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700754 *p_param_values++ = reverb->wet_mix;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800755 param_values[2] += 1;
756 }
757 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
758 *p_param_values++ = REVERB_GAIN_ADJUST;
759 *p_param_values++ = CONFIG_SET;
760 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
761 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700762 *p_param_values++ = reverb->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800763 param_values[2] += 1;
764 }
765 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
766 *p_param_values++ = REVERB_ROOM_LEVEL;
767 *p_param_values++ = CONFIG_SET;
768 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
769 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700770 *p_param_values++ = reverb->room_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800771 param_values[2] += 1;
772 }
773 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
774 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
775 *p_param_values++ = CONFIG_SET;
776 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
777 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700778 *p_param_values++ = reverb->room_hf_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800779 param_values[2] += 1;
780 }
781 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
782 *p_param_values++ = REVERB_DECAY_TIME;
783 *p_param_values++ = CONFIG_SET;
784 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
785 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700786 *p_param_values++ = reverb->decay_time;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800787 param_values[2] += 1;
788 }
789 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
790 *p_param_values++ = REVERB_DECAY_HF_RATIO;
791 *p_param_values++ = CONFIG_SET;
792 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
793 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700794 *p_param_values++ = reverb->decay_hf_ratio;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800795 param_values[2] += 1;
796 }
797 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
798 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
799 *p_param_values++ = CONFIG_SET;
800 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
801 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700802 *p_param_values++ = reverb->reflections_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800803 param_values[2] += 1;
804 }
805 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
806 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
807 *p_param_values++ = CONFIG_SET;
808 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
809 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700810 *p_param_values++ = reverb->reflections_delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800811 param_values[2] += 1;
812 }
813 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
814 *p_param_values++ = REVERB_LEVEL;
815 *p_param_values++ = CONFIG_SET;
816 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
817 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700818 *p_param_values++ = reverb->level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800819 param_values[2] += 1;
820 }
821 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
822 *p_param_values++ = REVERB_DELAY;
823 *p_param_values++ = CONFIG_SET;
824 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
825 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700826 *p_param_values++ = reverb->delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800827 param_values[2] += 1;
828 }
829 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
830 *p_param_values++ = REVERB_DIFFUSION;
831 *p_param_values++ = CONFIG_SET;
832 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
833 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700834 *p_param_values++ = reverb->diffusion;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800835 param_values[2] += 1;
836 }
837 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
838 *p_param_values++ = REVERB_DENSITY;
839 *p_param_values++ = CONFIG_SET;
840 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
841 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700842 *p_param_values++ = reverb->density;
843 param_values[2] += 1;
844 }
845
846 if ((mode == OFFLOAD) && param_values[2] && ctl) {
847 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
848 ARRAY_SIZE(param_values));
849 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
850 ctl && *(int *)ctl) {
851 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
852 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
853 }
854
855 return 0;
856}
857
858int offload_reverb_send_params(struct mixer_ctl *ctl,
859 struct reverb_params *reverb,
860 unsigned param_send_flags)
861{
862 return reverb_send_params(OFFLOAD, (void *)ctl, reverb,
863 param_send_flags);
864}
865
866int hw_acc_reverb_send_params(int fd, struct reverb_params *reverb,
867 unsigned param_send_flags)
868{
869 return reverb_send_params(HW_ACCELERATOR, (void *)&fd,
870 reverb, param_send_flags);
871}
872
873void offload_soft_volume_set_enable(struct soft_volume_params *vol, bool enable)
874{
875 ALOGV("%s", __func__);
876 vol->enable_flag = enable;
877}
878
879void offload_soft_volume_set_gain_master(struct soft_volume_params *vol, int gain)
880{
881 ALOGV("%s", __func__);
882 vol->master_gain = gain;
883}
884
885void offload_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
886 int l_gain, int r_gain)
887{
888 ALOGV("%s", __func__);
889 vol->left_gain = l_gain;
890 vol->right_gain = r_gain;
891}
892
893int offload_soft_volume_send_params(struct mixer_ctl *ctl,
894 struct soft_volume_params vol,
895 unsigned param_send_flags)
896{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530897 long param_values[128] = {0};
898 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700899
900 ALOGV("%s", __func__);
901 *p_param_values++ = SOFT_VOLUME_MODULE;
902 *p_param_values++ = 0;
903 *p_param_values++ = 0; /* num of commands*/
904 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_ENABLE_FLAG) {
905 *p_param_values++ = SOFT_VOLUME_ENABLE;
906 *p_param_values++ = CONFIG_SET;
907 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
908 *p_param_values++ = SOFT_VOLUME_ENABLE_PARAM_LEN;
909 *p_param_values++ = vol.enable_flag;
910 param_values[2] += 1;
911 }
912 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_MASTER) {
913 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER;
914 *p_param_values++ = CONFIG_SET;
915 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
916 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER_PARAM_LEN;
917 *p_param_values++ = vol.master_gain;
918 param_values[2] += 1;
919 }
920 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_2CH) {
921 *p_param_values++ = SOFT_VOLUME_GAIN_2CH;
922 *p_param_values++ = CONFIG_SET;
923 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
924 *p_param_values++ = SOFT_VOLUME_GAIN_2CH_PARAM_LEN;
925 *p_param_values++ = vol.left_gain;
926 *p_param_values++ = vol.right_gain;
927 param_values[2] += 1;
928 }
929
930 if (param_values[2] && ctl)
931 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
932
933 return 0;
934}
935
936void offload_transition_soft_volume_set_enable(struct soft_volume_params *vol,
937 bool enable)
938{
939 ALOGV("%s", __func__);
940 vol->enable_flag = enable;
941}
942
943void offload_transition_soft_volume_set_gain_master(struct soft_volume_params *vol,
944 int gain)
945{
946 ALOGV("%s", __func__);
947 vol->master_gain = gain;
948}
949
950void offload_transition_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
951 int l_gain, int r_gain)
952{
953 ALOGV("%s", __func__);
954 vol->left_gain = l_gain;
955 vol->right_gain = r_gain;
956}
957
958int offload_transition_soft_volume_send_params(struct mixer_ctl *ctl,
959 struct soft_volume_params vol,
960 unsigned param_send_flags)
961{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530962 long param_values[128] = {0};
963 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700964
965 ALOGV("%s", __func__);
966 *p_param_values++ = SOFT_VOLUME2_MODULE;
967 *p_param_values++ = 0;
968 *p_param_values++ = 0; /* num of commands*/
969 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_ENABLE_FLAG) {
970 *p_param_values++ = SOFT_VOLUME2_ENABLE;
971 *p_param_values++ = CONFIG_SET;
972 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
973 *p_param_values++ = SOFT_VOLUME2_ENABLE_PARAM_LEN;
974 *p_param_values++ = vol.enable_flag;
975 param_values[2] += 1;
976 }
977 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_MASTER) {
978 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER;
979 *p_param_values++ = CONFIG_SET;
980 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
981 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER_PARAM_LEN;
982 *p_param_values++ = vol.master_gain;
983 param_values[2] += 1;
984 }
985 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_2CH) {
986 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH;
987 *p_param_values++ = CONFIG_SET;
988 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
989 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH_PARAM_LEN;
990 *p_param_values++ = vol.left_gain;
991 *p_param_values++ = vol.right_gain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800992 param_values[2] += 1;
993 }
994
995 if (param_values[2] && ctl)
996 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
997
998 return 0;
999}
Alexy Josephd464f3b2014-11-18 16:14:41 -08001000
1001static int hpx_send_params(eff_mode_t mode, void *ctl,
1002 unsigned param_send_flags)
1003{
Manish Dewangan338c50a2017-09-12 15:22:03 +05301004 long param_values[128] = {0};
1005 long *p_param_values = param_values;
Alexy Josephd464f3b2014-11-18 16:14:41 -08001006
1007 ALOGV("%s", __func__);
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +05301008 if (!ctl) {
1009 ALOGE("%s: ctl is NULL, return invalid", __func__);
1010 return -EINVAL;
1011 }
1012
Alexy Josephd464f3b2014-11-18 16:14:41 -08001013 if (param_send_flags & OFFLOAD_SEND_HPX_STATE_OFF) {
1014 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
1015 *p_param_values++ = 0; /* hpx off*/
1016 } else if (param_send_flags & OFFLOAD_SEND_HPX_STATE_ON) {
1017 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
1018 *p_param_values++ = 1; /* hpx on*/
1019 }
1020
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +05301021 if (mode == OFFLOAD)
Alexy Josephd464f3b2014-11-18 16:14:41 -08001022 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
1023 else {
1024 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
1025 ALOGE("%s: sending h/w acc hpx state params fail[%d]", __func__, errno);
1026 }
1027 return 0;
1028}
1029
1030int offload_hpx_send_params(struct mixer_ctl *ctl, unsigned param_send_flags)
1031{
1032 return hpx_send_params(OFFLOAD, (void *)ctl, param_send_flags);
1033}
1034
1035int hw_acc_hpx_send_params(int fd, unsigned param_send_flags)
1036{
1037 return hpx_send_params(HW_ACCELERATOR, (void *)&fd, param_send_flags);
1038}