1 /* 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 34 typedef int audio_io_handle_t; 35 36 /* Audio stream types */ 37 typedef 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 */ 57 typedef 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 AUDIO_SOURCE_REMOTE_SUBMIX = 8, /* Source for the mix to be presented remotely. */ 67 /* An example of remote presentation is Wifi Display */ 68 /* where a dongle attached to a TV can be used to */ 69 /* play the mix captured by this audio source. */ 70 AUDIO_SOURCE_CNT, 71 AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1, 72 } audio_source_t; 73 74 /* special audio session values 75 * (XXX: should this be living in the audio effects land?) 76 */ 77 typedef enum { 78 /* session for effects attached to a particular output stream 79 * (value must be less than 0) 80 */ 81 AUDIO_SESSION_OUTPUT_STAGE = -1, 82 83 /* session for effects applied to output mix. These effects can 84 * be moved by audio policy manager to another output stream 85 * (value must be 0) 86 */ 87 AUDIO_SESSION_OUTPUT_MIX = 0, 88 } audio_session_t; 89 90 /* Audio sub formats (see enum audio_format). */ 91 92 /* PCM sub formats */ 93 typedef enum { 94 AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */ 95 AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */ 96 AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */ 97 AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */ 98 } audio_format_pcm_sub_fmt_t; 99 100 /* MP3 sub format field definition : can use 11 LSBs in the same way as MP3 101 * frame header to specify bit rate, stereo mode, version... 102 */ 103 typedef enum { 104 AUDIO_FORMAT_MP3_SUB_NONE = 0x0, 105 } audio_format_mp3_sub_fmt_t; 106 107 /* AMR NB/WB sub format field definition: specify frame block interleaving, 108 * bandwidth efficient or octet aligned, encoding mode for recording... 109 */ 110 typedef enum { 111 AUDIO_FORMAT_AMR_SUB_NONE = 0x0, 112 } audio_format_amr_sub_fmt_t; 113 114 /* AAC sub format field definition: specify profile or bitrate for recording... */ 115 typedef enum { 116 AUDIO_FORMAT_AAC_SUB_NONE = 0x0, 117 } audio_format_aac_sub_fmt_t; 118 119 /* VORBIS sub format field definition: specify quality for recording... */ 120 typedef enum { 121 AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0, 122 } audio_format_vorbis_sub_fmt_t; 123 124 /* Audio format consists in a main format field (upper 8 bits) and a sub format 125 * field (lower 24 bits). 126 * 127 * The main format indicates the main codec type. The sub format field 128 * indicates options and parameters for each format. The sub format is mainly 129 * used for record to indicate for instance the requested bitrate or profile. 130 * It can also be used for certain formats to give informations not present in 131 * the encoded audio stream (e.g. octet alignement for AMR). 132 */ 133 typedef enum { 134 AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL, 135 AUDIO_FORMAT_DEFAULT = 0, 136 AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */ 137 AUDIO_FORMAT_MP3 = 0x01000000UL, 138 AUDIO_FORMAT_AMR_NB = 0x02000000UL, 139 AUDIO_FORMAT_AMR_WB = 0x03000000UL, 140 AUDIO_FORMAT_AAC = 0x04000000UL, 141 AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, 142 AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, 143 AUDIO_FORMAT_VORBIS = 0x07000000UL, 144 AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL, 145 AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL, 146 147 /* Aliases */ 148 AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM | 149 AUDIO_FORMAT_PCM_SUB_16_BIT), 150 AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM | 151 AUDIO_FORMAT_PCM_SUB_8_BIT), 152 AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM | 153 AUDIO_FORMAT_PCM_SUB_32_BIT), 154 AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM | 155 AUDIO_FORMAT_PCM_SUB_8_24_BIT), 156 } audio_format_t; 157 158 enum { 159 /* output channels */ 160 AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1, 161 AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2, 162 AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4, 163 AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8, 164 AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10, 165 AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20, 166 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40, 167 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80, 168 AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100, 169 AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200, 170 AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400, 171 AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800, 172 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000, 173 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000, 174 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000, 175 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000, 176 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000, 177 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000, 178 179 AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT, 180 AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 181 AUDIO_CHANNEL_OUT_FRONT_RIGHT), 182 AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 183 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 184 AUDIO_CHANNEL_OUT_BACK_LEFT | 185 AUDIO_CHANNEL_OUT_BACK_RIGHT), 186 AUDIO_CHANNEL_OUT_SURROUND = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 187 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 188 AUDIO_CHANNEL_OUT_FRONT_CENTER | 189 AUDIO_CHANNEL_OUT_BACK_CENTER), 190 AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 191 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 192 AUDIO_CHANNEL_OUT_FRONT_CENTER | 193 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 194 AUDIO_CHANNEL_OUT_BACK_LEFT | 195 AUDIO_CHANNEL_OUT_BACK_RIGHT), 196 // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1 197 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 198 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 199 AUDIO_CHANNEL_OUT_FRONT_CENTER | 200 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 201 AUDIO_CHANNEL_OUT_BACK_LEFT | 202 AUDIO_CHANNEL_OUT_BACK_RIGHT | 203 AUDIO_CHANNEL_OUT_SIDE_LEFT | 204 AUDIO_CHANNEL_OUT_SIDE_RIGHT), 205 AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 206 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 207 AUDIO_CHANNEL_OUT_FRONT_CENTER | 208 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 209 AUDIO_CHANNEL_OUT_BACK_LEFT | 210 AUDIO_CHANNEL_OUT_BACK_RIGHT | 211 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER | 212 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | 213 AUDIO_CHANNEL_OUT_BACK_CENTER| 214 AUDIO_CHANNEL_OUT_SIDE_LEFT| 215 AUDIO_CHANNEL_OUT_SIDE_RIGHT| 216 AUDIO_CHANNEL_OUT_TOP_CENTER| 217 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT| 218 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER| 219 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT| 220 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT| 221 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER| 222 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT), 223 224 /* input channels */ 225 AUDIO_CHANNEL_IN_LEFT = 0x4, 226 AUDIO_CHANNEL_IN_RIGHT = 0x8, 227 AUDIO_CHANNEL_IN_FRONT = 0x10, 228 AUDIO_CHANNEL_IN_BACK = 0x20, 229 AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40, 230 AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80, 231 AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100, 232 AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200, 233 AUDIO_CHANNEL_IN_PRESSURE = 0x400, 234 AUDIO_CHANNEL_IN_X_AXIS = 0x800, 235 AUDIO_CHANNEL_IN_Y_AXIS = 0x1000, 236 AUDIO_CHANNEL_IN_Z_AXIS = 0x2000, 237 AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000, 238 AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000, 239 240 AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT, 241 AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT), 242 AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK), 243 AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT | 244 AUDIO_CHANNEL_IN_RIGHT | 245 AUDIO_CHANNEL_IN_FRONT | 246 AUDIO_CHANNEL_IN_BACK| 247 AUDIO_CHANNEL_IN_LEFT_PROCESSED | 248 AUDIO_CHANNEL_IN_RIGHT_PROCESSED | 249 AUDIO_CHANNEL_IN_FRONT_PROCESSED | 250 AUDIO_CHANNEL_IN_BACK_PROCESSED| 251 AUDIO_CHANNEL_IN_PRESSURE | 252 AUDIO_CHANNEL_IN_X_AXIS | 253 AUDIO_CHANNEL_IN_Y_AXIS | 254 AUDIO_CHANNEL_IN_Z_AXIS | 255 AUDIO_CHANNEL_IN_VOICE_UPLINK | 256 AUDIO_CHANNEL_IN_VOICE_DNLINK), 257 }; 258 259 typedef uint32_t audio_channel_mask_t; 260 261 typedef enum { 262 AUDIO_MODE_INVALID = -2, 263 AUDIO_MODE_CURRENT = -1, 264 AUDIO_MODE_NORMAL = 0, 265 AUDIO_MODE_RINGTONE = 1, 266 AUDIO_MODE_IN_CALL = 2, 267 AUDIO_MODE_IN_COMMUNICATION = 3, 268 269 AUDIO_MODE_CNT, 270 AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1, 271 } audio_mode_t; 272 273 typedef enum { 274 AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001, 275 AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0, 276 AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002, 277 AUDIO_IN_ACOUSTICS_NS_DISABLE = 0, 278 AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004, 279 AUDIO_IN_ACOUSTICS_TX_DISABLE = 0, 280 } audio_in_acoustics_t; 281 282 enum { 283 AUDIO_DEVICE_NONE = 0x0, 284 /* reserved bits */ 285 AUDIO_DEVICE_BIT_IN = 0x80000000, 286 AUDIO_DEVICE_BIT_DEFAULT = 0x40000000, 287 /* output devices */ 288 AUDIO_DEVICE_OUT_EARPIECE = 0x1, 289 AUDIO_DEVICE_OUT_SPEAKER = 0x2, 290 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4, 291 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8, 292 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10, 293 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20, 294 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40, 295 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80, 296 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100, 297 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200, 298 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400, 299 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800, 300 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000, 301 AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000, 302 AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000, 303 AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000, 304 AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT, 305 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | 306 AUDIO_DEVICE_OUT_SPEAKER | 307 AUDIO_DEVICE_OUT_WIRED_HEADSET | 308 AUDIO_DEVICE_OUT_WIRED_HEADPHONE | 309 AUDIO_DEVICE_OUT_BLUETOOTH_SCO | 310 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | 311 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT | 312 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | 313 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | 314 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | 315 AUDIO_DEVICE_OUT_AUX_DIGITAL | 316 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | 317 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | 318 AUDIO_DEVICE_OUT_USB_ACCESSORY | 319 AUDIO_DEVICE_OUT_USB_DEVICE | 320 AUDIO_DEVICE_OUT_REMOTE_SUBMIX | 321 AUDIO_DEVICE_OUT_DEFAULT), 322 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | 323 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | 324 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER), 325 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO | 326 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | 327 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT), 328 AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY | 329 AUDIO_DEVICE_OUT_USB_DEVICE), 330 331 /* input devices */ 332 AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1, 333 AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2, 334 AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4, 335 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8, 336 AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10, 337 AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20, 338 AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40, 339 AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80, 340 AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100, 341 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200, 342 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400, 343 AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800, 344 AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000, 345 AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT, 346 347 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION | 348 AUDIO_DEVICE_IN_AMBIENT | 349 AUDIO_DEVICE_IN_BUILTIN_MIC | 350 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET | 351 AUDIO_DEVICE_IN_WIRED_HEADSET | 352 AUDIO_DEVICE_IN_AUX_DIGITAL | 353 AUDIO_DEVICE_IN_VOICE_CALL | 354 AUDIO_DEVICE_IN_BACK_MIC | 355 AUDIO_DEVICE_IN_REMOTE_SUBMIX | 356 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET | 357 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET | 358 AUDIO_DEVICE_IN_USB_ACCESSORY | 359 AUDIO_DEVICE_IN_USB_DEVICE | 360 AUDIO_DEVICE_IN_DEFAULT), 361 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, 362 }; 363 364 typedef uint32_t audio_devices_t; 365 366 /* the audio output flags serve two purposes: 367 * - when an AudioTrack is created they indicate a "wish" to be connected to an 368 * output stream with attributes corresponding to the specified flags 369 * - when present in an output profile descriptor listed for a particular audio 370 * hardware module, they indicate that an output stream can be opened that 371 * supports the attributes indicated by the flags. 372 * the audio policy manager will try to match the flags in the request 373 * (when getOuput() is called) to an available output stream. 374 */ 375 typedef enum { 376 AUDIO_OUTPUT_FLAG_NONE = 0x0, // no attributes 377 AUDIO_OUTPUT_FLAG_DIRECT = 0x1, // this output directly connects a track 378 // to one output stream: no software mixer 379 AUDIO_OUTPUT_FLAG_PRIMARY = 0x2, // this output is the primary output of 380 // the device. It is unique and must be 381 // present. It is opened by default and 382 // receives routing, audio mode and volume 383 // controls related to voice calls. 384 AUDIO_OUTPUT_FLAG_FAST = 0x4, // output supports "fast tracks", 385 // defined elsewhere 386 AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8 // use deep audio buffers 387 } audio_output_flags_t; 388 389 static inline bool audio_is_output_device(audio_devices_t device) 390 { 391 if (((device & AUDIO_DEVICE_BIT_IN) == 0) && 392 (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0)) 393 return true; 394 else 395 return false; 396 } 397 398 static inline bool audio_is_input_device(audio_devices_t device) 399 { 400 if ((device & AUDIO_DEVICE_BIT_IN) != 0) { 401 device &= ~AUDIO_DEVICE_BIT_IN; 402 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0)) 403 return true; 404 } 405 return false; 406 } 407 408 static inline bool audio_is_output_devices(audio_devices_t device) 409 { 410 return (device & AUDIO_DEVICE_BIT_IN) == 0; 411 } 412 413 414 static inline bool audio_is_a2dp_device(audio_devices_t device) 415 { 416 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP)) 417 return true; 418 else 419 return false; 420 } 421 422 static inline bool audio_is_bluetooth_sco_device(audio_devices_t device) 423 { 424 device &= ~AUDIO_DEVICE_BIT_IN; 425 if ((popcount(device) == 1) && (device & (AUDIO_DEVICE_OUT_ALL_SCO | 426 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET))) 427 return true; 428 else 429 return false; 430 } 431 432 static inline bool audio_is_usb_device(audio_devices_t device) 433 { 434 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB)) 435 return true; 436 else 437 return false; 438 } 439 440 static inline bool audio_is_remote_submix_device(audio_devices_t device) 441 { 442 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) 443 return true; 444 else 445 return false; 446 } 447 448 static inline bool audio_is_input_channel(uint32_t channel) 449 { 450 if ((channel & ~AUDIO_CHANNEL_IN_ALL) == 0) 451 return true; 452 else 453 return false; 454 } 455 456 static inline bool audio_is_output_channel(uint32_t channel) 457 { 458 if ((channel & ~AUDIO_CHANNEL_OUT_ALL) == 0) 459 return true; 460 else 461 return false; 462 } 463 464 /* Derive an output channel mask from a channel count. 465 * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel 466 * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad, 467 * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC 468 * for continuity with stereo. 469 * Returns the matching channel mask, or 0 if the number of channels exceeds that of the 470 * configurations for which a default channel mask is defined. 471 */ 472 static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count) 473 { 474 switch(channel_count) { 475 case 1: 476 return AUDIO_CHANNEL_OUT_MONO; 477 case 2: 478 return AUDIO_CHANNEL_OUT_STEREO; 479 case 3: 480 return (AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER); 481 case 4: // 4.0 482 return AUDIO_CHANNEL_OUT_QUAD; 483 case 5: // 5.0 484 return (AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER); 485 case 6: // 5.1 486 return AUDIO_CHANNEL_OUT_5POINT1; 487 case 7: // 6.1 488 return (AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER); 489 case 8: 490 return AUDIO_CHANNEL_OUT_7POINT1; 491 default: 492 return 0; 493 } 494 } 495 496 /* Similar to above, but for input. Currently handles only mono and stereo. */ 497 static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count) 498 { 499 switch (channel_count) { 500 case 1: 501 return AUDIO_CHANNEL_IN_MONO; 502 case 2: 503 return AUDIO_CHANNEL_IN_STEREO; 504 default: 505 return 0; 506 } 507 } 508 509 static inline bool audio_is_valid_format(audio_format_t format) 510 { 511 switch (format & AUDIO_FORMAT_MAIN_MASK) { 512 case AUDIO_FORMAT_PCM: 513 if (format != AUDIO_FORMAT_PCM_16_BIT && 514 format != AUDIO_FORMAT_PCM_8_BIT) { 515 return false; 516 } 517 case AUDIO_FORMAT_MP3: 518 case AUDIO_FORMAT_AMR_NB: 519 case AUDIO_FORMAT_AMR_WB: 520 case AUDIO_FORMAT_AAC: 521 case AUDIO_FORMAT_HE_AAC_V1: 522 case AUDIO_FORMAT_HE_AAC_V2: 523 case AUDIO_FORMAT_VORBIS: 524 return true; 525 default: 526 return false; 527 } 528 } 529 530 static inline bool audio_is_linear_pcm(audio_format_t format) 531 { 532 return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM); 533 } 534 535 static inline size_t audio_bytes_per_sample(audio_format_t format) 536 { 537 size_t size = 0; 538 539 switch (format) { 540 case AUDIO_FORMAT_PCM_32_BIT: 541 case AUDIO_FORMAT_PCM_8_24_BIT: 542 size = sizeof(int32_t); 543 break; 544 case AUDIO_FORMAT_PCM_16_BIT: 545 size = sizeof(int16_t); 546 break; 547 case AUDIO_FORMAT_PCM_8_BIT: 548 size = sizeof(uint8_t); 549 break; 550 default: 551 break; 552 } 553 return size; 554 } 555 556 __END_DECLS 557 558 #endif // ANDROID_AUDIO_CORE_H 559