From 4b4349af525d96de894e202363777e9b2c63c75f Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Mon, 17 Feb 2025 23:03:06 +0100 Subject: [PATCH 1/9] Fix miniaudio_libvorbis.h compilation as c++ --- extras/miniaudio_libvorbis.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/miniaudio_libvorbis.h b/extras/miniaudio_libvorbis.h index e734d27f..0c298212 100644 --- a/extras/miniaudio_libvorbis.h +++ b/extras/miniaudio_libvorbis.h @@ -328,7 +328,7 @@ MA_API ma_result ma_libvorbis_read_pcm_frames(ma_libvorbis* pVorbis, void* pFram } } } else { - libvorbisResult = ov_read(&pVorbis->vf, ma_offset_pcm_frames_ptr(pFramesOut, totalFramesRead, format, channels), framesToRead * ma_get_bytes_per_frame(format, channels), 0, 2, 1, NULL); + libvorbisResult = ov_read(&pVorbis->vf, (char*)ma_offset_pcm_frames_ptr(pFramesOut, totalFramesRead, format, channels), framesToRead * ma_get_bytes_per_frame(format, channels), 0, 2, 1, NULL); if (libvorbisResult < 0) { result = MA_ERROR; /* Error while decoding. */ break; From 48ac10d1e100fa198fe2b05a0661ac8a1f533238 Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 18 Feb 2025 18:41:10 +1000 Subject: [PATCH 2/9] Fix a C++ compilation error. --- extras/decoders/libvorbis/miniaudio_libvorbis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/decoders/libvorbis/miniaudio_libvorbis.c b/extras/decoders/libvorbis/miniaudio_libvorbis.c index 1ce7e7b5..fe8081c3 100644 --- a/extras/decoders/libvorbis/miniaudio_libvorbis.c +++ b/extras/decoders/libvorbis/miniaudio_libvorbis.c @@ -298,7 +298,7 @@ MA_API ma_result ma_libvorbis_read_pcm_frames(ma_libvorbis* pVorbis, void* pFram } } } else { - libvorbisResult = ov_read((OggVorbis_File*)pVorbis->vf, ma_offset_pcm_frames_ptr(pFramesOut, totalFramesRead, format, channels), framesToRead * ma_get_bytes_per_frame(format, channels), 0, 2, 1, NULL); + libvorbisResult = ov_read((OggVorbis_File*)pVorbis->vf, (char*)ma_offset_pcm_frames_ptr(pFramesOut, totalFramesRead, format, channels), framesToRead * ma_get_bytes_per_frame(format, channels), 0, 2, 1, NULL); if (libvorbisResult < 0) { result = MA_ERROR; /* Error while decoding. */ break; From d3a4b9cf207419d973db8835f13a53376812a754 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 19 Feb 2025 08:23:11 +1000 Subject: [PATCH 3/9] Minor changes to CMakeLists. --- CMakeLists.txt | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57d2a38f..ffa8bcd5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,8 @@ project(miniaudio # Options option(MINIAUDIO_BUILD_EXAMPLES "Build miniaudio examples" OFF) option(MINIAUDIO_BUILD_TESTS "Build miniaudio tests" OFF) -option(MINIAUDIO_FORCE_CXX "Use C++ compiler for C files" OFF) -option(MINIAUDIO_FORCE_C89 "Use C89 standard" OFF) +option(MINIAUDIO_FORCE_CXX "Force compilation as C++" OFF) +option(MINIAUDIO_FORCE_C89 "Force compilation as C89" OFF) option(MINIAUDIO_NO_LIBVORBIS "Disable miniaudio_libvorbis" OFF) option(MINIAUDIO_NO_LIBOPUS "Disable miniaudio_libopus" OFF) option(MINIAUDIO_NO_WASAPI "Disable the WASAPI backend" OFF) @@ -64,19 +64,30 @@ option(MINIAUDIO_DEBUG_OUTPUT "Enable stdout debug output" # Construct compiler options. set(COMPILE_OPTIONS) +if(MINIAUDIO_FORCE_CXX AND MINIAUDIO_FORCE_C89) + message(FATAL_ERROR "MINIAUDIO_FORCE_CXX and MINIAUDIO_FORCE_C89 cannot be enabled at the same time.") +endif() + if(MINIAUDIO_FORCE_CXX) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + message(STATUS "Compiling as C++ (GNU/Clang)") list(APPEND COMPILE_OPTIONS -x c++) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + message(STATUS "Compiling as C++ (MSVC)") list(APPEND COMPILE_OPTIONS /TP) + else() + message(WARNING "MINIAUDIO_FORCE_CXX is enabled but the compiler does not support it. Ignoring.") endif() endif() if(MINIAUDIO_FORCE_C89) - if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + message(STATUS "Compiling as C89") list(APPEND COMPILE_OPTIONS -std=c89) - elseif(CMAKE_C_COMPILER_ID STREQUAL "MSVC") - # MSVC does not have an option for forcing C89. + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + message(WARNING "MSVC does not support forcing C89. MINIAUDIO_FORCE_C89 ignored.") + else() + message(WARNING "MINIAUDIO_FORCE_C89 is enabled but the compiler does not support it. Ingoring.") endif() endif() @@ -245,8 +256,6 @@ if(NOT MINIAUDIO_NO_LIBVORBIS) else() message(STATUS "libvorbisfile not found. miniaudio_libvorbis will be excluded.") endif() - - endif() if(NOT MINIAUDIO_NO_LIBOPUS) From eee86a0ae196cc101fe190e2f5574f0742b2f00d Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 19 Feb 2025 08:28:01 +1000 Subject: [PATCH 4/9] Fix the C++ build for some examples. --- examples/data_source_chaining.c | 8 ++++---- examples/hilo_interop.c | 2 +- examples/resource_manager_advanced.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/data_source_chaining.c b/examples/data_source_chaining.c index a66258ee..c9126976 100644 --- a/examples/data_source_chaining.c +++ b/examples/data_source_chaining.c @@ -135,15 +135,15 @@ int main(int argc, char** argv) deviceConfig.dataCallback = data_callback; deviceConfig.pUserData = NULL; - if (ma_device_init(NULL, &deviceConfig, &device) != MA_SUCCESS) { + result = ma_device_init(NULL, &deviceConfig, &device); + if (result != MA_SUCCESS) { printf("Failed to open playback device.\n"); - result = -1; goto done_decoders; } - if (ma_device_start(&device) != MA_SUCCESS) { + result = ma_device_start(&device); + if (result != MA_SUCCESS) { printf("Failed to start playback device.\n"); - result = -1; goto done; } diff --git a/examples/hilo_interop.c b/examples/hilo_interop.c index 4a82f89d..ea115660 100644 --- a/examples/hilo_interop.c +++ b/examples/hilo_interop.c @@ -46,7 +46,7 @@ void capture_data_callback(ma_device* pDevice, void* pFramesOut, const void* pFr } /* Copy the data from the capture buffer to the ring buffer. */ - ma_copy_pcm_frames(pMappedBuffer, ma_offset_pcm_frames_const_ptr_f32(pFramesIn, framesWritten, pDevice->capture.channels), framesToWrite, pDevice->capture.format, pDevice->capture.channels); + ma_copy_pcm_frames(pMappedBuffer, ma_offset_pcm_frames_const_ptr_f32((const float*)pFramesIn, framesWritten, pDevice->capture.channels), framesToWrite, pDevice->capture.format, pDevice->capture.channels); result = ma_pcm_rb_commit_write(&rb, framesToWrite); if (result != MA_SUCCESS) { diff --git a/examples/resource_manager_advanced.c b/examples/resource_manager_advanced.c index 25b37e78..292aa99e 100644 --- a/examples/resource_manager_advanced.c +++ b/examples/resource_manager_advanced.c @@ -110,7 +110,7 @@ MA_API ma_result ma_data_source_read_pcm_frames_and_mix_f32(ma_data_source* pDat result = ma_data_source_read_pcm_frames_f32_ex(pDataSource, temp, framesToRead, &framesJustRead, format, channels); - ma_mix_pcm_frames_f32(ma_offset_pcm_frames_ptr(pFramesOut, totalFramesRead, ma_format_f32, channels), temp, framesJustRead, channels, volume); + ma_mix_pcm_frames_f32(ma_offset_pcm_frames_ptr_f32(pFramesOut, totalFramesRead, channels), temp, framesJustRead, channels, volume); totalFramesRead += framesJustRead; if (result != MA_SUCCESS) { From 698a4319f0febecc06398f9ade0aec3ac04f1ac1 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 19 Feb 2025 09:43:19 +1000 Subject: [PATCH 5/9] Update fs. --- external/fs/fs.c | 20 ++++++++++---------- external/fs/fs.h | 7 +++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/external/fs/fs.c b/external/fs/fs.c index 5c7fe7f2..4ac09710 100644 --- a/external/fs/fs.c +++ b/external/fs/fs.c @@ -11,14 +11,14 @@ #if defined(_WIN32) #include /* <-- Just can't get away from this darn thing... Needed for mutexes and file iteration. */ -static int fs_result_from_GetLastError(DWORD error) +static fs_result fs_result_from_GetLastError(DWORD error) { switch (error) { case ERROR_SUCCESS: return FS_SUCCESS; - case ERROR_NOT_ENOUGH_MEMORY: return ENOMEM; - case ERROR_SEM_TIMEOUT: return ETIMEDOUT; - case ERROR_BUSY: return EBUSY; + case ERROR_NOT_ENOUGH_MEMORY: return FS_OUT_OF_MEMORY; + case ERROR_BUSY: return FS_BUSY; + case ERROR_SEM_TIMEOUT: return FS_TIMEOUT; default: break; } @@ -1376,9 +1376,11 @@ static fs_result fs_file_duplicate_proxy(fs_file* pFile, fs_file* pDuplicatedFil /* Increment the reference count of the opened archive if necessary. */ if (fs_file_proxy_get_unref_archive_on_close(pFile)) { + fs* pOwnerFS; + fs_file_proxy_set_unref_archive_on_close(pDuplicatedFile, FS_TRUE); - fs* pOwnerFS = fs_proxy_get_owner_fs(pFS); + pOwnerFS = fs_proxy_get_owner_fs(pFS); if (pOwnerFS != NULL) { fs_increment_opened_archive_ref_count(pOwnerFS, pFS); } @@ -4517,7 +4519,7 @@ static fs_uint64 fs_FILETIME_to_unix(const FILETIME* pFT) li.HighPart = pFT->dwHighDateTime; li.LowPart = pFT->dwLowDateTime; - return (fs_uint64)(li.QuadPart / 10000000ULL - 11644473600ULL); /* Convert from Windows epoch to Unix epoch. */ + return (fs_uint64)(li.QuadPart / 10000000UL - 11644473600UL); /* Convert from Windows epoch to Unix epoch. */ } static fs_file_info fs_file_info_from_WIN32_FIND_DATAW(const WIN32_FIND_DATAW* pFD) @@ -5048,7 +5050,7 @@ FS_API fs_result fs_file_duplicate_stdio(fs_file* pFile, fs_file* pDuplicatedFil return fs_result_from_errno(GetLastError()); } - fdDuplicate = _open_osfhandle((intptr_t)hFileDuplicate, _O_RDONLY); + fdDuplicate = _open_osfhandle((fs_intptr)hFileDuplicate, _O_RDONLY); if (fdDuplicate == -1) { CloseHandle(hFileDuplicate); return fs_result_from_errno(errno); @@ -6003,8 +6005,6 @@ FS_API int fs_path_normalize(char* pDst, size_t dstCap, const char* pPath, size_ /* BEG fs_memory_stream.c */ -#include - static fs_result fs_memory_stream_read_internal(fs_stream* pStream, void* pDst, size_t bytesToRead, size_t* pBytesRead) { return fs_memory_stream_read((fs_memory_stream*)pStream, pDst, bytesToRead, pBytesRead); @@ -6030,7 +6030,7 @@ static fs_result fs_memory_stream_tell_internal(fs_stream* pStream, fs_int64* pC return result; } - if (cursor > INT64_MAX) { /* <-- INT64_MAX may not be defined on some compilers. Need to check this. Can easily define this ourselves. */ + if (cursor > FS_INT64_MAX) { /* <-- INT64_MAX may not be defined on some compilers. Need to check this. Can easily define this ourselves. */ return FS_ERROR; } diff --git a/external/fs/fs.h b/external/fs/fs.h index 53d201e7..e99686bb 100644 --- a/external/fs/fs.h +++ b/external/fs/fs.h @@ -580,8 +580,10 @@ extern "C" { #if FS_SIZEOF_PTR == 8 typedef unsigned long long fs_uintptr; + typedef long long fs_intptr; #else typedef unsigned int fs_uintptr; + typedef int fs_intptr; #endif typedef unsigned char fs_bool8; @@ -590,6 +592,9 @@ typedef unsigned int fs_bool32; #define FS_FALSE 0 +#define FS_INT64_MAX ((fs_int64)(((fs_uint64)0x7FFFFFFF << 32) | 0xFFFFFFFF)) + + #ifndef FS_API #define FS_API #endif @@ -659,8 +664,10 @@ typedef enum fs_result FS_IS_DIRECTORY = -15, FS_DIRECTORY_NOT_EMPTY = -16, FS_AT_END = -17, + FS_BUSY = -19, FS_BAD_SEEK = -25, FS_NOT_IMPLEMENTED = -29, + FS_TIMEOUT = -34, FS_CHECKSUM_MISMATCH = -100, FS_NO_BACKEND = -101 } fs_result; From e08c1303ef9d89ca011da322149133c4c339d7ed Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 19 Feb 2025 09:43:51 +1000 Subject: [PATCH 6/9] Fix a bug with the deviceio test. --- tests/test_deviceio/ma_test_deviceio.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_deviceio/ma_test_deviceio.c b/tests/test_deviceio/ma_test_deviceio.c index 495066e8..effc0027 100644 --- a/tests/test_deviceio/ma_test_deviceio.c +++ b/tests/test_deviceio/ma_test_deviceio.c @@ -594,7 +594,7 @@ int main(int argc, char** argv) } /* Now we just keep looping and wait for user input. */ - while (!g_State.wantsToClose) { + for (;;) { if (interactive) { int c; @@ -630,6 +630,10 @@ int main(int argc, char** argv) } } else { /* Running in auto-close mode. Just sleep for a bit. The data callback will control when this loop aborts. */ + if (g_State.wantsToClose) { + break; + } + ma_sleep(10); } } From 466a1354ce96fb3f8194fe7a1b37a809f7399fe4 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 19 Feb 2025 10:30:09 +1000 Subject: [PATCH 7/9] Experiment with a fix for older versions of Clang. --- miniaudio.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 49fe4178..0da25990 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -14905,7 +14905,9 @@ typedef int ma_atomic_memory_order; } #if defined(__clang__) #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Watomic-alignment" + #if __clang_major__ >= 8 + #pragma clang diagnostic ignored "-Watomic-alignment" + #endif #endif static MA_INLINE ma_uint64 ma_atomic_compare_and_swap_64(volatile ma_uint64* dst, ma_uint64 expected, ma_uint64 desired) { From b40803cf97d5a90f24da46b83cbf4ac196bcb756 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 19 Feb 2025 12:01:22 +1000 Subject: [PATCH 8/9] Update fs. --- external/fs/fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/fs/fs.c b/external/fs/fs.c index 4ac09710..afc88fd4 100644 --- a/external/fs/fs.c +++ b/external/fs/fs.c @@ -22,7 +22,7 @@ static fs_result fs_result_from_GetLastError(DWORD error) default: break; } - return EINVAL; + return FS_ERROR; } #endif From 8ad250ccf68f2cb4a2ddd72440a61c0e305a6938 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 19 Feb 2025 12:02:37 +1000 Subject: [PATCH 9/9] Updates to custom decoders. --- CMakeLists.txt | 18 +-- examples/custom_decoder.c | 143 +----------------- examples/custom_decoder_engine.c | 143 +----------------- extras/decoders/libopus/miniaudio_libopus.c | 90 ++++++++++- extras/decoders/libopus/miniaudio_libopus.h | 3 + .../decoders/libvorbis/miniaudio_libvorbis.c | 105 +++++++++++-- .../decoders/libvorbis/miniaudio_libvorbis.h | 3 + miniaudio.h | 10 +- 8 files changed, 206 insertions(+), 309 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffa8bcd5..59931629 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") list(APPEND COMPILE_OPTIONS -Wall -Wextra -Wpedantic) elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - list(APPEND COMPILE_OPTIONS /W4) + #list(APPEND COMPILE_OPTIONS /W4) endif() @@ -445,29 +445,21 @@ if (MINIAUDIO_BUILD_EXAMPLES) add_miniaudio_example(miniaudio_custom_backend custom_backend.c) add_miniaudio_example(miniaudio_custom_decoder_engine custom_decoder_engine.c) - if(HAS_LIBVORBIS) - target_link_libraries(miniaudio_custom_decoder_engine PRIVATE miniaudio_libvorbis) - else() + if(NOT HAS_LIBVORBIS) target_compile_definitions(miniaudio_custom_decoder_engine PRIVATE MA_NO_LIBVORBIS) message(STATUS "miniaudio_libvorbis is disabled. Vorbis support is disabled in miniaudio_custom_decoder_engine.") endif() - if(HAS_LIBOPUS) - target_link_libraries(miniaudio_custom_decoder_engine PRIVATE miniaudio_libopus) - else() + if(NOT HAS_LIBOPUS) target_compile_definitions(miniaudio_custom_decoder_engine PRIVATE MA_NO_LIBOPUS) message(STATUS "miniaudio_libopus is disabled. Opus support is disabled in miniaudio_custom_decoder_engine.") endif() add_miniaudio_example(miniaudio_custom_decoder custom_decoder.c) - if(HAS_LIBVORBIS) - target_link_libraries(miniaudio_custom_decoder PRIVATE miniaudio_libvorbis) - else() + if(NOT HAS_LIBVORBIS) target_compile_definitions(miniaudio_custom_decoder PRIVATE MA_NO_LIBVORBIS) message(STATUS "miniaudio_libvorbis is disabled. Vorbis support is disabled in miniaudio_custom_decoder.") endif() - if(HAS_LIBOPUS) - target_link_libraries(miniaudio_custom_decoder PRIVATE miniaudio_libopus) - else() + if(NOT HAS_LIBOPUS) target_compile_definitions(miniaudio_custom_decoder PRIVATE MA_NO_LIBOPUS) message(STATUS "miniaudio_libopus is disabled. Opus support is disabled in miniaudio_custom_decoder.") endif() diff --git a/examples/custom_decoder.c b/examples/custom_decoder.c index 1ba1a184..e218945a 100644 --- a/examples/custom_decoder.c +++ b/examples/custom_decoder.c @@ -20,145 +20,12 @@ The `onInitFile`, `onInitFileW` and `onInitMemory` functions are optional. For now these need to be declared before miniaudio.c due to some compatibility issues with the old MINIAUDIO_IMPLEMENTATION system. This will change from version 0.12. */ -#include "../extras/decoders/libvorbis/miniaudio_libvorbis.h" -#include "../extras/decoders/libopus/miniaudio_libopus.h" +#include "../extras/decoders/libvorbis/miniaudio_libvorbis.c" +#include "../extras/decoders/libopus/miniaudio_libopus.c" #include "../miniaudio.c" #include -static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) -{ - ma_result result; - ma_libvorbis* pVorbis; - - (void)pUserData; - - pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks); - if (pVorbis == NULL) { - return MA_OUT_OF_MEMORY; - } - - result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis); - if (result != MA_SUCCESS) { - ma_free(pVorbis, pAllocationCallbacks); - return result; - } - - *ppBackend = pVorbis; - - return MA_SUCCESS; -} - -static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) -{ - ma_result result; - ma_libvorbis* pVorbis; - - (void)pUserData; - - pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks); - if (pVorbis == NULL) { - return MA_OUT_OF_MEMORY; - } - - result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis); - if (result != MA_SUCCESS) { - ma_free(pVorbis, pAllocationCallbacks); - return result; - } - - *ppBackend = pVorbis; - - return MA_SUCCESS; -} - -static void ma_decoding_backend_uninit__libvorbis(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks) -{ - ma_libvorbis* pVorbis = (ma_libvorbis*)pBackend; - - (void)pUserData; - - ma_libvorbis_uninit(pVorbis, pAllocationCallbacks); - ma_free(pVorbis, pAllocationCallbacks); -} - -static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libvorbis = -{ - ma_decoding_backend_init__libvorbis, - ma_decoding_backend_init_file__libvorbis, - NULL, /* onInitFileW() */ - NULL, /* onInitMemory() */ - ma_decoding_backend_uninit__libvorbis -}; - - - -static ma_result ma_decoding_backend_init__libopus(void* pUserData, ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) -{ - ma_result result; - ma_libopus* pOpus; - - (void)pUserData; - - pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks); - if (pOpus == NULL) { - return MA_OUT_OF_MEMORY; - } - - result = ma_libopus_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pOpus); - if (result != MA_SUCCESS) { - ma_free(pOpus, pAllocationCallbacks); - return result; - } - - *ppBackend = pOpus; - - return MA_SUCCESS; -} - -static ma_result ma_decoding_backend_init_file__libopus(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) -{ - ma_result result; - ma_libopus* pOpus; - - (void)pUserData; - - pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks); - if (pOpus == NULL) { - return MA_OUT_OF_MEMORY; - } - - result = ma_libopus_init_file(pFilePath, pConfig, pAllocationCallbacks, pOpus); - if (result != MA_SUCCESS) { - ma_free(pOpus, pAllocationCallbacks); - return result; - } - - *ppBackend = pOpus; - - return MA_SUCCESS; -} - -static void ma_decoding_backend_uninit__libopus(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks) -{ - ma_libopus* pOpus = (ma_libopus*)pBackend; - - (void)pUserData; - - ma_libopus_uninit(pOpus, pAllocationCallbacks); - ma_free(pOpus, pAllocationCallbacks); -} - -static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libopus = -{ - ma_decoding_backend_init__libopus, - ma_decoding_backend_init_file__libopus, - NULL, /* onInitFileW() */ - NULL, /* onInitMemory() */ - ma_decoding_backend_uninit__libopus -}; - - void data_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { @@ -187,10 +54,10 @@ int main(int argc, char** argv) Add your custom backend vtables here. The order in the array defines the order of priority. The vtables will be passed in via the decoder config. */ - ma_decoding_backend_vtable* pCustomBackendVTables[] = + const ma_decoding_backend_vtable* pCustomBackendVTables[] = { - &g_ma_decoding_backend_vtable_libvorbis, - &g_ma_decoding_backend_vtable_libopus + ma_decoding_backend_libvorbis, + ma_decoding_backend_libopus }; diff --git a/examples/custom_decoder_engine.c b/examples/custom_decoder_engine.c index e0b5949c..df452cc1 100644 --- a/examples/custom_decoder_engine.c +++ b/examples/custom_decoder_engine.c @@ -10,145 +10,12 @@ example (via libopus). For now these need to be declared before miniaudio.c due to some compatibility issues with the old MINIAUDIO_IMPLEMENTATION system. This will change from version 0.12. */ -#include "../extras/decoders/libvorbis/miniaudio_libvorbis.h" -#include "../extras/decoders/libopus/miniaudio_libopus.h" +#include "../extras/decoders/libvorbis/miniaudio_libvorbis.c" +#include "../extras/decoders/libopus/miniaudio_libopus.c" #include "../miniaudio.c" #include -static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) -{ - ma_result result; - ma_libvorbis* pVorbis; - - (void)pUserData; - - pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks); - if (pVorbis == NULL) { - return MA_OUT_OF_MEMORY; - } - - result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis); - if (result != MA_SUCCESS) { - ma_free(pVorbis, pAllocationCallbacks); - return result; - } - - *ppBackend = pVorbis; - - return MA_SUCCESS; -} - -static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) -{ - ma_result result; - ma_libvorbis* pVorbis; - - (void)pUserData; - - pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks); - if (pVorbis == NULL) { - return MA_OUT_OF_MEMORY; - } - - result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis); - if (result != MA_SUCCESS) { - ma_free(pVorbis, pAllocationCallbacks); - return result; - } - - *ppBackend = pVorbis; - - return MA_SUCCESS; -} - -static void ma_decoding_backend_uninit__libvorbis(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks) -{ - ma_libvorbis* pVorbis = (ma_libvorbis*)pBackend; - - (void)pUserData; - - ma_libvorbis_uninit(pVorbis, pAllocationCallbacks); - ma_free(pVorbis, pAllocationCallbacks); -} - -static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libvorbis = -{ - ma_decoding_backend_init__libvorbis, - ma_decoding_backend_init_file__libvorbis, - NULL, /* onInitFileW() */ - NULL, /* onInitMemory() */ - ma_decoding_backend_uninit__libvorbis -}; - - - -static ma_result ma_decoding_backend_init__libopus(void* pUserData, ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) -{ - ma_result result; - ma_libopus* pOpus; - - (void)pUserData; - - pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks); - if (pOpus == NULL) { - return MA_OUT_OF_MEMORY; - } - - result = ma_libopus_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pOpus); - if (result != MA_SUCCESS) { - ma_free(pOpus, pAllocationCallbacks); - return result; - } - - *ppBackend = pOpus; - - return MA_SUCCESS; -} - -static ma_result ma_decoding_backend_init_file__libopus(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) -{ - ma_result result; - ma_libopus* pOpus; - - (void)pUserData; - - pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks); - if (pOpus == NULL) { - return MA_OUT_OF_MEMORY; - } - - result = ma_libopus_init_file(pFilePath, pConfig, pAllocationCallbacks, pOpus); - if (result != MA_SUCCESS) { - ma_free(pOpus, pAllocationCallbacks); - return result; - } - - *ppBackend = pOpus; - - return MA_SUCCESS; -} - -static void ma_decoding_backend_uninit__libopus(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks) -{ - ma_libopus* pOpus = (ma_libopus*)pBackend; - - (void)pUserData; - - ma_libopus_uninit(pOpus, pAllocationCallbacks); - ma_free(pOpus, pAllocationCallbacks); -} - -static ma_decoding_backend_vtable g_ma_decoding_backend_vtable_libopus = -{ - ma_decoding_backend_init__libopus, - ma_decoding_backend_init_file__libopus, - NULL, /* onInitFileW() */ - NULL, /* onInitMemory() */ - ma_decoding_backend_uninit__libopus -}; - - int main(int argc, char** argv) { @@ -162,10 +29,10 @@ int main(int argc, char** argv) Add your custom backend vtables here. The order in the array defines the order of priority. The vtables will be passed in to the resource manager config. */ - ma_decoding_backend_vtable* pCustomBackendVTables[] = + const ma_decoding_backend_vtable* pCustomBackendVTables[] = { - &g_ma_decoding_backend_vtable_libvorbis, - &g_ma_decoding_backend_vtable_libopus + ma_decoding_backend_libvorbis, + ma_decoding_backend_libopus }; diff --git a/extras/decoders/libopus/miniaudio_libopus.c b/extras/decoders/libopus/miniaudio_libopus.c index b3403bd7..61c1d19b 100644 --- a/extras/decoders/libopus/miniaudio_libopus.c +++ b/extras/decoders/libopus/miniaudio_libopus.c @@ -3,8 +3,12 @@ #include "miniaudio_libopus.h" +#if !defined(MA_NO_LIBOPUS) #include +#endif + #include /* For memset(). */ +#include static ma_result ma_libopus_ds_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead) { @@ -221,7 +225,7 @@ MA_API void ma_libopus_uninit(ma_libopus* pOpus, const ma_allocation_callbacks* #else { /* libopus is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); } #endif @@ -296,7 +300,7 @@ MA_API ma_result ma_libopus_read_pcm_frames(ma_libopus* pOpus, void* pFramesOut, #else { /* libopus is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); (void)pFramesOut; (void)frameCount; @@ -331,7 +335,7 @@ MA_API ma_result ma_libopus_seek_to_pcm_frame(ma_libopus* pOpus, ma_uint64 frame #else { /* libopus is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); (void)frameIndex; @@ -385,7 +389,7 @@ MA_API ma_result ma_libopus_get_data_format(ma_libopus* pOpus, ma_format* pForma #else { /* libopus is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); return MA_NOT_IMPLEMENTED; } #endif @@ -417,7 +421,7 @@ MA_API ma_result ma_libopus_get_cursor_in_pcm_frames(ma_libopus* pOpus, ma_uint6 #else { /* libopus is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); return MA_NOT_IMPLEMENTED; } #endif @@ -449,10 +453,84 @@ MA_API ma_result ma_libopus_get_length_in_pcm_frames(ma_libopus* pOpus, ma_uint6 #else { /* libopus is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); return MA_NOT_IMPLEMENTED; } #endif } + +/* +The code below defines the vtable that you'll plug into your `ma_decoder_config` object. +*/ +#if !defined(MA_NO_LIBOPUS) +static ma_result ma_decoding_backend_init__libopus(void* pUserData, ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) +{ + ma_result result; + ma_libopus* pOpus; + + (void)pUserData; + + pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks); + if (pOpus == NULL) { + return MA_OUT_OF_MEMORY; + } + + result = ma_libopus_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pOpus); + if (result != MA_SUCCESS) { + ma_free(pOpus, pAllocationCallbacks); + return result; + } + + *ppBackend = pOpus; + + return MA_SUCCESS; +} + +static ma_result ma_decoding_backend_init_file__libopus(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) +{ + ma_result result; + ma_libopus* pOpus; + + (void)pUserData; + + pOpus = (ma_libopus*)ma_malloc(sizeof(*pOpus), pAllocationCallbacks); + if (pOpus == NULL) { + return MA_OUT_OF_MEMORY; + } + + result = ma_libopus_init_file(pFilePath, pConfig, pAllocationCallbacks, pOpus); + if (result != MA_SUCCESS) { + ma_free(pOpus, pAllocationCallbacks); + return result; + } + + *ppBackend = pOpus; + + return MA_SUCCESS; +} + +static void ma_decoding_backend_uninit__libopus(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks) +{ + ma_libopus* pOpus = (ma_libopus*)pBackend; + + (void)pUserData; + + ma_libopus_uninit(pOpus, pAllocationCallbacks); + ma_free(pOpus, pAllocationCallbacks); +} + +static ma_decoding_backend_vtable ma_gDecodingBackendVTable_libopus = +{ + ma_decoding_backend_init__libopus, + ma_decoding_backend_init_file__libopus, + NULL, /* onInitFileW() */ + NULL, /* onInitMemory() */ + ma_decoding_backend_uninit__libopus +}; +const ma_decoding_backend_vtable* ma_decoding_backend_libopus = &ma_gDecodingBackendVTable_libopus; +#else +const ma_decoding_backend_vtable* ma_decoding_backend_libopus = NULL; +#endif + #endif /* miniaudio_libopus_c */ diff --git a/extras/decoders/libopus/miniaudio_libopus.h b/extras/decoders/libopus/miniaudio_libopus.h index 66e9505a..f8d005c5 100644 --- a/extras/decoders/libopus/miniaudio_libopus.h +++ b/extras/decoders/libopus/miniaudio_libopus.h @@ -33,6 +33,9 @@ MA_API ma_result ma_libopus_get_data_format(ma_libopus* pOpus, ma_format* pForma MA_API ma_result ma_libopus_get_cursor_in_pcm_frames(ma_libopus* pOpus, ma_uint64* pCursor); MA_API ma_result ma_libopus_get_length_in_pcm_frames(ma_libopus* pOpus, ma_uint64* pLength); +/* Decoding backend vtable. This is what you'll plug into ma_decoder_config.pBackendVTables. No user data required. */ +extern const ma_decoding_backend_vtable* ma_decoding_backend_libopus; + #ifdef __cplusplus } #endif diff --git a/extras/decoders/libvorbis/miniaudio_libvorbis.c b/extras/decoders/libvorbis/miniaudio_libvorbis.c index fe8081c3..49dcaf12 100644 --- a/extras/decoders/libvorbis/miniaudio_libvorbis.c +++ b/extras/decoders/libvorbis/miniaudio_libvorbis.c @@ -11,6 +11,7 @@ #endif #include /* For memset(). */ +#include static ma_result ma_libvorbis_ds_read(ma_data_source* pDataSource, void* pFramesOut, ma_uint64 frameCount, ma_uint64* pFramesRead) { @@ -135,11 +136,20 @@ static ma_result ma_libvorbis_init_internal(const ma_decoding_backend_config* pC return result; /* Failed to initialize the base data source. */ } - pVorbis->vf = (OggVorbis_File*)ma_malloc(sizeof(OggVorbis_File), pAllocationCallbacks); - if (pVorbis->vf == NULL) { - ma_data_source_uninit(&pVorbis->ds); - return MA_OUT_OF_MEMORY; + #if !defined(MA_NO_LIBVORBIS) + { + pVorbis->vf = (OggVorbis_File*)ma_malloc(sizeof(OggVorbis_File), pAllocationCallbacks); + if (pVorbis->vf == NULL) { + ma_data_source_uninit(&pVorbis->ds); + return MA_OUT_OF_MEMORY; + } } + #else + { + /* libvorbis is disabled. */ + return MA_NOT_IMPLEMENTED; + } + #endif return MA_SUCCESS; } @@ -236,7 +246,7 @@ MA_API void ma_libvorbis_uninit(ma_libvorbis* pVorbis, const ma_allocation_callb #else { /* libvorbis is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); } #endif @@ -327,7 +337,7 @@ MA_API ma_result ma_libvorbis_read_pcm_frames(ma_libvorbis* pVorbis, void* pFram #else { /* libvorbis is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); (void)pFramesOut; (void)frameCount; @@ -362,7 +372,7 @@ MA_API ma_result ma_libvorbis_seek_to_pcm_frame(ma_libvorbis* pVorbis, ma_uint64 #else { /* libvorbis is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); (void)frameIndex; @@ -419,7 +429,7 @@ MA_API ma_result ma_libvorbis_get_data_format(ma_libvorbis* pVorbis, ma_format* #else { /* libvorbis is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); return MA_NOT_IMPLEMENTED; } #endif @@ -451,7 +461,7 @@ MA_API ma_result ma_libvorbis_get_cursor_in_pcm_frames(ma_libvorbis* pVorbis, ma #else { /* libvorbis is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); return MA_NOT_IMPLEMENTED; } #endif @@ -479,10 +489,85 @@ MA_API ma_result ma_libvorbis_get_length_in_pcm_frames(ma_libvorbis* pVorbis, ma #else { /* libvorbis is disabled. Should never hit this since initialization would have failed. */ - MA_ASSERT(MA_FALSE); + assert(MA_FALSE); return MA_NOT_IMPLEMENTED; } #endif } + +/* +The code below defines the vtable that you'll plug into your `ma_decoder_config` object. +*/ +#if !defined(MA_NO_LIBVORBIS) +static ma_result ma_decoding_backend_init__libvorbis(void* pUserData, ma_read_proc onRead, ma_seek_proc onSeek, ma_tell_proc onTell, void* pReadSeekTellUserData, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) +{ + ma_result result; + ma_libvorbis* pVorbis; + + (void)pUserData; + + pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks); + if (pVorbis == NULL) { + return MA_OUT_OF_MEMORY; + } + + result = ma_libvorbis_init(onRead, onSeek, onTell, pReadSeekTellUserData, pConfig, pAllocationCallbacks, pVorbis); + if (result != MA_SUCCESS) { + ma_free(pVorbis, pAllocationCallbacks); + return result; + } + + *ppBackend = pVorbis; + + return MA_SUCCESS; +} + +static ma_result ma_decoding_backend_init_file__libvorbis(void* pUserData, const char* pFilePath, const ma_decoding_backend_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_data_source** ppBackend) +{ + ma_result result; + ma_libvorbis* pVorbis; + + (void)pUserData; + + pVorbis = (ma_libvorbis*)ma_malloc(sizeof(*pVorbis), pAllocationCallbacks); + if (pVorbis == NULL) { + return MA_OUT_OF_MEMORY; + } + + result = ma_libvorbis_init_file(pFilePath, pConfig, pAllocationCallbacks, pVorbis); + if (result != MA_SUCCESS) { + ma_free(pVorbis, pAllocationCallbacks); + return result; + } + + *ppBackend = pVorbis; + + return MA_SUCCESS; +} + +static void ma_decoding_backend_uninit__libvorbis(void* pUserData, ma_data_source* pBackend, const ma_allocation_callbacks* pAllocationCallbacks) +{ + ma_libvorbis* pVorbis = (ma_libvorbis*)pBackend; + + (void)pUserData; + + ma_libvorbis_uninit(pVorbis, pAllocationCallbacks); + ma_free(pVorbis, pAllocationCallbacks); +} + + +static ma_decoding_backend_vtable ma_gDecodingBackendVTable_libvorbis = +{ + ma_decoding_backend_init__libvorbis, + ma_decoding_backend_init_file__libvorbis, + NULL, /* onInitFileW() */ + NULL, /* onInitMemory() */ + ma_decoding_backend_uninit__libvorbis +}; +const ma_decoding_backend_vtable* ma_decoding_backend_libvorbis = &ma_gDecodingBackendVTable_libvorbis; +#else +const ma_decoding_backend_vtable* ma_decoding_backend_libvorbis = NULL; +#endif + #endif /* miniaudio_libvorbis_c */ diff --git a/extras/decoders/libvorbis/miniaudio_libvorbis.h b/extras/decoders/libvorbis/miniaudio_libvorbis.h index 55145748..24994fbf 100644 --- a/extras/decoders/libvorbis/miniaudio_libvorbis.h +++ b/extras/decoders/libvorbis/miniaudio_libvorbis.h @@ -33,6 +33,9 @@ MA_API ma_result ma_libvorbis_get_data_format(ma_libvorbis* pVorbis, ma_format* MA_API ma_result ma_libvorbis_get_cursor_in_pcm_frames(ma_libvorbis* pVorbis, ma_uint64* pCursor); MA_API ma_result ma_libvorbis_get_length_in_pcm_frames(ma_libvorbis* pVorbis, ma_uint64* pLength); +/* Decoding backend vtable. This is what you'll plug into ma_decoder_config.pBackendVTables. No user data required. */ +extern const ma_decoding_backend_vtable* ma_decoding_backend_libvorbis; + #ifdef __cplusplus } #endif diff --git a/miniaudio.h b/miniaudio.h index 0da25990..828124d1 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -9955,7 +9955,7 @@ typedef struct ma_allocation_callbacks allocationCallbacks; ma_encoding_format encodingFormat; ma_uint32 seekPointCount; /* When set to > 0, specifies the number of seek points to use for the generation of a seek table. Not all decoding backends support this. */ - ma_decoding_backend_vtable** ppCustomBackendVTables; + const ma_decoding_backend_vtable** ppCustomBackendVTables; ma_uint32 customBackendCount; void* pCustomBackendUserData; } ma_decoder_config; @@ -10482,7 +10482,7 @@ typedef struct ma_uint32 jobQueueCapacity; /* The maximum number of jobs that can fit in the queue at a time. Defaults to MA_JOB_TYPE_RESOURCE_MANAGER_QUEUE_CAPACITY. Cannot be zero. */ ma_uint32 flags; ma_vfs* pVFS; /* Can be NULL in which case defaults will be used. */ - ma_decoding_backend_vtable** ppCustomDecodingBackendVTables; + const ma_decoding_backend_vtable** ppCustomDecodingBackendVTables; ma_uint32 customDecodingBackendCount; void* pCustomDecodingBackendUserData; } ma_resource_manager_config; @@ -68274,8 +68274,9 @@ MA_API ma_result ma_resource_manager_init(const ma_resource_manager_config* pCon /* Custom decoding backends. */ if (pConfig->ppCustomDecodingBackendVTables != NULL && pConfig->customDecodingBackendCount > 0) { size_t sizeInBytes = sizeof(*pResourceManager->config.ppCustomDecodingBackendVTables) * pConfig->customDecodingBackendCount; + ma_decoding_backend_vtable** ppCustomDecodingBackendVTables; - pResourceManager->config.ppCustomDecodingBackendVTables = (ma_decoding_backend_vtable**)ma_malloc(sizeInBytes, &pResourceManager->config.allocationCallbacks); + ppCustomDecodingBackendVTables = (ma_decoding_backend_vtable**)ma_malloc(sizeInBytes, &pResourceManager->config.allocationCallbacks); if (pResourceManager->config.ppCustomDecodingBackendVTables == NULL) { ma_job_queue_uninit(&pResourceManager->jobQueue, &pResourceManager->config.allocationCallbacks); return MA_OUT_OF_MEMORY; @@ -68283,6 +68284,7 @@ MA_API ma_result ma_resource_manager_init(const ma_resource_manager_config* pCon MA_COPY_MEMORY(pResourceManager->config.ppCustomDecodingBackendVTables, pConfig->ppCustomDecodingBackendVTables, sizeInBytes); + pResourceManager->config.ppCustomDecodingBackendVTables = (const ma_decoding_backend_vtable**)ppCustomDecodingBackendVTables; pResourceManager->config.customDecodingBackendCount = pConfig->customDecodingBackendCount; pResourceManager->config.pCustomDecodingBackendUserData = pConfig->pCustomDecodingBackendUserData; } @@ -68386,7 +68388,7 @@ MA_API void ma_resource_manager_uninit(ma_resource_manager* pResourceManager) #endif } - ma_free(pResourceManager->config.ppCustomDecodingBackendVTables, &pResourceManager->config.allocationCallbacks); + ma_free((ma_decoding_backend_vtable**)pResourceManager->config.ppCustomDecodingBackendVTables, &pResourceManager->config.allocationCallbacks); /* <-- Naughty const-cast, but this is safe. */ if (pResourceManager->config.pLog == &pResourceManager->log) { ma_log_uninit(&pResourceManager->log);