Oboe 1.5 A library for creating real-time audio apps on 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
29 class AudioStreamBase {
30
31 public:
32
33 AudioStreamBase() {}
34
35 virtual ~AudioStreamBase() = default;
36
37 // This class only contains primitives so we can use default constructor and copy methods.
38
42 AudioStreamBase(const AudioStreamBase&) = default;
43
47 AudioStreamBase& operator=(const AudioStreamBase&) = default;
48
52 int32_t getChannelCount() const { return mChannelCount; }
53
57 Direction getDirection() const { return mDirection; }
58
62 int32_t getSampleRate() const { return mSampleRate; }
63
67 int32_t getFramesPerCallback() const { return getFramesPerDataCallback(); }
68
72 int32_t getFramesPerDataCallback() const { return mFramesPerCallback; }
73
77 AudioFormat getFormat() const { return mFormat; }
78
85 virtual int32_t getBufferSizeInFrames() { return mBufferSizeInFrames; }
86
90 virtual int32_t getBufferCapacityInFrames() const { return mBufferCapacityInFrames; }
91
95 SharingMode getSharingMode() const { return mSharingMode; }
96
100 PerformanceMode getPerformanceMode() const { return mPerformanceMode; }
101
105 int32_t getDeviceId() const { return mDeviceId; }
106
111 AudioStreamDataCallback *getDataCallback() const {
112 return mDataCallback;
113 }
114
119 AudioStreamErrorCallback *getErrorCallback() const {
120 return mErrorCallback;
121 }
122
126 bool isDataCallbackSpecified() const {
127 return mDataCallback != nullptr;
128 }
129
135 bool isErrorCallbackSpecified() const {
136 return mErrorCallback != nullptr;
137 }
138
142 Usage getUsage() const { return mUsage; }
143
147 ContentType getContentType() const { return mContentType; }
148
152 InputPreset getInputPreset() const { return mInputPreset; }
153
157 SessionId getSessionId() const { return mSessionId; }
158
162 bool isChannelConversionAllowed() const {
163 return mChannelConversionAllowed;
164 }
165
169 bool isFormatConversionAllowed() const {
170 return mFormatConversionAllowed;
171 }
172
176 SampleRateConversionQuality getSampleRateConversionQuality() const {
177 return mSampleRateConversionQuality;
178 }
179
180 protected:
182 AudioStreamDataCallback *mDataCallback = nullptr;
183
185 AudioStreamErrorCallback *mErrorCallback = nullptr;
186
188 int32_t mFramesPerCallback = kUnspecified;
190 int32_t mChannelCount = kUnspecified;
192 int32_t mSampleRate = kUnspecified;
194 int32_t mDeviceId = kUnspecified;
196 int32_t mBufferCapacityInFrames = kUnspecified;
198 int32_t mBufferSizeInFrames = kUnspecified;
203 int32_t mFramesPerBurst = kUnspecified;
204
206 SharingMode mSharingMode = SharingMode::Shared;
208 AudioFormat mFormat = AudioFormat::Unspecified;
210 Direction mDirection = Direction::Output;
212 PerformanceMode mPerformanceMode = PerformanceMode::None;
213
215 Usage mUsage = Usage::Media;
217 ContentType mContentType = ContentType::Music;
221 InputPreset mInputPreset = InputPreset::VoiceRecognition;
223 SessionId mSessionId = SessionId::None;
224
225 // Control whether Oboe can convert channel counts to achieve optimal results.
226 bool mChannelConversionAllowed = false;
227 // Control whether Oboe can convert data formats to achieve optimal results.
228 bool mFormatConversionAllowed = false;
229 // Control whether and how Oboe can convert sample rates to achieve optimal results.
230 SampleRateConversionQuality mSampleRateConversionQuality = SampleRateConversionQuality::None;
231
233 virtual Result isValidConfig() {
234 switch (mFormat) {
235 case AudioFormat::Unspecified:
236 case AudioFormat::I16:
237 case AudioFormat::Float:
238 break;
239
240 default:
241 return Result::ErrorInvalidFormat;
242 }
243
244 switch (mSampleRateConversionQuality) {
245 case SampleRateConversionQuality::None:
246 case SampleRateConversionQuality::Fastest:
247 case SampleRateConversionQuality::Low:
248 case SampleRateConversionQuality::Medium:
249 case SampleRateConversionQuality::High:
250 case SampleRateConversionQuality::Best:
251 return Result::OK;
252 default:
253 return Result::ErrorIllegalArgument;
254 }
255 }
256 };
257
258 } // namespace oboe
259
260 #endif /* OBOE_STREAM_BASE_H_ */
oboe::AudioStreamBase::getDataCallback
AudioStreamDataCallback * getDataCallback() const
Definition: AudioStreamBase.h:111
oboe::AudioStreamBase::isChannelConversionAllowed
bool isChannelConversionAllowed() const
Definition: AudioStreamBase.h:162
oboe::AudioStreamBase::mBufferSizeInFrames
int32_t mBufferSizeInFrames
Definition: AudioStreamBase.h:198
oboe::Direction::Output
oboe::AudioStreamBase::mSessionId
SessionId mSessionId
Definition: AudioStreamBase.h:223
oboe::AudioStreamBase::mDirection
Direction mDirection
Definition: AudioStreamBase.h:210
oboe::AudioStreamBase::getDeviceId
int32_t getDeviceId() const
Definition: AudioStreamBase.h:105
oboe::AudioStreamBase::mDataCallback
AudioStreamDataCallback * mDataCallback
Definition: AudioStreamBase.h:182
oboe::AudioStreamBase::mFormat
AudioFormat mFormat
Definition: AudioStreamBase.h:208
oboe::AudioStreamBase::isErrorCallbackSpecified
bool isErrorCallbackSpecified() const
Definition: AudioStreamBase.h:135
oboe::AudioStreamBase::getFramesPerCallback
int32_t getFramesPerCallback() const
Definition: AudioStreamBase.h:67
oboe::AudioStreamBase::mContentType
ContentType mContentType
Definition: AudioStreamBase.h:217
oboe::PerformanceMode
PerformanceMode
Definition: Definitions.h:192
oboe::SessionId
SessionId
Definition: Definitions.h:414
oboe::SharingMode::Shared
oboe::AudioStreamBase::mPerformanceMode
PerformanceMode mPerformanceMode
Definition: AudioStreamBase.h:212
oboe::AudioStreamBase::getPerformanceMode
PerformanceMode getPerformanceMode() const
Definition: AudioStreamBase.h:100
oboe::AudioStreamBase::getChannelCount
int32_t getChannelCount() const
Definition: AudioStreamBase.h:52
oboe::AudioStreamBase::getSessionId
SessionId getSessionId() const
Definition: AudioStreamBase.h:157
oboe::AudioStreamDataCallback
Definition: AudioStreamCallback.h:34
oboe::AudioStreamBase::mSharingMode
SharingMode mSharingMode
Definition: AudioStreamBase.h:206
oboe::AudioStreamBase::mChannelCount
int32_t mChannelCount
Definition: AudioStreamBase.h:190
oboe::AudioStreamBase::isFormatConversionAllowed
bool isFormatConversionAllowed() const
Definition: AudioStreamBase.h:169
oboe::AudioStreamBase::getFormat
AudioFormat getFormat() const
Definition: AudioStreamBase.h:77
oboe::ContentType
ContentType
Definition: Definitions.h:339
oboe::AudioStreamBase::getFramesPerDataCallback
int32_t getFramesPerDataCallback() const
Definition: AudioStreamBase.h:72
oboe::AudioStreamBase::mDeviceId
int32_t mDeviceId
Definition: AudioStreamBase.h:194
oboe::AudioStreamBase::isValidConfig
virtual Result isValidConfig()
Definition: AudioStreamBase.h:233
oboe::SampleRateConversionQuality::Best
oboe::AudioStreamBase::getContentType
ContentType getContentType() const
Definition: AudioStreamBase.h:147
oboe::AudioStreamBase::mUsage
Usage mUsage
Definition: AudioStreamBase.h:215
oboe::Usage
Usage
Definition: Definitions.h:263
oboe::AudioStreamErrorCallback
Definition: AudioStreamCallback.h:97
oboe::AudioStreamBase::getSampleRate
int32_t getSampleRate() const
Definition: AudioStreamBase.h:62
oboe::AudioStreamBase::mSampleRate
int32_t mSampleRate
Definition: AudioStreamBase.h:192
oboe::Usage::Media
oboe::AudioStreamBase::mFramesPerBurst
int32_t mFramesPerBurst
Definition: AudioStreamBase.h:203
oboe::AudioStreamBase::getSharingMode
SharingMode getSharingMode() const
Definition: AudioStreamBase.h:95
oboe::AudioFormat::I16
oboe::AudioStreamBase
Definition: AudioStreamBase.h:29
oboe::AudioStreamBase::mBufferCapacityInFrames
int32_t mBufferCapacityInFrames
Definition: AudioStreamBase.h:196
oboe::AudioFormat::Float
oboe::AudioStreamBase::getSampleRateConversionQuality
SampleRateConversionQuality getSampleRateConversionQuality() const
Definition: AudioStreamBase.h:176
oboe::AudioStreamBase::operator=
AudioStreamBase & operator=(const AudioStreamBase &)=default
oboe::AudioStreamBase::getBufferSizeInFrames
virtual int32_t getBufferSizeInFrames()
Definition: AudioStreamBase.h:85
oboe::AudioFormat
AudioFormat
Definition: Definitions.h:94
oboe::Result
Result
Definition: Definitions.h:131
oboe::kUnspecified
constexpr int32_t kUnspecified
Definition: Definitions.h:32
oboe::AudioStreamBase::getBufferCapacityInFrames
virtual int32_t getBufferCapacityInFrames() const
Definition: AudioStreamBase.h:90
oboe
Definition: AudioStream.h:31
oboe::SampleRateConversionQuality
SampleRateConversionQuality
Definition: Definitions.h:235
oboe::AudioStreamBase::mInputPreset
InputPreset mInputPreset
Definition: AudioStreamBase.h:221
oboe::Direction
Direction
Definition: Definitions.h:78
oboe::AudioStreamBase::getDirection
Direction getDirection() const
Definition: AudioStreamBase.h:57
oboe::SharingMode
SharingMode
Definition: Definitions.h:167
oboe::InputPreset
InputPreset
Definition: Definitions.h:372
oboe::SampleRateConversionQuality::Fastest
oboe::AudioStreamBase::mFramesPerCallback
int32_t mFramesPerCallback
Definition: AudioStreamBase.h:188
oboe::AudioStreamBase::isDataCallbackSpecified
bool isDataCallbackSpecified() const
Definition: AudioStreamBase.h:126
oboe::AudioStreamBase::getUsage
Usage getUsage() const
Definition: AudioStreamBase.h:142
oboe::AudioStreamBase::mErrorCallback
AudioStreamErrorCallback * mErrorCallback
Definition: AudioStreamBase.h:185
oboe::AudioStreamBase::getInputPreset
InputPreset getInputPreset() const
Definition: AudioStreamBase.h:152
oboe::AudioStreamBase::getErrorCallback
AudioStreamErrorCallback * getErrorCallback() const
Definition: AudioStreamBase.h:119