Oboe  1.0
A library for creating real-time audio apps on Android
Definitions.h
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 #ifndef OBOE_DEFINITIONS_H
18 #define OBOE_DEFINITIONS_H
19 
20 #include <cstdint>
21 #include <type_traits>
22 #include <aaudio/AAudio.h>
23 
24 // Ensure that all AAudio primitive data types are int32_t
25 #define ASSERT_INT32(type) static_assert(std::is_same<int32_t, type>::value, \
26 #type" must be int32_t")
27 
28 ASSERT_INT32(aaudio_stream_state_t);
29 ASSERT_INT32(aaudio_direction_t);
30 ASSERT_INT32(aaudio_format_t);
31 ASSERT_INT32(aaudio_data_callback_result_t);
32 ASSERT_INT32(aaudio_result_t);
33 ASSERT_INT32(aaudio_sharing_mode_t);
34 ASSERT_INT32(aaudio_performance_mode_t);
35 
36 namespace oboe {
37 
41  constexpr int32_t kUnspecified = 0;
42 
43  // TODO: Investigate using std::chrono
47  constexpr int64_t kNanosPerMicrosecond = 1000;
48 
52  constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000;
53 
57  constexpr int64_t kMillisPerSecond = 1000;
58 
63 
67  enum class StreamState : aaudio_stream_state_t {
68  Uninitialized = AAUDIO_STREAM_STATE_UNINITIALIZED,
69  Unknown = AAUDIO_STREAM_STATE_UNKNOWN,
70  Open = AAUDIO_STREAM_STATE_OPEN,
71  Starting = AAUDIO_STREAM_STATE_STARTING,
72  Started = AAUDIO_STREAM_STATE_STARTED,
73  Pausing = AAUDIO_STREAM_STATE_PAUSING,
74  Paused = AAUDIO_STREAM_STATE_PAUSED,
75  Flushing = AAUDIO_STREAM_STATE_FLUSHING,
76  Flushed = AAUDIO_STREAM_STATE_FLUSHED,
77  Stopping = AAUDIO_STREAM_STATE_STOPPING,
78  Stopped = AAUDIO_STREAM_STATE_STOPPED,
79  Closing = AAUDIO_STREAM_STATE_CLOSING,
80  Closed = AAUDIO_STREAM_STATE_CLOSED,
81  Disconnected = AAUDIO_STREAM_STATE_DISCONNECTED,
82  };
83 
87  enum class Direction : aaudio_direction_t {
88 
92  Output = AAUDIO_DIRECTION_OUTPUT,
93 
97  Input = AAUDIO_DIRECTION_INPUT,
98  };
99 
103  enum class AudioFormat : aaudio_format_t {
107  Invalid = AAUDIO_FORMAT_INVALID,
108 
112  Unspecified = AAUDIO_FORMAT_UNSPECIFIED,
113 
117  I16 = AAUDIO_FORMAT_PCM_I16,
118 
122  Float = AAUDIO_FORMAT_PCM_FLOAT,
123  };
124 
128  enum class DataCallbackResult : aaudio_data_callback_result_t {
129  // Indicates to the caller that the callbacks should continue.
130  Continue = AAUDIO_CALLBACK_RESULT_CONTINUE,
131 
132  // Indicates to the caller that the callbacks should stop immediately.
133  Stop = AAUDIO_CALLBACK_RESULT_STOP,
134  };
135 
140  enum class Result : aaudio_result_t {
141  OK,
142  ErrorBase = AAUDIO_ERROR_BASE,
143  ErrorDisconnected = AAUDIO_ERROR_DISCONNECTED,
144  ErrorIllegalArgument = AAUDIO_ERROR_ILLEGAL_ARGUMENT,
145  ErrorInternal = AAUDIO_ERROR_INTERNAL,
146  ErrorInvalidState = AAUDIO_ERROR_INVALID_STATE,
147  ErrorInvalidHandle = AAUDIO_ERROR_INVALID_HANDLE,
148  ErrorUnimplemented = AAUDIO_ERROR_UNIMPLEMENTED,
149  ErrorUnavailable = AAUDIO_ERROR_UNAVAILABLE,
150  ErrorNoFreeHandles = AAUDIO_ERROR_NO_FREE_HANDLES,
151  ErrorNoMemory = AAUDIO_ERROR_NO_MEMORY,
152  ErrorNull = AAUDIO_ERROR_NULL,
153  ErrorTimeout = AAUDIO_ERROR_TIMEOUT,
154  ErrorWouldBlock = AAUDIO_ERROR_WOULD_BLOCK,
155  ErrorInvalidFormat = AAUDIO_ERROR_INVALID_FORMAT,
156  ErrorOutOfRange = AAUDIO_ERROR_OUT_OF_RANGE,
157  ErrorNoService = AAUDIO_ERROR_NO_SERVICE,
158  ErrorInvalidRate = AAUDIO_ERROR_INVALID_RATE,
159  // Reserved for future AAudio result types
160  Reserved1,
161  Reserved2,
162  Reserved3,
163  Reserved4,
164  Reserved5,
165  Reserved6,
166  Reserved7,
167  Reserved8,
168  Reserved9,
169  Reserved10,
170  ErrorClosed,
171  };
172 
176  enum class SharingMode : aaudio_sharing_mode_t {
177 
183  Exclusive = AAUDIO_SHARING_MODE_EXCLUSIVE,
184 
189  Shared = AAUDIO_SHARING_MODE_SHARED,
190  };
191 
195  enum class PerformanceMode : aaudio_performance_mode_t {
196 
200  None = AAUDIO_PERFORMANCE_MODE_NONE,
201 
205  PowerSaving = AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
206 
210  LowLatency = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
211  };
212 
216  enum class AudioApi : int32_t {
221 
225  OpenSLES,
226 
230  AAudio
231  };
232 
233 // Hard code constants so they can be compiled with versions of the NDK before P.
234 #if __ANDROID_API_LEVEL__ >= __ANDROID_API_P__
235 #define CONSTANT_API_P(hard_constant, soft_constant) (soft_constant)
236 #else
237 #define CONSTANT_API_P(hard_constant, soft_constant) (hard_constant)
238 #endif
239 
249  enum class Usage : aaudio_usage_t {
253  Media = CONSTANT_API_P(1, AAUDIO_USAGE_MEDIA),
254 
258  VoiceCommunication = CONSTANT_API_P(2, AAUDIO_USAGE_VOICE_COMMUNICATION),
259 
263  VoiceCommunicationSignalling = CONSTANT_API_P(3,
264  AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING),
265 
269  Alarm = CONSTANT_API_P(4, AAUDIO_USAGE_ALARM),
270 
275  Notification = CONSTANT_API_P(5, AAUDIO_USAGE_NOTIFICATION),
276 
280  NotificationRingtone = CONSTANT_API_P(6, AAUDIO_USAGE_NOTIFICATION_RINGTONE),
281 
285  NotificationEvent = CONSTANT_API_P(10, AAUDIO_USAGE_NOTIFICATION_EVENT),
286 
290  AssistanceAccessibility = CONSTANT_API_P(11, AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY),
291 
295  AssistanceNavigationGuidance = CONSTANT_API_P(12,
296  AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE),
297 
301  AssistanceSonification = CONSTANT_API_P(13, AAUDIO_USAGE_ASSISTANCE_SONIFICATION),
302 
306  Game = CONSTANT_API_P(14, AAUDIO_USAGE_GAME),
307 
311  Assistant = CONSTANT_API_P(16, AAUDIO_USAGE_ASSISTANT),
312  };
313 
314 
327  enum ContentType : aaudio_content_type_t {
328 
332  Speech = CONSTANT_API_P(1, AAUDIO_CONTENT_TYPE_SPEECH),
333 
337  Music = CONSTANT_API_P(2, AAUDIO_CONTENT_TYPE_MUSIC),
338 
342  Movie = CONSTANT_API_P(3, AAUDIO_CONTENT_TYPE_MOVIE),
343 
348  Sonification = CONSTANT_API_P(4, AAUDIO_CONTENT_TYPE_SONIFICATION),
349  };
350 
360  enum InputPreset : aaudio_input_preset_t {
364  Generic = CONSTANT_API_P(1, AAUDIO_INPUT_PRESET_GENERIC),
365 
369  Camcorder = CONSTANT_API_P(5, AAUDIO_INPUT_PRESET_CAMCORDER),
370 
374  VoiceRecognition = CONSTANT_API_P(6, AAUDIO_INPUT_PRESET_VOICE_RECOGNITION),
375 
379  VoiceCommunication = CONSTANT_API_P(7, AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION),
380 
386  Unprocessed = CONSTANT_API_P(9, AAUDIO_INPUT_PRESET_UNPROCESSED),
387  };
388 
394  enum SessionId {
400  None = CONSTANT_API_P(-1, AAUDIO_SESSION_ID_NONE),
401 
409  Allocate = CONSTANT_API_P(0, AAUDIO_SESSION_ID_ALLOCATE),
410  };
411 
422  enum ChannelCount : int32_t {
427 
431  Mono = 1,
432 
436  Stereo = 2,
437  };
438 
439 #undef CONSTANT_API_P
440 
460 
461  public:
462 
464  static int32_t SampleRate;
466  static int32_t FramesPerBurst;
468  static int32_t ChannelCount;
469 
470  };
471 
472 
473 
474 } // namespace oboe
475 
476 #endif // OBOE_DEFINITIONS_H
constexpr int64_t kNanosPerMicrosecond
Definition: Definitions.h:47
Direction
Definition: Definitions.h:87
Definition: Definitions.h:348
Definition: Definitions.h:409
Definition: Definitions.h:400
constexpr int64_t kNanosPerSecond
Definition: Definitions.h:62
SessionId
Definition: Definitions.h:394
Result
Definition: Definitions.h:140
Definition: Definitions.h:386
AudioApi
Definition: Definitions.h:216
Definition: Definitions.h:459
Definition: Definitions.h:337
Definition: Definitions.h:369
Definition: Definitions.h:379
Definition: Definitions.h:364
AudioFormat
Definition: Definitions.h:103
DataCallbackResult
Definition: Definitions.h:128
Definition: Definitions.h:436
static int32_t FramesPerBurst
Definition: Definitions.h:466
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:52
ContentType
Definition: Definitions.h:327
Definition: Definitions.h:431
ChannelCount
Definition: Definitions.h:422
SharingMode
Definition: Definitions.h:176
StreamState
Definition: Definitions.h:67
constexpr int32_t kUnspecified
Definition: Definitions.h:41
Definition: AudioStream.h:29
constexpr int64_t kMillisPerSecond
Definition: Definitions.h:57
PerformanceMode
Definition: Definitions.h:195
Definition: Definitions.h:426
InputPreset
Definition: Definitions.h:360
static int32_t SampleRate
Definition: Definitions.h:464
Usage
Definition: Definitions.h:249
static int32_t ChannelCount
Definition: Definitions.h:468
Definition: Definitions.h:332
Definition: Definitions.h:374
Definition: Definitions.h:342