blob: e2c6d9aa43aaaaa195f4391af3bf403c1d1894c0 [file] [log] [blame]
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08001/*
wjiangee2ff962014-03-18 06:49:46 +08002 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -08003 * Not a Contribution.
4 *
5 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
20#define LOG_TAG "offload_effect_bass_boost"
21#define LOG_NDEBUG 0
22
23#include <cutils/list.h>
24#include <cutils/log.h>
25#include <tinyalsa/asoundlib.h>
Subhash Chandra Bose Naripeddy090a2aa2014-01-30 14:03:12 -080026#include <sound/audio_effects.h>
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080027#include <audio_effects/effect_bassboost.h>
28
29#include "effect_api.h"
30#include "bass_boost.h"
31
32/* Offload bassboost UUID: 2c4a8c24-1581-487f-94f6-0002a5d5c51b */
33const effect_descriptor_t bassboost_descriptor = {
34 {0x0634f220, 0xddd4, 0x11db, 0xa0fc, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b }},
35 {0x2c4a8c24, 0x1581, 0x487f, 0x94f6, { 0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}}, // uuid
36 EFFECT_CONTROL_API_VERSION,
37 (EFFECT_FLAG_TYPE_INSERT | EFFECT_FLAG_DEVICE_IND | EFFECT_FLAG_HW_ACC_TUNNEL),
38 0, /* TODO */
39 1,
40 "MSM offload bassboost",
41 "The Android Open Source Project",
42};
43
44/*
45 * Bassboost operations
46 */
47
48int bassboost_get_strength(bassboost_context_t *context)
49{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053050 ALOGV("%s: ctxt %p, strength: %d", __func__,
51 context, context->strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080052 return context->strength;
53}
54
55int bassboost_set_strength(bassboost_context_t *context, uint32_t strength)
56{
Dhananjay Kumar574f3922014-03-25 17:41:44 +053057 ALOGV("%s: ctxt %p, strength: %d", __func__, context, strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080058 context->strength = strength;
59
60 offload_bassboost_set_strength(&(context->offload_bass), strength);
61 if (context->ctl)
62 offload_bassboost_send_params(context->ctl, context->offload_bass,
63 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG |
64 OFFLOAD_SEND_BASSBOOST_STRENGTH);
65 return 0;
66}
67
68int bassboost_get_parameter(effect_context_t *context, effect_param_t *p,
69 uint32_t *size)
70{
71 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
72 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
73 int32_t *param_tmp = (int32_t *)p->data;
74 int32_t param = *param_tmp++;
75 void *value = p->data + voffset;
76 int i;
77
Dhananjay Kumar574f3922014-03-25 17:41:44 +053078 ALOGV("%s: ctxt %p, param %d", __func__, bass_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -080079
80 p->status = 0;
81
82 switch (param) {
83 case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
84 if (p->vsize < sizeof(uint32_t))
85 p->status = -EINVAL;
86 p->vsize = sizeof(uint32_t);
87 break;
88 case BASSBOOST_PARAM_STRENGTH:
89 if (p->vsize < sizeof(int16_t))
90 p->status = -EINVAL;
91 p->vsize = sizeof(int16_t);
92 break;
93 default:
94 p->status = -EINVAL;
95 }
96
97 *size = sizeof(effect_param_t) + voffset + p->vsize;
98
99 if (p->status != 0)
100 return 0;
101
102 switch (param) {
103 case BASSBOOST_PARAM_STRENGTH_SUPPORTED:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800104 *(uint32_t *)value = 1;
105 break;
106
107 case BASSBOOST_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800108 *(int16_t *)value = bassboost_get_strength(bass_ctxt);
109 break;
110
111 default:
112 p->status = -EINVAL;
113 break;
114 }
115
116 return 0;
117}
118
119int bassboost_set_parameter(effect_context_t *context, effect_param_t *p,
120 uint32_t size)
121{
122 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
123 int voffset = ((p->psize - 1) / sizeof(int32_t) + 1) * sizeof(int32_t);
124 void *value = p->data + voffset;
125 int32_t *param_tmp = (int32_t *)p->data;
126 int32_t param = *param_tmp++;
127 uint32_t strength;
128
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530129 ALOGV("%s: ctxt %p, param %d", __func__, bass_ctxt, param);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800130
131 p->status = 0;
132
133 switch (param) {
134 case BASSBOOST_PARAM_STRENGTH:
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800135 strength = (uint32_t)(*(int16_t *)value);
136 bassboost_set_strength(bass_ctxt, strength);
137 break;
138 default:
139 p->status = -EINVAL;
140 break;
141 }
142
143 return 0;
144}
145
146int bassboost_set_device(effect_context_t *context, uint32_t device)
147{
148 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
149
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530150 ALOGV("%s: ctxt %p, device 0x%x", __func__, bass_ctxt, device);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800151 bass_ctxt->device = device;
152 if((device == AUDIO_DEVICE_OUT_SPEAKER) ||
153 (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) ||
wjiangee2ff962014-03-18 06:49:46 +0800154 (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER) ||
Mingming Yin67e34512014-04-03 17:47:22 -0700155#ifdef AFE_PROXY_ENABLED
wjiangee2ff962014-03-18 06:49:46 +0800156 (device == AUDIO_DEVICE_OUT_PROXY) ||
Mingming Yin67e34512014-04-03 17:47:22 -0700157#endif
wjiangee2ff962014-03-18 06:49:46 +0800158 (device == AUDIO_DEVICE_OUT_AUX_DIGITAL) ||
Dhananjay Kumarfd00bef2014-05-06 16:48:17 +0530159 (device == AUDIO_DEVICE_OUT_USB_ACCESSORY) ||
wjiangee2ff962014-03-18 06:49:46 +0800160 (device == AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET)) {
wjiang50b81f42014-08-06 08:03:14 +0800161 if (!bass_ctxt->temp_disabled) {
162 if (effect_is_active(&bass_ctxt->common)) {
163 offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false);
164 if (bass_ctxt->ctl)
165 offload_bassboost_send_params(bass_ctxt->ctl,
166 bass_ctxt->offload_bass,
167 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG);
168 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800169 bass_ctxt->temp_disabled = true;
170 }
wjiang50b81f42014-08-06 08:03:14 +0800171 ALOGI("%s: ctxt %p, disabled based on device", __func__, bass_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800172 } else {
wjiang50b81f42014-08-06 08:03:14 +0800173 if (bass_ctxt->temp_disabled) {
174 if (effect_is_active(&bass_ctxt->common)) {
175 offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true);
176 if (bass_ctxt->ctl)
177 offload_bassboost_send_params(bass_ctxt->ctl,
178 bass_ctxt->offload_bass,
179 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG);
180 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800181 bass_ctxt->temp_disabled = false;
182 }
183 }
184 offload_bassboost_set_device(&(bass_ctxt->offload_bass), device);
185 return 0;
186}
187
188int bassboost_reset(effect_context_t *context)
189{
190 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
191
192 return 0;
193}
194
195int bassboost_init(effect_context_t *context)
196{
197 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
198
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530199 ALOGV("%s: ctxt %p", __func__, bass_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800200 context->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
201 context->config.inputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
202 context->config.inputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
203 context->config.inputCfg.samplingRate = 44100;
204 context->config.inputCfg.bufferProvider.getBuffer = NULL;
205 context->config.inputCfg.bufferProvider.releaseBuffer = NULL;
206 context->config.inputCfg.bufferProvider.cookie = NULL;
207 context->config.inputCfg.mask = EFFECT_CONFIG_ALL;
208 context->config.outputCfg.accessMode = EFFECT_BUFFER_ACCESS_ACCUMULATE;
209 context->config.outputCfg.channels = AUDIO_CHANNEL_OUT_STEREO;
210 context->config.outputCfg.format = AUDIO_FORMAT_PCM_16_BIT;
211 context->config.outputCfg.samplingRate = 44100;
212 context->config.outputCfg.bufferProvider.getBuffer = NULL;
213 context->config.outputCfg.bufferProvider.releaseBuffer = NULL;
214 context->config.outputCfg.bufferProvider.cookie = NULL;
215 context->config.outputCfg.mask = EFFECT_CONFIG_ALL;
216
217 set_config(context, &context->config);
218
219 bass_ctxt->temp_disabled = false;
220 memset(&(bass_ctxt->offload_bass), 0, sizeof(struct bass_boost_params));
221
222 return 0;
223}
224
225int bassboost_enable(effect_context_t *context)
226{
227 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
228
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530229 ALOGV("%s: ctxt %p, strength %d", __func__, bass_ctxt, bass_ctxt->strength);
wjiang95d74c22014-03-28 12:29:58 +0800230
231 if (!offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)) &&
232 !(bass_ctxt->temp_disabled)) {
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800233 offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), true);
wjiangd45948e2014-02-24 22:19:43 +0800234 if (bass_ctxt->ctl && bass_ctxt->strength)
235 offload_bassboost_send_params(bass_ctxt->ctl,
236 bass_ctxt->offload_bass,
237 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG |
238 OFFLOAD_SEND_BASSBOOST_STRENGTH);
239 }
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800240 return 0;
241}
242
243int bassboost_disable(effect_context_t *context)
244{
245 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
246
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530247 ALOGV("%s: ctxt %p", __func__, bass_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800248 if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass))) {
249 offload_bassboost_set_enable_flag(&(bass_ctxt->offload_bass), false);
250 if (bass_ctxt->ctl)
251 offload_bassboost_send_params(bass_ctxt->ctl,
252 bass_ctxt->offload_bass,
253 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG);
254 }
255 return 0;
256}
257
258int bassboost_start(effect_context_t *context, output_context_t *output)
259{
260 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
261
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530262 ALOGV("%s: ctxt %p, ctl %p, strength %d", __func__, bass_ctxt,
263 output->ctl, bass_ctxt->strength);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800264 bass_ctxt->ctl = output->ctl;
Amit Shekhard02f2cd2014-01-16 16:51:43 -0800265 if (offload_bassboost_get_enable_flag(&(bass_ctxt->offload_bass)))
266 if (bass_ctxt->ctl)
267 offload_bassboost_send_params(bass_ctxt->ctl, bass_ctxt->offload_bass,
268 OFFLOAD_SEND_BASSBOOST_ENABLE_FLAG |
269 OFFLOAD_SEND_BASSBOOST_STRENGTH);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800270 return 0;
271}
272
273int bassboost_stop(effect_context_t *context, output_context_t *output)
274{
275 bassboost_context_t *bass_ctxt = (bassboost_context_t *)context;
276
Dhananjay Kumar574f3922014-03-25 17:41:44 +0530277 ALOGV("%s: ctxt %p", __func__, bass_ctxt);
Subhash Chandra Bose Naripeddy3eedc002013-11-12 20:45:15 -0800278 bass_ctxt->ctl = NULL;
279 return 0;
280}