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