Oboe  1.2
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 
21 #include <cstdint>
22 #include <type_traits>
23 
24 // Oboe needs to be able to build on old NDKs so we use hard coded constants.
25 // The correctness of these constants is verified in "aaudio/AAudioLoader.cpp".
26 
27 namespace oboe {
28 
32  constexpr int32_t kUnspecified = 0;
33 
34  // TODO: Investigate using std::chrono
38  constexpr int64_t kNanosPerMicrosecond = 1000;
39 
43  constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000;
44 
48  constexpr int64_t kMillisPerSecond = 1000;
49 
54 
58  enum class StreamState : int32_t { // aaudio_stream_state_t
59  Uninitialized = 0, // AAUDIO_STREAM_STATE_UNINITIALIZED,
60  Unknown = 1, // AAUDIO_STREAM_STATE_UNKNOWN,
61  Open = 2, // AAUDIO_STREAM_STATE_OPEN,
62  Starting = 3, // AAUDIO_STREAM_STATE_STARTING,
63  Started = 4, // AAUDIO_STREAM_STATE_STARTED,
64  Pausing = 5, // AAUDIO_STREAM_STATE_PAUSING,
65  Paused = 6, // AAUDIO_STREAM_STATE_PAUSED,
66  Flushing = 7, // AAUDIO_STREAM_STATE_FLUSHING,
67  Flushed = 8, // AAUDIO_STREAM_STATE_FLUSHED,
68  Stopping = 9, // AAUDIO_STREAM_STATE_STOPPING,
69  Stopped = 10, // AAUDIO_STREAM_STATE_STOPPED,
70  Closing = 11, // AAUDIO_STREAM_STATE_CLOSING,
71  Closed = 12, // AAUDIO_STREAM_STATE_CLOSED,
72  Disconnected = 13, // AAUDIO_STREAM_STATE_DISCONNECTED,
73  };
74 
78  enum class Direction : int32_t { // aaudio_direction_t
79 
83  Output = 0, // AAUDIO_DIRECTION_OUTPUT,
84 
88  Input = 1, // AAUDIO_DIRECTION_INPUT,
89  };
90 
94  enum class AudioFormat : int32_t { // aaudio_format_t
98  Invalid = -1, // AAUDIO_FORMAT_INVALID,
99 
103  Unspecified = 0, // AAUDIO_FORMAT_UNSPECIFIED,
104 
108  I16 = 1, // AAUDIO_FORMAT_PCM_I16,
109 
113  Float = 2, // AAUDIO_FORMAT_PCM_FLOAT,
114  };
115 
119  enum class DataCallbackResult : int32_t { // aaudio_data_callback_result_t
120  // Indicates to the caller that the callbacks should continue.
121  Continue = 0, // AAUDIO_CALLBACK_RESULT_CONTINUE,
122 
123  // Indicates to the caller that the callbacks should stop immediately.
124  Stop = 1, // AAUDIO_CALLBACK_RESULT_STOP,
125  };
126 
131  enum class Result : int32_t { // aaudio_result_t
132  OK = 0, // AAUDIO_OK
133  ErrorBase = -900, // AAUDIO_ERROR_BASE,
134  ErrorDisconnected = -899, // AAUDIO_ERROR_DISCONNECTED,
135  ErrorIllegalArgument = -898, // AAUDIO_ERROR_ILLEGAL_ARGUMENT,
136  ErrorInternal = -896, // AAUDIO_ERROR_INTERNAL,
137  ErrorInvalidState = -895, // AAUDIO_ERROR_INVALID_STATE,
138  ErrorInvalidHandle = -892, // AAUDIO_ERROR_INVALID_HANDLE,
139  ErrorUnimplemented = -890, // AAUDIO_ERROR_UNIMPLEMENTED,
140  ErrorUnavailable = -889, // AAUDIO_ERROR_UNAVAILABLE,
141  ErrorNoFreeHandles = -888, // AAUDIO_ERROR_NO_FREE_HANDLES,
142  ErrorNoMemory = -887, // AAUDIO_ERROR_NO_MEMORY,
143  ErrorNull = -886, // AAUDIO_ERROR_NULL,
144  ErrorTimeout = -885, // AAUDIO_ERROR_TIMEOUT,
145  ErrorWouldBlock = -884, // AAUDIO_ERROR_WOULD_BLOCK,
146  ErrorInvalidFormat = -883, // AAUDIO_ERROR_INVALID_FORMAT,
147  ErrorOutOfRange = -882, // AAUDIO_ERROR_OUT_OF_RANGE,
148  ErrorNoService = -881, // AAUDIO_ERROR_NO_SERVICE,
149  ErrorInvalidRate = -880, // AAUDIO_ERROR_INVALID_RATE,
150  // Reserved for future AAudio result types
151  Reserved1,
152  Reserved2,
153  Reserved3,
154  Reserved4,
155  Reserved5,
156  Reserved6,
157  Reserved7,
158  Reserved8,
159  Reserved9,
160  Reserved10,
161  ErrorClosed,
162  };
163 
167  enum class SharingMode : int32_t { // aaudio_sharing_mode_t
168 
177  Exclusive = 0, // AAUDIO_SHARING_MODE_EXCLUSIVE,
178 
186  Shared = 1, // AAUDIO_SHARING_MODE_SHARED,
187  };
188 
192  enum class PerformanceMode : int32_t { // aaudio_performance_mode_t
193 
197  None = 10, // AAUDIO_PERFORMANCE_MODE_NONE,
198 
202  PowerSaving = 11, // AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
203 
207  LowLatency = 12, // AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
208  };
209 
213  enum class AudioApi : int32_t {
218 
222  OpenSLES,
223 
227  AAudio
228  };
229 
239  enum class Usage : int32_t { // aaudio_usage_t
243  Media = 1, // AAUDIO_USAGE_MEDIA
244 
248  VoiceCommunication = 2, // AAUDIO_USAGE_VOICE_COMMUNICATION
249 
253  VoiceCommunicationSignalling = 3, // AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING
254 
258  Alarm = 4, // AAUDIO_USAGE_ALARM
259 
264  Notification = 5, // AAUDIO_USAGE_NOTIFICATION
265 
269  NotificationRingtone = 6, // AAUDIO_USAGE_NOTIFICATION_RINGTONE
270 
274  NotificationEvent = 10, // AAUDIO_USAGE_NOTIFICATION_EVENT
275 
279  AssistanceAccessibility = 11, // AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY
280 
284  AssistanceNavigationGuidance = 12, // AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
285 
289  AssistanceSonification = 13, // AAUDIO_USAGE_ASSISTANCE_SONIFICATION
290 
294  Game = 14, // AAUDIO_USAGE_GAME
295 
299  Assistant = 16, // AAUDIO_USAGE_ASSISTANT
300  };
301 
302 
315  enum ContentType : int32_t { // aaudio_content_type_t
316 
320  Speech = 1, // AAUDIO_CONTENT_TYPE_SPEECH
321 
325  Music = 2, // AAUDIO_CONTENT_TYPE_MUSIC
326 
330  Movie = 3, // AAUDIO_CONTENT_TYPE_MOVIE
331 
336  Sonification = 4, // AAUDIO_CONTENT_TYPE_SONIFICATION
337  };
338 
348  enum InputPreset : int32_t { // aaudio_input_preset_t
352  Generic = 1, // AAUDIO_INPUT_PRESET_GENERIC
353 
357  Camcorder = 5, // AAUDIO_INPUT_PRESET_CAMCORDER
358 
362  VoiceRecognition = 6, // AAUDIO_INPUT_PRESET_VOICE_RECOGNITION
363 
367  VoiceCommunication = 7, // AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION
368 
374  Unprocessed = 9, // AAUDIO_INPUT_PRESET_UNPROCESSED
375  };
376 
382  enum SessionId {
388  None = -1, // AAUDIO_SESSION_ID_NONE
389 
397  Allocate = 0, // AAUDIO_SESSION_ID_ALLOCATE
398  };
399 
410  enum ChannelCount : int32_t {
415 
419  Mono = 1,
420 
424  Stereo = 2,
425  };
426 
446 
447  public:
448 
450  static int32_t SampleRate;
452  static int32_t FramesPerBurst;
454  static int32_t ChannelCount;
455 
456  };
457 
461  struct FrameTimestamp {
462  int64_t position; // in frames
463  int64_t timestamp; // in nanoseconds
464  };
465 
466 } // namespace oboe
467 
468 #endif // OBOE_DEFINITIONS_H
constexpr int64_t kNanosPerMicrosecond
Definition: Definitions.h:38
Definition: Definitions.h:397
Definition: Definitions.h:362
Definition: Definitions.h:388
constexpr int64_t kNanosPerSecond
Definition: Definitions.h:53
PerformanceMode
Definition: Definitions.h:192
SessionId
Definition: Definitions.h:382
Definition: Definitions.h:330
Definition: Definitions.h:352
DataCallbackResult
Definition: Definitions.h:119
AudioApi
Definition: Definitions.h:213
ContentType
Definition: Definitions.h:315
Definition: Definitions.h:445
Definition: Definitions.h:461
Usage
Definition: Definitions.h:239
Definition: Definitions.h:424
Definition: Definitions.h:367
static int32_t FramesPerBurst
Definition: Definitions.h:452
Definition: Definitions.h:357
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:43
Definition: Definitions.h:374
Definition: Definitions.h:419
AudioFormat
Definition: Definitions.h:94
Definition: Definitions.h:336
ChannelCount
Definition: Definitions.h:410
Result
Definition: Definitions.h:131
constexpr int32_t kUnspecified
Definition: Definitions.h:32
Definition: AudioStream.h:31
constexpr int64_t kMillisPerSecond
Definition: Definitions.h:48
Definition: Definitions.h:414
Direction
Definition: Definitions.h:78
SharingMode
Definition: Definitions.h:167
InputPreset
Definition: Definitions.h:348
StreamState
Definition: Definitions.h:58
static int32_t SampleRate
Definition: Definitions.h:450
static int32_t ChannelCount
Definition: Definitions.h:454
Definition: Definitions.h:325
Definition: Definitions.h:320