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
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
102 Unspecified = 0, // AAUDIO_FORMAT_UNSPECIFIED,
103
107 I16 = 1, // AAUDIO_FORMAT_PCM_I16,
108
116 Float = 2, // AAUDIO_FORMAT_PCM_FLOAT,
117
127 I24 = 3, // AAUDIO_FORMAT_PCM_I24_PACKED
128
138 I32 = 4, // AAUDIO_FORMAT_PCM_I32
139
140 };
141
145 enum class DataCallbackResult : int32_t { // aaudio_data_callback_result_t
146 // Indicates to the caller that the callbacks should continue.
147 Continue = 0, // AAUDIO_CALLBACK_RESULT_CONTINUE,
148
149 // Indicates to the caller that the callbacks should stop immediately.
150 Stop = 1, // AAUDIO_CALLBACK_RESULT_STOP,
151 };
152
157 enum class Result : int32_t { // aaudio_result_t
158 OK = 0, // AAUDIO_OK
159 ErrorBase = -900, // AAUDIO_ERROR_BASE,
160 ErrorDisconnected = -899, // AAUDIO_ERROR_DISCONNECTED,
161 ErrorIllegalArgument = -898, // AAUDIO_ERROR_ILLEGAL_ARGUMENT,
162 ErrorInternal = -896, // AAUDIO_ERROR_INTERNAL,
163 ErrorInvalidState = -895, // AAUDIO_ERROR_INVALID_STATE,
164 ErrorInvalidHandle = -892, // AAUDIO_ERROR_INVALID_HANDLE,
165 ErrorUnimplemented = -890, // AAUDIO_ERROR_UNIMPLEMENTED,
166 ErrorUnavailable = -889, // AAUDIO_ERROR_UNAVAILABLE,
167 ErrorNoFreeHandles = -888, // AAUDIO_ERROR_NO_FREE_HANDLES,
168 ErrorNoMemory = -887, // AAUDIO_ERROR_NO_MEMORY,
169 ErrorNull = -886, // AAUDIO_ERROR_NULL,
170 ErrorTimeout = -885, // AAUDIO_ERROR_TIMEOUT,
171 ErrorWouldBlock = -884, // AAUDIO_ERROR_WOULD_BLOCK,
172 ErrorInvalidFormat = -883, // AAUDIO_ERROR_INVALID_FORMAT,
173 ErrorOutOfRange = -882, // AAUDIO_ERROR_OUT_OF_RANGE,
174 ErrorNoService = -881, // AAUDIO_ERROR_NO_SERVICE,
175 ErrorInvalidRate = -880, // AAUDIO_ERROR_INVALID_RATE,
176 // Reserved for future AAudio result types
177 Reserved1,
178 Reserved2,
179 Reserved3,
180 Reserved4,
181 Reserved5,
182 Reserved6,
183 Reserved7,
184 Reserved8,
185 Reserved9,
186 Reserved10,
187 ErrorClosed = -869,
188 };
189
193 enum class SharingMode : int32_t { // aaudio_sharing_mode_t
194
203 Exclusive = 0, // AAUDIO_SHARING_MODE_EXCLUSIVE,
204
212 Shared = 1, // AAUDIO_SHARING_MODE_SHARED,
213 };
214
218 enum class PerformanceMode : int32_t { // aaudio_performance_mode_t
219
223 None = 10, // AAUDIO_PERFORMANCE_MODE_NONE,
224
228 PowerSaving = 11, // AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
229
233 LowLatency = 12, // AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
234 };
235
239 enum class AudioApi : int32_t {
244
249 OpenSLES,
250
256 AAudio
257 };
258
264 enum class SampleRateConversionQuality : int32_t {
268 None,
273 Fastest,
277 Low,
281 Medium,
285 High,
289 Best,
290 };
291
301 enum class Usage : int32_t { // aaudio_usage_t
305 Media = 1, // AAUDIO_USAGE_MEDIA
306
310 VoiceCommunication = 2, // AAUDIO_USAGE_VOICE_COMMUNICATION
311
315 VoiceCommunicationSignalling = 3, // AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING
316
320 Alarm = 4, // AAUDIO_USAGE_ALARM
321
326 Notification = 5, // AAUDIO_USAGE_NOTIFICATION
327
331 NotificationRingtone = 6, // AAUDIO_USAGE_NOTIFICATION_RINGTONE
332
336 NotificationEvent = 10, // AAUDIO_USAGE_NOTIFICATION_EVENT
337
341 AssistanceAccessibility = 11, // AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY
342
346 AssistanceNavigationGuidance = 12, // AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE
347
351 AssistanceSonification = 13, // AAUDIO_USAGE_ASSISTANCE_SONIFICATION
352
356 Game = 14, // AAUDIO_USAGE_GAME
357
361 Assistant = 16, // AAUDIO_USAGE_ASSISTANT
362 };
363
364
377 enum ContentType : int32_t { // aaudio_content_type_t
378
382 Speech = 1, // AAUDIO_CONTENT_TYPE_SPEECH
383
387 Music = 2, // AAUDIO_CONTENT_TYPE_MUSIC
388
392 Movie = 3, // AAUDIO_CONTENT_TYPE_MOVIE
393
398 Sonification = 4, // AAUDIO_CONTENT_TYPE_SONIFICATION
399 };
400
410 enum InputPreset : int32_t { // aaudio_input_preset_t
414 Generic = 1, // AAUDIO_INPUT_PRESET_GENERIC
415
419 Camcorder = 5, // AAUDIO_INPUT_PRESET_CAMCORDER
420
424 VoiceRecognition = 6, // AAUDIO_INPUT_PRESET_VOICE_RECOGNITION
425
429 VoiceCommunication = 7, // AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION
430
436 Unprocessed = 9, // AAUDIO_INPUT_PRESET_UNPROCESSED
437
443 VoicePerformance = 10, // AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE
444
445 };
446
458 None = -1, // AAUDIO_SESSION_ID_NONE
459
467 Allocate = 0, // AAUDIO_SESSION_ID_ALLOCATE
468 };
469
480 enum ChannelCount : int32_t {
485
489 Mono = 1,
490
495 };
496
506 enum class ChannelMask : uint32_t { // aaudio_channel_mask_t
508 FrontLeft = 1 << 0,
509 FrontRight = 1 << 1,
510 FrontCenter = 1 << 2,
511 LowFrequency = 1 << 3,
512 BackLeft = 1 << 4,
513 BackRight = 1 << 5,
514 FrontLeftOfCenter = 1 << 6,
515 FrontRightOfCenter = 1 << 7,
516 BackCenter = 1 << 8,
517 SideLeft = 1 << 9,
518 SideRight = 1 << 10,
519 TopCenter = 1 << 11,
520 TopFrontLeft = 1 << 12,
521 TopFrontCenter = 1 << 13,
522 TopFrontRight = 1 << 14,
523 TopBackLeft = 1 << 15,
524 TopBackCenter = 1 << 16,
525 TopBackRight = 1 << 17,
526 TopSideLeft = 1 << 18,
527 TopSideRight = 1 << 19,
528 BottomFrontLeft = 1 << 20,
529 BottomFrontCenter = 1 << 21,
530 BottomFrontRight = 1 << 22,
531 LowFrequency2 = 1 << 23,
532 FrontWideLeft = 1 << 24,
533 FrontWideRight = 1 << 25,
534
535 Mono = FrontLeft,
536
537 Stereo = FrontLeft |
538 FrontRight,
539
540 CM2Point1 = FrontLeft |
541 FrontRight |
542 LowFrequency,
543
544 Tri = FrontLeft |
545 FrontRight |
546 FrontCenter,
547
548 TriBack = FrontLeft |
549 FrontRight |
550 BackCenter,
551
552 CM3Point1 = FrontLeft |
553 FrontRight |
554 FrontCenter |
555 LowFrequency,
556
557 CM2Point0Point2 = FrontLeft |
558 FrontRight |
559 TopSideLeft |
560 TopSideRight,
561
562 CM2Point1Point2 = CM2Point0Point2 |
563 LowFrequency,
564
565 CM3Point0Point2 = FrontLeft |
566 FrontRight |
567 FrontCenter |
568 TopSideLeft |
569 TopSideRight,
570
571 CM3Point1Point2 = CM3Point0Point2 |
572 LowFrequency,
573
574 Quad = FrontLeft |
575 FrontRight |
576 BackLeft |
577 BackRight,
578
579 QuadSide = FrontLeft |
580 FrontRight |
581 SideLeft |
582 SideRight,
583
584 Surround = FrontLeft |
585 FrontRight |
586 FrontCenter |
587 BackCenter,
588
589 Penta = Quad |
590 FrontCenter,
591
592 // aka 5Point1Back
593 CM5Point1 = FrontLeft |
594 FrontRight |
595 FrontCenter |
596 LowFrequency |
597 BackLeft |
598 BackRight,
599
600 CM5Point1Side = FrontLeft |
601 FrontRight |
602 FrontCenter |
603 LowFrequency |
604 SideLeft |
605 SideRight,
606
607 CM6Point1 = FrontLeft |
608 FrontRight |
609 FrontCenter |
610 LowFrequency |
611 BackLeft |
612 BackRight |
613 BackCenter,
614
615 CM7Point1 = CM5Point1 |
616 SideLeft |
617 SideRight,
618
619 CM5Point1Point2 = CM5Point1 |
620 TopSideLeft |
621 TopSideRight,
622
623 CM5Point1Point4 = CM5Point1 |
624 TopFrontLeft |
625 TopFrontRight |
626 TopBackLeft |
627 TopBackRight,
628
629 CM7Point1Point2 = CM7Point1 |
630 TopSideLeft |
631 TopSideRight,
632
633 CM7Point1Point4 = CM7Point1 |
634 TopFrontLeft |
635 TopFrontRight |
636 TopBackLeft |
637 TopBackRight,
638
639 CM9Point1Point4 = CM7Point1Point4 |
640 FrontWideLeft |
641 FrontWideRight,
642
643 CM9Point1Point6 = CM9Point1Point4 |
644 TopSideLeft |
645 TopSideRight,
646
647 FrontBack = FrontCenter |
648 BackCenter,
649 };
650
670
671 public:
672
674 static int32_t SampleRate;
676 static int32_t FramesPerBurst;
678 static int32_t ChannelCount;
679
680 };
681
686 int64_t position; // in frames
687 int64_t timestamp; // in nanoseconds
688 };
689
691 public:
692
693 static bool areWorkaroundsEnabled() {
694 return mWorkaroundsEnabled;
695 }
696
702 static void setWorkaroundsEnabled(bool enabled) {
703 mWorkaroundsEnabled = enabled;
704 }
705
706 private:
707 static bool mWorkaroundsEnabled;
708 };
709} // namespace oboe
710
711#endif // OBOE_DEFINITIONS_H
Definition: Definitions.h:669
static int32_t SampleRate
Definition: Definitions.h:674
static int32_t FramesPerBurst
Definition: Definitions.h:676
static int32_t ChannelCount
Definition: Definitions.h:678
Definition: Definitions.h:690
static void setWorkaroundsEnabled(bool enabled)
Definition: Definitions.h:702
Definition: AudioStream.h:31
Usage
Definition: Definitions.h:301
@ AssistanceSonification
@ VoiceCommunicationSignalling
@ NotificationRingtone
@ AssistanceAccessibility
@ AssistanceNavigationGuidance
PerformanceMode
Definition: Definitions.h:218
ContentType
Definition: Definitions.h:377
@ Sonification
Definition: Definitions.h:398
@ Speech
Definition: Definitions.h:382
@ Movie
Definition: Definitions.h:392
@ Music
Definition: Definitions.h:387
InputPreset
Definition: Definitions.h:410
@ Generic
Definition: Definitions.h:414
@ VoiceCommunication
Definition: Definitions.h:429
@ Camcorder
Definition: Definitions.h:419
@ Unprocessed
Definition: Definitions.h:436
@ VoicePerformance
Definition: Definitions.h:443
@ VoiceRecognition
Definition: Definitions.h:424
Result
Definition: Definitions.h:157
ChannelCount
Definition: Definitions.h:480
@ Stereo
Definition: Definitions.h:494
@ Mono
Definition: Definitions.h:489
@ Unspecified
Definition: Definitions.h:484
SessionId
Definition: Definitions.h:452
@ None
Definition: Definitions.h:458
@ Allocate
Definition: Definitions.h:467
constexpr int64_t kNanosPerSecond
Definition: Definitions.h:52
SampleRateConversionQuality
Definition: Definitions.h:264
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:42
SharingMode
Definition: Definitions.h:193
StreamState
Definition: Definitions.h:57
AudioApi
Definition: Definitions.h:239
AudioFormat
Definition: Definitions.h:93
constexpr int32_t kUnspecified
Definition: Definitions.h:31
ChannelMask
Definition: Definitions.h:506
constexpr int64_t kMillisPerSecond
Definition: Definitions.h:47
constexpr int64_t kNanosPerMicrosecond
Definition: Definitions.h:37
Direction
Definition: Definitions.h:77
DataCallbackResult
Definition: Definitions.h:145
Definition: Definitions.h:685