blob: 93f2329a05226a08eceaecab82fb8ad26416bf55 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Akhil Karuturi60c23472020-05-19 22:19:00 -07002 * Copyright (c) 2013-2015, 2019-2020 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
Akhil Karuturi60c23472020-05-19 22:19:00 -0700178static inline long get_config_set_param()
179{
180 long config_param = 0;
181
182#ifdef AUDIO_GKI_ENABLED
183 config_param = AUDIO_EFFECTS_CONFIG_SET;
184#else
185 config_param = CONFIG_SET;
186#endif
187
188 return config_param;
189}
190
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700191static int bassboost_send_params(eff_mode_t mode, void *ctl,
192 struct bass_boost_params *bassboost,
193 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800194{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530195 long param_values[128] = {0};
196 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800197
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530198 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800199 *p_param_values++ = BASS_BOOST_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700200 *p_param_values++ = bassboost->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800201 *p_param_values++ = 0; /* num of commands*/
202 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
203 *p_param_values++ = BASS_BOOST_ENABLE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700204 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800205 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
206 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700207 *p_param_values++ = bassboost->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800208 param_values[2] += 1;
209 }
210 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
211 *p_param_values++ = BASS_BOOST_STRENGTH;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700212 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800213 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
214 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700215 *p_param_values++ = bassboost->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800216 param_values[2] += 1;
217 }
218 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
219 *p_param_values++ = BASS_BOOST_MODE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700220 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800221 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
222 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700223 *p_param_values++ = bassboost->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800224 param_values[2] += 1;
225 }
226
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700227 if ((mode == OFFLOAD) && param_values[2] && ctl) {
228 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
229 ARRAY_SIZE(param_values));
230 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
231 ctl && *(int *)ctl) {
232 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
233 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
234 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800235
236 return 0;
237}
238
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700239int offload_bassboost_send_params(struct mixer_ctl *ctl,
240 struct bass_boost_params *bassboost,
241 unsigned param_send_flags)
242{
243 return bassboost_send_params(OFFLOAD, (void *)ctl, bassboost,
244 param_send_flags);
245}
246
247int hw_acc_bassboost_send_params(int fd, struct bass_boost_params *bassboost,
248 unsigned param_send_flags)
249{
250 return bassboost_send_params(HW_ACCELERATOR, (void *)&fd,
251 bassboost, param_send_flags);
252}
253
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800254void offload_pbe_set_device(struct pbe_params *pbe,
255 uint32_t device)
256{
257 ALOGV("%s: device=%d", __func__, device);
258 pbe->device = device;
259}
260
261void offload_pbe_set_enable_flag(struct pbe_params *pbe,
262 bool enable)
263{
264 ALOGV("%s: enable=%d", __func__, enable);
265 pbe->enable_flag = enable;
266}
267
268int offload_pbe_get_enable_flag(struct pbe_params *pbe)
269{
270 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
271 return pbe->enable_flag;
272}
273
274static int pbe_send_params(eff_mode_t mode, void *ctl,
275 struct pbe_params *pbe,
276 unsigned param_send_flags)
277{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530278 long param_values[128] = {0};
279 long *p_param_values = param_values;
Weiyin Jiang26c41bd2019-05-23 01:52:13 +0800280 int i;
281 int32_t *p_coeffs = NULL;
282 uint32_t lpf_len = 0, hpf_len = 0, bpf_len = 0;
283 uint32_t bsf_len = 0, tsf_len = 0, total_coeffs_len = 0;
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800284
285 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
286 *p_param_values++ = PBE_MODULE;
287 *p_param_values++ = pbe->device;
288 *p_param_values++ = 0; /* num of commands*/
289 if (param_send_flags & OFFLOAD_SEND_PBE_ENABLE_FLAG) {
290 *p_param_values++ = PBE_ENABLE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700291 *p_param_values++ = get_config_set_param();
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800292 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
293 *p_param_values++ = PBE_ENABLE_PARAM_LEN;
294 *p_param_values++ = pbe->enable_flag;
295 param_values[2] += 1;
296 }
297 if (param_send_flags & OFFLOAD_SEND_PBE_CONFIG) {
298 *p_param_values++ = PBE_CONFIG;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700299 *p_param_values++ = get_config_set_param();
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800300 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
301 *p_param_values++ = pbe->cfg_len;
Weiyin Jiang26c41bd2019-05-23 01:52:13 +0800302 *p_param_values++ = pbe->config.real_bass_mix;
303 *p_param_values++ = pbe->config.bass_color_control;
304 *p_param_values++ = pbe->config.main_chain_delay;
305 *p_param_values++ = pbe->config.xover_filter_order;
306 *p_param_values++ = pbe->config.bandpass_filter_order;
307 *p_param_values++ = pbe->config.drc_delay;
308 *p_param_values++ = pbe->config.rms_tav;
309 *p_param_values++ = pbe->config.exp_threshold;
310 *p_param_values++ = pbe->config.exp_slope;
311 *p_param_values++ = pbe->config.comp_threshold;
312 *p_param_values++ = pbe->config.comp_slope;
313 *p_param_values++ = pbe->config.makeup_gain;
314 *p_param_values++ = pbe->config.comp_attack;
315 *p_param_values++ = pbe->config.comp_release;
316 *p_param_values++ = pbe->config.exp_attack;
317 *p_param_values++ = pbe->config.exp_release;
318 *p_param_values++ = pbe->config.limiter_bass_threshold;
319 *p_param_values++ = pbe->config.limiter_high_threshold;
320 *p_param_values++ = pbe->config.limiter_bass_makeup_gain;
321 *p_param_values++ = pbe->config.limiter_high_makeup_gain;
322 *p_param_values++ = pbe->config.limiter_bass_gc;
323 *p_param_values++ = pbe->config.limiter_high_gc;
324 *p_param_values++ = pbe->config.limiter_delay;
325 *p_param_values++ = pbe->config.reserved;
326
327 p_coeffs = &pbe->config.p1LowPassCoeffs[0];
328 lpf_len = (pbe->config.xover_filter_order == 3) ? 10 : 5;
329 hpf_len = (pbe->config.xover_filter_order == 3) ? 10 : 5;
330 bpf_len = pbe->config.bandpass_filter_order * 5;
331 bsf_len = 5;
332 tsf_len = 5;
333 total_coeffs_len = lpf_len + hpf_len + bpf_len + bsf_len + tsf_len;
334
335 for (i = 0; i < total_coeffs_len; i++) {
336 *p_param_values++ = *p_coeffs++;
337 }
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800338 param_values[2] += 1;
339 }
340
341 if ((mode == OFFLOAD) && param_values[2] && ctl) {
342 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
343 ARRAY_SIZE(param_values));
344 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
345 ctl && *(int *)ctl) {
346 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
347 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
348 }
349
350 return 0;
351}
352
353int offload_pbe_send_params(struct mixer_ctl *ctl,
354 struct pbe_params *pbe,
355 unsigned param_send_flags)
356{
357 return pbe_send_params(OFFLOAD, (void *)ctl, pbe,
358 param_send_flags);
359}
360
361int hw_acc_pbe_send_params(int fd, struct pbe_params *pbe,
362 unsigned param_send_flags)
363{
364 return pbe_send_params(HW_ACCELERATOR, (void *)&fd,
365 pbe, param_send_flags);
366}
367
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800368void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
369 uint32_t device)
370{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530371 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800372 virtualizer->device = device;
373}
374
375void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
376 bool enable)
377{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530378 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800379 virtualizer->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800380
381#ifdef DTS_EAGLE
382 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
383#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800384}
385
386int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
387{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530388 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800389 return virtualizer->enable_flag;
390}
391
392void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
393 int strength)
394{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530395 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800396 virtualizer->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800397
398#ifdef DTS_EAGLE
399 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
400#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800401}
402
403void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
404 int out_type)
405{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530406 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800407 virtualizer->out_type = out_type;
408}
409
410void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
411 int gain_adjust)
412{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530413 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800414 virtualizer->gain_adjust = gain_adjust;
415}
416
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700417static int virtualizer_send_params(eff_mode_t mode, void *ctl,
418 struct virtualizer_params *virtualizer,
419 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800420{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530421 long param_values[128] = {0};
422 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800423
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530424 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800425 *p_param_values++ = VIRTUALIZER_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700426 *p_param_values++ = virtualizer->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800427 *p_param_values++ = 0; /* num of commands*/
428 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
429 *p_param_values++ = VIRTUALIZER_ENABLE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700430 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800431 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
432 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700433 *p_param_values++ = virtualizer->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800434 param_values[2] += 1;
435 }
436 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
437 *p_param_values++ = VIRTUALIZER_STRENGTH;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700438 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800439 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
440 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700441 *p_param_values++ = virtualizer->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800442 param_values[2] += 1;
443 }
444 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
445 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700446 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800447 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
448 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700449 *p_param_values++ = virtualizer->out_type;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800450 param_values[2] += 1;
451 }
452 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
453 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700454 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800455 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
456 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700457 *p_param_values++ = virtualizer->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800458 param_values[2] += 1;
459 }
460
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700461 if ((mode == OFFLOAD) && param_values[2] && ctl) {
462 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
463 ARRAY_SIZE(param_values));
464 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
465 ctl && *(int *)ctl) {
466 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
467 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
468 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800469
470 return 0;
471}
472
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700473int offload_virtualizer_send_params(struct mixer_ctl *ctl,
474 struct virtualizer_params *virtualizer,
475 unsigned param_send_flags)
476{
477 return virtualizer_send_params(OFFLOAD, (void *)ctl, virtualizer,
478 param_send_flags);
479}
480
481int hw_acc_virtualizer_send_params(int fd,
482 struct virtualizer_params *virtualizer,
483 unsigned param_send_flags)
484{
485 return virtualizer_send_params(HW_ACCELERATOR, (void *)&fd,
486 virtualizer, param_send_flags);
487}
488
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800489void offload_eq_set_device(struct eq_params *eq, uint32_t device)
490{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530491 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800492 eq->device = device;
493}
494
495void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
496{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530497 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800498 eq->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800499
500#ifdef DTS_EAGLE
501 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
502#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800503}
504
505int offload_eq_get_enable_flag(struct eq_params *eq)
506{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530507 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800508 return eq->enable_flag;
509}
510
511void offload_eq_set_preset(struct eq_params *eq, int preset)
512{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530513 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800514 eq->config.preset_id = preset;
515 eq->config.eq_pregain = Q27_UNITY;
516}
517
518void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
519 const uint16_t *band_freq_list,
520 int *band_gain_list)
521{
522 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530523 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800524 eq->config.num_bands = num_bands;
525 for (i=0; i<num_bands; i++) {
526 eq->per_band_cfg[i].band_idx = i;
527 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
528 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
529 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
530 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800531#ifdef DTS_EAGLE
532 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_SET_PARAM, EFFECT_NO_OP, EFFECT_NO_OP, i, band_gain_list[i] * 100);
533#endif
Weiyin Jiangda604552019-10-11 11:07:39 +0800534 }
535
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800536}
537
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700538static int eq_send_params(eff_mode_t mode, void *ctl, struct eq_params *eq,
539 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800540{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530541 long param_values[128] = {0};
542 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800543 uint32_t i;
544
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530545 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700546 if ((eq->config.preset_id < -1) ||
547 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq->config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800548 ALOGV("No Valid preset to set");
549 return 0;
550 }
551 *p_param_values++ = EQ_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700552 *p_param_values++ = eq->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800553 *p_param_values++ = 0; /* num of commands*/
554 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
555 *p_param_values++ = EQ_ENABLE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700556 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800557 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
558 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700559 *p_param_values++ = eq->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800560 param_values[2] += 1;
561 }
562 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
563 *p_param_values++ = EQ_CONFIG;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700564 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800565 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
566 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700567 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800568 *p_param_values++ =
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700569 map_eq_opensl_preset_2_offload_preset[eq->config.preset_id];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800570 *p_param_values++ = 0;
571 param_values[2] += 1;
572 }
573 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
574 *p_param_values++ = EQ_CONFIG;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700575 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800576 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
577 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700578 eq->config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
579 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800580 *p_param_values++ = CUSTOM_OPENSL_PRESET;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700581 *p_param_values++ = eq->config.num_bands;
582 for (i=0; i<eq->config.num_bands; i++) {
583 *p_param_values++ = eq->per_band_cfg[i].band_idx;
584 *p_param_values++ = eq->per_band_cfg[i].filter_type;
Weiyin Jiang26c41bd2019-05-23 01:52:13 +0800585 *p_param_values++ = eq->per_band_cfg[i].freq_millihertz;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700586 *p_param_values++ = eq->per_band_cfg[i].gain_millibels;
587 *p_param_values++ = eq->per_band_cfg[i].quality_factor;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800588 }
589 param_values[2] += 1;
590 }
591
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700592 if ((mode == OFFLOAD) && param_values[2] && ctl) {
593 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
594 ARRAY_SIZE(param_values));
595 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
596 ctl && *(int *)ctl) {
597 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
598 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
599 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800600
601 return 0;
602}
603
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700604int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params *eq,
605 unsigned param_send_flags)
606{
607 return eq_send_params(OFFLOAD, (void *)ctl, eq, param_send_flags);
608}
609
610int hw_acc_eq_send_params(int fd, struct eq_params *eq,
611 unsigned param_send_flags)
612{
613 return eq_send_params(HW_ACCELERATOR, (void *)&fd, eq,
614 param_send_flags);
615}
616
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800617void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
618{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530619 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800620 reverb->device = device;
621}
622
623void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
624{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530625 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800626 reverb->enable_flag = enable;
627}
628
629int offload_reverb_get_enable_flag(struct reverb_params *reverb)
630{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530631 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800632 return reverb->enable_flag;
633}
634
635void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
636{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530637 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800638 reverb->mode = mode;
639}
640
641void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
642{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530643 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800644 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800645 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800646}
647
648void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
649{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530650 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800651 reverb->wet_mix = wet_mix;
652}
653
654void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
655 int gain_adjust)
656{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530657 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800658 reverb->gain_adjust = gain_adjust;
659}
660
661void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
662{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530663 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800664 reverb->room_level = room_level;
665}
666
667void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
668 int room_hf_level)
669{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530670 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800671 reverb->room_hf_level = room_hf_level;
672}
673
674void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
675{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530676 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800677 reverb->decay_time = decay_time;
678}
679
680void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
681 int decay_hf_ratio)
682{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530683 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800684 reverb->decay_hf_ratio = decay_hf_ratio;
685}
686
687void offload_reverb_set_reflections_level(struct reverb_params *reverb,
688 int reflections_level)
689{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530690 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800691 reverb->reflections_level = reflections_level;
692}
693
694void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
695 int reflections_delay)
696{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530697 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800698 reverb->reflections_delay = reflections_delay;
699}
700
701void offload_reverb_set_reverb_level(struct reverb_params *reverb,
702 int reverb_level)
703{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530704 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800705 reverb->level = reverb_level;
706}
707
708void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
709{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530710 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800711 reverb->delay = delay;
712}
713
714void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
715{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530716 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800717 reverb->diffusion = diffusion;
718}
719
720void offload_reverb_set_density(struct reverb_params *reverb, int density)
721{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530722 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800723 reverb->density = density;
724}
725
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700726static int reverb_send_params(eff_mode_t mode, void *ctl,
727 struct reverb_params *reverb,
728 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800729{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530730 long param_values[128] = {0};
731 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800732
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530733 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800734 *p_param_values++ = REVERB_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700735 *p_param_values++ = reverb->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800736 *p_param_values++ = 0; /* num of commands*/
737
738 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
739 *p_param_values++ = REVERB_ENABLE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700740 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800741 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
742 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700743 *p_param_values++ = reverb->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800744 param_values[2] += 1;
745 }
746 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
747 *p_param_values++ = REVERB_MODE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700748 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800749 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
750 *p_param_values++ = REVERB_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700751 *p_param_values++ = reverb->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800752 param_values[2] += 1;
753 }
754 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
755 *p_param_values++ = REVERB_PRESET;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700756 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800757 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
758 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700759 *p_param_values++ = reverb->preset;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800760 param_values[2] += 1;
761 }
762 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
763 *p_param_values++ = REVERB_WET_MIX;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700764 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800765 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
766 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700767 *p_param_values++ = reverb->wet_mix;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800768 param_values[2] += 1;
769 }
770 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
771 *p_param_values++ = REVERB_GAIN_ADJUST;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700772 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800773 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
774 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700775 *p_param_values++ = reverb->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800776 param_values[2] += 1;
777 }
778 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
779 *p_param_values++ = REVERB_ROOM_LEVEL;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700780 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800781 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
782 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700783 *p_param_values++ = reverb->room_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800784 param_values[2] += 1;
785 }
786 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
787 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700788 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800789 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
790 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700791 *p_param_values++ = reverb->room_hf_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800792 param_values[2] += 1;
793 }
794 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
795 *p_param_values++ = REVERB_DECAY_TIME;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700796 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800797 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
798 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700799 *p_param_values++ = reverb->decay_time;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800800 param_values[2] += 1;
801 }
802 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
803 *p_param_values++ = REVERB_DECAY_HF_RATIO;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700804 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800805 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
806 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700807 *p_param_values++ = reverb->decay_hf_ratio;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800808 param_values[2] += 1;
809 }
810 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
811 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700812 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800813 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
814 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700815 *p_param_values++ = reverb->reflections_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800816 param_values[2] += 1;
817 }
818 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
819 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700820 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800821 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
822 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700823 *p_param_values++ = reverb->reflections_delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800824 param_values[2] += 1;
825 }
826 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
827 *p_param_values++ = REVERB_LEVEL;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700828 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800829 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
830 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700831 *p_param_values++ = reverb->level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800832 param_values[2] += 1;
833 }
834 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
835 *p_param_values++ = REVERB_DELAY;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700836 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800837 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
838 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700839 *p_param_values++ = reverb->delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800840 param_values[2] += 1;
841 }
842 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
843 *p_param_values++ = REVERB_DIFFUSION;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700844 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800845 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
846 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700847 *p_param_values++ = reverb->diffusion;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800848 param_values[2] += 1;
849 }
850 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
851 *p_param_values++ = REVERB_DENSITY;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700852 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800853 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
854 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700855 *p_param_values++ = reverb->density;
856 param_values[2] += 1;
857 }
858
859 if ((mode == OFFLOAD) && param_values[2] && ctl) {
860 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
861 ARRAY_SIZE(param_values));
862 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
863 ctl && *(int *)ctl) {
864 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
865 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
866 }
867
868 return 0;
869}
870
871int offload_reverb_send_params(struct mixer_ctl *ctl,
872 struct reverb_params *reverb,
873 unsigned param_send_flags)
874{
875 return reverb_send_params(OFFLOAD, (void *)ctl, reverb,
876 param_send_flags);
877}
878
879int hw_acc_reverb_send_params(int fd, struct reverb_params *reverb,
880 unsigned param_send_flags)
881{
882 return reverb_send_params(HW_ACCELERATOR, (void *)&fd,
883 reverb, param_send_flags);
884}
885
886void offload_soft_volume_set_enable(struct soft_volume_params *vol, bool enable)
887{
888 ALOGV("%s", __func__);
889 vol->enable_flag = enable;
890}
891
892void offload_soft_volume_set_gain_master(struct soft_volume_params *vol, int gain)
893{
894 ALOGV("%s", __func__);
895 vol->master_gain = gain;
896}
897
898void offload_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
899 int l_gain, int r_gain)
900{
901 ALOGV("%s", __func__);
902 vol->left_gain = l_gain;
903 vol->right_gain = r_gain;
904}
905
906int offload_soft_volume_send_params(struct mixer_ctl *ctl,
907 struct soft_volume_params vol,
908 unsigned param_send_flags)
909{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530910 long param_values[128] = {0};
911 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700912
913 ALOGV("%s", __func__);
914 *p_param_values++ = SOFT_VOLUME_MODULE;
915 *p_param_values++ = 0;
916 *p_param_values++ = 0; /* num of commands*/
917 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_ENABLE_FLAG) {
918 *p_param_values++ = SOFT_VOLUME_ENABLE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700919 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700920 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
921 *p_param_values++ = SOFT_VOLUME_ENABLE_PARAM_LEN;
922 *p_param_values++ = vol.enable_flag;
923 param_values[2] += 1;
924 }
925 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_MASTER) {
926 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700927 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700928 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
929 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER_PARAM_LEN;
930 *p_param_values++ = vol.master_gain;
931 param_values[2] += 1;
932 }
933 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_2CH) {
934 *p_param_values++ = SOFT_VOLUME_GAIN_2CH;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700935 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700936 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
937 *p_param_values++ = SOFT_VOLUME_GAIN_2CH_PARAM_LEN;
938 *p_param_values++ = vol.left_gain;
939 *p_param_values++ = vol.right_gain;
940 param_values[2] += 1;
941 }
942
943 if (param_values[2] && ctl)
944 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
945
946 return 0;
947}
948
949void offload_transition_soft_volume_set_enable(struct soft_volume_params *vol,
950 bool enable)
951{
952 ALOGV("%s", __func__);
953 vol->enable_flag = enable;
954}
955
956void offload_transition_soft_volume_set_gain_master(struct soft_volume_params *vol,
957 int gain)
958{
959 ALOGV("%s", __func__);
960 vol->master_gain = gain;
961}
962
963void offload_transition_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
964 int l_gain, int r_gain)
965{
966 ALOGV("%s", __func__);
967 vol->left_gain = l_gain;
968 vol->right_gain = r_gain;
969}
970
971int offload_transition_soft_volume_send_params(struct mixer_ctl *ctl,
972 struct soft_volume_params vol,
973 unsigned param_send_flags)
974{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530975 long param_values[128] = {0};
976 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700977
978 ALOGV("%s", __func__);
979 *p_param_values++ = SOFT_VOLUME2_MODULE;
980 *p_param_values++ = 0;
981 *p_param_values++ = 0; /* num of commands*/
982 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_ENABLE_FLAG) {
983 *p_param_values++ = SOFT_VOLUME2_ENABLE;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700984 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700985 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
986 *p_param_values++ = SOFT_VOLUME2_ENABLE_PARAM_LEN;
987 *p_param_values++ = vol.enable_flag;
988 param_values[2] += 1;
989 }
990 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_MASTER) {
991 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER;
Akhil Karuturi60c23472020-05-19 22:19:00 -0700992 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700993 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
994 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER_PARAM_LEN;
995 *p_param_values++ = vol.master_gain;
996 param_values[2] += 1;
997 }
998 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_2CH) {
999 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH;
Akhil Karuturi60c23472020-05-19 22:19:00 -07001000 *p_param_values++ = get_config_set_param();
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -07001001 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
1002 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH_PARAM_LEN;
1003 *p_param_values++ = vol.left_gain;
1004 *p_param_values++ = vol.right_gain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001005 param_values[2] += 1;
1006 }
1007
1008 if (param_values[2] && ctl)
1009 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
1010
1011 return 0;
1012}
Alexy Josephd464f3b2014-11-18 16:14:41 -08001013
1014static int hpx_send_params(eff_mode_t mode, void *ctl,
1015 unsigned param_send_flags)
1016{
Manish Dewangan338c50a2017-09-12 15:22:03 +05301017 long param_values[128] = {0};
1018 long *p_param_values = param_values;
Alexy Josephd464f3b2014-11-18 16:14:41 -08001019
1020 ALOGV("%s", __func__);
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +05301021 if (!ctl) {
1022 ALOGE("%s: ctl is NULL, return invalid", __func__);
1023 return -EINVAL;
1024 }
1025
Alexy Josephd464f3b2014-11-18 16:14:41 -08001026 if (param_send_flags & OFFLOAD_SEND_HPX_STATE_OFF) {
1027 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
1028 *p_param_values++ = 0; /* hpx off*/
1029 } else if (param_send_flags & OFFLOAD_SEND_HPX_STATE_ON) {
1030 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
1031 *p_param_values++ = 1; /* hpx on*/
1032 }
1033
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +05301034 if (mode == OFFLOAD)
Alexy Josephd464f3b2014-11-18 16:14:41 -08001035 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
1036 else {
1037 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
1038 ALOGE("%s: sending h/w acc hpx state params fail[%d]", __func__, errno);
1039 }
1040 return 0;
1041}
1042
1043int offload_hpx_send_params(struct mixer_ctl *ctl, unsigned param_send_flags)
1044{
1045 return hpx_send_params(OFFLOAD, (void *)ctl, param_send_flags);
1046}
1047
1048int hw_acc_hpx_send_params(int fd, unsigned param_send_flags)
1049{
1050 return hpx_send_params(HW_ACCELERATOR, (void *)&fd, param_send_flags);
1051}