From ae46e989013a0237193024701541b43b27f3bde0 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 25 Apr 2018 11:54:05 +1000 Subject: [PATCH] OpenSL: Add support for retrieving detailed device info. --- mini_al.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mini_al.h b/mini_al.h index 3c8f36d7..0b425e03 100644 --- a/mini_al.h +++ b/mini_al.h @@ -2423,7 +2423,7 @@ mal_uint64 mal_sine_wave_read(mal_sine_wave* pSignWave, mal_uint64 count, float* #else #define MAL_NO_XGETBV #endif - #elif defined(__GNUC__) || defined(__clang__) + #elif (defined(__GNUC__) || defined(__clang__)) && !defined(MAL_ANDROID) static MAL_INLINE void mal_cpuid(int info[4], int fid) { __asm__ ( @@ -12538,6 +12538,8 @@ mal_result mal_context_get_device_info__opensl(mal_context* pContext, mal_device mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), (const char*)desc.deviceName, (size_t)-1); } + + goto return_detailed_info; #else goto return_default_device; #endif @@ -12557,6 +12559,26 @@ return_default_device: mal_strncpy_s(pDeviceInfo->name, sizeof(pDeviceInfo->name), MAL_DEFAULT_CAPTURE_DEVICE_NAME, (size_t)-1); } + goto return_detailed_info; + + +return_detailed_info: + + // For now we're just outputting a set of values that are supported by the API but not necessarily supported + // by the device natively. Later on we should work on this so that it more closely reflects the device's + // actual native format. + pDeviceInfo->minChannels = 1; + pDeviceInfo->maxChannels = 2; + pDeviceInfo->minSampleRate = 8000; + pDeviceInfo->maxSampleRate = 48000; + pDeviceInfo->formatCount = 2; + pDeviceInfo->formats[0] = mal_format_u8; + pDeviceInfo->formats[1] = mal_format_s16; +#if defined(MAL_ANDROID) && __ANDROID_API__ >= 21 + pDeviceInfo->formats[pDeviceInfo->formatCount] = mal_format_f32; + pDeviceInfo->formatCount += 1; +#endif + return MAL_SUCCESS; }