Oboe
A library for creating real-time audio apps on Android
Loading...
Searching...
No Matches
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
23// Oboe needs to be able to build on old NDKs so we use hard coded constants.
24// The correctness of these constants is verified in "aaudio/AAudioLoader.cpp".
25
26namespace oboe {
27
31 constexpr int32_t kUnspecified = 0;
32
33 // TODO: Investigate using std::chrono
37 constexpr int64_t kNanosPerMicrosecond = 1000;
38
42 constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000;
43
47 constexpr int64_t kMillisPerSecond = 1000;
48
52 constexpr int64_t kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond;
53
57 enum class StreamState : int32_t { // aaudio_stream_state_t
58 Uninitialized = 0, // AAUDIO_STREAM_STATE_UNINITIALIZED,
59 Unknown = 1, // AAUDIO_STREAM_STATE_UNKNOWN,
60 Open = 2, // AAUDIO_STREAM_STATE_OPEN,
61 Starting = 3, // AAUDIO_STREAM_STATE_STARTING,
62 Started = 4, // AAUDIO_STREAM_STATE_STARTED,
63 Pausing = 5, // AAUDIO_STREAM_STATE_PAUSING,
64 Paused = 6, // AAUDIO_STREAM_STATE_PAUSED,
65 Flushing = 7, // AAUDIO_STREAM_STATE_FLUSHING,
66 Flushed = 8, // AAUDIO_STREAM_STATE_FLUSHED,
67 Stopping = 9, // AAUDIO_STREAM_STATE_STOPPING,
68 Stopped = 10, // AAUDIO_STREAM_STATE_STOPPED,
69 Closing = 11, // AAUDIO_STREAM_STATE_CLOSING,
70 Closed = 12, // AAUDIO_STREAM_STATE_CLOSED,
71 Disconnected = 13, // AAUDIO_STREAM_STATE_DISCONNECTED,
72 };
73
77 enum class Direction : int32_t { // aaudio_direction_t
78
82 Output = 0, // AAUDIO_DIRECTION_OUTPUT,
83
87 Input = 1, // AAUDIO_DIRECTION_INPUT,
88 };
89
93 enum class AudioFormat : int32_t { // aaudio_format_t
97 Invalid = -1, // AAUDIO_FORMAT_INVALID,
98
104 Unspecified = 0, // AAUDIO_FORMAT_UNSPECIFIED,
105
109 I16 = 1, // AAUDIO_FORMAT_PCM_I16,
110
118 Float = 2, // AAUDIO_FORMAT_PCM_FLOAT,
119
129 I24 = 3, // AAUDIO_FORMAT_PCM_I24_PACKED
130
140 I32 = 4, // AAUDIO_FORMAT_PCM_I32
141
154 IEC61937 = 5, // AAUDIO_FORMAT_IEC61937
155
159 MP3 = 6, // AAUDIO_FORMAT_MP3
160
164 AAC_LC, // AAUDIO_FORMAT_AAC_LC
165
169 AAC_HE_V1, // AAUDIO_FORMAT_AAC_HE_V1,
170
174 AAC_HE_V2, // AAUDIO_FORMAT_AAC_HE_V2
175
179 AAC_ELD, // AAUDIO_FORMAT_AAC_ELD
180
184 AAC_XHE, // AAUDIO_FORMAT_AAC_XHE
185
189 OPUS, // AAUDIO_FORMAT_OPUS
190 };
191
195 enum class DataCallbackResult : int32_t { // aaudio_data_callback_result_t
196 // Indicates to the caller that the callbacks should continue.
197 Continue = 0, // AAUDIO_CALLBACK_RESULT_CONTINUE,
198
199 // Indicates to the caller that the callbacks should stop immediately.
200 Stop = 1, // AAUDIO_CALLBACK_RESULT_STOP,
201 };
202
207 enum class Result : int32_t { // aaudio_result_t
208 OK = 0, // AAUDIO_OK
209 ErrorBase = -900, // AAUDIO_ERROR_BASE,
210 ErrorDisconnected = -899, // AAUDIO_ERROR_DISCONNECTED,
211 ErrorIllegalArgument = -898, // AAUDIO_ERROR_ILLEGAL_ARGUMENT,
212 ErrorInternal = -896, // AAUDIO_ERROR_INTERNAL,
213 ErrorInvalidState = -895, // AAUDIO_ERROR_INVALID_STATE,
214 ErrorInvalidHandle = -892, // AAUDIO_ERROR_INVALID_HANDLE,
215 ErrorUnimplemented = -890, // AAUDIO_ERROR_UNIMPLEMENTED,
216 ErrorUnavailable = -889, // AAUDIO_ERROR_UNAVAILABLE,
217 ErrorNoFreeHandles = -888, // AAUDIO_ERROR_NO_FREE_HANDLES,
218 ErrorNoMemory = -887, // AAUDIO_ERROR_NO_MEMORY,
219 ErrorNull = -886, // AAUDIO_ERROR_NULL,
220 ErrorTimeout = -885, // AAUDIO_ERROR_TIMEOUT,
221 ErrorWouldBlock = -884, // AAUDIO_ERROR_WOULD_BLOCK,
222 ErrorInvalidFormat = -883, // AAUDIO_ERROR_INVALID_FORMAT,
223 ErrorOutOfRange = -882, // AAUDIO_ERROR_OUT_OF_RANGE,
224 ErrorNoService = -881, // AAUDIO_ERROR_NO_SERVICE,
225 ErrorInvalidRate = -880, // AAUDIO_ERROR_INVALID_RATE,
226 // Reserved for future AAudio result types
227 Reserved1,
228 Reserved2,
229 Reserved3,
230 Reserved4,
231 Reserved5,
232 Reserved6,
233 Reserved7,
234 Reserved8,
235 Reserved9,
236 Reserved10,
237 ErrorClosed = -869,
238 };
239
243 enum class SharingMode : int32_t { // aaudio_sharing_mode_t
244
253 Exclusive = 0, // AAUDIO_SHARING_MODE_EXCLUSIVE,
254
262 Shared = 1, // AAUDIO_SHARING_MODE_SHARED,
263 };
264
268 enum class PerformanceMode : int32_t { // aaudio_performance_mode_t
269
273 None = 10, // AAUDIO_PERFORMANCE_MODE_NONE,
274
278 PowerSaving = 11, // AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
279
283 LowLatency = 12, // AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
284
293 PowerSavingOffloaded = 13, // AAUDIO_PERFORMANCE_MODE_POWER_SAVING_OFFLOADED
294 };
295
299 enum class AudioApi : int32_t {
303 Unspecified = kUnspecified,
304
309 OpenSLES,
310
316 AAudio
317 };
318
324 enum class SampleRateConversionQuality : int32_t {
328 None,
333 Fastest,
337 Low,
341 Medium,
345 High,
349 Best,
350 };
351
361 enum class Usage : int32_t { // aaudio_usage_t
365 Media = 1, // AAUDIO_USAGE_MEDIA
366
370 VoiceCommunication = 2, // AAUDIO_USAGE_VOICE_COMMUNICATION
371
375 VoiceCommunicationSignalling = 3, // AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING
376
380 Alarm = 4, // AAUDIO_USAGE_ALARM
381
386 Notification = 5, // AAUDIO_USAGE_NOTIFICATION
387
391 NotificationRingtone = 6, // AAUDIO_USAGE_NOTIFICATION_RINGTONE
392
396 NotificationEvent = 10, // AAUDIO_USAGE_NOTIFICATION_EVENT
397
401 AssistanceAccessibility = 11, // AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY
402
406 AssistanceNavigationGuidance = 12, // AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
407
411 AssistanceSonification = 13, // AAUDIO_USAGE_ASSISTANCE_SONIFICATION
412
416 Game = 14, // AAUDIO_USAGE_GAME
417
421 Assistant = 16, // AAUDIO_USAGE_ASSISTANT
422 };
423
424
437 enum ContentType : int32_t { // aaudio_content_type_t
438
442 Speech = 1, // AAUDIO_CONTENT_TYPE_SPEECH
443
447 Music = 2, // AAUDIO_CONTENT_TYPE_MUSIC
448
452 Movie = 3, // AAUDIO_CONTENT_TYPE_MOVIE
453
458 Sonification = 4, // AAUDIO_CONTENT_TYPE_SONIFICATION
459 };
460
470 enum InputPreset : int32_t { // aaudio_input_preset_t
474 Generic = 1, // AAUDIO_INPUT_PRESET_GENERIC
475
479 Camcorder = 5, // AAUDIO_INPUT_PRESET_CAMCORDER
480
484 VoiceRecognition = 6, // AAUDIO_INPUT_PRESET_VOICE_RECOGNITION
485
489 VoiceCommunication = 7, // AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION
490
496 Unprocessed = 9, // AAUDIO_INPUT_PRESET_UNPROCESSED
497
503 VoicePerformance = 10, // AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE
504
505 };
506
514 enum SessionId {
520 None = -1, // AAUDIO_SESSION_ID_NONE
521
529 Allocate = 0, // AAUDIO_SESSION_ID_ALLOCATE
530 };
531
542 enum ChannelCount : int32_t {
546 Unspecified = kUnspecified,
547
551 Mono = 1,
552
556 Stereo = 2,
557 };
558
573 enum class ChannelMask : uint32_t { // aaudio_channel_mask_t
574 Unspecified = kUnspecified,
575 FrontLeft = 1 << 0,
576 FrontRight = 1 << 1,
577 FrontCenter = 1 << 2,
578 LowFrequency = 1 << 3,
579 BackLeft = 1 << 4,
580 BackRight = 1 << 5,
581 FrontLeftOfCenter = 1 << 6,
582 FrontRightOfCenter = 1 << 7,
583 BackCenter = 1 << 8,
584 SideLeft = 1 << 9,
585 SideRight = 1 << 10,
586 TopCenter = 1 << 11,
587 TopFrontLeft = 1 << 12,
588 TopFrontCenter = 1 << 13,
589 TopFrontRight = 1 << 14,
590 TopBackLeft = 1 << 15,
591 TopBackCenter = 1 << 16,
592 TopBackRight = 1 << 17,
593 TopSideLeft = 1 << 18,
594 TopSideRight = 1 << 19,
595 BottomFrontLeft = 1 << 20,
596 BottomFrontCenter = 1 << 21,
597 BottomFrontRight = 1 << 22,
598 LowFrequency2 = 1 << 23,
599 FrontWideLeft = 1 << 24,
600 FrontWideRight = 1 << 25,
601
605 Mono = FrontLeft,
606
610 Stereo = FrontLeft |
611 FrontRight,
612
616 CM2Point1 = FrontLeft |
617 FrontRight |
618 LowFrequency,
619
623 Tri = FrontLeft |
624 FrontRight |
625 FrontCenter,
626
630 TriBack = FrontLeft |
631 FrontRight |
632 BackCenter,
633
637 CM3Point1 = FrontLeft |
638 FrontRight |
639 FrontCenter |
640 LowFrequency,
641
645 CM2Point0Point2 = FrontLeft |
646 FrontRight |
647 TopSideLeft |
648 TopSideRight,
649
653 CM2Point1Point2 = CM2Point0Point2 |
654 LowFrequency,
655
659 CM3Point0Point2 = FrontLeft |
660 FrontRight |
661 FrontCenter |
662 TopSideLeft |
663 TopSideRight,
664
668 CM3Point1Point2 = CM3Point0Point2 |
669 LowFrequency,
670
674 Quad = FrontLeft |
675 FrontRight |
676 BackLeft |
677 BackRight,
678
682 QuadSide = FrontLeft |
683 FrontRight |
684 SideLeft |
685 SideRight,
686
690 Surround = FrontLeft |
691 FrontRight |
692 FrontCenter |
693 BackCenter,
694
698 Penta = Quad |
699 FrontCenter,
700
704 CM5Point1 = FrontLeft |
705 FrontRight |
706 FrontCenter |
707 LowFrequency |
708 BackLeft |
709 BackRight,
710
714 CM5Point1Side = FrontLeft |
715 FrontRight |
716 FrontCenter |
717 LowFrequency |
718 SideLeft |
719 SideRight,
720
724 CM6Point1 = FrontLeft |
725 FrontRight |
726 FrontCenter |
727 LowFrequency |
728 BackLeft |
729 BackRight |
730 BackCenter,
731
735 CM7Point1 = CM5Point1 |
736 SideLeft |
737 SideRight,
738
742 CM5Point1Point2 = CM5Point1 |
743 TopSideLeft |
744 TopSideRight,
745
749 CM5Point1Point4 = CM5Point1 |
750 TopFrontLeft |
751 TopFrontRight |
752 TopBackLeft |
753 TopBackRight,
754
758 CM7Point1Point2 = CM7Point1 |
759 TopSideLeft |
760 TopSideRight,
761
765 CM7Point1Point4 = CM7Point1 |
766 TopFrontLeft |
767 TopFrontRight |
768 TopBackLeft |
769 TopBackRight,
770
774 CM9Point1Point4 = CM7Point1Point4 |
775 FrontWideLeft |
776 FrontWideRight,
777
781 CM9Point1Point6 = CM9Point1Point4 |
782 TopSideLeft |
783 TopSideRight,
784
788 FrontBack = FrontCenter |
789 BackCenter,
790 };
791
808 enum class ChannelAcnMask : uint32_t { // AAudio_ChannelAcnMask
809 Unspecified = kUnspecified,
810
814 Order0 = 1,
818 Order1 = 4,
822 Order2 = 9,
826 Order3 = 16,
830 Order4 = 25,
834 Order5 = 36,
838 Order6 = 49,
842 Order7 = 64,
846 Order8 = 81,
850 Order9 = 100,
854 Order10 = 121,
858 Order11 = 144,
862 Order12 = 169,
866 Order13 = 196,
870 Order14 = 225,
871
876 Horizontal = 1 << 9,
877
882 CountMask = (1 << 8) - 1,
883
887 Order0Hrz = Horizontal | 1,
891 Order1Hrz = Horizontal | 3,
895 Order2Hrz = Horizontal | 5,
899 Order3Hrz = Horizontal | 7,
903 Order4Hrz = Horizontal | 9,
907 Order5Hrz = Horizontal | 11,
911 Order6Hrz = Horizontal | 13,
915 Order7Hrz = Horizontal | 15,
919 Order8Hrz = Horizontal | 17,
923 Order9Hrz = Horizontal | 19,
927 Order10Hrz = Horizontal | 21,
931 Order11Hrz = Horizontal | 23,
935 Order12Hrz = Horizontal | 25,
939 Order13Hrz = Horizontal | 27,
943 Order14Hrz = Horizontal | 29,
944 };
945
949 enum class SpatializationBehavior : int32_t {
950
954 Unspecified = kUnspecified,
955
960 Auto = 1,
961
966 Never = 2,
967 };
968
976 enum class PrivacySensitiveMode : int32_t {
977
982 Unspecified = kUnspecified,
983
987 Disabled = 1,
988
992 Enabled = 2,
993 };
994
1003 enum class AllowedCapturePolicy : int32_t {
1008 Unspecified = kUnspecified,
1019 All = 1,
1027 System = 2,
1035 None = 3,
1036 };
1037
1046 enum class DeviceType : int32_t {
1050 BuiltinEarpiece = 1,
1051
1056 BuiltinSpeaker = 2,
1057
1062 WiredHeadset = 3,
1063
1067 WiredHeadphones = 4,
1068
1072 LineAnalog = 5,
1073
1077 LineDigital = 6,
1078
1082 BluetoothSco = 7,
1083
1087 BluetoothA2dp = 8,
1088
1092 Hdmi = 9,
1093
1097 HdmiArc = 10,
1098
1102 UsbDevice = 11,
1103
1107 UsbAccessory = 12,
1108
1112 Dock = 13,
1113
1117 FM = 14,
1118
1122 BuiltinMic = 15,
1123
1127 FMTuner = 16,
1128
1132 TVTuner = 17,
1133
1137 Telephony = 18,
1138
1142 AuxLine = 19,
1143
1147 IP = 20,
1148
1152 Bus = 21,
1153
1157 UsbHeadset = 22,
1158
1162 HearingAid = 23,
1163
1171 BuiltinSpeakerSafe = 24,
1172
1177 RemoteSubmix = 25,
1183 BleHeadset = 26,
1184
1188 BleSpeaker = 27,
1189
1193 HdmiEarc = 29,
1194
1198 BleBroadcast = 30,
1199
1204 DockAnalog = 31
1205 };
1206
1212 enum class MMapPolicy : int32_t {
1216 Unspecified = kUnspecified,
1217
1221 Never = 1,
1222
1228 Auto,
1229
1233 Always
1234 };
1235
1240 enum class FlushFromAccuracy : int32_t {
1245 Undefined = 0, // AAUDIO_FLUSH_FROM_ACCURACY_UNDEFINED
1246
1251 Accurate = 1, // AAUDIO_FLUSH_FROM_ACCURACY_ACCURATE
1252 };
1253
1257 enum class FallbackMode : int32_t {
1261 Default = 0, // AAUDIO_FALLBACK_MODE_DEFAULT
1265 Mute = 1, // AAUDIO_FALLBACK_MODE_MUTE
1270 Fail = 2, // AAUDIO_FALLBACK_MODE_FAIL
1271 };
1272
1277 enum class StretchMode : int32_t {
1281 Default = 0, // AAUDIO_STRETCH_MODE_DEFAULT
1285 Voice = 1, // AAUDIO_STRETCH_MODE_VOICE
1286 };
1287
1295 FallbackMode fallbackMode;
1299 StretchMode stretchMode;
1305 float pitch;
1310 float speed;
1311 };
1312
1332
1333 public:
1334
1336 static int32_t SampleRate;
1338 static int32_t FramesPerBurst;
1340 static int32_t ChannelCount;
1341
1342 };
1343
1348 int64_t position; // in frames
1349 int64_t timestamp; // in nanoseconds
1350 };
1351
1353 public:
1354
1355 static bool areWorkaroundsEnabled() {
1356 return mWorkaroundsEnabled;
1357 }
1358
1364 static void setWorkaroundsEnabled(bool enabled) {
1365 mWorkaroundsEnabled = enabled;
1366 }
1367
1368 private:
1369 static bool mWorkaroundsEnabled;
1370 };
1371} // namespace oboe
1372
1373#endif // OBOE_DEFINITIONS_H
Definition Definitions.h:1331
static int32_t SampleRate
Definition Definitions.h:1336
static int32_t FramesPerBurst
Definition Definitions.h:1338
static int32_t ChannelCount
Definition Definitions.h:1340
Definition Definitions.h:1352
static void setWorkaroundsEnabled(bool enabled)
Definition Definitions.h:1364
Definition Definitions.h:1347
Definition Definitions.h:1291
float pitch
Definition Definitions.h:1305
float speed
Definition Definitions.h:1310
FallbackMode fallbackMode
Definition Definitions.h:1295
StretchMode stretchMode
Definition Definitions.h:1299