diff --git a/docs/reference/_audio_stream_8h_source.html b/docs/reference/_audio_stream_8h_source.html deleted file mode 100644 index 458f30204..000000000 --- a/docs/reference/_audio_stream_8h_source.html +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - - -Oboe: include/oboe/AudioStream.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
AudioStream.h
-
-
-
1 /*
2  * Copyright 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_STREAM_H_
18 #define OBOE_STREAM_H_
19 
20 #include <cstdint>
21 #include <ctime>
22 #include "oboe/Definitions.h"
23 #include "oboe/ResultWithValue.h"
24 #include "oboe/AudioStreamBuilder.h"
25 #include "oboe/AudioStreamBase.h"
26 
29 namespace oboe {
30 
31 constexpr int64_t kDefaultTimeoutNanos = (2000 * kNanosPerMillisecond);
32 
36 class AudioStream : public AudioStreamBase {
37 public:
38 
39  AudioStream() {}
40  explicit AudioStream(const AudioStreamBuilder &builder);
41 
42  virtual ~AudioStream() = default;
43 
52  virtual Result open();
53 
57  virtual Result close() = 0;
58 
59  /*
60  * These are synchronous and will block until the operation is complete.
61  */
62  virtual Result start(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
63  virtual Result pause(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
64  virtual Result flush(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
65  virtual Result stop(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
66 
67  /* Asynchronous requests.
68  * Use waitForStateChange() if you need to wait for completion.
69  */
70  virtual Result requestStart() = 0;
71  virtual Result requestPause() = 0;
72  virtual Result requestFlush() = 0;
73  virtual Result requestStop() = 0;
74 
80  virtual StreamState getState() = 0;
81 
106  virtual Result waitForStateChange(StreamState inputState,
107  StreamState *nextState,
108  int64_t timeoutNanoseconds) = 0;
109 
122  virtual ResultWithValue<int32_t> setBufferSizeInFrames(int32_t requestedFrames) {
123  return Result::ErrorUnimplemented;
124  }
125 
139  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
140  }
141 
145  virtual bool isXRunCountSupported() const = 0;
146 
152  virtual int32_t getFramesPerBurst() = 0;
153 
154  bool isPlaying();
155 
156  int32_t getBytesPerFrame() const { return mChannelCount * getBytesPerSample(); }
157 
158  int32_t getBytesPerSample() const;
159 
164  virtual int64_t getFramesWritten() { return mFramesWritten; }
165 
166  virtual int64_t getFramesRead() { return mFramesRead; }
167 
192  return ResultWithValue<double>(Result::ErrorUnimplemented);
193  }
194 
195  virtual Result getTimestamp(clockid_t clockId,
196  int64_t *framePosition,
197  int64_t *timeNanoseconds) {
198  return Result::ErrorUnimplemented;
199  }
200 
201  // ============== I/O ===========================
213  virtual ResultWithValue<int32_t> write(const void *buffer,
214  int32_t numFrames,
215  int64_t timeoutNanoseconds) {
216  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
217  }
218 
219  virtual ResultWithValue<int32_t> read(void *buffer,
220  int32_t numFrames,
221  int64_t timeoutNanoseconds) {
222  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
223  }
224 
229  virtual AudioApi getAudioApi() const = 0;
230 
234  bool usesAAudio() const {
235  return getAudioApi() == AudioApi::AAudio;
236  }
237 
246  virtual void *getUnderlyingStream() const {
247  return nullptr;
248  }
249 
250 protected:
251 
252  virtual int64_t incrementFramesWritten(int32_t frames) {
253  return mFramesWritten += frames;
254  }
255  virtual int64_t incrementFramesRead(int32_t frames) {
256  return mFramesRead += frames;
257  }
258 
265  virtual Result waitForStateTransition(StreamState startingState,
266  StreamState endingState,
267  int64_t timeoutNanoseconds);
268 
276  virtual DataCallbackResult onDefaultCallback(void *audioData, int numFrames) {
277  return DataCallbackResult::Stop;
278  }
279 
280  DataCallbackResult fireCallback(void *audioData, int numFrames);
281 
282  virtual void setNativeFormat(AudioFormat format) {
283  mNativeFormat = format;
284  }
285 
286  // TODO: make private
287  // These do not change after open.
288  AudioFormat mNativeFormat = AudioFormat::Invalid;
289 
290  // TODO these should be atomic like in AAudio
291  int64_t mFramesWritten = 0;
292  int64_t mFramesRead = 0;
293 
294 private:
295  // TODO these should be atomic like in AAudio
296  int mPreviousScheduler = -1;
297 };
298 
299 } // namespace oboe
300 
301 #endif /* OBOE_STREAM_H_ */
-
Definition: AudioStreamBuilder.h:28
-
bool usesAAudio() const
Definition: AudioStream.h:234
-
virtual ResultWithValue< int32_t > getXRunCount() const
Definition: AudioStream.h:138
-
virtual void * getUnderlyingStream() const
Definition: AudioStream.h:246
-
virtual int64_t getFramesWritten()
Definition: AudioStream.h:164
-
virtual Result close()=0
-
virtual ResultWithValue< int32_t > setBufferSizeInFrames(int32_t requestedFrames)
Definition: AudioStream.h:122
-
virtual StreamState getState()=0
-
AudioApi
Definition: Definitions.h:141
-
virtual Result waitForStateTransition(StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)
-
virtual int32_t getFramesPerBurst()=0
-
virtual ResultWithValue< double > calculateLatencyMillis()
Definition: AudioStream.h:191
-
virtual Result open()
-
Definition: AudioStream.h:36
-
Definition: AudioStreamBase.h:34
-
virtual ResultWithValue< int32_t > write(const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
Definition: AudioStream.h:213
-
virtual DataCallbackResult onDefaultCallback(void *audioData, int numFrames)
Definition: AudioStream.h:276
-
virtual AudioApi getAudioApi() const =0
-
virtual Result waitForStateChange(StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0
-
Definition: AudioStream.h:29
-
virtual bool isXRunCountSupported() const =0
-
Definition: ResultWithValue.h:27
-
- - - - diff --git a/docs/reference/_audio_stream_base_8h_source.html b/docs/reference/_audio_stream_base_8h_source.html deleted file mode 100644 index 6633e44bf..000000000 --- a/docs/reference/_audio_stream_base_8h_source.html +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - -Oboe: include/oboe/AudioStreamBase.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
AudioStreamBase.h
-
-
-
1 /*
2  * Copyright 2015 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_STREAM_BASE_H_
18 #define OBOE_STREAM_BASE_H_
19 
20 #include <memory>
21 #include "oboe/AudioStreamCallback.h"
22 #include "oboe/Definitions.h"
23 
24 namespace oboe {
25 
35 public:
36 
37  AudioStreamBase() {}
38 
39  virtual ~AudioStreamBase() = default;
40 
41  // This class only contains primitives so we can use default constructor and copy methods.
42  AudioStreamBase(const AudioStreamBase&) = default;
43 
44  AudioStreamBase& operator=(const AudioStreamBase&) = default;
45 
49  int getChannelCount() const { return mChannelCount; }
50 
54  Direction getDirection() const { return mDirection; }
55 
59  int32_t getSampleRate() const { return mSampleRate; }
60 
64  int getFramesPerCallback() const { return mFramesPerCallback; }
65 
70  AudioFormat getFormat() const { return mFormat; }
71 
78  virtual int32_t getBufferSizeInFrames() { return mBufferSizeInFrames; };
79 
83  virtual int32_t getBufferCapacityInFrames() const { return mBufferCapacityInFrames; }
84 
85  SharingMode getSharingMode() const { return mSharingMode; }
86 
87  PerformanceMode getPerformanceMode() const { return mPerformanceMode; }
88 
89  int32_t getDeviceId() const { return mDeviceId; }
90 
91  AudioStreamCallback* getCallback() const {
92  return mStreamCallback;
93  }
94 
95  Usage getUsage() const { return mUsage; }
96 
97  ContentType getContentType() const { return mContentType; }
98 
99  InputPreset getInputPreset() const { return mInputPreset; }
100 
101  SessionId getSessionId() const { return mSessionId; }
102 
103 protected:
104  AudioStreamCallback *mStreamCallback = nullptr;
105  int32_t mFramesPerCallback = kUnspecified;
106  int32_t mChannelCount = kUnspecified;
107  int32_t mSampleRate = kUnspecified;
108  int32_t mDeviceId = kUnspecified;
109  int32_t mBufferCapacityInFrames = kUnspecified;
110  int32_t mBufferSizeInFrames = kUnspecified;
111  int32_t mFramesPerBurst = kUnspecified;
112 
113  SharingMode mSharingMode = SharingMode::Shared;
114  AudioFormat mFormat = AudioFormat::Unspecified;
115  Direction mDirection = Direction::Output;
116  PerformanceMode mPerformanceMode = PerformanceMode::None;
117  // Added in API 28
118  Usage mUsage = Usage::Media;
119  ContentType mContentType = ContentType::Music;
120  InputPreset mInputPreset = InputPreset::VoiceRecognition;
121  SessionId mSessionId = SessionId::None;
122 };
123 
124 } // namespace oboe
125 
126 #endif /* OBOE_STREAM_BASE_H_ */
-
SessionId
Definition: Definitions.h:314
- -
AudioFormat getFormat() const
Definition: AudioStreamBase.h:70
-
int32_t getSampleRate() const
Definition: AudioStreamBase.h:59
-
Definition: AudioStreamBase.h:34
-
virtual int32_t getBufferSizeInFrames()
Definition: AudioStreamBase.h:78
-
int getChannelCount() const
Definition: AudioStreamBase.h:49
-
ContentType
Definition: Definitions.h:252
-
SharingMode
Definition: Definitions.h:113
-
virtual int32_t getBufferCapacityInFrames() const
Definition: AudioStreamBase.h:83
-
Definition: AudioStream.h:29
-
InputPreset
Definition: Definitions.h:285
-
Direction getDirection() const
Definition: AudioStreamBase.h:54
-
Usage
Definition: Definitions.h:174
-
int getFramesPerCallback() const
Definition: AudioStreamBase.h:64
-
- - - - diff --git a/docs/reference/_audio_stream_builder_8h_source.html b/docs/reference/_audio_stream_builder_8h_source.html deleted file mode 100644 index e3442449c..000000000 --- a/docs/reference/_audio_stream_builder_8h_source.html +++ /dev/null @@ -1,111 +0,0 @@ - - - - - - - -Oboe: include/oboe/AudioStreamBuilder.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
AudioStreamBuilder.h
-
-
-
1 /*
2  * Copyright 2015 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_STREAM_BUILDER_H_
18 #define OBOE_STREAM_BUILDER_H_
19 
20 #include "oboe/Definitions.h"
21 #include "oboe/AudioStreamBase.h"
22 
23 namespace oboe {
24 
29 public:
30 
32 
39  AudioStreamBuilder *setChannelCount(int channelCount) {
40  mChannelCount = channelCount;
41  return this;
42  }
43 
49  AudioStreamBuilder *setDirection(Direction direction) {
50  mDirection = direction;
51  return this;
52  }
53 
65  AudioStreamBuilder *setSampleRate(int32_t sampleRate) {
66  mSampleRate = sampleRate;
67  return this;
68  }
69 
84  AudioStreamBuilder *setFramesPerCallback(int framesPerCallback) {
85  mFramesPerCallback = framesPerCallback;
86  return this;
87  }
88 
95  AudioStreamBuilder *setFormat(AudioFormat format) {
96  mFormat = format;
97  return this;
98  }
99 
109  AudioStreamBuilder *setBufferCapacityInFrames(int32_t bufferCapacityInFrames) {
110  mBufferCapacityInFrames = bufferCapacityInFrames;
111  return this;
112  }
113 
114  AudioApi getAudioApi() const { return mAudioApi; }
115 
126  mAudioApi = audioApi;
127  return this;
128  }
129 
137  static bool isAAudioSupported();
138 
146  static bool isAAudioRecommended();
147 
157  mSharingMode = sharingMode;
158  return this;
159  }
160 
169  AudioStreamBuilder *setPerformanceMode(PerformanceMode performanceMode) {
170  mPerformanceMode = performanceMode;
171  return this;
172  }
173 
174 
188  mUsage = usage;
189  return this;
190  }
191 
205  mContentType = contentType;
206  return this;
207  }
208 
225  mInputPreset = inputPreset;
226  return this;
227  }
228 
254  mSessionId = sessionId;
255  return this;
256  }
257 
270  AudioStreamBuilder *setDeviceId(int32_t deviceId) {
271  mDeviceId = deviceId;
272  return this;
273  }
274 
294  mStreamCallback = streamCallback;
295  return this;
296  }
297 
304  Result openStream(AudioStream **stream);
305 
306 protected:
307 
308 private:
309 
315  oboe::AudioStream *build();
316 
317  AudioApi mAudioApi = AudioApi::Unspecified;
318 };
319 
320 } // namespace oboe
321 
322 #endif /* OBOE_STREAM_BUILDER_H_ */
AudioStreamBuilder * setDeviceId(int32_t deviceId)
Definition: AudioStreamBuilder.h:270
-
Definition: AudioStreamBuilder.h:28
-
AudioStreamBuilder * setPerformanceMode(PerformanceMode performanceMode)
Definition: AudioStreamBuilder.h:169
-
static bool isAAudioRecommended()
-
SessionId
Definition: Definitions.h:314
-
AudioStreamBuilder * setSessionId(SessionId sessionId)
Definition: AudioStreamBuilder.h:253
-
Definition: AudioStreamCallback.h:26
-
AudioStreamBuilder * setContentType(ContentType contentType)
Definition: AudioStreamBuilder.h:204
-
AudioApi
Definition: Definitions.h:141
-
AudioStreamBuilder * setUsage(Usage usage)
Definition: AudioStreamBuilder.h:187
-
static bool isAAudioSupported()
-
AudioStreamBuilder * setFramesPerCallback(int framesPerCallback)
Definition: AudioStreamBuilder.h:84
-
AudioStreamBuilder * setDirection(Direction direction)
Definition: AudioStreamBuilder.h:49
-
AudioStreamBuilder * setFormat(AudioFormat format)
Definition: AudioStreamBuilder.h:95
-
Definition: AudioStream.h:36
-
AudioStreamBuilder * setAudioApi(AudioApi audioApi)
Definition: AudioStreamBuilder.h:125
-
AudioStreamBuilder * setInputPreset(InputPreset inputPreset)
Definition: AudioStreamBuilder.h:224
-
AudioStreamBuilder * setSampleRate(int32_t sampleRate)
Definition: AudioStreamBuilder.h:65
-
Definition: AudioStreamBase.h:34
-
AudioStreamBuilder * setBufferCapacityInFrames(int32_t bufferCapacityInFrames)
Definition: AudioStreamBuilder.h:109
-
Result openStream(AudioStream **stream)
-
ContentType
Definition: Definitions.h:252
-
SharingMode
Definition: Definitions.h:113
-
AudioStreamBuilder * setSharingMode(SharingMode sharingMode)
Definition: AudioStreamBuilder.h:156
-
Definition: AudioStream.h:29
-
InputPreset
Definition: Definitions.h:285
-
AudioStreamBuilder * setChannelCount(int channelCount)
Definition: AudioStreamBuilder.h:39
-
AudioStreamBuilder * setCallback(AudioStreamCallback *streamCallback)
Definition: AudioStreamBuilder.h:293
-
Usage
Definition: Definitions.h:174
-
- - - - diff --git a/docs/reference/_audio_stream_callback_8h_source.html b/docs/reference/_audio_stream_callback_8h_source.html deleted file mode 100644 index 919e4719f..000000000 --- a/docs/reference/_audio_stream_callback_8h_source.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - -Oboe: include/oboe/AudioStreamCallback.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
AudioStreamCallback.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_STREAM_CALLBACK_H
18 #define OBOE_STREAM_CALLBACK_H
19 
20 #include "oboe/Definitions.h"
21 
22 namespace oboe {
23 
24 class AudioStream;
25 
27 public:
28  virtual ~AudioStreamCallback() = default;
29 
38  virtual DataCallbackResult onAudioReady(
39  AudioStream *oboeStream,
40  void *audioData,
41  int32_t numFrames) = 0;
42 
51  virtual void onErrorBeforeClose(AudioStream *oboeStream, Result error) {}
52 
63  virtual void onErrorAfterClose(AudioStream *oboeStream, Result error) {}
64 
65 };
66 
67 } // namespace oboe
68 
69 #endif //OBOE_STREAM_CALLBACK_H
virtual void onErrorAfterClose(AudioStream *oboeStream, Result error)
Definition: AudioStreamCallback.h:63
-
virtual void onErrorBeforeClose(AudioStream *oboeStream, Result error)
Definition: AudioStreamCallback.h:51
-
Definition: AudioStreamCallback.h:26
-
virtual DataCallbackResult onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames)=0
-
Definition: AudioStream.h:36
-
Definition: AudioStream.h:29
-
- - - - diff --git a/docs/reference/_definitions_8h_source.html b/docs/reference/_definitions_8h_source.html deleted file mode 100644 index 12caaed9a..000000000 --- a/docs/reference/_definitions_8h_source.html +++ /dev/null @@ -1,121 +0,0 @@ - - - - - - - -Oboe: include/oboe/Definitions.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for 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 
38  constexpr int32_t kUnspecified = 0;
39 
40  // TODO: Investigate using std::chrono
41  constexpr int64_t kNanosPerMicrosecond = 1000;
42  constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000;
43  constexpr int64_t kMillisPerSecond = 1000;
44  constexpr int64_t kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond;
45 
46  enum class StreamState : aaudio_stream_state_t {
47  Uninitialized = AAUDIO_STREAM_STATE_UNINITIALIZED,
48  Unknown = AAUDIO_STREAM_STATE_UNKNOWN,
49  Open = AAUDIO_STREAM_STATE_OPEN,
50  Starting = AAUDIO_STREAM_STATE_STARTING,
51  Started = AAUDIO_STREAM_STATE_STARTED,
52  Pausing = AAUDIO_STREAM_STATE_PAUSING,
53  Paused = AAUDIO_STREAM_STATE_PAUSED,
54  Flushing = AAUDIO_STREAM_STATE_FLUSHING,
55  Flushed = AAUDIO_STREAM_STATE_FLUSHED,
56  Stopping = AAUDIO_STREAM_STATE_STOPPING,
57  Stopped = AAUDIO_STREAM_STATE_STOPPED,
58  Closing = AAUDIO_STREAM_STATE_CLOSING,
59  Closed = AAUDIO_STREAM_STATE_CLOSED,
60  Disconnected = AAUDIO_STREAM_STATE_DISCONNECTED,
61  };
62 
63  enum class Direction : aaudio_direction_t {
64  Output = AAUDIO_DIRECTION_OUTPUT,
65  Input = AAUDIO_DIRECTION_INPUT,
66  };
67 
68  enum class AudioFormat : aaudio_format_t {
69  Invalid = AAUDIO_FORMAT_INVALID,
70  Unspecified = AAUDIO_FORMAT_UNSPECIFIED,
71  I16 = AAUDIO_FORMAT_PCM_I16,
72  Float = AAUDIO_FORMAT_PCM_FLOAT,
73  };
74 
75  enum class DataCallbackResult : aaudio_data_callback_result_t {
76  Continue = AAUDIO_CALLBACK_RESULT_CONTINUE,
77  Stop = AAUDIO_CALLBACK_RESULT_STOP,
78  };
79 
80  enum class Result : aaudio_result_t {
81  OK,
82  ErrorBase = AAUDIO_ERROR_BASE,
83  ErrorDisconnected = AAUDIO_ERROR_DISCONNECTED,
84  ErrorIllegalArgument = AAUDIO_ERROR_ILLEGAL_ARGUMENT,
85  ErrorInternal = AAUDIO_ERROR_INTERNAL,
86  ErrorInvalidState = AAUDIO_ERROR_INVALID_STATE,
87  ErrorInvalidHandle = AAUDIO_ERROR_INVALID_HANDLE,
88  ErrorUnimplemented = AAUDIO_ERROR_UNIMPLEMENTED,
89  ErrorUnavailable = AAUDIO_ERROR_UNAVAILABLE,
90  ErrorNoFreeHandles = AAUDIO_ERROR_NO_FREE_HANDLES,
91  ErrorNoMemory = AAUDIO_ERROR_NO_MEMORY,
92  ErrorNull = AAUDIO_ERROR_NULL,
93  ErrorTimeout = AAUDIO_ERROR_TIMEOUT,
94  ErrorWouldBlock = AAUDIO_ERROR_WOULD_BLOCK,
95  ErrorInvalidFormat = AAUDIO_ERROR_INVALID_FORMAT,
96  ErrorOutOfRange = AAUDIO_ERROR_OUT_OF_RANGE,
97  ErrorNoService = AAUDIO_ERROR_NO_SERVICE,
98  ErrorInvalidRate = AAUDIO_ERROR_INVALID_RATE,
99  // Reserved for future AAudio result types
100  Reserved1,
101  Reserved2,
102  Reserved3,
103  Reserved4,
104  Reserved5,
105  Reserved6,
106  Reserved7,
107  Reserved8,
108  Reserved9,
109  Reserved10,
110  ErrorClosed,
111  };
112 
113  enum class SharingMode : aaudio_sharing_mode_t {
114 
120  Exclusive = AAUDIO_SHARING_MODE_EXCLUSIVE,
121 
126  Shared = AAUDIO_SHARING_MODE_SHARED,
127  };
128 
129  enum class PerformanceMode : aaudio_performance_mode_t {
130 
131  // No particular performance needs. Default.
132  None = AAUDIO_PERFORMANCE_MODE_NONE,
133 
134  // Extending battery life is most important.
135  PowerSaving = AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
136 
137  // Reducing latency is most important.
138  LowLatency = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
139  };
140 
141  enum class AudioApi : int32_t {
145  Unspecified = kUnspecified,
146 
150  OpenSLES,
151 
155  AAudio
156  };
157 
158 // Hard code constants so they can be compiled with versions of the NDK before P.
159 #if __ANDROID_API_LEVEL__ >= __ANDROID_API_P__
160 #define CONSTANT_API_P(hard_constant, soft_constant) (soft_constant)
161 #else
162 #define CONSTANT_API_P(hard_constant, soft_constant) (hard_constant)
163 #endif
164 
174  enum class Usage : aaudio_usage_t {
178  Media = CONSTANT_API_P(1, AAUDIO_USAGE_MEDIA),
179 
183  VoiceCommunication = CONSTANT_API_P(2, AAUDIO_USAGE_VOICE_COMMUNICATION),
184 
188  VoiceCommunicationSignalling = CONSTANT_API_P(3,
189  AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING),
190 
194  Alarm = CONSTANT_API_P(4, AAUDIO_USAGE_ALARM),
195 
200  Notification = CONSTANT_API_P(5, AAUDIO_USAGE_NOTIFICATION),
201 
205  NotificationRingtone = CONSTANT_API_P(6, AAUDIO_USAGE_NOTIFICATION_RINGTONE),
206 
210  NotificationEvent = CONSTANT_API_P(10, AAUDIO_USAGE_NOTIFICATION_EVENT),
211 
215  AssistanceAccessibility = CONSTANT_API_P(11, AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY),
216 
220  AssistanceNavigationGuidance = CONSTANT_API_P(12,
221  AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE),
222 
226  AssistanceSonification = CONSTANT_API_P(13, AAUDIO_USAGE_ASSISTANCE_SONIFICATION),
227 
231  Game = CONSTANT_API_P(14, AAUDIO_USAGE_GAME),
232 
236  Assistant = CONSTANT_API_P(16, AAUDIO_USAGE_ASSISTANT),
237  };
238 
239 
252  enum ContentType : aaudio_content_type_t {
253 
257  Speech = CONSTANT_API_P(1, AAUDIO_CONTENT_TYPE_SPEECH),
258 
262  Music = CONSTANT_API_P(2, AAUDIO_CONTENT_TYPE_MUSIC),
263 
267  Movie = CONSTANT_API_P(3, AAUDIO_CONTENT_TYPE_MOVIE),
268 
273  Sonification = CONSTANT_API_P(4, AAUDIO_CONTENT_TYPE_SONIFICATION),
274  };
275 
285  enum InputPreset : aaudio_input_preset_t {
289  Generic = CONSTANT_API_P(1, AAUDIO_INPUT_PRESET_GENERIC),
290 
294  Camcorder = CONSTANT_API_P(5, AAUDIO_INPUT_PRESET_CAMCORDER),
295 
299  VoiceRecognition = CONSTANT_API_P(6, AAUDIO_INPUT_PRESET_VOICE_RECOGNITION),
300 
304  VoiceCommunication = CONSTANT_API_P(7, AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION),
305 
311  Unprocessed = CONSTANT_API_P(9, AAUDIO_INPUT_PRESET_UNPROCESSED),
312  };
313 
314  enum SessionId {
322  None = CONSTANT_API_P(-1, AAUDIO_SESSION_ID_NONE),
323 
333  Allocate = CONSTANT_API_P(0, AAUDIO_SESSION_ID_ALLOCATE),
334  };
335 
336  enum ChannelCount : int32_t {
340  Unspecified = kUnspecified,
341 
345  Mono = 1,
346 
350  Stereo = 2,
351  };
352 
353 #undef CONSTANT_API_P
354 
356 
357  public:
358 
377  static int32_t SampleRate;
378  static int32_t FramesPerBurst;
379  static int32_t ChannelCount;
380  };
381 
382 
383 
384 } // namespace oboe
385 
386 #endif // OBOE_DEFINITIONS_H
- - - -
Definition: Definitions.h:273
-
Definition: Definitions.h:333
-
Definition: Definitions.h:322
-
SessionId
Definition: Definitions.h:314
- -
Definition: Definitions.h:311
- -
AudioApi
Definition: Definitions.h:141
-
Definition: Definitions.h:355
- - -
Definition: Definitions.h:262
-
Definition: Definitions.h:294
-
Definition: Definitions.h:304
- -
Definition: Definitions.h:289
-
Definition: Definitions.h:350
-
ContentType
Definition: Definitions.h:252
-
Definition: Definitions.h:345
-
ChannelCount
Definition: Definitions.h:336
- - -
SharingMode
Definition: Definitions.h:113
- -
Definition: AudioStream.h:29
- - -
Definition: Definitions.h:340
-
InputPreset
Definition: Definitions.h:285
-
static int32_t SampleRate
Definition: Definitions.h:377
-
Usage
Definition: Definitions.h:174
- -
Definition: Definitions.h:257
-
Definition: Definitions.h:299
-
Definition: Definitions.h:267
-
- - - - diff --git a/docs/reference/_latency_tuner_8h_source.html b/docs/reference/_latency_tuner_8h_source.html deleted file mode 100644 index 66e82f898..000000000 --- a/docs/reference/_latency_tuner_8h_source.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - -Oboe: include/oboe/LatencyTuner.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
LatencyTuner.h
-
-
-
1 /*
2  * Copyright 2017 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_LATENCY_TUNER_
18 #define OBOE_LATENCY_TUNER_
19 
20 #include <atomic>
21 #include <cstdint>
22 #include "oboe/Definitions.h"
23 #include "oboe/AudioStream.h"
24 
25 namespace oboe {
26 
42 class LatencyTuner {
43 public:
44  explicit LatencyTuner(AudioStream &stream);
45 
54  Result tune();
55 
64  void requestReset();
65 
66 private:
67 
74  void reset();
75 
76  enum class State {
77  Idle,
78  Active,
79  AtMax,
80  Unsupported
81  } ;
82 
83  // arbitrary number of calls to wait before bumping up the latency
84  static constexpr int32_t kIdleCount = 8;
85 
86  AudioStream &mStream;
87  State mState = State::Idle;
88  int32_t mPreviousXRuns = 0;
89  int32_t mIdleCountDown = 0;
90  std::atomic<int32_t> mLatencyTriggerRequests{0}; // TODO user atomic requester from AAudio
91  std::atomic<int32_t> mLatencyTriggerResponses{0};
92 };
93 
94 } // namespace oboe
95 
96 #endif // OBOE_LATENCY_TUNER_
-
Definition: AudioStream.h:36
- -
Definition: LatencyTuner.h:42
-
Definition: AudioStream.h:29
-
- - - - diff --git a/docs/reference/_oboe_8h_source.html b/docs/reference/_oboe_8h_source.html deleted file mode 100644 index 11346b96e..000000000 --- a/docs/reference/_oboe_8h_source.html +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - -Oboe: include/oboe/Oboe.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
Oboe.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_OBOE_H
18 #define OBOE_OBOE_H
19 
20 #include "oboe/Definitions.h"
21 #include "oboe/ResultWithValue.h"
22 #include "oboe/LatencyTuner.h"
23 #include "oboe/AudioStream.h"
24 #include "oboe/AudioStreamBase.h"
25 #include "oboe/AudioStreamBuilder.h"
26 #include "oboe/Utilities.h"
27 #include "oboe/Version.h"
28 
29 #endif //OBOE_OBOE_H
- - - - diff --git a/docs/reference/_result_with_value_8h_source.html b/docs/reference/_result_with_value_8h_source.html deleted file mode 100644 index 8eeb9332b..000000000 --- a/docs/reference/_result_with_value_8h_source.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - -Oboe: include/oboe/ResultWithValue.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
ResultWithValue.h
-
-
-
1 /*
2  * Copyright (C) 2018 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_RESULT_WITH_VALUE_H
18 #define OBOE_RESULT_WITH_VALUE_H
19 
20 #include "oboe/Definitions.h"
21 #include <iostream>
22 #include <sstream>
23 
24 namespace oboe {
25 
26 template <typename T>
28 public:
29  ResultWithValue(oboe::Result error)
30  : mValue{}
31  , mError(error) {}
32 
33  explicit ResultWithValue(T value)
34  : mValue(value)
35  , mError(oboe::Result::OK) {}
36 
37  oboe::Result error() const {
38  return mError;
39  }
40 
41  T value() const {
42  return mValue;
43  }
44 
48  explicit operator bool() const { return mError == oboe::Result::OK; }
49 
60  bool operator !() const { return mError != oboe::Result::OK; }
61 
70  operator Result() const {
71  return mError;
72  }
73 
81  static ResultWithValue<T> createBasedOnSign(T numericResult){
82 
83  // Ensure that the type is either an integer or float
84  static_assert(std::is_arithmetic<T>::value,
85  "createBasedOnSign can only be called for numeric types (int or float)");
86 
87  if (numericResult >= 0){
88  return ResultWithValue<T>(numericResult);
89  } else {
90  return ResultWithValue<T>(static_cast<Result>(numericResult));
91  }
92  }
93 
94 private:
95  const T mValue;
96  const oboe::Result mError;
97 };
98 
99 template <typename T>
100 std::ostream& operator<<(std::ostream &strm, const ResultWithValue<T> &result) {
101  if (!result) {
102  strm << convertToText(result.error());
103  } else {
104  strm << result.value();
105  }
106  return strm;
107 }
108 
109 } // namespace oboe
110 
111 
112 #endif //OBOE_RESULT_WITH_VALUE_H
static ResultWithValue< T > createBasedOnSign(T numericResult)
Definition: ResultWithValue.h:81
-
const char * convertToText(FromType)
-
Definition: AudioStream.h:29
-
bool operator!() const
Definition: ResultWithValue.h:60
-
Definition: ResultWithValue.h:27
-
- - - - diff --git a/docs/reference/_utilities_8h_source.html b/docs/reference/_utilities_8h_source.html deleted file mode 100644 index 8797fcbbd..000000000 --- a/docs/reference/_utilities_8h_source.html +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - -Oboe: include/oboe/Utilities.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
Utilities.h
-
-
-
1 /*
2  * Copyright 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_UTILITIES_H
18 #define OBOE_UTILITIES_H
19 
20 #include <unistd.h>
21 #include <sys/types.h>
22 #include "oboe/Definitions.h"
23 
24 namespace oboe {
25 
26 void convertFloatToPcm16(const float *source, int16_t *destination, int32_t numSamples);
27 void convertPcm16ToFloat(const int16_t *source, float *destination, int32_t numSamples);
28 
32 int32_t convertFormatToSizeInBytes(AudioFormat format);
33 
43 template <typename FromType>
44 const char * convertToText(FromType);
45 
54 int getSdkVersion();
55 
56 } // namespace oboe
57 
58 #endif //OBOE_UTILITIES_H
const char * convertToText(FromType)
-
int32_t convertFormatToSizeInBytes(AudioFormat format)
-
Definition: AudioStream.h:29
-
int getSdkVersion()
-
- - - - diff --git a/docs/reference/_version_8h_source.html b/docs/reference/_version_8h_source.html deleted file mode 100644 index 348ac5818..000000000 --- a/docs/reference/_version_8h_source.html +++ /dev/null @@ -1,89 +0,0 @@ - - - - - - - -Oboe: include/oboe/Version.h Source File - - - - - - - - - -
-
- - - - - - -
-
Oboe -  1.0 -
-
Audio library for Android
-
-
- - - - - - - - -
-
- - -
- -
- - -
-
-
-
Version.h
-
-
-
1 /*
2  * Copyright 2017 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_VERSIONINFO_H
18 #define OBOE_VERSIONINFO_H
19 
31 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description.
32 #define OBOE_VERSION_MAJOR 0
33 
34 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description.
35 #define OBOE_VERSION_MINOR 12
36 
37 // Type: 16-bit unsigned int. Min value: 0 Max value: 65535. See below for description.
38 #define OBOE_VERSION_PATCH 0
39 
40 #define OBOE_STRINGIFY(x) #x
41 #define OBOE_TOSTRING(x) OBOE_STRINGIFY(x)
42 
43 // Type: String literal. See below for description.
44 #define OBOE_VERSION_TEXT \
45  OBOE_TOSTRING(OBOE_VERSION_MAJOR) "." \
46  OBOE_TOSTRING(OBOE_VERSION_MINOR) "." \
47  OBOE_TOSTRING(OBOE_VERSION_PATCH)
48 
49 // Type: 32-bit unsigned int. See below for description.
50 #define OBOE_VERSION_NUMBER ((OBOE_VERSION_MAJOR << 24) | (OBOE_VERSION_MINOR << 16) | OBOE_VERSION_PATCH)
51 
52 namespace oboe {
53 
54 struct Version {
58  static constexpr uint8_t Major = OBOE_VERSION_MAJOR;
59 
64  static constexpr uint8_t Minor = OBOE_VERSION_MINOR;
65 
70  static constexpr uint16_t Patch = OBOE_VERSION_PATCH;
71 
75  static constexpr const char * Text = OBOE_VERSION_TEXT;
76 
81  static constexpr uint32_t Number = OBOE_VERSION_NUMBER;
82 };
83 
84 } // namespace oboe
85 #endif //OBOE_VERSIONINFO_H
Definition: Version.h:54
-
static constexpr uint8_t Minor
Definition: Version.h:64
-
static constexpr uint8_t Major
Definition: Version.h:58
-
static constexpr uint32_t Number
Definition: Version.h:81
-
static constexpr const char * Text
Definition: Version.h:75
-
Definition: AudioStream.h:29
-
static constexpr uint16_t Patch
Definition: Version.h:70
-
- - - - diff --git a/docs/reference/a00002_source.html b/docs/reference/a00002_source.html index c9ff42a2c..e22584d08 100644 --- a/docs/reference/a00002_source.html +++ b/docs/reference/a00002_source.html @@ -71,29 +71,58 @@
AudioStream.h
-
1 /*
2  * Copyright 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_STREAM_H_
18 #define OBOE_STREAM_H_
19 
20 #include <cstdint>
21 #include <ctime>
22 #include "oboe/Definitions.h"
23 #include "oboe/ResultWithValue.h"
24 #include "oboe/AudioStreamBuilder.h"
25 #include "oboe/AudioStreamBase.h"
26 
29 namespace oboe {
30 
31 constexpr int64_t kDefaultTimeoutNanos = (2000 * kNanosPerMillisecond);
32 
36 class AudioStream : public AudioStreamBase {
37 public:
38 
39  AudioStream() {}
40  explicit AudioStream(const AudioStreamBuilder &builder);
41 
42  virtual ~AudioStream() = default;
43 
52  virtual Result open();
53 
57  virtual Result close() = 0;
58 
59  /*
60  * These are synchronous and will block until the operation is complete.
61  */
62  virtual Result start(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
63  virtual Result pause(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
64  virtual Result flush(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
65  virtual Result stop(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
66 
67  /* Asynchronous requests.
68  * Use waitForStateChange() if you need to wait for completion.
69  */
70  virtual Result requestStart() = 0;
71  virtual Result requestPause() = 0;
72  virtual Result requestFlush() = 0;
73  virtual Result requestStop() = 0;
74 
80  virtual StreamState getState() = 0;
81 
106  virtual Result waitForStateChange(StreamState inputState,
107  StreamState *nextState,
108  int64_t timeoutNanoseconds) = 0;
109 
122  virtual ResultWithValue<int32_t> setBufferSizeInFrames(int32_t requestedFrames) {
123  return Result::ErrorUnimplemented;
124  }
125 
139  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
140  }
141 
145  virtual bool isXRunCountSupported() const = 0;
146 
152  virtual int32_t getFramesPerBurst() = 0;
153 
154  bool isPlaying();
155 
156  int32_t getBytesPerFrame() const { return mChannelCount * getBytesPerSample(); }
157 
158  int32_t getBytesPerSample() const;
159 
164  virtual int64_t getFramesWritten() { return mFramesWritten; }
165 
166  virtual int64_t getFramesRead() { return mFramesRead; }
167 
192  return ResultWithValue<double>(Result::ErrorUnimplemented);
193  }
194 
195  virtual Result getTimestamp(clockid_t clockId,
196  int64_t *framePosition,
197  int64_t *timeNanoseconds) {
198  return Result::ErrorUnimplemented;
199  }
200 
201  // ============== I/O ===========================
213  virtual ResultWithValue<int32_t> write(const void *buffer,
214  int32_t numFrames,
215  int64_t timeoutNanoseconds) {
216  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
217  }
218 
219  virtual ResultWithValue<int32_t> read(void *buffer,
220  int32_t numFrames,
221  int64_t timeoutNanoseconds) {
222  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
223  }
224 
229  virtual AudioApi getAudioApi() const = 0;
230 
234  bool usesAAudio() const {
235  return getAudioApi() == AudioApi::AAudio;
236  }
237 
246  virtual void *getUnderlyingStream() const {
247  return nullptr;
248  }
249 
250 protected:
251 
252  virtual int64_t incrementFramesWritten(int32_t frames) {
253  return mFramesWritten += frames;
254  }
255  virtual int64_t incrementFramesRead(int32_t frames) {
256  return mFramesRead += frames;
257  }
258 
265  virtual Result waitForStateTransition(StreamState startingState,
266  StreamState endingState,
267  int64_t timeoutNanoseconds);
268 
276  virtual DataCallbackResult onDefaultCallback(void *audioData, int numFrames) {
277  return DataCallbackResult::Stop;
278  }
279 
280  DataCallbackResult fireCallback(void *audioData, int numFrames);
281 
282  virtual void setNativeFormat(AudioFormat format) {
283  mNativeFormat = format;
284  }
285 
286  // TODO: make private
287  // These do not change after open.
288  AudioFormat mNativeFormat = AudioFormat::Invalid;
289 
290  // TODO these should be atomic like in AAudio
291  int64_t mFramesWritten = 0;
292  int64_t mFramesRead = 0;
293 
294 private:
295  // TODO these should be atomic like in AAudio
296  int mPreviousScheduler = -1;
297 };
298 
299 } // namespace oboe
300 
301 #endif /* OBOE_STREAM_H_ */
virtual StreamState getState()=0
+
1 /*
2  * Copyright 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_STREAM_H_
18 #define OBOE_STREAM_H_
19 
20 #include <cstdint>
21 #include <ctime>
22 #include "oboe/Definitions.h"
23 #include "oboe/ResultWithValue.h"
24 #include "oboe/AudioStreamBuilder.h"
25 #include "oboe/AudioStreamBase.h"
26 
29 namespace oboe {
30 
37 constexpr int64_t kDefaultTimeoutNanos = (2000 * kNanosPerMillisecond);
38 
42 class AudioStream : public AudioStreamBase {
43 public:
44 
45  AudioStream() {}
46 
52  explicit AudioStream(const AudioStreamBuilder &builder);
53 
54  virtual ~AudioStream() = default;
55 
64  virtual Result open();
65 
69  virtual Result close() = 0;
70 
75  virtual Result start(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
76 
81  virtual Result pause(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
82 
87  virtual Result flush(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
88 
93  virtual Result stop(int64_t timeoutNanoseconds = kDefaultTimeoutNanos);
94 
95  /* Asynchronous requests.
96  * Use waitForStateChange() if you need to wait for completion.
97  */
98 
103  virtual Result requestStart() = 0;
104 
109  virtual Result requestPause() = 0;
110 
115  virtual Result requestFlush() = 0;
116 
121  virtual Result requestStop() = 0;
122 
128  virtual StreamState getState() = 0;
129 
154  virtual Result waitForStateChange(StreamState inputState,
155  StreamState *nextState,
156  int64_t timeoutNanoseconds) = 0;
157 
170  virtual ResultWithValue<int32_t> setBufferSizeInFrames(int32_t requestedFrames) {
171  return Result::ErrorUnimplemented;
172  }
173 
187  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
188  }
189 
193  virtual bool isXRunCountSupported() const = 0;
194 
200  virtual int32_t getFramesPerBurst() = 0;
201 
207  bool isPlaying();
208 
216  int32_t getBytesPerFrame() const { return mChannelCount * getBytesPerSample(); }
217 
224  int32_t getBytesPerSample() const;
225 
232  virtual int64_t getFramesWritten() { return mFramesWritten; }
233 
240  virtual int64_t getFramesRead() { return mFramesRead; }
241 
266  return ResultWithValue<double>(Result::ErrorUnimplemented);
267  }
268 
278  virtual Result getTimestamp(clockid_t clockId,
279  int64_t *framePosition,
280  int64_t *timeNanoseconds) {
281  return Result::ErrorUnimplemented;
282  }
283 
284  // ============== I/O ===========================
297  virtual ResultWithValue<int32_t> write(const void *buffer,
298  int32_t numFrames,
299  int64_t timeoutNanoseconds) {
300  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
301  }
302 
315  virtual ResultWithValue<int32_t> read(void *buffer,
316  int32_t numFrames,
317  int64_t timeoutNanoseconds) {
318  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
319  }
320 
326  virtual AudioApi getAudioApi() const = 0;
327 
333  bool usesAAudio() const {
334  return getAudioApi() == AudioApi::AAudio;
335  }
336 
345  virtual void *getUnderlyingStream() const {
346  return nullptr;
347  }
348 
349 protected:
350 
357  virtual int64_t incrementFramesWritten(int32_t frames) {
358  return mFramesWritten += frames;
359  }
360 
367  virtual int64_t incrementFramesRead(int32_t frames) {
368  return mFramesRead += frames;
369  }
370 
377  virtual Result waitForStateTransition(StreamState startingState,
378  StreamState endingState,
379  int64_t timeoutNanoseconds);
380 
388  virtual DataCallbackResult onDefaultCallback(void *audioData, int numFrames) {
389  return DataCallbackResult::Stop;
390  }
391 
400  DataCallbackResult fireCallback(void *audioData, int numFrames);
401 
405  virtual void setNativeFormat(AudioFormat format) {
406  mNativeFormat = format;
407  }
408 
416 
422  int64_t mFramesWritten = 0;
423 
429  int64_t mFramesRead = 0;
430 
431 private:
432  int mPreviousScheduler = -1;
433 };
434 
435 } // namespace oboe
436 
437 #endif /* OBOE_STREAM_H_ */
virtual Result requestStart()=0
+
virtual Result requestStop()=0
+
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:52
+ +
virtual StreamState getState()=0
Definition: AudioStreamBuilder.h:28
virtual Result close()=0
+
int64_t mFramesWritten
Definition: AudioStream.h:422
+
virtual Result stop(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
+
int32_t getBytesPerFrame() const
Definition: AudioStream.h:216
+
int32_t getBytesPerSample() const
+
AudioFormat mNativeFormat
Definition: AudioStream.h:415
+
virtual Result getTimestamp(clockid_t clockId, int64_t *framePosition, int64_t *timeNanoseconds)
Definition: AudioStream.h:278
virtual Result waitForStateTransition(StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)
+
int32_t mChannelCount
Definition: AudioStreamBase.h:135
virtual int32_t getFramesPerBurst()=0
-
virtual void * getUnderlyingStream() const
Definition: AudioStream.h:246
+
constexpr int64_t kDefaultTimeoutNanos
Definition: AudioStream.h:37
+
virtual Result start(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
+
DataCallbackResult fireCallback(void *audioData, int numFrames)
+
virtual void * getUnderlyingStream() const
Definition: AudioStream.h:345
virtual bool isXRunCountSupported() const =0
-
virtual ResultWithValue< int32_t > write(const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
Definition: AudioStream.h:213
-
virtual ResultWithValue< int32_t > getXRunCount() const
Definition: AudioStream.h:138
+
virtual ResultWithValue< int32_t > write(const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
Definition: AudioStream.h:297
+
virtual ResultWithValue< int32_t > getXRunCount() const
Definition: AudioStream.h:186
virtual AudioApi getAudioApi() const =0
+
virtual int64_t incrementFramesRead(int32_t frames)
Definition: AudioStream.h:367
+
int64_t mFramesRead
Definition: AudioStream.h:429
+
virtual Result flush(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
+
virtual Result requestPause()=0
Definition: AudioStream.h:29
-
AudioApi
Definition: Definitions.h:141
-
virtual DataCallbackResult onDefaultCallback(void *audioData, int numFrames)
Definition: AudioStream.h:276
-
virtual ResultWithValue< int32_t > setBufferSizeInFrames(int32_t requestedFrames)
Definition: AudioStream.h:122
-
virtual ResultWithValue< double > calculateLatencyMillis()
Definition: AudioStream.h:191
-
bool usesAAudio() const
Definition: AudioStream.h:234
-
Definition: AudioStreamBase.h:34
-
Definition: ResultWithValue.h:27
+
virtual int64_t getFramesRead()
Definition: AudioStream.h:240
+
AudioApi
Definition: Definitions.h:216
+
virtual DataCallbackResult onDefaultCallback(void *audioData, int numFrames)
Definition: AudioStream.h:388
+
virtual ResultWithValue< int32_t > read(void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
Definition: AudioStream.h:315
+
virtual ResultWithValue< int32_t > setBufferSizeInFrames(int32_t requestedFrames)
Definition: AudioStream.h:170
+
virtual ResultWithValue< double > calculateLatencyMillis()
Definition: AudioStream.h:265
+
Result
Definition: Definitions.h:140
+
bool usesAAudio() const
Definition: AudioStream.h:333
+
Definition: AudioStreamBase.h:29
+
virtual Result pause(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
+
AudioFormat
Definition: Definitions.h:103
+
Definition: ResultWithValue.h:47
virtual Result waitForStateChange(StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0
+
DataCallbackResult
Definition: Definitions.h:128
+
virtual int64_t incrementFramesWritten(int32_t frames)
Definition: AudioStream.h:357
+
virtual Result open()
-
virtual int64_t getFramesWritten()
Definition: AudioStream.h:164
-
Definition: AudioStream.h:36
+
virtual void setNativeFormat(AudioFormat format)
Definition: AudioStream.h:405
+
StreamState
Definition: Definitions.h:67
+
virtual Result requestFlush()=0
+
virtual int64_t getFramesWritten()
Definition: AudioStream.h:232
+
Definition: AudioStream.h:42
-
1 /*
2  * Copyright 2015 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_STREAM_BASE_H_
18 #define OBOE_STREAM_BASE_H_
19 
20 #include <memory>
21 #include "oboe/AudioStreamCallback.h"
22 #include "oboe/Definitions.h"
23 
24 namespace oboe {
25 
35 public:
36 
37  AudioStreamBase() {}
38 
39  virtual ~AudioStreamBase() = default;
40 
41  // This class only contains primitives so we can use default constructor and copy methods.
42  AudioStreamBase(const AudioStreamBase&) = default;
43 
44  AudioStreamBase& operator=(const AudioStreamBase&) = default;
45 
49  int getChannelCount() const { return mChannelCount; }
50 
54  Direction getDirection() const { return mDirection; }
55 
59  int32_t getSampleRate() const { return mSampleRate; }
60 
64  int getFramesPerCallback() const { return mFramesPerCallback; }
65 
70  AudioFormat getFormat() const { return mFormat; }
71 
78  virtual int32_t getBufferSizeInFrames() { return mBufferSizeInFrames; };
79 
83  virtual int32_t getBufferCapacityInFrames() const { return mBufferCapacityInFrames; }
84 
85  SharingMode getSharingMode() const { return mSharingMode; }
86 
87  PerformanceMode getPerformanceMode() const { return mPerformanceMode; }
88 
89  int32_t getDeviceId() const { return mDeviceId; }
90 
91  AudioStreamCallback* getCallback() const {
92  return mStreamCallback;
93  }
94 
95  Usage getUsage() const { return mUsage; }
96 
97  ContentType getContentType() const { return mContentType; }
98 
99  InputPreset getInputPreset() const { return mInputPreset; }
100 
101  SessionId getSessionId() const { return mSessionId; }
102 
103 protected:
104  AudioStreamCallback *mStreamCallback = nullptr;
105  int32_t mFramesPerCallback = kUnspecified;
106  int32_t mChannelCount = kUnspecified;
107  int32_t mSampleRate = kUnspecified;
108  int32_t mDeviceId = kUnspecified;
109  int32_t mBufferCapacityInFrames = kUnspecified;
110  int32_t mBufferSizeInFrames = kUnspecified;
111  int32_t mFramesPerBurst = kUnspecified;
112 
113  SharingMode mSharingMode = SharingMode::Shared;
114  AudioFormat mFormat = AudioFormat::Unspecified;
115  Direction mDirection = Direction::Output;
116  PerformanceMode mPerformanceMode = PerformanceMode::None;
117  // Added in API 28
118  Usage mUsage = Usage::Media;
119  ContentType mContentType = ContentType::Music;
120  InputPreset mInputPreset = InputPreset::VoiceRecognition;
121  SessionId mSessionId = SessionId::None;
122 };
123 
124 } // namespace oboe
125 
126 #endif /* OBOE_STREAM_BASE_H_ */
virtual int32_t getBufferSizeInFrames()
Definition: AudioStreamBase.h:78
-
SessionId
Definition: Definitions.h:314
+
1 /*
2  * Copyright 2015 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_STREAM_BASE_H_
18 #define OBOE_STREAM_BASE_H_
19 
20 #include <memory>
21 #include "oboe/AudioStreamCallback.h"
22 #include "oboe/Definitions.h"
23 
24 namespace oboe {
25 
30 public:
31 
32  AudioStreamBase() {}
33 
34  virtual ~AudioStreamBase() = default;
35 
36  // This class only contains primitives so we can use default constructor and copy methods.
37 
41  AudioStreamBase(const AudioStreamBase&) = default;
42 
46  AudioStreamBase& operator=(const AudioStreamBase&) = default;
47 
51  int getChannelCount() const { return mChannelCount; }
52 
56  Direction getDirection() const { return mDirection; }
57 
61  int32_t getSampleRate() const { return mSampleRate; }
62 
66  int getFramesPerCallback() const { return mFramesPerCallback; }
67 
71  AudioFormat getFormat() const { return mFormat; }
72 
79  virtual int32_t getBufferSizeInFrames() { return mBufferSizeInFrames; };
80 
84  virtual int32_t getBufferCapacityInFrames() const { return mBufferCapacityInFrames; }
85 
90 
95 
99  int32_t getDeviceId() const { return mDeviceId; }
100 
105  return mStreamCallback;
106  }
107 
111  Usage getUsage() const { return mUsage; }
112 
117 
122 
126  SessionId getSessionId() const { return mSessionId; }
127 
128 protected:
129 
149 
153  AudioFormat mFormat = AudioFormat::Unspecified;
157  PerformanceMode mPerformanceMode = PerformanceMode::None;
158 
162  ContentType mContentType = ContentType::Music;
164  InputPreset mInputPreset = InputPreset::VoiceRecognition;
166  SessionId mSessionId = SessionId::None;
167 };
168 
169 } // namespace oboe
170 
171 #endif /* OBOE_STREAM_BASE_H_ */
InputPreset getInputPreset() const
Definition: AudioStreamBase.h:121
+
int32_t mSampleRate
Definition: AudioStreamBase.h:137
+
virtual int32_t getBufferSizeInFrames()
Definition: AudioStreamBase.h:79
+
SessionId mSessionId
Definition: AudioStreamBase.h:166
+
InputPreset mInputPreset
Definition: AudioStreamBase.h:164
+
int32_t mFramesPerBurst
Definition: AudioStreamBase.h:148
+
ContentType mContentType
Definition: AudioStreamBase.h:162
+
PerformanceMode getPerformanceMode() const
Definition: AudioStreamBase.h:94
+
PerformanceMode mPerformanceMode
Definition: AudioStreamBase.h:157
+ +
AudioStreamBase & operator=(const AudioStreamBase &)=default
+
int32_t mChannelCount
Definition: AudioStreamBase.h:135
+
SharingMode getSharingMode() const
Definition: AudioStreamBase.h:89
+
int32_t mBufferSizeInFrames
Definition: AudioStreamBase.h:143
+
int32_t mBufferCapacityInFrames
Definition: AudioStreamBase.h:141
+
ContentType getContentType() const
Definition: AudioStreamBase.h:116
+
SharingMode mSharingMode
Definition: AudioStreamBase.h:151
+
SessionId getSessionId() const
Definition: AudioStreamBase.h:126
+
SessionId
Definition: Definitions.h:394
-
Direction getDirection() const
Definition: AudioStreamBase.h:54
-
int getChannelCount() const
Definition: AudioStreamBase.h:49
-
AudioFormat getFormat() const
Definition: AudioStreamBase.h:70
+
int32_t mDeviceId
Definition: AudioStreamBase.h:139
+
Usage mUsage
Definition: AudioStreamBase.h:160
+
Direction getDirection() const
Definition: AudioStreamBase.h:56
+
int32_t mFramesPerCallback
Definition: AudioStreamBase.h:133
+
int32_t getDeviceId() const
Definition: AudioStreamBase.h:99
+
int getChannelCount() const
Definition: AudioStreamBase.h:51
+
AudioFormat getFormat() const
Definition: AudioStreamBase.h:71
Definition: AudioStream.h:29
-
virtual int32_t getBufferCapacityInFrames() const
Definition: AudioStreamBase.h:83
-
ContentType
Definition: Definitions.h:252
-
SharingMode
Definition: Definitions.h:113
-
Definition: AudioStreamBase.h:34
-
int32_t getSampleRate() const
Definition: AudioStreamBase.h:59
+
virtual int32_t getBufferCapacityInFrames() const
Definition: AudioStreamBase.h:84
+
AudioStreamCallback * getCallback() const
Definition: AudioStreamBase.h:104
+
Direction
Definition: Definitions.h:87
+
ContentType
Definition: Definitions.h:327
+
Direction mDirection
Definition: AudioStreamBase.h:155
+
SharingMode
Definition: Definitions.h:176
+
Definition: AudioStreamBase.h:29
+
AudioStreamCallback * mStreamCallback
Definition: AudioStreamBase.h:131
+
AudioFormat
Definition: Definitions.h:103
+
int32_t getSampleRate() const
Definition: AudioStreamBase.h:61
-
InputPreset
Definition: Definitions.h:285
-
int getFramesPerCallback() const
Definition: AudioStreamBase.h:64
-
Usage
Definition: Definitions.h:174
+
Usage getUsage() const
Definition: AudioStreamBase.h:111
+
AudioFormat mFormat
Definition: AudioStreamBase.h:153
+
InputPreset
Definition: Definitions.h:360
+
int getFramesPerCallback() const
Definition: AudioStreamBase.h:66
+
constexpr int32_t kUnspecified
Definition: Definitions.h:41
+
PerformanceMode
Definition: Definitions.h:195
+
Definition: AudioStreamCallback.h:33
+
Usage
Definition: Definitions.h:249
-
1 /*
2  * Copyright 2015 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_STREAM_BUILDER_H_
18 #define OBOE_STREAM_BUILDER_H_
19 
20 #include "oboe/Definitions.h"
21 #include "oboe/AudioStreamBase.h"
22 
23 namespace oboe {
24 
29 public:
30 
32 
39  AudioStreamBuilder *setChannelCount(int channelCount) {
40  mChannelCount = channelCount;
41  return this;
42  }
43 
49  AudioStreamBuilder *setDirection(Direction direction) {
50  mDirection = direction;
51  return this;
52  }
53 
65  AudioStreamBuilder *setSampleRate(int32_t sampleRate) {
66  mSampleRate = sampleRate;
67  return this;
68  }
69 
84  AudioStreamBuilder *setFramesPerCallback(int framesPerCallback) {
85  mFramesPerCallback = framesPerCallback;
86  return this;
87  }
88 
95  AudioStreamBuilder *setFormat(AudioFormat format) {
96  mFormat = format;
97  return this;
98  }
99 
109  AudioStreamBuilder *setBufferCapacityInFrames(int32_t bufferCapacityInFrames) {
110  mBufferCapacityInFrames = bufferCapacityInFrames;
111  return this;
112  }
113 
114  AudioApi getAudioApi() const { return mAudioApi; }
115 
126  mAudioApi = audioApi;
127  return this;
128  }
129 
137  static bool isAAudioSupported();
138 
146  static bool isAAudioRecommended();
147 
157  mSharingMode = sharingMode;
158  return this;
159  }
160 
169  AudioStreamBuilder *setPerformanceMode(PerformanceMode performanceMode) {
170  mPerformanceMode = performanceMode;
171  return this;
172  }
173 
174 
188  mUsage = usage;
189  return this;
190  }
191 
205  mContentType = contentType;
206  return this;
207  }
208 
225  mInputPreset = inputPreset;
226  return this;
227  }
228 
254  mSessionId = sessionId;
255  return this;
256  }
257 
270  AudioStreamBuilder *setDeviceId(int32_t deviceId) {
271  mDeviceId = deviceId;
272  return this;
273  }
274 
294  mStreamCallback = streamCallback;
295  return this;
296  }
297 
304  Result openStream(AudioStream **stream);
305 
306 protected:
307 
308 private:
309 
315  oboe::AudioStream *build();
316 
317  AudioApi mAudioApi = AudioApi::Unspecified;
318 };
319 
320 } // namespace oboe
321 
322 #endif /* OBOE_STREAM_BUILDER_H_ */
Definition: AudioStreamBuilder.h:28
+
1 /*
2  * Copyright 2015 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_STREAM_BUILDER_H_
18 #define OBOE_STREAM_BUILDER_H_
19 
20 #include "oboe/Definitions.h"
21 #include "oboe/AudioStreamBase.h"
22 
23 namespace oboe {
24 
29 public:
30 
32 
39  AudioStreamBuilder *setChannelCount(int channelCount) {
40  mChannelCount = channelCount;
41  return this;
42  }
43 
50  mDirection = direction;
51  return this;
52  }
53 
65  AudioStreamBuilder *setSampleRate(int32_t sampleRate) {
66  mSampleRate = sampleRate;
67  return this;
68  }
69 
84  AudioStreamBuilder *setFramesPerCallback(int framesPerCallback) {
85  mFramesPerCallback = framesPerCallback;
86  return this;
87  }
88 
96  mFormat = format;
97  return this;
98  }
99 
109  AudioStreamBuilder *setBufferCapacityInFrames(int32_t bufferCapacityInFrames) {
110  mBufferCapacityInFrames = bufferCapacityInFrames;
111  return this;
112  }
113 
121  AudioApi getAudioApi() const { return mAudioApi; }
122 
133  mAudioApi = audioApi;
134  return this;
135  }
136 
144  static bool isAAudioSupported();
145 
153  static bool isAAudioRecommended();
154 
164  mSharingMode = sharingMode;
165  return this;
166  }
167 
177  mPerformanceMode = performanceMode;
178  return this;
179  }
180 
181 
195  mUsage = usage;
196  return this;
197  }
198 
212  mContentType = contentType;
213  return this;
214  }
215 
232  mInputPreset = inputPreset;
233  return this;
234  }
235 
261  mSessionId = sessionId;
262  return this;
263  }
264 
277  AudioStreamBuilder *setDeviceId(int32_t deviceId) {
278  mDeviceId = deviceId;
279  return this;
280  }
281 
301  mStreamCallback = streamCallback;
302  return this;
303  }
304 
311  Result openStream(AudioStream **stream);
312 
313 protected:
314 
315 private:
316 
322  oboe::AudioStream *build();
323 
324  AudioApi mAudioApi = AudioApi::Unspecified;
325 };
326 
327 } // namespace oboe
328 
329 #endif /* OBOE_STREAM_BUILDER_H_ */
int32_t mSampleRate
Definition: AudioStreamBase.h:137
+
Definition: AudioStreamBuilder.h:28
+
SessionId mSessionId
Definition: AudioStreamBase.h:166
static bool isAAudioRecommended()
-
AudioStreamBuilder * setUsage(Usage usage)
Definition: AudioStreamBuilder.h:187
-
AudioStreamBuilder * setContentType(ContentType contentType)
Definition: AudioStreamBuilder.h:204
+
InputPreset mInputPreset
Definition: AudioStreamBase.h:164
+
ContentType mContentType
Definition: AudioStreamBase.h:162
+
PerformanceMode mPerformanceMode
Definition: AudioStreamBase.h:157
+
int32_t mChannelCount
Definition: AudioStreamBase.h:135
+
AudioStreamBuilder * setUsage(Usage usage)
Definition: AudioStreamBuilder.h:194
+
AudioStreamBuilder * setContentType(ContentType contentType)
Definition: AudioStreamBuilder.h:211
AudioStreamBuilder * setDirection(Direction direction)
Definition: AudioStreamBuilder.h:49
-
AudioStreamBuilder * setDeviceId(int32_t deviceId)
Definition: AudioStreamBuilder.h:270
-
AudioStreamBuilder * setInputPreset(InputPreset inputPreset)
Definition: AudioStreamBuilder.h:224
+
AudioStreamBuilder * setDeviceId(int32_t deviceId)
Definition: AudioStreamBuilder.h:277
+
AudioStreamBuilder * setInputPreset(InputPreset inputPreset)
Definition: AudioStreamBuilder.h:231
Result openStream(AudioStream **stream)
-
SessionId
Definition: Definitions.h:314
+
int32_t mBufferCapacityInFrames
Definition: AudioStreamBase.h:141
+
SharingMode mSharingMode
Definition: AudioStreamBase.h:151
+
SessionId
Definition: Definitions.h:394
+
int32_t mDeviceId
Definition: AudioStreamBase.h:139
AudioStreamBuilder * setBufferCapacityInFrames(int32_t bufferCapacityInFrames)
Definition: AudioStreamBuilder.h:109
-
AudioStreamBuilder * setAudioApi(AudioApi audioApi)
Definition: AudioStreamBuilder.h:125
+
AudioStreamBuilder * setAudioApi(AudioApi audioApi)
Definition: AudioStreamBuilder.h:132
+
Usage mUsage
Definition: AudioStreamBase.h:160
AudioStreamBuilder * setFramesPerCallback(int framesPerCallback)
Definition: AudioStreamBuilder.h:84
AudioStreamBuilder * setFormat(AudioFormat format)
Definition: AudioStreamBuilder.h:95
-
AudioStreamBuilder * setSessionId(SessionId sessionId)
Definition: AudioStreamBuilder.h:253
-
AudioStreamBuilder * setCallback(AudioStreamCallback *streamCallback)
Definition: AudioStreamBuilder.h:293
+
AudioStreamBuilder * setSessionId(SessionId sessionId)
Definition: AudioStreamBuilder.h:260
+
int32_t mFramesPerCallback
Definition: AudioStreamBase.h:133
+
AudioStreamBuilder * setCallback(AudioStreamCallback *streamCallback)
Definition: AudioStreamBuilder.h:300
Definition: AudioStream.h:29
AudioStreamBuilder * setSampleRate(int32_t sampleRate)
Definition: AudioStreamBuilder.h:65
-
AudioApi
Definition: Definitions.h:141
-
ContentType
Definition: Definitions.h:252
+
Direction
Definition: Definitions.h:87
+
AudioApi
Definition: Definitions.h:216
+
ContentType
Definition: Definitions.h:327
+
Direction mDirection
Definition: AudioStreamBase.h:155
static bool isAAudioSupported()
-
SharingMode
Definition: Definitions.h:113
-
Definition: AudioStreamBase.h:34
-
AudioStreamBuilder * setSharingMode(SharingMode sharingMode)
Definition: AudioStreamBuilder.h:156
+
AudioApi getAudioApi() const
Definition: AudioStreamBuilder.h:121
+
Result
Definition: Definitions.h:140
+
SharingMode
Definition: Definitions.h:176
+
Definition: AudioStreamBase.h:29
+
AudioStreamCallback * mStreamCallback
Definition: AudioStreamBase.h:131
+
AudioFormat
Definition: Definitions.h:103
+
AudioFormat mFormat
Definition: AudioStreamBase.h:153
+
AudioStreamBuilder * setSharingMode(SharingMode sharingMode)
Definition: AudioStreamBuilder.h:163
AudioStreamBuilder * setChannelCount(int channelCount)
Definition: AudioStreamBuilder.h:39
-
InputPreset
Definition: Definitions.h:285
-
AudioStreamBuilder * setPerformanceMode(PerformanceMode performanceMode)
Definition: AudioStreamBuilder.h:169
-
Definition: AudioStreamCallback.h:26
-
Definition: AudioStream.h:36
-
Usage
Definition: Definitions.h:174
+
InputPreset
Definition: Definitions.h:360
+
PerformanceMode
Definition: Definitions.h:195
+
AudioStreamBuilder * setPerformanceMode(PerformanceMode performanceMode)
Definition: AudioStreamBuilder.h:176
+
Definition: AudioStreamCallback.h:33
+
Definition: AudioStream.h:42
+
Usage
Definition: Definitions.h:249
-
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_STREAM_CALLBACK_H
18 #define OBOE_STREAM_CALLBACK_H
19 
20 #include "oboe/Definitions.h"
21 
22 namespace oboe {
23 
24 class AudioStream;
25 
27 public:
28  virtual ~AudioStreamCallback() = default;
29 
38  virtual DataCallbackResult onAudioReady(
39  AudioStream *oboeStream,
40  void *audioData,
41  int32_t numFrames) = 0;
42 
51  virtual void onErrorBeforeClose(AudioStream *oboeStream, Result error) {}
52 
63  virtual void onErrorAfterClose(AudioStream *oboeStream, Result error) {}
64 
65 };
66 
67 } // namespace oboe
68 
69 #endif //OBOE_STREAM_CALLBACK_H
virtual DataCallbackResult onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames)=0
-
virtual void onErrorBeforeClose(AudioStream *oboeStream, Result error)
Definition: AudioStreamCallback.h:51
+
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_STREAM_CALLBACK_H
18 #define OBOE_STREAM_CALLBACK_H
19 
20 #include "oboe/Definitions.h"
21 
22 namespace oboe {
23 
24 class AudioStream;
25 
34 public:
35  virtual ~AudioStreamCallback() = default;
36 
46  AudioStream *oboeStream,
47  void *audioData,
48  int32_t numFrames) = 0;
49 
58  virtual void onErrorBeforeClose(AudioStream *oboeStream, Result error) {}
59 
70  virtual void onErrorAfterClose(AudioStream *oboeStream, Result error) {}
71 
72 };
73 
74 } // namespace oboe
75 
76 #endif //OBOE_STREAM_CALLBACK_H
virtual DataCallbackResult onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames)=0
+
virtual void onErrorBeforeClose(AudioStream *oboeStream, Result error)
Definition: AudioStreamCallback.h:58
Definition: AudioStream.h:29
-
Definition: AudioStreamCallback.h:26
-
virtual void onErrorAfterClose(AudioStream *oboeStream, Result error)
Definition: AudioStreamCallback.h:63
-
Definition: AudioStream.h:36
+
Result
Definition: Definitions.h:140
+
DataCallbackResult
Definition: Definitions.h:128
+
Definition: AudioStreamCallback.h:33
+
virtual void onErrorAfterClose(AudioStream *oboeStream, Result error)
Definition: AudioStreamCallback.h:70
+
Definition: AudioStream.h:42
-
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 
38  constexpr int32_t kUnspecified = 0;
39 
40  // TODO: Investigate using std::chrono
41  constexpr int64_t kNanosPerMicrosecond = 1000;
42  constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000;
43  constexpr int64_t kMillisPerSecond = 1000;
44  constexpr int64_t kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond;
45 
46  enum class StreamState : aaudio_stream_state_t {
47  Uninitialized = AAUDIO_STREAM_STATE_UNINITIALIZED,
48  Unknown = AAUDIO_STREAM_STATE_UNKNOWN,
49  Open = AAUDIO_STREAM_STATE_OPEN,
50  Starting = AAUDIO_STREAM_STATE_STARTING,
51  Started = AAUDIO_STREAM_STATE_STARTED,
52  Pausing = AAUDIO_STREAM_STATE_PAUSING,
53  Paused = AAUDIO_STREAM_STATE_PAUSED,
54  Flushing = AAUDIO_STREAM_STATE_FLUSHING,
55  Flushed = AAUDIO_STREAM_STATE_FLUSHED,
56  Stopping = AAUDIO_STREAM_STATE_STOPPING,
57  Stopped = AAUDIO_STREAM_STATE_STOPPED,
58  Closing = AAUDIO_STREAM_STATE_CLOSING,
59  Closed = AAUDIO_STREAM_STATE_CLOSED,
60  Disconnected = AAUDIO_STREAM_STATE_DISCONNECTED,
61  };
62 
63  enum class Direction : aaudio_direction_t {
64  Output = AAUDIO_DIRECTION_OUTPUT,
65  Input = AAUDIO_DIRECTION_INPUT,
66  };
67 
68  enum class AudioFormat : aaudio_format_t {
69  Invalid = AAUDIO_FORMAT_INVALID,
70  Unspecified = AAUDIO_FORMAT_UNSPECIFIED,
71  I16 = AAUDIO_FORMAT_PCM_I16,
72  Float = AAUDIO_FORMAT_PCM_FLOAT,
73  };
74 
75  enum class DataCallbackResult : aaudio_data_callback_result_t {
76  Continue = AAUDIO_CALLBACK_RESULT_CONTINUE,
77  Stop = AAUDIO_CALLBACK_RESULT_STOP,
78  };
79 
80  enum class Result : aaudio_result_t {
81  OK,
82  ErrorBase = AAUDIO_ERROR_BASE,
83  ErrorDisconnected = AAUDIO_ERROR_DISCONNECTED,
84  ErrorIllegalArgument = AAUDIO_ERROR_ILLEGAL_ARGUMENT,
85  ErrorInternal = AAUDIO_ERROR_INTERNAL,
86  ErrorInvalidState = AAUDIO_ERROR_INVALID_STATE,
87  ErrorInvalidHandle = AAUDIO_ERROR_INVALID_HANDLE,
88  ErrorUnimplemented = AAUDIO_ERROR_UNIMPLEMENTED,
89  ErrorUnavailable = AAUDIO_ERROR_UNAVAILABLE,
90  ErrorNoFreeHandles = AAUDIO_ERROR_NO_FREE_HANDLES,
91  ErrorNoMemory = AAUDIO_ERROR_NO_MEMORY,
92  ErrorNull = AAUDIO_ERROR_NULL,
93  ErrorTimeout = AAUDIO_ERROR_TIMEOUT,
94  ErrorWouldBlock = AAUDIO_ERROR_WOULD_BLOCK,
95  ErrorInvalidFormat = AAUDIO_ERROR_INVALID_FORMAT,
96  ErrorOutOfRange = AAUDIO_ERROR_OUT_OF_RANGE,
97  ErrorNoService = AAUDIO_ERROR_NO_SERVICE,
98  ErrorInvalidRate = AAUDIO_ERROR_INVALID_RATE,
99  // Reserved for future AAudio result types
100  Reserved1,
101  Reserved2,
102  Reserved3,
103  Reserved4,
104  Reserved5,
105  Reserved6,
106  Reserved7,
107  Reserved8,
108  Reserved9,
109  Reserved10,
110  ErrorClosed,
111  };
112 
113  enum class SharingMode : aaudio_sharing_mode_t {
114 
120  Exclusive = AAUDIO_SHARING_MODE_EXCLUSIVE,
121 
126  Shared = AAUDIO_SHARING_MODE_SHARED,
127  };
128 
129  enum class PerformanceMode : aaudio_performance_mode_t {
130 
131  // No particular performance needs. Default.
132  None = AAUDIO_PERFORMANCE_MODE_NONE,
133 
134  // Extending battery life is most important.
135  PowerSaving = AAUDIO_PERFORMANCE_MODE_POWER_SAVING,
136 
137  // Reducing latency is most important.
138  LowLatency = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY
139  };
140 
141  enum class AudioApi : int32_t {
145  Unspecified = kUnspecified,
146 
150  OpenSLES,
151 
155  AAudio
156  };
157 
158 // Hard code constants so they can be compiled with versions of the NDK before P.
159 #if __ANDROID_API_LEVEL__ >= __ANDROID_API_P__
160 #define CONSTANT_API_P(hard_constant, soft_constant) (soft_constant)
161 #else
162 #define CONSTANT_API_P(hard_constant, soft_constant) (hard_constant)
163 #endif
164 
174  enum class Usage : aaudio_usage_t {
178  Media = CONSTANT_API_P(1, AAUDIO_USAGE_MEDIA),
179 
183  VoiceCommunication = CONSTANT_API_P(2, AAUDIO_USAGE_VOICE_COMMUNICATION),
184 
188  VoiceCommunicationSignalling = CONSTANT_API_P(3,
189  AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING),
190 
194  Alarm = CONSTANT_API_P(4, AAUDIO_USAGE_ALARM),
195 
200  Notification = CONSTANT_API_P(5, AAUDIO_USAGE_NOTIFICATION),
201 
205  NotificationRingtone = CONSTANT_API_P(6, AAUDIO_USAGE_NOTIFICATION_RINGTONE),
206 
210  NotificationEvent = CONSTANT_API_P(10, AAUDIO_USAGE_NOTIFICATION_EVENT),
211 
215  AssistanceAccessibility = CONSTANT_API_P(11, AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY),
216 
220  AssistanceNavigationGuidance = CONSTANT_API_P(12,
221  AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE),
222 
226  AssistanceSonification = CONSTANT_API_P(13, AAUDIO_USAGE_ASSISTANCE_SONIFICATION),
227 
231  Game = CONSTANT_API_P(14, AAUDIO_USAGE_GAME),
232 
236  Assistant = CONSTANT_API_P(16, AAUDIO_USAGE_ASSISTANT),
237  };
238 
239 
252  enum ContentType : aaudio_content_type_t {
253 
257  Speech = CONSTANT_API_P(1, AAUDIO_CONTENT_TYPE_SPEECH),
258 
262  Music = CONSTANT_API_P(2, AAUDIO_CONTENT_TYPE_MUSIC),
263 
267  Movie = CONSTANT_API_P(3, AAUDIO_CONTENT_TYPE_MOVIE),
268 
273  Sonification = CONSTANT_API_P(4, AAUDIO_CONTENT_TYPE_SONIFICATION),
274  };
275 
285  enum InputPreset : aaudio_input_preset_t {
289  Generic = CONSTANT_API_P(1, AAUDIO_INPUT_PRESET_GENERIC),
290 
294  Camcorder = CONSTANT_API_P(5, AAUDIO_INPUT_PRESET_CAMCORDER),
295 
299  VoiceRecognition = CONSTANT_API_P(6, AAUDIO_INPUT_PRESET_VOICE_RECOGNITION),
300 
304  VoiceCommunication = CONSTANT_API_P(7, AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION),
305 
311  Unprocessed = CONSTANT_API_P(9, AAUDIO_INPUT_PRESET_UNPROCESSED),
312  };
313 
314  enum SessionId {
322  None = CONSTANT_API_P(-1, AAUDIO_SESSION_ID_NONE),
323 
333  Allocate = CONSTANT_API_P(0, AAUDIO_SESSION_ID_ALLOCATE),
334  };
335 
336  enum ChannelCount : int32_t {
340  Unspecified = kUnspecified,
341 
345  Mono = 1,
346 
350  Stereo = 2,
351  };
352 
353 #undef CONSTANT_API_P
354 
356 
357  public:
358 
377  static int32_t SampleRate;
378  static int32_t FramesPerBurst;
379  static int32_t ChannelCount;
380  };
381 
382 
383 
384 } // namespace oboe
385 
386 #endif // OBOE_DEFINITIONS_H
Definition: Definitions.h:333
-
Definition: Definitions.h:299
-
Definition: Definitions.h:257
-
ChannelCount
Definition: Definitions.h:336
+
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
Definition: Definitions.h:409
+
Definition: Definitions.h:374
+
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:52
+
Definition: Definitions.h:332
+
ChannelCount
Definition: Definitions.h:422
+ +
static int32_t FramesPerBurst
Definition: Definitions.h:466
+
static int32_t ChannelCount
Definition: Definitions.h:468
-
Definition: Definitions.h:304
-
SessionId
Definition: Definitions.h:314
-
static int32_t SampleRate
Definition: Definitions.h:377
+ +
Definition: Definitions.h:379
+
constexpr int64_t kNanosPerMicrosecond
Definition: Definitions.h:47
+ +
SessionId
Definition: Definitions.h:394
+
static int32_t SampleRate
Definition: Definitions.h:464
-
Definition: Definitions.h:322
-
Definition: Definitions.h:340
-
Definition: Definitions.h:311
-
Definition: Definitions.h:267
+
Definition: Definitions.h:400
+
Definition: Definitions.h:426
+
Definition: Definitions.h:386
+
Definition: Definitions.h:342
-
Definition: Definitions.h:350
-
Definition: Definitions.h:262
+ +
Definition: Definitions.h:436
+
Definition: Definitions.h:337
+
constexpr int64_t kNanosPerSecond
Definition: Definitions.h:62
-
Definition: Definitions.h:289
+
Definition: Definitions.h:364
Definition: AudioStream.h:29
+
Direction
Definition: Definitions.h:87
-
AudioApi
Definition: Definitions.h:141
-
ContentType
Definition: Definitions.h:252
-
Definition: Definitions.h:355
-
SharingMode
Definition: Definitions.h:113
-
Definition: Definitions.h:294
-
Definition: Definitions.h:345
+
AudioApi
Definition: Definitions.h:216
+
ContentType
Definition: Definitions.h:327
+ +
Definition: Definitions.h:459
+
Result
Definition: Definitions.h:140
+
SharingMode
Definition: Definitions.h:176
+
Definition: Definitions.h:369
+
AudioFormat
Definition: Definitions.h:103
+
constexpr int64_t kMillisPerSecond
Definition: Definitions.h:57
+
Definition: Definitions.h:431
+
DataCallbackResult
Definition: Definitions.h:128
-
InputPreset
Definition: Definitions.h:285
+
InputPreset
Definition: Definitions.h:360
+ +
constexpr int32_t kUnspecified
Definition: Definitions.h:41
+
PerformanceMode
Definition: Definitions.h:195
+ -
Definition: Definitions.h:273
+
Definition: Definitions.h:348
+
StreamState
Definition: Definitions.h:67
-
Usage
Definition: Definitions.h:174
+
Usage
Definition: Definitions.h:249
-
1 /*
2  * Copyright 2017 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_LATENCY_TUNER_
18 #define OBOE_LATENCY_TUNER_
19 
20 #include <atomic>
21 #include <cstdint>
22 #include "oboe/Definitions.h"
23 #include "oboe/AudioStream.h"
24 
25 namespace oboe {
26 
42 class LatencyTuner {
43 public:
44  explicit LatencyTuner(AudioStream &stream);
45 
54  Result tune();
55 
64  void requestReset();
65 
66 private:
67 
74  void reset();
75 
76  enum class State {
77  Idle,
78  Active,
79  AtMax,
80  Unsupported
81  } ;
82 
83  // arbitrary number of calls to wait before bumping up the latency
84  static constexpr int32_t kIdleCount = 8;
85 
86  AudioStream &mStream;
87  State mState = State::Idle;
88  int32_t mPreviousXRuns = 0;
89  int32_t mIdleCountDown = 0;
90  std::atomic<int32_t> mLatencyTriggerRequests{0}; // TODO user atomic requester from AAudio
91  std::atomic<int32_t> mLatencyTriggerResponses{0};
92 };
93 
94 } // namespace oboe
95 
96 #endif // OBOE_LATENCY_TUNER_
Definition: LatencyTuner.h:42
+
1 /*
2  * Copyright 2017 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_LATENCY_TUNER_
18 #define OBOE_LATENCY_TUNER_
19 
20 #include <atomic>
21 #include <cstdint>
22 #include "oboe/Definitions.h"
23 #include "oboe/AudioStream.h"
24 
25 namespace oboe {
26 
41 class LatencyTuner {
42 public:
43 
49  explicit LatencyTuner(AudioStream &stream);
50 
59  Result tune();
60 
69  void requestReset();
70 
71 private:
72 
79  void reset();
80 
81  enum class State {
82  Idle,
83  Active,
84  AtMax,
85  Unsupported
86  } ;
87 
88  // arbitrary number of calls to wait before bumping up the latency
89  static constexpr int32_t kIdleCount = 8;
90 
91  AudioStream &mStream;
92  State mState = State::Idle;
93  int32_t mPreviousXRuns = 0;
94  int32_t mIdleCountDown = 0;
95  std::atomic<int32_t> mLatencyTriggerRequests{0}; // TODO user atomic requester from AAudio
96  std::atomic<int32_t> mLatencyTriggerResponses{0};
97 };
98 
99 } // namespace oboe
100 
101 #endif // OBOE_LATENCY_TUNER_
Definition: LatencyTuner.h:41
+
LatencyTuner(AudioStream &stream)
Definition: AudioStream.h:29
+
Result
Definition: Definitions.h:140
-
Definition: AudioStream.h:36
+
Definition: AudioStream.h:42
-
1 /*
2  * Copyright (C) 2018 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_RESULT_WITH_VALUE_H
18 #define OBOE_RESULT_WITH_VALUE_H
19 
20 #include "oboe/Definitions.h"
21 #include <iostream>
22 #include <sstream>
23 
24 namespace oboe {
25 
26 template <typename T>
28 public:
29  ResultWithValue(oboe::Result error)
30  : mValue{}
31  , mError(error) {}
32 
33  explicit ResultWithValue(T value)
34  : mValue(value)
35  , mError(oboe::Result::OK) {}
36 
37  oboe::Result error() const {
38  return mError;
39  }
40 
41  T value() const {
42  return mValue;
43  }
44 
48  explicit operator bool() const { return mError == oboe::Result::OK; }
49 
60  bool operator !() const { return mError != oboe::Result::OK; }
61 
70  operator Result() const {
71  return mError;
72  }
73 
81  static ResultWithValue<T> createBasedOnSign(T numericResult){
82 
83  // Ensure that the type is either an integer or float
84  static_assert(std::is_arithmetic<T>::value,
85  "createBasedOnSign can only be called for numeric types (int or float)");
86 
87  if (numericResult >= 0){
88  return ResultWithValue<T>(numericResult);
89  } else {
90  return ResultWithValue<T>(static_cast<Result>(numericResult));
91  }
92  }
93 
94 private:
95  const T mValue;
96  const oboe::Result mError;
97 };
98 
99 template <typename T>
100 std::ostream& operator<<(std::ostream &strm, const ResultWithValue<T> &result) {
101  if (!result) {
102  strm << convertToText(result.error());
103  } else {
104  strm << result.value();
105  }
106  return strm;
107 }
108 
109 } // namespace oboe
110 
111 
112 #endif //OBOE_RESULT_WITH_VALUE_H
const char * convertToText(FromType)
-
static ResultWithValue< T > createBasedOnSign(T numericResult)
Definition: ResultWithValue.h:81
-
bool operator!() const
Definition: ResultWithValue.h:60
+
1 /*
2  * Copyright (C) 2018 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_RESULT_WITH_VALUE_H
18 #define OBOE_RESULT_WITH_VALUE_H
19 
20 #include "oboe/Definitions.h"
21 #include <iostream>
22 #include <sstream>
23 
24 namespace oboe {
25 
46 template <typename T>
48 public:
49 
56  : mValue{}
57  , mError(error) {}
58 
64  explicit ResultWithValue(T value)
65  : mValue(value)
66  , mError(oboe::Result::OK) {}
67 
73  oboe::Result error() const {
74  return mError;
75  }
76 
81  T value() const {
82  return mValue;
83  }
84 
88  explicit operator bool() const { return mError == oboe::Result::OK; }
89 
100  bool operator !() const { return mError != oboe::Result::OK; }
101 
110  operator Result() const {
111  return mError;
112  }
113 
121  static ResultWithValue<T> createBasedOnSign(T numericResult){
122 
123  // Ensure that the type is either an integer or float
124  static_assert(std::is_arithmetic<T>::value,
125  "createBasedOnSign can only be called for numeric types (int or float)");
126 
127  if (numericResult >= 0){
128  return ResultWithValue<T>(numericResult);
129  } else {
130  return ResultWithValue<T>(static_cast<Result>(numericResult));
131  }
132  }
133 
134 private:
135  const T mValue;
136  const oboe::Result mError;
137 };
138 
142 template <typename T>
143 std::ostream& operator<<(std::ostream &strm, const ResultWithValue<T> &result) {
144  if (!result) {
145  strm << convertToText(result.error());
146  } else {
147  strm << result.value();
148  }
149  return strm;
150 }
151 
152 } // namespace oboe
153 
154 
155 #endif //OBOE_RESULT_WITH_VALUE_H
ResultWithValue(oboe::Result error)
Definition: ResultWithValue.h:55
+
const char * convertToText(FromType input)
+
ResultWithValue(T value)
Definition: ResultWithValue.h:64
+
oboe::Result error() const
Definition: ResultWithValue.h:73
+
T value() const
Definition: ResultWithValue.h:81
+
static ResultWithValue< T > createBasedOnSign(T numericResult)
Definition: ResultWithValue.h:121
+
bool operator!() const
Definition: ResultWithValue.h:100
Definition: AudioStream.h:29
-
Definition: ResultWithValue.h:27
+
Result
Definition: Definitions.h:140
+
Definition: ResultWithValue.h:47
-
1 /*
2  * Copyright 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_UTILITIES_H
18 #define OBOE_UTILITIES_H
19 
20 #include <unistd.h>
21 #include <sys/types.h>
22 #include "oboe/Definitions.h"
23 
24 namespace oboe {
25 
26 void convertFloatToPcm16(const float *source, int16_t *destination, int32_t numSamples);
27 void convertPcm16ToFloat(const int16_t *source, float *destination, int32_t numSamples);
28 
32 int32_t convertFormatToSizeInBytes(AudioFormat format);
33 
43 template <typename FromType>
44 const char * convertToText(FromType);
45 
54 int getSdkVersion();
55 
56 } // namespace oboe
57 
58 #endif //OBOE_UTILITIES_H
const char * convertToText(FromType)
+
1 /*
2  * Copyright 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_UTILITIES_H
18 #define OBOE_UTILITIES_H
19 
20 #include <unistd.h>
21 #include <sys/types.h>
22 #include "oboe/Definitions.h"
23 
24 namespace oboe {
25 
33 void convertFloatToPcm16(const float *source, int16_t *destination, int32_t numSamples);
34 
42 void convertPcm16ToFloat(const int16_t *source, float *destination, int32_t numSamples);
43 
48 
58 template <typename FromType>
59 const char * convertToText(FromType input);
60 
69 int getSdkVersion();
70 
71 } // namespace oboe
72 
73 #endif //OBOE_UTILITIES_H
const char * convertToText(FromType input)
int32_t convertFormatToSizeInBytes(AudioFormat format)
int getSdkVersion()
+
void convertFloatToPcm16(const float *source, int16_t *destination, int32_t numSamples)
Definition: AudioStream.h:29
+
void convertPcm16ToFloat(const int16_t *source, float *destination, int32_t numSamples)
+
AudioFormat
Definition: Definitions.h:103
-
1 /*
2  * Copyright 2017 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_VERSIONINFO_H
18 #define OBOE_VERSIONINFO_H
19 
31 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description.
32 #define OBOE_VERSION_MAJOR 0
33 
34 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description.
35 #define OBOE_VERSION_MINOR 12
36 
37 // Type: 16-bit unsigned int. Min value: 0 Max value: 65535. See below for description.
38 #define OBOE_VERSION_PATCH 0
39 
40 #define OBOE_STRINGIFY(x) #x
41 #define OBOE_TOSTRING(x) OBOE_STRINGIFY(x)
42 
43 // Type: String literal. See below for description.
44 #define OBOE_VERSION_TEXT \
45  OBOE_TOSTRING(OBOE_VERSION_MAJOR) "." \
46  OBOE_TOSTRING(OBOE_VERSION_MINOR) "." \
47  OBOE_TOSTRING(OBOE_VERSION_PATCH)
48 
49 // Type: 32-bit unsigned int. See below for description.
50 #define OBOE_VERSION_NUMBER ((OBOE_VERSION_MAJOR << 24) | (OBOE_VERSION_MINOR << 16) | OBOE_VERSION_PATCH)
51 
52 namespace oboe {
53 
54 struct Version {
58  static constexpr uint8_t Major = OBOE_VERSION_MAJOR;
59 
64  static constexpr uint8_t Minor = OBOE_VERSION_MINOR;
65 
70  static constexpr uint16_t Patch = OBOE_VERSION_PATCH;
71 
75  static constexpr const char * Text = OBOE_VERSION_TEXT;
76 
81  static constexpr uint32_t Number = OBOE_VERSION_NUMBER;
82 };
83 
84 } // namespace oboe
85 #endif //OBOE_VERSIONINFO_H
static constexpr uint8_t Minor
Definition: Version.h:64
-
Definition: Version.h:54
+
1 /*
2  * Copyright 2017 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_VERSIONINFO_H
18 #define OBOE_VERSIONINFO_H
19 
31 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description.
32 #define OBOE_VERSION_MAJOR 0
33 
34 // Type: 8-bit unsigned int. Min value: 0 Max value: 255. See below for description.
35 #define OBOE_VERSION_MINOR 12
36 
37 // Type: 16-bit unsigned int. Min value: 0 Max value: 65535. See below for description.
38 #define OBOE_VERSION_PATCH 0
39 
40 #define OBOE_STRINGIFY(x) #x
41 #define OBOE_TOSTRING(x) OBOE_STRINGIFY(x)
42 
43 // Type: String literal. See below for description.
44 #define OBOE_VERSION_TEXT \
45  OBOE_TOSTRING(OBOE_VERSION_MAJOR) "." \
46  OBOE_TOSTRING(OBOE_VERSION_MINOR) "." \
47  OBOE_TOSTRING(OBOE_VERSION_PATCH)
48 
49 // Type: 32-bit unsigned int. See below for description.
50 #define OBOE_VERSION_NUMBER ((OBOE_VERSION_MAJOR << 24) | (OBOE_VERSION_MINOR << 16) | OBOE_VERSION_PATCH)
51 
52 namespace oboe {
53 
57 struct Version {
61  static constexpr uint8_t Major = OBOE_VERSION_MAJOR;
62 
67  static constexpr uint8_t Minor = OBOE_VERSION_MINOR;
68 
73  static constexpr uint16_t Patch = OBOE_VERSION_PATCH;
74 
78  static constexpr const char * Text = OBOE_VERSION_TEXT;
79 
84  static constexpr uint32_t Number = OBOE_VERSION_NUMBER;
85 };
86 
87 } // namespace oboe
88 #endif //OBOE_VERSIONINFO_H
static constexpr uint8_t Minor
Definition: Version.h:67
+
Definition: Version.h:57
Definition: AudioStream.h:29
-
static constexpr uint16_t Patch
Definition: Version.h:70
-
static constexpr const char * Text
Definition: Version.h:75
-
static constexpr uint8_t Major
Definition: Version.h:58
-
static constexpr uint32_t Number
Definition: Version.h:81
+
static constexpr uint16_t Patch
Definition: Version.h:73
+
static constexpr const char * Text
Definition: Version.h:78
+
static constexpr uint8_t Major
Definition: Version.h:61
+
static constexpr uint32_t Number
Definition: Version.h:84
+

The format of audio samples.

+ + + + + +
Enumerator
Invalid 

Invalid format.

+
Unspecified 

Unspecified format. Format will be decided by Oboe.

+
I16 

Signed 16-bit integers.

+
Float 

Single precision floating points.

+
+
@@ -319,9 +344,13 @@

+

The channel count of the audio stream. The underlying type is int32_t. Use of this enum is convenient to avoid "magic" numbers when specifying the channel count.

+

For example, you can write builder.setChannelCount(ChannelCount::Stereo) rather than builder.setChannelCount(2)

+ - + @@ -512,8 +716,51 @@

-

◆ convertToText()

+ +

◆ convertPcm16ToFloat()

+ +
+
+

Enumerator
Unspecified 

Audio channel count definition, use Mono or Stereo

Unspecified 

Unspecified format. Format will be decided by Oboe.

+
Unspecified 

Try to use AAudio. If not available then use OpenSL ES.

Mono 

Use this for mono audio

@@ -343,9 +372,9 @@

-

The CONTENT_TYPE attribute describes "what" you are playing. It expresses the general category of the content. This information is optional. But in case it is known (for instance AAUDIO_CONTENT_TYPE_MOVIE for a movie streaming service or AAUDIO_CONTENT_TYPE_SPEECH for an audio book application) this information might be used by the audio framework to enforce audio focus.

+

The ContentType attribute describes what you are playing. It expresses the general category of the content. This information is optional. But in case it is known (for instance Movie for a movie streaming service or Speech for an audio book application) this information might be used by the audio framework to enforce audio focus.

Note that these match the equivalent values in AudioAttributes in the Android Java API.

-

Added in API level 28.

+

This attribute only has an effect on Android API 28+.

@@ -357,6 +386,58 @@

+

◆ DataCallbackResult

+ +
+
+

Enumerator
Speech 

Use this for spoken voice, audio books, etcetera.

+ + + + +
+ + + + +
enum oboe::DataCallbackResult : aaudio_data_callback_result_t
+
+strong
+
+

The result of an audio callback.

+ +
+ + +

◆ Direction

+ +
+
+ + + + + +
+ + + + +
enum oboe::Direction : aaudio_direction_t
+
+strong
+
+

The direction of the stream.

+ + + +
Enumerator
Output 

Used for playback.

+
Input 

Used for recording.

+
+
@@ -372,7 +453,7 @@

Defines the audio source. An audio source defines both a default physical source of audio signal, and a recording configuration.

Note that these match the equivalent values in MediaRecorder.AudioSource in the Android Java API.

-

Added in API level 28.

+

This attribute only has an effect on Android API 28+.

@@ -388,6 +469,60 @@

+

◆ PerformanceMode

+ +
+
+

Enumerator
Generic 

Use this preset when other presets do not apply.

+ + + + +
+ + + + +
enum oboe::PerformanceMode : aaudio_performance_mode_t
+
+strong
+
+

The performance mode of the audio stream.

+ + + + +
Enumerator
None 

No particular performance needs. Default.

+
PowerSaving 

Extending battery life is most important.

+
LowLatency 

Reducing latency is most important.

+
+ +
+ + +

◆ Result

+ +
+
+ + + + + +
+ + + + +
enum oboe::Result : aaudio_result_t
+
+strong
+
+

The result of an operation. All except the OK result indicates that an error occurred. The Result can be converted into a human readable string using convertToText.

+
@@ -401,13 +536,15 @@

+

This attribute can be used to allocate a session ID to the audio stream.

+

This attribute only has an effect on Android API 28+.

- +
Enumerator
None 

Do not allocate a session ID. Effects cannot be used with this stream. Default.

-

Added in API level 28.

+
Enumerator
None 

Do not allocate a session ID. Effects cannot be used with this stream. Default.

+
None 

No particular performance needs. Default.

Allocate 

Allocate a session ID that can be used to attach and control effects using the Java AudioEffects API. Note that the use of this flag may result in higher latency.

-

Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.

-

Added in API level 28.

+

Note that this matches the value of AudioManager.AUDIO_SESSION_ID_GENERATE.

@@ -432,6 +569,7 @@

+

The sharing mode of the audio stream.

@@ -439,6 +577,29 @@

+

◆ StreamState

+ +
+
+

Enumerator
Exclusive 

This will be the only stream using a particular source or sink. This mode will provide the lowest possible latency. You should close EXCLUSIVE streams immediately when you are not using them.

+ + + + +
+ + + + +
enum oboe::StreamState : aaudio_stream_state_t
+
+strong
+
+

The state of the audio stream.

+
@@ -460,9 +621,9 @@

-

The Usage attribute expresses "why" you are playing a sound, what is this sound used for. This information is used by certain platforms or routing policies to make more refined volume or routing decisions.

+

The Usage attribute expresses why you are playing a sound, what is this sound used for. This information is used by certain platforms or routing policies to make more refined volume or routing decisions.

Note that these match the equivalent values in AudioAttributes in the Android Java API.

-

Added in API level 28.

+

This attribute only has an effect on Android API 28+.

@@ -493,6 +654,49 @@

Function Documentation

+ +

◆ convertFloatToPcm16()

+ +
+
+
Enumerator
Media 

Use this for streaming media, music performance, video, podcasts, etcetera.

+ + + + + + + + + + + + + + + + + + + + + + + +
void oboe::convertFloatToPcm16 (const float * source,
int16_t * destination,
int32_t numSamples 
)
+
+

Convert an array of floats to an array of 16-bit integers.

+
Parameters
+ + + + +
sourcethe input array.
destinationthe output array.
numSamplesthe number of values to convert.
+
+
+ +
+

◆ convertFormatToSizeInBytes()

@@ -502,7 +706,7 @@

int32_t oboe::convertFormatToSizeInBytes

(AudioFormat AudioFormat  format)
+ + + + + + + + + + + + + + + + + + + + + + + +
void oboe::convertPcm16ToFloat (const int16_t * source,
float * destination,
int32_t numSamples 
)
+
+

Convert an array of 16-bit integers to an array of floats.

+
Parameters
+ + + + +
sourcethe input array.
destinationthe output array.
numSamplesthe number of values to convert.
+
+
+ +
+ + +

◆ convertToText()

+ +

◆ operator<<()

+ +
+
+
+template<typename T >
+ + + + + + + + + + + + + + + + + + +
std::ostream& oboe::operator<< (std::ostream & strm,
const ResultWithValue< T > & result 
)
+
+

If the result is OK then return the value, otherwise return a human-readable error message.

+ +
+
+

Variable Documentation

+ +

◆ kDefaultTimeoutNanos

+ +
+
+ + + + +
constexpr int64_t oboe::kDefaultTimeoutNanos = (2000 * kNanosPerMillisecond)
+
+

The default number of nanoseconds to wait for when performing state change operations on the stream, such as start and stop.

+
See also
oboe::AudioStream::start
+ +
+
+ +

◆ kMillisPerSecond

+ +
+
+ + + + +
constexpr int64_t oboe::kMillisPerSecond = 1000
+
+

The number of milliseconds in a second. 1,000.

+ +
+
+ +

◆ kNanosPerMicrosecond

+ +
+
+ + + + +
constexpr int64_t oboe::kNanosPerMicrosecond = 1000
+
+

The number of nanoseconds in a microsecond. 1,000.

+ +
+
+ +

◆ kNanosPerMillisecond

+ +
+
+ + + + +
constexpr int64_t oboe::kNanosPerMillisecond = kNanosPerMicrosecond * 1000
+
+

The number of nanoseconds in a millisecond. 1,000,000.

+ +
+
+ +

◆ kNanosPerSecond

+ +
+
+ + + + +
constexpr int64_t oboe::kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond
+
+

The number of nanoseconds in a second. 1,000,000,000.

+ +
+
+ +

◆ kUnspecified

+ +
+
+ + + + +
constexpr int32_t oboe::kUnspecified = 0
+
+

Represents any attribute, property or value which hasn't been specified.

+
diff --git a/docs/reference/a00033.html b/docs/reference/a00033.html index ed9e94e37..281e3ac4d 100644 --- a/docs/reference/a00033.html +++ b/docs/reference/a00033.html @@ -75,74 +75,74 @@

This is the complete list of members for oboe::AudioStream, including all inherited members.

- + - + - - + + - - - + + + - - + + - + - - + + - - + + - + - + - - - + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - + + + diff --git a/docs/reference/a00034.html b/docs/reference/a00034.html new file mode 100644 index 000000000..46afc3664 --- /dev/null +++ b/docs/reference/a00034.html @@ -0,0 +1,160 @@ + + + + + + + +Oboe: Member List + + + + + + + + + +
+
+
AudioStream() (defined in oboe::AudioStream)oboe::AudioStreaminline
AudioStream(const AudioStreamBuilder &builder) (defined in oboe::AudioStream)oboe::AudioStreamexplicit
AudioStream(const AudioStreamBuilder &builder)oboe::AudioStreamexplicit
AudioStreamBase() (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
AudioStreamBase(const AudioStreamBase &)=default (defined in oboe::AudioStreamBase)oboe::AudioStreamBase
AudioStreamBase(const AudioStreamBase &)=defaultoboe::AudioStreamBase
calculateLatencyMillis()oboe::AudioStreaminlinevirtual
close()=0oboe::AudioStreampure virtual
fireCallback(void *audioData, int numFrames) (defined in oboe::AudioStream)oboe::AudioStreamprotected
flush(int64_t timeoutNanoseconds=kDefaultTimeoutNanos) (defined in oboe::AudioStream)oboe::AudioStreamvirtual
fireCallback(void *audioData, int numFrames)oboe::AudioStreamprotected
flush(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
getAudioApi() const =0oboe::AudioStreampure virtual
getBufferCapacityInFrames() constoboe::AudioStreamBaseinlinevirtual
getBufferSizeInFrames()oboe::AudioStreamBaseinlinevirtual
getBytesPerFrame() const (defined in oboe::AudioStream)oboe::AudioStreaminline
getBytesPerSample() const (defined in oboe::AudioStream)oboe::AudioStream
getCallback() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getBytesPerFrame() constoboe::AudioStreaminline
getBytesPerSample() constoboe::AudioStream
getCallback() constoboe::AudioStreamBaseinline
getChannelCount() constoboe::AudioStreamBaseinline
getContentType() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getDeviceId() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getContentType() constoboe::AudioStreamBaseinline
getDeviceId() constoboe::AudioStreamBaseinline
getDirection() constoboe::AudioStreamBaseinline
getFormat() constoboe::AudioStreamBaseinline
getFramesPerBurst()=0oboe::AudioStreampure virtual
getFramesPerCallback() constoboe::AudioStreamBaseinline
getFramesRead() (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
getFramesRead()oboe::AudioStreaminlinevirtual
getFramesWritten()oboe::AudioStreaminlinevirtual
getInputPreset() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getPerformanceMode() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getInputPreset() constoboe::AudioStreamBaseinline
getPerformanceMode() constoboe::AudioStreamBaseinline
getSampleRate() constoboe::AudioStreamBaseinline
getSessionId() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getSharingMode() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getSessionId() constoboe::AudioStreamBaseinline
getSharingMode() constoboe::AudioStreamBaseinline
getState()=0oboe::AudioStreampure virtual
getTimestamp(clockid_t clockId, int64_t *framePosition, int64_t *timeNanoseconds) (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
getTimestamp(clockid_t clockId, int64_t *framePosition, int64_t *timeNanoseconds)oboe::AudioStreaminlinevirtual
getUnderlyingStream() constoboe::AudioStreaminlinevirtual
getUsage() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getUsage() constoboe::AudioStreamBaseinline
getXRunCount() constoboe::AudioStreaminlinevirtual
incrementFramesRead(int32_t frames) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
incrementFramesWritten(int32_t frames) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
isPlaying() (defined in oboe::AudioStream)oboe::AudioStream
incrementFramesRead(int32_t frames)oboe::AudioStreaminlineprotectedvirtual
incrementFramesWritten(int32_t frames)oboe::AudioStreaminlineprotectedvirtual
isPlaying()oboe::AudioStream
isXRunCountSupported() const =0oboe::AudioStreampure virtual
mBufferCapacityInFrames (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mBufferSizeInFrames (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mChannelCount (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mContentType (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mDeviceId (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mDirection (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFormat (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesPerBurst (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesPerCallback (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesRead (defined in oboe::AudioStream)oboe::AudioStreamprotected
mFramesWritten (defined in oboe::AudioStream)oboe::AudioStreamprotected
mInputPreset (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mNativeFormat (defined in oboe::AudioStream)oboe::AudioStreamprotected
mPerformanceMode (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSampleRate (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSessionId (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSharingMode (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mStreamCallback (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mUsage (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mBufferCapacityInFramesoboe::AudioStreamBaseprotected
mBufferSizeInFramesoboe::AudioStreamBaseprotected
mChannelCountoboe::AudioStreamBaseprotected
mContentTypeoboe::AudioStreamBaseprotected
mDeviceIdoboe::AudioStreamBaseprotected
mDirectionoboe::AudioStreamBaseprotected
mFormatoboe::AudioStreamBaseprotected
mFramesPerBurstoboe::AudioStreamBaseprotected
mFramesPerCallbackoboe::AudioStreamBaseprotected
mFramesReadoboe::AudioStreamprotected
mFramesWrittenoboe::AudioStreamprotected
mInputPresetoboe::AudioStreamBaseprotected
mNativeFormatoboe::AudioStreamprotected
mPerformanceModeoboe::AudioStreamBaseprotected
mSampleRateoboe::AudioStreamBaseprotected
mSessionIdoboe::AudioStreamBaseprotected
mSharingModeoboe::AudioStreamBaseprotected
mStreamCallbackoboe::AudioStreamBaseprotected
mUsageoboe::AudioStreamBaseprotected
onDefaultCallback(void *audioData, int numFrames)oboe::AudioStreaminlineprotectedvirtual
open()oboe::AudioStreamvirtual
operator=(const AudioStreamBase &)=default (defined in oboe::AudioStreamBase)oboe::AudioStreamBase
pause(int64_t timeoutNanoseconds=kDefaultTimeoutNanos) (defined in oboe::AudioStream)oboe::AudioStreamvirtual
read(void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
requestFlush()=0 (defined in oboe::AudioStream)oboe::AudioStreampure virtual
requestPause()=0 (defined in oboe::AudioStream)oboe::AudioStreampure virtual
requestStart()=0 (defined in oboe::AudioStream)oboe::AudioStreampure virtual
requestStop()=0 (defined in oboe::AudioStream)oboe::AudioStreampure virtual
operator=(const AudioStreamBase &)=defaultoboe::AudioStreamBase
pause(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
read(void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)oboe::AudioStreaminlinevirtual
requestFlush()=0oboe::AudioStreampure virtual
requestPause()=0oboe::AudioStreampure virtual
requestStart()=0oboe::AudioStreampure virtual
requestStop()=0oboe::AudioStreampure virtual
setBufferSizeInFrames(int32_t requestedFrames)oboe::AudioStreaminlinevirtual
setNativeFormat(AudioFormat format) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
start(int64_t timeoutNanoseconds=kDefaultTimeoutNanos) (defined in oboe::AudioStream)oboe::AudioStreamvirtual
stop(int64_t timeoutNanoseconds=kDefaultTimeoutNanos) (defined in oboe::AudioStream)oboe::AudioStreamvirtual
setNativeFormat(AudioFormat format)oboe::AudioStreaminlineprotectedvirtual
start(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
stop(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
usesAAudio() constoboe::AudioStreaminline
waitForStateChange(StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0oboe::AudioStreampure virtual
waitForStateTransition(StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)oboe::AudioStreamprotectedvirtual
+ + + + + +
+
Oboe +  1.0 +
+
Audio library for Android
+
+ + + + + + + + + +
+
+ + +
+ +
+ + + +
+
+
oboe::AudioStream Member List
+
+
+ +

This is the complete list of members for oboe::AudioStream, including all inherited members.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AudioStream() (defined in oboe::AudioStream)oboe::AudioStreaminline
AudioStream(const AudioStreamBuilder &builder)oboe::AudioStreamexplicit
AudioStreamBase() (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
AudioStreamBase(const AudioStreamBase &)=default (defined in oboe::AudioStreamBase)oboe::AudioStreamBase
calculateLatencyMillis()oboe::AudioStreaminlinevirtual
close()=0oboe::AudioStreampure virtual
fireCallback(void *audioData, int numFrames) (defined in oboe::AudioStream)oboe::AudioStreamprotected
flush(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
getAudioApi() const =0oboe::AudioStreampure virtual
getBufferCapacityInFrames() constoboe::AudioStreamBaseinlinevirtual
getBufferSizeInFrames()oboe::AudioStreamBaseinlinevirtual
getBytesPerFrame() const (defined in oboe::AudioStream)oboe::AudioStreaminline
getBytesPerSample() const (defined in oboe::AudioStream)oboe::AudioStream
getCallback() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getChannelCount() constoboe::AudioStreamBaseinline
getContentType() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getDeviceId() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getDirection() constoboe::AudioStreamBaseinline
getFormat() constoboe::AudioStreamBaseinline
getFramesPerBurst()=0oboe::AudioStreampure virtual
getFramesPerCallback() constoboe::AudioStreamBaseinline
getFramesRead() (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
getFramesWritten()oboe::AudioStreaminlinevirtual
getInputPreset() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getPerformanceMode() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getSampleRate() constoboe::AudioStreamBaseinline
getSessionId() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getSharingMode() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getState()=0oboe::AudioStreampure virtual
getTimestamp(clockid_t clockId, int64_t *framePosition, int64_t *timeNanoseconds) (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
getUnderlyingStream() constoboe::AudioStreaminlinevirtual
getUsage() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getXRunCount() constoboe::AudioStreaminlinevirtual
incrementFramesRead(int32_t frames) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
incrementFramesWritten(int32_t frames) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
isPlaying()oboe::AudioStream
isXRunCountSupported() const =0oboe::AudioStreampure virtual
mBufferCapacityInFrames (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mBufferSizeInFrames (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mChannelCount (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mContentType (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mDeviceId (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mDirection (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFormat (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesPerBurst (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesPerCallback (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesRead (defined in oboe::AudioStream)oboe::AudioStreamprotected
mFramesWritten (defined in oboe::AudioStream)oboe::AudioStreamprotected
mInputPreset (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mNativeFormat (defined in oboe::AudioStream)oboe::AudioStreamprotected
mPerformanceMode (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSampleRate (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSessionId (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSharingMode (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mStreamCallback (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mUsage (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
onDefaultCallback(void *audioData, int numFrames)oboe::AudioStreaminlineprotectedvirtual
open()oboe::AudioStreamvirtual
operator=(const AudioStreamBase &)=default (defined in oboe::AudioStreamBase)oboe::AudioStreamBase
pause(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
read(void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
requestFlush()=0oboe::AudioStreampure virtual
requestPause()=0oboe::AudioStreampure virtual
requestStart()=0oboe::AudioStreampure virtual
requestStop()=0oboe::AudioStreampure virtual
setBufferSizeInFrames(int32_t requestedFrames)oboe::AudioStreaminlinevirtual
setNativeFormat(AudioFormat format) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
start(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
stop(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
usesAAudio() constoboe::AudioStreaminline
waitForStateChange(StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0oboe::AudioStreampure virtual
waitForStateTransition(StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)oboe::AudioStreamprotectedvirtual
write(const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)oboe::AudioStreaminlinevirtual
~AudioStream()=default (defined in oboe::AudioStream)oboe::AudioStreamvirtual
~AudioStreamBase()=default (defined in oboe::AudioStreamBase)oboe::AudioStreamBasevirtual
+ + + + diff --git a/docs/reference/a00035.html b/docs/reference/a00035.html new file mode 100644 index 000000000..6bdd54705 --- /dev/null +++ b/docs/reference/a00035.html @@ -0,0 +1,160 @@ + + + + + + + +Oboe: Member List + + + + + + + + + +
+
+ + + + + + +
+
Oboe +  1.0 +
+
Audio library for Android
+
+
+ + + + + + + + +
+
+ + +
+ +
+ + +
+
+
+
oboe::AudioStream Member List
+
+
+ +

This is the complete list of members for oboe::AudioStream, including all inherited members.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AudioStream() (defined in oboe::AudioStream)oboe::AudioStreaminline
AudioStream(const AudioStreamBuilder &builder)oboe::AudioStreamexplicit
AudioStreamBase() (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
AudioStreamBase(const AudioStreamBase &)=default (defined in oboe::AudioStreamBase)oboe::AudioStreamBase
calculateLatencyMillis()oboe::AudioStreaminlinevirtual
close()=0oboe::AudioStreampure virtual
fireCallback(void *audioData, int numFrames) (defined in oboe::AudioStream)oboe::AudioStreamprotected
flush(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
getAudioApi() const =0oboe::AudioStreampure virtual
getBufferCapacityInFrames() constoboe::AudioStreamBaseinlinevirtual
getBufferSizeInFrames()oboe::AudioStreamBaseinlinevirtual
getBytesPerFrame() const (defined in oboe::AudioStream)oboe::AudioStreaminline
getBytesPerSample() const (defined in oboe::AudioStream)oboe::AudioStream
getCallback() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getChannelCount() constoboe::AudioStreamBaseinline
getContentType() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getDeviceId() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getDirection() constoboe::AudioStreamBaseinline
getFormat() constoboe::AudioStreamBaseinline
getFramesPerBurst()=0oboe::AudioStreampure virtual
getFramesPerCallback() constoboe::AudioStreamBaseinline
getFramesRead() (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
getFramesWritten()oboe::AudioStreaminlinevirtual
getInputPreset() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getPerformanceMode() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getSampleRate() constoboe::AudioStreamBaseinline
getSessionId() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getSharingMode() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getState()=0oboe::AudioStreampure virtual
getTimestamp(clockid_t clockId, int64_t *framePosition, int64_t *timeNanoseconds) (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
getUnderlyingStream() constoboe::AudioStreaminlinevirtual
getUsage() const (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseinline
getXRunCount() constoboe::AudioStreaminlinevirtual
incrementFramesRead(int32_t frames) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
incrementFramesWritten(int32_t frames) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
isPlaying()oboe::AudioStream
isXRunCountSupported() const =0oboe::AudioStreampure virtual
mBufferCapacityInFrames (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mBufferSizeInFrames (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mChannelCount (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mContentType (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mDeviceId (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mDirection (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFormat (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesPerBurst (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesPerCallback (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mFramesRead (defined in oboe::AudioStream)oboe::AudioStreamprotected
mFramesWritten (defined in oboe::AudioStream)oboe::AudioStreamprotected
mInputPreset (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mNativeFormat (defined in oboe::AudioStream)oboe::AudioStreamprotected
mPerformanceMode (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSampleRate (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSessionId (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mSharingMode (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mStreamCallback (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
mUsage (defined in oboe::AudioStreamBase)oboe::AudioStreamBaseprotected
onDefaultCallback(void *audioData, int numFrames)oboe::AudioStreaminlineprotectedvirtual
open()oboe::AudioStreamvirtual
operator=(const AudioStreamBase &)=default (defined in oboe::AudioStreamBase)oboe::AudioStreamBase
pause(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
read(void *buffer, int32_t numFrames, int64_t timeoutNanoseconds) (defined in oboe::AudioStream)oboe::AudioStreaminlinevirtual
requestFlush()=0oboe::AudioStreampure virtual
requestPause()=0oboe::AudioStreampure virtual
requestStart()=0oboe::AudioStreampure virtual
requestStop()=0oboe::AudioStreampure virtual
setBufferSizeInFrames(int32_t requestedFrames)oboe::AudioStreaminlinevirtual
setNativeFormat(AudioFormat format) (defined in oboe::AudioStream)oboe::AudioStreaminlineprotectedvirtual
start(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
stop(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)oboe::AudioStreamvirtual
usesAAudio() constoboe::AudioStreaminline
waitForStateChange(StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0oboe::AudioStreampure virtual
waitForStateTransition(StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)oboe::AudioStreamprotectedvirtual
write(const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)oboe::AudioStreaminlinevirtual
~AudioStream()=default (defined in oboe::AudioStream)oboe::AudioStreamvirtual
~AudioStreamBase()=default (defined in oboe::AudioStreamBase)oboe::AudioStreamBasevirtual
+ + + + diff --git a/docs/reference/a00036.html b/docs/reference/a00036.html index f11a47e41..f132bf6f5 100644 --- a/docs/reference/a00036.html +++ b/docs/reference/a00036.html @@ -90,40 +90,31 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -133,29 +124,23 @@ - + - + - + - + - + - + @@ -164,134 +149,135 @@ - + - + - + - + - + - + - + - + - + - + - + - +

Public Member Functions

AudioStream (const AudioStreamBuilder &builder)
 AudioStream (const AudioStreamBuilder &builder)
 
virtual Result open ()
virtual Result open ()
 
virtual Result close ()=0
virtual Result close ()=0
 
-virtual Result start (int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
virtual Result start (int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
 
-virtual Result pause (int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
virtual Result pause (int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
 
-virtual Result flush (int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
virtual Result flush (int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
 
-virtual Result stop (int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
virtual Result stop (int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
 
-virtual Result requestStart ()=0
virtual Result requestStart ()=0
 
-virtual Result requestPause ()=0
virtual Result requestPause ()=0
 
-virtual Result requestFlush ()=0
virtual Result requestFlush ()=0
 
-virtual Result requestStop ()=0
virtual Result requestStop ()=0
 
virtual StreamState getState ()=0
virtual StreamState getState ()=0
 
virtual Result waitForStateChange (StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0
virtual Result waitForStateChange (StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0
 
virtual ResultWithValue< int32_t > setBufferSizeInFrames (int32_t requestedFrames)
 
 
virtual int32_t getFramesPerBurst ()=0
 
-bool isPlaying ()
bool isPlaying ()
 
-int32_t getBytesPerFrame () const
int32_t getBytesPerFrame () const
 
-int32_t getBytesPerSample () const
int32_t getBytesPerSample () const
 
virtual int64_t getFramesWritten ()
 
-virtual int64_t getFramesRead ()
virtual int64_t getFramesRead ()
 
virtual ResultWithValue< double > calculateLatencyMillis ()
 
-virtual Result getTimestamp (clockid_t clockId, int64_t *framePosition, int64_t *timeNanoseconds)
virtual Result getTimestamp (clockid_t clockId, int64_t *framePosition, int64_t *timeNanoseconds)
 
virtual ResultWithValue< int32_t > write (const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
 
-virtual ResultWithValue< int32_t > read (void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
virtual ResultWithValue< int32_t > read (void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
 
virtual AudioApi getAudioApi () const =0
 
virtual void * getUnderlyingStream () const
 
- Public Member Functions inherited from oboe::AudioStreamBase
AudioStreamBase (const AudioStreamBase &)=default
 AudioStreamBase (const AudioStreamBase &)=default
 
-AudioStreamBaseoperator= (const AudioStreamBase &)=default
AudioStreamBaseoperator= (const AudioStreamBase &)=default
 
int getChannelCount () const
 
Direction getDirection () const
Direction getDirection () const
 
int32_t getSampleRate () const
 
int getFramesPerCallback () const
 
AudioFormat getFormat () const
AudioFormat getFormat () const
 
virtual int32_t getBufferSizeInFrames ()
 
virtual int32_t getBufferCapacityInFrames () const
 
-SharingMode getSharingMode () const
SharingMode getSharingMode () const
 
-PerformanceMode getPerformanceMode () const
PerformanceMode getPerformanceMode () const
 
-int32_t getDeviceId () const
int32_t getDeviceId () const
 
-AudioStreamCallbackgetCallback () const
AudioStreamCallbackgetCallback () const
 
-Usage getUsage () const
Usage getUsage () const
 
-ContentType getContentType () const
ContentType getContentType () const
 
-InputPreset getInputPreset () const
InputPreset getInputPreset () const
 
-SessionId getSessionId () const
SessionId getSessionId () const
 
- + - + - + - + - + - +

Protected Member Functions

-virtual int64_t incrementFramesWritten (int32_t frames)
virtual int64_t incrementFramesWritten (int32_t frames)
 
-virtual int64_t incrementFramesRead (int32_t frames)
virtual int64_t incrementFramesRead (int32_t frames)
 
virtual Result waitForStateTransition (StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)
virtual Result waitForStateTransition (StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)
 
virtual DataCallbackResult onDefaultCallback (void *audioData, int numFrames)
virtual DataCallbackResult onDefaultCallback (void *audioData, int numFrames)
 
-DataCallbackResult fireCallback (void *audioData, int numFrames)
DataCallbackResult fireCallback (void *audioData, int numFrames)
 
-virtual void setNativeFormat (AudioFormat format)
virtual void setNativeFormat (AudioFormat format)
 
- + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +

Protected Attributes

-AudioFormat mNativeFormat = AudioFormat::Invalid
AudioFormat mNativeFormat = AudioFormat::Invalid
 
-int64_t mFramesWritten = 0
int64_t mFramesWritten = 0
 
-int64_t mFramesRead = 0
int64_t mFramesRead = 0
 
- Protected Attributes inherited from oboe::AudioStreamBase
-AudioStreamCallbackmStreamCallback = nullptr
AudioStreamCallbackmStreamCallback = nullptr
 
-int32_t mFramesPerCallback = kUnspecified
int32_t mFramesPerCallback = kUnspecified
 
-int32_t mChannelCount = kUnspecified
int32_t mChannelCount = kUnspecified
 
-int32_t mSampleRate = kUnspecified
int32_t mSampleRate = kUnspecified
 
-int32_t mDeviceId = kUnspecified
int32_t mDeviceId = kUnspecified
 
-int32_t mBufferCapacityInFrames = kUnspecified
int32_t mBufferCapacityInFrames = kUnspecified
 
-int32_t mBufferSizeInFrames = kUnspecified
int32_t mBufferSizeInFrames = kUnspecified
 
-int32_t mFramesPerBurst = kUnspecified
int32_t mFramesPerBurst = kUnspecified
 
-SharingMode mSharingMode = SharingMode::Shared
SharingMode mSharingMode = SharingMode::Shared
 
-AudioFormat mFormat = AudioFormat::Unspecified
AudioFormat mFormat = AudioFormat::Unspecified
 
-Direction mDirection = Direction::Output
Direction mDirection = Direction::Output
 
-PerformanceMode mPerformanceMode = PerformanceMode::None
PerformanceMode mPerformanceMode = PerformanceMode::None
 
-Usage mUsage = Usage::Media
Usage mUsage = Usage::Media
 
-ContentType mContentType = ContentType::Music
ContentType mContentType = ContentType::Music
 
-InputPreset mInputPreset = InputPreset::VoiceRecognition
InputPreset mInputPreset = InputPreset::VoiceRecognition
 
-SessionId mSessionId = SessionId::None
SessionId mSessionId = SessionId::None
 

Detailed Description

Base class for Oboe C++ audio stream.

-

Member Function Documentation

+

Constructor & Destructor Documentation

+ +

◆ AudioStream()

+ +
+
+ + + + + +
+ + + + + + + + +
oboe::AudioStream::AudioStream (const AudioStreamBuilderbuilder)
+
+explicit
+
+

Construct an AudioStream using the given AudioStreamBuilder

+
Parameters
+ + +
buildercontaining all the stream's attributes
+
+
+ +
+
+

Member Function Documentation

◆ calculateLatencyMillis()

@@ -302,30 +288,528 @@

- + + + + + +
virtual ResultWithValue<double> oboe::AudioStream::calculateLatencyMillis virtual ResultWithValue<double> oboe::AudioStream::calculateLatencyMillis ()
+ + +inlinevirtual + + +
+

Calculate the latency of a stream based on getTimestamp().

+

Output latency is the time it takes for a given frame to travel from the app to some type of digital-to-analog converter. If the DAC is external, for example in a USB interface or a TV connected by HDMI, then there may be additional latency that the Android device is unaware of.

+

Input latency is the time it takes to a given frame to travel from an analog-to-digital converter (ADC) to the app.

+

Note that the latency of an OUTPUT stream will increase abruptly when you write data to it and then decrease slowly over time as the data is consumed.

+

The latency of an INPUT stream will decrease abruptly when you read data from it and then increase slowly over time as more data arrives.

+

The latency of an OUTPUT stream is generally higher than the INPUT latency because an app generally tries to keep the OUTPUT buffer full and the INPUT buffer empty.

+
Returns
a ResultWithValue which has a result of Result::OK and a value containing the latency in milliseconds, or a result of Result::Error*.
+ +
+ + +

◆ close()

+ +
+
+ + + + + +
+ + + + + + + +
virtual Result oboe::AudioStream::close ()
+
+pure virtual
+
+

Close the stream and deallocate any resources from the open() call.

+ +
+
+ +

◆ fireCallback()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
DataCallbackResult oboe::AudioStream::fireCallback (void * audioData,
int numFrames 
)
+
+protected
+
+

Override this to provide your own behaviour for the audio callback

+
Parameters
+ + + +
audioDatacontainer array which audio frames will be written into or read from
numFramesnumber of frames which were read/written
+
+
+
Returns
the result of the callback: stop or continue
+ +
+
+ +

◆ flush()

+ +
+
+ + + + + +
+ + + + + + + + +
virtual Result oboe::AudioStream::flush (int64_t timeoutNanoseconds = kDefaultTimeoutNanos)
+
+virtual
+
+

Flush the stream. This will block until the stream has been flushed, an error occurs or timeoutNanoseconds has been reached.

+ +
+
+ +

◆ getAudioApi()

+ +
+
+ + + + + +
+ + + + + + + +
virtual AudioApi oboe::AudioStream::getAudioApi () const
+
+pure virtual
+
+

Get the underlying audio API which the stream uses.

+
Returns
the API that this stream uses.
+ +
+
+ +

◆ getBytesPerFrame()

+ +
+
+ + + + + +
+ + + + + + + +
int32_t oboe::AudioStream::getBytesPerFrame () const
+
+inline
+
+

Get the number of bytes in each audio frame. This is calculated using the channel count and the sample format. For example, a 2 channel floating point stream will have 2 * 4 = 8 bytes per frame.

+
Returns
number of bytes in each audio frame.
+ +
+
+ +

◆ getBytesPerSample()

+ +
+
+ + + + + + + +
int32_t oboe::AudioStream::getBytesPerSample () const
+
+

Get the number of bytes per sample. This is calculated using the sample format. For example, stream using 16-bit integer samples will have 2 bytes per sample.

+
Returns
the number of bytes per sample.
+ +
+
+ +

◆ getFramesPerBurst()

+ +
+
+ + + + + +
+ + + + + + + +
virtual int32_t oboe::AudioStream::getFramesPerBurst ()
+
+pure virtual
+
+

Query the number of frames that are read or written by the endpoint at one time.

+
Returns
burst size
+ +
+
+ +

◆ getFramesRead()

+ +
+
+ + + + + +
+ + + + + + + +
virtual int64_t oboe::AudioStream::getFramesRead ()
+
+inlinevirtual
+
+

The number of audio frames read from the stream. This monotonic counter will never get reset.

+
Returns
the number of frames read so far
+ +
+
+ +

◆ getFramesWritten()

+ +
+
+ + + + + +
+ + + + + + + +
virtual int64_t oboe::AudioStream::getFramesWritten ()
+
+inlinevirtual
+
+

The number of audio frames written into the stream. This monotonic counter will never get reset.

+
Returns
the number of frames written so far
+ +
+
+ +

◆ getState()

+ +
+
+ + + + + +
+ + + + + + + +
virtual StreamState oboe::AudioStream::getState ()
+
+pure virtual
+
+

Query the current state, eg. StreamState::Pausing

+
Returns
state or a negative error.
+ +
+
+ +

◆ getTimestamp()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
virtual Result oboe::AudioStream::getTimestamp (clockid_t clockId,
int64_t * framePosition,
int64_t * timeNanoseconds 
)
+
+inlinevirtual
+
+

Get the timestamp that the frame at framePosition was presented to the audio hardware.

+
Parameters
+ + + + +
clockIdthe type of clock to use e.g. CLOCK_MONOTONIC
framePositionthe frame number to query
timeNanosecondsan output parameter which will contain the presentation timestamp (if the operation is successful)
+
+
+ +
+
+ +

◆ getUnderlyingStream()

+ +
+
+ + + + + +
+ + + + + + + +
virtual void* oboe::AudioStream::getUnderlyingStream () const
+
+inlinevirtual
+
+

Only for debugging. Do use in production. If you need to call this method something is wrong. If you think you need it for production then please let us know so we can modify Oboe so that you don't need this.

+
Returns
nullptr or a pointer to a stream from the system API
+ +
+
+ +

◆ getXRunCount()

+ +
+
+ + + + + +
+ + + + + + + +
virtual ResultWithValue<int32_t> oboe::AudioStream::getXRunCount () const
+
+inlinevirtual
+
+

An XRun is an Underrun or an Overrun. During playing, an underrun will occur if the stream is not written in time and the system runs out of valid data. During recording, an overrun will occur if the stream is not read in time and there is no place to put the incoming data so it is discarded.

+

An underrun or overrun can cause an audible "pop" or "glitch".

+
Returns
a result which is either Result::OK with the xRun count as the value, or a Result::Error* code
+ +
+
+ +

◆ incrementFramesRead()

+ +
+
+ + + + + +
+ + + + + + + + +
virtual int64_t oboe::AudioStream::incrementFramesRead (int32_t frames)
+
+inlineprotectedvirtual
+
+

Increment the frames which have been read from this stream

+
Parameters
+ + +
framesnumber of frames to increment by
+
+
+
Returns
total frames which have been read
+ +
+
+ +

◆ incrementFramesWritten()

+ +
+
+ + + + + +
+ + + + + + + + +
virtual int64_t oboe::AudioStream::incrementFramesWritten (int32_t frames)
+
+inlineprotectedvirtual
+
+

Increment the frames written to this stream

+
Parameters
+ + +
framesnumber of frames to increment by
+
+
+
Returns
total frames which have been written
+ +
+
+ +

◆ isPlaying()

+ +
+
+ + + + + + + +
bool oboe::AudioStream::isPlaying ()
+
+

Indicates whether the audio stream is playing.

+

THIS MAY BE REMOVED IN FUTURE. https://github.com/google/oboe/issues/208

+ +
+
+ +

◆ isXRunCountSupported()

+ +
+
+ + + +pure virtual
+ + + - +
virtual bool oboe::AudioStream::isXRunCountSupported ( ) const
-inlinevirtual
-

Calculate the latency of a stream based on getTimestamp().

-

Output latency is the time it takes for a given frame to travel from the app to some type of digital-to-analog converter. If the DAC is external, for example in a USB interface or a TV connected by HDMI, then there may be additional latency that the Android device is unaware of.

-

Input latency is the time it takes to a given frame to travel from an analog-to-digital converter (ADC) to the app.

-

Note that the latency of an OUTPUT stream will increase abruptly when you write data to it and then decrease slowly over time as the data is consumed.

-

The latency of an INPUT stream will decrease abruptly when you read data from it and then increase slowly over time as more data arrives.

-

The latency of an OUTPUT stream is generally higher than the INPUT latency because an app generally tries to keep the OUTPUT buffer full and the INPUT buffer empty.

-
Returns
a ResultWithValue which has a result of Result::OK and a value containing the latency in milliseconds, or a result of Result::Error*.
+
Returns
true if XRun counts are supported on the stream
- -

◆ close()

+ +

◆ onDefaultCallback()

- -

◆ getAudioApi()

+ +

◆ open()

- -

◆ getFramesPerBurst()

+ +

◆ pause()

- -

◆ getFramesWritten()

+ +

◆ read()

- -

◆ getState()

+ +

◆ requestFlush()

- -

◆ getXRunCount()

+ +

◆ requestStart()

- -

◆ isXRunCountSupported()

+ +

◆ requestStop()

- -

◆ onDefaultCallback()

+ +

◆ setBufferSizeInFrames()

-

Override this to provide a default for when the application did not specify a callback.

+

This can be used to adjust the latency of the buffer by changing the threshold where blocking will occur. By combining this with getXRunCount(), the latency can be tuned at run-time for each device.

+

This cannot be set higher than getBufferCapacity().

Parameters
- - +
audioData
numFrames
requestedFramesrequested number of frames that can be filled without blocking
-
Returns
result
+
Returns
the resulting buffer size in frames (obtained using value()) or an error (obtained using error())
- -

◆ open()

+ +

◆ setNativeFormat()

+ +

◆ start()

+ +
+
-

This can be used to adjust the latency of the buffer by changing the threshold where blocking will occur. By combining this with getXRunCount(), the latency can be tuned at run-time for each device.

-

This cannot be set higher than getBufferCapacity().

-
Parameters
- - -
requestedFramesrequested number of frames that can be filled without blocking
-
-
-
Returns
the resulting buffer size in frames (obtained using value()) or an error (obtained using error())
+

Stop the stream. This will block until the stream has been stopped, an error occurs or timeoutNanoseconds has been reached.

@@ -667,7 +1203,8 @@

-
Returns
true if this stream is implemented using the AAudio API
+

Returns true if the underlying audio API is AAudio.

+
Returns
true if this stream is implemented using the AAudio API.
@@ -681,15 +1218,15 @@

- + - + - + @@ -743,15 +1280,15 @@

virtual Result oboe::AudioStream::waitForStateChange virtual Result oboe::AudioStream::waitForStateChange (StreamState StreamState  inputState,
StreamState * StreamState nextState,
- + - + - + @@ -815,10 +1352,10 @@

-

A high level write that will wait until the write is complete or it runs out of time. If timeoutNanoseconds is zero then this call will not wait.

+

Write data from the supplied buffer into the stream. This method will block until the write is complete or it runs out of time.

+

If timeoutNanoseconds is zero then this call will not wait.

Parameters

virtual Result oboe::AudioStream::waitForStateTransition virtual Result oboe::AudioStream::waitForStateTransition (StreamState StreamState  startingState,
StreamState StreamState  endingState,
- @@ -827,6 +1364,79 @@

Returns
a ResultWithValue which has a result of Result::OK and a value containing the number of frames actually written, or result of Result::Error*.
+ + +

Member Data Documentation

+ +

◆ mFramesRead

+ +
+
+
streamA stream created using OboeStream_Open().
bufferThe address of the first sample.
numFramesNumber of frames to write. Only complete frames will be written.
timeoutNanosecondsMaximum number of nanoseconds to wait for completion.
+ + + + +
+ + + + +
int64_t oboe::AudioStream::mFramesRead = 0
+
+protected
+
+

Number of frames which have been read from the stream

+

TODO these should be atomic like in AAudio

+ +
+ + +

◆ mFramesWritten

+ +
+
+ + + + + +
+ + + + +
int64_t oboe::AudioStream::mFramesWritten = 0
+
+protected
+
+

Number of frames which have been written into the stream

+

TODO these should be atomic like in AAudio

+ +
+
+ +

◆ mNativeFormat

+ +
+
+ + + + + +
+ + + + +
AudioFormat oboe::AudioStream::mNativeFormat = AudioFormat::Invalid
+
+protected
+
+

Do not set directly, use setNativeFormat

+

TODO: make private These do not change after open.

+

The documentation for this class was generated from the following file:
@@ -72,12 +72,12 @@
-

This is the complete list of members for oboe::AudioStreamCallback, including all inherited members.

+

This is the complete list of members for oboe::AudioStreamCallback, including all inherited members.

- - - - + + + +
onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames)=0oboe::AudioStreamCallbackpure virtual
onErrorAfterClose(AudioStream *oboeStream, Result error)oboe::AudioStreamCallbackinlinevirtual
onErrorBeforeClose(AudioStream *oboeStream, Result error)oboe::AudioStreamCallbackinlinevirtual
~AudioStreamCallback()=default (defined in oboe::AudioStreamCallback)oboe::AudioStreamCallbackvirtual
onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames)=0oboe::AudioStreamCallbackpure virtual
onErrorAfterClose(AudioStream *oboeStream, Result error)oboe::AudioStreamCallbackinlinevirtual
onErrorBeforeClose(AudioStream *oboeStream, Result error)oboe::AudioStreamCallbackinlinevirtual
~AudioStreamCallback()=default (defined in oboe::AudioStreamCallback)oboe::AudioStreamCallbackvirtual