From fa84240364daab8cbb5fa8b23d938922c03f735c Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 9 Sep 2025 17:27:25 +1000 Subject: [PATCH 1/3] Fix a typo. --- miniaudio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 5be4e1ac..174aa686 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -11286,7 +11286,7 @@ typedef struct ma_log* pLog; /* When set to NULL, will use the context's log. */ ma_uint32 listenerCount; /* Must be between 1 and MA_ENGINE_MAX_LISTENERS. */ ma_uint32 channels; /* The number of channels to use when mixing and spatializing. When set to 0, will use the native channel count of the device. */ - ma_uint32 sampleRate; /* The sample rate. When set to 0 will use the native channel count of the device. */ + ma_uint32 sampleRate; /* The sample rate. When set to 0 will use the native sample rate of the device. */ ma_uint32 periodSizeInFrames; /* If set to something other than 0, updates will always be exactly this size. The underlying device may be a different size, but from the perspective of the mixer that won't matter.*/ ma_uint32 periodSizeInMilliseconds; /* Used if periodSizeInFrames is unset. */ ma_uint32 gainSmoothTimeInFrames; /* The number of frames to interpolate the gain of spatialized sounds across. If set to 0, will use gainSmoothTimeInMilliseconds. */ From 9e1f02b12a5dc54c38321370407ae6b80569ec19 Mon Sep 17 00:00:00 2001 From: spevnev Date: Tue, 9 Sep 2025 09:27:27 -0400 Subject: [PATCH 2/3] Fix unsigned offset overflow --- miniaudio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 174aa686..b4dd06b7 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -69310,7 +69310,7 @@ static MA_INLINE ma_uint32 ma_hash_getblock(const ma_uint32* blocks, int i) ma_uint32 block; /* Try silencing a sanitization warning about unaligned access by doing a memcpy() instead of assignment. */ - MA_COPY_MEMORY(&block, ma_offset_ptr(blocks, i * sizeof(block)), sizeof(block)); + MA_COPY_MEMORY(&block, ma_offset_ptr(blocks, i * (int) sizeof(block)), sizeof(block)); if (ma_is_little_endian()) { return block; From b306c6a2705429c158d0127f84b21d30732f0ef2 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 10 Sep 2025 09:51:13 +1000 Subject: [PATCH 3/3] Use pkg-config for libvorbis and libopus detection. --- CMakeLists.txt | 72 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab9f7581..e31c6c59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,15 +345,21 @@ endfunction() # vorbisfile # # The vorbisfile target is required for miniaudio_libvorbis. If the vorbisfile target has already been -# defined we'll just use that. Otherwise we'll try to find_library(). If that fails, as a last resort +# defined we'll just use that. Otherwise we'll try to use pkg-config. If that fails, as a last resort # we'll allow building it from source from the external/vorbis directory. if(NOT MINIAUDIO_NO_LIBVORBIS) if(NOT TARGET vorbisfile) - find_library(LIBVORBISFILE NAMES vorbisfile) - if(LIBVORBISFILE) - message(STATUS "Found libvorbisfile: ${LIBVORBISFILE}") + # Try pkg-config first + find_package(PkgConfig QUIET) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_VORBISFILE vorbisfile) + endif() + + if(PC_VORBISFILE_FOUND) + message(STATUS "Found vorbisfile via pkg-config: ${PC_VORBISFILE_LIBRARIES}") set(HAS_LIBVORBIS TRUE) else() + # Fallback to building from source. add_libvorbis_subdirectory() if(NOT TARGET vorbisfile) message(STATUS "libvorbisfile not found. miniaudio_libvorbis will be excluded.") @@ -369,27 +375,20 @@ endif() # opusfile # -# This is the same as vorbisfile above. +# This is the same as vorbisfile above, but for opusfile. if(NOT MINIAUDIO_NO_LIBOPUS) if(NOT TARGET opusfile) - find_library(LIBOPUSFILE NAMES opusfile) - if(LIBOPUSFILE) - message(STATUS "Found libopusfile: ${LIBOPUSFILE}") + # Try pkg-config first + find_package(PkgConfig QUIET) + if(PKG_CONFIG_FOUND) + pkg_check_modules(PC_OPUSFILE opusfile) + endif() - # opusfile is very annoying because they do "#include " in opusfile.h which results - # in an error unless we explicitly add the include path to the opus include directory. - find_path(OPUSFILE_INCLUDE_DIR - NAMES opus/opusfile.h - DOC "Directory containing opusfile.h" - ) - - if(OPUSFILE_INCLUDE_DIR) - message(STATUS "Found opusfile.h in ${OPUSFILE_INCLUDE_DIR}") - set(HAS_LIBOPUS TRUE) - else() - message(STATUS "Could not find opusfile.h. miniaudio_libopus will be excluded.") - endif() + if(PC_OPUSFILE_FOUND) + message(STATUS "Found opusfile via pkg-config: ${PC_OPUSFILE_LIBRARIES}") + set(HAS_LIBOPUS TRUE) else() + # Fallback to building from source. add_libopusfile_subdirectory() if(NOT TARGET opusfile) message(STATUS "libopusfile not found. miniaudio_libopus will be excluded.") @@ -519,8 +518,11 @@ add_library(libvorbis_interface INTERFACE) if(HAS_LIBVORBIS) if(TARGET vorbisfile) target_link_libraries(libvorbis_interface INTERFACE vorbisfile) - else() - target_link_libraries(libvorbis_interface INTERFACE ${LIBVORBISFILE}) + elseif(PC_VORBISFILE_FOUND) + target_link_libraries (libvorbis_interface INTERFACE ${PC_VORBISFILE_LIBRARIES}) + target_include_directories(libvorbis_interface INTERFACE ${PC_VORBISFILE_INCLUDE_DIRS}) + target_link_directories (libvorbis_interface INTERFACE ${PC_VORBISFILE_LIBRARY_DIRS}) + target_compile_options (libvorbis_interface INTERFACE ${PC_VORBISFILE_CFLAGS_OTHER}) endif() endif() @@ -543,9 +545,11 @@ add_library(libopus_interface INTERFACE) if(HAS_LIBOPUS) if(TARGET opusfile) target_link_libraries (libopus_interface INTERFACE opusfile) - else() - target_link_libraries (libopus_interface INTERFACE ${LIBOPUSFILE}) - target_include_directories(libopus_interface INTERFACE ${OPUSFILE_INCLUDE_DIR}/opus) + elseif(PC_OPUSFILE_FOUND) + target_link_libraries (libopus_interface INTERFACE ${PC_OPUSFILE_LIBRARIES}) + target_include_directories(libopus_interface INTERFACE ${PC_OPUSFILE_INCLUDE_DIRS}) + target_link_directories (libopus_interface INTERFACE ${PC_OPUSFILE_LIBRARY_DIRS}) + target_compile_options (libopus_interface INTERFACE ${PC_OPUSFILE_CFLAGS_OTHER}) endif() endif() @@ -819,6 +823,22 @@ else() endif() string(JOIN ", " MINIAUDIO_PC_REQUIRES_PRIVATE ${LINKED_LIBS}) + +# Add vorbisfile and opusfile to pkg-config dependencies if found via pkg-config +set(PC_REQUIRES_PRIVATE_LIST) +if(PC_VORBISFILE_FOUND AND HAS_LIBVORBIS) + list(APPEND PC_REQUIRES_PRIVATE_LIST "vorbisfile") +endif() +if(PC_OPUSFILE_FOUND AND HAS_LIBOPUS) + list(APPEND PC_REQUIRES_PRIVATE_LIST "opusfile") +endif() +if(PC_REQUIRES_PRIVATE_LIST) + if(MINIAUDIO_PC_REQUIRES_PRIVATE) + string(APPEND MINIAUDIO_PC_REQUIRES_PRIVATE ", ") + endif() + string(JOIN ", " PC_REQUIRES_STR ${PC_REQUIRES_PRIVATE_LIST}) + string(APPEND MINIAUDIO_PC_REQUIRES_PRIVATE "${PC_REQUIRES_STR}") +endif() list(TRANSFORM COMMON_LINK_LIBRARIES PREPEND "-l") string(JOIN " " MINIAUDIO_PC_LIBS_PRIVATE ${COMMON_LINK_LIBRARIES}) list(TRANSFORM COMPILE_DEFINES PREPEND "-D")