blob: 8b8f119568f4f90973cf24272bce31a59238411d [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
wjiang120b9ea2014-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 Kumarb2c7ac12014-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>
42#include <audio_effects.h>
43
44#include "effect_api.h"
Ramjee Singh7f718d52015-08-13 18:41:11 +053045#include <errno.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080046
47#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
48
49#define OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL 19
50const int map_eq_opensl_preset_2_offload_preset[] = {
51 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL, /* Normal Preset */
52 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+1, /* Classical Preset */
53 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+2, /* Dance Preset */
54 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+3, /* Flat Preset */
55 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+4, /* Folk Preset */
56 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+5, /* Heavy Metal Preset */
57 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+6, /* Hip Hop Preset */
58 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+7, /* Jazz Preset */
59 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+8, /* Pop Preset */
60 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+9, /* Rock Preset */
61 OFFLOAD_PRESET_START_OFFSET_FOR_OPENSL+10 /* FX Booster */
62};
63
64const int map_reverb_opensl_preset_2_offload_preset
65 [NUM_OSL_REVERB_PRESETS_SUPPORTED][2] = {
66 {1, 15},
67 {2, 16},
68 {3, 17},
69 {4, 18},
70 {5, 3},
71 {6, 20}
72};
73
74int offload_update_mixer_and_effects_ctl(int card, int device_id,
75 struct mixer *mixer,
76 struct mixer_ctl *ctl)
77{
78 char mixer_string[128];
79
80 snprintf(mixer_string, sizeof(mixer_string),
81 "%s %d", "Audio Effects Config", device_id);
82 ALOGV("%s: mixer_string: %s", __func__, mixer_string);
83 mixer = mixer_open(card);
84 if (!mixer) {
85 ALOGE("Failed to open mixer");
86 ctl = NULL;
87 return -EINVAL;
88 } else {
89 ctl = mixer_get_ctl_by_name(mixer, mixer_string);
90 if (!ctl) {
91 ALOGE("mixer_get_ctl_by_name failed");
92 mixer_close(mixer);
93 mixer = NULL;
94 return -EINVAL;
95 }
96 }
97 ALOGV("mixer: %p, ctl: %p", mixer, ctl);
98 return 0;
99}
100
101void offload_close_mixer(struct mixer *mixer)
102{
103 mixer_close(mixer);
104}
105
106void offload_bassboost_set_device(struct bass_boost_params *bassboost,
107 uint32_t device)
108{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530109 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800110 bassboost->device = device;
111}
112
113void offload_bassboost_set_enable_flag(struct bass_boost_params *bassboost,
114 bool enable)
115{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530116 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800117 bassboost->enable_flag = enable;
118}
119
120int offload_bassboost_get_enable_flag(struct bass_boost_params *bassboost)
121{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530122 ALOGVV("%s: enable=%d", __func__, (int)bassboost->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800123 return bassboost->enable_flag;
124}
125
126void offload_bassboost_set_strength(struct bass_boost_params *bassboost,
127 int strength)
128{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530129 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800130 bassboost->strength = strength;
131}
132
133void offload_bassboost_set_mode(struct bass_boost_params *bassboost,
134 int mode)
135{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530136 ALOGVV("%s: mode %d", __func__, mode);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800137 bassboost->mode = mode;
138}
139
140int offload_bassboost_send_params(struct mixer_ctl *ctl,
141 struct bass_boost_params bassboost,
142 unsigned param_send_flags)
143{
144 int param_values[128] = {0};
145 int *p_param_values = param_values;
146
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530147 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800148 *p_param_values++ = BASS_BOOST_MODULE;
149 *p_param_values++ = bassboost.device;
150 *p_param_values++ = 0; /* num of commands*/
151 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG) {
152 *p_param_values++ = BASS_BOOST_ENABLE;
153 *p_param_values++ = CONFIG_SET;
154 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
155 *p_param_values++ = BASS_BOOST_ENABLE_PARAM_LEN;
156 *p_param_values++ = bassboost.enable_flag;
157 param_values[2] += 1;
158 }
159 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_STRENGTH) {
160 *p_param_values++ = BASS_BOOST_STRENGTH;
161 *p_param_values++ = CONFIG_SET;
162 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
163 *p_param_values++ = BASS_BOOST_STRENGTH_PARAM_LEN;
164 *p_param_values++ = bassboost.strength;
165 param_values[2] += 1;
166 }
167 if (param_send_flags & OFFLOAD_SEND_BASSBOOST_MODE) {
168 *p_param_values++ = BASS_BOOST_MODE;
169 *p_param_values++ = CONFIG_SET;
170 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
171 *p_param_values++ = BASS_BOOST_MODE_PARAM_LEN;
172 *p_param_values++ = bassboost.mode;
173 param_values[2] += 1;
174 }
175
176 if (param_values[2] && ctl)
177 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
178
179 return 0;
180}
181
182void offload_virtualizer_set_device(struct virtualizer_params *virtualizer,
183 uint32_t device)
184{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530185 ALOGVV("%s: device=0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800186 virtualizer->device = device;
187}
188
189void offload_virtualizer_set_enable_flag(struct virtualizer_params *virtualizer,
190 bool enable)
191{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530192 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800193 virtualizer->enable_flag = enable;
194}
195
196int offload_virtualizer_get_enable_flag(struct virtualizer_params *virtualizer)
197{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530198 ALOGVV("%s: enabled %d", __func__, (int)virtualizer->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800199 return virtualizer->enable_flag;
200}
201
202void offload_virtualizer_set_strength(struct virtualizer_params *virtualizer,
203 int strength)
204{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530205 ALOGVV("%s: strength %d", __func__, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800206 virtualizer->strength = strength;
207}
208
209void offload_virtualizer_set_out_type(struct virtualizer_params *virtualizer,
210 int out_type)
211{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530212 ALOGVV("%s: out_type %d", __func__, out_type);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800213 virtualizer->out_type = out_type;
214}
215
216void offload_virtualizer_set_gain_adjust(struct virtualizer_params *virtualizer,
217 int gain_adjust)
218{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530219 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800220 virtualizer->gain_adjust = gain_adjust;
221}
222
223int offload_virtualizer_send_params(struct mixer_ctl *ctl,
224 struct virtualizer_params virtualizer,
225 unsigned param_send_flags)
226{
227 int param_values[128] = {0};
228 int *p_param_values = param_values;
229
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530230 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800231 *p_param_values++ = VIRTUALIZER_MODULE;
232 *p_param_values++ = virtualizer.device;
233 *p_param_values++ = 0; /* num of commands*/
234 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_ENABLE_FLAG) {
235 *p_param_values++ = VIRTUALIZER_ENABLE;
236 *p_param_values++ = CONFIG_SET;
237 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
238 *p_param_values++ = VIRTUALIZER_ENABLE_PARAM_LEN;
239 *p_param_values++ = virtualizer.enable_flag;
240 param_values[2] += 1;
241 }
242 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_STRENGTH) {
243 *p_param_values++ = VIRTUALIZER_STRENGTH;
244 *p_param_values++ = CONFIG_SET;
245 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
246 *p_param_values++ = VIRTUALIZER_STRENGTH_PARAM_LEN;
247 *p_param_values++ = virtualizer.strength;
248 param_values[2] += 1;
249 }
250 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_OUT_TYPE) {
251 *p_param_values++ = VIRTUALIZER_OUT_TYPE;
252 *p_param_values++ = CONFIG_SET;
253 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
254 *p_param_values++ = VIRTUALIZER_OUT_TYPE_PARAM_LEN;
255 *p_param_values++ = virtualizer.out_type;
256 param_values[2] += 1;
257 }
258 if (param_send_flags & OFFLOAD_SEND_VIRTUALIZER_GAIN_ADJUST) {
259 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST;
260 *p_param_values++ = CONFIG_SET;
261 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
262 *p_param_values++ = VIRTUALIZER_GAIN_ADJUST_PARAM_LEN;
263 *p_param_values++ = virtualizer.gain_adjust;
264 param_values[2] += 1;
265 }
266
267 if (param_values[2] && ctl)
268 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
269
270 return 0;
271}
272
273void offload_eq_set_device(struct eq_params *eq, uint32_t device)
274{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530275 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800276 eq->device = device;
277}
278
279void offload_eq_set_enable_flag(struct eq_params *eq, bool enable)
280{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530281 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800282 eq->enable_flag = enable;
283}
284
285int offload_eq_get_enable_flag(struct eq_params *eq)
286{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530287 ALOGVV("%s: enabled=%d", __func__, (int)eq->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800288 return eq->enable_flag;
289}
290
291void offload_eq_set_preset(struct eq_params *eq, int preset)
292{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530293 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800294 eq->config.preset_id = preset;
295 eq->config.eq_pregain = Q27_UNITY;
296}
297
298void offload_eq_set_bands_level(struct eq_params *eq, int num_bands,
299 const uint16_t *band_freq_list,
300 int *band_gain_list)
301{
302 int i;
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530303 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800304 eq->config.num_bands = num_bands;
305 for (i=0; i<num_bands; i++) {
306 eq->per_band_cfg[i].band_idx = i;
307 eq->per_band_cfg[i].filter_type = EQ_BAND_BOOST;
308 eq->per_band_cfg[i].freq_millihertz = band_freq_list[i] * 1000;
309 eq->per_band_cfg[i].gain_millibels = band_gain_list[i] * 100;
310 eq->per_band_cfg[i].quality_factor = Q8_UNITY;
311 }
312}
313
314int offload_eq_send_params(struct mixer_ctl *ctl, struct eq_params eq,
315 unsigned param_send_flags)
316{
317 int param_values[128] = {0};
318 int *p_param_values = param_values;
319 uint32_t i;
320
wjiang74ff5952014-05-15 19:38:26 +0800321 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
322 if ((eq.config.preset_id < -1) ||
323 ((param_send_flags & OFFLOAD_SEND_EQ_PRESET) && (eq.config.preset_id == -1))) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800324 ALOGV("No Valid preset to set");
325 return 0;
326 }
327 *p_param_values++ = EQ_MODULE;
328 *p_param_values++ = eq.device;
329 *p_param_values++ = 0; /* num of commands*/
330 if (param_send_flags & OFFLOAD_SEND_EQ_ENABLE_FLAG) {
331 *p_param_values++ = EQ_ENABLE;
332 *p_param_values++ = CONFIG_SET;
333 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
334 *p_param_values++ = EQ_ENABLE_PARAM_LEN;
335 *p_param_values++ = eq.enable_flag;
336 param_values[2] += 1;
337 }
338 if (param_send_flags & OFFLOAD_SEND_EQ_PRESET) {
339 *p_param_values++ = EQ_CONFIG;
340 *p_param_values++ = CONFIG_SET;
341 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
342 *p_param_values++ = EQ_CONFIG_PARAM_LEN;
343 *p_param_values++ = eq.config.eq_pregain;
344 *p_param_values++ =
345 map_eq_opensl_preset_2_offload_preset[eq.config.preset_id];
346 *p_param_values++ = 0;
347 param_values[2] += 1;
348 }
349 if (param_send_flags & OFFLOAD_SEND_EQ_BANDS_LEVEL) {
350 *p_param_values++ = EQ_CONFIG;
351 *p_param_values++ = CONFIG_SET;
352 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
353 *p_param_values++ = EQ_CONFIG_PARAM_LEN +
354 eq.config.num_bands * EQ_CONFIG_PER_BAND_PARAM_LEN;
355 *p_param_values++ = eq.config.eq_pregain;
356 *p_param_values++ = CUSTOM_OPENSL_PRESET;
357 *p_param_values++ = eq.config.num_bands;
358 for (i=0; i<eq.config.num_bands; i++) {
359 *p_param_values++ = eq.per_band_cfg[i].band_idx;
360 *p_param_values++ = eq.per_band_cfg[i].filter_type;
361 *p_param_values++ = eq.per_band_cfg[i].freq_millihertz;
362 *p_param_values++ = eq.per_band_cfg[i].gain_millibels;
363 *p_param_values++ = eq.per_band_cfg[i].quality_factor;
364 }
365 param_values[2] += 1;
366 }
367
368 if (param_values[2] && ctl)
369 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
370
371 return 0;
372}
373
374void offload_reverb_set_device(struct reverb_params *reverb, uint32_t device)
375{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530376 ALOGVV("%s: device 0x%x", __func__, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800377 reverb->device = device;
378}
379
380void offload_reverb_set_enable_flag(struct reverb_params *reverb, bool enable)
381{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530382 ALOGVV("%s: enable=%d", __func__, (int)enable);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800383 reverb->enable_flag = enable;
384}
385
386int offload_reverb_get_enable_flag(struct reverb_params *reverb)
387{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530388 ALOGVV("%s: enabled=%d", __func__, reverb->enable_flag);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800389 return reverb->enable_flag;
390}
391
392void offload_reverb_set_mode(struct reverb_params *reverb, int mode)
393{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530394 ALOGVV("%s", __func__);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800395 reverb->mode = mode;
396}
397
398void offload_reverb_set_preset(struct reverb_params *reverb, int preset)
399{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530400 ALOGVV("%s: preset %d", __func__, preset);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800401 if (preset && (preset <= NUM_OSL_REVERB_PRESETS_SUPPORTED))
wjiang120b9ea2014-03-18 06:43:48 +0800402 reverb->preset = map_reverb_opensl_preset_2_offload_preset[preset-1][1];
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800403}
404
405void offload_reverb_set_wet_mix(struct reverb_params *reverb, int wet_mix)
406{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530407 ALOGVV("%s: wet_mix %d", __func__, wet_mix);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800408 reverb->wet_mix = wet_mix;
409}
410
411void offload_reverb_set_gain_adjust(struct reverb_params *reverb,
412 int gain_adjust)
413{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530414 ALOGVV("%s: gain %d", __func__, gain_adjust);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800415 reverb->gain_adjust = gain_adjust;
416}
417
418void offload_reverb_set_room_level(struct reverb_params *reverb, int room_level)
419{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530420 ALOGVV("%s: level %d", __func__, room_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800421 reverb->room_level = room_level;
422}
423
424void offload_reverb_set_room_hf_level(struct reverb_params *reverb,
425 int room_hf_level)
426{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530427 ALOGVV("%s: level %d", __func__, room_hf_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800428 reverb->room_hf_level = room_hf_level;
429}
430
431void offload_reverb_set_decay_time(struct reverb_params *reverb, int decay_time)
432{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530433 ALOGVV("%s: decay time %d", __func__, decay_time);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800434 reverb->decay_time = decay_time;
435}
436
437void offload_reverb_set_decay_hf_ratio(struct reverb_params *reverb,
438 int decay_hf_ratio)
439{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530440 ALOGVV("%s: decay_hf_ratio %d", __func__, decay_hf_ratio);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800441 reverb->decay_hf_ratio = decay_hf_ratio;
442}
443
444void offload_reverb_set_reflections_level(struct reverb_params *reverb,
445 int reflections_level)
446{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530447 ALOGVV("%s: ref level %d", __func__, reflections_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800448 reverb->reflections_level = reflections_level;
449}
450
451void offload_reverb_set_reflections_delay(struct reverb_params *reverb,
452 int reflections_delay)
453{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530454 ALOGVV("%s: ref delay", __func__, reflections_delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800455 reverb->reflections_delay = reflections_delay;
456}
457
458void offload_reverb_set_reverb_level(struct reverb_params *reverb,
459 int reverb_level)
460{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530461 ALOGD("%s: reverb level %d", __func__, reverb_level);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800462 reverb->level = reverb_level;
463}
464
465void offload_reverb_set_delay(struct reverb_params *reverb, int delay)
466{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530467 ALOGVV("%s: delay %d", __func__, delay);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800468 reverb->delay = delay;
469}
470
471void offload_reverb_set_diffusion(struct reverb_params *reverb, int diffusion)
472{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530473 ALOGVV("%s: diffusion %d", __func__, diffusion);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800474 reverb->diffusion = diffusion;
475}
476
477void offload_reverb_set_density(struct reverb_params *reverb, int density)
478{
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530479 ALOGVV("%s: density %d", __func__, density);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800480 reverb->density = density;
481}
482
483int offload_reverb_send_params(struct mixer_ctl *ctl,
484 struct reverb_params reverb,
485 unsigned param_send_flags)
486{
487 int param_values[128] = {0};
488 int *p_param_values = param_values;
489
Dhananjay Kumarb2c7ac12014-03-25 17:41:44 +0530490 ALOGV("%s: flags 0x%x", __func__, param_send_flags);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800491 *p_param_values++ = REVERB_MODULE;
492 *p_param_values++ = reverb.device;
493 *p_param_values++ = 0; /* num of commands*/
494
495 if (param_send_flags & OFFLOAD_SEND_REVERB_ENABLE_FLAG) {
496 *p_param_values++ = REVERB_ENABLE;
497 *p_param_values++ = CONFIG_SET;
498 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
499 *p_param_values++ = REVERB_ENABLE_PARAM_LEN;
500 *p_param_values++ = reverb.enable_flag;
501 param_values[2] += 1;
502 }
503 if (param_send_flags & OFFLOAD_SEND_REVERB_MODE) {
504 *p_param_values++ = REVERB_MODE;
505 *p_param_values++ = CONFIG_SET;
506 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
507 *p_param_values++ = REVERB_MODE_PARAM_LEN;
508 *p_param_values++ = reverb.mode;
509 param_values[2] += 1;
510 }
511 if (param_send_flags & OFFLOAD_SEND_REVERB_PRESET) {
512 *p_param_values++ = REVERB_PRESET;
513 *p_param_values++ = CONFIG_SET;
514 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
515 *p_param_values++ = REVERB_PRESET_PARAM_LEN;
516 *p_param_values++ = reverb.preset;
517 param_values[2] += 1;
518 }
519 if (param_send_flags & OFFLOAD_SEND_REVERB_WET_MIX) {
520 *p_param_values++ = REVERB_WET_MIX;
521 *p_param_values++ = CONFIG_SET;
522 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
523 *p_param_values++ = REVERB_WET_MIX_PARAM_LEN;
524 *p_param_values++ = reverb.wet_mix;
525 param_values[2] += 1;
526 }
527 if (param_send_flags & OFFLOAD_SEND_REVERB_GAIN_ADJUST) {
528 *p_param_values++ = REVERB_GAIN_ADJUST;
529 *p_param_values++ = CONFIG_SET;
530 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
531 *p_param_values++ = REVERB_GAIN_ADJUST_PARAM_LEN;
532 *p_param_values++ = reverb.gain_adjust;
533 param_values[2] += 1;
534 }
535 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_LEVEL) {
536 *p_param_values++ = REVERB_ROOM_LEVEL;
537 *p_param_values++ = CONFIG_SET;
538 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
539 *p_param_values++ = REVERB_ROOM_LEVEL_PARAM_LEN;
540 *p_param_values++ = reverb.room_level;
541 param_values[2] += 1;
542 }
543 if (param_send_flags & OFFLOAD_SEND_REVERB_ROOM_HF_LEVEL) {
544 *p_param_values++ = REVERB_ROOM_HF_LEVEL;
545 *p_param_values++ = CONFIG_SET;
546 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
547 *p_param_values++ = REVERB_ROOM_HF_LEVEL_PARAM_LEN;
548 *p_param_values++ = reverb.room_hf_level;
549 param_values[2] += 1;
550 }
551 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_TIME) {
552 *p_param_values++ = REVERB_DECAY_TIME;
553 *p_param_values++ = CONFIG_SET;
554 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
555 *p_param_values++ = REVERB_DECAY_TIME_PARAM_LEN;
556 *p_param_values++ = reverb.decay_time;
557 param_values[2] += 1;
558 }
559 if (param_send_flags & OFFLOAD_SEND_REVERB_DECAY_HF_RATIO) {
560 *p_param_values++ = REVERB_DECAY_HF_RATIO;
561 *p_param_values++ = CONFIG_SET;
562 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
563 *p_param_values++ = REVERB_DECAY_HF_RATIO_PARAM_LEN;
564 *p_param_values++ = reverb.decay_hf_ratio;
565 param_values[2] += 1;
566 }
567 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_LEVEL) {
568 *p_param_values++ = REVERB_REFLECTIONS_LEVEL;
569 *p_param_values++ = CONFIG_SET;
570 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
571 *p_param_values++ = REVERB_REFLECTIONS_LEVEL_PARAM_LEN;
572 *p_param_values++ = reverb.reflections_level;
573 param_values[2] += 1;
574 }
575 if (param_send_flags & OFFLOAD_SEND_REVERB_REFLECTIONS_DELAY) {
576 *p_param_values++ = REVERB_REFLECTIONS_DELAY;
577 *p_param_values++ = CONFIG_SET;
578 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
579 *p_param_values++ = REVERB_REFLECTIONS_DELAY_PARAM_LEN;
580 *p_param_values++ = reverb.reflections_delay;
581 param_values[2] += 1;
582 }
583 if (param_send_flags & OFFLOAD_SEND_REVERB_LEVEL) {
584 *p_param_values++ = REVERB_LEVEL;
585 *p_param_values++ = CONFIG_SET;
586 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
587 *p_param_values++ = REVERB_LEVEL_PARAM_LEN;
588 *p_param_values++ = reverb.level;
589 param_values[2] += 1;
590 }
591 if (param_send_flags & OFFLOAD_SEND_REVERB_DELAY) {
592 *p_param_values++ = REVERB_DELAY;
593 *p_param_values++ = CONFIG_SET;
594 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
595 *p_param_values++ = REVERB_DELAY_PARAM_LEN;
596 *p_param_values++ = reverb.delay;
597 param_values[2] += 1;
598 }
599 if (param_send_flags & OFFLOAD_SEND_REVERB_DIFFUSION) {
600 *p_param_values++ = REVERB_DIFFUSION;
601 *p_param_values++ = CONFIG_SET;
602 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
603 *p_param_values++ = REVERB_DIFFUSION_PARAM_LEN;
604 *p_param_values++ = reverb.diffusion;
605 param_values[2] += 1;
606 }
607 if (param_send_flags & OFFLOAD_SEND_REVERB_DENSITY) {
608 *p_param_values++ = REVERB_DENSITY;
609 *p_param_values++ = CONFIG_SET;
610 *p_param_values++ = 0; /* start offset if param size if greater than 128 */
611 *p_param_values++ = REVERB_DENSITY_PARAM_LEN;
612 *p_param_values++ = reverb.density;
613 param_values[2] += 1;
614 }
615
616 if (param_values[2] && ctl)
617 mixer_ctl_set_array(ctl, param_values, ARRAY_SIZE(param_values));
618
619 return 0;
620}