blob: 6536542918850014b277572a700391784b4fddaf [file] [log] [blame]
Phil Burk5ed503c2017-02-01 09:38:15 -08001/*
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 Burka45be8b2017-04-05 14:45:48 -070018 * @addtogroup Audio
19 * @{
20 */
21
22/**
23 * @file AAudio.h
24 */
25
26/**
27 * This is the 'C' API for AAudio.
Phil Burk5ed503c2017-02-01 09:38:15 -080028 */
29#ifndef AAUDIO_AAUDIO_H
30#define AAUDIO_AAUDIO_H
31
Phil Burk3316d5e2017-02-15 11:23:01 -080032#include <time.h>
Phil Burk5ed503c2017-02-01 09:38:15 -080033
34#ifdef __cplusplus
35extern "C" {
36#endif
37
Phil Burka4eb0d82017-04-12 15:44:06 -070038/**
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
Phil Burka4eb0d82017-04-12 15:44:06 -070045
46enum {
47 AAUDIO_DIRECTION_OUTPUT,
48 AAUDIO_DIRECTION_INPUT
49};
50typedef int32_t aaudio_direction_t;
51
52enum {
53 AAUDIO_FORMAT_INVALID = -1,
54 AAUDIO_FORMAT_UNSPECIFIED = 0,
55 AAUDIO_FORMAT_PCM_I16,
Phil Burk74733452017-04-18 19:50:28 -070056 AAUDIO_FORMAT_PCM_FLOAT
Phil Burka4eb0d82017-04-12 15:44:06 -070057};
58typedef int32_t aaudio_format_t;
59
Phil Burka4eb0d82017-04-12 15:44:06 -070060enum {
61 AAUDIO_OK,
62 AAUDIO_ERROR_BASE = -900, // TODO review
63 AAUDIO_ERROR_DISCONNECTED,
64 AAUDIO_ERROR_ILLEGAL_ARGUMENT,
Phil Burk17fff382017-05-16 14:06:45 -070065 // reserved
66 AAUDIO_ERROR_INTERNAL = AAUDIO_ERROR_ILLEGAL_ARGUMENT + 2,
Phil Burka4eb0d82017-04-12 15:44:06 -070067 AAUDIO_ERROR_INVALID_STATE,
Phil Burk17fff382017-05-16 14:06:45 -070068 // reserved
69 // reserved
70 AAUDIO_ERROR_INVALID_HANDLE = AAUDIO_ERROR_INVALID_STATE + 3,
71 // reserved
72 AAUDIO_ERROR_UNIMPLEMENTED = AAUDIO_ERROR_INVALID_HANDLE + 2,
Phil Burka4eb0d82017-04-12 15:44:06 -070073 AAUDIO_ERROR_UNAVAILABLE,
74 AAUDIO_ERROR_NO_FREE_HANDLES,
75 AAUDIO_ERROR_NO_MEMORY,
76 AAUDIO_ERROR_NULL,
77 AAUDIO_ERROR_TIMEOUT,
78 AAUDIO_ERROR_WOULD_BLOCK,
79 AAUDIO_ERROR_INVALID_FORMAT,
80 AAUDIO_ERROR_OUT_OF_RANGE,
81 AAUDIO_ERROR_NO_SERVICE,
82 AAUDIO_ERROR_INVALID_RATE
83};
84typedef int32_t aaudio_result_t;
85
86enum
87{
88 AAUDIO_STREAM_STATE_UNINITIALIZED = 0,
89 AAUDIO_STREAM_STATE_UNKNOWN,
90 AAUDIO_STREAM_STATE_OPEN,
91 AAUDIO_STREAM_STATE_STARTING,
92 AAUDIO_STREAM_STATE_STARTED,
93 AAUDIO_STREAM_STATE_PAUSING,
94 AAUDIO_STREAM_STATE_PAUSED,
95 AAUDIO_STREAM_STATE_FLUSHING,
96 AAUDIO_STREAM_STATE_FLUSHED,
97 AAUDIO_STREAM_STATE_STOPPING,
98 AAUDIO_STREAM_STATE_STOPPED,
99 AAUDIO_STREAM_STATE_CLOSING,
100 AAUDIO_STREAM_STATE_CLOSED,
101 AAUDIO_STREAM_STATE_DISCONNECTED
102};
103typedef int32_t aaudio_stream_state_t;
104
105
106enum {
107 /**
108 * This will be the only stream using a particular source or sink.
109 * This mode will provide the lowest possible latency.
110 * You should close EXCLUSIVE streams immediately when you are not using them.
111 */
112 AAUDIO_SHARING_MODE_EXCLUSIVE,
113 /**
114 * Multiple applications will be mixed by the AAudio Server.
115 * This will have higher latency than the EXCLUSIVE mode.
116 */
117 AAUDIO_SHARING_MODE_SHARED
118};
119typedef int32_t aaudio_sharing_mode_t;
120
Phil Burke2fbb592017-05-01 15:05:52 -0700121
122enum {
123 /**
124 * No particular performance needs. Default.
125 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800126 AAUDIO_PERFORMANCE_MODE_NONE = 10,
Phil Burke2fbb592017-05-01 15:05:52 -0700127
128 /**
129 * Extending battery life is most important.
130 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800131 AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
Phil Burke2fbb592017-05-01 15:05:52 -0700132
133 /**
134 * Reducing latency is most important.
135 */
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800136 AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
Phil Burke2fbb592017-05-01 15:05:52 -0700137};
138typedef int32_t aaudio_performance_mode_t;
139
Phil Burk361b1422017-12-20 14:24:16 -0800140/**
141 * The USAGE attribute expresses "why" you are playing a sound, what is this sound used for.
142 * This information is used by certain platforms or routing policies
143 * to make more refined volume or routing decisions.
144 *
145 * Note that these match the equivalent values in AudioAttributes in the Android Java API.
146 */
147enum {
148 /**
149 * Use this for streaming media, music performance, video, podcasts, etcetera.
150 */
151 AAUDIO_USAGE_MEDIA = 1,
152
153 /**
154 * Use this for voice over IP, telephony, etcetera.
155 */
156 AAUDIO_USAGE_VOICE_COMMUNICATION = 2,
157
158 /**
159 * Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.
160 */
161 AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING = 3,
162
163 /**
164 * Use this to demand the users attention.
165 */
166 AAUDIO_USAGE_ALARM = 4,
167
168 /**
169 * Use this for notifying the user when a message has arrived or some
170 * other background event has occured.
171 */
172 AAUDIO_USAGE_NOTIFICATION = 5,
173
174 /**
175 * Use this when the phone rings.
176 */
177 AAUDIO_USAGE_NOTIFICATION_RINGTONE = 6,
178
179 /**
180 * Use this to attract the users attention when, for example, the battery is low.
181 */
182 AAUDIO_USAGE_NOTIFICATION_EVENT = 10,
183
184 /**
185 * Use this for screen readers, etcetera.
186 */
187 AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY = 11,
188
189 /**
190 * Use this for driving or navigation directions.
191 */
192 AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE = 12,
193
194 /**
195 * Use this for user interface sounds, beeps, etcetera.
196 */
197 AAUDIO_USAGE_ASSISTANCE_SONIFICATION = 13,
198
199 /**
200 * Use this for game audio and sound effects.
201 */
202 AAUDIO_USAGE_GAME = 14,
203
204 /**
205 * Use this for audio responses to user queries, audio instructions or help utterances.
206 */
207 AAUDIO_USAGE_ASSISTANT = 16
208};
209typedef int32_t aaudio_usage_t;
210
211/**
212 * The CONTENT_TYPE attribute describes "what" you are playing.
213 * It expresses the general category of the content. This information is optional.
214 * But in case it is known (for instance {@link #AAUDIO_CONTENT_TYPE_MOVIE} for a
215 * movie streaming service or {@link #AAUDIO_CONTENT_TYPE_SPEECH} for
216 * an audio book application) this information might be used by the audio framework to
217 * enforce audio focus.
218 *
219 * Note that these match the equivalent values in AudioAttributes in the Android Java API.
220 */
221enum {
222
223 /**
224 * Use this for spoken voice, audio books, etcetera.
225 */
226 AAUDIO_CONTENT_TYPE_SPEECH = 1,
227
228 /**
229 * Use this for pre-recorded or live music.
230 */
231 AAUDIO_CONTENT_TYPE_MUSIC = 2,
232
233 /**
234 * Use this for a movie or video soundtrack.
235 */
236 AAUDIO_CONTENT_TYPE_MOVIE = 3,
237
238 /**
239 * Use this for sound is designed to accompany a user action,
240 * such as a click or beep sound made when the user presses a button.
241 */
242 AAUDIO_CONTENT_TYPE_SONIFICATION = 4
243};
244typedef int32_t aaudio_content_type_t;
245
246/**
247 * Defines the audio source.
248 * An audio source defines both a default physical source of audio signal, and a recording
249 * configuration.
250 *
251 * Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.
252 */
253enum {
254 /**
255 * Use this preset when other presets do not apply.
256 */
257 AAUDIO_INPUT_PRESET_GENERIC = 1,
258
259 /**
260 * Use this preset when recording video.
261 */
262 AAUDIO_INPUT_PRESET_CAMCORDER = 5,
263
264 /**
265 * Use this preset when doing speech recognition.
266 */
267 AAUDIO_INPUT_PRESET_VOICE_RECOGNITION = 6,
268
269 /**
270 * Use this preset when doing telephony or voice messaging.
271 */
272 AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION = 7,
273
274 /**
275 * Use this preset to obtain an input with no effects.
276 * Note that this input will not have automatic gain control
277 * so the recorded volume may be very low.
278 */
279 AAUDIO_INPUT_PRESET_UNPROCESSED = 9,
280};
281typedef int32_t aaudio_input_preset_t;
282
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800283enum {
284 /**
285 * Do not allocate a session ID.
286 * Effects cannot be used with this stream.
287 * Default.
288 */
289 AAUDIO_SESSION_ID_NONE = -1,
290
291 /**
292 * Allocate a session ID that can be used to attach and control
293 * effects using the Java AudioEffects API.
294 * Note that the use of this flag may result in higher latency.
295 *
296 * Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.
297 */
298 AAUDIO_SESSION_ID_ALLOCATE = 0,
299};
300typedef int32_t aaudio_session_id_t;
301
Phil Burke2155ef2017-02-24 13:50:29 -0800302typedef struct AAudioStreamStruct AAudioStream;
303typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder;
Phil Burk5ed503c2017-02-01 09:38:15 -0800304
Phil Burk5ed503c2017-02-01 09:38:15 -0800305#ifndef AAUDIO_API
Phil Burk3316d5e2017-02-15 11:23:01 -0800306#define AAUDIO_API /* export this symbol */
Phil Burk5ed503c2017-02-01 09:38:15 -0800307#endif
308
309// ============================================================
310// Audio System
311// ============================================================
312
313/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800314 * The text is the ASCII symbol corresponding to the returnCode,
315 * or an English message saying the returnCode is unrecognized.
316 * This is intended for developers to use when debugging.
317 * It is not for display to users.
318 *
319 * @return pointer to a text representation of an AAudio result code.
320 */
321AAUDIO_API const char * AAudio_convertResultToText(aaudio_result_t returnCode);
322
323/**
324 * The text is the ASCII symbol corresponding to the stream state,
325 * or an English message saying the state is unrecognized.
326 * This is intended for developers to use when debugging.
327 * It is not for display to users.
328 *
329 * @return pointer to a text representation of an AAudio state.
330 */
331AAUDIO_API const char * AAudio_convertStreamStateToText(aaudio_stream_state_t state);
332
333// ============================================================
334// StreamBuilder
335// ============================================================
336
337/**
338 * Create a StreamBuilder that can be used to open a Stream.
339 *
340 * The deviceId is initially unspecified, meaning that the current default device will be used.
341 *
342 * The default direction is AAUDIO_DIRECTION_OUTPUT.
Phil Burk3316d5e2017-02-15 11:23:01 -0800343 * The default sharing mode is AAUDIO_SHARING_MODE_SHARED.
Phil Burk5ed503c2017-02-01 09:38:15 -0800344 * The data format, samplesPerFrames and sampleRate are unspecified and will be
345 * chosen by the device when it is opened.
346 *
347 * AAudioStreamBuilder_delete() must be called when you are done using the builder.
348 */
Phil Burke2155ef2017-02-24 13:50:29 -0800349AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** builder);
Phil Burk5ed503c2017-02-01 09:38:15 -0800350
351/**
352 * Request an audio device identified device using an ID.
Phil Burk5ed503c2017-02-01 09:38:15 -0800353 * On Android, for example, the ID could be obtained from the Java AudioManager.
354 *
Glenn Kasten5f510d22017-05-30 15:52:15 -0700355 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED,
Phil Burke057ca92017-03-28 11:31:34 -0700356 * in which case the primary device will be used.
Phil Burk5ed503c2017-02-01 09:38:15 -0800357 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800358 * @param builder reference provided by AAudio_createStreamBuilder()
Glenn Kasten5f510d22017-05-30 15:52:15 -0700359 * @param deviceId device identifier or AAUDIO_UNSPECIFIED
Phil Burk5ed503c2017-02-01 09:38:15 -0800360 */
Phil Burke2155ef2017-02-24 13:50:29 -0800361AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
Phil Burk3316d5e2017-02-15 11:23:01 -0800362 int32_t deviceId);
Phil Burk5ed503c2017-02-01 09:38:15 -0800363
364/**
Phil Burke057ca92017-03-28 11:31:34 -0700365 * Request a sample rate in Hertz.
366 *
Phil Burke057ca92017-03-28 11:31:34 -0700367 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700368 * An optimal value will then be chosen when the stream is opened.
369 * After opening a stream with an unspecified value, the application must
370 * query for the actual value, which may vary by device.
371 *
372 * If an exact value is specified then an opened stream will use that value.
373 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700374 *
375 * @param builder reference provided by AAudio_createStreamBuilder()
376 * @param sampleRate frames per second. Common rates include 44100 and 48000 Hz.
Phil Burk5ed503c2017-02-01 09:38:15 -0800377 */
Phil Burke2155ef2017-02-24 13:50:29 -0800378AAUDIO_API void AAudioStreamBuilder_setSampleRate(AAudioStreamBuilder* builder,
Phil Burk3316d5e2017-02-15 11:23:01 -0800379 int32_t sampleRate);
Phil Burk5ed503c2017-02-01 09:38:15 -0800380
381/**
Phil Burk20523ed2017-04-24 17:04:01 -0700382 * Request a number of channels for the stream.
Phil Burke057ca92017-03-28 11:31:34 -0700383 *
Phil Burke057ca92017-03-28 11:31:34 -0700384 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700385 * An optimal value will then be chosen when the stream is opened.
386 * After opening a stream with an unspecified value, the application must
387 * query for the actual value, which may vary by device.
Phil Burk5ed503c2017-02-01 09:38:15 -0800388 *
Phil Burk8f624892017-05-11 11:44:20 -0700389 * If an exact value is specified then an opened stream will use that value.
390 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700391 *
392 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk20523ed2017-04-24 17:04:01 -0700393 * @param channelCount Number of channels desired.
Phil Burk5ed503c2017-02-01 09:38:15 -0800394 */
Phil Burk20523ed2017-04-24 17:04:01 -0700395AAUDIO_API void AAudioStreamBuilder_setChannelCount(AAudioStreamBuilder* builder,
396 int32_t channelCount);
397
398/**
Phil Burke74240d2017-08-03 15:25:43 -0700399 * Identical to AAudioStreamBuilder_setChannelCount().
400 *
401 * @param builder reference provided by AAudio_createStreamBuilder()
402 * @param samplesPerFrame Number of samples in a frame.
403 */
404AAUDIO_API void AAudioStreamBuilder_setSamplesPerFrame(AAudioStreamBuilder* builder,
405 int32_t samplesPerFrame);
406
407/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800408 * Request a sample data format, for example AAUDIO_FORMAT_PCM_I16.
Phil Burke057ca92017-03-28 11:31:34 -0700409 *
410 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk8f624892017-05-11 11:44:20 -0700411 * An optimal value will then be chosen when the stream is opened.
412 * After opening a stream with an unspecified value, the application must
413 * query for the actual value, which may vary by device.
Phil Burke057ca92017-03-28 11:31:34 -0700414 *
Phil Burk8f624892017-05-11 11:44:20 -0700415 * If an exact value is specified then an opened stream will use that value.
416 * If a stream cannot be opened with the specified value then the open will fail.
Phil Burke057ca92017-03-28 11:31:34 -0700417 *
418 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk8f624892017-05-11 11:44:20 -0700419 * @param format common formats are AAUDIO_FORMAT_PCM_FLOAT and AAUDIO_FORMAT_PCM_I16.
Phil Burk5ed503c2017-02-01 09:38:15 -0800420 */
Phil Burke2155ef2017-02-24 13:50:29 -0800421AAUDIO_API void AAudioStreamBuilder_setFormat(AAudioStreamBuilder* builder,
Phil Burk9dca9822017-05-26 14:27:43 -0700422 aaudio_format_t format);
Phil Burk5ed503c2017-02-01 09:38:15 -0800423
424/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800425 * Request a mode for sharing the device.
Phil Burke057ca92017-03-28 11:31:34 -0700426 *
427 * The default, if you do not call this function, is AAUDIO_SHARING_MODE_SHARED.
428 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800429 * The requested sharing mode may not be available.
Phil Burke057ca92017-03-28 11:31:34 -0700430 * The application can query for the actual mode after the stream is opened.
Phil Burk5ed503c2017-02-01 09:38:15 -0800431 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800432 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burke057ca92017-03-28 11:31:34 -0700433 * @param sharingMode AAUDIO_SHARING_MODE_SHARED or AAUDIO_SHARING_MODE_EXCLUSIVE
Phil Burk5ed503c2017-02-01 09:38:15 -0800434 */
Phil Burke2155ef2017-02-24 13:50:29 -0800435AAUDIO_API void AAudioStreamBuilder_setSharingMode(AAudioStreamBuilder* builder,
Phil Burk5ed503c2017-02-01 09:38:15 -0800436 aaudio_sharing_mode_t sharingMode);
437
438/**
Phil Burke057ca92017-03-28 11:31:34 -0700439 * Request the direction for a stream.
440 *
441 * The default, if you do not call this function, is AAUDIO_DIRECTION_OUTPUT.
Phil Burk5ed503c2017-02-01 09:38:15 -0800442 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800443 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800444 * @param direction AAUDIO_DIRECTION_OUTPUT or AAUDIO_DIRECTION_INPUT
Phil Burk5ed503c2017-02-01 09:38:15 -0800445 */
Phil Burke2155ef2017-02-24 13:50:29 -0800446AAUDIO_API void AAudioStreamBuilder_setDirection(AAudioStreamBuilder* builder,
Phil Burk3df348f2017-02-08 11:41:55 -0800447 aaudio_direction_t direction);
Phil Burk5ed503c2017-02-01 09:38:15 -0800448
449/**
Phil Burke057ca92017-03-28 11:31:34 -0700450 * Set the requested buffer capacity in frames.
Phil Burk3df348f2017-02-08 11:41:55 -0800451 * The final AAudioStream capacity may differ, but will probably be at least this big.
452 *
Phil Burke057ca92017-03-28 11:31:34 -0700453 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
Phil Burk3df348f2017-02-08 11:41:55 -0800454 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800455 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burke057ca92017-03-28 11:31:34 -0700456 * @param numFrames the desired buffer capacity in frames or AAUDIO_UNSPECIFIED
Phil Burk3df348f2017-02-08 11:41:55 -0800457 */
Phil Burke2155ef2017-02-24 13:50:29 -0800458AAUDIO_API void AAudioStreamBuilder_setBufferCapacityInFrames(AAudioStreamBuilder* builder,
Phil Burke057ca92017-03-28 11:31:34 -0700459 int32_t numFrames);
Phil Burke2fbb592017-05-01 15:05:52 -0700460
461/**
462 * Set the requested performance mode.
463 *
464 * The default, if you do not call this function, is AAUDIO_PERFORMANCE_MODE_NONE.
465 *
466 * @param builder reference provided by AAudio_createStreamBuilder()
467 * @param mode the desired performance mode, eg. AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
468 */
469AAUDIO_API void AAudioStreamBuilder_setPerformanceMode(AAudioStreamBuilder* builder,
470 aaudio_performance_mode_t mode);
471
Phil Burke057ca92017-03-28 11:31:34 -0700472/**
Phil Burk361b1422017-12-20 14:24:16 -0800473 * Set the intended use case for the stream.
474 *
475 * The AAudio system will use this information to optimize the
476 * behavior of the stream.
477 * This could, for example, affect how volume and focus is handled for the stream.
478 *
479 * The default, if you do not call this function, is AAUDIO_USAGE_MEDIA.
480 *
481 * @param builder reference provided by AAudio_createStreamBuilder()
482 * @param usage the desired usage, eg. AAUDIO_USAGE_GAME
483 */
484AAUDIO_API void AAudioStreamBuilder_setUsage(AAudioStreamBuilder* builder,
485 aaudio_usage_t usage);
486
487/**
488 * Set the type of audio data that the stream will carry.
489 *
490 * The AAudio system will use this information to optimize the
491 * behavior of the stream.
492 * This could, for example, affect whether a stream is paused when a notification occurs.
493 *
494 * The default, if you do not call this function, is AAUDIO_CONTENT_TYPE_MUSIC.
495 *
496 * @param builder reference provided by AAudio_createStreamBuilder()
497 * @param contentType the type of audio data, eg. AAUDIO_CONTENT_TYPE_SPEECH
498 */
499AAUDIO_API void AAudioStreamBuilder_setContentType(AAudioStreamBuilder* builder,
500 aaudio_content_type_t contentType);
501
502/**
503 * Set the input (capture) preset for the stream.
504 *
505 * The AAudio system will use this information to optimize the
506 * behavior of the stream.
507 * This could, for example, affect which microphones are used and how the
508 * recorded data is processed.
509 *
510 * The default, if you do not call this function, is AAUDIO_INPUT_PRESET_GENERIC.
511 *
512 * @param builder reference provided by AAudio_createStreamBuilder()
513 * @param inputPreset the desired configuration for recording
514 */
515AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
516 aaudio_input_preset_t inputPreset);
517
Phil Burk7e7dcaa2018-01-03 15:16:15 -0800518/** Set the requested session ID.
519 *
520 * The session ID can be used to associate a stream with effects processors.
521 * The effects are controlled using the Android AudioEffect Java API.
522 *
523 * The default, if you do not call this function, is AAUDIO_SESSION_ID_NONE.
524 *
525 * If set to AAUDIO_SESSION_ID_ALLOCATE then a session ID will be allocated
526 * when the stream is opened.
527 *
528 * The allocated session ID can be obtained by calling AAudioStream_getSessionId()
529 * and then used with this function when opening another stream.
530 * This allows effects to be shared between streams.
531 *
532 * Session IDs from AAudio can be used the Android Java APIs and vice versa.
533 * So a session ID from an AAudio stream can be passed to Java
534 * and effects applied using the Java AudioEffect API.
535 *
536 * Allocated session IDs will always be positive and nonzero.
537 *
538 * @param builder reference provided by AAudio_createStreamBuilder()
539 * @param sessionId an allocated sessionID or AAUDIO_SESSION_ID_ALLOCATE
540 */
541AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
542 aaudio_session_id_t sessionId);
543
Phil Burk361b1422017-12-20 14:24:16 -0800544/**
Phil Burke057ca92017-03-28 11:31:34 -0700545 * Return one of these values from the data callback function.
546 */
547enum {
548
549 /**
550 * Continue calling the callback.
551 */
552 AAUDIO_CALLBACK_RESULT_CONTINUE = 0,
553
554 /**
555 * Stop calling the callback.
556 *
557 * The application will still need to call AAudioStream_requestPause()
558 * or AAudioStream_requestStop().
559 */
560 AAUDIO_CALLBACK_RESULT_STOP,
561
562};
563typedef int32_t aaudio_data_callback_result_t;
564
565/**
566 * Prototype for the data function that is passed to AAudioStreamBuilder_setDataCallback().
567 *
568 * For an output stream, this function should render and write numFrames of data
569 * in the streams current data format to the audioData buffer.
570 *
571 * For an input stream, this function should read and process numFrames of data
572 * from the audioData buffer.
573 *
574 * Note that this callback function should be considered a "real-time" function.
575 * It must not do anything that could cause an unbounded delay because that can cause the
576 * audio to glitch or pop.
577 *
578 * These are things the function should NOT do:
579 * <ul>
580 * <li>allocate memory using, for example, malloc() or new</li>
581 * <li>any file operations such as opening, closing, reading or writing</li>
582 * <li>any network operations such as streaming</li>
583 * <li>use any mutexes or other synchronization primitives</li>
584 * <li>sleep</li>
585 * </ul>
586 *
587 * If you need to move data, eg. MIDI commands, in or out of the callback function then
588 * we recommend the use of non-blocking techniques such as an atomic FIFO.
589 *
590 * @param stream reference provided by AAudioStreamBuilder_openStream()
591 * @param userData the same address that was passed to AAudioStreamBuilder_setCallback()
592 * @param audioData a pointer to the audio data
593 * @param numFrames the number of frames to be processed
594 * @return AAUDIO_CALLBACK_RESULT_*
595 */
596typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
597 AAudioStream *stream,
598 void *userData,
599 void *audioData,
600 int32_t numFrames);
601
602/**
603 * Request that AAudio call this functions when the stream is running.
604 *
605 * Note that when using this callback, the audio data will be passed in or out
606 * of the function as an argument.
607 * So you cannot call AAudioStream_write() or AAudioStream_read() on the same stream
608 * that has an active data callback.
609 *
610 * The callback function will start being called after AAudioStream_requestStart() is called.
611 * It will stop being called after AAudioStream_requestPause() or
612 * AAudioStream_requestStop() is called.
613 *
614 * This callback function will be called on a real-time thread owned by AAudio. See
Glenn Kasten0d804362017-04-13 09:20:14 -0700615 * {@link AAudioStream_dataCallback} for more information.
Phil Burke057ca92017-03-28 11:31:34 -0700616 *
617 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
618 *
619 * @param builder reference provided by AAudio_createStreamBuilder()
620 * @param callback pointer to a function that will process audio data.
621 * @param userData pointer to an application data structure that will be passed
622 * to the callback functions.
623 */
624AAUDIO_API void AAudioStreamBuilder_setDataCallback(AAudioStreamBuilder* builder,
625 AAudioStream_dataCallback callback,
626 void *userData);
627
628/**
629 * Set the requested data callback buffer size in frames.
630 * See {@link AAudioStream_dataCallback}.
631 *
632 * The default, if you do not call this function, is AAUDIO_UNSPECIFIED.
633 *
634 * For the lowest possible latency, do not call this function. AAudio will then
635 * call the dataProc callback function with whatever size is optimal.
636 * That size may vary from one callback to another.
637 *
638 * Only use this function if the application requires a specific number of frames for processing.
639 * The application might, for example, be using an FFT that requires
640 * a specific power-of-two sized buffer.
641 *
642 * AAudio may need to add additional buffering in order to adapt between the internal
643 * buffer size and the requested buffer size.
644 *
645 * If you do call this function then the requested size should be less than
646 * half the buffer capacity, to allow double buffering.
647 *
648 * @param builder reference provided by AAudio_createStreamBuilder()
649 * @param numFrames the desired buffer size in frames or AAUDIO_UNSPECIFIED
650 */
651AAUDIO_API void AAudioStreamBuilder_setFramesPerDataCallback(AAudioStreamBuilder* builder,
652 int32_t numFrames);
653
654/**
655 * Prototype for the callback function that is passed to
656 * AAudioStreamBuilder_setErrorCallback().
657 *
658 * @param stream reference provided by AAudioStreamBuilder_openStream()
659 * @param userData the same address that was passed to AAudioStreamBuilder_setErrorCallback()
660 * @param error an AAUDIO_ERROR_* value.
661 */
662typedef void (*AAudioStream_errorCallback)(
663 AAudioStream *stream,
664 void *userData,
665 aaudio_result_t error);
666
667/**
668 * Request that AAudio call this functions if any error occurs on a callback thread.
669 *
670 * It will be called, for example, if a headset or a USB device is unplugged causing the stream's
671 * device to be unavailable.
672 * In response, this function could signal or launch another thread to reopen a
673 * stream on another device. Do not reopen the stream in this callback.
674 *
675 * This will not be called because of actions by the application, such as stopping
676 * or closing a stream.
677 *
678 * Another possible cause of error would be a timeout or an unanticipated internal error.
679 *
680 * Note that the AAudio callbacks will never be called simultaneously from multiple threads.
681 *
682 * @param builder reference provided by AAudio_createStreamBuilder()
683 * @param callback pointer to a function that will be called if an error occurs.
684 * @param userData pointer to an application data structure that will be passed
685 * to the callback functions.
686 */
687AAUDIO_API void AAudioStreamBuilder_setErrorCallback(AAudioStreamBuilder* builder,
688 AAudioStream_errorCallback callback,
689 void *userData);
Phil Burk5ed503c2017-02-01 09:38:15 -0800690
691/**
692 * Open a stream based on the options in the StreamBuilder.
693 *
694 * AAudioStream_close must be called when finished with the stream to recover
695 * the memory and to free the associated resources.
696 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800697 * @param builder reference provided by AAudio_createStreamBuilder()
698 * @param stream pointer to a variable to receive the new stream reference
Phil Burk5ed503c2017-02-01 09:38:15 -0800699 * @return AAUDIO_OK or a negative error.
700 */
Phil Burke2155ef2017-02-24 13:50:29 -0800701AAUDIO_API aaudio_result_t AAudioStreamBuilder_openStream(AAudioStreamBuilder* builder,
702 AAudioStream** stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800703
704/**
705 * Delete the resources associated with the StreamBuilder.
706 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800707 * @param builder reference provided by AAudio_createStreamBuilder()
Phil Burk5ed503c2017-02-01 09:38:15 -0800708 * @return AAUDIO_OK or a negative error.
709 */
Phil Burke2155ef2017-02-24 13:50:29 -0800710AAUDIO_API aaudio_result_t AAudioStreamBuilder_delete(AAudioStreamBuilder* builder);
Phil Burk5ed503c2017-02-01 09:38:15 -0800711
712// ============================================================
713// Stream Control
714// ============================================================
715
716/**
717 * Free the resources associated with a stream created by AAudioStreamBuilder_openStream()
718 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800719 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800720 * @return AAUDIO_OK or a negative error.
721 */
Phil Burke2155ef2017-02-24 13:50:29 -0800722AAUDIO_API aaudio_result_t AAudioStream_close(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800723
724/**
725 * Asynchronously request to start playing the stream. For output streams, one should
726 * write to the stream to fill the buffer before starting.
727 * Otherwise it will underflow.
728 * After this call the state will be in AAUDIO_STREAM_STATE_STARTING or AAUDIO_STREAM_STATE_STARTED.
729 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800730 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800731 * @return AAUDIO_OK or a negative error.
732 */
Phil Burke2155ef2017-02-24 13:50:29 -0800733AAUDIO_API aaudio_result_t AAudioStream_requestStart(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800734
735/**
736 * Asynchronous request for the stream to pause.
737 * Pausing a stream will freeze the data flow but not flush any buffers.
738 * Use AAudioStream_Start() to resume playback after a pause.
739 * After this call the state will be in AAUDIO_STREAM_STATE_PAUSING or AAUDIO_STREAM_STATE_PAUSED.
740 *
Phil Burk068c10f2017-05-08 16:36:41 -0700741 * This will return AAUDIO_ERROR_UNIMPLEMENTED for input streams.
742 * For input streams use AAudioStream_requestStop().
743 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800744 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800745 * @return AAUDIO_OK or a negative error.
746 */
Phil Burke2155ef2017-02-24 13:50:29 -0800747AAUDIO_API aaudio_result_t AAudioStream_requestPause(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800748
749/**
750 * Asynchronous request for the stream to flush.
751 * Flushing will discard any pending data.
752 * This call only works if the stream is pausing or paused. TODO review
753 * Frame counters are not reset by a flush. They may be advanced.
754 * After this call the state will be in AAUDIO_STREAM_STATE_FLUSHING or AAUDIO_STREAM_STATE_FLUSHED.
755 *
Phil Burk068c10f2017-05-08 16:36:41 -0700756 * This will return AAUDIO_ERROR_UNIMPLEMENTED for input streams.
757 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800758 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800759 * @return AAUDIO_OK or a negative error.
760 */
Phil Burke2155ef2017-02-24 13:50:29 -0800761AAUDIO_API aaudio_result_t AAudioStream_requestFlush(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800762
763/**
764 * Asynchronous request for the stream to stop.
765 * The stream will stop after all of the data currently buffered has been played.
766 * After this call the state will be in AAUDIO_STREAM_STATE_STOPPING or AAUDIO_STREAM_STATE_STOPPED.
767 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800768 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800769 * @return AAUDIO_OK or a negative error.
770 */
Phil Burke2155ef2017-02-24 13:50:29 -0800771AAUDIO_API aaudio_result_t AAudioStream_requestStop(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800772
773/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800774 * Query the current state of the client, eg. AAUDIO_STREAM_STATE_PAUSING
Phil Burk5ed503c2017-02-01 09:38:15 -0800775 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800776 * This function will immediately return the state without updating the state.
777 * If you want to update the client state based on the server state then
778 * call AAudioStream_waitForStateChange() with currentState
779 * set to AAUDIO_STREAM_STATE_UNKNOWN and a zero timeout.
780 *
781 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800782 */
Phil Burke2155ef2017-02-24 13:50:29 -0800783AAUDIO_API aaudio_stream_state_t AAudioStream_getState(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800784
785/**
786 * Wait until the current state no longer matches the input state.
787 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800788 * This will update the current client state.
789 *
Phil Burk5ed503c2017-02-01 09:38:15 -0800790 * <pre><code>
791 * aaudio_stream_state_t currentState;
792 * aaudio_result_t result = AAudioStream_getState(stream, &currentState);
793 * while (result == AAUDIO_OK && currentState != AAUDIO_STREAM_STATE_PAUSING) {
794 * result = AAudioStream_waitForStateChange(
795 * stream, currentState, &currentState, MY_TIMEOUT_NANOS);
796 * }
797 * </code></pre>
798 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800799 * @param stream A reference provided by AAudioStreamBuilder_openStream()
Phil Burk5ed503c2017-02-01 09:38:15 -0800800 * @param inputState The state we want to avoid.
801 * @param nextState Pointer to a variable that will be set to the new state.
802 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
803 * @return AAUDIO_OK or a negative error.
804 */
Phil Burke2155ef2017-02-24 13:50:29 -0800805AAUDIO_API aaudio_result_t AAudioStream_waitForStateChange(AAudioStream* stream,
Phil Burk5ed503c2017-02-01 09:38:15 -0800806 aaudio_stream_state_t inputState,
807 aaudio_stream_state_t *nextState,
Phil Burk3316d5e2017-02-15 11:23:01 -0800808 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800809
810// ============================================================
811// Stream I/O
812// ============================================================
813
814/**
815 * Read data from the stream.
816 *
817 * The call will wait until the read is complete or until it runs out of time.
818 * If timeoutNanos is zero then this call will not wait.
819 *
820 * Note that timeoutNanoseconds is a relative duration in wall clock time.
821 * Time will not stop if the thread is asleep.
822 * So it will be implemented using CLOCK_BOOTTIME.
823 *
824 * This call is "strong non-blocking" unless it has to wait for data.
825 *
826 * @param stream A stream created using AAudioStreamBuilder_openStream().
827 * @param buffer The address of the first sample.
828 * @param numFrames Number of frames to read. Only complete frames will be written.
829 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
Phil Burk3316d5e2017-02-15 11:23:01 -0800830 * @return The number of frames actually read or a negative error.
Phil Burk5ed503c2017-02-01 09:38:15 -0800831 */
Phil Burke2155ef2017-02-24 13:50:29 -0800832AAUDIO_API aaudio_result_t AAudioStream_read(AAudioStream* stream,
Phil Burk5ed503c2017-02-01 09:38:15 -0800833 void *buffer,
Phil Burk3316d5e2017-02-15 11:23:01 -0800834 int32_t numFrames,
835 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800836
837/**
838 * Write data to the stream.
839 *
840 * The call will wait until the write is complete or until it runs out of time.
841 * If timeoutNanos is zero then this call will not wait.
842 *
843 * Note that timeoutNanoseconds is a relative duration in wall clock time.
844 * Time will not stop if the thread is asleep.
845 * So it will be implemented using CLOCK_BOOTTIME.
846 *
847 * This call is "strong non-blocking" unless it has to wait for room in the buffer.
848 *
849 * @param stream A stream created using AAudioStreamBuilder_openStream().
850 * @param buffer The address of the first sample.
851 * @param numFrames Number of frames to write. Only complete frames will be written.
852 * @param timeoutNanoseconds Maximum number of nanoseconds to wait for completion.
853 * @return The number of frames actually written or a negative error.
854 */
Phil Burke2155ef2017-02-24 13:50:29 -0800855AAUDIO_API aaudio_result_t AAudioStream_write(AAudioStream* stream,
Phil Burk5ed503c2017-02-01 09:38:15 -0800856 const void *buffer,
Phil Burk3316d5e2017-02-15 11:23:01 -0800857 int32_t numFrames,
858 int64_t timeoutNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -0800859
Phil Burk5ed503c2017-02-01 09:38:15 -0800860// ============================================================
861// Stream - queries
862// ============================================================
863
Phil Burk5ed503c2017-02-01 09:38:15 -0800864/**
865 * This can be used to adjust the latency of the buffer by changing
866 * the threshold where blocking will occur.
Phil Burk3316d5e2017-02-15 11:23:01 -0800867 * By combining this with AAudioStream_getXRunCount(), the latency can be tuned
Phil Burk5ed503c2017-02-01 09:38:15 -0800868 * at run-time for each device.
869 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800870 * This cannot be set higher than AAudioStream_getBufferCapacityInFrames().
Phil Burk5ed503c2017-02-01 09:38:15 -0800871 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800872 * Note that you will probably not get the exact size you request.
873 * Call AAudioStream_getBufferSizeInFrames() to see what the actual final size is.
874 *
875 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -0700876 * @param numFrames requested number of frames that can be filled without blocking
Phil Burk3316d5e2017-02-15 11:23:01 -0800877 * @return actual buffer size in frames or a negative error
Phil Burk5ed503c2017-02-01 09:38:15 -0800878 */
Phil Burke2155ef2017-02-24 13:50:29 -0800879AAUDIO_API aaudio_result_t AAudioStream_setBufferSizeInFrames(AAudioStream* stream,
Phil Burke057ca92017-03-28 11:31:34 -0700880 int32_t numFrames);
Phil Burk5ed503c2017-02-01 09:38:15 -0800881
882/**
883 * Query the maximum number of frames that can be filled without blocking.
884 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800885 * @param stream reference provided by AAudioStreamBuilder_openStream()
886 * @return buffer size in frames.
Phil Burk5ed503c2017-02-01 09:38:15 -0800887 */
Phil Burke2155ef2017-02-24 13:50:29 -0800888AAUDIO_API int32_t AAudioStream_getBufferSizeInFrames(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800889
890/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800891 * Query the number of frames that the application should read or write at
892 * one time for optimal performance. It is OK if an application writes
893 * a different number of frames. But the buffer size may need to be larger
894 * in order to avoid underruns or overruns.
Phil Burk5ed503c2017-02-01 09:38:15 -0800895 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800896 * Note that this may or may not match the actual device burst size.
897 * For some endpoints, the burst size can vary dynamically.
898 * But these tend to be devices with high latency.
899 *
900 * @param stream reference provided by AAudioStreamBuilder_openStream()
901 * @return burst size
Phil Burk5ed503c2017-02-01 09:38:15 -0800902 */
Phil Burke2155ef2017-02-24 13:50:29 -0800903AAUDIO_API int32_t AAudioStream_getFramesPerBurst(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800904
905/**
906 * Query maximum buffer capacity in frames.
907 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800908 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke057ca92017-03-28 11:31:34 -0700909 * @return buffer capacity in frames
Phil Burk5ed503c2017-02-01 09:38:15 -0800910 */
Phil Burke2155ef2017-02-24 13:50:29 -0800911AAUDIO_API int32_t AAudioStream_getBufferCapacityInFrames(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800912
913/**
Phil Burke057ca92017-03-28 11:31:34 -0700914 * Query the size of the buffer that will be passed to the dataProc callback
915 * in the numFrames parameter.
916 *
917 * This call can be used if the application needs to know the value of numFrames before
918 * the stream is started. This is not normally necessary.
919 *
920 * If a specific size was requested by calling AAudioStreamBuilder_setCallbackSizeInFrames()
921 * then this will be the same size.
922 *
923 * If AAudioStreamBuilder_setCallbackSizeInFrames() was not called then this will
924 * return the size chosen by AAudio, or AAUDIO_UNSPECIFIED.
925 *
926 * AAUDIO_UNSPECIFIED indicates that the callback buffer size for this stream
927 * may vary from one dataProc callback to the next.
928 *
929 * @param stream reference provided by AAudioStreamBuilder_openStream()
930 * @return callback buffer size in frames or AAUDIO_UNSPECIFIED
931 */
932AAUDIO_API int32_t AAudioStream_getFramesPerDataCallback(AAudioStream* stream);
933
934/**
Phil Burk5ed503c2017-02-01 09:38:15 -0800935 * An XRun is an Underrun or an Overrun.
936 * During playing, an underrun will occur if the stream is not written in time
937 * and the system runs out of valid data.
938 * During recording, an overrun will occur if the stream is not read in time
939 * and there is no place to put the incoming data so it is discarded.
940 *
941 * An underrun or overrun can cause an audible "pop" or "glitch".
942 *
Phil Burk068c10f2017-05-08 16:36:41 -0700943 * Note that some INPUT devices may not support this function.
944 * In that case a 0 will always be returned.
945 *
Phil Burk3316d5e2017-02-15 11:23:01 -0800946 * @param stream reference provided by AAudioStreamBuilder_openStream()
947 * @return the underrun or overrun count
Phil Burk5ed503c2017-02-01 09:38:15 -0800948 */
Phil Burke2155ef2017-02-24 13:50:29 -0800949AAUDIO_API int32_t AAudioStream_getXRunCount(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800950
951/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800952 * @param stream reference provided by AAudioStreamBuilder_openStream()
953 * @return actual sample rate
Phil Burk5ed503c2017-02-01 09:38:15 -0800954 */
Phil Burke2155ef2017-02-24 13:50:29 -0800955AAUDIO_API int32_t AAudioStream_getSampleRate(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800956
957/**
Phil Burk20523ed2017-04-24 17:04:01 -0700958 * A stream has one or more channels of data.
959 * A frame will contain one sample for each channel.
960 *
961 * @param stream reference provided by AAudioStreamBuilder_openStream()
962 * @return actual number of channels
963 */
964AAUDIO_API int32_t AAudioStream_getChannelCount(AAudioStream* stream);
965
966/**
Phil Burke74240d2017-08-03 15:25:43 -0700967 * Identical to AAudioStream_getChannelCount().
968 *
969 * @param stream reference provided by AAudioStreamBuilder_openStream()
970 * @return actual number of samples frame
971 */
972AAUDIO_API int32_t AAudioStream_getSamplesPerFrame(AAudioStream* stream);
973
974/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800975 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burke2155ef2017-02-24 13:50:29 -0800976 * @return actual device ID
Phil Burk5ed503c2017-02-01 09:38:15 -0800977 */
Phil Burke2155ef2017-02-24 13:50:29 -0800978AAUDIO_API int32_t AAudioStream_getDeviceId(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800979
980/**
Phil Burk3316d5e2017-02-15 11:23:01 -0800981 * @param stream reference provided by AAudioStreamBuilder_openStream()
982 * @return actual data format
Phil Burk5ed503c2017-02-01 09:38:15 -0800983 */
Phil Burk9dca9822017-05-26 14:27:43 -0700984AAUDIO_API aaudio_format_t AAudioStream_getFormat(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800985
986/**
987 * Provide actual sharing mode.
Phil Burk3316d5e2017-02-15 11:23:01 -0800988 * @param stream reference provided by AAudioStreamBuilder_openStream()
989 * @return actual sharing mode
Phil Burk5ed503c2017-02-01 09:38:15 -0800990 */
Phil Burke2155ef2017-02-24 13:50:29 -0800991AAUDIO_API aaudio_sharing_mode_t AAudioStream_getSharingMode(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -0800992
993/**
Phil Burke2fbb592017-05-01 15:05:52 -0700994 * Get the performance mode used by the stream.
995 *
996 * @param stream reference provided by AAudioStreamBuilder_openStream()
997 */
998AAUDIO_API aaudio_performance_mode_t AAudioStream_getPerformanceMode(AAudioStream* stream);
999
1000/**
Phil Burk3316d5e2017-02-15 11:23:01 -08001001 * @param stream reference provided by AAudioStreamBuilder_openStream()
1002 * @return direction
Phil Burk5ed503c2017-02-01 09:38:15 -08001003 */
Phil Burke2155ef2017-02-24 13:50:29 -08001004AAUDIO_API aaudio_direction_t AAudioStream_getDirection(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -08001005
1006/**
1007 * Passes back the number of frames that have been written since the stream was created.
1008 * For an output stream, this will be advanced by the application calling write().
Phil Burk3316d5e2017-02-15 11:23:01 -08001009 * For an input stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -08001010 *
1011 * The frame position is monotonically increasing.
1012 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001013 * @param stream reference provided by AAudioStreamBuilder_openStream()
1014 * @return frames written
Phil Burk5ed503c2017-02-01 09:38:15 -08001015 */
Phil Burke2155ef2017-02-24 13:50:29 -08001016AAUDIO_API int64_t AAudioStream_getFramesWritten(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -08001017
1018/**
1019 * Passes back the number of frames that have been read since the stream was created.
Phil Burk3316d5e2017-02-15 11:23:01 -08001020 * For an output stream, this will be advanced by the endpoint.
Phil Burk5ed503c2017-02-01 09:38:15 -08001021 * For an input stream, this will be advanced by the application calling read().
1022 *
1023 * The frame position is monotonically increasing.
1024 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001025 * @param stream reference provided by AAudioStreamBuilder_openStream()
1026 * @return frames read
Phil Burk5ed503c2017-02-01 09:38:15 -08001027 */
Phil Burke2155ef2017-02-24 13:50:29 -08001028AAUDIO_API int64_t AAudioStream_getFramesRead(AAudioStream* stream);
Phil Burk5ed503c2017-02-01 09:38:15 -08001029
1030/**
Phil Burk7e7dcaa2018-01-03 15:16:15 -08001031 * Passes back the session ID associated with this stream.
1032 *
1033 * The session ID can be used to associate a stream with effects processors.
1034 * The effects are controlled using the Android AudioEffect Java API.
1035 *
1036 * If AAudioStreamBuilder_setSessionId() was called with AAUDIO_SESSION_ID_ALLOCATE
1037 * then a new session ID should be allocated once when the stream is opened.
1038 *
1039 * If AAudioStreamBuilder_setSessionId() was called with a previously allocated
1040 * session ID then that value should be returned.
1041 *
1042 * If AAudioStreamBuilder_setSessionId() was not called then this function should
1043 * return AAUDIO_SESSION_ID_NONE.
1044 *
1045 * The sessionID for a stream should not change once the stream has been opened.
1046 *
1047 * @param stream reference provided by AAudioStreamBuilder_openStream()
1048 * @return session ID or AAUDIO_SESSION_ID_NONE
1049 */
1050AAUDIO_API aaudio_session_id_t AAudioStream_getSessionId(AAudioStream* stream);
1051
1052/**
Phil Burk5ed503c2017-02-01 09:38:15 -08001053 * Passes back the time at which a particular frame was presented.
1054 * This can be used to synchronize audio with video or MIDI.
1055 * It can also be used to align a recorded stream with a playback stream.
1056 *
1057 * Timestamps are only valid when the stream is in AAUDIO_STREAM_STATE_STARTED.
1058 * AAUDIO_ERROR_INVALID_STATE will be returned if the stream is not started.
1059 * Note that because requestStart() is asynchronous, timestamps will not be valid until
1060 * a short time after calling requestStart().
1061 * So AAUDIO_ERROR_INVALID_STATE should not be considered a fatal error.
1062 * Just try calling again later.
1063 *
1064 * If an error occurs, then the position and time will not be modified.
1065 *
1066 * The position and time passed back are monotonically increasing.
1067 *
Phil Burk3316d5e2017-02-15 11:23:01 -08001068 * @param stream reference provided by AAudioStreamBuilder_openStream()
Phil Burkec159502017-07-25 17:33:47 -07001069 * @param clockid CLOCK_MONOTONIC or CLOCK_BOOTTIME
Phil Burk5ed503c2017-02-01 09:38:15 -08001070 * @param framePosition pointer to a variable to receive the position
1071 * @param timeNanoseconds pointer to a variable to receive the time
1072 * @return AAUDIO_OK or a negative error
1073 */
Phil Burke2155ef2017-02-24 13:50:29 -08001074AAUDIO_API aaudio_result_t AAudioStream_getTimestamp(AAudioStream* stream,
Phil Burk3316d5e2017-02-15 11:23:01 -08001075 clockid_t clockid,
1076 int64_t *framePosition,
1077 int64_t *timeNanoseconds);
Phil Burk5ed503c2017-02-01 09:38:15 -08001078
Phil Burk361b1422017-12-20 14:24:16 -08001079/**
1080 * Return the use case for the stream.
1081 *
1082 * @param stream reference provided by AAudioStreamBuilder_openStream()
1083 * @return frames read
1084 */
1085AAUDIO_API aaudio_usage_t AAudioStream_getUsage(AAudioStream* stream);
1086
1087/**
1088 * Return the content type for the stream.
1089 *
1090 * @param stream reference provided by AAudioStreamBuilder_openStream()
1091 * @return content type, for example AAUDIO_CONTENT_TYPE_MUSIC
1092 */
1093AAUDIO_API aaudio_content_type_t AAudioStream_getContentType(AAudioStream* stream);
1094
1095/**
1096 * Return the input preset for the stream.
1097 *
1098 * @param stream reference provided by AAudioStreamBuilder_openStream()
1099 * @return input preset, for example AAUDIO_INPUT_PRESET_CAMCORDER
1100 */
1101AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream);
1102
Phil Burk5ed503c2017-02-01 09:38:15 -08001103#ifdef __cplusplus
1104}
1105#endif
1106
1107#endif //AAUDIO_AAUDIO_H
Phil Burka45be8b2017-04-05 14:45:48 -07001108
1109/** @} */