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 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 32 | #include <time.h> |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 33 | |
| 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 38 | /** |
| 39 | * This is used to represent a value that has not been specified. |
| 40 | * For example, an application could use AAUDIO_UNSPECIFIED to indicate |
| 41 | * that is did not not care what the specific value of a parameter was |
| 42 | * and would accept whatever it was given. |
| 43 | */ |
| 44 | #define AAUDIO_UNSPECIFIED 0 |
| 45 | #define AAUDIO_DEVICE_UNSPECIFIED 0 |
| 46 | |
| 47 | enum { |
| 48 | AAUDIO_DIRECTION_OUTPUT, |
| 49 | AAUDIO_DIRECTION_INPUT |
| 50 | }; |
| 51 | typedef int32_t aaudio_direction_t; |
| 52 | |
| 53 | enum { |
| 54 | AAUDIO_FORMAT_INVALID = -1, |
| 55 | AAUDIO_FORMAT_UNSPECIFIED = 0, |
| 56 | AAUDIO_FORMAT_PCM_I16, |
Phil Burk | 7473345 | 2017-04-18 19:50:28 -0700 | [diff] [blame] | 57 | AAUDIO_FORMAT_PCM_FLOAT |
Phil Burk | a4eb0d8 | 2017-04-12 15:44:06 -0700 | [diff] [blame] | 58 | }; |
| 59 | typedef int32_t aaudio_format_t; |
| 60 | |
| 61 | /** |
| 62 | * @deprecated use aaudio_format_t instead |
| 63 | * TODO remove when tests and examples are updated |
| 64 | */ |
| 65 | typedef int32_t aaudio_audio_format_t; |
| 66 | |
| 67 | enum { |
| 68 | AAUDIO_OK, |
| 69 | AAUDIO_ERROR_BASE = -900, // TODO review |
| 70 | AAUDIO_ERROR_DISCONNECTED, |
| 71 | AAUDIO_ERROR_ILLEGAL_ARGUMENT, |
| 72 | AAUDIO_ERROR_INCOMPATIBLE, |
| 73 | AAUDIO_ERROR_INTERNAL, // an underlying API returned an error code |
| 74 | AAUDIO_ERROR_INVALID_STATE, |
| 75 | AAUDIO_ERROR_UNEXPECTED_STATE, |
| 76 | AAUDIO_ERROR_UNEXPECTED_VALUE, |
| 77 | AAUDIO_ERROR_INVALID_HANDLE, |
| 78 | AAUDIO_ERROR_INVALID_QUERY, |
| 79 | AAUDIO_ERROR_UNIMPLEMENTED, |
| 80 | AAUDIO_ERROR_UNAVAILABLE, |
| 81 | AAUDIO_ERROR_NO_FREE_HANDLES, |
| 82 | AAUDIO_ERROR_NO_MEMORY, |
| 83 | AAUDIO_ERROR_NULL, |
| 84 | AAUDIO_ERROR_TIMEOUT, |
| 85 | AAUDIO_ERROR_WOULD_BLOCK, |
| 86 | AAUDIO_ERROR_INVALID_FORMAT, |
| 87 | AAUDIO_ERROR_OUT_OF_RANGE, |
| 88 | AAUDIO_ERROR_NO_SERVICE, |
| 89 | AAUDIO_ERROR_INVALID_RATE |
| 90 | }; |
| 91 | typedef int32_t aaudio_result_t; |
| 92 | |
| 93 | enum |
| 94 | { |
| 95 | AAUDIO_STREAM_STATE_UNINITIALIZED = 0, |
| 96 | AAUDIO_STREAM_STATE_UNKNOWN, |
| 97 | AAUDIO_STREAM_STATE_OPEN, |
| 98 | AAUDIO_STREAM_STATE_STARTING, |
| 99 | AAUDIO_STREAM_STATE_STARTED, |
| 100 | AAUDIO_STREAM_STATE_PAUSING, |
| 101 | AAUDIO_STREAM_STATE_PAUSED, |
| 102 | AAUDIO_STREAM_STATE_FLUSHING, |
| 103 | AAUDIO_STREAM_STATE_FLUSHED, |
| 104 | AAUDIO_STREAM_STATE_STOPPING, |
| 105 | AAUDIO_STREAM_STATE_STOPPED, |
| 106 | AAUDIO_STREAM_STATE_CLOSING, |
| 107 | AAUDIO_STREAM_STATE_CLOSED, |
| 108 | AAUDIO_STREAM_STATE_DISCONNECTED |
| 109 | }; |
| 110 | typedef int32_t aaudio_stream_state_t; |
| 111 | |
| 112 | |
| 113 | enum { |
| 114 | /** |
| 115 | * This will be the only stream using a particular source or sink. |
| 116 | * This mode will provide the lowest possible latency. |
| 117 | * You should close EXCLUSIVE streams immediately when you are not using them. |
| 118 | */ |
| 119 | AAUDIO_SHARING_MODE_EXCLUSIVE, |
| 120 | /** |
| 121 | * Multiple applications will be mixed by the AAudio Server. |
| 122 | * This will have higher latency than the EXCLUSIVE mode. |
| 123 | */ |
| 124 | AAUDIO_SHARING_MODE_SHARED |
| 125 | }; |
| 126 | typedef int32_t aaudio_sharing_mode_t; |
| 127 | |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 128 | typedef struct AAudioStreamStruct AAudioStream; |
| 129 | typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder; |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 130 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 131 | #ifndef AAUDIO_API |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 132 | #define AAUDIO_API /* export this symbol */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 133 | #endif |
| 134 | |
| 135 | // ============================================================ |
| 136 | // Audio System |
| 137 | // ============================================================ |
| 138 | |
| 139 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 140 | * The text is the ASCII symbol corresponding to the returnCode, |
| 141 | * or an English message saying the returnCode is unrecognized. |
| 142 | * This is intended for developers to use when debugging. |
| 143 | * It is not for display to users. |
| 144 | * |
| 145 | * @return pointer to a text representation of an AAudio result code. |
| 146 | */ |
| 147 | AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode); |
| 148 | |
| 149 | /** |
| 150 | * The text is the ASCII symbol corresponding to the stream state, |
| 151 | * or an English message saying the state is unrecognized. |
| 152 | * This is intended for developers to use when debugging. |
| 153 | * It is not for display to users. |
| 154 | * |
| 155 | * @return pointer to a text representation of an AAudio state. |
| 156 | */ |
| 157 | AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state); |
| 158 | |
| 159 | // ============================================================ |
| 160 | // StreamBuilder |
| 161 | // ============================================================ |
| 162 | |
| 163 | /** |
| 164 | * Create a StreamBuilder that can be used to open a Stream. |
| 165 | * |
| 166 | * The deviceId is initially unspecified, meaning that the current default device will be used. |
| 167 | * |
| 168 | * The default direction is AAUDIO_DIRECTION_OUTPUT. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 169 | * The default sharing mode is AAUDIO_SHARING_MODE_SHARED. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 170 | * The data format, samplesPerFrames and sampleRate are unspecified and will be |
| 171 | * chosen by the device when it is opened. |
| 172 | * |
| 173 | * AAudioStreamBuilder_delete() must be called when you are done using the builder. |
| 174 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 175 | AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 176 | |
| 177 | /** |
| 178 | * Request an audio device identified device using an ID. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 179 | * On Android, for example, the ID could be obtained from the Java AudioManager. |
| 180 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 181 | * The default, if you do not call this function, is AAUDIO_DEVICE_UNSPECIFIED, |
| 182 | * in which case the primary device will be used. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 183 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 184 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 185 | * @param deviceId device identifier or AAUDIO_DEVICE_UNSPECIFIED |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 186 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 187 | AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 188 | int32_t deviceId); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 189 | |
| 190 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 191 | * Request a sample rate in Hertz. |
| 192 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 193 | * The stream may be opened with a different sample rate. |
| 194 | * So the application should query for the actual rate after the stream is opened. |
| 195 | * |
| 196 | * Technically, this should be called the "frame rate" or "frames per second", |
| 197 | * because it refers to the number of complete frames transferred per second. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 198 | * But it is traditionally called "sample rate". So we use that term. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 199 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 200 | * The default, if you do not call this function, is AAUDIO_UNSPECIFIED. |
| 201 | * |
| 202 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 203 | * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 204 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 205 | AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 206 | int32_t sampleRate); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 207 | |
| 208 | /** |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame^] | 209 | * Request a number of channels for the stream. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 210 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 211 | * The stream may be opened with a different value. |
| 212 | * So the application should query for the actual value after the stream is opened. |
| 213 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 214 | * The default, if you do not call this function, is AAUDIO_UNSPECIFIED. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 215 | * |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame^] | 216 | * Note, this quantity is sometimes referred to as "samples per frame". |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 217 | * |
| 218 | * @param builder reference provided by AAudio_createStreamBuilder() |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame^] | 219 | * @param channelCount Number of channels desired. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 220 | */ |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame^] | 221 | AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder, |
| 222 | int32_t channelCount); |
| 223 | |
| 224 | /** |
| 225 | * |
| 226 | * @deprecated use AAudioStreamBuilder_setChannelCount() |
| 227 | */ |
| 228 | // TODO remove as soon as the NDK and OS are in sync, before RC1 |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 229 | AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder, |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame^] | 230 | int32_t samplesPerFrame); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 231 | |
| 232 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 233 | * Request a sample data format, for example AAUDIO_FORMAT_PCM_I16. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 234 | * |
| 235 | * The default, if you do not call this function, is AAUDIO_UNSPECIFIED. |
| 236 | * |
| 237 | * The stream may be opened with a different value. |
| 238 | * So the application should query for the actual value after the stream is opened. |
| 239 | * |
| 240 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 241 | * @param format Most common formats are AAUDIO_FORMAT_PCM_FLOAT and AAUDIO_FORMAT_PCM_I16. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 242 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 243 | AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder, |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 244 | aaudio_audio_format_t format); |
| 245 | |
| 246 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 247 | * Request a mode for sharing the device. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 248 | * |
| 249 | * The default, if you do not call this function, is AAUDIO_SHARING_MODE_SHARED. |
| 250 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 251 | * The requested sharing mode may not be available. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 252 | * 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] | 253 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 254 | * @param builder reference provided by AAudio_createStreamBuilder() |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 255 | * @param sharingMode AAUDIO_SHARING_MODE_SHARED or AAUDIO_SHARING_MODE_EXCLUSIVE |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 256 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 257 | AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder, |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 258 | aaudio_sharing_mode_t sharingMode); |
| 259 | |
| 260 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 261 | * Request the direction for a stream. |
| 262 | * |
| 263 | * The default, if you do not call this function, is AAUDIO_DIRECTION_OUTPUT. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 264 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 265 | * @param builder reference provided by AAudio_createStreamBuilder() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 266 | * @param direction AAUDIO_DIRECTION_OUTPUT or AAUDIO_DIRECTION_INPUT |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 267 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 268 | AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder, |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 269 | aaudio_direction_t direction); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 270 | |
| 271 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 272 | * Set the requested buffer capacity in frames. |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 273 | * The final AAudioStream capacity may differ, but will probably be at least this big. |
| 274 | * |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 275 | * The default, if you do not call this function, is AAUDIO_UNSPECIFIED. |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 276 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 277 | * @param builder reference provided by AAudio_createStreamBuilder() |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 278 | * @param numFrames the desired buffer capacity in frames or AAUDIO_UNSPECIFIED |
Phil Burk | 3df348f | 2017-02-08 11:41:55 -0800 | [diff] [blame] | 279 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 280 | AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder, |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 281 | int32_t numFrames); |
| 282 | /** |
| 283 | * Return one of these values from the data callback function. |
| 284 | */ |
| 285 | enum { |
| 286 | |
| 287 | /** |
| 288 | * Continue calling the callback. |
| 289 | */ |
| 290 | AAUDIO_CALLBACK_RESULT_CONTINUE = 0, |
| 291 | |
| 292 | /** |
| 293 | * Stop calling the callback. |
| 294 | * |
| 295 | * The application will still need to call AAudioStream_requestPause() |
| 296 | * or AAudioStream_requestStop(). |
| 297 | */ |
| 298 | AAUDIO_CALLBACK_RESULT_STOP, |
| 299 | |
| 300 | }; |
| 301 | typedef int32_t aaudio_data_callback_result_t; |
| 302 | |
| 303 | /** |
| 304 | * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback(). |
| 305 | * |
| 306 | * For an output stream, this function should render and write numFrames of data |
| 307 | * in the streams current data format to the audioData buffer. |
| 308 | * |
| 309 | * For an input stream, this function should read and process numFrames of data |
| 310 | * from the audioData buffer. |
| 311 | * |
| 312 | * Note that this callback function should be considered a "real-time" function. |
| 313 | * It must not do anything that could cause an unbounded delay because that can cause the |
| 314 | * audio to glitch or pop. |
| 315 | * |
| 316 | * These are things the function should NOT do: |
| 317 | * <ul> |
| 318 | * <li>allocate memory using, for example, malloc() or new</li> |
| 319 | * <li>any file operations such as opening, closing, reading or writing</li> |
| 320 | * <li>any network operations such as streaming</li> |
| 321 | * <li>use any mutexes or other synchronization primitives</li> |
| 322 | * <li>sleep</li> |
| 323 | * </ul> |
| 324 | * |
| 325 | * If you need to move data, eg. MIDI commands, in or out of the callback function then |
| 326 | * we recommend the use of non-blocking techniques such as an atomic FIFO. |
| 327 | * |
| 328 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 329 | * @param userData the same address that was passed to AAudioStreamBuilder_setCallback() |
| 330 | * @param audioData a pointer to the audio data |
| 331 | * @param numFrames the number of frames to be processed |
| 332 | * @return AAUDIO_CALLBACK_RESULT_* |
| 333 | */ |
| 334 | typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)( |
| 335 | AAudioStream *stream, |
| 336 | void *userData, |
| 337 | void *audioData, |
| 338 | int32_t numFrames); |
| 339 | |
| 340 | /** |
| 341 | * Request that AAudio call this functions when the stream is running. |
| 342 | * |
| 343 | * Note that when using this callback, the audio data will be passed in or out |
| 344 | * of the function as an argument. |
| 345 | * So you cannot call AAudioStream_write() or AAudioStream_read() on the same stream |
| 346 | * that has an active data callback. |
| 347 | * |
| 348 | * The callback function will start being called after AAudioStream_requestStart() is called. |
| 349 | * It will stop being called after AAudioStream_requestPause() or |
| 350 | * AAudioStream_requestStop() is called. |
| 351 | * |
| 352 | * This callback function will be called on a real-time thread owned by AAudio. See |
Glenn Kasten | 0d80436 | 2017-04-13 09:20:14 -0700 | [diff] [blame] | 353 | * {@link AAudioStream_dataCallback} for more information. |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 354 | * |
| 355 | * Note that the AAudio callbacks will never be called simultaneously from multiple threads. |
| 356 | * |
| 357 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 358 | * @param callback pointer to a function that will process audio data. |
| 359 | * @param userData pointer to an application data structure that will be passed |
| 360 | * to the callback functions. |
| 361 | */ |
| 362 | AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder, |
| 363 | AAudioStream_dataCallback callback, |
| 364 | void *userData); |
| 365 | |
| 366 | /** |
| 367 | * Set the requested data callback buffer size in frames. |
| 368 | * See {@link AAudioStream_dataCallback}. |
| 369 | * |
| 370 | * The default, if you do not call this function, is AAUDIO_UNSPECIFIED. |
| 371 | * |
| 372 | * For the lowest possible latency, do not call this function. AAudio will then |
| 373 | * call the dataProc callback function with whatever size is optimal. |
| 374 | * That size may vary from one callback to another. |
| 375 | * |
| 376 | * Only use this function if the application requires a specific number of frames for processing. |
| 377 | * The application might, for example, be using an FFT that requires |
| 378 | * a specific power-of-two sized buffer. |
| 379 | * |
| 380 | * AAudio may need to add additional buffering in order to adapt between the internal |
| 381 | * buffer size and the requested buffer size. |
| 382 | * |
| 383 | * If you do call this function then the requested size should be less than |
| 384 | * half the buffer capacity, to allow double buffering. |
| 385 | * |
| 386 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 387 | * @param numFrames the desired buffer size in frames or AAUDIO_UNSPECIFIED |
| 388 | */ |
| 389 | AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder, |
| 390 | int32_t numFrames); |
| 391 | |
| 392 | /** |
| 393 | * Prototype for the callback function that is passed to |
| 394 | * AAudioStreamBuilder_setErrorCallback(). |
| 395 | * |
| 396 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 397 | * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback() |
| 398 | * @param error an AAUDIO_ERROR_* value. |
| 399 | */ |
| 400 | typedef void (*AAudioStream_errorCallback)( |
| 401 | AAudioStream *stream, |
| 402 | void *userData, |
| 403 | aaudio_result_t error); |
| 404 | |
| 405 | /** |
| 406 | * Request that AAudio call this functions if any error occurs on a callback thread. |
| 407 | * |
| 408 | * It will be called, for example, if a headset or a USB device is unplugged causing the stream's |
| 409 | * device to be unavailable. |
| 410 | * In response, this function could signal or launch another thread to reopen a |
| 411 | * stream on another device. Do not reopen the stream in this callback. |
| 412 | * |
| 413 | * This will not be called because of actions by the application, such as stopping |
| 414 | * or closing a stream. |
| 415 | * |
| 416 | * Another possible cause of error would be a timeout or an unanticipated internal error. |
| 417 | * |
| 418 | * Note that the AAudio callbacks will never be called simultaneously from multiple threads. |
| 419 | * |
| 420 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 421 | * @param callback pointer to a function that will be called if an error occurs. |
| 422 | * @param userData pointer to an application data structure that will be passed |
| 423 | * to the callback functions. |
| 424 | */ |
| 425 | AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder, |
| 426 | AAudioStream_errorCallback callback, |
| 427 | void *userData); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 428 | |
| 429 | /** |
| 430 | * Open a stream based on the options in the StreamBuilder. |
| 431 | * |
| 432 | * AAudioStream_close must be called when finished with the stream to recover |
| 433 | * the memory and to free the associated resources. |
| 434 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 435 | * @param builder reference provided by AAudio_createStreamBuilder() |
| 436 | * @param stream pointer to a variable to receive the new stream reference |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 437 | * @return AAUDIO_OK or a negative error. |
| 438 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 439 | AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder, |
| 440 | AAudioStream** stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 441 | |
| 442 | /** |
| 443 | * Delete the resources associated with the StreamBuilder. |
| 444 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 445 | * @param builder reference provided by AAudio_createStreamBuilder() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 446 | * @return AAUDIO_OK or a negative error. |
| 447 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 448 | AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 449 | |
| 450 | // ============================================================ |
| 451 | // Stream Control |
| 452 | // ============================================================ |
| 453 | |
| 454 | /** |
| 455 | * Free the resources associated with a stream created by AAudioStreamBuilder_openStream() |
| 456 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 457 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 458 | * @return AAUDIO_OK or a negative error. |
| 459 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 460 | AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 461 | |
| 462 | /** |
| 463 | * Asynchronously request to start playing the stream. For output streams, one should |
| 464 | * write to the stream to fill the buffer before starting. |
| 465 | * Otherwise it will underflow. |
| 466 | * After this call the state will be in AAUDIO_STREAM_STATE_STARTING or AAUDIO_STREAM_STATE_STARTED. |
| 467 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 468 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 469 | * @return AAUDIO_OK or a negative error. |
| 470 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 471 | AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 472 | |
| 473 | /** |
| 474 | * Asynchronous request for the stream to pause. |
| 475 | * Pausing a stream will freeze the data flow but not flush any buffers. |
| 476 | * Use AAudioStream_Start() to resume playback after a pause. |
| 477 | * After this call the state will be in AAUDIO_STREAM_STATE_PAUSING or AAUDIO_STREAM_STATE_PAUSED. |
| 478 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 479 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 480 | * @return AAUDIO_OK or a negative error. |
| 481 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 482 | AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 483 | |
| 484 | /** |
| 485 | * Asynchronous request for the stream to flush. |
| 486 | * Flushing will discard any pending data. |
| 487 | * This call only works if the stream is pausing or paused. TODO review |
| 488 | * Frame counters are not reset by a flush. They may be advanced. |
| 489 | * After this call the state will be in AAUDIO_STREAM_STATE_FLUSHING or AAUDIO_STREAM_STATE_FLUSHED. |
| 490 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 491 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 492 | * @return AAUDIO_OK or a negative error. |
| 493 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 494 | AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 495 | |
| 496 | /** |
| 497 | * Asynchronous request for the stream to stop. |
| 498 | * The stream will stop after all of the data currently buffered has been played. |
| 499 | * After this call the state will be in AAUDIO_STREAM_STATE_STOPPING or AAUDIO_STREAM_STATE_STOPPED. |
| 500 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 501 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 502 | * @return AAUDIO_OK or a negative error. |
| 503 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 504 | AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 505 | |
| 506 | /** |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 507 | * Query the current state of the client, eg. AAUDIO_STREAM_STATE_PAUSING |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 508 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 509 | * This function will immediately return the state without updating the state. |
| 510 | * If you want to update the client state based on the server state then |
| 511 | * call AAudioStream_waitForStateChange() with currentState |
| 512 | * set to AAUDIO_STREAM_STATE_UNKNOWN and a zero timeout. |
| 513 | * |
| 514 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 515 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 516 | AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 517 | |
| 518 | /** |
| 519 | * Wait until the current state no longer matches the input state. |
| 520 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 521 | * This will update the current client state. |
| 522 | * |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 523 | * <pre><code> |
| 524 | * aaudio_stream_state_t currentState; |
| 525 | * aaudio_result_t result = AAudioStream_getState(stream, ¤tState); |
| 526 | * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSING) { |
| 527 | * result = AAudioStream_waitForStateChange( |
| 528 | * stream, currentState, ¤tState, MY_TIMEOUT_NANOS); |
| 529 | * } |
| 530 | * </code></pre> |
| 531 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 532 | * @param stream A reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 533 | * @param inputState The state we want to avoid. |
| 534 | * @param nextState Pointer to a variable that will be set to the new state. |
| 535 | * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. |
| 536 | * @return AAUDIO_OK or a negative error. |
| 537 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 538 | AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream, |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 539 | aaudio_stream_state_t inputState, |
| 540 | aaudio_stream_state_t *nextState, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 541 | int64_t timeoutNanoseconds); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 542 | |
| 543 | // ============================================================ |
| 544 | // Stream I/O |
| 545 | // ============================================================ |
| 546 | |
| 547 | /** |
| 548 | * Read data from the stream. |
| 549 | * |
| 550 | * The call will wait until the read is complete or until it runs out of time. |
| 551 | * If timeoutNanos is zero then this call will not wait. |
| 552 | * |
| 553 | * Note that timeoutNanoseconds is a relative duration in wall clock time. |
| 554 | * Time will not stop if the thread is asleep. |
| 555 | * So it will be implemented using CLOCK_BOOTTIME. |
| 556 | * |
| 557 | * This call is "strong non-blocking" unless it has to wait for data. |
| 558 | * |
| 559 | * @param stream A stream created using AAudioStreamBuilder_openStream(). |
| 560 | * @param buffer The address of the first sample. |
| 561 | * @param numFrames Number of frames to read. Only complete frames will be written. |
| 562 | * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 563 | * @return The number of frames actually read or a negative error. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 564 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 565 | AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream, |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 566 | void *buffer, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 567 | int32_t numFrames, |
| 568 | int64_t timeoutNanoseconds); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 569 | |
| 570 | /** |
| 571 | * Write data to the stream. |
| 572 | * |
| 573 | * The call will wait until the write is complete or until it runs out of time. |
| 574 | * If timeoutNanos is zero then this call will not wait. |
| 575 | * |
| 576 | * Note that timeoutNanoseconds is a relative duration in wall clock time. |
| 577 | * Time will not stop if the thread is asleep. |
| 578 | * So it will be implemented using CLOCK_BOOTTIME. |
| 579 | * |
| 580 | * This call is "strong non-blocking" unless it has to wait for room in the buffer. |
| 581 | * |
| 582 | * @param stream A stream created using AAudioStreamBuilder_openStream(). |
| 583 | * @param buffer The address of the first sample. |
| 584 | * @param numFrames Number of frames to write. Only complete frames will be written. |
| 585 | * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion. |
| 586 | * @return The number of frames actually written or a negative error. |
| 587 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 588 | AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream, |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 589 | const void *buffer, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 590 | int32_t numFrames, |
| 591 | int64_t timeoutNanoseconds); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 592 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 593 | // ============================================================ |
| 594 | // Stream - queries |
| 595 | // ============================================================ |
| 596 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 597 | /** |
| 598 | * This can be used to adjust the latency of the buffer by changing |
| 599 | * the threshold where blocking will occur. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 600 | * By combining this with AAudioStream_getXRunCount(), the latency can be tuned |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 601 | * at run-time for each device. |
| 602 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 603 | * This cannot be set higher than AAudioStream_getBufferCapacityInFrames(). |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 604 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 605 | * Note that you will probably not get the exact size you request. |
| 606 | * Call AAudioStream_getBufferSizeInFrames() to see what the actual final size is. |
| 607 | * |
| 608 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 609 | * @param numFrames requested number of frames that can be filled without blocking |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 610 | * @return actual buffer size in frames or a negative error |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 611 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 612 | AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream, |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 613 | int32_t numFrames); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 614 | |
| 615 | /** |
| 616 | * Query the maximum number of frames that can be filled without blocking. |
| 617 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 618 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 619 | * @return buffer size in frames. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 620 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 621 | AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 622 | |
| 623 | /** |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 624 | * Query the number of frames that the application should read or write at |
| 625 | * one time for optimal performance. It is OK if an application writes |
| 626 | * a different number of frames. But the buffer size may need to be larger |
| 627 | * in order to avoid underruns or overruns. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 628 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 629 | * Note that this may or may not match the actual device burst size. |
| 630 | * For some endpoints, the burst size can vary dynamically. |
| 631 | * But these tend to be devices with high latency. |
| 632 | * |
| 633 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 634 | * @return burst size |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 635 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 636 | AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 637 | |
| 638 | /** |
| 639 | * Query maximum buffer capacity in frames. |
| 640 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 641 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 642 | * @return buffer capacity in frames |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 643 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 644 | AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 645 | |
| 646 | /** |
Phil Burk | e057ca9 | 2017-03-28 11:31:34 -0700 | [diff] [blame] | 647 | * Query the size of the buffer that will be passed to the dataProc callback |
| 648 | * in the numFrames parameter. |
| 649 | * |
| 650 | * This call can be used if the application needs to know the value of numFrames before |
| 651 | * the stream is started. This is not normally necessary. |
| 652 | * |
| 653 | * If a specific size was requested by calling AAudioStreamBuilder_setCallbackSizeInFrames() |
| 654 | * then this will be the same size. |
| 655 | * |
| 656 | * If AAudioStreamBuilder_setCallbackSizeInFrames() was not called then this will |
| 657 | * return the size chosen by AAudio, or AAUDIO_UNSPECIFIED. |
| 658 | * |
| 659 | * AAUDIO_UNSPECIFIED indicates that the callback buffer size for this stream |
| 660 | * may vary from one dataProc callback to the next. |
| 661 | * |
| 662 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 663 | * @return callback buffer size in frames or AAUDIO_UNSPECIFIED |
| 664 | */ |
| 665 | AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream); |
| 666 | |
| 667 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 668 | * An XRun is an Underrun or an Overrun. |
| 669 | * During playing, an underrun will occur if the stream is not written in time |
| 670 | * and the system runs out of valid data. |
| 671 | * During recording, an overrun will occur if the stream is not read in time |
| 672 | * and there is no place to put the incoming data so it is discarded. |
| 673 | * |
| 674 | * An underrun or overrun can cause an audible "pop" or "glitch". |
| 675 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 676 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 677 | * @return the underrun or overrun count |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 678 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 679 | AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 680 | |
| 681 | /** |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 682 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 683 | * @return actual sample rate |
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 int32_t AAudioStream_getSampleRate(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 686 | |
| 687 | /** |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame^] | 688 | * A stream has one or more channels of data. |
| 689 | * A frame will contain one sample for each channel. |
| 690 | * |
| 691 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 692 | * @return actual number of channels |
| 693 | */ |
| 694 | AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream); |
| 695 | |
| 696 | /** |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 697 | * The samplesPerFrame is also known as channelCount. |
| 698 | * |
Phil Burk | 20523ed | 2017-04-24 17:04:01 -0700 | [diff] [blame^] | 699 | * @deprecated use AAudioStream_getChannelCount() |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 700 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 701 | * @return actual samples per frame |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 702 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 703 | AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 704 | |
| 705 | /** |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 706 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 707 | * @return actual device ID |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 708 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 709 | AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 710 | |
| 711 | /** |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 712 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 713 | * @return actual data format |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 714 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 715 | AAUDIO_API aaudio_audio_format_t AAudioStream_getFormat(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 716 | |
| 717 | /** |
| 718 | * Provide actual sharing mode. |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 719 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 720 | * @return actual sharing mode |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 721 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 722 | AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 723 | |
| 724 | /** |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 725 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 726 | * @return direction |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 727 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 728 | AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 729 | |
| 730 | /** |
| 731 | * Passes back the number of frames that have been written since the stream was created. |
| 732 | * For an output stream, this will be advanced by the application calling write(). |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 733 | * For an input stream, this will be advanced by the endpoint. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 734 | * |
| 735 | * The frame position is monotonically increasing. |
| 736 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 737 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 738 | * @return frames written |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 739 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 740 | AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 741 | |
| 742 | /** |
| 743 | * 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] | 744 | * For an output stream, this will be advanced by the endpoint. |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 745 | * For an input stream, this will be advanced by the application calling read(). |
| 746 | * |
| 747 | * The frame position is monotonically increasing. |
| 748 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 749 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
| 750 | * @return frames read |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 751 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 752 | AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 753 | |
| 754 | /** |
| 755 | * Passes back the time at which a particular frame was presented. |
| 756 | * This can be used to synchronize audio with video or MIDI. |
| 757 | * It can also be used to align a recorded stream with a playback stream. |
| 758 | * |
| 759 | * Timestamps are only valid when the stream is in AAUDIO_STREAM_STATE_STARTED. |
| 760 | * AAUDIO_ERROR_INVALID_STATE will be returned if the stream is not started. |
| 761 | * Note that because requestStart() is asynchronous, timestamps will not be valid until |
| 762 | * a short time after calling requestStart(). |
| 763 | * So AAUDIO_ERROR_INVALID_STATE should not be considered a fatal error. |
| 764 | * Just try calling again later. |
| 765 | * |
| 766 | * If an error occurs, then the position and time will not be modified. |
| 767 | * |
| 768 | * The position and time passed back are monotonically increasing. |
| 769 | * |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 770 | * @param stream reference provided by AAudioStreamBuilder_openStream() |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 771 | * @param clockid AAUDIO_CLOCK_MONOTONIC or AAUDIO_CLOCK_BOOTTIME |
| 772 | * @param framePosition pointer to a variable to receive the position |
| 773 | * @param timeNanoseconds pointer to a variable to receive the time |
| 774 | * @return AAUDIO_OK or a negative error |
| 775 | */ |
Phil Burk | e2155ef | 2017-02-24 13:50:29 -0800 | [diff] [blame] | 776 | AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream, |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 777 | clockid_t clockid, |
| 778 | int64_t *framePosition, |
| 779 | int64_t *timeNanoseconds); |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 780 | |
| 781 | #ifdef __cplusplus |
| 782 | } |
| 783 | #endif |
| 784 | |
| 785 | #endif //AAUDIO_AAUDIO_H |
Phil Burk | a45be8b | 2017-04-05 14:45:48 -0700 | [diff] [blame] | 786 | |
| 787 | /** @} */ |