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 
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 
96 
101 
105  int32_t getDeviceId() const { return mDeviceId; }
106 
112  return mDataCallback;
113  }
114 
120  return mErrorCallback;
121  }
122 
126  bool isDataCallbackSpecified() const {
127  return mDataCallback != nullptr;
128  }
129 
136  return mErrorCallback != nullptr;
137  }
138 
142  Usage getUsage() const { return mUsage; }
143 
148 
153 
157  SessionId getSessionId() const { return mSessionId; }
158 
163  return mChannelConversionAllowed;
164  }
165 
170  return mFormatConversionAllowed;
171  }
172 
177  return mSampleRateConversionQuality;
178  }
179 
180 protected:
183 
186 
204 
208  AudioFormat mFormat = AudioFormat::Unspecified;
212  PerformanceMode mPerformanceMode = PerformanceMode::None;
213 
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:
247  case SampleRateConversionQuality::Low:
248  case SampleRateConversionQuality::Medium:
249  case SampleRateConversionQuality::High:
251  return Result::OK;
252  default:
253  return Result::ErrorIllegalArgument;
254  }
255  }
256 };
257 
258 } // namespace oboe
259 
260 #endif /* OBOE_STREAM_BASE_H_ */
AudioStreamDataCallback * getDataCallback() const
Definition: AudioStreamBase.h:111
bool isChannelConversionAllowed() const
Definition: AudioStreamBase.h:162
int32_t mBufferSizeInFrames
Definition: AudioStreamBase.h:198
SessionId mSessionId
Definition: AudioStreamBase.h:223
Direction mDirection
Definition: AudioStreamBase.h:210
int32_t getDeviceId() const
Definition: AudioStreamBase.h:105
AudioStreamDataCallback * mDataCallback
Definition: AudioStreamBase.h:182
AudioFormat mFormat
Definition: AudioStreamBase.h:208
bool isErrorCallbackSpecified() const
Definition: AudioStreamBase.h:135
int32_t getFramesPerCallback() const
Definition: AudioStreamBase.h:67
ContentType mContentType
Definition: AudioStreamBase.h:217
PerformanceMode
Definition: Definitions.h:192
SessionId
Definition: Definitions.h:414
PerformanceMode mPerformanceMode
Definition: AudioStreamBase.h:212
PerformanceMode getPerformanceMode() const
Definition: AudioStreamBase.h:100
int32_t getChannelCount() const
Definition: AudioStreamBase.h:52
SessionId getSessionId() const
Definition: AudioStreamBase.h:157
Definition: AudioStreamCallback.h:34
SharingMode mSharingMode
Definition: AudioStreamBase.h:206
int32_t mChannelCount
Definition: AudioStreamBase.h:190
bool isFormatConversionAllowed() const
Definition: AudioStreamBase.h:169
AudioFormat getFormat() const
Definition: AudioStreamBase.h:77
ContentType
Definition: Definitions.h:339
int32_t getFramesPerDataCallback() const
Definition: AudioStreamBase.h:72
int32_t mDeviceId
Definition: AudioStreamBase.h:194
virtual Result isValidConfig()
Definition: AudioStreamBase.h:233
ContentType getContentType() const
Definition: AudioStreamBase.h:147
Usage mUsage
Definition: AudioStreamBase.h:215
Usage
Definition: Definitions.h:263
Definition: AudioStreamCallback.h:97
int32_t getSampleRate() const
Definition: AudioStreamBase.h:62
int32_t mSampleRate
Definition: AudioStreamBase.h:192
int32_t mFramesPerBurst
Definition: AudioStreamBase.h:203
SharingMode getSharingMode() const
Definition: AudioStreamBase.h:95
Definition: AudioStreamBase.h:29
int32_t mBufferCapacityInFrames
Definition: AudioStreamBase.h:196
SampleRateConversionQuality getSampleRateConversionQuality() const
Definition: AudioStreamBase.h:176
AudioStreamBase & operator=(const AudioStreamBase &)=default
virtual int32_t getBufferSizeInFrames()
Definition: AudioStreamBase.h:85
AudioFormat
Definition: Definitions.h:94
Result
Definition: Definitions.h:131
constexpr int32_t kUnspecified
Definition: Definitions.h:32
virtual int32_t getBufferCapacityInFrames() const
Definition: AudioStreamBase.h:90
Definition: AudioStream.h:31
SampleRateConversionQuality
Definition: Definitions.h:235
InputPreset mInputPreset
Definition: AudioStreamBase.h:221
Direction
Definition: Definitions.h:78
Direction getDirection() const
Definition: AudioStreamBase.h:57
SharingMode
Definition: Definitions.h:167
InputPreset
Definition: Definitions.h:372
int32_t mFramesPerCallback
Definition: AudioStreamBase.h:188
bool isDataCallbackSpecified() const
Definition: AudioStreamBase.h:126
Usage getUsage() const
Definition: AudioStreamBase.h:142
AudioStreamErrorCallback * mErrorCallback
Definition: AudioStreamBase.h:185
InputPreset getInputPreset() const
Definition: AudioStreamBase.h:152
AudioStreamErrorCallback * getErrorCallback() const
Definition: AudioStreamBase.h:119