Skip to content

Commit 52a6938

Browse files
committed
Merge branch 'origin/dev-0.12' into copilot/fix-d286572c-2e52-44f1-89d1-d2c5a0240531
2 parents 42a040d + c366358 commit 52a6938

File tree

12 files changed

+188
-221
lines changed

12 files changed

+188
-221
lines changed

CMakeLists.txt

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -462,18 +462,28 @@ set(COMMON_LINK_LIBRARIES)
462462
if (UNIX)
463463
if(NOT MINIAUDIO_NO_RUNTIME_LINKING)
464464
# Not all platforms actually use a separate "dl" library, notably NetBSD and OpenBSD.
465-
find_library(LIB_DL "dl")
465+
find_library(LIB_DL NAMES dl)
466466
if(LIB_DL)
467-
list(APPEND COMMON_LINK_LIBRARIES dl) # For dlopen(), etc. Most compilers will link to this by default, but some may not.
467+
list(APPEND COMMON_LINK_LIBRARIES ${LIB_DL}) # For dlopen(), etc. Most compilers will link to this by default, but some may not.
468468
endif()
469469
endif()
470+
471+
find_library(LIB_PTHREAD NAMES pthread)
472+
if(LIB_PTHREAD)
473+
list(APPEND COMMON_LINK_LIBRARIES pthread) # Some compilers will not link to pthread by default so list it here just in case.
474+
endif()
470475

471-
list(APPEND COMMON_LINK_LIBRARIES pthread) # Some compilers will not link to pthread by default so list it here just in case.
472-
list(APPEND COMMON_LINK_LIBRARIES m)
476+
find_library(LIB_M NAMES m)
477+
if(LIB_M)
478+
list(APPEND COMMON_LINK_LIBRARIES m)
479+
endif()
473480

474481
# If we're compiling for 32-bit ARM we need to link to -latomic.
475482
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
476-
list(APPEND COMMON_LINK_LIBRARIES atomic)
483+
find_library(LIB_ATOMIC NAMES atomic)
484+
if(LIB_ATOMIC)
485+
list(APPEND COMMON_LINK_LIBRARIES ${LIB_ATOMIC})
486+
endif()
477487
endif()
478488
endif()
479489

@@ -578,7 +588,7 @@ if(NOT MINIAUDIO_NO_EXTRA_NODES)
578588

579589
if(MINIAUDIO_BUILD_EXAMPLES)
580590
add_executable(miniaudio_${name}_node_example extras/nodes/ma_${name}_node/ma_${name}_node_example.c)
581-
target_link_libraries(miniaudio_${name}_node_example PRIVATE miniaudio_common_options)
591+
target_link_libraries(miniaudio_${name}_node_example PRIVATE miniaudio_example)
582592
endif()
583593
endfunction()
584594

@@ -590,12 +600,18 @@ if(NOT MINIAUDIO_NO_EXTRA_NODES)
590600
endif()
591601

592602

593-
# Interface with common options to simplify the setup of tests and examples. Note that we don't pass
594-
# in COMPILE_DEFINES here because want to allow the tests and examples to define their own defines. If
595-
# we were to use COMPILE_DEFINES here many of the tests and examples would not compile.
596-
add_library(miniaudio_common_options INTERFACE)
597-
target_compile_options(miniaudio_common_options INTERFACE ${COMPILE_OPTIONS})
598-
target_link_libraries (miniaudio_common_options INTERFACE ${COMMON_LINK_LIBRARIES})
603+
# Interface for examples. Examples do not include COMPILE_OPTIONS because when compiling with things
604+
# like MINIAUDIO_FORCE_C89, etc. it could sometimes result in warnings which would make automated
605+
# build tools have unnecessarily messy output. Working around these errors would require us modifying
606+
# the examples in ways where it would negatively affect its readablity.
607+
add_library(miniaudio_example INTERFACE)
608+
target_link_libraries (miniaudio_example INTERFACE ${COMMON_LINK_LIBRARIES})
609+
610+
# Interface for tests. This includes our COMPILE_OPTIONS settings because we want tests to check for
611+
# build errors with MINIAUDIO_FORCE_C89, etc.
612+
add_library(miniaudio_test INTERFACE)
613+
target_compile_options(miniaudio_test INTERFACE ${COMPILE_OPTIONS})
614+
target_link_libraries (miniaudio_test INTERFACE ${COMMON_LINK_LIBRARIES})
599615

600616
# Tests
601617
#
@@ -607,22 +623,28 @@ if(MINIAUDIO_BUILD_TESTS)
607623

608624
function(add_miniaudio_test name source)
609625
add_executable(${name} ${TESTS_DIR}/${source})
610-
target_link_libraries(${name} PRIVATE miniaudio_common_options)
626+
target_link_libraries(${name} PRIVATE miniaudio_test)
611627
if(TARGET miniaudio_pipewire)
612628
target_link_libraries(${name} PRIVATE miniaudio_pipewire)
613629
target_compile_definitions(${name} PRIVATE MA_TESTS_INCLUDE_PIPEWIRE)
614630
endif()
615631
endfunction()
616632

617-
# The debugging test is only used for debugging miniaudio itself. Don't do add_test() for this, and do not include it in in any automated testing.
618-
add_miniaudio_test(miniaudio_debugging debugging/debugging.cpp)
633+
# Disable C++ tests when forcing C89. This is needed because we'll be passing -std=c89 which will cause errors when trying to compile a C++ file.
634+
if(NOT MINIAUDIO_FORCE_C89)
635+
# The debugging test is only used for debugging miniaudio itself. Don't do add_test() for this, and do not include it in in any automated testing.
636+
add_miniaudio_test(miniaudio_debugging debugging/debugging.cpp)
637+
638+
add_miniaudio_test(miniaudio_cpp cpp/cpp.cpp)
639+
add_test(NAME miniaudio_cpp COMMAND miniaudio_cpp --auto) # This is just the deviceio test.
640+
endif()
619641

620642
add_miniaudio_test(miniaudio_deviceio deviceio/deviceio.c)
643+
if(CMAKE_CXX_COMPILER_ID STREQUAL "Emscripten")
644+
target_compile_options(miniaudio_deviceio PRIVATE --use-port=sdl2)
645+
endif()
621646
add_test(NAME miniaudio_deviceio COMMAND miniaudio_deviceio --auto)
622647

623-
add_miniaudio_test(miniaudio_cpp cpp/cpp.cpp)
624-
add_test(NAME miniaudio_cpp COMMAND miniaudio_cpp --auto) # This is just the deviceio test.
625-
626648
add_miniaudio_test(miniaudio_conversion conversion/conversion.c)
627649
add_test(NAME miniaudio_conversion COMMAND miniaudio_conversion)
628650

@@ -631,15 +653,6 @@ if(MINIAUDIO_BUILD_TESTS)
631653

632654
add_miniaudio_test(miniaudio_generation generation/generation.c)
633655
add_test(NAME miniaudio_generation COMMAND miniaudio_generation)
634-
635-
if(NOT MINIAUDIO_NO_PIPEWIRE)
636-
add_executable (miniaudio_pipewire_test extras/backends/pipewire/miniaudio_pipewire_test.c)
637-
target_compile_options (miniaudio_pipewire_test PRIVATE ${COMPILE_OPTIONS})
638-
target_compile_definitions(miniaudio_pipewire_test PRIVATE ${COMPILE_DEFINES})
639-
target_include_directories(miniaudio_pipewire_test PRIVATE ${SPA_INCLUDE_DIR})
640-
target_link_libraries (miniaudio_pipewire_test PRIVATE ${COMMON_LINK_LIBRARIES})
641-
add_test(NAME miniaudio_pipewire_test COMMAND miniaudio_pipewire_test --auto)
642-
endif()
643656
endif()
644657

645658
# Examples
@@ -650,7 +663,7 @@ if (MINIAUDIO_BUILD_EXAMPLES)
650663

651664
function(add_miniaudio_example name source)
652665
add_executable(${name} ${EXAMPLES_DIR}/${source})
653-
target_link_libraries(${name} PRIVATE miniaudio_common_options)
666+
target_link_libraries(${name} PRIVATE miniaudio_example)
654667
endfunction()
655668

656669
add_miniaudio_example(miniaudio_custom_backend custom_backend.c)

examples/engine_sdl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ static ma_sound g_sound; /* This example will play only a single soun
2222

2323
void data_callback(void* pUserData, ma_uint8* pBuffer, int bufferSizeInBytes)
2424
{
25+
ma_uint32 bufferSizeInFrames;
26+
2527
(void)pUserData;
2628

2729
/* Reading is just a matter of reading straight from the engine. */
28-
ma_uint32 bufferSizeInFrames = (ma_uint32)bufferSizeInBytes / ma_get_bytes_per_frame(ma_format_f32, ma_engine_get_channels(&g_engine));
30+
bufferSizeInFrames = (ma_uint32)bufferSizeInBytes / ma_get_bytes_per_frame(ma_format_f32, ma_engine_get_channels(&g_engine));
2931
ma_engine_read_pcm_frames(&g_engine, pBuffer, bufferSizeInFrames, NULL);
3032
}
3133

examples/engine_steamaudio.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ of buffering solution to your node.
1717
#include "../miniaudio.c"
1818

1919
#include <stdint.h> /* Required for uint32_t which is used by STEAMAUDIO_VERSION, and a random use of uint8_t. If there's a Steam Audio maintainer reading this, that needs to be fixed to use IPLuint32 and IPLuint8. */
20+
21+
/* Need to silence some warnings from the Steam Audio headers. */
22+
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
23+
#pragma GCC diagnostic push
24+
#pragma GCC diagnostic ignored "-Wlong-long"
25+
#pragma GCC diagnostic ignored "-Wpedantic"
26+
#endif
2027
#include <phonon.h> /* Steam Audio */
28+
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
29+
#pragma GCC diagnostic pop
30+
#endif
2131

2232
#define FORMAT ma_format_f32 /* Must be floating point. */
2333
#define CHANNELS 2 /* Must be stereo for this example. */

examples/simple_spatialization.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main(int argc, char** argv)
6767
/* Rotate the listener on the spot to create an orbiting effect. */
6868
for (;;) {
6969
listenerAngle += 0.01f;
70-
ma_engine_listener_set_direction(&engine, 0, sinf(listenerAngle), 0, cosf(listenerAngle));
70+
ma_engine_listener_set_direction(&engine, 0, (float)sin(listenerAngle), 0, (float)cos(listenerAngle));
7171

7272
ma_sleep(1);
7373
}

external/fs/fs.c

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
#include "fs.h"
55

6+
/* TODO: Remove this. To replicate errors, Just comment out this _XOPEN_SOURCE section and compile with `-std=c89` on GCC. */
7+
/* This is for `-std=c89` compatibility. Without this there will be a few pthread related issues as well as some stdio functions being unavailable. They will need workarounds. */
8+
#ifndef _XOPEN_SOURCE
9+
#define _XOPEN_SOURCE 700
10+
#else
11+
#if _XOPEN_SOURCE < 500
12+
#error _XOPEN_SOURCE must be >= 500. fs is not usable.
13+
#endif
14+
#endif
15+
616
#include <errno.h>
717

818
/* BEG fs_common_macros.c */
@@ -14,8 +24,12 @@
1424
/* BEG fs_va_copy.c */
1525
#ifndef fs_va_copy
1626
#if !defined(_MSC_VER) || _MSC_VER >= 1800
17-
#if (defined(__GNUC__) && __GNUC__ < 3)
18-
#define fs_va_copy(dst, src) ((dst) = (src)) /* This is untested. Not sure if this is correct for old GCC. */
27+
#if !defined(__STDC_VERSION__) || (defined(__GNUC__) && __GNUC__ < 3) /* <-- va_copy() is not available when using `-std=c89`. The `!defined(__STDC_VERSION__)` parts is what checks for this. */
28+
#if defined(__va_copy)
29+
#define fs_va_copy(dst, src) __va_copy(dst, src)
30+
#else
31+
#define fs_va_copy(dst, src) ((dst) = (src)) /* This is untested. Not sure if this is correct for old GCC. */
32+
#endif
1933
#else
2034
#define fs_va_copy(dst, src) va_copy((dst), (src))
2135
#endif
@@ -495,14 +509,6 @@ Parameter ordering is the same as c89thread to make amalgamation easier.
495509
#if defined(_WIN32) && !defined(FS_USE_PTHREAD)
496510
/* Win32. Don't include windows.h here. */
497511
#else
498-
#ifndef _XOPEN_SOURCE
499-
#define _XOPEN_SOURCE 700
500-
#else
501-
#if _XOPEN_SOURCE < 500
502-
#error _XOPEN_SOURCE must be >= 500. c89thread is not usable.
503-
#endif
504-
#endif
505-
506512
#include <pthread.h>
507513
typedef pthread_t fs_pthread;
508514
typedef pthread_mutex_t fs_pthread_mutex;
@@ -7320,6 +7326,12 @@ logic in stb_sprintf() which we might be able to do via the amalgamator.
73207326
#define FS_SPRINTF_NOUNALIGNED
73217327
#endif
73227328

7329+
/* We'll get -Wlong-long warnings when forcing C89. Just force disable them. */
7330+
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
7331+
#pragma GCC diagnostic push
7332+
#pragma GCC diagnostic ignored "-Wlong-long"
7333+
#endif
7334+
73237335
/* We need to disable the implicit-fallthrough warning on GCC. */
73247336
#if defined(__GNUC__) && (__GNUC__ >= 7 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1))
73257337
#pragma GCC diagnostic push
@@ -8982,7 +8994,10 @@ static fs_int32 fs_real_to_str(char const* *start, fs_uint32 *len, char* out, fs
89828994
/* END stb_sprintf.c */
89838995

89848996
#if defined(__GNUC__) && (__GNUC__ >= 7 || (__GNUC__ == 6 && __GNUC_MINOR__ >= 1))
8985-
#pragma GCC diagnostic pop
8997+
#pragma GCC diagnostic pop /* Fallthrough warnings. */
8998+
#endif
8999+
#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)))
9000+
#pragma GCC diagnostic pop /* -Wlong-long */
89869001
#endif
89879002
/* END fs_snprintf.c */
89889003

extras/backends/pipewire/miniaudio_pipewire.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ which can then be stored in the backend state?
7676

7777

7878
#if defined(MA_LINUX)
79-
#define MA_SUPPORT_PIPEWIRE
79+
#if defined(__STDC_VERSION__) /* <-- PipeWire cannot be used with C89 mode (__STDC_VERSION__ is only defined starting with C90). */
80+
#define MA_SUPPORT_PIPEWIRE
81+
#endif
8082
#endif
8183

8284
#if defined(MA_SUPPORT_PIPEWIRE) && !defined(MA_NO_PIPEWIRE) && (!defined(MA_ENABLE_ONLY_SPECIFIC_BACKENDS) || defined(MA_ENABLE_PIPEWIRE))
@@ -438,6 +440,7 @@ static void ma_stream_event_param_changed__pipewire(void* pUserData, ma_uint32 i
438440
const struct spa_pod* pBufferParameters[1];
439441
ma_uint32 bufferSizeInFrames;
440442
ma_uint32 bytesPerFrame;
443+
ma_uint32 iChannel;
441444

442445
if (pDeviceStatePipeWire->isInternalFormatFinalised) {
443446
ma_log_postf(pContextStatePipeWire->pLog, MA_LOG_LEVEL_WARNING, "PipeWire format parameter changed after device has been initialized.");
@@ -456,7 +459,7 @@ static void ma_stream_event_param_changed__pipewire(void* pUserData, ma_uint32 i
456459
printf("Channels: %d\n", audioInfo.channels);
457460
printf("Rate: %d\n", audioInfo.rate);
458461
printf("Channel Map: {");
459-
for (ma_uint32 iChannel = 0; iChannel < audioInfo.channels; iChannel += 1) {
462+
for (iChannel = 0; iChannel < audioInfo.channels; iChannel += 1) {
460463
printf("%d", audioInfo.position[iChannel]);
461464
if (iChannel < audioInfo.channels - 1) {
462465
printf(", ");
@@ -529,7 +532,7 @@ static void ma_stream_event_process__pipewire(void* pUserData)
529532
return;
530533
}
531534

532-
//frameCount = (ma_uint32)ma_min(pBuffer->requested, pBuffer->buffer->datas[0].maxsize / bytesPerFrame);
535+
/*frameCount = (ma_uint32)ma_min(pBuffer->requested, pBuffer->buffer->datas[0].maxsize / bytesPerFrame);*/
533536
frameCount = (ma_uint32)(pBuffer->buffer->datas[0].maxsize / bytesPerFrame);
534537
if (frameCount > 0) {
535538
if (pStream == pDeviceStatePipeWire->pStreamPlayback) {

extras/backends/pipewire/miniaudio_pipewire.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Unfortunately PipeWire has a hard dependency on the above package, and because i
1313
entirely of non-trivial inlined code, it's not possible to avoid this dependency. It's for
1414
this reason the PipeWire backend cannot be included in miniaudio.h since it has a requirement
1515
that it does not depend on external development packages.
16+
17+
The PipeWire backend cannot be used with `-std=c89`. This is because the SPA headers do not
18+
support it.
1619
*/
1720
#ifndef miniaudio_backend_pipewire_h
1821
#define miniaudio_backend_pipewire_h

0 commit comments

Comments
 (0)