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