diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dc02104..9749caaa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -678,6 +678,16 @@ if(NOT MINIAUDIO_NO_DEVICEIO) target_link_libraries(miniaudio_sdl2 PRIVATE PkgConfig::SDL2) endif() endif() + + # Template Backend (for build validation only, not installed) + add_library(miniaudio_backend_template STATIC + extras/backends/template/miniaudio_backend_template.c + extras/backends/template/miniaudio_backend_template.h + ) + + target_include_directories(miniaudio_backend_template PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/extras/backends/template) + target_compile_options (miniaudio_backend_template PRIVATE ${COMPILE_OPTIONS}) + target_compile_definitions(miniaudio_backend_template PRIVATE ${COMPILE_DEFINES}) endif() diff --git a/extras/backends/template/miniaudio_backend_template.c b/extras/backends/template/miniaudio_backend_template.c new file mode 100644 index 00000000..7b071d5c --- /dev/null +++ b/extras/backends/template/miniaudio_backend_template.c @@ -0,0 +1,131 @@ +#ifndef miniaudio_backend_template_c +#define miniaudio_backend_template_c + +/* Do not include this in your backend. It's only used to validate the template build. Needed for MA_ZERO_OBJECT(). */ +#include "../../../miniaudio.c" + +#include "miniaudio_backend_template.h" + +/* Wrap this in a #ifdef/#endif depending on the build environment. */ +#define MA_SUPPORT_TEMPLATE + +#if defined(MA_SUPPORT_TEMPLATE) && !defined(MA_NO_TEMPLATE) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_TEMPLATE)) + #define MA_HAS_TEMPLATE +#endif + +#if defined(MA_HAS_TEMPLATE) + +static void ma_backend_info__template(ma_device_backend_info* pBackendInfo) +{ + (void)pBackendInfo; +} + +static ma_result ma_context_init__template(ma_context* pContext, const void* pContextBackendConfig, void** ppContextState) +{ + (void)pContext; + (void)pContextBackendConfig; + (void)ppContextState; + + return MA_NOT_IMPLEMENTED; +} + +static void ma_context_uninit__template(ma_context* pContext) +{ + (void)pContext; +} + +static ma_result ma_context_enumerate_devices__template(ma_context* pContext, ma_enum_devices_callback_proc callback, void* pCallbackUserData) +{ + (void)pContext; + (void)callback; + (void)pCallbackUserData; + + return MA_NOT_IMPLEMENTED; +} + +static ma_result ma_device_init__template(ma_device* pDevice, const void* pDeviceBackendConfig, ma_device_descriptor* pDescriptorPlayback, ma_device_descriptor* pDescriptorCapture, void** ppDeviceState) +{ + (void)pDevice; + (void)pDeviceBackendConfig; + (void)pDescriptorPlayback; + (void)pDescriptorCapture; + (void)ppDeviceState; + + return MA_NOT_IMPLEMENTED; +} + +static void ma_device_uninit__template(ma_device* pDevice) +{ + (void)pDevice; +} + +static ma_result ma_device_start__template(ma_device* pDevice) +{ + (void)pDevice; + + return MA_NOT_IMPLEMENTED; +} + +static ma_result ma_device_stop__template(ma_device* pDevice) +{ + (void)pDevice; + + return MA_NOT_IMPLEMENTED; +} + +static ma_result ma_device_step__template(ma_device* pDevice, ma_blocking_mode blockingMode) +{ + (void)pDevice; + (void)blockingMode; + + return MA_NOT_IMPLEMENTED; +} + +static void ma_device_wakeup__template(ma_device* pDevice) +{ + (void)pDevice; +} + +static ma_device_backend_vtable ma_gDeviceBackendVTable_Template = +{ + ma_backend_info__template, + ma_context_init__template, + ma_context_uninit__template, + ma_context_enumerate_devices__template, + ma_device_init__template, + ma_device_uninit__template, + ma_device_start__template, + ma_device_stop__template, + ma_device_step__template, + ma_device_wakeup__template +}; + +ma_device_backend_vtable* ma_device_backend_template = &ma_gDeviceBackendVTable_Template; +#else +ma_device_backend_vtable* ma_device_backend_template = NULL; +#endif /* MA_HAS_TEMPLATE */ + +MA_API ma_device_backend_vtable* ma_template_get_vtable(void) +{ + return ma_device_backend_template; +} + +MA_API ma_context_config_template ma_context_config_template_init(void) +{ + ma_context_config_template config; + + MA_ZERO_OBJECT(&config); + + return config; +} + +MA_API ma_device_config_template ma_device_config_template_init(void) +{ + ma_device_config_template config; + + MA_ZERO_OBJECT(&config); + + return config; +} + +#endif /* miniaudio_backend_template_c */ diff --git a/extras/backends/template/miniaudio_backend_template.h b/extras/backends/template/miniaudio_backend_template.h new file mode 100644 index 00000000..d116eb35 --- /dev/null +++ b/extras/backends/template/miniaudio_backend_template.h @@ -0,0 +1,33 @@ +#ifndef miniaudio_backend_template_h +#define miniaudio_backend_template_h + +#include "../../../miniaudio.h" + +#ifdef __cplusplus +extern "C" { +#endif + +extern ma_device_backend_vtable* ma_device_backend_template; +MA_API ma_device_backend_vtable* ma_template_get_vtable(void); + + +typedef struct +{ + int _unused; +} ma_context_config_template; + +MA_API ma_context_config_template ma_context_config_template_init(void); + + +typedef struct +{ + int _unused; +} ma_device_config_template; + +MA_API ma_device_config_template ma_device_config_template_init(void); + +#ifdef __cplusplus +} +#endif +#endif /* miniaudio_backend_template_h */ +