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
53 constexpr int64_t kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond;
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 {
217 Unspecified = kUnspecified,
218
222 OpenSLES,
223
227 AAudio
228 };
229
235 enum class SampleRateConversionQuality : int32_t {
239 None,
244 Fastest,
245 Low,
246 Medium,
247 High,
251 Best,
252 };
253
263 enum class Usage : int32_t { // aaudio_usage_t
267 Media = 1, // AAUDIO_USAGE_MEDIA
268
272 VoiceCommunication = 2, // AAUDIO_USAGE_VOICE_COMMUNICATION
273
277 VoiceCommunicationSignalling = 3, // AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING
278
282 Alarm = 4, // AAUDIO_USAGE_ALARM
283
288 Notification = 5, // AAUDIO_USAGE_NOTIFICATION
289
293 NotificationRingtone = 6, // AAUDIO_USAGE_NOTIFICATION_RINGTONE
294
298 NotificationEvent = 10, // AAUDIO_USAGE_NOTIFICATION_EVENT
299
303 AssistanceAccessibility = 11, // AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY
304
308 AssistanceNavigationGuidance = 12, // AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
309
313 AssistanceSonification = 13, // AAUDIO_USAGE_ASSISTANCE_SONIFICATION
314
318 Game = 14, // AAUDIO_USAGE_GAME
319
323 Assistant = 16, // AAUDIO_USAGE_ASSISTANT
324 };
325
326
339 enum ContentType : int32_t { // aaudio_content_type_t
340
344 Speech = 1, // AAUDIO_CONTENT_TYPE_SPEECH
345
349 Music = 2, // AAUDIO_CONTENT_TYPE_MUSIC
350
354 Movie = 3, // AAUDIO_CONTENT_TYPE_MOVIE
355
360 Sonification = 4, // AAUDIO_CONTENT_TYPE_SONIFICATION
361 };
362
372 enum InputPreset : int32_t { // aaudio_input_preset_t
376 Generic = 1, // AAUDIO_INPUT_PRESET_GENERIC
377
381 Camcorder = 5, // AAUDIO_INPUT_PRESET_CAMCORDER
382
386 VoiceRecognition = 6, // AAUDIO_INPUT_PRESET_VOICE_RECOGNITION
387
391 VoiceCommunication = 7, // AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION
392
398 Unprocessed = 9, // AAUDIO_INPUT_PRESET_UNPROCESSED
399
405 VoicePerformance = 10, // AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE
406
407 };
408
414 enum SessionId {
420 None = -1, // AAUDIO_SESSION_ID_NONE
421
429 Allocate = 0, // AAUDIO_SESSION_ID_ALLOCATE
430 };
431
442 enum ChannelCount : int32_t {
446 Unspecified = kUnspecified,
447
451 Mono = 1,
452
456 Stereo = 2,
457 };
458
477 class DefaultStreamValues {
478
479 public:
480
482 static int32_t SampleRate;
484 static int32_t FramesPerBurst;
486 static int32_t ChannelCount;
487
488 };
489
493 struct FrameTimestamp {
494 int64_t position; // in frames
495 int64_t timestamp; // in nanoseconds
496 };
497
498 } // namespace oboe
499
500 #endif // OBOE_DEFINITIONS_H
oboe::kNanosPerMicrosecond
constexpr int64_t kNanosPerMicrosecond
Definition: Definitions.h:38
oboe::AudioApi::AAudio
oboe::Direction::Output
oboe::Allocate
Definition: Definitions.h:429
oboe::VoiceRecognition
Definition: Definitions.h:386
oboe::None
Definition: Definitions.h:420
oboe::kNanosPerSecond
constexpr int64_t kNanosPerSecond
Definition: Definitions.h:53
oboe::Usage::Assistant
oboe::Usage::AssistanceAccessibility
oboe::PerformanceMode::PowerSaving
oboe::SharingMode::Exclusive
oboe::PerformanceMode
PerformanceMode
Definition: Definitions.h:192
oboe::SessionId
SessionId
Definition: Definitions.h:414
oboe::SharingMode::Shared
oboe::Usage::AssistanceSonification
oboe::Movie
Definition: Definitions.h:354
oboe::Generic
Definition: Definitions.h:376
oboe::PerformanceMode::LowLatency
oboe::DataCallbackResult
DataCallbackResult
Definition: Definitions.h:119
oboe::AudioApi
AudioApi
Definition: Definitions.h:213
oboe::ContentType
ContentType
Definition: Definitions.h:339
oboe::DefaultStreamValues
Definition: Definitions.h:477
oboe::AudioApi::OpenSLES
oboe::FrameTimestamp
Definition: Definitions.h:493
oboe::SampleRateConversionQuality::Best
oboe::Usage::NotificationRingtone
oboe::Usage
Usage
Definition: Definitions.h:263
oboe::Stereo
Definition: Definitions.h:456
oboe::VoiceCommunication
Definition: Definitions.h:391
oboe::Usage::Media
oboe::AudioFormat::I16
oboe::DefaultStreamValues::FramesPerBurst
static int32_t FramesPerBurst
Definition: Definitions.h:484
oboe::Camcorder
Definition: Definitions.h:381
oboe::kNanosPerMillisecond
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:43
oboe::Usage::Game
oboe::AudioFormat::Float
oboe::Unprocessed
Definition: Definitions.h:398
oboe::Mono
Definition: Definitions.h:451
oboe::AudioFormat
AudioFormat
Definition: Definitions.h:94
oboe::Direction::Input
oboe::Sonification
Definition: Definitions.h:360
oboe::ChannelCount
ChannelCount
Definition: Definitions.h:442
oboe::AudioFormat::Invalid
oboe::Result
Result
Definition: Definitions.h:131
oboe::Usage::AssistanceNavigationGuidance
oboe::kUnspecified
constexpr int32_t kUnspecified
Definition: Definitions.h:32
oboe
Definition: AudioStream.h:31
oboe::kMillisPerSecond
constexpr int64_t kMillisPerSecond
Definition: Definitions.h:48
oboe::SampleRateConversionQuality
SampleRateConversionQuality
Definition: Definitions.h:235
oboe::Unspecified
Definition: Definitions.h:446
oboe::Direction
Direction
Definition: Definitions.h:78
oboe::SharingMode
SharingMode
Definition: Definitions.h:167
oboe::InputPreset
InputPreset
Definition: Definitions.h:372
oboe::StreamState
StreamState
Definition: Definitions.h:58
oboe::Usage::VoiceCommunicationSignalling
oboe::DefaultStreamValues::SampleRate
static int32_t SampleRate
Definition: Definitions.h:482
oboe::DefaultStreamValues::ChannelCount
static int32_t ChannelCount
Definition: Definitions.h:486
oboe::VoicePerformance
Definition: Definitions.h:405
oboe::Music
Definition: Definitions.h:349
oboe::SampleRateConversionQuality::Fastest
oboe::Speech
Definition: Definitions.h:344
oboe::Usage::NotificationEvent
oboe::Usage::Notification
oboe::Usage::Alarm