1 /* 2 * Copyright (C) 2016 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 #ifndef OBOE_DEFINITIONS_H 18 #define OBOE_DEFINITIONS_H 19 20 #include <cstdint> 21 #include <type_traits> 22 23 // Oboe needs to be able to build on old NDKs so we use hard coded constants. 24 // The correctness of these constants is verified in "aaudio/AAudioLoader.cpp". 25 26 namespace oboe { 27 28 /** 29 * Represents any attribute, property or value which hasn't been specified. 30 */ 31 constexpr int32_t kUnspecified = 0; 32 33 // TODO: Investigate using std::chrono 34 /** 35 * The number of nanoseconds in a microsecond. 1,000. 36 */ 37 constexpr int64_t kNanosPerMicrosecond = 1000; 38 39 /** 40 * The number of nanoseconds in a millisecond. 1,000,000. 41 */ 42 constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000; 43 44 /** 45 * The number of milliseconds in a second. 1,000. 46 */ 47 constexpr int64_t kMillisPerSecond = 1000; 48 49 /** 50 * The number of nanoseconds in a second. 1,000,000,000. 51 */ 52 constexpr int64_t kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond; 53 54 /** 55 * The state of the audio stream. 56 */ 57 enum class StreamState : int32_t { // aaudio_stream_state_t 58 Uninitialized = 0, // AAUDIO_STREAM_STATE_UNINITIALIZED, 59 Unknown = 1, // AAUDIO_STREAM_STATE_UNKNOWN, 60 Open = 2, // AAUDIO_STREAM_STATE_OPEN, 61 Starting = 3, // AAUDIO_STREAM_STATE_STARTING, 62 Started = 4, // AAUDIO_STREAM_STATE_STARTED, 63 Pausing = 5, // AAUDIO_STREAM_STATE_PAUSING, 64 Paused = 6, // AAUDIO_STREAM_STATE_PAUSED, 65 Flushing = 7, // AAUDIO_STREAM_STATE_FLUSHING, 66 Flushed = 8, // AAUDIO_STREAM_STATE_FLUSHED, 67 Stopping = 9, // AAUDIO_STREAM_STATE_STOPPING, 68 Stopped = 10, // AAUDIO_STREAM_STATE_STOPPED, 69 Closing = 11, // AAUDIO_STREAM_STATE_CLOSING, 70 Closed = 12, // AAUDIO_STREAM_STATE_CLOSED, 71 Disconnected = 13, // AAUDIO_STREAM_STATE_DISCONNECTED, 72 }; 73 74 /** 75 * The direction of the stream. 76 */ 77 enum class Direction : int32_t { // aaudio_direction_t 78 79 /** 80 * Used for playback. 81 */ 82 Output = 0, // AAUDIO_DIRECTION_OUTPUT, 83 84 /** 85 * Used for recording. 86 */ 87 Input = 1, // AAUDIO_DIRECTION_INPUT, 88 }; 89 90 /** 91 * The format of audio samples. 92 */ 93 enum class AudioFormat : int32_t { // aaudio_format_t 94 /** 95 * Invalid format. 96 */ 97 Invalid = -1, // AAUDIO_FORMAT_INVALID, 98 99 /** 100 * Unspecified format. Format will be decided by Oboe. 101 * When calling getHardwareFormat(), this will be returned if 102 * the API is not supported. 103 */ 104 Unspecified = 0, // AAUDIO_FORMAT_UNSPECIFIED, 105 106 /** 107 * Signed 16-bit integers. 108 */ 109 I16 = 1, // AAUDIO_FORMAT_PCM_I16, 110 111 /** 112 * Single precision floating point. 113 * 114 * This is the recommended format for most applications. 115 * But note that the use of Float may prevent the opening of 116 * a low-latency input path on OpenSL ES or Legacy AAudio streams. 117 */ 118 Float = 2, // AAUDIO_FORMAT_PCM_FLOAT, 119 120 /** 121 * Signed 24-bit integers, packed into 3 bytes. 122 * 123 * Note that the use of this format does not guarantee that 124 * the full precision will be provided. The underlying device may 125 * be using I16 format. 126 * 127 * Added in API 31 (S). 128 */ 129 I24 = 3, // AAUDIO_FORMAT_PCM_I24_PACKED 130 131 /** 132 * Signed 32-bit integers. 133 * 134 * Note that the use of this format does not guarantee that 135 * the full precision will be provided. The underlying device may 136 * be using I16 format. 137 * 138 * Added in API 31 (S). 139 */ 140 I32 = 4, // AAUDIO_FORMAT_PCM_I32 141 142 /** 143 * This format is used for compressed audio wrapped in IEC61937 for HDMI 144 * or S/PDIF passthrough. 145 * 146 * Unlike PCM playback, the Android framework is not able to do format 147 * conversion for IEC61937. In that case, when IEC61937 is requested, sampling 148 * rate and channel count or channel mask must be specified. Otherwise, it may 149 * fail when opening the stream. Apps are able to get the correct configuration 150 * for the playback by calling AudioManager#getDevices(int). 151 * 152 * Available since API 34 (U). 153 */ 154 IEC61937 = 5, // AAUDIO_FORMAT_IEC61937 155 156 /** 157 * This format is used for audio compressed in MP3 format. 158 */ 159 MP3 = 6, // AAUDIO_FORMAT_MP3 160 161 /** 162 * This format is used for audio compressed in AAC LC format. 163 */ 164 AAC_LC, // AAUDIO_FORMAT_AAC_LC 165 166 /** 167 * This format is used for audio compressed in AAC HE V1 format. 168 */ 169 AAC_HE_V1, // AAUDIO_FORMAT_AAC_HE_V1, 170 171 /** 172 * This format is used for audio compressed in AAC HE V2 format. 173 */ 174 AAC_HE_V2, // AAUDIO_FORMAT_AAC_HE_V2 175 176 /** 177 * This format is used for audio compressed in AAC ELD format. 178 */ 179 AAC_ELD, // AAUDIO_FORMAT_AAC_ELD 180 181 /** 182 * This format is used for audio compressed in AAC XHE format. 183 */ 184 AAC_XHE, // AAUDIO_FORMAT_AAC_XHE 185 186 /** 187 * This format is used for audio compressed in OPUS. 188 */ 189 OPUS, // AAUDIO_FORMAT_OPUS 190 }; 191 192 /** 193 * The result of an audio callback. 194 */ 195 enum class DataCallbackResult : int32_t { // aaudio_data_callback_result_t 196 // Indicates to the caller that the callbacks should continue. 197 Continue = 0, // AAUDIO_CALLBACK_RESULT_CONTINUE, 198 199 // Indicates to the caller that the callbacks should stop immediately. 200 Stop = 1, // AAUDIO_CALLBACK_RESULT_STOP, 201 }; 202 203 /** 204 * The result of an operation. All except the `OK` result indicates that an error occurred. 205 * The `Result` can be converted into a human readable string using `convertToText`. 206 */ 207 enum class Result : int32_t { // aaudio_result_t 208 OK = 0, // AAUDIO_OK 209 ErrorBase = -900, // AAUDIO_ERROR_BASE, 210 ErrorDisconnected = -899, // AAUDIO_ERROR_DISCONNECTED, 211 ErrorIllegalArgument = -898, // AAUDIO_ERROR_ILLEGAL_ARGUMENT, 212 ErrorInternal = -896, // AAUDIO_ERROR_INTERNAL, 213 ErrorInvalidState = -895, // AAUDIO_ERROR_INVALID_STATE, 214 ErrorInvalidHandle = -892, // AAUDIO_ERROR_INVALID_HANDLE, 215 ErrorUnimplemented = -890, // AAUDIO_ERROR_UNIMPLEMENTED, 216 ErrorUnavailable = -889, // AAUDIO_ERROR_UNAVAILABLE, 217 ErrorNoFreeHandles = -888, // AAUDIO_ERROR_NO_FREE_HANDLES, 218 ErrorNoMemory = -887, // AAUDIO_ERROR_NO_MEMORY, 219 ErrorNull = -886, // AAUDIO_ERROR_NULL, 220 ErrorTimeout = -885, // AAUDIO_ERROR_TIMEOUT, 221 ErrorWouldBlock = -884, // AAUDIO_ERROR_WOULD_BLOCK, 222 ErrorInvalidFormat = -883, // AAUDIO_ERROR_INVALID_FORMAT, 223 ErrorOutOfRange = -882, // AAUDIO_ERROR_OUT_OF_RANGE, 224 ErrorNoService = -881, // AAUDIO_ERROR_NO_SERVICE, 225 ErrorInvalidRate = -880, // AAUDIO_ERROR_INVALID_RATE, 226 // Reserved for future AAudio result types 227 Reserved1, 228 Reserved2, 229 Reserved3, 230 Reserved4, 231 Reserved5, 232 Reserved6, 233 Reserved7, 234 Reserved8, 235 Reserved9, 236 Reserved10, 237 ErrorClosed = -869, 238 }; 239 240 /** 241 * The sharing mode of the audio stream. 242 */ 243 enum class SharingMode : int32_t { // aaudio_sharing_mode_t 244 245 /** 246 * This will be the only stream using a particular source or sink. 247 * This mode will provide the lowest possible latency. 248 * You should close EXCLUSIVE streams immediately when you are not using them. 249 * 250 * If you do not need the lowest possible latency then we recommend using Shared, 251 * which is the default. 252 */ 253 Exclusive = 0, // AAUDIO_SHARING_MODE_EXCLUSIVE, 254 255 /** 256 * Multiple applications can share the same device. 257 * The data from output streams will be mixed by the audio service. 258 * The data for input streams will be distributed by the audio service. 259 * 260 * This will have higher latency than the EXCLUSIVE mode. 261 */ 262 Shared = 1, // AAUDIO_SHARING_MODE_SHARED, 263 }; 264 265 /** 266 * The performance mode of the audio stream. 267 */ 268 enum class PerformanceMode : int32_t { // aaudio_performance_mode_t 269 270 /** 271 * No particular performance needs. Default. 272 */ 273 None = 10, // AAUDIO_PERFORMANCE_MODE_NONE, 274 275 /** 276 * Extending battery life is most important. 277 */ 278 PowerSaving = 11, // AAUDIO_PERFORMANCE_MODE_POWER_SAVING, 279 280 /** 281 * Reducing latency is most important. 282 */ 283 LowLatency = 12, // AAUDIO_PERFORMANCE_MODE_LOW_LATENCY 284 285 /** 286 * Extending battery life is more important than low latency. 287 * 288 * This mode is not supported in input streams. 289 * This mode will play through the offloaded audio path to save battery life. 290 * With the offload playback, the default data callback size will be large and it 291 * allows data feeding thread to sleep longer time after sending enough data. 292 */ 293 POWER_SAVING_OFFLOADED = 13, // AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED 294 }; 295 296 /** 297 * The underlying audio API used by the audio stream. 298 */ 299 enum class AudioApi : int32_t { 300 /** 301 * Try to use AAudio. If not available then use OpenSL ES. 302 */ 303 Unspecified = kUnspecified, 304 305 /** 306 * Use OpenSL ES. 307 * Note that OpenSL ES is deprecated in Android 13, API 30 and above. 308 */ 309 OpenSLES, 310 311 /** 312 * Try to use AAudio. Fail if unavailable. 313 * AAudio was first supported in Android 8, API 26 and above. 314 * It is only recommended for API 27 and above. 315 */ 316 AAudio 317 }; 318 319 /** 320 * Specifies the quality of the sample rate conversion performed by Oboe. 321 * Higher quality will require more CPU load. 322 * Higher quality conversion will probably be implemented using a sinc based resampler. 323 */ 324 enum class SampleRateConversionQuality : int32_t { 325 /** 326 * No conversion by Oboe. Underlying APIs may still do conversion. 327 */ 328 None, 329 /** 330 * Fastest conversion but may not sound great. 331 * This may be implemented using bilinear interpolation. 332 */ 333 Fastest, 334 /** 335 * Low quality conversion with 8 taps. 336 */ 337 Low, 338 /** 339 * Medium quality conversion with 16 taps. 340 */ 341 Medium, 342 /** 343 * High quality conversion with 32 taps. 344 */ 345 High, 346 /** 347 * Highest quality conversion, which may be expensive in terms of CPU. 348 */ 349 Best, 350 }; 351 352 /** 353 * The Usage attribute expresses *why* you are playing a sound, what is this sound used for. 354 * This information is used by certain platforms or routing policies 355 * to make more refined volume or routing decisions. 356 * 357 * Note that these match the equivalent values in AudioAttributes in the Android Java API. 358 * 359 * This attribute only has an effect on Android API 28+. 360 */ 361 enum class Usage : int32_t { // aaudio_usage_t 362 /** 363 * Use this for streaming media, music performance, video, podcasts, etcetera. 364 */ 365 Media = 1, // AAUDIO_USAGE_MEDIA 366 367 /** 368 * Use this for voice over IP, telephony, etcetera. 369 */ 370 VoiceCommunication = 2, // AAUDIO_USAGE_VOICE_COMMUNICATION 371 372 /** 373 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera. 374 */ 375 VoiceCommunicationSignalling = 3, // AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING 376 377 /** 378 * Use this to demand the users attention. 379 */ 380 Alarm = 4, // AAUDIO_USAGE_ALARM 381 382 /** 383 * Use this for notifying the user when a message has arrived or some 384 * other background event has occured. 385 */ 386 Notification = 5, // AAUDIO_USAGE_NOTIFICATION 387 388 /** 389 * Use this when the phone rings. 390 */ 391 NotificationRingtone = 6, // AAUDIO_USAGE_NOTIFICATION_RINGTONE 392 393 /** 394 * Use this to attract the users attention when, for example, the battery is low. 395 */ 396 NotificationEvent = 10, // AAUDIO_USAGE_NOTIFICATION_EVENT 397 398 /** 399 * Use this for screen readers, etcetera. 400 */ 401 AssistanceAccessibility = 11, // AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY 402 403 /** 404 * Use this for driving or navigation directions. 405 */ 406 AssistanceNavigationGuidance = 12, // AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE 407 408 /** 409 * Use this for user interface sounds, beeps, etcetera. 410 */ 411 AssistanceSonification = 13, // AAUDIO_USAGE_ASSISTANCE_SONIFICATION 412 413 /** 414 * Use this for game audio and sound effects. 415 */ 416 Game = 14, // AAUDIO_USAGE_GAME 417 418 /** 419 * Use this for audio responses to user queries, audio instructions or help utterances. 420 */ 421 Assistant = 16, // AAUDIO_USAGE_ASSISTANT 422 }; 423 424 425 /** 426 * The ContentType attribute describes *what* you are playing. 427 * It expresses the general category of the content. This information is optional. 428 * But in case it is known (for instance {@link Movie} for a 429 * movie streaming service or {@link Speech} for 430 * an audio book application) this information might be used by the audio framework to 431 * enforce audio focus. 432 * 433 * Note that these match the equivalent values in AudioAttributes in the Android Java API. 434 * 435 * This attribute only has an effect on Android API 28+. 436 */ 437 enum ContentType : int32_t { // aaudio_content_type_t 438 439 /** 440 * Use this for spoken voice, audio books, etcetera. 441 */ 442 Speech = 1, // AAUDIO_CONTENT_TYPE_SPEECH 443 444 /** 445 * Use this for pre-recorded or live music. 446 */ 447 Music = 2, // AAUDIO_CONTENT_TYPE_MUSIC 448 449 /** 450 * Use this for a movie or video soundtrack. 451 */ 452 Movie = 3, // AAUDIO_CONTENT_TYPE_MOVIE 453 454 /** 455 * Use this for sound is designed to accompany a user action, 456 * such as a click or beep sound made when the user presses a button. 457 */ 458 Sonification = 4, // AAUDIO_CONTENT_TYPE_SONIFICATION 459 }; 460 461 /** 462 * Defines the audio source. 463 * An audio source defines both a default physical source of audio signal, and a recording 464 * configuration. 465 * 466 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API. 467 * 468 * This attribute only has an effect on Android API 28+. 469 */ 470 enum InputPreset : int32_t { // aaudio_input_preset_t 471 /** 472 * Use this preset when other presets do not apply. 473 */ 474 Generic = 1, // AAUDIO_INPUT_PRESET_GENERIC 475 476 /** 477 * Use this preset when recording video. 478 */ 479 Camcorder = 5, // AAUDIO_INPUT_PRESET_CAMCORDER 480 481 /** 482 * Use this preset when doing speech recognition. 483 */ 484 VoiceRecognition = 6, // AAUDIO_INPUT_PRESET_VOICE_RECOGNITION 485 486 /** 487 * Use this preset when doing telephony or voice messaging. 488 */ 489 VoiceCommunication = 7, // AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION 490 491 /** 492 * Use this preset to obtain an input with no effects. 493 * Note that this input will not have automatic gain control 494 * so the recorded volume may be very low. 495 */ 496 Unprocessed = 9, // AAUDIO_INPUT_PRESET_UNPROCESSED 497 498 /** 499 * Use this preset for capturing audio meant to be processed in real time 500 * and played back for live performance (e.g karaoke). 501 * The capture path will minimize latency and coupling with playback path. 502 */ 503 VoicePerformance = 10, // AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE 504 505 }; 506 507 /** 508 * This attribute can be used to allocate a session ID to the audio stream. 509 * 510 * This attribute only has an effect on Android API 28+. 511 */ 512 enum SessionId { 513 /** 514 * Do not allocate a session ID. 515 * Effects cannot be used with this stream. 516 * Default. 517 */ 518 None = -1, // AAUDIO_SESSION_ID_NONE 519 520 /** 521 * Allocate a session ID that can be used to attach and control 522 * effects using the Java AudioEffects API. 523 * Note that the use of this flag may result in higher latency. 524 * 525 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE. 526 */ 527 Allocate = 0, // AAUDIO_SESSION_ID_ALLOCATE 528 }; 529 530 /** 531 * The channel count of the audio stream. The underlying type is `int32_t`. 532 * Use of this enum is convenient to avoid "magic" 533 * numbers when specifying the channel count. 534 * 535 * For example, you can write 536 * `builder.setChannelCount(ChannelCount::Stereo)` 537 * rather than `builder.setChannelCount(2)` 538 * 539 */ 540 enum ChannelCount : int32_t { 541 /** 542 * Audio channel count definition, use Mono or Stereo 543 */ 544 Unspecified = kUnspecified, 545 546 /** 547 * Use this for mono audio 548 */ 549 Mono = 1, 550 551 /** 552 * Use this for stereo audio. 553 */ 554 Stereo = 2, 555 }; 556 557 /** 558 * The channel mask of the audio stream. The underlying type is `uint32_t`. 559 * Use of this enum is convenient. 560 * 561 * ChannelMask::Unspecified means this is not specified. 562 * The rest of the enums are channel position masks. 563 * Use the combinations of the channel position masks defined below instead of 564 * using those values directly. 565 * 566 * Channel masks are for input only, output only, or both input and output. 567 * These channel masks are different than those defined in AudioFormat.java. 568 * If an app gets a channel mask from Java API and wants to use it in Oboe, 569 * conversion should be done by the app. 570 */ 571 enum class ChannelMask : uint32_t { // aaudio_channel_mask_t 572 Unspecified = kUnspecified, 573 FrontLeft = 1 << 0, 574 FrontRight = 1 << 1, 575 FrontCenter = 1 << 2, 576 LowFrequency = 1 << 3, 577 BackLeft = 1 << 4, 578 BackRight = 1 << 5, 579 FrontLeftOfCenter = 1 << 6, 580 FrontRightOfCenter = 1 << 7, 581 BackCenter = 1 << 8, 582 SideLeft = 1 << 9, 583 SideRight = 1 << 10, 584 TopCenter = 1 << 11, 585 TopFrontLeft = 1 << 12, 586 TopFrontCenter = 1 << 13, 587 TopFrontRight = 1 << 14, 588 TopBackLeft = 1 << 15, 589 TopBackCenter = 1 << 16, 590 TopBackRight = 1 << 17, 591 TopSideLeft = 1 << 18, 592 TopSideRight = 1 << 19, 593 BottomFrontLeft = 1 << 20, 594 BottomFrontCenter = 1 << 21, 595 BottomFrontRight = 1 << 22, 596 LowFrequency2 = 1 << 23, 597 FrontWideLeft = 1 << 24, 598 FrontWideRight = 1 << 25, 599 600 /** 601 * Supported for Input and Output 602 */ 603 Mono = FrontLeft, 604 605 /** 606 * Supported for Input and Output 607 */ 608 Stereo = FrontLeft | 609 FrontRight, 610 611 /** 612 * Supported for only Output 613 */ 614 CM2Point1 = FrontLeft | 615 FrontRight | 616 LowFrequency, 617 618 /** 619 * Supported for only Output 620 */ 621 Tri = FrontLeft | 622 FrontRight | 623 FrontCenter, 624 625 /** 626 * Supported for only Output 627 */ 628 TriBack = FrontLeft | 629 FrontRight | 630 BackCenter, 631 632 /** 633 * Supported for only Output 634 */ 635 CM3Point1 = FrontLeft | 636 FrontRight | 637 FrontCenter | 638 LowFrequency, 639 640 /** 641 * Supported for Input and Output 642 */ 643 CM2Point0Point2 = FrontLeft | 644 FrontRight | 645 TopSideLeft | 646 TopSideRight, 647 648 /** 649 * Supported for Input and Output 650 */ 651 CM2Point1Point2 = CM2Point0Point2 | 652 LowFrequency, 653 654 /** 655 * Supported for Input and Output 656 */ 657 CM3Point0Point2 = FrontLeft | 658 FrontRight | 659 FrontCenter | 660 TopSideLeft | 661 TopSideRight, 662 663 /** 664 * Supported for Input and Output 665 */ 666 CM3Point1Point2 = CM3Point0Point2 | 667 LowFrequency, 668 669 /** 670 * Supported for only Output 671 */ 672 Quad = FrontLeft | 673 FrontRight | 674 BackLeft | 675 BackRight, 676 677 /** 678 * Supported for only Output 679 */ 680 QuadSide = FrontLeft | 681 FrontRight | 682 SideLeft | 683 SideRight, 684 685 /** 686 * Supported for only Output 687 */ 688 Surround = FrontLeft | 689 FrontRight | 690 FrontCenter | 691 BackCenter, 692 693 /** 694 * Supported for only Output 695 */ 696 Penta = Quad | 697 FrontCenter, 698 699 /** 700 * Supported for Input and Output. aka 5Point1Back 701 */ 702 CM5Point1 = FrontLeft | 703 FrontRight | 704 FrontCenter | 705 LowFrequency | 706 BackLeft | 707 BackRight, 708 709 /** 710 * Supported for only Output 711 */ 712 CM5Point1Side = FrontLeft | 713 FrontRight | 714 FrontCenter | 715 LowFrequency | 716 SideLeft | 717 SideRight, 718 719 /** 720 * Supported for only Output 721 */ 722 CM6Point1 = FrontLeft | 723 FrontRight | 724 FrontCenter | 725 LowFrequency | 726 BackLeft | 727 BackRight | 728 BackCenter, 729 730 /** 731 * Supported for only Output 732 */ 733 CM7Point1 = CM5Point1 | 734 SideLeft | 735 SideRight, 736 737 /** 738 * Supported for only Output 739 */ 740 CM5Point1Point2 = CM5Point1 | 741 TopSideLeft | 742 TopSideRight, 743 744 /** 745 * Supported for only Output 746 */ 747 CM5Point1Point4 = CM5Point1 | 748 TopFrontLeft | 749 TopFrontRight | 750 TopBackLeft | 751 TopBackRight, 752 753 /** 754 * Supported for only Output 755 */ 756 CM7Point1Point2 = CM7Point1 | 757 TopSideLeft | 758 TopSideRight, 759 760 /** 761 * Supported for only Output 762 */ 763 CM7Point1Point4 = CM7Point1 | 764 TopFrontLeft | 765 TopFrontRight | 766 TopBackLeft | 767 TopBackRight, 768 769 /** 770 * Supported for only Output 771 */ 772 CM9Point1Point4 = CM7Point1Point4 | 773 FrontWideLeft | 774 FrontWideRight, 775 776 /** 777 * Supported for only Output 778 */ 779 CM9Point1Point6 = CM9Point1Point4 | 780 TopSideLeft | 781 TopSideRight, 782 783 /** 784 * Supported for only Input 785 */ 786 FrontBack = FrontCenter | 787 BackCenter, 788 }; 789 790 /** 791 * The spatialization behavior of the audio stream. 792 */ 793 enum class SpatializationBehavior : int32_t { 794 795 /** 796 * Constant indicating that the spatialization behavior is not specified. 797 */ 798 Unspecified = kUnspecified, 799 800 /** 801 * Constant indicating the audio content associated with these attributes will follow the 802 * default platform behavior with regards to which content will be spatialized or not. 803 */ 804 Auto = 1, 805 806 /** 807 * Constant indicating the audio content associated with these attributes should never 808 * be spatialized. 809 */ 810 Never = 2, 811 }; 812 813 /** 814 * The PrivacySensitiveMode attribute determines whether an input stream can be shared 815 * with another privileged app, for example the Assistant. 816 * 817 * This allows to override the default behavior tied to the audio source (e.g 818 * InputPreset::VoiceCommunication is private by default but InputPreset::Unprocessed is not). 819 */ 820 enum class PrivacySensitiveMode : int32_t { 821 822 /** 823 * When not explicitly requested, set privacy sensitive mode according to input preset: 824 * communication and camcorder captures are considered privacy sensitive by default. 825 */ 826 Unspecified = kUnspecified, 827 828 /** 829 * Privacy sensitive mode disabled. 830 */ 831 Disabled = 1, 832 833 /** 834 * Privacy sensitive mode enabled. 835 */ 836 Enabled = 2, 837 }; 838 839 /** 840 * Specifies whether audio may or may not be captured by other apps or the system for an 841 * output stream. 842 * 843 * Note that these match the equivalent values in AudioAttributes in the Android Java API. 844 * 845 * Added in API level 29 for AAudio. 846 */ 847 enum class AllowedCapturePolicy : int32_t { 848 /** 849 * When not explicitly requested, set privacy sensitive mode according to the Usage. 850 * This should behave similarly to setting AllowedCapturePolicy::All. 851 */ 852 Unspecified = kUnspecified, 853 /** 854 * Indicates that the audio may be captured by any app. 855 * 856 * For privacy, the following Usages can not be recorded: VoiceCommunication*, 857 * Notification*, Assistance* and Assistant. 858 * 859 * On Android Q, only Usage::Game and Usage::Media may be captured. 860 * 861 * See ALLOW_CAPTURE_BY_ALL in the AudioAttributes Java API. 862 */ 863 All = 1, 864 /** 865 * Indicates that the audio may only be captured by system apps. 866 * 867 * System apps can capture for many purposes like accessibility, user guidance... 868 * but have strong restriction. See ALLOW_CAPTURE_BY_SYSTEM in the AudioAttributes Java API 869 * for what the system apps can do with the capture audio. 870 */ 871 System = 2, 872 /** 873 * Indicates that the audio may not be recorded by any app, even if it is a system app. 874 * 875 * It is encouraged to use AllowedCapturePolicy::System instead of this value as system apps 876 * provide significant and useful features for the user (eg. accessibility). 877 * See ALLOW_CAPTURE_BY_NONE in the AudioAttributes Java API 878 */ 879 None = 3, 880 }; 881 882 /** 883 * Audio device type. 884 * 885 * Note that these match the device types defined in android/media/AudioDeviceInfo.java 886 * and the definitions of AAudio_DeviceType in AAudio.h. 887 * 888 * Added in API level 36 for AAudio. 889 */ 890 enum class DeviceType : int32_t { 891 /** 892 * A device type describing the attached earphone speaker. 893 */ 894 BuiltinEarpiece = 1, 895 896 /** 897 * A device type describing the speaker system (i.e. a mono speaker or stereo speakers) 898 * built in a device. 899 */ 900 BuiltinSpeaker = 2, 901 902 /** 903 * A device type describing a headset, which is the combination of a headphones and 904 * microphone. 905 */ 906 WiredHeadset = 3, 907 908 /** 909 * A device type describing a pair of wired headphones. 910 */ 911 WiredHeadphones = 4, 912 913 /** 914 * A device type describing an analog line-level connection. 915 */ 916 LineAnalog = 5, 917 918 /** 919 * A device type describing a digital line connection (e.g. SPDIF). 920 */ 921 LineDigital = 6, 922 923 /** 924 * A device type describing a Bluetooth device typically used for telephony. 925 */ 926 BluetoothSco = 7, 927 928 /** 929 * A device type describing a Bluetooth device supporting the A2DP profile. 930 */ 931 BluetoothA2dp = 8, 932 933 /** 934 * A device type describing an HDMI connection . 935 */ 936 Hdmi = 9, 937 938 /** 939 * A device type describing the Audio Return Channel of an HDMI connection. 940 */ 941 HdmiArc = 10, 942 943 /** 944 * A device type describing a USB audio device. 945 */ 946 UsbDevice = 11, 947 948 /** 949 * A device type describing a USB audio device in accessory mode. 950 */ 951 UsbAccessory = 12, 952 953 /** 954 * A device type describing the audio device associated with a dock. 955 */ 956 Dock = 13, 957 958 /** 959 * A device type associated with the transmission of audio signals over FM. 960 */ 961 FM = 14, 962 963 /** 964 * A device type describing the microphone(s) built in a device. 965 */ 966 BuiltinMic = 15, 967 968 /** 969 * A device type for accessing the audio content transmitted over FM. 970 */ 971 FMTuner = 16, 972 973 /** 974 * A device type for accessing the audio content transmitted over the TV tuner system. 975 */ 976 TVTuner = 17, 977 978 /** 979 * A device type describing the transmission of audio signals over the telephony network. 980 */ 981 Telephony = 18, 982 983 /** 984 * A device type describing the auxiliary line-level connectors. 985 */ 986 AuxLine = 19, 987 988 /** 989 * A device type connected over IP. 990 */ 991 IP = 20, 992 993 /** 994 * A type-agnostic device used for communication with external audio systems. 995 */ 996 Bus = 21, 997 998 /** 999 * A device type describing a USB audio headset. 1000 */ 1001 UsbHeadset = 22, 1002 1003 /** 1004 * A device type describing a Hearing Aid. 1005 */ 1006 HearingAid = 23, 1007 1008 /** 1009 * A device type describing the speaker system (i.e. a mono speaker or stereo speakers) 1010 * built in a device, that is specifically tuned for outputting sounds like notifications 1011 * and alarms (i.e. sounds the user couldn't necessarily anticipate). 1012 * <p>Note that this physical audio device may be the same as {@link #TYPE_BUILTIN_SPEAKER} 1013 * but is driven differently to safely accommodate the different use case.</p> 1014 */ 1015 BuiltinSpeakerSafe = 24, 1016 1017 /** 1018 * A device type for rerouting audio within the Android framework between mixes and 1019 * system applications. 1020 */ 1021 RemoteSubmix = 25, 1022 /** 1023 * A device type describing a Bluetooth Low Energy (BLE) audio headset or headphones. 1024 * Headphones are grouped with headsets when the device is a sink: 1025 * the features of headsets and headphones with regard to playback are the same. 1026 */ 1027 BleHeadset = 26, 1028 1029 /** 1030 * A device type describing a Bluetooth Low Energy (BLE) audio speaker. 1031 */ 1032 BleSpeaker = 27, 1033 1034 /** 1035 * A device type describing the Enhanced Audio Return Channel of an HDMI connection. 1036 */ 1037 HdmiEarc = 29, 1038 1039 /** 1040 * A device type describing a Bluetooth Low Energy (BLE) broadcast group. 1041 */ 1042 BleBroadcast = 30, 1043 1044 /** 1045 * A device type describing the audio device associated with a dock using an 1046 * analog connection. 1047 */ 1048 DockAnalog = 31 1049 }; 1050 1051 /** 1052 * MMAP policy is defined to describe how aaudio MMAP will be used. 1053 * 1054 * Added in API level 36. 1055 */ 1056 enum class MMapPolicy : int32_t { 1057 /** 1058 * When MMAP policy is not specified or the querying API is not supported. 1059 */ 1060 Unspecified = kUnspecified, 1061 1062 /** 1063 * AAudio MMAP is disabled and never used. 1064 */ 1065 Never = 1, 1066 1067 /** 1068 * AAudio MMAP support depends on device's availability. It will be used 1069 * when it is possible or fallback to the normal path, where the audio data 1070 * will be delivered via audio framework data pipeline. 1071 */ 1072 Auto, 1073 1074 /** 1075 * AAudio MMAP must be used or fail. 1076 */ 1077 Always 1078 }; 1079 1080 /** 1081 * On API 16 to 26 OpenSL ES will be used. When using OpenSL ES the optimal values for sampleRate and 1082 * framesPerBurst are not known by the native code. 1083 * On API 17+ these values should be obtained from the AudioManager using this code: 1084 * 1085 * <pre><code> 1086 * // Note that this technique only works for built-in speakers and headphones. 1087 * AudioManager myAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 1088 * String sampleRateStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE); 1089 * int defaultSampleRate = Integer.parseInt(sampleRateStr); 1090 * String framesPerBurstStr = myAudioMgr.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER); 1091 * int defaultFramesPerBurst = Integer.parseInt(framesPerBurstStr); 1092 * </code></pre> 1093 * 1094 * It can then be passed down to Oboe through JNI. 1095 * 1096 * AAudio will get the optimal framesPerBurst from the HAL and will ignore this value. 1097 */ 1098 class DefaultStreamValues { 1099 1100 public: 1101 1102 /** The default sample rate to use when opening new audio streams */ 1103 static int32_t SampleRate; 1104 /** The default frames per burst to use when opening new audio streams */ 1105 static int32_t FramesPerBurst; 1106 /** The default channel count to use when opening new audio streams */ 1107 static int32_t ChannelCount; 1108 1109 }; 1110 1111 /** 1112 * The time at which the frame at `position` was presented 1113 */ 1114 struct FrameTimestamp { 1115 int64_t position; // in frames 1116 int64_t timestamp; // in nanoseconds 1117 }; 1118 1119 class OboeGlobals { 1120 public: 1121 areWorkaroundsEnabled()1122 static bool areWorkaroundsEnabled() { 1123 return mWorkaroundsEnabled; 1124 } 1125 1126 /** 1127 * Disable this when writing tests to reproduce bugs in AAudio or OpenSL ES 1128 * that have workarounds in Oboe. 1129 * @param enabled 1130 */ setWorkaroundsEnabled(bool enabled)1131 static void setWorkaroundsEnabled(bool enabled) { 1132 mWorkaroundsEnabled = enabled; 1133 } 1134 1135 private: 1136 static bool mWorkaroundsEnabled; 1137 }; 1138 } // namespace oboe 1139 1140 #endif // OBOE_DEFINITIONS_H 1141