audio.h revision 4cd050121fd22c0f7277a988d548d0e8f327a760
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/* device address used to refer to the standard remote submix */ 35#define AUDIO_REMOTE_SUBMIX_DEVICE_ADDRESS "0" 36 37/* AudioFlinger and AudioPolicy services use I/O handles to identify audio sources and sinks */ 38typedef int audio_io_handle_t; 39#define AUDIO_IO_HANDLE_NONE 0 40 41/* Audio stream types */ 42typedef enum { 43 /* These values must kept in sync with 44 * frameworks/base/media/java/android/media/AudioSystem.java 45 */ 46 AUDIO_STREAM_DEFAULT = -1, 47 AUDIO_STREAM_MIN = 0, 48 AUDIO_STREAM_VOICE_CALL = 0, 49 AUDIO_STREAM_SYSTEM = 1, 50 AUDIO_STREAM_RING = 2, 51 AUDIO_STREAM_MUSIC = 3, 52 AUDIO_STREAM_ALARM = 4, 53 AUDIO_STREAM_NOTIFICATION = 5, 54 AUDIO_STREAM_BLUETOOTH_SCO = 6, 55 AUDIO_STREAM_ENFORCED_AUDIBLE = 7, /* Sounds that cannot be muted by user and must be routed to speaker */ 56 AUDIO_STREAM_DTMF = 8, 57 AUDIO_STREAM_TTS = 9, 58 59 AUDIO_STREAM_CNT, 60 AUDIO_STREAM_MAX = AUDIO_STREAM_CNT - 1, 61} audio_stream_type_t; 62 63/* Do not change these values without updating their counterparts 64 * in frameworks/base/media/java/android/media/MediaRecorder.java, 65 * frameworks/av/services/audioflinger/AudioPolicyService.cpp, 66 * and system/media/audio_effects/include/audio_effects/audio_effects_conf.h! 67 */ 68typedef enum { 69 AUDIO_SOURCE_DEFAULT = 0, 70 AUDIO_SOURCE_MIC = 1, 71 AUDIO_SOURCE_VOICE_UPLINK = 2, 72 AUDIO_SOURCE_VOICE_DOWNLINK = 3, 73 AUDIO_SOURCE_VOICE_CALL = 4, 74 AUDIO_SOURCE_CAMCORDER = 5, 75 AUDIO_SOURCE_VOICE_RECOGNITION = 6, 76 AUDIO_SOURCE_VOICE_COMMUNICATION = 7, 77 AUDIO_SOURCE_REMOTE_SUBMIX = 8, /* Source for the mix to be presented remotely. */ 78 /* An example of remote presentation is Wifi Display */ 79 /* where a dongle attached to a TV can be used to */ 80 /* play the mix captured by this audio source. */ 81 AUDIO_SOURCE_CNT, 82 AUDIO_SOURCE_MAX = AUDIO_SOURCE_CNT - 1, 83 AUDIO_SOURCE_HOTWORD = 1999, /* A low-priority, preemptible audio source for 84 for background software hotword detection. 85 Same tuning as AUDIO_SOURCE_VOICE_RECOGNITION. 86 Used only internally to the framework. Not exposed 87 at the audio HAL. */ 88} audio_source_t; 89 90/* special audio session values 91 * (XXX: should this be living in the audio effects land?) 92 */ 93typedef enum { 94 /* session for effects attached to a particular output stream 95 * (value must be less than 0) 96 */ 97 AUDIO_SESSION_OUTPUT_STAGE = -1, 98 99 /* session for effects applied to output mix. These effects can 100 * be moved by audio policy manager to another output stream 101 * (value must be 0) 102 */ 103 AUDIO_SESSION_OUTPUT_MIX = 0, 104 105 /* application does not specify an explicit session ID to be used, 106 * and requests a new session ID to be allocated 107 * TODO use unique values for AUDIO_SESSION_OUTPUT_MIX and AUDIO_SESSION_ALLOCATE, 108 * after all uses have been updated from 0 to the appropriate symbol, and have been tested. 109 */ 110 AUDIO_SESSION_ALLOCATE = 0, 111} audio_session_t; 112 113/* Audio sub formats (see enum audio_format). */ 114 115/* PCM sub formats */ 116typedef enum { 117 /* All of these are in native byte order */ 118 AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1, /* DO NOT CHANGE - PCM signed 16 bits */ 119 AUDIO_FORMAT_PCM_SUB_8_BIT = 0x2, /* DO NOT CHANGE - PCM unsigned 8 bits */ 120 AUDIO_FORMAT_PCM_SUB_32_BIT = 0x3, /* PCM signed .31 fixed point */ 121 AUDIO_FORMAT_PCM_SUB_8_24_BIT = 0x4, /* PCM signed 7.24 fixed point */ 122 AUDIO_FORMAT_PCM_SUB_FLOAT = 0x5, /* PCM single-precision floating point */ 123 AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED = 0x6, /* PCM signed .23 fixed point packed in 3 bytes */ 124} audio_format_pcm_sub_fmt_t; 125 126/* The audio_format_*_sub_fmt_t declarations are not currently used */ 127 128/* MP3 sub format field definition : can use 11 LSBs in the same way as MP3 129 * frame header to specify bit rate, stereo mode, version... 130 */ 131typedef enum { 132 AUDIO_FORMAT_MP3_SUB_NONE = 0x0, 133} audio_format_mp3_sub_fmt_t; 134 135/* AMR NB/WB sub format field definition: specify frame block interleaving, 136 * bandwidth efficient or octet aligned, encoding mode for recording... 137 */ 138typedef enum { 139 AUDIO_FORMAT_AMR_SUB_NONE = 0x0, 140} audio_format_amr_sub_fmt_t; 141 142/* AAC sub format field definition: specify profile or bitrate for recording... */ 143typedef enum { 144 AUDIO_FORMAT_AAC_SUB_NONE = 0x0, 145} audio_format_aac_sub_fmt_t; 146 147/* VORBIS sub format field definition: specify quality for recording... */ 148typedef enum { 149 AUDIO_FORMAT_VORBIS_SUB_NONE = 0x0, 150} audio_format_vorbis_sub_fmt_t; 151 152/* Audio format consists of a main format field (upper 8 bits) and a sub format 153 * field (lower 24 bits). 154 * 155 * The main format indicates the main codec type. The sub format field 156 * indicates options and parameters for each format. The sub format is mainly 157 * used for record to indicate for instance the requested bitrate or profile. 158 * It can also be used for certain formats to give informations not present in 159 * the encoded audio stream (e.g. octet alignement for AMR). 160 */ 161typedef enum { 162 AUDIO_FORMAT_INVALID = 0xFFFFFFFFUL, 163 AUDIO_FORMAT_DEFAULT = 0, 164 AUDIO_FORMAT_PCM = 0x00000000UL, /* DO NOT CHANGE */ 165 AUDIO_FORMAT_MP3 = 0x01000000UL, 166 AUDIO_FORMAT_AMR_NB = 0x02000000UL, 167 AUDIO_FORMAT_AMR_WB = 0x03000000UL, 168 AUDIO_FORMAT_AAC = 0x04000000UL, 169 AUDIO_FORMAT_HE_AAC_V1 = 0x05000000UL, 170 AUDIO_FORMAT_HE_AAC_V2 = 0x06000000UL, 171 AUDIO_FORMAT_VORBIS = 0x07000000UL, 172 AUDIO_FORMAT_OPUS = 0x08000000UL, 173 AUDIO_FORMAT_MAIN_MASK = 0xFF000000UL, 174 AUDIO_FORMAT_SUB_MASK = 0x00FFFFFFUL, 175 176 /* Aliases */ 177 /* note != AudioFormat.ENCODING_PCM_16BIT */ 178 AUDIO_FORMAT_PCM_16_BIT = (AUDIO_FORMAT_PCM | 179 AUDIO_FORMAT_PCM_SUB_16_BIT), 180 /* note != AudioFormat.ENCODING_PCM_8BIT */ 181 AUDIO_FORMAT_PCM_8_BIT = (AUDIO_FORMAT_PCM | 182 AUDIO_FORMAT_PCM_SUB_8_BIT), 183 AUDIO_FORMAT_PCM_32_BIT = (AUDIO_FORMAT_PCM | 184 AUDIO_FORMAT_PCM_SUB_32_BIT), 185 AUDIO_FORMAT_PCM_8_24_BIT = (AUDIO_FORMAT_PCM | 186 AUDIO_FORMAT_PCM_SUB_8_24_BIT), 187 AUDIO_FORMAT_PCM_FLOAT = (AUDIO_FORMAT_PCM | 188 AUDIO_FORMAT_PCM_SUB_FLOAT), 189 AUDIO_FORMAT_PCM_24_BIT_PACKED = (AUDIO_FORMAT_PCM | 190 AUDIO_FORMAT_PCM_SUB_24_BIT_PACKED), 191} audio_format_t; 192 193enum { 194 AUDIO_CHANNEL_NONE = 0x0, 195 /* output channels */ 196 AUDIO_CHANNEL_OUT_FRONT_LEFT = 0x1, 197 AUDIO_CHANNEL_OUT_FRONT_RIGHT = 0x2, 198 AUDIO_CHANNEL_OUT_FRONT_CENTER = 0x4, 199 AUDIO_CHANNEL_OUT_LOW_FREQUENCY = 0x8, 200 AUDIO_CHANNEL_OUT_BACK_LEFT = 0x10, 201 AUDIO_CHANNEL_OUT_BACK_RIGHT = 0x20, 202 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER = 0x40, 203 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER = 0x80, 204 AUDIO_CHANNEL_OUT_BACK_CENTER = 0x100, 205 AUDIO_CHANNEL_OUT_SIDE_LEFT = 0x200, 206 AUDIO_CHANNEL_OUT_SIDE_RIGHT = 0x400, 207 AUDIO_CHANNEL_OUT_TOP_CENTER = 0x800, 208 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT = 0x1000, 209 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER = 0x2000, 210 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT = 0x4000, 211 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT = 0x8000, 212 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER = 0x10000, 213 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT = 0x20000, 214 215 AUDIO_CHANNEL_OUT_MONO = AUDIO_CHANNEL_OUT_FRONT_LEFT, 216 AUDIO_CHANNEL_OUT_STEREO = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 217 AUDIO_CHANNEL_OUT_FRONT_RIGHT), 218 AUDIO_CHANNEL_OUT_QUAD = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 219 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 220 AUDIO_CHANNEL_OUT_BACK_LEFT | 221 AUDIO_CHANNEL_OUT_BACK_RIGHT), 222 AUDIO_CHANNEL_OUT_QUAD_BACK = AUDIO_CHANNEL_OUT_QUAD, 223 /* like AUDIO_CHANNEL_OUT_QUAD_BACK with *_SIDE_* instead of *_BACK_* */ 224 AUDIO_CHANNEL_OUT_QUAD_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 225 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 226 AUDIO_CHANNEL_OUT_SIDE_LEFT | 227 AUDIO_CHANNEL_OUT_SIDE_RIGHT), 228 AUDIO_CHANNEL_OUT_5POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 229 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 230 AUDIO_CHANNEL_OUT_FRONT_CENTER | 231 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 232 AUDIO_CHANNEL_OUT_BACK_LEFT | 233 AUDIO_CHANNEL_OUT_BACK_RIGHT), 234 AUDIO_CHANNEL_OUT_5POINT1_BACK = AUDIO_CHANNEL_OUT_5POINT1, 235 /* like AUDIO_CHANNEL_OUT_5POINT1_BACK with *_SIDE_* instead of *_BACK_* */ 236 AUDIO_CHANNEL_OUT_5POINT1_SIDE = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 237 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 238 AUDIO_CHANNEL_OUT_FRONT_CENTER | 239 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 240 AUDIO_CHANNEL_OUT_SIDE_LEFT | 241 AUDIO_CHANNEL_OUT_SIDE_RIGHT), 242 // matches the correct AudioFormat.CHANNEL_OUT_7POINT1_SURROUND definition for 7.1 243 AUDIO_CHANNEL_OUT_7POINT1 = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 244 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 245 AUDIO_CHANNEL_OUT_FRONT_CENTER | 246 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 247 AUDIO_CHANNEL_OUT_BACK_LEFT | 248 AUDIO_CHANNEL_OUT_BACK_RIGHT | 249 AUDIO_CHANNEL_OUT_SIDE_LEFT | 250 AUDIO_CHANNEL_OUT_SIDE_RIGHT), 251 AUDIO_CHANNEL_OUT_ALL = (AUDIO_CHANNEL_OUT_FRONT_LEFT | 252 AUDIO_CHANNEL_OUT_FRONT_RIGHT | 253 AUDIO_CHANNEL_OUT_FRONT_CENTER | 254 AUDIO_CHANNEL_OUT_LOW_FREQUENCY | 255 AUDIO_CHANNEL_OUT_BACK_LEFT | 256 AUDIO_CHANNEL_OUT_BACK_RIGHT | 257 AUDIO_CHANNEL_OUT_FRONT_LEFT_OF_CENTER | 258 AUDIO_CHANNEL_OUT_FRONT_RIGHT_OF_CENTER | 259 AUDIO_CHANNEL_OUT_BACK_CENTER| 260 AUDIO_CHANNEL_OUT_SIDE_LEFT| 261 AUDIO_CHANNEL_OUT_SIDE_RIGHT| 262 AUDIO_CHANNEL_OUT_TOP_CENTER| 263 AUDIO_CHANNEL_OUT_TOP_FRONT_LEFT| 264 AUDIO_CHANNEL_OUT_TOP_FRONT_CENTER| 265 AUDIO_CHANNEL_OUT_TOP_FRONT_RIGHT| 266 AUDIO_CHANNEL_OUT_TOP_BACK_LEFT| 267 AUDIO_CHANNEL_OUT_TOP_BACK_CENTER| 268 AUDIO_CHANNEL_OUT_TOP_BACK_RIGHT), 269 270 /* input channels */ 271 AUDIO_CHANNEL_IN_LEFT = 0x4, 272 AUDIO_CHANNEL_IN_RIGHT = 0x8, 273 AUDIO_CHANNEL_IN_FRONT = 0x10, 274 AUDIO_CHANNEL_IN_BACK = 0x20, 275 AUDIO_CHANNEL_IN_LEFT_PROCESSED = 0x40, 276 AUDIO_CHANNEL_IN_RIGHT_PROCESSED = 0x80, 277 AUDIO_CHANNEL_IN_FRONT_PROCESSED = 0x100, 278 AUDIO_CHANNEL_IN_BACK_PROCESSED = 0x200, 279 AUDIO_CHANNEL_IN_PRESSURE = 0x400, 280 AUDIO_CHANNEL_IN_X_AXIS = 0x800, 281 AUDIO_CHANNEL_IN_Y_AXIS = 0x1000, 282 AUDIO_CHANNEL_IN_Z_AXIS = 0x2000, 283 AUDIO_CHANNEL_IN_VOICE_UPLINK = 0x4000, 284 AUDIO_CHANNEL_IN_VOICE_DNLINK = 0x8000, 285 286 AUDIO_CHANNEL_IN_MONO = AUDIO_CHANNEL_IN_FRONT, 287 AUDIO_CHANNEL_IN_STEREO = (AUDIO_CHANNEL_IN_LEFT | AUDIO_CHANNEL_IN_RIGHT), 288 AUDIO_CHANNEL_IN_FRONT_BACK = (AUDIO_CHANNEL_IN_FRONT | AUDIO_CHANNEL_IN_BACK), 289 AUDIO_CHANNEL_IN_ALL = (AUDIO_CHANNEL_IN_LEFT | 290 AUDIO_CHANNEL_IN_RIGHT | 291 AUDIO_CHANNEL_IN_FRONT | 292 AUDIO_CHANNEL_IN_BACK| 293 AUDIO_CHANNEL_IN_LEFT_PROCESSED | 294 AUDIO_CHANNEL_IN_RIGHT_PROCESSED | 295 AUDIO_CHANNEL_IN_FRONT_PROCESSED | 296 AUDIO_CHANNEL_IN_BACK_PROCESSED| 297 AUDIO_CHANNEL_IN_PRESSURE | 298 AUDIO_CHANNEL_IN_X_AXIS | 299 AUDIO_CHANNEL_IN_Y_AXIS | 300 AUDIO_CHANNEL_IN_Z_AXIS | 301 AUDIO_CHANNEL_IN_VOICE_UPLINK | 302 AUDIO_CHANNEL_IN_VOICE_DNLINK), 303}; 304 305/* A channel mask per se only defines the presence or absence of a channel, not the order. 306 * But see AUDIO_INTERLEAVE_* below for the platform convention of order. 307 */ 308typedef uint32_t audio_channel_mask_t; 309 310/* Expresses the convention when stereo audio samples are stored interleaved 311 * in an array. This should improve readability by allowing code to use 312 * symbolic indices instead of hard-coded [0] and [1]. 313 * 314 * For multi-channel beyond stereo, the platform convention is that channels 315 * are interleaved in order from least significant channel mask bit 316 * to most significant channel mask bit, with unused bits skipped. 317 * Any exceptions to this convention will be noted at the appropriate API. 318 */ 319enum { 320 AUDIO_INTERLEAVE_LEFT = 0, 321 AUDIO_INTERLEAVE_RIGHT = 1, 322}; 323 324typedef enum { 325 AUDIO_MODE_INVALID = -2, 326 AUDIO_MODE_CURRENT = -1, 327 AUDIO_MODE_NORMAL = 0, 328 AUDIO_MODE_RINGTONE = 1, 329 AUDIO_MODE_IN_CALL = 2, 330 AUDIO_MODE_IN_COMMUNICATION = 3, 331 332 AUDIO_MODE_CNT, 333 AUDIO_MODE_MAX = AUDIO_MODE_CNT - 1, 334} audio_mode_t; 335 336/* This enum is deprecated */ 337typedef enum { 338 AUDIO_IN_ACOUSTICS_NONE = 0, 339 AUDIO_IN_ACOUSTICS_AGC_ENABLE = 0x0001, 340 AUDIO_IN_ACOUSTICS_AGC_DISABLE = 0, 341 AUDIO_IN_ACOUSTICS_NS_ENABLE = 0x0002, 342 AUDIO_IN_ACOUSTICS_NS_DISABLE = 0, 343 AUDIO_IN_ACOUSTICS_TX_IIR_ENABLE = 0x0004, 344 AUDIO_IN_ACOUSTICS_TX_DISABLE = 0, 345} audio_in_acoustics_t; 346 347enum { 348 AUDIO_DEVICE_NONE = 0x0, 349 /* reserved bits */ 350 AUDIO_DEVICE_BIT_IN = 0x80000000, 351 AUDIO_DEVICE_BIT_DEFAULT = 0x40000000, 352 /* output devices */ 353 AUDIO_DEVICE_OUT_EARPIECE = 0x1, 354 AUDIO_DEVICE_OUT_SPEAKER = 0x2, 355 AUDIO_DEVICE_OUT_WIRED_HEADSET = 0x4, 356 AUDIO_DEVICE_OUT_WIRED_HEADPHONE = 0x8, 357 AUDIO_DEVICE_OUT_BLUETOOTH_SCO = 0x10, 358 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET = 0x20, 359 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT = 0x40, 360 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP = 0x80, 361 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100, 362 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200, 363 AUDIO_DEVICE_OUT_AUX_DIGITAL = 0x400, 364 AUDIO_DEVICE_OUT_HDMI = AUDIO_DEVICE_OUT_AUX_DIGITAL, 365 /* uses an analog connection (multiplexed over the USB connector pins for instance) */ 366 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET = 0x800, 367 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET = 0x1000, 368 /* USB accessory mode: your Android device is a USB device and the dock is a USB host */ 369 AUDIO_DEVICE_OUT_USB_ACCESSORY = 0x2000, 370 /* USB host mode: your Android device is a USB host and the dock is a USB device */ 371 AUDIO_DEVICE_OUT_USB_DEVICE = 0x4000, 372 AUDIO_DEVICE_OUT_REMOTE_SUBMIX = 0x8000, 373 /* Telephony voice TX path */ 374 AUDIO_DEVICE_OUT_TELEPHONY_TX = 0x10000, 375 /* Analog jack with line impedance detected */ 376 AUDIO_DEVICE_OUT_LINE = 0x20000, 377 /* HDMI Audio Return Channel */ 378 AUDIO_DEVICE_OUT_HDMI_ARC = 0x40000, 379 /* S/PDIF out */ 380 AUDIO_DEVICE_OUT_SPDIF = 0x80000, 381 /* FM transmitter out */ 382 AUDIO_DEVICE_OUT_FM = 0x100000, 383 AUDIO_DEVICE_OUT_DEFAULT = AUDIO_DEVICE_BIT_DEFAULT, 384 AUDIO_DEVICE_OUT_ALL = (AUDIO_DEVICE_OUT_EARPIECE | 385 AUDIO_DEVICE_OUT_SPEAKER | 386 AUDIO_DEVICE_OUT_WIRED_HEADSET | 387 AUDIO_DEVICE_OUT_WIRED_HEADPHONE | 388 AUDIO_DEVICE_OUT_BLUETOOTH_SCO | 389 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | 390 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT | 391 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | 392 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | 393 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | 394 AUDIO_DEVICE_OUT_HDMI | 395 AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET | 396 AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | 397 AUDIO_DEVICE_OUT_USB_ACCESSORY | 398 AUDIO_DEVICE_OUT_USB_DEVICE | 399 AUDIO_DEVICE_OUT_REMOTE_SUBMIX | 400 AUDIO_DEVICE_OUT_TELEPHONY_TX | 401 AUDIO_DEVICE_OUT_LINE | 402 AUDIO_DEVICE_OUT_HDMI_ARC | 403 AUDIO_DEVICE_OUT_SPDIF | 404 AUDIO_DEVICE_OUT_FM | 405 AUDIO_DEVICE_OUT_DEFAULT), 406 AUDIO_DEVICE_OUT_ALL_A2DP = (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP | 407 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | 408 AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER), 409 AUDIO_DEVICE_OUT_ALL_SCO = (AUDIO_DEVICE_OUT_BLUETOOTH_SCO | 410 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_HEADSET | 411 AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT), 412 AUDIO_DEVICE_OUT_ALL_USB = (AUDIO_DEVICE_OUT_USB_ACCESSORY | 413 AUDIO_DEVICE_OUT_USB_DEVICE), 414 415 /* input devices */ 416 AUDIO_DEVICE_IN_COMMUNICATION = AUDIO_DEVICE_BIT_IN | 0x1, 417 AUDIO_DEVICE_IN_AMBIENT = AUDIO_DEVICE_BIT_IN | 0x2, 418 AUDIO_DEVICE_IN_BUILTIN_MIC = AUDIO_DEVICE_BIT_IN | 0x4, 419 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET = AUDIO_DEVICE_BIT_IN | 0x8, 420 AUDIO_DEVICE_IN_WIRED_HEADSET = AUDIO_DEVICE_BIT_IN | 0x10, 421 AUDIO_DEVICE_IN_AUX_DIGITAL = AUDIO_DEVICE_BIT_IN | 0x20, 422 AUDIO_DEVICE_IN_HDMI = AUDIO_DEVICE_IN_AUX_DIGITAL, 423 /* Telephony voice RX path */ 424 AUDIO_DEVICE_IN_VOICE_CALL = AUDIO_DEVICE_BIT_IN | 0x40, 425 AUDIO_DEVICE_IN_TELEPHONY_RX = AUDIO_DEVICE_IN_VOICE_CALL, 426 AUDIO_DEVICE_IN_BACK_MIC = AUDIO_DEVICE_BIT_IN | 0x80, 427 AUDIO_DEVICE_IN_REMOTE_SUBMIX = AUDIO_DEVICE_BIT_IN | 0x100, 428 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x200, 429 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET = AUDIO_DEVICE_BIT_IN | 0x400, 430 AUDIO_DEVICE_IN_USB_ACCESSORY = AUDIO_DEVICE_BIT_IN | 0x800, 431 AUDIO_DEVICE_IN_USB_DEVICE = AUDIO_DEVICE_BIT_IN | 0x1000, 432 /* FM tuner input */ 433 AUDIO_DEVICE_IN_FM_TUNER = AUDIO_DEVICE_BIT_IN | 0x2000, 434 /* TV tuner input */ 435 AUDIO_DEVICE_IN_TV_TUNER = AUDIO_DEVICE_BIT_IN | 0x4000, 436 /* Analog jack with line impedance detected */ 437 AUDIO_DEVICE_IN_LINE = AUDIO_DEVICE_BIT_IN | 0x8000, 438 /* S/PDIF in */ 439 AUDIO_DEVICE_IN_SPDIF = AUDIO_DEVICE_BIT_IN | 0x10000, 440 AUDIO_DEVICE_IN_DEFAULT = AUDIO_DEVICE_BIT_IN | AUDIO_DEVICE_BIT_DEFAULT, 441 442 AUDIO_DEVICE_IN_ALL = (AUDIO_DEVICE_IN_COMMUNICATION | 443 AUDIO_DEVICE_IN_AMBIENT | 444 AUDIO_DEVICE_IN_BUILTIN_MIC | 445 AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET | 446 AUDIO_DEVICE_IN_WIRED_HEADSET | 447 AUDIO_DEVICE_IN_HDMI | 448 AUDIO_DEVICE_IN_TELEPHONY_RX | 449 AUDIO_DEVICE_IN_BACK_MIC | 450 AUDIO_DEVICE_IN_REMOTE_SUBMIX | 451 AUDIO_DEVICE_IN_ANLG_DOCK_HEADSET | 452 AUDIO_DEVICE_IN_DGTL_DOCK_HEADSET | 453 AUDIO_DEVICE_IN_USB_ACCESSORY | 454 AUDIO_DEVICE_IN_USB_DEVICE | 455 AUDIO_DEVICE_IN_FM_TUNER | 456 AUDIO_DEVICE_IN_TV_TUNER | 457 AUDIO_DEVICE_IN_LINE | 458 AUDIO_DEVICE_IN_SPDIF | 459 AUDIO_DEVICE_IN_DEFAULT), 460 AUDIO_DEVICE_IN_ALL_SCO = AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET, 461 AUDIO_DEVICE_IN_ALL_USB = (AUDIO_DEVICE_IN_USB_ACCESSORY | 462 AUDIO_DEVICE_IN_USB_DEVICE), 463}; 464 465typedef uint32_t audio_devices_t; 466 467/* the audio output flags serve two purposes: 468 * - when an AudioTrack is created they indicate a "wish" to be connected to an 469 * output stream with attributes corresponding to the specified flags 470 * - when present in an output profile descriptor listed for a particular audio 471 * hardware module, they indicate that an output stream can be opened that 472 * supports the attributes indicated by the flags. 473 * the audio policy manager will try to match the flags in the request 474 * (when getOuput() is called) to an available output stream. 475 */ 476typedef enum { 477 AUDIO_OUTPUT_FLAG_NONE = 0x0, // no attributes 478 AUDIO_OUTPUT_FLAG_DIRECT = 0x1, // this output directly connects a track 479 // to one output stream: no software mixer 480 AUDIO_OUTPUT_FLAG_PRIMARY = 0x2, // this output is the primary output of 481 // the device. It is unique and must be 482 // present. It is opened by default and 483 // receives routing, audio mode and volume 484 // controls related to voice calls. 485 AUDIO_OUTPUT_FLAG_FAST = 0x4, // output supports "fast tracks", 486 // defined elsewhere 487 AUDIO_OUTPUT_FLAG_DEEP_BUFFER = 0x8, // use deep audio buffers 488 AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD = 0x10, // offload playback of compressed 489 // streams to hardware codec 490 AUDIO_OUTPUT_FLAG_NON_BLOCKING = 0x20 // use non-blocking write 491} audio_output_flags_t; 492 493/* The audio input flags are analogous to audio output flags. 494 * Currently they are used only when an AudioRecord is created, 495 * to indicate a preference to be connected to an input stream with 496 * attributes corresponding to the specified flags. 497 */ 498typedef enum { 499 AUDIO_INPUT_FLAG_NONE = 0x0, // no attributes 500 AUDIO_INPUT_FLAG_FAST = 0x1, // prefer an input that supports "fast tracks" 501} audio_input_flags_t; 502 503/* Additional information about compressed streams offloaded to 504 * hardware playback 505 * The version and size fields must be initialized by the caller by using 506 * one of the constants defined here. 507 */ 508typedef struct { 509 uint16_t version; // version of the info structure 510 uint16_t size; // total size of the structure including version and size 511 uint32_t sample_rate; // sample rate in Hz 512 audio_channel_mask_t channel_mask; // channel mask 513 audio_format_t format; // audio format 514 audio_stream_type_t stream_type; // stream type 515 uint32_t bit_rate; // bit rate in bits per second 516 int64_t duration_us; // duration in microseconds, -1 if unknown 517 bool has_video; // true if stream is tied to a video stream 518 bool is_streaming; // true if streaming, false if local playback 519} audio_offload_info_t; 520 521#define AUDIO_MAKE_OFFLOAD_INFO_VERSION(maj,min) \ 522 ((((maj) & 0xff) << 8) | ((min) & 0xff)) 523 524#define AUDIO_OFFLOAD_INFO_VERSION_0_1 AUDIO_MAKE_OFFLOAD_INFO_VERSION(0, 1) 525#define AUDIO_OFFLOAD_INFO_VERSION_CURRENT AUDIO_OFFLOAD_INFO_VERSION_0_1 526 527static const audio_offload_info_t AUDIO_INFO_INITIALIZER = { 528 version: AUDIO_OFFLOAD_INFO_VERSION_CURRENT, 529 size: sizeof(audio_offload_info_t), 530}; 531 532 533/* audio hw module handle functions or structures referencing a module */ 534typedef int audio_module_handle_t; 535 536/****************************** 537 * Volume control 538 *****************************/ 539 540/* If the audio hardware supports gain control on some audio paths, 541 * the platform can expose them in the audio_policy.conf file. The audio HAL 542 * will then implement gain control functions that will use the following data 543 * structures. */ 544 545/* Type of gain control exposed by an audio port */ 546#define AUDIO_GAIN_MODE_JOINT 0x1 /* supports joint channel gain control */ 547#define AUDIO_GAIN_MODE_CHANNELS 0x2 /* supports separate channel gain control */ 548#define AUDIO_GAIN_MODE_RAMP 0x4 /* supports gain ramps */ 549 550typedef uint32_t audio_gain_mode_t; 551 552 553/* An audio_gain struct is a representation of a gain stage. 554 * A gain stage is always attached to an audio port. */ 555struct audio_gain { 556 audio_gain_mode_t mode; /* e.g. AUDIO_GAIN_MODE_JOINT */ 557 audio_channel_mask_t channel_mask; /* channels which gain an be controlled. 558 N/A if AUDIO_GAIN_MODE_CHANNELS is not supported */ 559 int min_value; /* minimum gain value in millibels */ 560 int max_value; /* maximum gain value in millibels */ 561 int default_value; /* default gain value in millibels */ 562 unsigned int step_value; /* gain step in millibels */ 563 unsigned int min_ramp_ms; /* minimum ramp duration in ms */ 564 unsigned int max_ramp_ms; /* maximum ramp duration in ms */ 565}; 566 567/* The gain configuration structure is used to get or set the gain values of a 568 * given port */ 569struct audio_gain_config { 570 int index; /* index of the corresponding audio_gain in the 571 audio_port gains[] table */ 572 audio_gain_mode_t mode; /* mode requested for this command */ 573 audio_channel_mask_t channel_mask; /* channels which gain value follows. 574 N/A in joint mode */ 575 int values[sizeof(audio_channel_mask_t)]; /* gain values in millibels for each 576 channel ordered from LSb to MSb in channel mask. 577 The number of values is 1 in joint mode or 578 popcount(channel_mask) */ 579 unsigned int ramp_duration_ms; /* ramp duration in ms */ 580}; 581 582/****************************** 583 * Routing control 584 *****************************/ 585 586/* Types defined here are used to describe an audio source or sink at internal 587 * framework interfaces (audio policy, patch panel) or at the audio HAL. 588 * Sink and sources are grouped in a concept of “audio port” representing an 589 * audio end point at the edge of the system managed by the module exposing 590 * the interface. */ 591 592/* Audio port role: either source or sink */ 593typedef enum { 594 AUDIO_PORT_ROLE_NONE, 595 AUDIO_PORT_ROLE_SOURCE, 596 AUDIO_PORT_ROLE_SINK, 597} audio_port_role_t; 598 599/* Audio port type indicates if it is a session (e.g AudioTrack), 600 * a mix (e.g PlaybackThread output) or a physical device 601 * (e.g AUDIO_DEVICE_OUT_SPEAKER) */ 602typedef enum { 603 AUDIO_PORT_TYPE_NONE, 604 AUDIO_PORT_TYPE_DEVICE, 605 AUDIO_PORT_TYPE_MIX, 606 AUDIO_PORT_TYPE_SESSION, 607} audio_port_type_t; 608 609/* Each port has a unique ID or handle allocated by policy manager */ 610typedef int audio_port_handle_t; 611#define AUDIO_PORT_HANDLE_NONE 0 612 613 614/* maximum audio device address length */ 615#define AUDIO_DEVICE_MAX_ADDRESS_LEN 32 616 617/* extension for audio port configuration structure when the audio port is a 618 * hardware device */ 619struct audio_port_config_device_ext { 620 audio_module_handle_t hw_module; /* module the device is attached to */ 621 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */ 622 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; /* device address. "" if N/A */ 623}; 624 625/* extension for audio port configuration structure when the audio port is a 626 * sub mix */ 627struct audio_port_config_mix_ext { 628 audio_module_handle_t hw_module; /* module the stream is attached to */ 629 audio_io_handle_t handle; /* I/O handle of the input/output stream */ 630 union { 631 //TODO: change use case for output streams: use strategy and mixer attributes 632 audio_stream_type_t stream; 633 audio_source_t source; 634 } usecase; 635}; 636 637/* extension for audio port configuration structure when the audio port is an 638 * audio session */ 639struct audio_port_config_session_ext { 640 audio_session_t session; /* audio session */ 641}; 642 643/* Flags indicating which fields are to be considered in struct audio_port_config */ 644#define AUDIO_PORT_CONFIG_SAMPLE_RATE 0x1 645#define AUDIO_PORT_CONFIG_CHANNEL_MASK 0x2 646#define AUDIO_PORT_CONFIG_FORMAT 0x4 647#define AUDIO_PORT_CONFIG_GAIN 0x8 648#define AUDIO_PORT_CONFIG_ALL (AUDIO_PORT_CONFIG_SAMPLE_RATE | \ 649 AUDIO_PORT_CONFIG_CHANNEL_MASK | \ 650 AUDIO_PORT_CONFIG_FORMAT | \ 651 AUDIO_PORT_CONFIG_GAIN) 652 653/* audio port configuration structure used to specify a particular configuration of 654 * an audio port */ 655struct audio_port_config { 656 audio_port_handle_t id; /* port unique ID */ 657 audio_port_role_t role; /* sink or source */ 658 audio_port_type_t type; /* device, mix ... */ 659 unsigned int config_mask; /* e.g AUDIO_PORT_CONFIG_ALL */ 660 unsigned int sample_rate; /* sampling rate in Hz */ 661 audio_channel_mask_t channel_mask; /* channel mask if applicable */ 662 audio_format_t format; /* format if applicable */ 663 struct audio_gain_config gain; /* gain to apply if applicable */ 664 union { 665 struct audio_port_config_device_ext device; /* device specific info */ 666 struct audio_port_config_mix_ext mix; /* mix specific info */ 667 struct audio_port_config_session_ext session; /* session specific info */ 668 } ext; 669}; 670 671 672/* max number of sampling rates in audio port */ 673#define AUDIO_PORT_MAX_SAMPLING_RATES 16 674/* max number of channel masks in audio port */ 675#define AUDIO_PORT_MAX_CHANNEL_MASKS 16 676/* max number of audio formats in audio port */ 677#define AUDIO_PORT_MAX_FORMATS 16 678/* max number of gain controls in audio port */ 679#define AUDIO_PORT_MAX_GAINS 16 680 681/* extension for audio port structure when the audio port is a hardware device */ 682struct audio_port_device_ext { 683 audio_module_handle_t hw_module; /* module the device is attached to */ 684 audio_devices_t type; /* device type (e.g AUDIO_DEVICE_OUT_SPEAKER) */ 685 char address[AUDIO_DEVICE_MAX_ADDRESS_LEN]; 686}; 687 688/* Latency class of the audio mix */ 689typedef enum { 690 AUDIO_LATENCY_LOW, 691 AUDIO_LATENCY_NORMAL, 692} audio_mix_latency_class_t; 693 694/* extension for audio port structure when the audio port is a sub mix */ 695struct audio_port_mix_ext { 696 audio_module_handle_t hw_module; /* module the stream is attached to */ 697 audio_io_handle_t handle; /* I/O handle of the input.output stream */ 698 audio_mix_latency_class_t latency_class; /* latency class */ 699 // other attributes: routing strategies 700}; 701 702/* extension for audio port structure when the audio port is an audio session */ 703struct audio_port_session_ext { 704 audio_session_t session; /* audio session */ 705}; 706 707 708struct audio_port { 709 audio_port_handle_t id; /* port unique ID */ 710 audio_port_role_t role; /* sink or source */ 711 audio_port_type_t type; /* device, mix ... */ 712 unsigned int num_sample_rates; /* number of sampling rates in following array */ 713 unsigned int sample_rates[AUDIO_PORT_MAX_SAMPLING_RATES]; 714 unsigned int num_channel_masks; /* number of channel masks in following array */ 715 audio_channel_mask_t channel_masks[AUDIO_PORT_MAX_CHANNEL_MASKS]; 716 unsigned int num_formats; /* number of formats in following array */ 717 audio_format_t formats[AUDIO_PORT_MAX_FORMATS]; 718 unsigned int num_gains; /* number of gains in following array */ 719 struct audio_gain gains[AUDIO_PORT_MAX_GAINS]; 720 struct audio_port_config active_config; /* current audio port configuration */ 721 union { 722 struct audio_port_device_ext device; 723 struct audio_port_mix_ext mix; 724 struct audio_port_session_ext session; 725 } ext; 726}; 727 728/* An audio patch represents a connection between one or more source ports and 729 * one or more sink ports. Patches are connected and disconnected by audio policy manager or by 730 * applications via framework APIs. 731 * Each patch is identified by a handle at the interface used to create that patch. For instance, 732 * when a patch is created by the audio HAL, the HAL allocates and returns a handle. 733 * This handle is unique to a given audio HAL hardware module. 734 * But the same patch receives another system wide unique handle allocated by the framework. 735 * This unique handle is used for all transactions inside the framework. 736 */ 737typedef int audio_patch_handle_t; 738#define AUDIO_PATCH_HANDLE_NONE 0 739 740#define AUDIO_PATCH_PORTS_MAX 16 741 742struct audio_patch { 743 audio_patch_handle_t id; /* patch unique ID */ 744 unsigned int num_sources; /* number of sources in following array */ 745 struct audio_port_config sources[AUDIO_PATCH_PORTS_MAX]; 746 unsigned int num_sinks; /* number of sinks in following array */ 747 struct audio_port_config sinks[AUDIO_PATCH_PORTS_MAX]; 748}; 749 750 751static inline bool audio_is_output_device(audio_devices_t device) 752{ 753 if (((device & AUDIO_DEVICE_BIT_IN) == 0) && 754 (popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL) == 0)) 755 return true; 756 else 757 return false; 758} 759 760static inline bool audio_is_input_device(audio_devices_t device) 761{ 762 if ((device & AUDIO_DEVICE_BIT_IN) != 0) { 763 device &= ~AUDIO_DEVICE_BIT_IN; 764 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_ALL) == 0)) 765 return true; 766 } 767 return false; 768} 769 770static inline bool audio_is_output_devices(audio_devices_t device) 771{ 772 return (device & AUDIO_DEVICE_BIT_IN) == 0; 773} 774 775 776static inline bool audio_is_a2dp_device(audio_devices_t device) 777{ 778 if ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_A2DP)) 779 return true; 780 else 781 return false; 782} 783 784static inline bool audio_is_bluetooth_sco_device(audio_devices_t device) 785{ 786 if ((device & AUDIO_DEVICE_BIT_IN) == 0) { 787 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_OUT_ALL_SCO) == 0)) 788 return true; 789 } else { 790 device &= ~AUDIO_DEVICE_BIT_IN; 791 if ((popcount(device) == 1) && ((device & ~AUDIO_DEVICE_IN_BLUETOOTH_SCO_HEADSET) == 0)) 792 return true; 793 } 794 795 return false; 796} 797 798static inline bool audio_is_usb_out_device(audio_devices_t device) 799{ 800 return ((popcount(device) == 1) && (device & AUDIO_DEVICE_OUT_ALL_USB)); 801} 802 803static inline bool audio_is_usb_in_device(audio_devices_t device) 804{ 805 if ((device & AUDIO_DEVICE_BIT_IN) != 0) { 806 device &= ~AUDIO_DEVICE_BIT_IN; 807 if (popcount(device) == 1 && (device & AUDIO_DEVICE_IN_ALL_USB) != 0) 808 return true; 809 } 810 return false; 811} 812 813/* OBSOLETE - use audio_is_usb_out_device() instead. */ 814static inline bool audio_is_usb_device(audio_devices_t device) 815{ 816 return audio_is_usb_out_device(device); 817} 818 819static inline bool audio_is_remote_submix_device(audio_devices_t device) 820{ 821 if ((device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) == AUDIO_DEVICE_OUT_REMOTE_SUBMIX 822 || (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) == AUDIO_DEVICE_IN_REMOTE_SUBMIX) 823 return true; 824 else 825 return false; 826} 827 828static inline bool audio_is_input_channel(audio_channel_mask_t channel) 829{ 830 if ((channel & ~AUDIO_CHANNEL_IN_ALL) == 0) 831 return channel != 0; 832 else 833 return false; 834} 835 836static inline bool audio_is_output_channel(audio_channel_mask_t channel) 837{ 838 if ((channel & ~AUDIO_CHANNEL_OUT_ALL) == 0) 839 return channel != 0; 840 else 841 return false; 842} 843 844/* Returns the number of channels from an input channel mask, 845 * used in the context of audio input or recording. 846 */ 847static inline uint32_t audio_channel_count_from_in_mask(audio_channel_mask_t channel) 848{ 849 return popcount(channel & AUDIO_CHANNEL_IN_ALL); 850} 851 852/* Returns the number of channels from an output channel mask, 853 * used in the context of audio output or playback. 854 */ 855static inline uint32_t audio_channel_count_from_out_mask(audio_channel_mask_t channel) 856{ 857 return popcount(channel & AUDIO_CHANNEL_OUT_ALL); 858} 859 860/* Derive an output channel mask from a channel count. 861 * This is to be used when the content channel mask is unknown. The 1, 2, 4, 5, 6, 7 and 8 channel 862 * cases are mapped to the standard game/home-theater layouts, but note that 4 is mapped to quad, 863 * and not stereo + FC + mono surround. A channel count of 3 is arbitrarily mapped to stereo + FC 864 * for continuity with stereo. 865 * Returns the matching channel mask, or 0 if the number of channels exceeds that of the 866 * configurations for which a default channel mask is defined. 867 */ 868static inline audio_channel_mask_t audio_channel_out_mask_from_count(uint32_t channel_count) 869{ 870 switch (channel_count) { 871 case 1: 872 return AUDIO_CHANNEL_OUT_MONO; 873 case 2: 874 return AUDIO_CHANNEL_OUT_STEREO; 875 case 3: 876 return (AUDIO_CHANNEL_OUT_STEREO | AUDIO_CHANNEL_OUT_FRONT_CENTER); 877 case 4: // 4.0 878 return AUDIO_CHANNEL_OUT_QUAD; 879 case 5: // 5.0 880 return (AUDIO_CHANNEL_OUT_QUAD | AUDIO_CHANNEL_OUT_FRONT_CENTER); 881 case 6: // 5.1 882 return AUDIO_CHANNEL_OUT_5POINT1; 883 case 7: // 6.1 884 return (AUDIO_CHANNEL_OUT_5POINT1 | AUDIO_CHANNEL_OUT_BACK_CENTER); 885 case 8: 886 return AUDIO_CHANNEL_OUT_7POINT1; 887 default: 888 return 0; 889 } 890} 891 892/* Similar to above, but for input. Currently handles only mono and stereo. */ 893static inline audio_channel_mask_t audio_channel_in_mask_from_count(uint32_t channel_count) 894{ 895 switch (channel_count) { 896 case 1: 897 return AUDIO_CHANNEL_IN_MONO; 898 case 2: 899 return AUDIO_CHANNEL_IN_STEREO; 900 default: 901 return 0; 902 } 903} 904 905static inline bool audio_is_valid_format(audio_format_t format) 906{ 907 switch (format & AUDIO_FORMAT_MAIN_MASK) { 908 case AUDIO_FORMAT_PCM: 909 switch (format) { 910 case AUDIO_FORMAT_PCM_16_BIT: 911 case AUDIO_FORMAT_PCM_8_BIT: 912 case AUDIO_FORMAT_PCM_32_BIT: 913 case AUDIO_FORMAT_PCM_8_24_BIT: 914 case AUDIO_FORMAT_PCM_FLOAT: 915 case AUDIO_FORMAT_PCM_24_BIT_PACKED: 916 return true; 917 default: 918 return false; 919 } 920 /* not reached */ 921 case AUDIO_FORMAT_MP3: 922 case AUDIO_FORMAT_AMR_NB: 923 case AUDIO_FORMAT_AMR_WB: 924 case AUDIO_FORMAT_AAC: 925 case AUDIO_FORMAT_HE_AAC_V1: 926 case AUDIO_FORMAT_HE_AAC_V2: 927 case AUDIO_FORMAT_VORBIS: 928 return true; 929 default: 930 return false; 931 } 932} 933 934static inline bool audio_is_linear_pcm(audio_format_t format) 935{ 936 return ((format & AUDIO_FORMAT_MAIN_MASK) == AUDIO_FORMAT_PCM); 937} 938 939static inline size_t audio_bytes_per_sample(audio_format_t format) 940{ 941 size_t size = 0; 942 943 switch (format) { 944 case AUDIO_FORMAT_PCM_32_BIT: 945 case AUDIO_FORMAT_PCM_8_24_BIT: 946 size = sizeof(int32_t); 947 break; 948 case AUDIO_FORMAT_PCM_24_BIT_PACKED: 949 size = sizeof(uint8_t) * 3; 950 break; 951 case AUDIO_FORMAT_PCM_16_BIT: 952 size = sizeof(int16_t); 953 break; 954 case AUDIO_FORMAT_PCM_8_BIT: 955 size = sizeof(uint8_t); 956 break; 957 case AUDIO_FORMAT_PCM_FLOAT: 958 size = sizeof(float); 959 break; 960 default: 961 break; 962 } 963 return size; 964} 965 966__END_DECLS 967 968#endif // ANDROID_AUDIO_CORE_H 969