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 /** 18 * @addtogroup Audio 19 * @{ 20 */ 21 22 /** 23 * @file AAudio.h 24 */ 25 26 /** 27 * This is the 'C' API for AAudio. 28 */ 29 #ifndef AAUDIO_AAUDIO_H 30 #define AAUDIO_AAUDIO_H 31 32 #include <time.h> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /** 39 * This is used to represent a value that has not been specified. 40 * For example, an application could use {@link #AAUDIO_UNSPECIFIED} to indicate 41 * that is did not not care what the specific value of a parameter was 42 * and would accept whatever it was given. 43 */ 44 #define AAUDIO_UNSPECIFIED 0 45 46 enum { 47 /** 48 * Audio data will travel out of the device, for example through a speaker. 49 */ 50 AAUDIO_DIRECTION_OUTPUT, 51 52 53 /** 54 * Audio data will travel into the device, for example from a microphone. 55 */ 56 AAUDIO_DIRECTION_INPUT 57 }; 58 typedef int32_t aaudio_direction_t; 59 60 enum { 61 AAUDIO_FORMAT_INVALID = -1, 62 AAUDIO_FORMAT_UNSPECIFIED = 0, 63 64 /** 65 * This format uses the int16_t data type. 66 * The maximum range of the data is -32768 to 32767. 67 */ 68 AAUDIO_FORMAT_PCM_I16, 69 70 /** 71 * This format uses the float data type. 72 * The nominal range of the data is [-1.0f, 1.0f). 73 * Values outside that range may be clipped. 74 * 75 * See also 'floatData' at 76 * https://developer.android.com/reference/android/media/AudioTrack#write(float[],%20int,%20int,%20int) 77 */ 78 AAUDIO_FORMAT_PCM_FLOAT 79 }; 80 typedef int32_t aaudio_format_t; 81 82 /** 83 * These result codes are returned from AAudio functions to indicate success or failure. 84 * Note that error return codes may change in the future so applications should generally 85 * not rely on specific return codes. 86 */ 87 enum { 88 /** 89 * The call was successful. 90 */ 91 AAUDIO_OK, 92 AAUDIO_ERROR_BASE = -900, // TODO review 93 94 /** 95 * The audio device was disconnected. This could occur, for example, when headphones 96 * are plugged in or unplugged. The stream cannot be used after the device is disconnected. 97 * Applications should stop and close the stream. 98 * If this error is received in an error callback then another thread should be 99 * used to stop and close the stream. 100 */ 101 AAUDIO_ERROR_DISCONNECTED, 102 103 /** 104 * An invalid parameter was passed to AAudio. 105 */ 106 AAUDIO_ERROR_ILLEGAL_ARGUMENT, 107 // reserved 108 AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2, 109 110 /** 111 * The requested operation is not appropriate for the current state of AAudio. 112 */ 113 AAUDIO_ERROR_INVALID_STATE, 114 // reserved 115 // reserved 116 /* The server rejected the handle used to identify the stream. 117 */ 118 AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3, 119 // reserved 120 121 /** 122 * The function is not implemented for this stream. 123 */ 124 AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2, 125 126 /** 127 * A resource or information is unavailable. 128 * This could occur when an application tries to open too many streams, 129 * or a timestamp is not available. 130 */ 131 AAUDIO_ERROR_UNAVAILABLE, 132 AAUDIO_ERROR_NO_FREE_HANDLES, 133 134 /** 135 * Memory could not be allocated. 136 */ 137 AAUDIO_ERROR_NO_MEMORY, 138 139 /** 140 * A NULL pointer was passed to AAudio. 141 * Or a NULL pointer was detected internally. 142 */ 143 AAUDIO_ERROR_NULL, 144 145 /** 146 * An operation took longer than expected. 147 */ 148 AAUDIO_ERROR_TIMEOUT, 149 AAUDIO_ERROR_WOULD_BLOCK, 150 151 /** 152 * The requested data format is not supported. 153 */ 154 AAUDIO_ERROR_INVALID_FORMAT, 155 156 /** 157 * A requested was out of range. 158 */ 159 AAUDIO_ERROR_OUT_OF_RANGE, 160 161 /** 162 * The audio service was not available. 163 */ 164 AAUDIO_ERROR_NO_SERVICE, 165 166 /** 167 * The requested sample rate was not supported. 168 */ 169 AAUDIO_ERROR_INVALID_RATE 170 }; 171 typedef int32_t aaudio_result_t; 172 173 enum 174 { 175 AAUDIO_STREAM_STATE_UNINITIALIZED = 0, 176 AAUDIO_STREAM_STATE_UNKNOWN, 177 AAUDIO_STREAM_STATE_OPEN, 178 AAUDIO_STREAM_STATE_STARTING, 179 AAUDIO_STREAM_STATE_STARTED, 180 AAUDIO_STREAM_STATE_PAUSING, 181 AAUDIO_STREAM_STATE_PAUSED, 182 AAUDIO_STREAM_STATE_FLUSHING, 183 AAUDIO_STREAM_STATE_FLUSHED, 184 AAUDIO_STREAM_STATE_STOPPING, 185 AAUDIO_STREAM_STATE_STOPPED, 186 AAUDIO_STREAM_STATE_CLOSING, 187 AAUDIO_STREAM_STATE_CLOSED, 188 AAUDIO_STREAM_STATE_DISCONNECTED 189 }; 190 typedef int32_t aaudio_stream_state_t; 191 192 193 enum { 194 /** 195 * This will be the only stream using a particular source or sink. 196 * This mode will provide the lowest possible latency. 197 * You should close EXCLUSIVE streams immediately when you are not using them. 198 */ 199 AAUDIO_SHARING_MODE_EXCLUSIVE, 200 /** 201 * Multiple applications will be mixed by the AAudio Server. 202 * This will have higher latency than the EXCLUSIVE mode. 203 */ 204 AAUDIO_SHARING_MODE_SHARED 205 }; 206 typedef int32_t aaudio_sharing_mode_t; 207 208 209 enum { 210 /** 211 * No particular performance needs. Default. 212 */ 213 AAUDIO_PERFORMANCE_MODE_NONE = 10, 214 215 /** 216 * Extending battery life is more important than low latency. 217 * 218 * This mode is not supported in input streams. 219 * For input, mode NONE will be used if this is requested. 220 */ 221 AAUDIO_PERFORMANCE_MODE_POWER_SAVING, 222 223 /** 224 * Reducing latency is more important than battery life. 225 */ 226 AAUDIO_PERFORMANCE_MODE_LOW_LATENCY 227 }; 228 typedef int32_t aaudio_performance_mode_t; 229 230 /** 231 * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for. 232 * This information is used by certain platforms or routing policies 233 * to make more refined volume or routing decisions. 234 * 235 * Note that these match the equivalent values in {@link android.media.AudioAttributes} 236 * in the Android Java API. 237 * 238 * Added in API level 28. 239 */ 240 enum { 241 /** 242 * Use this for streaming media, music performance, video, podcasts, etcetera. 243 */ 244 AAUDIO_USAGE_MEDIA = 1, 245 246 /** 247 * Use this for voice over IP, telephony, etcetera. 248 */ 249 AAUDIO_USAGE_VOICE_COMMUNICATION = 2, 250 251 /** 252 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera. 253 */ 254 AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3, 255 256 /** 257 * Use this to demand the users attention. 258 */ 259 AAUDIO_USAGE_ALARM = 4, 260 261 /** 262 * Use this for notifying the user when a message has arrived or some 263 * other background event has occured. 264 */ 265 AAUDIO_USAGE_NOTIFICATION = 5, 266 267 /** 268 * Use this when the phone rings. 269 */ 270 AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6, 271 272 /** 273 * Use this to attract the users attention when, for example, the battery is low. 274 */ 275 AAUDIO_USAGE_NOTIFICATION_EVENT = 10, 276 277 /** 278 * Use this for screen readers, etcetera. 279 */ 280 AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11, 281 282 /** 283 * Use this for driving or navigation directions. 284 */ 285 AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12, 286 287 /** 288 * Use this for user interface sounds, beeps, etcetera. 289 */ 290 AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13, 291 292 /** 293 * Use this for game audio and sound effects. 294 */ 295 AAUDIO_USAGE_GAME = 14, 296 297 /** 298 * Use this for audio responses to user queries, audio instructions or help utterances. 299 */ 300 AAUDIO_USAGE_ASSISTANT = 16 301 }; 302 typedef int32_t aaudio_usage_t; 303 304 /** 305 * The CONTENT_TYPE attribute describes "what" you are playing. 306 * It expresses the general category of the content. This information is optional. 307 * But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a 308 * movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for 309 * an audio book application) this information might be used by the audio framework to 310 * enforce audio focus. 311 * 312 * Note that these match the equivalent values in {@link android.media.AudioAttributes} 313 * in the Android Java API. 314 * 315 * Added in API level 28. 316 */ 317 enum { 318 319 /** 320 * Use this for spoken voice, audio books, etcetera. 321 */ 322 AAUDIO_CONTENT_TYPE_SPEECH = 1, 323 324 /** 325 * Use this for pre-recorded or live music. 326 */ 327 AAUDIO_CONTENT_TYPE_MUSIC = 2, 328 329 /** 330 * Use this for a movie or video soundtrack. 331 */ 332 AAUDIO_CONTENT_TYPE_MOVIE = 3, 333 334 /** 335 * Use this for sound is designed to accompany a user action, 336 * such as a click or beep sound made when the user presses a button. 337 */ 338 AAUDIO_CONTENT_TYPE_SONIFICATION = 4 339 }; 340 typedef int32_t aaudio_content_type_t; 341 342 /** 343 * Defines the audio source. 344 * An audio source defines both a default physical source of audio signal, and a recording 345 * configuration. 346 * 347 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API. 348 * 349 * Added in API level 28. 350 */ 351 enum { 352 /** 353 * Use this preset when other presets do not apply. 354 */ 355 AAUDIO_INPUT_PRESET_GENERIC = 1, 356 357 /** 358 * Use this preset when recording video. 359 */ 360 AAUDIO_INPUT_PRESET_CAMCORDER = 5, 361 362 /** 363 * Use this preset when doing speech recognition. 364 */ 365 AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6, 366 367 /** 368 * Use this preset when doing telephony or voice messaging. 369 */ 370 AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7, 371 372 /** 373 * Use this preset to obtain an input with no effects. 374 * Note that this input will not have automatic gain control 375 * so the recorded volume may be very low. 376 */ 377 AAUDIO_INPUT_PRESET_UNPROCESSED = 9, 378 379 /** 380 * Use this preset for capturing audio meant to be processed in real time 381 * and played back for live performance (e.g karaoke). 382 * The capture path will minimize latency and coupling with playback path. 383 */ 384 AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE = 10, 385 }; 386 typedef int32_t aaudio_input_preset_t; 387 388 /** 389 * Specifying if audio may or may not be captured by other apps or the system. 390 * 391 * Note that these match the equivalent values in {@link android.media.AudioAttributes} 392 * in the Android Java API. 393 * 394 * Added in API level 29. 395 */ 396 enum { 397 /** 398 * Indicates that the audio may be captured by any app. 399 * 400 * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*, 401 * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and {@link #AAUDIO_USAGE_ASSISTANT}. 402 * 403 * On {@link android.os.Build.VERSION_CODES#Q}, this means only {@link #AAUDIO_USAGE_MEDIA} 404 * and {@link #AAUDIO_USAGE_GAME} may be captured. 405 * 406 * See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_ALL}. 407 */ 408 AAUDIO_ALLOW_CAPTURE_BY_ALL = 1, 409 /** 410 * Indicates that the audio may only be captured by system apps. 411 * 412 * System apps can capture for many purposes like accessibility, user guidance... 413 * but have strong restriction. See 414 * {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_SYSTEM} for what the system apps 415 * can do with the capture audio. 416 */ 417 AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2, 418 /** 419 * Indicates that the audio may not be recorded by any app, even if it is a system app. 420 * 421 * It is encouraged to use {@link #AAUDIO_ALLOW_CAPTURE_BY_SYSTEM} instead of this value as system apps 422 * provide significant and useful features for the user (eg. accessibility). 423 * See {@link android.media.AudioAttributes#ALLOW_CAPTURE_BY_NONE}. 424 */ 425 AAUDIO_ALLOW_CAPTURE_BY_NONE = 3, 426 }; 427 428 typedef int32_t aaudio_allowed_capture_policy_t; 429 430 /** 431 * These may be used with AAudioStreamBuilder_setSessionId(). 432 * 433 * Added in API level 28. 434 */ 435 enum { 436 /** 437 * Do not allocate a session ID. 438 * Effects cannot be used with this stream. 439 * Default. 440 * 441 * Added in API level 28. 442 */ 443 AAUDIO_SESSION_ID_NONE = -1, 444 445 /** 446 * Allocate a session ID that can be used to attach and control 447 * effects using the Java AudioEffects API. 448 * Note that using this may result in higher latency. 449 * 450 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE. 451 * 452 * Added in API level 28. 453 */ 454 AAUDIO_SESSION_ID_ALLOCATE = 0, 455 }; 456 typedef int32_t aaudio_session_id_t; 457 458 typedef struct AAudioStreamStruct AAudioStream; 459 typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder; 460 461 #ifndef AAUDIO_API 462 #define AAUDIO_API /* export this symbol */ 463 #endif 464 465 // ============================================================ 466 // Audio System 467 // ============================================================ 468 469 /** 470 * The text is the ASCII symbol corresponding to the returnCode, 471 * or an English message saying the returnCode is unrecognized. 472 * This is intended for developers to use when debugging. 473 * It is not for display to users. 474 * 475 * Available since API level 26. 476 * 477 * @return pointer to a text representation of an AAudio result code. 478 */ 479 AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode) __INTRODUCED_IN(26); 480 481 /** 482 * The text is the ASCII symbol corresponding to the stream state, 483 * or an English message saying the state is unrecognized. 484 * This is intended for developers to use when debugging. 485 * It is not for display to users. 486 * 487 * Available since API level 26. 488 * 489 * @return pointer to a text representation of an AAudio state. 490 */ 491 AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state) 492 __INTRODUCED_IN(26); 493 494 // ============================================================ 495 // StreamBuilder 496 // ============================================================ 497 498 /** 499 * Create a StreamBuilder that can be used to open a Stream. 500 * 501 * The deviceId is initially unspecified, meaning that the current default device will be used. 502 * 503 * The default direction is {@link #AAUDIO_DIRECTION_OUTPUT}. 504 * The default sharing mode is {@link #AAUDIO_SHARING_MODE_SHARED}. 505 * The data format, samplesPerFrames and sampleRate are unspecified and will be 506 * chosen by the device when it is opened. 507 * 508 * AAudioStreamBuilder_delete() must be called when you are done using the builder. 509 * 510 * Available since API level 26. 511 */ 512 AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder) 513 __INTRODUCED_IN(26); 514 515 /** 516 * Request an audio device identified device using an ID. 517 * On Android, for example, the ID could be obtained from the Java AudioManager. 518 * 519 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}, 520 * in which case the primary device will be used. 521 * 522 * Available since API level 26. 523 * 524 * @param builder reference provided by AAudio_createStreamBuilder() 525 * @param deviceId device identifier or {@link #AAUDIO_UNSPECIFIED} 526 */ 527 AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder, 528 int32_t deviceId) __INTRODUCED_IN(26); 529 530 /** 531 * Request a sample rate in Hertz. 532 * 533 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. 534 * An optimal value will then be chosen when the stream is opened. 535 * After opening a stream with an unspecified value, the application must 536 * query for the actual value, which may vary by device. 537 * 538 * If an exact value is specified then an opened stream will use that value. 539 * If a stream cannot be opened with the specified value then the open will fail. 540 * 541 * Available since API level 26. 542 * 543 * @param builder reference provided by AAudio_createStreamBuilder() 544 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz. 545 */ 546 AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder, 547 int32_t sampleRate) __INTRODUCED_IN(26); 548 549 /** 550 * Request a number of channels for the stream. 551 * 552 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. 553 * An optimal value will then be chosen when the stream is opened. 554 * After opening a stream with an unspecified value, the application must 555 * query for the actual value, which may vary by device. 556 * 557 * If an exact value is specified then an opened stream will use that value. 558 * If a stream cannot be opened with the specified value then the open will fail. 559 * 560 * Available since API level 26. 561 * 562 * @param builder reference provided by AAudio_createStreamBuilder() 563 * @param channelCount Number of channels desired. 564 */ 565 AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder, 566 int32_t channelCount) __INTRODUCED_IN(26); 567 568 /** 569 * Identical to AAudioStreamBuilder_setChannelCount(). 570 * 571 * Available since API level 26. 572 * 573 * @param builder reference provided by AAudio_createStreamBuilder() 574 * @param samplesPerFrame Number of samples in a frame. 575 */ 576 AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder, 577 int32_t samplesPerFrame) __INTRODUCED_IN(26); 578 579 /** 580 * Request a sample data format, for example {@link #AAUDIO_FORMAT_PCM_I16}. 581 * 582 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. 583 * An optimal value will then be chosen when the stream is opened. 584 * After opening a stream with an unspecified value, the application must 585 * query for the actual value, which may vary by device. 586 * 587 * If an exact value is specified then an opened stream will use that value. 588 * If a stream cannot be opened with the specified value then the open will fail. 589 * 590 * Available since API level 26. 591 * 592 * @param builder reference provided by AAudio_createStreamBuilder() 593 * @param format common formats are {@link #AAUDIO_FORMAT_PCM_FLOAT} and 594 * {@link #AAUDIO_FORMAT_PCM_I16}. 595 */ 596 AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder, 597 aaudio_format_t format) __INTRODUCED_IN(26); 598 599 /** 600 * Request a mode for sharing the device. 601 * 602 * The default, if you do not call this function, is {@link #AAUDIO_SHARING_MODE_SHARED}. 603 * 604 * The requested sharing mode may not be available. 605 * The application can query for the actual mode after the stream is opened. 606 * 607 * Available since API level 26. 608 * 609 * @param builder reference provided by AAudio_createStreamBuilder() 610 * @param sharingMode {@link #AAUDIO_SHARING_MODE_SHARED} or {@link #AAUDIO_SHARING_MODE_EXCLUSIVE} 611 */ 612 AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder, 613 aaudio_sharing_mode_t sharingMode) __INTRODUCED_IN(26); 614 615 /** 616 * Request the direction for a stream. 617 * 618 * The default, if you do not call this function, is {@link #AAUDIO_DIRECTION_OUTPUT}. 619 * 620 * Available since API level 26. 621 * 622 * @param builder reference provided by AAudio_createStreamBuilder() 623 * @param direction {@link #AAUDIO_DIRECTION_OUTPUT} or {@link #AAUDIO_DIRECTION_INPUT} 624 */ 625 AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder, 626 aaudio_direction_t direction) __INTRODUCED_IN(26); 627 628 /** 629 * Set the requested buffer capacity in frames. 630 * The final AAudioStream capacity may differ, but will probably be at least this big. 631 * 632 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. 633 * 634 * Available since API level 26. 635 * 636 * @param builder reference provided by AAudio_createStreamBuilder() 637 * @param numFrames the desired buffer capacity in frames or {@link #AAUDIO_UNSPECIFIED} 638 */ 639 AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder, 640 int32_t numFrames) __INTRODUCED_IN(26); 641 642 /** 643 * Set the requested performance mode. 644 * 645 * Supported modes are {@link #AAUDIO_PERFORMANCE_MODE_NONE}, 646 * {@link #AAUDIO_PERFORMANCE_MODE_POWER_SAVING} * and {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY}. 647 * 648 * The default, if you do not call this function, is {@link #AAUDIO_PERFORMANCE_MODE_NONE}. 649 * 650 * You may not get the mode you requested. 651 * You can call AAudioStream_getPerformanceMode() 652 * to find out the final mode for the stream. 653 * 654 * Available since API level 26. 655 * 656 * @param builder reference provided by AAudio_createStreamBuilder() 657 * @param mode the desired performance mode, eg. {@link #AAUDIO_PERFORMANCE_MODE_LOW_LATENCY} 658 */ 659 AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder, 660 aaudio_performance_mode_t mode) __INTRODUCED_IN(26); 661 662 /** 663 * Set the intended use case for the stream. 664 * 665 * The AAudio system will use this information to optimize the 666 * behavior of the stream. 667 * This could, for example, affect how volume and focus is handled for the stream. 668 * 669 * The default, if you do not call this function, is {@link #AAUDIO_USAGE_MEDIA}. 670 * 671 * Available since API level 28. 672 * 673 * @param builder reference provided by AAudio_createStreamBuilder() 674 * @param usage the desired usage, eg. {@link #AAUDIO_USAGE_GAME} 675 */ 676 AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder, 677 aaudio_usage_t usage) __INTRODUCED_IN(28); 678 679 /** 680 * Set the type of audio data that the stream will carry. 681 * 682 * The AAudio system will use this information to optimize the 683 * behavior of the stream. 684 * This could, for example, affect whether a stream is paused when a notification occurs. 685 * 686 * The default, if you do not call this function, is {@link #AAUDIO_CONTENT_TYPE_MUSIC}. 687 * 688 * Available since API level 28. 689 * 690 * @param builder reference provided by AAudio_createStreamBuilder() 691 * @param contentType the type of audio data, eg. {@link #AAUDIO_CONTENT_TYPE_SPEECH} 692 */ 693 AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder, 694 aaudio_content_type_t contentType) __INTRODUCED_IN(28); 695 696 /** 697 * Set the input (capture) preset for the stream. 698 * 699 * The AAudio system will use this information to optimize the 700 * behavior of the stream. 701 * This could, for example, affect which microphones are used and how the 702 * recorded data is processed. 703 * 704 * The default, if you do not call this function, is {@link #AAUDIO_INPUT_PRESET_VOICE_RECOGNITION}. 705 * That is because VOICE_RECOGNITION is the preset with the lowest latency 706 * on many platforms. 707 * 708 * Available since API level 28. 709 * 710 * @param builder reference provided by AAudio_createStreamBuilder() 711 * @param inputPreset the desired configuration for recording 712 */ 713 AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder, 714 aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28); 715 716 /** 717 * Specify whether this stream audio may or may not be captured by other apps or the system. 718 * 719 * The default is {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL}. 720 * 721 * Note that an application can also set its global policy, in which case the most restrictive 722 * policy is always applied. See {@link android.media.AudioAttributes#setAllowedCapturePolicy(int)} 723 * 724 * Available since API level 29. 725 * 726 * @param builder reference provided by AAudio_createStreamBuilder() 727 * @param inputPreset the desired level of opt-out from being captured. 728 */ 729 AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder, 730 aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29); 731 732 /** Set the requested session ID. 733 * 734 * The session ID can be used to associate a stream with effects processors. 735 * The effects are controlled using the Android AudioEffect Java API. 736 * 737 * The default, if you do not call this function, is {@link #AAUDIO_SESSION_ID_NONE}. 738 * 739 * If set to {@link #AAUDIO_SESSION_ID_ALLOCATE} then a session ID will be allocated 740 * when the stream is opened. 741 * 742 * The allocated session ID can be obtained by calling AAudioStream_getSessionId() 743 * and then used with this function when opening another stream. 744 * This allows effects to be shared between streams. 745 * 746 * Session IDs from AAudio can be used with the Android Java APIs and vice versa. 747 * So a session ID from an AAudio stream can be passed to Java 748 * and effects applied using the Java AudioEffect API. 749 * 750 * Note that allocating or setting a session ID may result in a stream with higher latency. 751 * 752 * Allocated session IDs will always be positive and nonzero. 753 * 754 * Available since API level 28. 755 * 756 * @param builder reference provided by AAudio_createStreamBuilder() 757 * @param sessionId an allocated sessionID or {@link #AAUDIO_SESSION_ID_ALLOCATE} 758 */ 759 AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder, 760 aaudio_session_id_t sessionId) __INTRODUCED_IN(28); 761 762 /** 763 * Return one of these values from the data callback function. 764 */ 765 enum { 766 767 /** 768 * Continue calling the callback. 769 */ 770 AAUDIO_CALLBACK_RESULT_CONTINUE = 0, 771 772 /** 773 * Stop calling the callback. 774 * 775 * The application will still need to call AAudioStream_requestPause() 776 * or AAudioStream_requestStop(). 777 */ 778 AAUDIO_CALLBACK_RESULT_STOP, 779 780 }; 781 typedef int32_t aaudio_data_callback_result_t; 782 783 /** 784 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback(). 785 * 786 * For an output stream, this function should render and write numFrames of data 787 * in the streams current data format to the audioData buffer. 788 * 789 * For an input stream, this function should read and process numFrames of data 790 * from the audioData buffer. 791 * 792 * The audio data is passed through the buffer. So do NOT call AAudioStream_read() or 793 * AAudioStream_write() on the stream that is making the callback. 794 * 795 * Note that numFrames can vary unless AAudioStreamBuilder_setFramesPerDataCallback() 796 * is called. 797 * 798 * Also note that this callback function should be considered a "real-time" function. 799 * It must not do anything that could cause an unbounded delay because that can cause the 800 * audio to glitch or pop. 801 * 802 * These are things the function should NOT do: 803 * <ul> 804 * <li>allocate memory using, for example, malloc() or new</li> 805 * <li>any file operations such as opening, closing, reading or writing</li> 806 * <li>any network operations such as streaming</li> 807 * <li>use any mutexes or other synchronization primitives</li> 808 * <li>sleep</li> 809 * <li>stop or close the stream</li> 810 * <li>AAudioStream_read()</li> 811 * <li>AAudioStream_write()</li> 812 * </ul> 813 * 814 * The following are OK to call from the data callback: 815 * <ul> 816 * <li>AAudioStream_get*()</li> 817 * <li>AAudio_convertResultToText()</li> 818 * </ul> 819 * 820 * If you need to move data, eg. MIDI commands, in or out of the callback function then 821 * we recommend the use of non-blocking techniques such as an atomic FIFO. 822 * 823 * @param stream reference provided by AAudioStreamBuilder_openStream() 824 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback() 825 * @param audioData a pointer to the audio data 826 * @param numFrames the number of frames to be processed, which can vary 827 * @return AAUDIO_CALLBACK_RESULT_* 828 */ 829 typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)( 830 AAudioStream *stream, 831 void *userData, 832 void *audioData, 833 int32_t numFrames); 834 835 /** 836 * Request that AAudio call this functions when the stream is running. 837 * 838 * Note that when using this callback, the audio data will be passed in or out 839 * of the function as an argument. 840 * So you cannot call AAudioStream_write() or AAudioStream_read() 841 * on the same stream that has an active data callback. 842 * 843 * The callback function will start being called after AAudioStream_requestStart() 844 * is called. 845 * It will stop being called after AAudioStream_requestPause() or 846 * AAudioStream_requestStop() is called. 847 * 848 * This callback function will be called on a real-time thread owned by AAudio. See 849 * {@link #AAudioStream_dataCallback} for more information. 850 * 851 * Note that the AAudio callbacks will never be called simultaneously from multiple threads. 852 * 853 * Available since API level 26. 854 * 855 * @param builder reference provided by AAudio_createStreamBuilder() 856 * @param callback pointer to a function that will process audio data. 857 * @param userData pointer to an application data structure that will be passed 858 * to the callback functions. 859 */ 860 AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder, 861 AAudioStream_dataCallback callback, void *userData) __INTRODUCED_IN(26); 862 863 /** 864 * Set the requested data callback buffer size in frames. 865 * See {@link #AAudioStream_dataCallback}. 866 * 867 * The default, if you do not call this function, is {@link #AAUDIO_UNSPECIFIED}. 868 * 869 * For the lowest possible latency, do not call this function. AAudio will then 870 * call the dataProc callback function with whatever size is optimal. 871 * That size may vary from one callback to another. 872 * 873 * Only use this function if the application requires a specific number of frames for processing. 874 * The application might, for example, be using an FFT that requires 875 * a specific power-of-two sized buffer. 876 * 877 * AAudio may need to add additional buffering in order to adapt between the internal 878 * buffer size and the requested buffer size. 879 * 880 * If you do call this function then the requested size should be less than 881 * half the buffer capacity, to allow double buffering. 882 * 883 * Available since API level 26. 884 * 885 * @param builder reference provided by AAudio_createStreamBuilder() 886 * @param numFrames the desired buffer size in frames or {@link #AAUDIO_UNSPECIFIED} 887 */ 888 AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder, 889 int32_t numFrames) __INTRODUCED_IN(26); 890 891 /** 892 * Prototype for the callback function that is passed to 893 * AAudioStreamBuilder_setErrorCallback(). 894 * 895 * The following may NOT be called from the error callback: 896 * <ul> 897 * <li>AAudioStream_requestStop()</li> 898 * <li>AAudioStream_requestPause()</li> 899 * <li>AAudioStream_close()</li> 900 * <li>AAudioStream_waitForStateChange()</li> 901 * <li>AAudioStream_read()</li> 902 * <li>AAudioStream_write()</li> 903 * </ul> 904 * 905 * The following are OK to call from the error callback: 906 * <ul> 907 * <li>AAudioStream_get*()</li> 908 * <li>AAudio_convertResultToText()</li> 909 * </ul> 910 * 911 * @param stream reference provided by AAudioStreamBuilder_openStream() 912 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback() 913 * @param error an AAUDIO_ERROR_* value. 914 */ 915 typedef void (*AAudioStream_errorCallback)( 916 AAudioStream *stream, 917 void *userData, 918 aaudio_result_t error); 919 920 /** 921 * Request that AAudio call this function if any error occurs or the stream is disconnected. 922 * 923 * It will be called, for example, if a headset or a USB device is unplugged causing the stream's 924 * device to be unavailable or "disconnected". 925 * Another possible cause of error would be a timeout or an unanticipated internal error. 926 * 927 * In response, this function should signal or create another thread to stop 928 * and close this stream. The other thread could then reopen a stream on another device. 929 * Do not stop or close the stream, or reopen the new stream, directly from this callback. 930 * 931 * This callback will not be called because of actions by the application, such as stopping 932 * or closing a stream. 933 * 934 * Note that the AAudio callbacks will never be called simultaneously from multiple threads. 935 * 936 * Available since API level 26. 937 * 938 * @param builder reference provided by AAudio_createStreamBuilder() 939 * @param callback pointer to a function that will be called if an error occurs. 940 * @param userData pointer to an application data structure that will be passed 941 * to the callback functions. 942 */ 943 AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder, 944 AAudioStream_errorCallback callback, void *userData) __INTRODUCED_IN(26); 945 946 /** 947 * Open a stream based on the options in the StreamBuilder. 948 * 949 * AAudioStream_close() must be called when finished with the stream to recover 950 * the memory and to free the associated resources. 951 * 952 * Available since API level 26. 953 * 954 * @param builder reference provided by AAudio_createStreamBuilder() 955 * @param stream pointer to a variable to receive the new stream reference 956 * @return {@link #AAUDIO_OK} or a negative error. 957 */ 958 AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder, 959 AAudioStream** stream) __INTRODUCED_IN(26); 960 961 /** 962 * Delete the resources associated with the StreamBuilder. 963 * 964 * Available since API level 26. 965 * 966 * @param builder reference provided by AAudio_createStreamBuilder() 967 * @return {@link #AAUDIO_OK} or a negative error. 968 */ 969 AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder) 970 __INTRODUCED_IN(26); 971 972 // ============================================================ 973 // Stream Control 974 // ============================================================ 975 976 /** 977 * Free the resources associated with a stream created by AAudioStreamBuilder_openStream() 978 * 979 * Available since API level 26. 980 * 981 * @param stream reference provided by AAudioStreamBuilder_openStream() 982 * @return {@link #AAUDIO_OK} or a negative error. 983 */ 984 AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream) __INTRODUCED_IN(26); 985 986 /** 987 * Asynchronously request to start playing the stream. For output streams, one should 988 * write to the stream to fill the buffer before starting. 989 * Otherwise it will underflow. 990 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STARTING} or 991 * {@link #AAUDIO_STREAM_STATE_STARTED}. 992 * 993 * Available since API level 26. 994 * 995 * @param stream reference provided by AAudioStreamBuilder_openStream() 996 * @return {@link #AAUDIO_OK} or a negative error. 997 */ 998 AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream) __INTRODUCED_IN(26); 999 1000 /** 1001 * Asynchronous request for the stream to pause. 1002 * Pausing a stream will freeze the data flow but not flush any buffers. 1003 * Use AAudioStream_requestStart() to resume playback after a pause. 1004 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_PAUSING} or 1005 * {@link #AAUDIO_STREAM_STATE_PAUSED}. 1006 * 1007 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams. 1008 * For input streams use AAudioStream_requestStop(). 1009 * 1010 * Available since API level 26. 1011 * 1012 * @param stream reference provided by AAudioStreamBuilder_openStream() 1013 * @return {@link #AAUDIO_OK} or a negative error. 1014 */ 1015 AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream) __INTRODUCED_IN(26); 1016 1017 /** 1018 * Asynchronous request for the stream to flush. 1019 * Flushing will discard any pending data. 1020 * This call only works if the stream is pausing or paused. TODO review 1021 * Frame counters are not reset by a flush. They may be advanced. 1022 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_FLUSHING} or 1023 * {@link #AAUDIO_STREAM_STATE_FLUSHED}. 1024 * 1025 * This will return {@link #AAUDIO_ERROR_UNIMPLEMENTED} for input streams. 1026 * 1027 * Available since API level 26. 1028 * 1029 * @param stream reference provided by AAudioStreamBuilder_openStream() 1030 * @return {@link #AAUDIO_OK} or a negative error. 1031 */ 1032 AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream) __INTRODUCED_IN(26); 1033 1034 /** 1035 * Asynchronous request for the stream to stop. 1036 * The stream will stop after all of the data currently buffered has been played. 1037 * After this call the state will be in {@link #AAUDIO_STREAM_STATE_STOPPING} or 1038 * {@link #AAUDIO_STREAM_STATE_STOPPED}. 1039 * 1040 * Available since API level 26. 1041 * 1042 * @param stream reference provided by AAudioStreamBuilder_openStream() 1043 * @return {@link #AAUDIO_OK} or a negative error. 1044 */ 1045 AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream) __INTRODUCED_IN(26); 1046 1047 /** 1048 * Query the current state of the client, eg. {@link #AAUDIO_STREAM_STATE_PAUSING} 1049 * 1050 * This function will immediately return the state without updating the state. 1051 * If you want to update the client state based on the server state then 1052 * call AAudioStream_waitForStateChange() with currentState 1053 * set to {@link #AAUDIO_STREAM_STATE_UNKNOWN} and a zero timeout. 1054 * 1055 * Available since API level 26. 1056 * 1057 * @param stream reference provided by AAudioStreamBuilder_openStream() 1058 */ 1059 AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream) __INTRODUCED_IN(26); 1060 1061 /** 1062 * Wait until the current state no longer matches the input state. 1063 * 1064 * This will update the current client state. 1065 * 1066 * <pre><code> 1067 * aaudio_result_t result = AAUDIO_OK; 1068 * aaudio_stream_state_t currentState = AAudioStream_getState(stream); 1069 * aaudio_stream_state_t inputState = currentState; 1070 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSED) { 1071 * result = AAudioStream_waitForStateChange( 1072 * stream, inputState, ¤tState, MY_TIMEOUT_NANOS); 1073 * inputState = currentState; 1074 * } 1075 * </code></pre> 1076 * 1077 * Available since API level 26. 1078 * 1079 * @param stream A reference provided by AAudioStreamBuilder_openStream() 1080 * @param inputState The state we want to avoid. 1081 * @param nextState Pointer to a variable that will be set to the new state. 1082 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. 1083 * @return {@link #AAUDIO_OK} or a negative error. 1084 */ 1085 AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream, 1086 aaudio_stream_state_t inputState, aaudio_stream_state_t *nextState, 1087 int64_t timeoutNanoseconds) __INTRODUCED_IN(26); 1088 1089 // ============================================================ 1090 // Stream I/O 1091 // ============================================================ 1092 1093 /** 1094 * Read data from the stream. 1095 * 1096 * The call will wait until the read is complete or until it runs out of time. 1097 * If timeoutNanos is zero then this call will not wait. 1098 * 1099 * Note that timeoutNanoseconds is a relative duration in wall clock time. 1100 * Time will not stop if the thread is asleep. 1101 * So it will be implemented using CLOCK_BOOTTIME. 1102 * 1103 * This call is "strong non-blocking" unless it has to wait for data. 1104 * 1105 * If the call times out then zero or a partial frame count will be returned. 1106 * 1107 * Available since API level 26. 1108 * 1109 * @param stream A stream created using AAudioStreamBuilder_openStream(). 1110 * @param buffer The address of the first sample. 1111 * @param numFrames Number of frames to read. Only complete frames will be written. 1112 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. 1113 * @return The number of frames actually read or a negative error. 1114 */ 1115 AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream, 1116 void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26); 1117 1118 /** 1119 * Write data to the stream. 1120 * 1121 * The call will wait until the write is complete or until it runs out of time. 1122 * If timeoutNanos is zero then this call will not wait. 1123 * 1124 * Note that timeoutNanoseconds is a relative duration in wall clock time. 1125 * Time will not stop if the thread is asleep. 1126 * So it will be implemented using CLOCK_BOOTTIME. 1127 * 1128 * This call is "strong non-blocking" unless it has to wait for room in the buffer. 1129 * 1130 * If the call times out then zero or a partial frame count will be returned. 1131 * 1132 * Available since API level 26. 1133 * 1134 * @param stream A stream created using AAudioStreamBuilder_openStream(). 1135 * @param buffer The address of the first sample. 1136 * @param numFrames Number of frames to write. Only complete frames will be written. 1137 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. 1138 * @return The number of frames actually written or a negative error. 1139 */ 1140 AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream, 1141 const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) __INTRODUCED_IN(26); 1142 1143 // ============================================================ 1144 // Stream - queries 1145 // ============================================================ 1146 1147 /** 1148 * This can be used to adjust the latency of the buffer by changing 1149 * the threshold where blocking will occur. 1150 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned 1151 * at run-time for each device. 1152 * 1153 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames(). 1154 * 1155 * Note that you will probably not get the exact size you request. 1156 * You can check the return value or call AAudioStream_getBufferSizeInFrames() 1157 * to see what the actual final size is. 1158 * 1159 * Available since API level 26. 1160 * 1161 * @param stream reference provided by AAudioStreamBuilder_openStream() 1162 * @param numFrames requested number of frames that can be filled without blocking 1163 * @return actual buffer size in frames or a negative error 1164 */ 1165 AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream, 1166 int32_t numFrames) __INTRODUCED_IN(26); 1167 1168 /** 1169 * Query the maximum number of frames that can be filled without blocking. 1170 * 1171 * Available since API level 26. 1172 * 1173 * @param stream reference provided by AAudioStreamBuilder_openStream() 1174 * @return buffer size in frames. 1175 */ 1176 AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream) __INTRODUCED_IN(26); 1177 1178 /** 1179 * Query the number of frames that the application should read or write at 1180 * one time for optimal performance. It is OK if an application writes 1181 * a different number of frames. But the buffer size may need to be larger 1182 * in order to avoid underruns or overruns. 1183 * 1184 * Note that this may or may not match the actual device burst size. 1185 * For some endpoints, the burst size can vary dynamically. 1186 * But these tend to be devices with high latency. 1187 * 1188 * Available since API level 26. 1189 * 1190 * @param stream reference provided by AAudioStreamBuilder_openStream() 1191 * @return burst size 1192 */ 1193 AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream) __INTRODUCED_IN(26); 1194 1195 /** 1196 * Query maximum buffer capacity in frames. 1197 * 1198 * Available since API level 26. 1199 * 1200 * @param stream reference provided by AAudioStreamBuilder_openStream() 1201 * @return buffer capacity in frames 1202 */ 1203 AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream) __INTRODUCED_IN(26); 1204 1205 /** 1206 * Query the size of the buffer that will be passed to the dataProc callback 1207 * in the numFrames parameter. 1208 * 1209 * This call can be used if the application needs to know the value of numFrames before 1210 * the stream is started. This is not normally necessary. 1211 * 1212 * If a specific size was requested by calling 1213 * AAudioStreamBuilder_setFramesPerDataCallback() then this will be the same size. 1214 * 1215 * If AAudioStreamBuilder_setFramesPerDataCallback() was not called then this will 1216 * return the size chosen by AAudio, or {@link #AAUDIO_UNSPECIFIED}. 1217 * 1218 * {@link #AAUDIO_UNSPECIFIED} indicates that the callback buffer size for this stream 1219 * may vary from one dataProc callback to the next. 1220 * 1221 * Available since API level 26. 1222 * 1223 * @param stream reference provided by AAudioStreamBuilder_openStream() 1224 * @return callback buffer size in frames or {@link #AAUDIO_UNSPECIFIED} 1225 */ 1226 AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream) __INTRODUCED_IN(26); 1227 1228 /** 1229 * An XRun is an Underrun or an Overrun. 1230 * During playing, an underrun will occur if the stream is not written in time 1231 * and the system runs out of valid data. 1232 * During recording, an overrun will occur if the stream is not read in time 1233 * and there is no place to put the incoming data so it is discarded. 1234 * 1235 * An underrun or overrun can cause an audible "pop" or "glitch". 1236 * 1237 * Note that some INPUT devices may not support this function. 1238 * In that case a 0 will always be returned. 1239 * 1240 * Available since API level 26. 1241 * 1242 * @param stream reference provided by AAudioStreamBuilder_openStream() 1243 * @return the underrun or overrun count 1244 */ 1245 AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream) __INTRODUCED_IN(26); 1246 1247 /** 1248 * Available since API level 26. 1249 * 1250 * @param stream reference provided by AAudioStreamBuilder_openStream() 1251 * @return actual sample rate 1252 */ 1253 AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream) __INTRODUCED_IN(26); 1254 1255 /** 1256 * A stream has one or more channels of data. 1257 * A frame will contain one sample for each channel. 1258 * 1259 * Available since API level 26. 1260 * 1261 * @param stream reference provided by AAudioStreamBuilder_openStream() 1262 * @return actual number of channels 1263 */ 1264 AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream) __INTRODUCED_IN(26); 1265 1266 /** 1267 * Identical to AAudioStream_getChannelCount(). 1268 * 1269 * Available since API level 26. 1270 * 1271 * @param stream reference provided by AAudioStreamBuilder_openStream() 1272 * @return actual number of samples frame 1273 */ 1274 AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream) __INTRODUCED_IN(26); 1275 1276 /** 1277 * Available since API level 26. 1278 * 1279 * @param stream reference provided by AAudioStreamBuilder_openStream() 1280 * @return actual device ID 1281 */ 1282 AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream) __INTRODUCED_IN(26); 1283 1284 /** 1285 * Available since API level 26. 1286 * 1287 * @param stream reference provided by AAudioStreamBuilder_openStream() 1288 * @return actual data format 1289 */ 1290 AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream) __INTRODUCED_IN(26); 1291 1292 /** 1293 * Provide actual sharing mode. 1294 * 1295 * Available since API level 26. 1296 * 1297 * @param stream reference provided by AAudioStreamBuilder_openStream() 1298 * @return actual sharing mode 1299 */ 1300 AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream) 1301 __INTRODUCED_IN(26); 1302 1303 /** 1304 * Get the performance mode used by the stream. 1305 * 1306 * Available since API level 26. 1307 * 1308 * @param stream reference provided by AAudioStreamBuilder_openStream() 1309 */ 1310 AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream) 1311 __INTRODUCED_IN(26); 1312 1313 /** 1314 * Available since API level 26. 1315 * 1316 * @param stream reference provided by AAudioStreamBuilder_openStream() 1317 * @return direction 1318 */ 1319 AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream) __INTRODUCED_IN(26); 1320 1321 /** 1322 * Passes back the number of frames that have been written since the stream was created. 1323 * For an output stream, this will be advanced by the application calling write() 1324 * or by a data callback. 1325 * For an input stream, this will be advanced by the endpoint. 1326 * 1327 * The frame position is monotonically increasing. 1328 * 1329 * Available since API level 26. 1330 * 1331 * @param stream reference provided by AAudioStreamBuilder_openStream() 1332 * @return frames written 1333 */ 1334 AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream) __INTRODUCED_IN(26); 1335 1336 /** 1337 * Passes back the number of frames that have been read since the stream was created. 1338 * For an output stream, this will be advanced by the endpoint. 1339 * For an input stream, this will be advanced by the application calling read() 1340 * or by a data callback. 1341 * 1342 * The frame position is monotonically increasing. 1343 * 1344 * Available since API level 26. 1345 * 1346 * @param stream reference provided by AAudioStreamBuilder_openStream() 1347 * @return frames read 1348 */ 1349 AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream) __INTRODUCED_IN(26); 1350 1351 /** 1352 * Passes back the session ID associated with this stream. 1353 * 1354 * The session ID can be used to associate a stream with effects processors. 1355 * The effects are controlled using the Android AudioEffect Java API. 1356 * 1357 * If AAudioStreamBuilder_setSessionId() was 1358 * called with {@link #AAUDIO_SESSION_ID_ALLOCATE} 1359 * then a new session ID should be allocated once when the stream is opened. 1360 * 1361 * If AAudioStreamBuilder_setSessionId() was called with a previously allocated 1362 * session ID then that value should be returned. 1363 * 1364 * If AAudioStreamBuilder_setSessionId() was not called then this function should 1365 * return {@link #AAUDIO_SESSION_ID_NONE}. 1366 * 1367 * The sessionID for a stream should not change once the stream has been opened. 1368 * 1369 * Available since API level 28. 1370 * 1371 * @param stream reference provided by AAudioStreamBuilder_openStream() 1372 * @return session ID or {@link #AAUDIO_SESSION_ID_NONE} 1373 */ 1374 AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream) __INTRODUCED_IN(28); 1375 1376 /** 1377 * Passes back the time at which a particular frame was presented. 1378 * This can be used to synchronize audio with video or MIDI. 1379 * It can also be used to align a recorded stream with a playback stream. 1380 * 1381 * Timestamps are only valid when the stream is in {@link #AAUDIO_STREAM_STATE_STARTED}. 1382 * {@link #AAUDIO_ERROR_INVALID_STATE} will be returned if the stream is not started. 1383 * Note that because requestStart() is asynchronous, timestamps will not be valid until 1384 * a short time after calling requestStart(). 1385 * So {@link #AAUDIO_ERROR_INVALID_STATE} should not be considered a fatal error. 1386 * Just try calling again later. 1387 * 1388 * If an error occurs, then the position and time will not be modified. 1389 * 1390 * The position and time passed back are monotonically increasing. 1391 * 1392 * Available since API level 26. 1393 * 1394 * @param stream reference provided by AAudioStreamBuilder_openStream() 1395 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME 1396 * @param framePosition pointer to a variable to receive the position 1397 * @param timeNanoseconds pointer to a variable to receive the time 1398 * @return {@link #AAUDIO_OK} or a negative error 1399 */ 1400 AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream, 1401 clockid_t clockid, int64_t *framePosition, int64_t *timeNanoseconds) __INTRODUCED_IN(26); 1402 1403 /** 1404 * Return the use case for the stream. 1405 * 1406 * Available since API level 28. 1407 * 1408 * @param stream reference provided by AAudioStreamBuilder_openStream() 1409 * @return frames read 1410 */ 1411 AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream) __INTRODUCED_IN(28); 1412 1413 /** 1414 * Return the content type for the stream. 1415 * 1416 * Available since API level 28. 1417 * 1418 * @param stream reference provided by AAudioStreamBuilder_openStream() 1419 * @return content type, for example {@link #AAUDIO_CONTENT_TYPE_MUSIC} 1420 */ 1421 AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream) 1422 __INTRODUCED_IN(28); 1423 1424 /** 1425 * Return the input preset for the stream. 1426 * 1427 * Available since API level 28. 1428 * 1429 * @param stream reference provided by AAudioStreamBuilder_openStream() 1430 * @return input preset, for example {@link #AAUDIO_INPUT_PRESET_CAMCORDER} 1431 */ 1432 AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream) 1433 __INTRODUCED_IN(28); 1434 1435 /** 1436 * Return the policy that determines whether the audio may or may not be captured 1437 * by other apps or the system. 1438 * 1439 * Available since API level 29. 1440 * 1441 * @param stream reference provided by AAudioStreamBuilder_openStream() 1442 * @return the allowed capture policy, for example {@link #AAUDIO_ALLOW_CAPTURE_BY_ALL} 1443 */ 1444 AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy( 1445 AAudioStream* stream) __INTRODUCED_IN(29); 1446 1447 #ifdef __cplusplus 1448 } 1449 #endif 1450 1451 #endif //AAUDIO_AAUDIO_H 1452 1453 /** @} */ 1454