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