Skip to content

Commit

Permalink
Use runtime query getSdkVersion() for OpenSL ES
Browse files Browse the repository at this point in the history
Fixes #52
  • Loading branch information
Phil Burk committed Mar 27, 2018
1 parent 2925aa7 commit 0964356
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/common/AudioStreamBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ bool AudioStreamBuilder::isAAudioSupported() {
}

bool AudioStreamBuilder::isAAudioRecommended() {
const int ANDROID_8_1 = 27; // OC-MR1
// See https://github.com/google/oboe/issues/40,
// AAudio may not be stable on Android 8.0, depending on how it is used.
return (getSdkVersion() >= ANDROID_8_1);
// AAudio may not be stable on Android O, depending on how it is used.
// To be safe, use AAUdio on O_MR1 and above.
return (getSdkVersion() >= __ANDROID_API_O_MR1__);
}

AudioStream *AudioStreamBuilder::build() {
Expand Down
2 changes: 1 addition & 1 deletion src/opensles/AudioOutputStreamOpenSLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Result AudioOutputStreamOpenSLES::open() {
* type, creating it from our original format.
*/
SLAndroidDataFormat_PCM_EX format_pcm_ex;
if (__ANDROID_API__ >= __ANDROID_API_L__) {
if (getSdkVersion() >= __ANDROID_API_L__) {
SLuint32 representation = OpenSLES_ConvertFormatToRepresentation(getFormat());
// Fill in the format structure.
format_pcm_ex = OpenSLES_createExtendedFormat(format_pcm, representation);
Expand Down
5 changes: 2 additions & 3 deletions src/opensles/AudioStreamOpenSLES.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Result AudioStreamOpenSLES::open() {
LOGI("AudioStreamOpenSLES::open(chans:%d, rate:%d)",
mChannelCount, mSampleRate);

if (__ANDROID_API__ < __ANDROID_API_L__ && mFormat == AudioFormat::Float){
if (getSdkVersion() < __ANDROID_API_L__ && mFormat == AudioFormat::Float){
// TODO: Allow floating point format on API <21 using float->int16 converter
return Result::ErrorInvalidFormat;
}
Expand All @@ -74,8 +74,7 @@ Result AudioStreamOpenSLES::open() {
// API 21+: FLOAT
// API <21: INT16
if (mFormat == AudioFormat::Unspecified){
// TODO use runtime check
mFormat = (__ANDROID_API__ < __ANDROID_API_L__) ?
mFormat = (getSdkVersion() < __ANDROID_API_L__) ?
AudioFormat::I16 : AudioFormat::Float;
}

Expand Down

0 comments on commit 0964356

Please sign in to comment.