blob: 32945007e8d44dad1f2212045dffad51815ec5f0 [file] [log] [blame]
Dima Zavine8e4be52011-05-12 10:25:33 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18#ifndef ANDROID_AUDIO_CORE_H
19#define ANDROID_AUDIO_CORE_H
20
21#include <stdbool.h>
22#include <stdint.h>
23#include <sys/cdefs.h>
24#include <sys/types.h>
25
26#include <cutils/bitops.h>
27
28__BEGIN_DECLS
29
30/* The enums were moved here mostly from
31 * frameworks/base/include/media/AudioSystem.h
32 */
33
34typedef int audio_io_handle_t;
35
36/* Audio stream types */
37typedef enum {
38 AUDIO_STREAM_DEFAULT = -1,
39 AUDIO_STREAM_VOICE_CALL = 0,
40 AUDIO_STREAM_SYSTEM = 1,
41 AUDIO_STREAM_RING = 2,
42 AUDIO_STREAM_MUSIC = 3,
43 AUDIO_STREAM_ALARM = 4,
44 AUDIO_STREAM_NOTIFICATION = 5,
45 AUDIO_STREAM_BLUETOOTH_SCO = 6,
46 AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user and must be routed to speaker */
47 AUDIO_STREAM_DTMF = 8,
48 AUDIO_STREAM_TTS = 9,
49
50 AUDIO_STREAM_CNT,
51 AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1,
52} audio_stream_type_t;
53
54/* Do not change these values without updating their counterparts
55 * in media/java/android/media/MediaRecorder.java!
56 */
57typedef enum {
58 AUDIO_SOURCE_DEFAULT = 0,
59 AUDIO_SOURCE_MIC = 1,
60 AUDIO_SOURCE_VOICE_UPLINK = 2,
61 AUDIO_SOURCE_VOICE_DOWNLINK = 3,
62 AUDIO_SOURCE_VOICE_CALL = 4,
63 AUDIO_SOURCE_CAMCORDER = 5,
64 AUDIO_SOURCE_VOICE_RECOGNITION = 6,
65 AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
66
67 AUDIO_SOURCE_CNT,
68 AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1,
69} audio_source_t;
70
71/* special audio session values
72 * (XXX: should this be living in the audio effects land?)
73 */
74typedef enum {
75 /* session for effects attached to a particular output stream
76 * (value must be less than 0)
77 */
78 AUDIO_SESSION_OUTPUT_STAGE = -1,
79
80 /* session for effects applied to output mix. These effects can
81 * be moved by audio policy manager to another output stream
82 * (value must be 0)
83 */
84 AUDIO_SESSION_OUTPUT_MIX = 0,
85} audio_session_t;
86
87/* Audio sub formats (see enum audio_format). */
88
89/* PCM sub formats */
90typedef enum {
Eric Laurent9714b272011-05-26 13:52:47 -070091 AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */
92 AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */
93 AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */
94 AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */
Dima Zavine8e4be52011-05-12 10:25:33 -070095} audio_format_pcm_sub_fmt_t;
96
97/* MP3 sub format field definition : can use 11 LSBs in the same way as MP3
98 * frame header to specify bit rate, stereo mode, version...
99 */
100typedef enum {
101 AUDIO_FORMAT_MP3_SUB_NONE = 0x0,
102} audio_format_mp3_sub_fmt_t;
103
104/* AMR NB/WB sub format field definition: specify frame block interleaving,
105 * bandwidth efficient or octet aligned, encoding mode for recording...
106 */
107typedef enum {
108 AUDIO_FORMAT_AMR_SUB_NONE = 0x0,
109} audio_format_amr_sub_fmt_t;
110
111/* AAC sub format field definition: specify profile or bitrate for recording... */
112typedef enum {
113 AUDIO_FORMAT_AAC_SUB_NONE = 0x0,
114} audio_format_aac_sub_fmt_t;
115
116/* VORBIS sub format field definition: specify quality for recording... */
117typedef enum {
118 AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0,
119} audio_format_vorbis_sub_fmt_t;
120
121/* Audio format consists in a main format field (upper 8 bits) and a sub format
122 * field (lower 24 bits).
123 *
124 * The main format indicates the main codec type. The sub format field
125 * indicates options and parameters for each format. The sub format is mainly
126 * used for record to indicate for instance the requested bitrate or profile.
127 * It can also be used for certain formats to give informations not present in
128 * the encoded audio stream (e.g. octet alignement for AMR).
129 */
130typedef enum {
131 AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL,
132 AUDIO_FORMAT_DEFAULT = 0,
133 AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */
134 AUDIO_FORMAT_MP3 = 0x01000000UL,
135 AUDIO_FORMAT_AMR_NB = 0x02000000UL,
136 AUDIO_FORMAT_AMR_WB = 0x03000000UL,
137 AUDIO_FORMAT_AAC = 0x04000000UL,
138 AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL,
139 AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL,
140 AUDIO_FORMAT_VORBIS = 0x07000000UL,
141 AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL,
142 AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL,
143
144 /* Aliases */
145 AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM |
146 AUDIO_FORMAT_PCM_SUB_16_BIT),
147 AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM |
148 AUDIO_FORMAT_PCM_SUB_8_BIT),
Eric Laurent9714b272011-05-26 13:52:47 -0700149 AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM |
150 AUDIO_FORMAT_PCM_SUB_32_BIT),
151 AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM |
152 AUDIO_FORMAT_PCM_SUB_8_24_BIT),
Dima Zavine8e4be52011-05-12 10:25:33 -0700153} audio_format_t;
154
155/* Channel mask definitions must be kept in sync with JAVA values in
156 * frameworks/base/media/java/android/media/AudioFormat.java */
157typedef enum {
158 /* output channels */
159 AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x4,
160 AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x8,
161 AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x10,
162 AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x20,
163 AUDIO_CHANNEL_OUT_BACK_LEFT = 0x40,
164 AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x80,
165 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x100,
166 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x200,
167 AUDIO_CHANNEL_OUT_BACK_CENTER = 0x400,
168
169 AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT,
170 AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
171 AUDIO_CHANNEL_OUT_FRONT_RIGHT),
172 AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
173 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
174 AUDIO_CHANNEL_OUT_BACK_LEFT |
175 AUDIO_CHANNEL_OUT_BACK_RIGHT),
176 AUDIO_CHANNEL_OUT_SURROUND = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
177 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
178 AUDIO_CHANNEL_OUT_FRONT_CENTER |
179 AUDIO_CHANNEL_OUT_BACK_CENTER),
180 AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
181 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
182 AUDIO_CHANNEL_OUT_FRONT_CENTER |
183 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
184 AUDIO_CHANNEL_OUT_BACK_LEFT |
185 AUDIO_CHANNEL_OUT_BACK_RIGHT),
186 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
187 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
188 AUDIO_CHANNEL_OUT_FRONT_CENTER |
189 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
190 AUDIO_CHANNEL_OUT_BACK_LEFT |
191 AUDIO_CHANNEL_OUT_BACK_RIGHT |
192 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
193 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER),
194 AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT |
195 AUDIO_CHANNEL_OUT_FRONT_RIGHT |
196 AUDIO_CHANNEL_OUT_FRONT_CENTER |
197 AUDIO_CHANNEL_OUT_LOW_FREQUENCY |
198 AUDIO_CHANNEL_OUT_BACK_LEFT |
199 AUDIO_CHANNEL_OUT_BACK_RIGHT |
200 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER |
201 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER |
202 AUDIO_CHANNEL_OUT_BACK_CENTER),
203
204 /* input channels */
205 AUDIO_CHANNEL_IN_LEFT = 0x4,
206 AUDIO_CHANNEL_IN_RIGHT = 0x8,
207 AUDIO_CHANNEL_IN_FRONT = 0x10,
208 AUDIO_CHANNEL_IN_BACK = 0x20,
209 AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40,
210 AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80,
211 AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100,
212 AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200,
213 AUDIO_CHANNEL_IN_PRESSURE = 0x400,
214 AUDIO_CHANNEL_IN_X_AXIS = 0x800,
215 AUDIO_CHANNEL_IN_Y_AXIS = 0x1000,
216 AUDIO_CHANNEL_IN_Z_AXIS = 0x2000,
217 AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000,
218 AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000,
219
220 AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT,
221 AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT),
222 AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT |
223 AUDIO_CHANNEL_IN_RIGHT |
224 AUDIO_CHANNEL_IN_FRONT |
225 AUDIO_CHANNEL_IN_BACK|
226 AUDIO_CHANNEL_IN_LEFT_PROCESSED |
227 AUDIO_CHANNEL_IN_RIGHT_PROCESSED |
228 AUDIO_CHANNEL_IN_FRONT_PROCESSED |
229 AUDIO_CHANNEL_IN_BACK_PROCESSED|
230 AUDIO_CHANNEL_IN_PRESSURE |
231 AUDIO_CHANNEL_IN_X_AXIS |
232 AUDIO_CHANNEL_IN_Y_AXIS |
233 AUDIO_CHANNEL_IN_Z_AXIS |
234 AUDIO_CHANNEL_IN_VOICE_UPLINK |
235 AUDIO_CHANNEL_IN_VOICE_DNLINK),
236} audio_channels_t;
237
238typedef enum {
239 AUDIO_MODE_INVALID = -2,
240 AUDIO_MODE_CURRENT = -1,
241 AUDIO_MODE_NORMAL = 0,
242 AUDIO_MODE_RINGTONE = 1,
243 AUDIO_MODE_IN_CALL = 2,
244 AUDIO_MODE_IN_COMMUNICATION = 3,
245
246 AUDIO_MODE_CNT,
247 AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1,
248} audio_mode_t;
249
250typedef enum {
251 AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001,
252 AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0,
253 AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002,
254 AUDIO_IN_ACOUSTICS_NS_DISABLE = 0,
255 AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004,
256 AUDIO_IN_ACOUSTICS_TX_DISABLE = 0,
257} audio_in_acoustics_t;
258
259typedef enum {
260 /* output devices */
261 AUDIO_DEVICE_OUT_EARPIECE = 0x1,
262 AUDIO_DEVICE_OUT_SPEAKER = 0x2,
263 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4,
264 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8,
265 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10,
266 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20,
267 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40,
268 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80,
269 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
270 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
271 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400,
272 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800,
273 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000,
274 AUDIO_DEVICE_OUT_DEFAULT = 0x8000,
275 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE |
276 AUDIO_DEVICE_OUT_SPEAKER |
277 AUDIO_DEVICE_OUT_WIRED_HEADSET |
278 AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
279 AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
280 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
281 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT |
282 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
283 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
284 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER |
285 AUDIO_DEVICE_OUT_AUX_DIGITAL |
286 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
287 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET |
288 AUDIO_DEVICE_OUT_DEFAULT),
289 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP |
290 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
291 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER),
292 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO |
293 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
294 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT),
295
296 /* input devices */
297 AUDIO_DEVICE_IN_COMMUNICATION = 0x10000,
298 AUDIO_DEVICE_IN_AMBIENT = 0x20000,
299 AUDIO_DEVICE_IN_BUILTIN_MIC = 0x40000,
300 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = 0x80000,
301 AUDIO_DEVICE_IN_WIRED_HEADSET = 0x100000,
302 AUDIO_DEVICE_IN_AUX_DIGITAL = 0x200000,
303 AUDIO_DEVICE_IN_VOICE_CALL = 0x400000,
304 AUDIO_DEVICE_IN_BACK_MIC = 0x800000,
305 AUDIO_DEVICE_IN_DEFAULT = 0x80000000,
306
307 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION |
308 AUDIO_DEVICE_IN_AMBIENT |
309 AUDIO_DEVICE_IN_BUILTIN_MIC |
310 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET |
311 AUDIO_DEVICE_IN_WIRED_HEADSET |
312 AUDIO_DEVICE_IN_AUX_DIGITAL |
313 AUDIO_DEVICE_IN_VOICE_CALL |
314 AUDIO_DEVICE_IN_BACK_MIC |
315 AUDIO_DEVICE_IN_DEFAULT),
316 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET,
317} audio_devices_t;
318
319static inline bool audio_is_output_device(audio_devices_t device)
320{
321 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0))
322 return true;
323 else
324 return false;
325}
326
327static inline bool audio_is_input_device(audio_devices_t device)
328{
329 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0))
330 return true;
331 else
332 return false;
333}
334
335static inline bool audio_is_a2dp_device(audio_devices_t device)
336{
337 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP))
338 return true;
339 else
340 return false;
341}
342
343static inline bool audio_is_bluetooth_sco_device(audio_devices_t device)
344{
345 if ((popcount(device) == 1) && (device & (AUDIO_DEVICE_OUT_ALL_SCO |
346 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET)))
347 return true;
348 else
349 return false;
350}
351
352static inline bool audio_is_input_channel(uint32_t channel)
353{
354 if ((channel & ~AUDIO_CHANNEL_IN_ALL) == 0)
355 return true;
356 else
357 return false;
358}
359
360static inline bool audio_is_output_channel(uint32_t channel)
361{
362 if ((channel & ~AUDIO_CHANNEL_OUT_ALL) == 0)
363 return true;
364 else
365 return false;
366}
367
368static inline bool audio_is_valid_format(uint32_t format)
369{
370 switch (format & AUDIO_FORMAT_MAIN_MASK) {
371 case AUDIO_FORMAT_PCM:
372 case AUDIO_FORMAT_MP3:
373 case AUDIO_FORMAT_AMR_NB:
374 case AUDIO_FORMAT_AMR_WB:
375 case AUDIO_FORMAT_AAC:
376 case AUDIO_FORMAT_HE_AAC_V1:
377 case AUDIO_FORMAT_HE_AAC_V2:
378 case AUDIO_FORMAT_VORBIS:
379 return true;
380 default:
381 return false;
382 }
383}
384
385static inline bool audio_is_linear_pcm(uint32_t format)
386{
387 switch (format) {
388 case AUDIO_FORMAT_PCM_16_BIT:
389 case AUDIO_FORMAT_PCM_8_BIT:
390 return true;
391 default:
392 return false;
393 }
394}
395
396
397__END_DECLS
398
399#endif // ANDROID_AUDIO_CORE_H