diff --git a/docs/reference/a00002_source.html b/docs/reference/a00002_source.html index e22584d08..ebf8d5d54 100644 --- a/docs/reference/a00002_source.html +++ b/docs/reference/a00002_source.html @@ -71,58 +71,57 @@
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 
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
-
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: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
-
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 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 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 
285  virtual Result getTimestamp(clockid_t clockId,
286  int64_t *framePosition,
287  int64_t *timeNanoseconds) {
288  return Result::ErrorUnimplemented;
289  }
290 
291  // ============== I/O ===========================
304  virtual ResultWithValue<int32_t> write(const void *buffer,
305  int32_t numFrames,
306  int64_t timeoutNanoseconds) {
307  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
308  }
309 
322  virtual ResultWithValue<int32_t> read(void *buffer,
323  int32_t numFrames,
324  int64_t timeoutNanoseconds) {
325  return ResultWithValue<int32_t>(Result::ErrorUnimplemented);
326  }
327 
333  virtual AudioApi getAudioApi() const = 0;
334 
340  bool usesAAudio() const {
341  return getAudioApi() == AudioApi::AAudio;
342  }
343 
352  virtual void *getUnderlyingStream() const {
353  return nullptr;
354  }
355 
356 protected:
357 
364  virtual int64_t incrementFramesWritten(int32_t frames) {
365  return mFramesWritten += frames;
366  }
367 
374  virtual int64_t incrementFramesRead(int32_t frames) {
375  return mFramesRead += frames;
376  }
377 
384  virtual Result waitForStateTransition(StreamState startingState,
385  StreamState endingState,
386  int64_t timeoutNanoseconds);
387 
395  virtual DataCallbackResult onDefaultCallback(void *audioData, int numFrames) {
396  return DataCallbackResult::Stop;
397  }
398 
407  DataCallbackResult fireCallback(void *audioData, int numFrames);
408 
412  virtual void setNativeFormat(AudioFormat format) {
413  mNativeFormat = format;
414  }
415 
416  AudioFormat mNativeFormat = AudioFormat::Invalid;
417 
423  int64_t mFramesWritten = 0;
424 
430  int64_t mFramesRead = 0;
431 
432 private:
433  int mPreviousScheduler = -1;
434 };
435 
436 } // namespace oboe
437 
438 #endif /* OBOE_STREAM_H_ */
virtual int64_t getFramesWritten()
Definition: AudioStream.h:232
+
virtual Result waitForStateChange(StreamState inputState, StreamState *nextState, int64_t timeoutNanoseconds)=0
+
virtual Result requestStop()=0
+
constexpr int64_t kDefaultTimeoutNanos
Definition: AudioStream.h:37
+
int64_t mFramesWritten
Definition: AudioStream.h:423
+
int32_t getBytesPerFrame() const
Definition: AudioStream.h:216
+
virtual Result close()=0
+
virtual AudioApi getAudioApi() const =0
+ +
virtual Result requestFlush()=0
+
int64_t mFramesRead
Definition: AudioStream.h:430
+
int32_t getBytesPerSample() const
+
virtual Result requestStart()=0
+
virtual Result waitForStateTransition(StreamState startingState, StreamState endingState, int64_t timeoutNanoseconds)
+
int32_t mChannelCount
Definition: AudioStreamBase.h:135
+
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:52
+ +
virtual Result requestPause()=0
+
virtual ResultWithValue< int32_t > getXRunCount() const
Definition: AudioStream.h:186
+
Definition: AudioStreamBase.h:29
+
virtual Result stop(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
+
virtual int64_t getFramesRead()
Definition: AudioStream.h:240
+
virtual void * getUnderlyingStream() const
Definition: AudioStream.h:352
+
virtual bool isXRunCountSupported() const =0
+
virtual ResultWithValue< int32_t > write(const void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
Definition: AudioStream.h:304
+
virtual ResultWithValue< int32_t > setBufferSizeInFrames(int32_t requestedFrames)
Definition: AudioStream.h:170
+
Definition: ResultWithValue.h:47
+
virtual ResultWithValue< double > calculateLatencyMillis()
Definition: AudioStream.h:265
+
virtual int64_t incrementFramesRead(int32_t frames)
Definition: AudioStream.h:374
+
StreamState
Definition: Definitions.h:67
+
virtual int32_t getFramesPerBurst()=0
+ +
virtual Result start(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
+
DataCallbackResult
Definition: Definitions.h:128
+
DataCallbackResult fireCallback(void *audioData, int numFrames)
+
virtual DataCallbackResult onDefaultCallback(void *audioData, int numFrames)
Definition: AudioStream.h:395
+
Definition: AudioStream.h:42
+
virtual int64_t incrementFramesWritten(int32_t frames)
Definition: AudioStream.h:364
+
AudioApi
Definition: Definitions.h:216
+
AudioFormat
Definition: Definitions.h:103
+
Result
Definition: Definitions.h:140
+
Definition: AudioStreamBuilder.h:28
+
Definition: AudioStream.h:29
+
virtual Result flush(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
+
virtual StreamState getState()=0
+
virtual ResultWithValue< int32_t > read(void *buffer, int32_t numFrames, int64_t timeoutNanoseconds)
Definition: AudioStream.h:322
+
virtual void setNativeFormat(AudioFormat format)
Definition: AudioStream.h:412
+
bool usesAAudio() const
Definition: AudioStream.h:340
+
virtual Result pause(int64_t timeoutNanoseconds=kDefaultTimeoutNanos)
+
virtual Result getTimestamp(clockid_t clockId, int64_t *framePosition, int64_t *timeNanoseconds)
Definition: AudioStream.h:285
+
virtual Result open()
-
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
- -
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: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
- -
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_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_ */
SessionId mSessionId
Definition: AudioStreamBase.h:166
+ +
int32_t mDeviceId
Definition: AudioStreamBase.h:139
+
SharingMode getSharingMode() const
Definition: AudioStreamBase.h:89
+
PerformanceMode mPerformanceMode
Definition: AudioStreamBase.h:157
+ +
InputPreset
Definition: Definitions.h:360
+
int32_t mChannelCount
Definition: AudioStreamBase.h:135
+ +
Direction
Definition: Definitions.h:87
+
int32_t mBufferSizeInFrames
Definition: AudioStreamBase.h:143
+
Usage mUsage
Definition: AudioStreamBase.h:160
+
Definition: AudioStreamBase.h:29
+
AudioFormat getFormat() const
Definition: AudioStreamBase.h:71
+
virtual int32_t getBufferCapacityInFrames() const
Definition: AudioStreamBase.h:84
+
int32_t mFramesPerBurst
Definition: AudioStreamBase.h:148
+
PerformanceMode getPerformanceMode() const
Definition: AudioStreamBase.h:94
+
AudioStreamBase & operator=(const AudioStreamBase &)=default
+
Direction mDirection
Definition: AudioStreamBase.h:155
+
int32_t mFramesPerCallback
Definition: AudioStreamBase.h:133
+
int32_t getDeviceId() const
Definition: AudioStreamBase.h:99
+
AudioStreamCallback * mStreamCallback
Definition: AudioStreamBase.h:131
+
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
+
int32_t getSampleRate() const
Definition: AudioStreamBase.h:61
+
ContentType
Definition: Definitions.h:327
+
Direction getDirection() const
Definition: AudioStreamBase.h:56
+
SessionId
Definition: Definitions.h:394
+
Definition: AudioStreamCallback.h:33
+
SharingMode
Definition: Definitions.h:176
+
Usage
Definition: Definitions.h:249
+
AudioFormat
Definition: Definitions.h:103
+
constexpr int32_t kUnspecified
Definition: Definitions.h:41
+
Definition: AudioStream.h:29
+
int getChannelCount() const
Definition: AudioStreamBase.h:51
+
Usage getUsage() const
Definition: AudioStreamBase.h:111
+
AudioStreamCallback * getCallback() const
Definition: AudioStreamBase.h:104
+
InputPreset getInputPreset() const
Definition: AudioStreamBase.h:121
+
AudioFormat mFormat
Definition: AudioStreamBase.h:153
+
int32_t mSampleRate
Definition: AudioStreamBase.h:137
+
int getFramesPerCallback() const
Definition: AudioStreamBase.h:66
+
virtual int32_t getBufferSizeInFrames()
Definition: AudioStreamBase.h:79
+
PerformanceMode
Definition: Definitions.h:195
+
InputPreset mInputPreset
Definition: AudioStreamBase.h:164
+
ContentType mContentType
Definition: AudioStreamBase.h:162
-
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()
-
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:277
-
AudioStreamBuilder * setInputPreset(InputPreset inputPreset)
Definition: AudioStreamBuilder.h:231
-
Result openStream(AudioStream **stream)
-
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: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: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
-
Direction
Definition: Definitions.h:87
-
AudioApi
Definition: Definitions.h:216
-
ContentType
Definition: Definitions.h:327
-
Direction mDirection
Definition: AudioStreamBase.h:155
-
static bool isAAudioSupported()
-
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: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 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_ */
SessionId mSessionId
Definition: AudioStreamBase.h:166
+
static bool isAAudioRecommended()
+
int32_t mDeviceId
Definition: AudioStreamBase.h:139
+
AudioStreamBuilder * setDirection(Direction direction)
Definition: AudioStreamBuilder.h:49
+
PerformanceMode mPerformanceMode
Definition: AudioStreamBase.h:157
+
InputPreset
Definition: Definitions.h:360
+
int32_t mChannelCount
Definition: AudioStreamBase.h:135
+
AudioStreamBuilder * setBufferCapacityInFrames(int32_t bufferCapacityInFrames)
Definition: AudioStreamBuilder.h:109
+
Direction
Definition: Definitions.h:87
+
AudioStreamBuilder * setFormat(AudioFormat format)
Definition: AudioStreamBuilder.h:95
+
Usage mUsage
Definition: AudioStreamBase.h:160
+
AudioStreamBuilder * setSharingMode(SharingMode sharingMode)
Definition: AudioStreamBuilder.h:163
+
Definition: AudioStreamBase.h:29
+
AudioStreamBuilder * setFramesPerCallback(int framesPerCallback)
Definition: AudioStreamBuilder.h:84
+
Result openStream(AudioStream **stream)
+
Direction mDirection
Definition: AudioStreamBase.h:155
+
int32_t mFramesPerCallback
Definition: AudioStreamBase.h:133
+
AudioStreamCallback * mStreamCallback
Definition: AudioStreamBase.h:131
+
int32_t mBufferCapacityInFrames
Definition: AudioStreamBase.h:141
+
SharingMode mSharingMode
Definition: AudioStreamBase.h:151
+
AudioStreamBuilder * setSampleRate(int32_t sampleRate)
Definition: AudioStreamBuilder.h:65
+
AudioStreamBuilder * setChannelCount(int channelCount)
Definition: AudioStreamBuilder.h:39
+
ContentType
Definition: Definitions.h:327
+
SessionId
Definition: Definitions.h:394
+
Definition: AudioStreamCallback.h:33
+
Definition: AudioStream.h:42
+
SharingMode
Definition: Definitions.h:176
+
AudioStreamBuilder * setCallback(AudioStreamCallback *streamCallback)
Definition: AudioStreamBuilder.h:300
+
AudioStreamBuilder * setInputPreset(InputPreset inputPreset)
Definition: AudioStreamBuilder.h:231
+
AudioApi
Definition: Definitions.h:216
+
Usage
Definition: Definitions.h:249
+
AudioFormat
Definition: Definitions.h:103
+
Result
Definition: Definitions.h:140
+
AudioStreamBuilder * setContentType(ContentType contentType)
Definition: AudioStreamBuilder.h:211
+
Definition: AudioStreamBuilder.h:28
+
Definition: AudioStream.h:29
+
AudioStreamBuilder * setDeviceId(int32_t deviceId)
Definition: AudioStreamBuilder.h:277
+
AudioFormat mFormat
Definition: AudioStreamBase.h:153
+
static bool isAAudioSupported()
+
int32_t mSampleRate
Definition: AudioStreamBase.h:137
+
AudioStreamBuilder * setUsage(Usage usage)
Definition: AudioStreamBuilder.h:194
+
AudioStreamBuilder * setPerformanceMode(PerformanceMode performanceMode)
Definition: AudioStreamBuilder.h:176
+
PerformanceMode
Definition: Definitions.h:195
+
AudioStreamBuilder * setAudioApi(AudioApi audioApi)
Definition: AudioStreamBuilder.h:132
+
InputPreset mInputPreset
Definition: AudioStreamBase.h:164
+
ContentType mContentType
Definition: AudioStreamBase.h:162
+
AudioStreamBuilder * setSessionId(SessionId sessionId)
Definition: AudioStreamBuilder.h:260
+
AudioApi getAudioApi() const
Definition: AudioStreamBuilder.h:121
-
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
-
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_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 void onErrorAfterClose(AudioStream *oboeStream, Result error)
Definition: AudioStreamCallback.h:70
+
virtual DataCallbackResult onAudioReady(AudioStream *oboeStream, void *audioData, int32_t numFrames)=0
+
virtual void onErrorBeforeClose(AudioStream *oboeStream, Result error)
Definition: AudioStreamCallback.h:58
+
DataCallbackResult
Definition: Definitions.h:128
+
Definition: AudioStreamCallback.h:33
+
Definition: AudioStream.h:42
+
Result
Definition: Definitions.h:140
+
Definition: AudioStream.h:29
-
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: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:400
-
Definition: Definitions.h:426
-
Definition: Definitions.h:386
-
Definition: Definitions.h:342
- - - -
Definition: Definitions.h:436
-
Definition: Definitions.h:337
-
constexpr int64_t kNanosPerSecond
Definition: Definitions.h:62
- -
Definition: Definitions.h:364
-
Definition: AudioStream.h:29
-
Direction
Definition: Definitions.h:87
- -
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:360
- -
constexpr int32_t kUnspecified
Definition: Definitions.h:41
-
PerformanceMode
Definition: Definitions.h:195
- - -
Definition: Definitions.h:348
-
StreamState
Definition: Definitions.h:67
- - -
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_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:348
+
Definition: Definitions.h:400
+ + + + + + +
InputPreset
Definition: Definitions.h:360
+
Definition: Definitions.h:426
+
constexpr int64_t kNanosPerMillisecond
Definition: Definitions.h:52
+ +
Direction
Definition: Definitions.h:87
+
Definition: Definitions.h:337
+
Definition: Definitions.h:386
+
static int32_t FramesPerBurst
Definition: Definitions.h:466
+ +
Definition: Definitions.h:436
+ +
Definition: Definitions.h:364
+
constexpr int64_t kMillisPerSecond
Definition: Definitions.h:57
+
StreamState
Definition: Definitions.h:67
+ + + +
DataCallbackResult
Definition: Definitions.h:128
+
ChannelCount
Definition: Definitions.h:422
+ +
ContentType
Definition: Definitions.h:327
+
SessionId
Definition: Definitions.h:394
+
static int32_t ChannelCount
Definition: Definitions.h:468
+
SharingMode
Definition: Definitions.h:176
+ +
Definition: Definitions.h:374
+
AudioApi
Definition: Definitions.h:216
+
Usage
Definition: Definitions.h:249
+ +
AudioFormat
Definition: Definitions.h:103
+
constexpr int32_t kUnspecified
Definition: Definitions.h:41
+
Definition: Definitions.h:342
+
Definition: Definitions.h:332
+
Result
Definition: Definitions.h:140
+
constexpr int64_t kNanosPerMicrosecond
Definition: Definitions.h:47
+ + +
Definition: Definitions.h:431
+
constexpr int64_t kNanosPerSecond
Definition: Definitions.h:62
+
Definition: AudioStream.h:29
+
static int32_t SampleRate
Definition: Definitions.h:464
+ + +
Definition: Definitions.h:379
+
Definition: Definitions.h:459
+
PerformanceMode
Definition: Definitions.h:195
+ +
Definition: Definitions.h:369
+
Definition: Definitions.h:409
+
-
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: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_
+
LatencyTuner(AudioStream &stream)
+
Definition: AudioStream.h:42
+
Result
Definition: Definitions.h:140
+
Definition: LatencyTuner.h:41
+ +
Definition: AudioStream.h:29
-
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
-
Result
Definition: Definitions.h:140
-
Definition: ResultWithValue.h:47
+
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
const char * convertToText(FromType input)
+
ResultWithValue(T value)
Definition: ResultWithValue.h:64
+
ResultWithValue(oboe::Result error)
Definition: ResultWithValue.h:55
+
T value() const
Definition: ResultWithValue.h:81
+
static ResultWithValue< T > createBasedOnSign(T numericResult)
Definition: ResultWithValue.h:121
+
bool operator!() const
Definition: ResultWithValue.h:100
+
oboe::Result error() const
Definition: ResultWithValue.h:73
+
Definition: ResultWithValue.h:47
+
Result
Definition: Definitions.h:140
+
Definition: AudioStream.h:29
-
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 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)
+
int getSdkVersion()
+
void convertFloatToPcm16(const float *source, int16_t *destination, int32_t numSamples)
+
void convertPcm16ToFloat(const int16_t *source, float *destination, int32_t numSamples)
+
AudioFormat
Definition: Definitions.h:103
+
Definition: AudioStream.h:29
+
int32_t convertFormatToSizeInBytes(AudioFormat format)
-
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: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
+
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 const char * Text
Definition: Version.h:78
+
static constexpr uint8_t Major
Definition: Version.h:61
+
static constexpr uint16_t Patch
Definition: Version.h:73
+
static constexpr uint32_t Number
Definition: Version.h:84
+
Definition: AudioStream.h:29
+
static constexpr uint8_t Minor
Definition: Version.h:67
+
Definition: Version.h:57
-
-
oboe Namespace Reference
+
Deprecated List
- - - - - - - - - - - - - - - - - - -

-Classes

class  AudioStream
 
class  AudioStreamBase
 
class  AudioStreamBuilder
 
class  AudioStreamCallback
 
class  DefaultStreamValues
 
class  LatencyTuner
 
class  ResultWithValue
 
struct  Version
 
- - - - - - - - - - - - - - - - - - - - - - - - - - - -

-Enumerations

enum  StreamState : aaudio_stream_state_t {
-  Uninitialized = AAUDIO_STREAM_STATE_UNINITIALIZED, -Unknown = AAUDIO_STREAM_STATE_UNKNOWN, -Open = AAUDIO_STREAM_STATE_OPEN, -Starting = AAUDIO_STREAM_STATE_STARTING, -
-  Started = AAUDIO_STREAM_STATE_STARTED, -Pausing = AAUDIO_STREAM_STATE_PAUSING, -Paused = AAUDIO_STREAM_STATE_PAUSED, -Flushing = AAUDIO_STREAM_STATE_FLUSHING, -
-  Flushed = AAUDIO_STREAM_STATE_FLUSHED, -Stopping = AAUDIO_STREAM_STATE_STOPPING, -Stopped = AAUDIO_STREAM_STATE_STOPPED, -Closing = AAUDIO_STREAM_STATE_CLOSING, -
-  Closed = AAUDIO_STREAM_STATE_CLOSED, -Disconnected = AAUDIO_STREAM_STATE_DISCONNECTED -
- }
 
enum  Direction : aaudio_direction_t { Direction::Output = AAUDIO_DIRECTION_OUTPUT, -Direction::Input = AAUDIO_DIRECTION_INPUT - }
 
enum  AudioFormat : aaudio_format_t { AudioFormat::Invalid = AAUDIO_FORMAT_INVALID, -Unspecified = AAUDIO_FORMAT_UNSPECIFIED, -AudioFormat::I16 = AAUDIO_FORMAT_PCM_I16, -AudioFormat::Float = AAUDIO_FORMAT_PCM_FLOAT - }
 
enum  DataCallbackResult : aaudio_data_callback_result_t { Continue = AAUDIO_CALLBACK_RESULT_CONTINUE, -Stop = AAUDIO_CALLBACK_RESULT_STOP - }
 
enum  Result : aaudio_result_t {
-  OK, -ErrorBase = AAUDIO_ERROR_BASE, -ErrorDisconnected = AAUDIO_ERROR_DISCONNECTED, -ErrorIllegalArgument = AAUDIO_ERROR_ILLEGAL_ARGUMENT, -
-  ErrorInternal = AAUDIO_ERROR_INTERNAL, -ErrorInvalidState = AAUDIO_ERROR_INVALID_STATE, -ErrorInvalidHandle = AAUDIO_ERROR_INVALID_HANDLE, -ErrorUnimplemented = AAUDIO_ERROR_UNIMPLEMENTED, -
-  ErrorUnavailable = AAUDIO_ERROR_UNAVAILABLE, -ErrorNoFreeHandles = AAUDIO_ERROR_NO_FREE_HANDLES, -ErrorNoMemory = AAUDIO_ERROR_NO_MEMORY, -ErrorNull = AAUDIO_ERROR_NULL, -
-  ErrorTimeout = AAUDIO_ERROR_TIMEOUT, -ErrorWouldBlock = AAUDIO_ERROR_WOULD_BLOCK, -ErrorInvalidFormat = AAUDIO_ERROR_INVALID_FORMAT, -ErrorOutOfRange = AAUDIO_ERROR_OUT_OF_RANGE, -
-  ErrorNoService = AAUDIO_ERROR_NO_SERVICE, -ErrorInvalidRate = AAUDIO_ERROR_INVALID_RATE, -Reserved1, -Reserved2, -
-  Reserved3, -Reserved4, -Reserved5, -Reserved6, -
-  Reserved7, -Reserved8, -Reserved9, -Reserved10, -
-  ErrorClosed -
- }
 
enum  SharingMode : aaudio_sharing_mode_t { SharingMode::Exclusive = AAUDIO_SHARING_MODE_EXCLUSIVE, -SharingMode::Shared = AAUDIO_SHARING_MODE_SHARED - }
 
enum  PerformanceMode : aaudio_performance_mode_t { None = AAUDIO_PERFORMANCE_MODE_NONE, -PerformanceMode::PowerSaving = AAUDIO_PERFORMANCE_MODE_POWER_SAVING, -PerformanceMode::LowLatency = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY - }
 
enum  AudioApi : int32_t { Unspecified = kUnspecified, -AudioApi::OpenSLES, -AudioApi::AAudio - }
 
enum  Usage : aaudio_usage_t {
-  Usage::Media = CONSTANT_API_P(1, AAUDIO_USAGE_MEDIA), -VoiceCommunication = CONSTANT_API_P(2, AAUDIO_USAGE_VOICE_COMMUNICATION), -Usage::VoiceCommunicationSignalling, -Usage::Alarm = CONSTANT_API_P(4, AAUDIO_USAGE_ALARM), -
-  Usage::Notification = CONSTANT_API_P(5, AAUDIO_USAGE_NOTIFICATION), -Usage::NotificationRingtone = CONSTANT_API_P(6, AAUDIO_USAGE_NOTIFICATION_RINGTONE), -Usage::NotificationEvent = CONSTANT_API_P(10, AAUDIO_USAGE_NOTIFICATION_EVENT), -Usage::AssistanceAccessibility = CONSTANT_API_P(11, AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY), -
-  Usage::AssistanceNavigationGuidance, -Usage::AssistanceSonification = CONSTANT_API_P(13, AAUDIO_USAGE_ASSISTANCE_SONIFICATION), -Usage::Game = CONSTANT_API_P(14, AAUDIO_USAGE_GAME), -Usage::Assistant = CONSTANT_API_P(16, AAUDIO_USAGE_ASSISTANT) -
- }
 
enum  ContentType : aaudio_content_type_t { Speech = CONSTANT_API_P(1, AAUDIO_CONTENT_TYPE_SPEECH), -Music = CONSTANT_API_P(2, AAUDIO_CONTENT_TYPE_MUSIC), -Movie = CONSTANT_API_P(3, AAUDIO_CONTENT_TYPE_MOVIE), -Sonification = CONSTANT_API_P(4, AAUDIO_CONTENT_TYPE_SONIFICATION) - }
 
enum  InputPreset : aaudio_input_preset_t {
-  Generic = CONSTANT_API_P(1, AAUDIO_INPUT_PRESET_GENERIC), -Camcorder = CONSTANT_API_P(5, AAUDIO_INPUT_PRESET_CAMCORDER), -VoiceRecognition = CONSTANT_API_P(6, AAUDIO_INPUT_PRESET_VOICE_RECOGNITION), -VoiceCommunication = CONSTANT_API_P(7, AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION), -
-  VoiceCommunication = CONSTANT_API_P(2, AAUDIO_USAGE_VOICE_COMMUNICATION), -Unprocessed = CONSTANT_API_P(9, AAUDIO_INPUT_PRESET_UNPROCESSED) -
- }
 
enum  SessionId { None = CONSTANT_API_P(-1, AAUDIO_SESSION_ID_NONE), -None = AAUDIO_PERFORMANCE_MODE_NONE, -Allocate = CONSTANT_API_P(0, AAUDIO_SESSION_ID_ALLOCATE) - }
 
enum  ChannelCount : int32_t {
-  Unspecified = kUnspecified, -Unspecified = AAUDIO_FORMAT_UNSPECIFIED, -Unspecified = kUnspecified, -Mono = 1, -
-  Stereo = 2 -
- }
 
- - - - - - - - - - - - - - - -

-Functions

template<typename T >
std::ostream & operator<< (std::ostream &strm, const ResultWithValue< T > &result)
 
void convertFloatToPcm16 (const float *source, int16_t *destination, int32_t numSamples)
 
void convertPcm16ToFloat (const int16_t *source, float *destination, int32_t numSamples)
 
int32_t convertFormatToSizeInBytes (AudioFormat format)
 
template<typename FromType >
const char * convertToText (FromType input)
 
int getSdkVersion ()
 
- - - - - - - - - - - - - -

-Variables

constexpr int64_t kDefaultTimeoutNanos = (2000 * kNanosPerMillisecond)
 
constexpr int32_t kUnspecified = 0
 
constexpr int64_t kNanosPerMicrosecond = 1000
 
constexpr int64_t kNanosPerMillisecond = kNanosPerMicrosecond * 1000
 
constexpr int64_t kMillisPerSecond = 1000
 
constexpr int64_t kNanosPerSecond = kNanosPerMillisecond * kMillisPerSecond
 
-

Detailed Description

-

WARNING - UNDER CONSTRUCTION - THIS API WILL CHANGE.

-

Enumeration Type Documentation

- -

◆ AudioApi

- -
-
- - - - - -
- - - - -
enum oboe::AudioApi : int32_t
-
-strong
-
-

The underlying audio API used by the audio stream.

- - - - -
Enumerator
Unspecified 

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

-
OpenSLES 

Use OpenSL ES.

-
AAudio 

Try to use AAudio. Fail if unavailable.

-
- -
-
- -

◆ AudioFormat

- -
-
- - - - - -
- - - - -
enum oboe::AudioFormat : aaudio_format_t
-
-strong
-
-

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.

-
- -
-
- -

◆ ChannelCount

- -
-
- - - - -
enum oboe::ChannelCount : int32_t
-
-

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)

- - - - - - -
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

-
Stereo 

Use this for stereo audio.

-
- -
-
- -

◆ ContentType

- -
-
- - - - -
enum oboe::ContentType : aaudio_content_type_t
-
-

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.

-

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

- - - - - -
Enumerator
Speech 

Use this for spoken voice, audio books, etcetera.

-
Music 

Use this for pre-recorded or live music.

-
Movie 

Use this for a movie or video soundtrack.

-
Sonification 

Use this for sound is designed to accompany a user action, such as a click or beep sound made when the user presses a button.

-
- -
-
- -

◆ DataCallbackResult

- -
-
- - - - - -
- - - - -
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.

-
- -
-
- -

◆ InputPreset

- -
-
- - - - -
enum oboe::InputPreset : aaudio_input_preset_t
-
-

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.

-

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

- - - - - - - -
Enumerator
Generic 

Use this preset when other presets do not apply.

-
Camcorder 

Use this preset when recording video.

-
VoiceRecognition 

Use this preset when doing speech recognition.

-
VoiceCommunication 

Use this preset when doing telephony or voice messaging.

-
VoiceCommunication 

Use this for voice over IP, telephony, etcetera.

-
Unprocessed 

Use this preset to obtain an input with no effects. Note that this input will not have automatic gain control so the recorded volume may be very low.

-
- -
-
- -

◆ PerformanceMode

- -
-
- - - - - -
- - - - -
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.

- -
-
- -

◆ SessionId

- -
-
- - - - -
enum oboe::SessionId
-
-

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.

-
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.

-
- -
-
- -

◆ SharingMode

- -
-
- - - - - -
- - - - -
enum oboe::SharingMode : aaudio_sharing_mode_t
-
-strong
-
-

The sharing mode of the audio stream.

- - - -
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.

-
Shared 

Multiple applications will be mixed by the AAudio Server. This will have higher latency than the EXCLUSIVE mode.

-
- -
-
- -

◆ StreamState

- -
-
- - - - - -
- - - - -
enum oboe::StreamState : aaudio_stream_state_t
-
-strong
-
-

The state of the audio stream.

- -
-
- -

◆ Usage

- -
-
- - - - - -
- - - - -
enum oboe::Usage : aaudio_usage_t
-
-strong
-
-

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.

-

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

- - - - - - - - - - - - - -
Enumerator
Media 

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

-
VoiceCommunication 

Use this for voice over IP, telephony, etcetera.

-
VoiceCommunicationSignalling 

Use this for sounds associated with telephony such as busy tones, DTMF, etcetera.

-
Alarm 

Use this to demand the users attention.

-
Notification 

Use this for notifying the user when a message has arrived or some other background event has occured.

-
NotificationRingtone 

Use this when the phone rings.

-
NotificationEvent 

Use this to attract the users attention when, for example, the battery is low.

-
AssistanceAccessibility 

Use this for screen readers, etcetera.

-
AssistanceNavigationGuidance 

Use this for driving or navigation directions.

-
AssistanceSonification 

Use this for user interface sounds, beeps, etcetera.

-
Game 

Use this for game audio and sound effects.

-
Assistant 

Use this for audio responses to user queries, audio instructions or help utterances.

-
- -
-
-

Function Documentation

- -

◆ convertFloatToPcm16()

- -
-
- - - - - - - - - - - - - - - - - - - - - - - - -
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.
-
+
+
Member oboe::AudioStream::isPlaying ()
+
check the stream state directly using AudioStream::getState.
- -
-
- -

◆ convertFormatToSizeInBytes()

- -
-
- - - - - - - - -
int32_t oboe::convertFormatToSizeInBytes (AudioFormat format)
-
-
Returns
the size of a sample of the given format in bytes or OBOE_ERROR_ILLEGAL_ARGUMENT
- -
-
- -

◆ convertPcm16ToFloat()

- -
-
- - - - - - - - - - - - - - - - - - - - - - - - -
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()

- -
-
-
-template<typename FromType >
- - - - - - - - -
const char* oboe::convertToText (FromType input)
-
-

The text is the ASCII symbol corresponding to the supplied Oboe enum value, or an English message saying the value is unrecognized. This is intended for developers to use when debugging. It is not for displaying to users.

-
Parameters
- - -
inputobject to convert from.
-
-
-
See also
common/Utilities.cpp for concrete implementations
-
Returns
text representation of an Oboe enum value.
- -
-
- -

◆ getSdkVersion()

- -
-
- - - - - - - -
int oboe::getSdkVersion ()
-
-

Return the version of the SDK that is currently running.

-

For example, on Android, this would return 27 for Oreo 8.1. If the version number cannot be determined then this will return -1.

-
Returns
version number or -1
- -
-
- -

◆ 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.

- -
-
-
+