opensles: fix API level check for FLOAT
diff --git a/src/opensles/AudioInputStreamOpenSLES.cpp b/src/opensles/AudioInputStreamOpenSLES.cpp
index 5cdadb5..71e27a1 100644
--- a/src/opensles/AudioInputStreamOpenSLES.cpp
+++ b/src/opensles/AudioInputStreamOpenSLES.cpp
@@ -108,14 +108,16 @@
* data format type: SLAndroidDataFormat_PCM_EX. If running on API 21+ use this newer format
* type, creating it from our original format.
*/
+#if __ANDROID_API__ >= __ANDROID_API_L__
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);
// Use in place of the previous format.
audioSink.pFormat = &format_pcm_ex;
}
+#endif // __ANDROID_API_L__
// configure audio source
SLDataLocator_IODevice loc_dev = {SL_DATALOCATOR_IODEVICE,
diff --git a/src/opensles/AudioOutputStreamOpenSLES.cpp b/src/opensles/AudioOutputStreamOpenSLES.cpp
index a8de563..749b509 100644
--- a/src/opensles/AudioOutputStreamOpenSLES.cpp
+++ b/src/opensles/AudioOutputStreamOpenSLES.cpp
@@ -108,6 +108,7 @@
* data format type: SLAndroidDataFormat_PCM_EX. If running on API 21+ use this newer format
* type, creating it from our original format.
*/
+#if __ANDROID_API__ >= __ANDROID_API_L__
SLAndroidDataFormat_PCM_EX format_pcm_ex;
if (getSdkVersion() >= __ANDROID_API_L__) {
SLuint32 representation = OpenSLES_ConvertFormatToRepresentation(getFormat());
@@ -116,6 +117,7 @@
// Use in place of the previous format.
audioSrc.pFormat = &format_pcm_ex;
}
+#endif // __ANDROID_API_L__
result = OutputMixerOpenSL::getInstance().createAudioPlayer(&mObjectInterface,
&audioSrc);
diff --git a/src/opensles/OpenSLESUtilities.cpp b/src/opensles/OpenSLESUtilities.cpp
index 45f1c18..5d908f2 100644
--- a/src/opensles/OpenSLESUtilities.cpp
+++ b/src/opensles/OpenSLESUtilities.cpp
@@ -45,6 +45,7 @@
return errStrings[code];
}
+#if __ANDROID_API__ >= __ANDROID_API_L__
SLAndroidDataFormat_PCM_EX OpenSLES_createExtendedFormat(
SLDataFormat_PCM format, SLuint32 representation) {
SLAndroidDataFormat_PCM_EX format_pcm_ex;
@@ -58,7 +59,9 @@
format_pcm_ex.representation = representation;
return format_pcm_ex;
}
+#endif // __ANDROID_API_L__
+#if __ANDROID_API__ >= __ANDROID_API_L__
SLuint32 OpenSLES_ConvertFormatToRepresentation(AudioFormat format) {
switch(format) {
case AudioFormat::I16:
@@ -71,5 +74,6 @@
return 0;
}
}
+#endif // __ANDROID_API_L__
} // namespace oboe
\ No newline at end of file
diff --git a/src/opensles/OpenSLESUtilities.h b/src/opensles/OpenSLESUtilities.h
index 941a527..dbcd7c9 100644
--- a/src/opensles/OpenSLESUtilities.h
+++ b/src/opensles/OpenSLESUtilities.h
@@ -24,6 +24,7 @@
const char *getSLErrStr(SLresult code);
+#if __ANDROID_API__ >= __ANDROID_API_L__
/**
* Creates an extended PCM format from the supplied format and data representation. This method
* should only be called on Android devices with API level 21+. API 21 introduced the
@@ -37,9 +38,8 @@
SLAndroidDataFormat_PCM_EX OpenSLES_createExtendedFormat(SLDataFormat_PCM format,
SLuint32 representation);
-
- SLuint32 OpenSLES_ConvertFormatToRepresentation(AudioFormat format);
-
+SLuint32 OpenSLES_ConvertFormatToRepresentation(AudioFormat format);
+#endif // __ANDROID_API_L__
} // namespace oboe