blob: b01acc53ce2f62c0fa27259f6dc3a0ebc63c4fc7 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +08002 * Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08003
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080028 *
29 * This file was modified by DTS, Inc. The portions of the
30 * code modified by DTS, Inc are copyrighted and
31 * licensed separately, as follows:
32 *
33 * (C) 2014 DTS, Inc.
34 *
35 * Licensed under the Apache License, Version 2.0 (the "License");
36 * you may not use this file except in compliance with the License.
37 * You may obtain a copy of the License at
38 *
39 * http://www.apache.org/licenses/LICENSE-2.0
40 *
41 * Unless required by applicable law or agreed to in writing, software
42 * distributed under the License is distributed on an "AS IS" BASIS,
43 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44 * See the License for the specific language governing permissions and
45 * limitations under the License.
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080046 */
47
48#define LOG_TAG "offload_effect_api"
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070049//#define LOG_NDEBUG 0
Dhananjay Kumar574f3922014-03-25 17:41:44 +053050//#define VERY_VERY_VERBOSE_LOGGING
51#ifdef VERY_VERY_VERBOSE_LOGGING
52#define ALOGVV ALOGV
53#else
54#define ALOGVV(a...) do { } while(0)
55#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080056
57#include <stdbool.h>
Mingming Yin497419f2015-07-01 16:57:32 -070058#include <errno.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080059#include <cutils/log.h>
60#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080061#include <sound/audio_effects.h>
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080062#include <sound/devdep_params.h>
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070063#include <linux/msm_audio.h>
Sharad Sangleb27354b2015-06-18 15:58:55 +053064#include <errno.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080065#include "effect_api.h"
66
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080067#ifdef DTS_EAGLE
68#include "effect_util.h"
69#endif
70
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080071#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070072typedef enum eff_mode {
73 OFFLOAD,
74 HW_ACCELERATOR
75} eff_mode_t;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080076
77#define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19
78const int map_eq_opensl_preset_2_offload_preset[] = {
79 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */
80 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */
81 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */
82 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */
83 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */
84 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */
85 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */
86 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */
87 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */
88 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */
89 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */
90};
91
92const int map_reverb_opensl_preset_2_offload_preset
93 [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = {
94 {1, 15},
95 {2, 16},
96 {3, 17},
97 {4, 18},
98 {5, 3},
99 {6, 20}
100};
101
102int offload_update_mixer_and_effects_ctl(int card, int device_id,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700103 struct mixer **mixer,
104 struct mixer_ctl **ctl)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800105{
106 char mixer_string[128];
107
108 snprintf(mixer_string, sizeof(mixer_string),
109 "%s %d", "Audio Effects Config", device_id);
110 ALOGV("%s: mixer_string: %s", __func__, mixer_string);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700111 *mixer = mixer_open(card);
112 if (!(*mixer)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800113 ALOGE("Failed to open mixer");
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800114 *ctl = NULL;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800115 return -EINVAL;
116 } else {
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700117 *ctl = mixer_get_ctl_by_name(*mixer, mixer_string);
Apoorv Raghuvanshi8880cac2015-02-06 15:33:49 -0800118 if (!*ctl) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800119 ALOGE("mixer_get_ctl_by_name failed");
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700120 mixer_close(*mixer);
121 *mixer = NULL;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800122 return -EINVAL;
123 }
124 }
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700125 ALOGV("mixer: %p, ctl: %p", *mixer, *ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800126 return 0;
127}
128
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700129void offload_close_mixer(struct mixer **mixer)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800130{
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700131 mixer_close(*mixer);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800132}
133
134void offload_bassboost_set_device(struct bass_boost_params *bassboost,
135 uint32_t device)
136{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530137 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800138 bassboost->device = device;
139}
140
141void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
142 bool enable)
143{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530144 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800145 bassboost->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800146
147#ifdef DTS_EAGLE
148 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
149#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800150}
151
152int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
153{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530154 ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800155 return bassboost->enable_flag;
156}
157
158void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
159 int strength)
160{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530161 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800162 bassboost->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800163
164#ifdef DTS_EAGLE
165 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
166#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800167}
168
169void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
170 int mode)
171{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530172 ALOGVV("%s: mode %d", __func__, mode);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800173 bassboost->mode = mode;
174}
175
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700176static int bassboost_send_params(eff_mode_t mode, void *ctl,
177 struct bass_boost_params *bassboost,
178 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800179{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530180 long param_values[128] = {0};
181 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800182
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530183 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800184 *p_param_values++ = BASS_BOOST_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700185 *p_param_values++ = bassboost->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800186 *p_param_values++ = 0; /* num of commands*/
187 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
188 *p_param_values++ = BASS_BOOST_ENABLE;
189 *p_param_values++ = CONFIG_SET;
190 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
191 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700192 *p_param_values++ = bassboost->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800193 param_values[2] += 1;
194 }
195 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
196 *p_param_values++ = BASS_BOOST_STRENGTH;
197 *p_param_values++ = CONFIG_SET;
198 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
199 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700200 *p_param_values++ = bassboost->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800201 param_values[2] += 1;
202 }
203 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
204 *p_param_values++ = BASS_BOOST_MODE;
205 *p_param_values++ = CONFIG_SET;
206 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
207 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700208 *p_param_values++ = bassboost->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800209 param_values[2] += 1;
210 }
211
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700212 if ((mode == OFFLOAD) && param_values[2] && ctl) {
213 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
214 ARRAY_SIZE(param_values));
215 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
216 ctl && *(int *)ctl) {
217 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
218 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
219 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800220
221 return 0;
222}
223
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700224int offload_bassboost_send_params(struct mixer_ctl *ctl,
225 struct bass_boost_params *bassboost,
226 unsigned param_send_flags)
227{
228 return bassboost_send_params(OFFLOAD, (void *)ctl, bassboost,
229 param_send_flags);
230}
231
232int hw_acc_bassboost_send_params(int fd, struct bass_boost_params *bassboost,
233 unsigned param_send_flags)
234{
235 return bassboost_send_params(HW_ACCELERATOR, (void *)&fd,
236 bassboost, param_send_flags);
237}
238
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800239void offload_pbe_set_device(struct pbe_params *pbe,
240 uint32_t device)
241{
242 ALOGV("%s: device=%d", __func__, device);
243 pbe->device = device;
244}
245
246void offload_pbe_set_enable_flag(struct pbe_params *pbe,
247 bool enable)
248{
249 ALOGV("%s: enable=%d", __func__, enable);
250 pbe->enable_flag = enable;
251}
252
253int offload_pbe_get_enable_flag(struct pbe_params *pbe)
254{
255 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
256 return pbe->enable_flag;
257}
258
259static int pbe_send_params(eff_mode_t mode, void *ctl,
260 struct pbe_params *pbe,
261 unsigned param_send_flags)
262{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530263 long param_values[128] = {0};
264 long *p_param_values = param_values;
265 int i, *cfg = NULL;
Dhananjay Kumar5f15ff92014-05-19 16:45:08 +0800266
267 ALOGV("%s: enabled=%d", __func__, pbe->enable_flag);
268 *p_param_values++ = PBE_MODULE;
269 *p_param_values++ = pbe->device;
270 *p_param_values++ = 0; /* num of commands*/
271 if (param_send_flags & OFFLOAD_SEND_PBE_ENABLE_FLAG) {
272 *p_param_values++ = PBE_ENABLE;
273 *p_param_values++ = CONFIG_SET;
274 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
275 *p_param_values++ = PBE_ENABLE_PARAM_LEN;
276 *p_param_values++ = pbe->enable_flag;
277 param_values[2] += 1;
278 }
279 if (param_send_flags & OFFLOAD_SEND_PBE_CONFIG) {
280 *p_param_values++ = PBE_CONFIG;
281 *p_param_values++ = CONFIG_SET;
282 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
283 *p_param_values++ = pbe->cfg_len;
284 cfg = (int *)&pbe->config;
285 for (i = 0; i < (int)pbe->cfg_len ; i+= sizeof(*p_param_values))
286 *p_param_values++ = *cfg++;
287 param_values[2] += 1;
288 }
289
290 if ((mode == OFFLOAD) && param_values[2] && ctl) {
291 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
292 ARRAY_SIZE(param_values));
293 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
294 ctl && *(int *)ctl) {
295 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
296 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
297 }
298
299 return 0;
300}
301
302int offload_pbe_send_params(struct mixer_ctl *ctl,
303 struct pbe_params *pbe,
304 unsigned param_send_flags)
305{
306 return pbe_send_params(OFFLOAD, (void *)ctl, pbe,
307 param_send_flags);
308}
309
310int hw_acc_pbe_send_params(int fd, struct pbe_params *pbe,
311 unsigned param_send_flags)
312{
313 return pbe_send_params(HW_ACCELERATOR, (void *)&fd,
314 pbe, param_send_flags);
315}
316
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800317void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
318 uint32_t device)
319{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530320 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800321 virtualizer->device = device;
322}
323
324void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
325 bool enable)
326{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530327 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800328 virtualizer->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800329
330#ifdef DTS_EAGLE
331 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
332#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800333}
334
335int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
336{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530337 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800338 return virtualizer->enable_flag;
339}
340
341void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
342 int strength)
343{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530344 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800345 virtualizer->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800346
347#ifdef DTS_EAGLE
348 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
349#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800350}
351
352void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
353 int out_type)
354{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530355 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800356 virtualizer->out_type = out_type;
357}
358
359void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
360 int gain_adjust)
361{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530362 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800363 virtualizer->gain_adjust = gain_adjust;
364}
365
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700366static int virtualizer_send_params(eff_mode_t mode, void *ctl,
367 struct virtualizer_params *virtualizer,
368 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800369{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530370 long param_values[128] = {0};
371 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800372
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530373 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800374 *p_param_values++ = VIRTUALIZER_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700375 *p_param_values++ = virtualizer->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800376 *p_param_values++ = 0; /* num of commands*/
377 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
378 *p_param_values++ = VIRTUALIZER_ENABLE;
379 *p_param_values++ = CONFIG_SET;
380 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
381 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700382 *p_param_values++ = virtualizer->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800383 param_values[2] += 1;
384 }
385 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
386 *p_param_values++ = VIRTUALIZER_STRENGTH;
387 *p_param_values++ = CONFIG_SET;
388 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
389 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700390 *p_param_values++ = virtualizer->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800391 param_values[2] += 1;
392 }
393 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
394 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
395 *p_param_values++ = CONFIG_SET;
396 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
397 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700398 *p_param_values++ = virtualizer->out_type;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800399 param_values[2] += 1;
400 }
401 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
402 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
403 *p_param_values++ = CONFIG_SET;
404 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
405 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700406 *p_param_values++ = virtualizer->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800407 param_values[2] += 1;
408 }
409
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700410 if ((mode == OFFLOAD) && param_values[2] && ctl) {
411 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
412 ARRAY_SIZE(param_values));
413 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
414 ctl && *(int *)ctl) {
415 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
416 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
417 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800418
419 return 0;
420}
421
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700422int offload_virtualizer_send_params(struct mixer_ctl *ctl,
423 struct virtualizer_params *virtualizer,
424 unsigned param_send_flags)
425{
426 return virtualizer_send_params(OFFLOAD, (void *)ctl, virtualizer,
427 param_send_flags);
428}
429
430int hw_acc_virtualizer_send_params(int fd,
431 struct virtualizer_params *virtualizer,
432 unsigned param_send_flags)
433{
434 return virtualizer_send_params(HW_ACCELERATOR, (void *)&fd,
435 virtualizer, param_send_flags);
436}
437
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800438void offload_eq_set_device(struct eq_params *eq, uint32_t device)
439{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530440 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800441 eq->device = device;
442}
443
444void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
445{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530446 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800447 eq->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800448
449#ifdef DTS_EAGLE
450 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
451#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800452}
453
454int offload_eq_get_enable_flag(struct eq_params *eq)
455{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530456 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800457 return eq->enable_flag;
458}
459
460void offload_eq_set_preset(struct eq_params *eq, int preset)
461{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530462 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800463 eq->config.preset_id = preset;
464 eq->config.eq_pregain = Q27_UNITY;
465}
466
467void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
468 const uint16_t *band_freq_list,
469 int *band_gain_list)
470{
471 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530472 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800473 eq->config.num_bands = num_bands;
474 for (i=0; i<num_bands; i++) {
475 eq->per_band_cfg[i].band_idx = i;
476 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
477 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
478 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
479 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
480 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800481
482#ifdef DTS_EAGLE
483 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_SET_PARAM, EFFECT_NO_OP, EFFECT_NO_OP, i, band_gain_list[i] * 100);
484#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800485}
486
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700487static int eq_send_params(eff_mode_t mode, void *ctl, struct eq_params *eq,
488 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800489{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530490 long param_values[128] = {0};
491 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800492 uint32_t i;
493
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530494 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700495 if ((eq->config.preset_id < -1) ||
496 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq->config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800497 ALOGV("No Valid preset to set");
498 return 0;
499 }
500 *p_param_values++ = EQ_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700501 *p_param_values++ = eq->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800502 *p_param_values++ = 0; /* num of commands*/
503 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
504 *p_param_values++ = EQ_ENABLE;
505 *p_param_values++ = CONFIG_SET;
506 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
507 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700508 *p_param_values++ = eq->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800509 param_values[2] += 1;
510 }
511 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
512 *p_param_values++ = EQ_CONFIG;
513 *p_param_values++ = CONFIG_SET;
514 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
515 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700516 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800517 *p_param_values++ =
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700518 map_eq_opensl_preset_2_offload_preset[eq->config.preset_id];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800519 *p_param_values++ = 0;
520 param_values[2] += 1;
521 }
522 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
523 *p_param_values++ = EQ_CONFIG;
524 *p_param_values++ = CONFIG_SET;
525 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
526 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700527 eq->config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
528 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800529 *p_param_values++ = CUSTOM_OPENSL_PRESET;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700530 *p_param_values++ = eq->config.num_bands;
531 for (i=0; i<eq->config.num_bands; i++) {
532 *p_param_values++ = eq->per_band_cfg[i].band_idx;
533 *p_param_values++ = eq->per_band_cfg[i].filter_type;
534 *p_param_values++ = eq->per_band_cfg[i].freq_millihertz;
535 *p_param_values++ = eq->per_band_cfg[i].gain_millibels;
536 *p_param_values++ = eq->per_band_cfg[i].quality_factor;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800537 }
538 param_values[2] += 1;
539 }
540
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700541 if ((mode == OFFLOAD) && param_values[2] && ctl) {
542 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
543 ARRAY_SIZE(param_values));
544 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
545 ctl && *(int *)ctl) {
546 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
547 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
548 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800549
550 return 0;
551}
552
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700553int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params *eq,
554 unsigned param_send_flags)
555{
556 return eq_send_params(OFFLOAD, (void *)ctl, eq, param_send_flags);
557}
558
559int hw_acc_eq_send_params(int fd, struct eq_params *eq,
560 unsigned param_send_flags)
561{
562 return eq_send_params(HW_ACCELERATOR, (void *)&fd, eq,
563 param_send_flags);
564}
565
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800566void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
567{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530568 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800569 reverb->device = device;
570}
571
572void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
573{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530574 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800575 reverb->enable_flag = enable;
576}
577
578int offload_reverb_get_enable_flag(struct reverb_params *reverb)
579{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530580 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800581 return reverb->enable_flag;
582}
583
584void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
585{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530586 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800587 reverb->mode = mode;
588}
589
590void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
591{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530592 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800593 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800594 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800595}
596
597void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
598{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530599 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800600 reverb->wet_mix = wet_mix;
601}
602
603void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
604 int gain_adjust)
605{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530606 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800607 reverb->gain_adjust = gain_adjust;
608}
609
610void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
611{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530612 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800613 reverb->room_level = room_level;
614}
615
616void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
617 int room_hf_level)
618{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530619 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800620 reverb->room_hf_level = room_hf_level;
621}
622
623void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
624{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530625 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800626 reverb->decay_time = decay_time;
627}
628
629void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
630 int decay_hf_ratio)
631{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530632 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800633 reverb->decay_hf_ratio = decay_hf_ratio;
634}
635
636void offload_reverb_set_reflections_level(struct reverb_params *reverb,
637 int reflections_level)
638{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530639 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800640 reverb->reflections_level = reflections_level;
641}
642
643void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
644 int reflections_delay)
645{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530646 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800647 reverb->reflections_delay = reflections_delay;
648}
649
650void offload_reverb_set_reverb_level(struct reverb_params *reverb,
651 int reverb_level)
652{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530653 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800654 reverb->level = reverb_level;
655}
656
657void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
658{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530659 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800660 reverb->delay = delay;
661}
662
663void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
664{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530665 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800666 reverb->diffusion = diffusion;
667}
668
669void offload_reverb_set_density(struct reverb_params *reverb, int density)
670{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530671 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800672 reverb->density = density;
673}
674
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700675static int reverb_send_params(eff_mode_t mode, void *ctl,
676 struct reverb_params *reverb,
677 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800678{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530679 long param_values[128] = {0};
680 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800681
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530682 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800683 *p_param_values++ = REVERB_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700684 *p_param_values++ = reverb->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800685 *p_param_values++ = 0; /* num of commands*/
686
687 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
688 *p_param_values++ = REVERB_ENABLE;
689 *p_param_values++ = CONFIG_SET;
690 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
691 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700692 *p_param_values++ = reverb->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800693 param_values[2] += 1;
694 }
695 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
696 *p_param_values++ = REVERB_MODE;
697 *p_param_values++ = CONFIG_SET;
698 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
699 *p_param_values++ = REVERB_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700700 *p_param_values++ = reverb->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800701 param_values[2] += 1;
702 }
703 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
704 *p_param_values++ = REVERB_PRESET;
705 *p_param_values++ = CONFIG_SET;
706 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
707 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700708 *p_param_values++ = reverb->preset;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800709 param_values[2] += 1;
710 }
711 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
712 *p_param_values++ = REVERB_WET_MIX;
713 *p_param_values++ = CONFIG_SET;
714 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
715 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700716 *p_param_values++ = reverb->wet_mix;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800717 param_values[2] += 1;
718 }
719 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
720 *p_param_values++ = REVERB_GAIN_ADJUST;
721 *p_param_values++ = CONFIG_SET;
722 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
723 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700724 *p_param_values++ = reverb->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800725 param_values[2] += 1;
726 }
727 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
728 *p_param_values++ = REVERB_ROOM_LEVEL;
729 *p_param_values++ = CONFIG_SET;
730 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
731 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700732 *p_param_values++ = reverb->room_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800733 param_values[2] += 1;
734 }
735 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
736 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
737 *p_param_values++ = CONFIG_SET;
738 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
739 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700740 *p_param_values++ = reverb->room_hf_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800741 param_values[2] += 1;
742 }
743 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
744 *p_param_values++ = REVERB_DECAY_TIME;
745 *p_param_values++ = CONFIG_SET;
746 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
747 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700748 *p_param_values++ = reverb->decay_time;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800749 param_values[2] += 1;
750 }
751 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
752 *p_param_values++ = REVERB_DECAY_HF_RATIO;
753 *p_param_values++ = CONFIG_SET;
754 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
755 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700756 *p_param_values++ = reverb->decay_hf_ratio;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800757 param_values[2] += 1;
758 }
759 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
760 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
761 *p_param_values++ = CONFIG_SET;
762 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
763 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700764 *p_param_values++ = reverb->reflections_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800765 param_values[2] += 1;
766 }
767 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
768 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
769 *p_param_values++ = CONFIG_SET;
770 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
771 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700772 *p_param_values++ = reverb->reflections_delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800773 param_values[2] += 1;
774 }
775 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
776 *p_param_values++ = REVERB_LEVEL;
777 *p_param_values++ = CONFIG_SET;
778 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
779 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700780 *p_param_values++ = reverb->level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800781 param_values[2] += 1;
782 }
783 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
784 *p_param_values++ = REVERB_DELAY;
785 *p_param_values++ = CONFIG_SET;
786 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
787 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700788 *p_param_values++ = reverb->delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800789 param_values[2] += 1;
790 }
791 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
792 *p_param_values++ = REVERB_DIFFUSION;
793 *p_param_values++ = CONFIG_SET;
794 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
795 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700796 *p_param_values++ = reverb->diffusion;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800797 param_values[2] += 1;
798 }
799 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
800 *p_param_values++ = REVERB_DENSITY;
801 *p_param_values++ = CONFIG_SET;
802 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
803 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700804 *p_param_values++ = reverb->density;
805 param_values[2] += 1;
806 }
807
808 if ((mode == OFFLOAD) && param_values[2] && ctl) {
809 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
810 ARRAY_SIZE(param_values));
811 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
812 ctl && *(int *)ctl) {
813 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
814 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
815 }
816
817 return 0;
818}
819
820int offload_reverb_send_params(struct mixer_ctl *ctl,
821 struct reverb_params *reverb,
822 unsigned param_send_flags)
823{
824 return reverb_send_params(OFFLOAD, (void *)ctl, reverb,
825 param_send_flags);
826}
827
828int hw_acc_reverb_send_params(int fd, struct reverb_params *reverb,
829 unsigned param_send_flags)
830{
831 return reverb_send_params(HW_ACCELERATOR, (void *)&fd,
832 reverb, param_send_flags);
833}
834
835void offload_soft_volume_set_enable(struct soft_volume_params *vol, bool enable)
836{
837 ALOGV("%s", __func__);
838 vol->enable_flag = enable;
839}
840
841void offload_soft_volume_set_gain_master(struct soft_volume_params *vol, int gain)
842{
843 ALOGV("%s", __func__);
844 vol->master_gain = gain;
845}
846
847void offload_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
848 int l_gain, int r_gain)
849{
850 ALOGV("%s", __func__);
851 vol->left_gain = l_gain;
852 vol->right_gain = r_gain;
853}
854
855int offload_soft_volume_send_params(struct mixer_ctl *ctl,
856 struct soft_volume_params vol,
857 unsigned param_send_flags)
858{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530859 long param_values[128] = {0};
860 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700861 uint32_t i;
862
863 ALOGV("%s", __func__);
864 *p_param_values++ = SOFT_VOLUME_MODULE;
865 *p_param_values++ = 0;
866 *p_param_values++ = 0; /* num of commands*/
867 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_ENABLE_FLAG) {
868 *p_param_values++ = SOFT_VOLUME_ENABLE;
869 *p_param_values++ = CONFIG_SET;
870 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
871 *p_param_values++ = SOFT_VOLUME_ENABLE_PARAM_LEN;
872 *p_param_values++ = vol.enable_flag;
873 param_values[2] += 1;
874 }
875 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_MASTER) {
876 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER;
877 *p_param_values++ = CONFIG_SET;
878 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
879 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER_PARAM_LEN;
880 *p_param_values++ = vol.master_gain;
881 param_values[2] += 1;
882 }
883 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_2CH) {
884 *p_param_values++ = SOFT_VOLUME_GAIN_2CH;
885 *p_param_values++ = CONFIG_SET;
886 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
887 *p_param_values++ = SOFT_VOLUME_GAIN_2CH_PARAM_LEN;
888 *p_param_values++ = vol.left_gain;
889 *p_param_values++ = vol.right_gain;
890 param_values[2] += 1;
891 }
892
893 if (param_values[2] && ctl)
894 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
895
896 return 0;
897}
898
899void offload_transition_soft_volume_set_enable(struct soft_volume_params *vol,
900 bool enable)
901{
902 ALOGV("%s", __func__);
903 vol->enable_flag = enable;
904}
905
906void offload_transition_soft_volume_set_gain_master(struct soft_volume_params *vol,
907 int gain)
908{
909 ALOGV("%s", __func__);
910 vol->master_gain = gain;
911}
912
913void offload_transition_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
914 int l_gain, int r_gain)
915{
916 ALOGV("%s", __func__);
917 vol->left_gain = l_gain;
918 vol->right_gain = r_gain;
919}
920
921int offload_transition_soft_volume_send_params(struct mixer_ctl *ctl,
922 struct soft_volume_params vol,
923 unsigned param_send_flags)
924{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530925 long param_values[128] = {0};
926 long *p_param_values = param_values;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700927 uint32_t i;
928
929 ALOGV("%s", __func__);
930 *p_param_values++ = SOFT_VOLUME2_MODULE;
931 *p_param_values++ = 0;
932 *p_param_values++ = 0; /* num of commands*/
933 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_ENABLE_FLAG) {
934 *p_param_values++ = SOFT_VOLUME2_ENABLE;
935 *p_param_values++ = CONFIG_SET;
936 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
937 *p_param_values++ = SOFT_VOLUME2_ENABLE_PARAM_LEN;
938 *p_param_values++ = vol.enable_flag;
939 param_values[2] += 1;
940 }
941 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_MASTER) {
942 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER;
943 *p_param_values++ = CONFIG_SET;
944 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
945 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER_PARAM_LEN;
946 *p_param_values++ = vol.master_gain;
947 param_values[2] += 1;
948 }
949 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_2CH) {
950 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH;
951 *p_param_values++ = CONFIG_SET;
952 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
953 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH_PARAM_LEN;
954 *p_param_values++ = vol.left_gain;
955 *p_param_values++ = vol.right_gain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800956 param_values[2] += 1;
957 }
958
959 if (param_values[2] && ctl)
960 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
961
962 return 0;
963}
Alexy Josephd464f3b2014-11-18 16:14:41 -0800964
965static int hpx_send_params(eff_mode_t mode, void *ctl,
966 unsigned param_send_flags)
967{
Manish Dewangan338c50a2017-09-12 15:22:03 +0530968 long param_values[128] = {0};
969 long *p_param_values = param_values;
Alexy Josephd464f3b2014-11-18 16:14:41 -0800970 uint32_t i;
971
972 ALOGV("%s", __func__);
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +0530973 if (!ctl) {
974 ALOGE("%s: ctl is NULL, return invalid", __func__);
975 return -EINVAL;
976 }
977
Alexy Josephd464f3b2014-11-18 16:14:41 -0800978 if (param_send_flags & OFFLOAD_SEND_HPX_STATE_OFF) {
979 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
980 *p_param_values++ = 0; /* hpx off*/
981 } else if (param_send_flags & OFFLOAD_SEND_HPX_STATE_ON) {
982 *p_param_values++ = DTS_EAGLE_MODULE_ENABLE;
983 *p_param_values++ = 1; /* hpx on*/
984 }
985
Chaithanya Krishna Bacharajub9bf50f2015-04-09 16:26:36 +0530986 if (mode == OFFLOAD)
Alexy Josephd464f3b2014-11-18 16:14:41 -0800987 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
988 else {
989 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
990 ALOGE("%s: sending h/w acc hpx state params fail[%d]", __func__, errno);
991 }
992 return 0;
993}
994
995int offload_hpx_send_params(struct mixer_ctl *ctl, unsigned param_send_flags)
996{
997 return hpx_send_params(OFFLOAD, (void *)ctl, param_send_flags);
998}
999
1000int hw_acc_hpx_send_params(int fd, unsigned param_send_flags)
1001{
1002 return hpx_send_params(HW_ACCELERATOR, (void *)&fd, param_send_flags);
1003}