blob: bad6ee10b43e52bb8f909d3dee22bbd6cc06571f [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.
28 */
29
30#define LOG_TAG "offload_effect_api"
31#define LOG_NDEBUG 0
Dhananjay Kumar574f3922014-03-25 17:41:44 +053032//#define VERY_VERY_VERBOSE_LOGGING
33#ifdef VERY_VERY_VERBOSE_LOGGING
34#define ALOGVV ALOGV
35#else
36#define ALOGVV(a...) do { } while(0)
37#endif
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080038
39#include <stdbool.h>
40#include <cutils/log.h>
41#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080042#include <sound/audio_effects.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080043
44#include "effect_api.h"
45
46#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
47
48#define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19
49const int map_eq_opensl_preset_2_offload_preset[] = {
50 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */
51 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */
52 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */
53 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */
54 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */
55 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */
56 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */
57 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */
58 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */
59 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */
60 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */
61};
62
63const int map_reverb_opensl_preset_2_offload_preset
64 [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = {
65 {1, 15},
66 {2, 16},
67 {3, 17},
68 {4, 18},
69 {5, 3},
70 {6, 20}
71};
72
73int offload_update_mixer_and_effects_ctl(int card, int device_id,
74 struct mixer *mixer,
75 struct mixer_ctl *ctl)
76{
77 char mixer_string[128];
78
79 snprintf(mixer_string, sizeof(mixer_string),
80 "%s %d", "Audio Effects Config", device_id);
81 ALOGV("%s: mixer_string: %s", __func__, mixer_string);
82 mixer = mixer_open(card);
83 if (!mixer) {
84 ALOGE("Failed to open mixer");
85 ctl = NULL;
86 return -EINVAL;
87 } else {
88 ctl = mixer_get_ctl_by_name(mixer, mixer_string);
89 if (!ctl) {
90 ALOGE("mixer_get_ctl_by_name failed");
91 mixer_close(mixer);
92 mixer = NULL;
93 return -EINVAL;
94 }
95 }
96 ALOGV("mixer: %p, ctl: %p", mixer, ctl);
97 return 0;
98}
99
100void offload_close_mixer(struct mixer *mixer)
101{
102 mixer_close(mixer);
103}
104
105void offload_bassboost_set_device(struct bass_boost_params *bassboost,
106 uint32_t device)
107{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530108 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800109 bassboost->device = device;
110}
111
112void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
113 bool enable)
114{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530115 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800116 bassboost->enable_flag = enable;
117}
118
119int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
120{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530121 ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800122 return bassboost->enable_flag;
123}
124
125void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
126 int strength)
127{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530128 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800129 bassboost->strength = strength;
130}
131
132void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
133 int mode)
134{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530135 ALOGVV("%s: mode %d", __func__, mode);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800136 bassboost->mode = mode;
137}
138
139int offload_bassboost_send_params(struct mixer_ctl *ctl,
140 struct bass_boost_params bassboost,
141 unsigned param_send_flags)
142{
143 int param_values[128] = {0};
144 int *p_param_values = param_values;
145
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530146 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800147 *p_param_values++ = BASS_BOOST_MODULE;
148 *p_param_values++ = bassboost.device;
149 *p_param_values++ = 0; /* num of commands*/
150 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
151 *p_param_values++ = BASS_BOOST_ENABLE;
152 *p_param_values++ = CONFIG_SET;
153 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
154 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
155 *p_param_values++ = bassboost.enable_flag;
156 param_values[2] += 1;
157 }
158 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
159 *p_param_values++ = BASS_BOOST_STRENGTH;
160 *p_param_values++ = CONFIG_SET;
161 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
162 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
163 *p_param_values++ = bassboost.strength;
164 param_values[2] += 1;
165 }
166 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
167 *p_param_values++ = BASS_BOOST_MODE;
168 *p_param_values++ = CONFIG_SET;
169 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
170 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
171 *p_param_values++ = bassboost.mode;
172 param_values[2] += 1;
173 }
174
175 if (param_values[2] && ctl)
176 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
177
178 return 0;
179}
180
181void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
182 uint32_t device)
183{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530184 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800185 virtualizer->device = device;
186}
187
188void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
189 bool enable)
190{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530191 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800192 virtualizer->enable_flag = enable;
193}
194
195int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
196{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530197 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800198 return virtualizer->enable_flag;
199}
200
201void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
202 int strength)
203{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530204 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800205 virtualizer->strength = strength;
206}
207
208void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
209 int out_type)
210{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530211 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800212 virtualizer->out_type = out_type;
213}
214
215void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
216 int gain_adjust)
217{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530218 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800219 virtualizer->gain_adjust = gain_adjust;
220}
221
222int offload_virtualizer_send_params(struct mixer_ctl *ctl,
223 struct virtualizer_params virtualizer,
224 unsigned param_send_flags)
225{
226 int param_values[128] = {0};
227 int *p_param_values = param_values;
228
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530229 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800230 *p_param_values++ = VIRTUALIZER_MODULE;
231 *p_param_values++ = virtualizer.device;
232 *p_param_values++ = 0; /* num of commands*/
233 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
234 *p_param_values++ = VIRTUALIZER_ENABLE;
235 *p_param_values++ = CONFIG_SET;
236 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
237 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
238 *p_param_values++ = virtualizer.enable_flag;
239 param_values[2] += 1;
240 }
241 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
242 *p_param_values++ = VIRTUALIZER_STRENGTH;
243 *p_param_values++ = CONFIG_SET;
244 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
245 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
246 *p_param_values++ = virtualizer.strength;
247 param_values[2] += 1;
248 }
249 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
250 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
251 *p_param_values++ = CONFIG_SET;
252 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
253 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
254 *p_param_values++ = virtualizer.out_type;
255 param_values[2] += 1;
256 }
257 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
258 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
259 *p_param_values++ = CONFIG_SET;
260 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
261 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
262 *p_param_values++ = virtualizer.gain_adjust;
263 param_values[2] += 1;
264 }
265
266 if (param_values[2] && ctl)
267 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
268
269 return 0;
270}
271
272void offload_eq_set_device(struct eq_params *eq, uint32_t device)
273{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530274 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800275 eq->device = device;
276}
277
278void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
279{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530280 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800281 eq->enable_flag = enable;
282}
283
284int offload_eq_get_enable_flag(struct eq_params *eq)
285{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530286 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800287 return eq->enable_flag;
288}
289
290void offload_eq_set_preset(struct eq_params *eq, int preset)
291{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530292 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800293 eq->config.preset_id = preset;
294 eq->config.eq_pregain = Q27_UNITY;
295}
296
297void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
298 const uint16_t *band_freq_list,
299 int *band_gain_list)
300{
301 int i;
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530302 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800303 eq->config.num_bands = num_bands;
304 for (i=0; i<num_bands; i++) {
305 eq->per_band_cfg[i].band_idx = i;
306 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
307 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
308 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
309 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
310 }
311}
312
313int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params eq,
314 unsigned param_send_flags)
315{
316 int param_values[128] = {0};
317 int *p_param_values = param_values;
318 uint32_t i;
319
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530320 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800321 if (eq.config.preset_id < -1 ) {
322 ALOGV("No Valid preset to set");
323 return 0;
324 }
325 *p_param_values++ = EQ_MODULE;
326 *p_param_values++ = eq.device;
327 *p_param_values++ = 0; /* num of commands*/
328 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
329 *p_param_values++ = EQ_ENABLE;
330 *p_param_values++ = CONFIG_SET;
331 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
332 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
333 *p_param_values++ = eq.enable_flag;
334 param_values[2] += 1;
335 }
336 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
337 *p_param_values++ = EQ_CONFIG;
338 *p_param_values++ = CONFIG_SET;
339 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
340 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
341 *p_param_values++ = eq.config.eq_pregain;
342 *p_param_values++ =
343 map_eq_opensl_preset_2_offload_preset[eq.config.preset_id];
344 *p_param_values++ = 0;
345 param_values[2] += 1;
346 }
347 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
348 *p_param_values++ = EQ_CONFIG;
349 *p_param_values++ = CONFIG_SET;
350 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
351 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
352 eq.config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
353 *p_param_values++ = eq.config.eq_pregain;
354 *p_param_values++ = CUSTOM_OPENSL_PRESET;
355 *p_param_values++ = eq.config.num_bands;
356 for (i=0; i<eq.config.num_bands; i++) {
357 *p_param_values++ = eq.per_band_cfg[i].band_idx;
358 *p_param_values++ = eq.per_band_cfg[i].filter_type;
359 *p_param_values++ = eq.per_band_cfg[i].freq_millihertz;
360 *p_param_values++ = eq.per_band_cfg[i].gain_millibels;
361 *p_param_values++ = eq.per_band_cfg[i].quality_factor;
362 }
363 param_values[2] += 1;
364 }
365
366 if (param_values[2] && ctl)
367 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
368
369 return 0;
370}
371
372void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
373{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530374 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800375 reverb->device = device;
376}
377
378void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
379{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530380 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800381 reverb->enable_flag = enable;
382}
383
384int offload_reverb_get_enable_flag(struct reverb_params *reverb)
385{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530386 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800387 return reverb->enable_flag;
388}
389
390void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
391{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530392 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800393 reverb->mode = mode;
394}
395
396void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
397{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530398 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800399 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiangca2685b2014-03-18 06:43:48 +0800400 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800401}
402
403void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
404{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530405 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800406 reverb->wet_mix = wet_mix;
407}
408
409void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
410 int gain_adjust)
411{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530412 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800413 reverb->gain_adjust = gain_adjust;
414}
415
416void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
417{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530418 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800419 reverb->room_level = room_level;
420}
421
422void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
423 int room_hf_level)
424{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530425 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800426 reverb->room_hf_level = room_hf_level;
427}
428
429void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
430{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530431 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800432 reverb->decay_time = decay_time;
433}
434
435void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
436 int decay_hf_ratio)
437{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530438 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800439 reverb->decay_hf_ratio = decay_hf_ratio;
440}
441
442void offload_reverb_set_reflections_level(struct reverb_params *reverb,
443 int reflections_level)
444{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530445 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800446 reverb->reflections_level = reflections_level;
447}
448
449void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
450 int reflections_delay)
451{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530452 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800453 reverb->reflections_delay = reflections_delay;
454}
455
456void offload_reverb_set_reverb_level(struct reverb_params *reverb,
457 int reverb_level)
458{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530459 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800460 reverb->level = reverb_level;
461}
462
463void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
464{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530465 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800466 reverb->delay = delay;
467}
468
469void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
470{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530471 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800472 reverb->diffusion = diffusion;
473}
474
475void offload_reverb_set_density(struct reverb_params *reverb, int density)
476{
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530477 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800478 reverb->density = density;
479}
480
481int offload_reverb_send_params(struct mixer_ctl *ctl,
482 struct reverb_params reverb,
483 unsigned param_send_flags)
484{
485 int param_values[128] = {0};
486 int *p_param_values = param_values;
487
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530488 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800489 *p_param_values++ = REVERB_MODULE;
490 *p_param_values++ = reverb.device;
491 *p_param_values++ = 0; /* num of commands*/
492
493 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
494 *p_param_values++ = REVERB_ENABLE;
495 *p_param_values++ = CONFIG_SET;
496 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
497 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
498 *p_param_values++ = reverb.enable_flag;
499 param_values[2] += 1;
500 }
501 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
502 *p_param_values++ = REVERB_MODE;
503 *p_param_values++ = CONFIG_SET;
504 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
505 *p_param_values++ = REVERB_MODE_PARAM_LEN;
506 *p_param_values++ = reverb.mode;
507 param_values[2] += 1;
508 }
509 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
510 *p_param_values++ = REVERB_PRESET;
511 *p_param_values++ = CONFIG_SET;
512 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
513 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
514 *p_param_values++ = reverb.preset;
515 param_values[2] += 1;
516 }
517 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
518 *p_param_values++ = REVERB_WET_MIX;
519 *p_param_values++ = CONFIG_SET;
520 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
521 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
522 *p_param_values++ = reverb.wet_mix;
523 param_values[2] += 1;
524 }
525 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
526 *p_param_values++ = REVERB_GAIN_ADJUST;
527 *p_param_values++ = CONFIG_SET;
528 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
529 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
530 *p_param_values++ = reverb.gain_adjust;
531 param_values[2] += 1;
532 }
533 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
534 *p_param_values++ = REVERB_ROOM_LEVEL;
535 *p_param_values++ = CONFIG_SET;
536 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
537 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
538 *p_param_values++ = reverb.room_level;
539 param_values[2] += 1;
540 }
541 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
542 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
543 *p_param_values++ = CONFIG_SET;
544 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
545 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
546 *p_param_values++ = reverb.room_hf_level;
547 param_values[2] += 1;
548 }
549 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
550 *p_param_values++ = REVERB_DECAY_TIME;
551 *p_param_values++ = CONFIG_SET;
552 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
553 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
554 *p_param_values++ = reverb.decay_time;
555 param_values[2] += 1;
556 }
557 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
558 *p_param_values++ = REVERB_DECAY_HF_RATIO;
559 *p_param_values++ = CONFIG_SET;
560 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
561 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
562 *p_param_values++ = reverb.decay_hf_ratio;
563 param_values[2] += 1;
564 }
565 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
566 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
567 *p_param_values++ = CONFIG_SET;
568 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
569 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
570 *p_param_values++ = reverb.reflections_level;
571 param_values[2] += 1;
572 }
573 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
574 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
575 *p_param_values++ = CONFIG_SET;
576 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
577 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
578 *p_param_values++ = reverb.reflections_delay;
579 param_values[2] += 1;
580 }
581 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
582 *p_param_values++ = REVERB_LEVEL;
583 *p_param_values++ = CONFIG_SET;
584 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
585 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
586 *p_param_values++ = reverb.level;
587 param_values[2] += 1;
588 }
589 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
590 *p_param_values++ = REVERB_DELAY;
591 *p_param_values++ = CONFIG_SET;
592 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
593 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
594 *p_param_values++ = reverb.delay;
595 param_values[2] += 1;
596 }
597 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
598 *p_param_values++ = REVERB_DIFFUSION;
599 *p_param_values++ = CONFIG_SET;
600 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
601 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
602 *p_param_values++ = reverb.diffusion;
603 param_values[2] += 1;
604 }
605 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
606 *p_param_values++ = REVERB_DENSITY;
607 *p_param_values++ = CONFIG_SET;
608 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
609 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
610 *p_param_values++ = reverb.density;
611 param_values[2] += 1;
612 }
613
614 if (param_values[2] && ctl)
615 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
616
617 return 0;
618}