blob: 327ddb9ccd251f06c6184b921e1abdf79cc79acd [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"
49#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 Naripeddy3eedc002013-11-12 20:45:15 -080062#include "effect_api.h"
63
Jitendra Naruka1b6513f2014-11-22 19:34:13 -080064#ifdef DTS_EAGLE
65#include "effect_util.h"
66#endif
67
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080068#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
69
70#define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19
71const int map_eq_opensl_preset_2_offload_preset[] = {
72 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */
73 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */
74 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */
75 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */
76 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */
77 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */
78 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */
79 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */
80 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */
81 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */
82 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */
83};
84
85const int map_reverb_opensl_preset_2_offload_preset
86 [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = {
87 {1, 15},
88 {2, 16},
89 {3, 17},
90 {4, 18},
91 {5, 3},
92 {6, 20}
93};
94
95int offload_update_mixer_and_effects_ctl(int card, int device_id,
96 struct mixer *mixer,
97 struct mixer_ctl *ctl)
98{
99 char mixer_string[128];
100
101 snprintf(mixer_string, sizeof(mixer_string),
102 "%s %d", "Audio Effects Config", device_id);
103 ALOGV("%s: mixer_string: %s", __func__, mixer_string);
104 mixer = mixer_open(card);
105 if (!mixer) {
106 ALOGE("Failed to open mixer");
107 ctl = NULL;
108 return -EINVAL;
109 } else {
110 ctl = mixer_get_ctl_by_name(mixer, mixer_string);
111 if (!ctl) {
112 ALOGE("mixer_get_ctl_by_name failed");
113 mixer_close(mixer);
114 mixer = NULL;
115 return -EINVAL;
116 }
117 }
118 ALOGV("mixer: %p, ctl: %p", mixer, ctl);
119 return 0;
120}
121
122void offload_close_mixer(struct mixer *mixer)
123{
124 mixer_close(mixer);
125}
126
127void offload_bassboost_set_device(struct bass_boost_params *bassboost,
128 uint32_t device)
129{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530130 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800131 bassboost->device = device;
132}
133
134void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
135 bool enable)
136{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530137 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800138 bassboost->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800139
140#ifdef DTS_EAGLE
141 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
142#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800143}
144
145int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
146{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530147 ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800148 return bassboost->enable_flag;
149}
150
151void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
152 int strength)
153{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530154 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800155 bassboost->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800156
157#ifdef DTS_EAGLE
158 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_BB, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
159#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800160}
161
162void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
163 int mode)
164{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530165 ALOGVV("%s: mode %d", __func__, mode);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800166 bassboost->mode = mode;
167}
168
169int offload_bassboost_send_params(struct mixer_ctl *ctl,
170 struct bass_boost_params bassboost,
171 unsigned param_send_flags)
172{
173 int param_values[128] = {0};
174 int *p_param_values = param_values;
175
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530176 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800177 *p_param_values++ = BASS_BOOST_MODULE;
178 *p_param_values++ = bassboost.device;
179 *p_param_values++ = 0; /* num of commands*/
180 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
181 *p_param_values++ = BASS_BOOST_ENABLE;
182 *p_param_values++ = CONFIG_SET;
183 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
184 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
185 *p_param_values++ = bassboost.enable_flag;
186 param_values[2] += 1;
187 }
188 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
189 *p_param_values++ = BASS_BOOST_STRENGTH;
190 *p_param_values++ = CONFIG_SET;
191 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
192 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
193 *p_param_values++ = bassboost.strength;
194 param_values[2] += 1;
195 }
196 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
197 *p_param_values++ = BASS_BOOST_MODE;
198 *p_param_values++ = CONFIG_SET;
199 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
200 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
201 *p_param_values++ = bassboost.mode;
202 param_values[2] += 1;
203 }
204
205 if (param_values[2] && ctl)
206 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
207
208 return 0;
209}
210
211void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
212 uint32_t device)
213{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530214 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800215 virtualizer->device = device;
216}
217
218void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
219 bool enable)
220{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530221 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800222 virtualizer->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800223
224#ifdef DTS_EAGLE
225 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
226#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800227}
228
229int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
230{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530231 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800232 return virtualizer->enable_flag;
233}
234
235void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
236 int strength)
237{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530238 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800239 virtualizer->strength = strength;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800240
241#ifdef DTS_EAGLE
242 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_VIRT, EFFECT_SET_PARAM, EFFECT_NO_OP, strength, EFFECT_NO_OP, EFFECT_NO_OP);
243#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800244}
245
246void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
247 int out_type)
248{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530249 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800250 virtualizer->out_type = out_type;
251}
252
253void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
254 int gain_adjust)
255{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530256 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800257 virtualizer->gain_adjust = gain_adjust;
258}
259
260int offload_virtualizer_send_params(struct mixer_ctl *ctl,
261 struct virtualizer_params virtualizer,
262 unsigned param_send_flags)
263{
264 int param_values[128] = {0};
265 int *p_param_values = param_values;
266
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530267 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800268 *p_param_values++ = VIRTUALIZER_MODULE;
269 *p_param_values++ = virtualizer.device;
270 *p_param_values++ = 0; /* num of commands*/
271 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
272 *p_param_values++ = VIRTUALIZER_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++ = VIRTUALIZER_ENABLE_PARAM_LEN;
276 *p_param_values++ = virtualizer.enable_flag;
277 param_values[2] += 1;
278 }
279 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
280 *p_param_values++ = VIRTUALIZER_STRENGTH;
281 *p_param_values++ = CONFIG_SET;
282 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
283 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
284 *p_param_values++ = virtualizer.strength;
285 param_values[2] += 1;
286 }
287 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
288 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
289 *p_param_values++ = CONFIG_SET;
290 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
291 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
292 *p_param_values++ = virtualizer.out_type;
293 param_values[2] += 1;
294 }
295 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
296 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
297 *p_param_values++ = CONFIG_SET;
298 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
299 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
300 *p_param_values++ = virtualizer.gain_adjust;
301 param_values[2] += 1;
302 }
303
304 if (param_values[2] && ctl)
305 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
306
307 return 0;
308}
309
310void offload_eq_set_device(struct eq_params *eq, uint32_t device)
311{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530312 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800313 eq->device = device;
314}
315
316void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
317{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530318 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800319 eq->enable_flag = enable;
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800320
321#ifdef DTS_EAGLE
322 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_ENABLE_PARAM, enable, EFFECT_NO_OP, EFFECT_NO_OP, EFFECT_NO_OP);
323#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800324}
325
326int offload_eq_get_enable_flag(struct eq_params *eq)
327{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530328 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800329 return eq->enable_flag;
330}
331
332void offload_eq_set_preset(struct eq_params *eq, int preset)
333{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530334 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800335 eq->config.preset_id = preset;
336 eq->config.eq_pregain = Q27_UNITY;
337}
338
339void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
340 const uint16_t *band_freq_list,
341 int *band_gain_list)
342{
343 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530344 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800345 eq->config.num_bands = num_bands;
346 for (i=0; i<num_bands; i++) {
347 eq->per_band_cfg[i].band_idx = i;
348 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
349 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
350 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
351 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
352 }
Jitendra Naruka1b6513f2014-11-22 19:34:13 -0800353
354#ifdef DTS_EAGLE
355 update_effects_node(PCM_DEV_ID, EFFECT_TYPE_EQ, EFFECT_SET_PARAM, EFFECT_NO_OP, EFFECT_NO_OP, i, band_gain_list[i] * 100);
356#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800357}
358
359int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params eq,
360 unsigned param_send_flags)
361{
362 int param_values[128] = {0};
363 int *p_param_values = param_values;
364 uint32_t i;
365
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530366 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
wjiangebb69fa2014-05-15 19:38:26 +0800367 if ((eq.config.preset_id < -1) ||
368 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq.config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800369 ALOGV("No Valid preset to set");
370 return 0;
371 }
372 *p_param_values++ = EQ_MODULE;
373 *p_param_values++ = eq.device;
374 *p_param_values++ = 0; /* num of commands*/
375 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
376 *p_param_values++ = EQ_ENABLE;
377 *p_param_values++ = CONFIG_SET;
378 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
379 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
380 *p_param_values++ = eq.enable_flag;
381 param_values[2] += 1;
382 }
383 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
384 *p_param_values++ = EQ_CONFIG;
385 *p_param_values++ = CONFIG_SET;
386 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
387 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
388 *p_param_values++ = eq.config.eq_pregain;
389 *p_param_values++ =
390 map_eq_opensl_preset_2_offload_preset[eq.config.preset_id];
391 *p_param_values++ = 0;
392 param_values[2] += 1;
393 }
394 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
395 *p_param_values++ = EQ_CONFIG;
396 *p_param_values++ = CONFIG_SET;
397 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
398 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
399 eq.config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
400 *p_param_values++ = eq.config.eq_pregain;
401 *p_param_values++ = CUSTOM_OPENSL_PRESET;
402 *p_param_values++ = eq.config.num_bands;
403 for (i=0; i<eq.config.num_bands; i++) {
404 *p_param_values++ = eq.per_band_cfg[i].band_idx;
405 *p_param_values++ = eq.per_band_cfg[i].filter_type;
406 *p_param_values++ = eq.per_band_cfg[i].freq_millihertz;
407 *p_param_values++ = eq.per_band_cfg[i].gain_millibels;
408 *p_param_values++ = eq.per_band_cfg[i].quality_factor;
409 }
410 param_values[2] += 1;
411 }
412
413 if (param_values[2] && ctl)
414 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
415
416 return 0;
417}
418
419void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
420{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530421 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800422 reverb->device = device;
423}
424
425void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
426{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530427 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800428 reverb->enable_flag = enable;
429}
430
431int offload_reverb_get_enable_flag(struct reverb_params *reverb)
432{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530433 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800434 return reverb->enable_flag;
435}
436
437void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
438{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530439 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800440 reverb->mode = mode;
441}
442
443void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
444{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530445 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800446 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800447 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800448}
449
450void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
451{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530452 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800453 reverb->wet_mix = wet_mix;
454}
455
456void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
457 int gain_adjust)
458{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530459 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800460 reverb->gain_adjust = gain_adjust;
461}
462
463void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
464{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530465 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800466 reverb->room_level = room_level;
467}
468
469void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
470 int room_hf_level)
471{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530472 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800473 reverb->room_hf_level = room_hf_level;
474}
475
476void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
477{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530478 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800479 reverb->decay_time = decay_time;
480}
481
482void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
483 int decay_hf_ratio)
484{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530485 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800486 reverb->decay_hf_ratio = decay_hf_ratio;
487}
488
489void offload_reverb_set_reflections_level(struct reverb_params *reverb,
490 int reflections_level)
491{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530492 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800493 reverb->reflections_level = reflections_level;
494}
495
496void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
497 int reflections_delay)
498{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530499 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800500 reverb->reflections_delay = reflections_delay;
501}
502
503void offload_reverb_set_reverb_level(struct reverb_params *reverb,
504 int reverb_level)
505{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530506 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800507 reverb->level = reverb_level;
508}
509
510void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
511{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530512 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800513 reverb->delay = delay;
514}
515
516void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
517{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530518 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800519 reverb->diffusion = diffusion;
520}
521
522void offload_reverb_set_density(struct reverb_params *reverb, int density)
523{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530524 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800525 reverb->density = density;
526}
527
528int offload_reverb_send_params(struct mixer_ctl *ctl,
529 struct reverb_params reverb,
530 unsigned param_send_flags)
531{
532 int param_values[128] = {0};
533 int *p_param_values = param_values;
534
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530535 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800536 *p_param_values++ = REVERB_MODULE;
537 *p_param_values++ = reverb.device;
538 *p_param_values++ = 0; /* num of commands*/
539
540 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
541 *p_param_values++ = REVERB_ENABLE;
542 *p_param_values++ = CONFIG_SET;
543 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
544 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
545 *p_param_values++ = reverb.enable_flag;
546 param_values[2] += 1;
547 }
548 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
549 *p_param_values++ = REVERB_MODE;
550 *p_param_values++ = CONFIG_SET;
551 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
552 *p_param_values++ = REVERB_MODE_PARAM_LEN;
553 *p_param_values++ = reverb.mode;
554 param_values[2] += 1;
555 }
556 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
557 *p_param_values++ = REVERB_PRESET;
558 *p_param_values++ = CONFIG_SET;
559 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
560 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
561 *p_param_values++ = reverb.preset;
562 param_values[2] += 1;
563 }
564 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
565 *p_param_values++ = REVERB_WET_MIX;
566 *p_param_values++ = CONFIG_SET;
567 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
568 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
569 *p_param_values++ = reverb.wet_mix;
570 param_values[2] += 1;
571 }
572 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
573 *p_param_values++ = REVERB_GAIN_ADJUST;
574 *p_param_values++ = CONFIG_SET;
575 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
576 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
577 *p_param_values++ = reverb.gain_adjust;
578 param_values[2] += 1;
579 }
580 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
581 *p_param_values++ = REVERB_ROOM_LEVEL;
582 *p_param_values++ = CONFIG_SET;
583 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
584 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
585 *p_param_values++ = reverb.room_level;
586 param_values[2] += 1;
587 }
588 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
589 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
590 *p_param_values++ = CONFIG_SET;
591 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
592 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
593 *p_param_values++ = reverb.room_hf_level;
594 param_values[2] += 1;
595 }
596 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
597 *p_param_values++ = REVERB_DECAY_TIME;
598 *p_param_values++ = CONFIG_SET;
599 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
600 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
601 *p_param_values++ = reverb.decay_time;
602 param_values[2] += 1;
603 }
604 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
605 *p_param_values++ = REVERB_DECAY_HF_RATIO;
606 *p_param_values++ = CONFIG_SET;
607 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
608 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
609 *p_param_values++ = reverb.decay_hf_ratio;
610 param_values[2] += 1;
611 }
612 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
613 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
614 *p_param_values++ = CONFIG_SET;
615 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
616 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
617 *p_param_values++ = reverb.reflections_level;
618 param_values[2] += 1;
619 }
620 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
621 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
622 *p_param_values++ = CONFIG_SET;
623 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
624 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
625 *p_param_values++ = reverb.reflections_delay;
626 param_values[2] += 1;
627 }
628 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
629 *p_param_values++ = REVERB_LEVEL;
630 *p_param_values++ = CONFIG_SET;
631 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
632 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
633 *p_param_values++ = reverb.level;
634 param_values[2] += 1;
635 }
636 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
637 *p_param_values++ = REVERB_DELAY;
638 *p_param_values++ = CONFIG_SET;
639 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
640 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
641 *p_param_values++ = reverb.delay;
642 param_values[2] += 1;
643 }
644 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
645 *p_param_values++ = REVERB_DIFFUSION;
646 *p_param_values++ = CONFIG_SET;
647 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
648 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
649 *p_param_values++ = reverb.diffusion;
650 param_values[2] += 1;
651 }
652 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
653 *p_param_values++ = REVERB_DENSITY;
654 *p_param_values++ = CONFIG_SET;
655 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
656 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
657 *p_param_values++ = reverb.density;
658 param_values[2] += 1;
659 }
660
661 if (param_values[2] && ctl)
662 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
663
664 return 0;
665}