mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 16:24:04 +02:00
API CHANGE: Remove ma_is_backend_enabled() and ma_get_enabled_backends()
For determining if a backend is enabled, just compare it to NULL:
if (ma_device_backend_wasapi != NULL) {
/* Enabled */
} else {
/* Disabled */
}
If you need to list available backends, just keep track of a list of
backends that you care about, and then check which ones are null.
This commit is contained in:
-229
@@ -9575,85 +9575,6 @@ is also zero, `MA_DEFAULT_SAMPLE_RATE` will be used instead.
|
||||
*/
|
||||
MA_API ma_uint32 ma_calculate_buffer_size_in_frames_from_descriptor(const ma_device_descriptor* pDescriptor, ma_uint32 nativeSampleRate, ma_performance_profile performanceProfile);
|
||||
|
||||
|
||||
/*
|
||||
Determines whether or not the given backend is available by the compilation environment.
|
||||
*/
|
||||
MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend);
|
||||
|
||||
/*
|
||||
Retrieves compile-time enabled backends.
|
||||
|
||||
|
||||
Parameters
|
||||
----------
|
||||
pBackends (out, optional)
|
||||
A pointer to the buffer that will receive the enabled backends. Set to NULL to retrieve the backend count. Setting
|
||||
the capacity of the buffer to `MA_BUFFER_COUNT` will guarantee it's large enough for all backends.
|
||||
|
||||
backendCap (in)
|
||||
The capacity of the `pBackends` buffer.
|
||||
|
||||
pBackendCount (out)
|
||||
A pointer to the variable that will receive the enabled backend count.
|
||||
|
||||
|
||||
Return Value
|
||||
------------
|
||||
MA_SUCCESS if successful.
|
||||
MA_INVALID_ARGS if `pBackendCount` is NULL.
|
||||
MA_NO_SPACE if the capacity of `pBackends` is not large enough.
|
||||
|
||||
If `MA_NO_SPACE` is returned, the `pBackends` buffer will be filled with `*pBackendCount` values.
|
||||
|
||||
|
||||
Thread Safety
|
||||
-------------
|
||||
Safe.
|
||||
|
||||
|
||||
Callback Safety
|
||||
---------------
|
||||
Safe.
|
||||
|
||||
|
||||
Remarks
|
||||
-------
|
||||
If you want to retrieve the number of backends so you can determine the capacity of `pBackends` buffer, you can call
|
||||
this function with `pBackends` set to NULL.
|
||||
|
||||
This will also enumerate the null backend. If you don't want to include this you need to check for `ma_backend_null`
|
||||
when you enumerate over the returned backends and handle it appropriately. Alternatively, you can disable it at
|
||||
compile time with `MA_NO_NULL`.
|
||||
|
||||
The returned backends are determined based on compile time settings, not the platform it's currently running on. For
|
||||
example, PulseAudio will be returned if it was enabled at compile time, even when the user doesn't actually have
|
||||
PulseAudio installed.
|
||||
|
||||
|
||||
Example 1
|
||||
---------
|
||||
The example below retrieves the enabled backend count using a fixed sized buffer allocated on the stack. The buffer is
|
||||
given a capacity of `MA_BACKEND_COUNT` which will guarantee it'll be large enough to store all available backends.
|
||||
Since `MA_BACKEND_COUNT` is always a relatively small value, this should be suitable for most scenarios.
|
||||
|
||||
```
|
||||
ma_backend enabledBackends[MA_BACKEND_COUNT];
|
||||
size_t enabledBackendCount;
|
||||
|
||||
result = ma_get_enabled_backends(enabledBackends, MA_BACKEND_COUNT, &enabledBackendCount);
|
||||
if (result != MA_SUCCESS) {
|
||||
// Failed to retrieve enabled backends. Should never happen in this example since all inputs are valid.
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
See Also
|
||||
--------
|
||||
ma_is_backend_enabled()
|
||||
*/
|
||||
MA_API ma_result ma_get_enabled_backends(ma_backend* pBackends, size_t backendCap, size_t* pBackendCount);
|
||||
|
||||
/*
|
||||
Determines whether or not loopback mode is support by a backend.
|
||||
*/
|
||||
@@ -19585,156 +19506,6 @@ MA_API void ma_device_info_add_native_data_format(ma_device_info* pDeviceInfo, m
|
||||
}
|
||||
|
||||
|
||||
|
||||
MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend)
|
||||
{
|
||||
/*
|
||||
This looks a little bit gross, but we want all backends to be included in the switch to avoid warnings on some compilers
|
||||
about some enums not being handled by the switch statement.
|
||||
*/
|
||||
switch (backend)
|
||||
{
|
||||
case ma_backend_wasapi:
|
||||
#if defined(MA_HAS_WASAPI)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_dsound:
|
||||
#if defined(MA_HAS_DSOUND)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_winmm:
|
||||
#if defined(MA_HAS_WINMM)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_coreaudio:
|
||||
#if defined(MA_HAS_COREAUDIO)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_sndio:
|
||||
#if defined(MA_HAS_SNDIO)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_audio4:
|
||||
#if defined(MA_HAS_AUDIO4)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_oss:
|
||||
#if defined(MA_HAS_OSS)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_pulseaudio:
|
||||
#if defined(MA_HAS_PULSEAUDIO)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_alsa:
|
||||
#if defined(MA_HAS_ALSA)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_jack:
|
||||
#if defined(MA_HAS_JACK)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_aaudio:
|
||||
#if defined(MA_HAS_AAUDIO)
|
||||
#if defined(MA_ANDROID)
|
||||
{
|
||||
return ma_android_sdk_version() >= MA_AAUDIO_MIN_ANDROID_SDK_VERSION;
|
||||
}
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_opensl:
|
||||
#if defined(MA_HAS_OPENSL)
|
||||
#if defined(MA_ANDROID)
|
||||
{
|
||||
return ma_android_sdk_version() >= 9;
|
||||
}
|
||||
#else
|
||||
return MA_TRUE;
|
||||
#endif
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_webaudio:
|
||||
#if defined(MA_HAS_WEBAUDIO)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_custom:
|
||||
#if defined(MA_HAS_CUSTOM)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
case ma_backend_null:
|
||||
#if defined(MA_HAS_NULL)
|
||||
return MA_TRUE;
|
||||
#else
|
||||
return MA_FALSE;
|
||||
#endif
|
||||
|
||||
default: return MA_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
MA_API ma_result ma_get_enabled_backends(ma_backend* pBackends, size_t backendCap, size_t* pBackendCount)
|
||||
{
|
||||
size_t backendCount;
|
||||
size_t iBackend;
|
||||
ma_result result = MA_SUCCESS;
|
||||
|
||||
if (pBackendCount == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
backendCount = 0;
|
||||
|
||||
for (iBackend = 0; iBackend <= ma_backend_null; iBackend += 1) {
|
||||
ma_backend backend = (ma_backend)iBackend;
|
||||
|
||||
if (ma_is_backend_enabled(backend)) {
|
||||
/* The backend is enabled. Try adding it to the list. If there's no room, MA_NO_SPACE needs to be returned. */
|
||||
if (backendCount == backendCap) {
|
||||
result = MA_NO_SPACE;
|
||||
break;
|
||||
} else {
|
||||
pBackends[backendCount] = backend;
|
||||
backendCount += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pBackendCount != NULL) {
|
||||
*pBackendCount = backendCount;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
MA_API ma_bool32 ma_is_loopback_supported(ma_backend backend)
|
||||
{
|
||||
switch (backend)
|
||||
|
||||
Reference in New Issue
Block a user