blob: 61f6f00b17dcf40564c1601fe260cac9412c02f1 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
wjiangca2685b2014-03-18 06:43:48 +08002 * Copyright (c) 2013-2014, 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>
58#include <cutils/log.h>
59#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080060#include <sound/audio_effects.h>
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080061#include <sound/devdep_params.h>
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070062#include <linux/msm_audio.h>
63
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080064#include "effect_api.h"
65
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080066#ifdef DTS_EAGLE
67#include "effect_util.h"
68#endif
69
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080070#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -070071typedef enum eff_mode {
72 OFFLOAD,
73 HW_ACCELERATOR
74} eff_mode_t;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080075
76#define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19
77const int map_eq_opensl_preset_2_offload_preset[] = {
78 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */
79 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */
80 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */
81 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */
82 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */
83 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */
84 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */
85 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */
86 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */
87 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */
88 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */
89};
90
91const int map_reverb_opensl_preset_2_offload_preset
92 [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = {
93 {1, 15},
94 {2, 16},
95 {3, 17},
96 {4, 18},
97 {5, 3},
98 {6, 20}
99};
100
101int offload_update_mixer_and_effects_ctl(int card, int device_id,
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700102 struct mixer **mixer,
103 struct mixer_ctl **ctl)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800104{
105 char mixer_string[128];
106
107 snprintf(mixer_string, sizeof(mixer_string),
108 "%s %d", "Audio Effects Config", device_id);
109 ALOGV("%s: mixer_string: %s", __func__, mixer_string);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700110 *mixer = mixer_open(card);
111 if (!(*mixer)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800112 ALOGE("Failed to open mixer");
113 ctl = NULL;
114 return -EINVAL;
115 } else {
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700116 *ctl = mixer_get_ctl_by_name(*mixer, mixer_string);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800117 if (!ctl) {
118 ALOGE("mixer_get_ctl_by_name failed");
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700119 mixer_close(*mixer);
120 *mixer = NULL;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800121 return -EINVAL;
122 }
123 }
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700124 ALOGV("mixer: %p, ctl: %p", *mixer, *ctl);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800125 return 0;
126}
127
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700128void offload_close_mixer(struct mixer **mixer)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800129{
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700130 mixer_close(*mixer);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800131}
132
133void offload_bassboost_set_device(struct bass_boost_params *bassboost,
134 uint32_t device)
135{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530136 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800137 bassboost->device = device;
138}
139
140void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
141 bool enable)
142{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530143 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800144 bassboost->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800145
146#ifdef DTS_EAGLE
147 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
148#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800149}
150
151int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
152{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530153 ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800154 return bassboost->enable_flag;
155}
156
157void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
158 int strength)
159{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530160 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800161 bassboost->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800162
163#ifdef DTS_EAGLE
164 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
165#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800166}
167
168void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
169 int mode)
170{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530171 ALOGVV("%s: mode %d", __func__, mode);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800172 bassboost->mode = mode;
173}
174
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700175static int bassboost_send_params(eff_mode_t mode, void *ctl,
176 struct bass_boost_params *bassboost,
177 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800178{
179 int param_values[128] = {0};
180 int *p_param_values = param_values;
181
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530182 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800183 *p_param_values++ = BASS_BOOST_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700184 *p_param_values++ = bassboost->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800185 *p_param_values++ = 0; /* num of commands*/
186 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
187 *p_param_values++ = BASS_BOOST_ENABLE;
188 *p_param_values++ = CONFIG_SET;
189 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
190 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700191 *p_param_values++ = bassboost->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800192 param_values[2] += 1;
193 }
194 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
195 *p_param_values++ = BASS_BOOST_STRENGTH;
196 *p_param_values++ = CONFIG_SET;
197 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
198 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700199 *p_param_values++ = bassboost->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800200 param_values[2] += 1;
201 }
202 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
203 *p_param_values++ = BASS_BOOST_MODE;
204 *p_param_values++ = CONFIG_SET;
205 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
206 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700207 *p_param_values++ = bassboost->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800208 param_values[2] += 1;
209 }
210
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700211 if ((mode == OFFLOAD) && param_values[2] && ctl) {
212 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
213 ARRAY_SIZE(param_values));
214 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
215 ctl && *(int *)ctl) {
216 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
217 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
218 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800219
220 return 0;
221}
222
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700223int offload_bassboost_send_params(struct mixer_ctl *ctl,
224 struct bass_boost_params *bassboost,
225 unsigned param_send_flags)
226{
227 return bassboost_send_params(OFFLOAD, (void *)ctl, bassboost,
228 param_send_flags);
229}
230
231int hw_acc_bassboost_send_params(int fd, struct bass_boost_params *bassboost,
232 unsigned param_send_flags)
233{
234 return bassboost_send_params(HW_ACCELERATOR, (void *)&fd,
235 bassboost, param_send_flags);
236}
237
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800238void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
239 uint32_t device)
240{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530241 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800242 virtualizer->device = device;
243}
244
245void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
246 bool enable)
247{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530248 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800249 virtualizer->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800250
251#ifdef DTS_EAGLE
252 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
253#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800254}
255
256int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
257{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530258 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800259 return virtualizer->enable_flag;
260}
261
262void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
263 int strength)
264{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530265 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800266 virtualizer->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800267
268#ifdef DTS_EAGLE
269 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
270#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800271}
272
273void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
274 int out_type)
275{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530276 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800277 virtualizer->out_type = out_type;
278}
279
280void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
281 int gain_adjust)
282{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530283 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800284 virtualizer->gain_adjust = gain_adjust;
285}
286
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700287static int virtualizer_send_params(eff_mode_t mode, void *ctl,
288 struct virtualizer_params *virtualizer,
289 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800290{
291 int param_values[128] = {0};
292 int *p_param_values = param_values;
293
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530294 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800295 *p_param_values++ = VIRTUALIZER_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700296 *p_param_values++ = virtualizer->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800297 *p_param_values++ = 0; /* num of commands*/
298 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
299 *p_param_values++ = VIRTUALIZER_ENABLE;
300 *p_param_values++ = CONFIG_SET;
301 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
302 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700303 *p_param_values++ = virtualizer->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800304 param_values[2] += 1;
305 }
306 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
307 *p_param_values++ = VIRTUALIZER_STRENGTH;
308 *p_param_values++ = CONFIG_SET;
309 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
310 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700311 *p_param_values++ = virtualizer->strength;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800312 param_values[2] += 1;
313 }
314 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
315 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
316 *p_param_values++ = CONFIG_SET;
317 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
318 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700319 *p_param_values++ = virtualizer->out_type;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800320 param_values[2] += 1;
321 }
322 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
323 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
324 *p_param_values++ = CONFIG_SET;
325 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
326 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700327 *p_param_values++ = virtualizer->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800328 param_values[2] += 1;
329 }
330
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700331 if ((mode == OFFLOAD) && param_values[2] && ctl) {
332 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
333 ARRAY_SIZE(param_values));
334 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
335 ctl && *(int *)ctl) {
336 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
337 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
338 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800339
340 return 0;
341}
342
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700343int offload_virtualizer_send_params(struct mixer_ctl *ctl,
344 struct virtualizer_params *virtualizer,
345 unsigned param_send_flags)
346{
347 return virtualizer_send_params(OFFLOAD, (void *)ctl, virtualizer,
348 param_send_flags);
349}
350
351int hw_acc_virtualizer_send_params(int fd,
352 struct virtualizer_params *virtualizer,
353 unsigned param_send_flags)
354{
355 return virtualizer_send_params(HW_ACCELERATOR, (void *)&fd,
356 virtualizer, param_send_flags);
357}
358
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800359void offload_eq_set_device(struct eq_params *eq, uint32_t device)
360{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530361 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800362 eq->device = device;
363}
364
365void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
366{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530367 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800368 eq->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800369
370#ifdef DTS_EAGLE
371 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
372#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800373}
374
375int offload_eq_get_enable_flag(struct eq_params *eq)
376{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530377 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800378 return eq->enable_flag;
379}
380
381void offload_eq_set_preset(struct eq_params *eq, int preset)
382{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530383 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800384 eq->config.preset_id = preset;
385 eq->config.eq_pregain = Q27_UNITY;
386}
387
388void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
389 const uint16_t *band_freq_list,
390 int *band_gain_list)
391{
392 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530393 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800394 eq->config.num_bands = num_bands;
395 for (i=0; i<num_bands; i++) {
396 eq->per_band_cfg[i].band_idx = i;
397 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
398 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
399 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
400 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
401 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800402
403#ifdef DTS_EAGLE
404 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_SET_PARAM, EFFECT_NO_OP, EFFECT_NO_OP, i, band_gain_list[i] * 100);
405#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800406}
407
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700408static int eq_send_params(eff_mode_t mode, void *ctl, struct eq_params *eq,
409 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800410{
411 int param_values[128] = {0};
412 int *p_param_values = param_values;
413 uint32_t i;
414
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530415 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700416 if ((eq->config.preset_id < -1) ||
417 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq->config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800418 ALOGV("No Valid preset to set");
419 return 0;
420 }
421 *p_param_values++ = EQ_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700422 *p_param_values++ = eq->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800423 *p_param_values++ = 0; /* num of commands*/
424 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
425 *p_param_values++ = EQ_ENABLE;
426 *p_param_values++ = CONFIG_SET;
427 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
428 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700429 *p_param_values++ = eq->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800430 param_values[2] += 1;
431 }
432 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
433 *p_param_values++ = EQ_CONFIG;
434 *p_param_values++ = CONFIG_SET;
435 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
436 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700437 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800438 *p_param_values++ =
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700439 map_eq_opensl_preset_2_offload_preset[eq->config.preset_id];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800440 *p_param_values++ = 0;
441 param_values[2] += 1;
442 }
443 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
444 *p_param_values++ = EQ_CONFIG;
445 *p_param_values++ = CONFIG_SET;
446 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
447 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700448 eq->config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
449 *p_param_values++ = eq->config.eq_pregain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800450 *p_param_values++ = CUSTOM_OPENSL_PRESET;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700451 *p_param_values++ = eq->config.num_bands;
452 for (i=0; i<eq->config.num_bands; i++) {
453 *p_param_values++ = eq->per_band_cfg[i].band_idx;
454 *p_param_values++ = eq->per_band_cfg[i].filter_type;
455 *p_param_values++ = eq->per_band_cfg[i].freq_millihertz;
456 *p_param_values++ = eq->per_band_cfg[i].gain_millibels;
457 *p_param_values++ = eq->per_band_cfg[i].quality_factor;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800458 }
459 param_values[2] += 1;
460 }
461
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700462 if ((mode == OFFLOAD) && param_values[2] && ctl) {
463 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
464 ARRAY_SIZE(param_values));
465 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
466 ctl && *(int *)ctl) {
467 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
468 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
469 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800470
471 return 0;
472}
473
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700474int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params *eq,
475 unsigned param_send_flags)
476{
477 return eq_send_params(OFFLOAD, (void *)ctl, eq, param_send_flags);
478}
479
480int hw_acc_eq_send_params(int fd, struct eq_params *eq,
481 unsigned param_send_flags)
482{
483 return eq_send_params(HW_ACCELERATOR, (void *)&fd, eq,
484 param_send_flags);
485}
486
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800487void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
488{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530489 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800490 reverb->device = device;
491}
492
493void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
494{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530495 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800496 reverb->enable_flag = enable;
497}
498
499int offload_reverb_get_enable_flag(struct reverb_params *reverb)
500{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530501 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800502 return reverb->enable_flag;
503}
504
505void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
506{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530507 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800508 reverb->mode = mode;
509}
510
511void offload_reverb_set_preset(struct reverb_params *reverb, 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 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800515 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800516}
517
518void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
519{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530520 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800521 reverb->wet_mix = wet_mix;
522}
523
524void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
525 int gain_adjust)
526{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530527 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800528 reverb->gain_adjust = gain_adjust;
529}
530
531void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
532{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530533 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800534 reverb->room_level = room_level;
535}
536
537void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
538 int room_hf_level)
539{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530540 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800541 reverb->room_hf_level = room_hf_level;
542}
543
544void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
545{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530546 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800547 reverb->decay_time = decay_time;
548}
549
550void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
551 int decay_hf_ratio)
552{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530553 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800554 reverb->decay_hf_ratio = decay_hf_ratio;
555}
556
557void offload_reverb_set_reflections_level(struct reverb_params *reverb,
558 int reflections_level)
559{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530560 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800561 reverb->reflections_level = reflections_level;
562}
563
564void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
565 int reflections_delay)
566{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530567 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800568 reverb->reflections_delay = reflections_delay;
569}
570
571void offload_reverb_set_reverb_level(struct reverb_params *reverb,
572 int reverb_level)
573{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530574 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800575 reverb->level = reverb_level;
576}
577
578void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
579{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530580 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800581 reverb->delay = delay;
582}
583
584void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
585{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530586 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800587 reverb->diffusion = diffusion;
588}
589
590void offload_reverb_set_density(struct reverb_params *reverb, int density)
591{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530592 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800593 reverb->density = density;
594}
595
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700596static int reverb_send_params(eff_mode_t mode, void *ctl,
597 struct reverb_params *reverb,
598 unsigned param_send_flags)
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800599{
600 int param_values[128] = {0};
601 int *p_param_values = param_values;
602
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530603 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800604 *p_param_values++ = REVERB_MODULE;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700605 *p_param_values++ = reverb->device;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800606 *p_param_values++ = 0; /* num of commands*/
607
608 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
609 *p_param_values++ = REVERB_ENABLE;
610 *p_param_values++ = CONFIG_SET;
611 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
612 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700613 *p_param_values++ = reverb->enable_flag;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800614 param_values[2] += 1;
615 }
616 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
617 *p_param_values++ = REVERB_MODE;
618 *p_param_values++ = CONFIG_SET;
619 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
620 *p_param_values++ = REVERB_MODE_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700621 *p_param_values++ = reverb->mode;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800622 param_values[2] += 1;
623 }
624 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
625 *p_param_values++ = REVERB_PRESET;
626 *p_param_values++ = CONFIG_SET;
627 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
628 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700629 *p_param_values++ = reverb->preset;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800630 param_values[2] += 1;
631 }
632 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
633 *p_param_values++ = REVERB_WET_MIX;
634 *p_param_values++ = CONFIG_SET;
635 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
636 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700637 *p_param_values++ = reverb->wet_mix;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800638 param_values[2] += 1;
639 }
640 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
641 *p_param_values++ = REVERB_GAIN_ADJUST;
642 *p_param_values++ = CONFIG_SET;
643 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
644 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700645 *p_param_values++ = reverb->gain_adjust;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800646 param_values[2] += 1;
647 }
648 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
649 *p_param_values++ = REVERB_ROOM_LEVEL;
650 *p_param_values++ = CONFIG_SET;
651 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
652 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700653 *p_param_values++ = reverb->room_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800654 param_values[2] += 1;
655 }
656 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
657 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
658 *p_param_values++ = CONFIG_SET;
659 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
660 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700661 *p_param_values++ = reverb->room_hf_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800662 param_values[2] += 1;
663 }
664 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
665 *p_param_values++ = REVERB_DECAY_TIME;
666 *p_param_values++ = CONFIG_SET;
667 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
668 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700669 *p_param_values++ = reverb->decay_time;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800670 param_values[2] += 1;
671 }
672 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
673 *p_param_values++ = REVERB_DECAY_HF_RATIO;
674 *p_param_values++ = CONFIG_SET;
675 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
676 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700677 *p_param_values++ = reverb->decay_hf_ratio;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800678 param_values[2] += 1;
679 }
680 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
681 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
682 *p_param_values++ = CONFIG_SET;
683 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
684 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700685 *p_param_values++ = reverb->reflections_level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800686 param_values[2] += 1;
687 }
688 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
689 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
690 *p_param_values++ = CONFIG_SET;
691 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
692 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700693 *p_param_values++ = reverb->reflections_delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800694 param_values[2] += 1;
695 }
696 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
697 *p_param_values++ = REVERB_LEVEL;
698 *p_param_values++ = CONFIG_SET;
699 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
700 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700701 *p_param_values++ = reverb->level;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800702 param_values[2] += 1;
703 }
704 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
705 *p_param_values++ = REVERB_DELAY;
706 *p_param_values++ = CONFIG_SET;
707 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
708 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700709 *p_param_values++ = reverb->delay;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800710 param_values[2] += 1;
711 }
712 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
713 *p_param_values++ = REVERB_DIFFUSION;
714 *p_param_values++ = CONFIG_SET;
715 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
716 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700717 *p_param_values++ = reverb->diffusion;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800718 param_values[2] += 1;
719 }
720 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
721 *p_param_values++ = REVERB_DENSITY;
722 *p_param_values++ = CONFIG_SET;
723 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
724 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
Subhash Chandra Bose Naripeddye40a7cd2014-06-03 19:42:41 -0700725 *p_param_values++ = reverb->density;
726 param_values[2] += 1;
727 }
728
729 if ((mode == OFFLOAD) && param_values[2] && ctl) {
730 mixer_ctl_set_array((struct mixer_ctl *)ctl, param_values,
731 ARRAY_SIZE(param_values));
732 } else if ((mode == HW_ACCELERATOR) && param_values[2] &&
733 ctl && *(int *)ctl) {
734 if (ioctl(*(int *)ctl, AUDIO_EFFECTS_SET_PP_PARAMS, param_values) < 0)
735 ALOGE("%s: sending h/w acc effects params fail[%d]", __func__, errno);
736 }
737
738 return 0;
739}
740
741int offload_reverb_send_params(struct mixer_ctl *ctl,
742 struct reverb_params *reverb,
743 unsigned param_send_flags)
744{
745 return reverb_send_params(OFFLOAD, (void *)ctl, reverb,
746 param_send_flags);
747}
748
749int hw_acc_reverb_send_params(int fd, struct reverb_params *reverb,
750 unsigned param_send_flags)
751{
752 return reverb_send_params(HW_ACCELERATOR, (void *)&fd,
753 reverb, param_send_flags);
754}
755
756void offload_soft_volume_set_enable(struct soft_volume_params *vol, bool enable)
757{
758 ALOGV("%s", __func__);
759 vol->enable_flag = enable;
760}
761
762void offload_soft_volume_set_gain_master(struct soft_volume_params *vol, int gain)
763{
764 ALOGV("%s", __func__);
765 vol->master_gain = gain;
766}
767
768void offload_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
769 int l_gain, int r_gain)
770{
771 ALOGV("%s", __func__);
772 vol->left_gain = l_gain;
773 vol->right_gain = r_gain;
774}
775
776int offload_soft_volume_send_params(struct mixer_ctl *ctl,
777 struct soft_volume_params vol,
778 unsigned param_send_flags)
779{
780 int param_values[128] = {0};
781 int *p_param_values = param_values;
782 uint32_t i;
783
784 ALOGV("%s", __func__);
785 *p_param_values++ = SOFT_VOLUME_MODULE;
786 *p_param_values++ = 0;
787 *p_param_values++ = 0; /* num of commands*/
788 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_ENABLE_FLAG) {
789 *p_param_values++ = SOFT_VOLUME_ENABLE;
790 *p_param_values++ = CONFIG_SET;
791 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
792 *p_param_values++ = SOFT_VOLUME_ENABLE_PARAM_LEN;
793 *p_param_values++ = vol.enable_flag;
794 param_values[2] += 1;
795 }
796 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_MASTER) {
797 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER;
798 *p_param_values++ = CONFIG_SET;
799 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
800 *p_param_values++ = SOFT_VOLUME_GAIN_MASTER_PARAM_LEN;
801 *p_param_values++ = vol.master_gain;
802 param_values[2] += 1;
803 }
804 if (param_send_flags & OFFLOAD_SEND_SOFT_VOLUME_GAIN_2CH) {
805 *p_param_values++ = SOFT_VOLUME_GAIN_2CH;
806 *p_param_values++ = CONFIG_SET;
807 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
808 *p_param_values++ = SOFT_VOLUME_GAIN_2CH_PARAM_LEN;
809 *p_param_values++ = vol.left_gain;
810 *p_param_values++ = vol.right_gain;
811 param_values[2] += 1;
812 }
813
814 if (param_values[2] && ctl)
815 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
816
817 return 0;
818}
819
820void offload_transition_soft_volume_set_enable(struct soft_volume_params *vol,
821 bool enable)
822{
823 ALOGV("%s", __func__);
824 vol->enable_flag = enable;
825}
826
827void offload_transition_soft_volume_set_gain_master(struct soft_volume_params *vol,
828 int gain)
829{
830 ALOGV("%s", __func__);
831 vol->master_gain = gain;
832}
833
834void offload_transition_soft_volume_set_gain_2ch(struct soft_volume_params *vol,
835 int l_gain, int r_gain)
836{
837 ALOGV("%s", __func__);
838 vol->left_gain = l_gain;
839 vol->right_gain = r_gain;
840}
841
842int offload_transition_soft_volume_send_params(struct mixer_ctl *ctl,
843 struct soft_volume_params vol,
844 unsigned param_send_flags)
845{
846 int param_values[128] = {0};
847 int *p_param_values = param_values;
848 uint32_t i;
849
850 ALOGV("%s", __func__);
851 *p_param_values++ = SOFT_VOLUME2_MODULE;
852 *p_param_values++ = 0;
853 *p_param_values++ = 0; /* num of commands*/
854 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_ENABLE_FLAG) {
855 *p_param_values++ = SOFT_VOLUME2_ENABLE;
856 *p_param_values++ = CONFIG_SET;
857 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
858 *p_param_values++ = SOFT_VOLUME2_ENABLE_PARAM_LEN;
859 *p_param_values++ = vol.enable_flag;
860 param_values[2] += 1;
861 }
862 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_MASTER) {
863 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER;
864 *p_param_values++ = CONFIG_SET;
865 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
866 *p_param_values++ = SOFT_VOLUME2_GAIN_MASTER_PARAM_LEN;
867 *p_param_values++ = vol.master_gain;
868 param_values[2] += 1;
869 }
870 if (param_send_flags & OFFLOAD_SEND_TRANSITION_SOFT_VOLUME_GAIN_2CH) {
871 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH;
872 *p_param_values++ = CONFIG_SET;
873 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
874 *p_param_values++ = SOFT_VOLUME2_GAIN_2CH_PARAM_LEN;
875 *p_param_values++ = vol.left_gain;
876 *p_param_values++ = vol.right_gain;
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800877 param_values[2] += 1;
878 }
879
880 if (param_values[2] && ctl)
881 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
882
883 return 0;
884}