From 9f10bc7540582f124449536a16b0b801f68c0ad1 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 22 Feb 2025 14:25:45 +1000 Subject: [PATCH] Improvements to the build system for extra nodes. With this change, nodes in the extras folder can now be compiled as a conventional library. --- CMakeLists.txt | 27 ++++++++++++++++++- .../ma_channel_combiner_node.c | 12 ++++++--- .../ma_channel_combiner_node.h | 8 +++--- .../ma_channel_separator_node.c | 10 +++++-- .../ma_channel_separator_node.h | 8 +++--- .../ma_channel_separator_node_example.c | 3 +-- .../ma_delay_node/ma_delay_node_example.c | 3 +-- extras/nodes/ma_ltrim_node/ma_ltrim_node.c | 18 ++++++++++--- extras/nodes/ma_ltrim_node/ma_ltrim_node.h | 8 +++--- .../ma_ltrim_node/ma_ltrim_node_example.c | 3 +-- extras/nodes/ma_reverb_node/ma_reverb_node.c | 14 +++++++--- extras/nodes/ma_reverb_node/ma_reverb_node.h | 7 ++--- .../ma_reverb_node/ma_reverb_node_example.c | 3 +-- .../nodes/ma_vocoder_node/ma_vocoder_node.c | 14 +++++++--- .../nodes/ma_vocoder_node/ma_vocoder_node.h | 8 +++--- .../ma_vocoder_node/ma_vocoder_node_example.c | 3 +-- 16 files changed, 105 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 88a27341..51c61085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ option(MINIAUDIO_BUILD_EXAMPLES "Build miniaudio examples" option(MINIAUDIO_BUILD_TESTS "Build miniaudio tests" OFF) option(MINIAUDIO_FORCE_CXX "Force compilation as C++" OFF) option(MINIAUDIO_FORCE_C89 "Force compilation as C89" OFF) +option(MINIAUDIO_NO_EXTRA_NODES "Do not build extra node graph nodes" 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) @@ -457,7 +458,6 @@ add_library(miniaudio STATIC ) target_include_directories(miniaudio PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - target_compile_options (miniaudio PRIVATE ${COMPILE_OPTIONS}) target_compile_definitions(miniaudio PRIVATE ${COMPILE_DEFINES}) @@ -505,6 +505,31 @@ if(HAS_LIBOPUS) endif() +if (NOT MINIAUDIO_NO_EXTRA_NODES) + function(add_extra_node name) + add_library(miniaudio_${name}_node STATIC + extras/nodes/ma_${name}_node/ma_${name}_node.c + extras/nodes/ma_${name}_node/ma_${name}_node.h + ) + + target_include_directories(miniaudio_${name}_node PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/extras/nodes/ma_${name}_node) + target_compile_options (miniaudio_${name}_node PRIVATE ${COMPILE_OPTIONS}) + target_compile_definitions(miniaudio_${name}_node PRIVATE ${COMPILE_DEFINES}) + + if(MINIAUDIO_BUILD_EXAMPLES) + add_executable(miniaudio_${name}_node_example extras/nodes/ma_${name}_node/ma_${name}_node_example.c) + target_link_libraries(miniaudio_${name}_node_example PRIVATE miniaudio_common_options) + endif() + endfunction() + + add_extra_node(channel_combiner) + add_extra_node(channel_separator) + add_extra_node(ltrim) + add_extra_node(reverb) + add_extra_node(vocoder) +endif() + + # Interface with common options to simplify the setup of tests and examples. Note that we don't pass # in COMPILE_DEFINES here because want to allow the tests and examples to define their own defines. If # we were to use COMPILE_DEFINES here many of the tests and examples would not compile. diff --git a/extras/nodes/ma_channel_combiner_node/ma_channel_combiner_node.c b/extras/nodes/ma_channel_combiner_node/ma_channel_combiner_node.c index 6e8af997..61128243 100644 --- a/extras/nodes/ma_channel_combiner_node/ma_channel_combiner_node.c +++ b/extras/nodes/ma_channel_combiner_node/ma_channel_combiner_node.c @@ -1,11 +1,15 @@ +#ifndef miniaudio_channel_combiner_node_c +#define miniaudio_channel_combiner_node_c #include "ma_channel_combiner_node.h" +#include /* For memset(). */ + MA_API ma_channel_combiner_node_config ma_channel_combiner_node_config_init(ma_uint32 channels) { ma_channel_combiner_node_config config; - MA_ZERO_OBJECT(&config); + memset(&config, 0, sizeof(config)); config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_channel_combiner_node_init(). */ config.channels = channels; @@ -43,7 +47,7 @@ MA_API ma_result ma_channel_combiner_node_init(ma_node_graph* pNodeGraph, const return MA_INVALID_ARGS; } - MA_ZERO_OBJECT(pCombinerNode); + memset(pCombinerNode, 0, sizeof(*pCombinerNode)); if (pConfig == NULL) { return MA_INVALID_ARGS; @@ -74,4 +78,6 @@ MA_API void ma_channel_combiner_node_uninit(ma_channel_combiner_node* pCombinerN { /* The base node is always uninitialized first. */ ma_node_uninit(pCombinerNode, pAllocationCallbacks); -} \ No newline at end of file +} + +#endif /* miniaudio_channel_combiner_node_c */ diff --git a/extras/nodes/ma_channel_combiner_node/ma_channel_combiner_node.h b/extras/nodes/ma_channel_combiner_node/ma_channel_combiner_node.h index d38b824a..94ff22e1 100644 --- a/extras/nodes/ma_channel_combiner_node/ma_channel_combiner_node.h +++ b/extras/nodes/ma_channel_combiner_node/ma_channel_combiner_node.h @@ -1,6 +1,8 @@ /* Include ma_channel_combiner_node.h after miniaudio.h */ -#ifndef ma_channel_combiner_node_h -#define ma_channel_combiner_node_h +#ifndef miniaudio_channel_combiner_node_h +#define miniaudio_channel_combiner_node_h + +#include "../../../miniaudio.h" #ifdef __cplusplus extern "C" { @@ -27,4 +29,4 @@ MA_API void ma_channel_combiner_node_uninit(ma_channel_combiner_node* pSeparator #ifdef __cplusplus } #endif -#endif /* ma_reverb_node_h */ +#endif /* miniaudio_channel_combiner_node_h */ diff --git a/extras/nodes/ma_channel_separator_node/ma_channel_separator_node.c b/extras/nodes/ma_channel_separator_node/ma_channel_separator_node.c index f1d9edc8..9c67c5e4 100644 --- a/extras/nodes/ma_channel_separator_node/ma_channel_separator_node.c +++ b/extras/nodes/ma_channel_separator_node/ma_channel_separator_node.c @@ -1,11 +1,15 @@ +#ifndef miniaudio_channel_separator_node_c +#define miniaudio_channel_separator_node_c #include "ma_channel_separator_node.h" +#include /* For memset(). */ + MA_API ma_channel_separator_node_config ma_channel_separator_node_config_init(ma_uint32 channels) { ma_channel_separator_node_config config; - MA_ZERO_OBJECT(&config); + memset(&config, 0, sizeof(config)); config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_channel_separator_node_init(). */ config.channels = channels; @@ -43,7 +47,7 @@ MA_API ma_result ma_channel_separator_node_init(ma_node_graph* pNodeGraph, const return MA_INVALID_ARGS; } - MA_ZERO_OBJECT(pSeparatorNode); + memset(pSeparatorNode, 0, sizeof(*pSeparatorNode)); if (pConfig == NULL) { return MA_INVALID_ARGS; @@ -79,3 +83,5 @@ MA_API void ma_channel_separator_node_uninit(ma_channel_separator_node* pSeparat /* The base node is always uninitialized first. */ ma_node_uninit(pSeparatorNode, pAllocationCallbacks); } + +#endif /* miniaudio_channel_separator_node_c */ diff --git a/extras/nodes/ma_channel_separator_node/ma_channel_separator_node.h b/extras/nodes/ma_channel_separator_node/ma_channel_separator_node.h index 9c230a9b..dd3f8046 100644 --- a/extras/nodes/ma_channel_separator_node/ma_channel_separator_node.h +++ b/extras/nodes/ma_channel_separator_node/ma_channel_separator_node.h @@ -1,6 +1,8 @@ /* Include ma_channel_separator_node.h after miniaudio.h */ -#ifndef ma_channel_separator_node_h -#define ma_channel_separator_node_h +#ifndef miniaudio_channel_separator_node_h +#define miniaudio_channel_separator_node_h + +#include "../../../miniaudio.h" #ifdef __cplusplus extern "C" { @@ -26,4 +28,4 @@ MA_API void ma_channel_separator_node_uninit(ma_channel_separator_node* pSeparat #ifdef __cplusplus } #endif -#endif /* ma_reverb_node_h */ +#endif /* miniaudio_channel_separator_node_h */ diff --git a/extras/nodes/ma_channel_separator_node/ma_channel_separator_node_example.c b/extras/nodes/ma_channel_separator_node/ma_channel_separator_node_example.c index de416481..00953275 100644 --- a/extras/nodes/ma_channel_separator_node/ma_channel_separator_node_example.c +++ b/extras/nodes/ma_channel_separator_node/ma_channel_separator_node_example.c @@ -1,5 +1,4 @@ -#define MINIAUDIO_IMPLEMENTATION -#include "../../../miniaudio.h" +#include "../../../miniaudio.c" #include "ma_channel_separator_node.c" #include "../ma_channel_combiner_node/ma_channel_combiner_node.c" diff --git a/extras/nodes/ma_delay_node/ma_delay_node_example.c b/extras/nodes/ma_delay_node/ma_delay_node_example.c index 6f102c81..740eedd9 100644 --- a/extras/nodes/ma_delay_node/ma_delay_node_example.c +++ b/extras/nodes/ma_delay_node/ma_delay_node_example.c @@ -1,6 +1,5 @@ -#define MINIAUDIO_IMPLEMENTATION -#include "../../../miniaudio.h" +#include "../../../miniaudio.c" #include diff --git a/extras/nodes/ma_ltrim_node/ma_ltrim_node.c b/extras/nodes/ma_ltrim_node/ma_ltrim_node.c index 64aae373..5698d95c 100644 --- a/extras/nodes/ma_ltrim_node/ma_ltrim_node.c +++ b/extras/nodes/ma_ltrim_node/ma_ltrim_node.c @@ -1,11 +1,19 @@ +#ifndef miniaudio_ltrim_node_c +#define miniaudio_ltrim_node_c #include "ma_ltrim_node.h" +#include /* For memset(). */ + +#ifndef ma_min +#define ma_min(a, b) (((a) < (b)) ? (a) : (b)) +#endif + MA_API ma_ltrim_node_config ma_ltrim_node_config_init(ma_uint32 channels, float threshold) { ma_ltrim_node_config config; - MA_ZERO_OBJECT(&config); + memset(&config, 0, sizeof(config)); config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_ltrim_node_init(). */ config.channels = channels; config.threshold = threshold; @@ -59,8 +67,8 @@ static ma_node_vtable g_ma_ltrim_node_vtable = { ma_ltrim_node_process_pcm_frames, NULL, - 1, /* 1 input channel. */ - 1, /* 1 output channel. */ + 1, /* 1 input bus. */ + 1, /* 1 output bus. */ MA_NODE_FLAG_DIFFERENT_PROCESSING_RATES }; @@ -73,7 +81,7 @@ MA_API ma_result ma_ltrim_node_init(ma_node_graph* pNodeGraph, const ma_ltrim_no return MA_INVALID_ARGS; } - MA_ZERO_OBJECT(pTrimNode); + memset(pTrimNode, 0, sizeof(*pTrimNode)); if (pConfig == NULL) { return MA_INVALID_ARGS; @@ -100,3 +108,5 @@ MA_API void ma_ltrim_node_uninit(ma_ltrim_node* pTrimNode, const ma_allocation_c /* The base node is always uninitialized first. */ ma_node_uninit(pTrimNode, pAllocationCallbacks); } + +#endif /* miniaudio_ltrim_node_c */ diff --git a/extras/nodes/ma_ltrim_node/ma_ltrim_node.h b/extras/nodes/ma_ltrim_node/ma_ltrim_node.h index 2dddd3a7..2fea45ce 100644 --- a/extras/nodes/ma_ltrim_node/ma_ltrim_node.h +++ b/extras/nodes/ma_ltrim_node/ma_ltrim_node.h @@ -1,6 +1,8 @@ /* Include ma_ltrim_node.h after miniaudio.h */ -#ifndef ma_ltrim_node_h -#define ma_ltrim_node_h +#ifndef miniaudio_ltrim_node_h +#define miniaudio_ltrim_node_h + +#include "../../../miniaudio.h" #ifdef __cplusplus extern "C" { @@ -32,4 +34,4 @@ MA_API void ma_ltrim_node_uninit(ma_ltrim_node* pTrimNode, const ma_allocation_c #ifdef __cplusplus } #endif -#endif /* ma_ltrim_node_h */ +#endif /* miniaudio_ltrim_node_h */ diff --git a/extras/nodes/ma_ltrim_node/ma_ltrim_node_example.c b/extras/nodes/ma_ltrim_node/ma_ltrim_node_example.c index 0bae166d..81b9ca87 100644 --- a/extras/nodes/ma_ltrim_node/ma_ltrim_node_example.c +++ b/extras/nodes/ma_ltrim_node/ma_ltrim_node_example.c @@ -1,5 +1,4 @@ -#define MINIAUDIO_IMPLEMENTATION -#include "../../../miniaudio.h" +#include "../../../miniaudio.c" #include "ma_ltrim_node.c" #include diff --git a/extras/nodes/ma_reverb_node/ma_reverb_node.c b/extras/nodes/ma_reverb_node/ma_reverb_node.c index 5c214d6c..f67b9f51 100644 --- a/extras/nodes/ma_reverb_node/ma_reverb_node.c +++ b/extras/nodes/ma_reverb_node/ma_reverb_node.c @@ -1,12 +1,16 @@ +#ifndef miniaudio_reverb_node_c +#define miniaudio_reverb_node_c #define VERBLIB_IMPLEMENTATION #include "ma_reverb_node.h" +#include /* For memset(). */ + MA_API ma_reverb_node_config ma_reverb_node_config_init(ma_uint32 channels, ma_uint32 sampleRate) { ma_reverb_node_config config; - MA_ZERO_OBJECT(&config); + memset(&config, 0, sizeof(config)); config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_reverb_node_init(). */ config.channels = channels; config.sampleRate = sampleRate; @@ -34,8 +38,8 @@ static ma_node_vtable g_ma_reverb_node_vtable = { ma_reverb_node_process_pcm_frames, NULL, - 1, /* 1 input channel. */ - 1, /* 1 output channel. */ + 1, /* 1 input bus. */ + 1, /* 1 output bus. */ MA_NODE_FLAG_CONTINUOUS_PROCESSING /* Reverb requires continuous processing to ensure the tail get's processed. */ }; @@ -48,7 +52,7 @@ MA_API ma_result ma_reverb_node_init(ma_node_graph* pNodeGraph, const ma_reverb_ return MA_INVALID_ARGS; } - MA_ZERO_OBJECT(pReverbNode); + memset(pReverbNode, 0, sizeof(*pReverbNode)); if (pConfig == NULL) { return MA_INVALID_ARGS; @@ -76,3 +80,5 @@ MA_API void ma_reverb_node_uninit(ma_reverb_node* pReverbNode, const ma_allocati /* The base node is always uninitialized first. */ ma_node_uninit(pReverbNode, pAllocationCallbacks); } + +#endif /* miniaudio_reverb_node_c */ diff --git a/extras/nodes/ma_reverb_node/ma_reverb_node.h b/extras/nodes/ma_reverb_node/ma_reverb_node.h index 80370fbd..4df6a725 100644 --- a/extras/nodes/ma_reverb_node/ma_reverb_node.h +++ b/extras/nodes/ma_reverb_node/ma_reverb_node.h @@ -1,7 +1,8 @@ /* Include ma_reverb_node.h after miniaudio.h */ -#ifndef ma_reverb_node_h -#define ma_reverb_node_h +#ifndef miniaudio_reverb_node_h +#define miniaudio_reverb_node_h +#include "../../../miniaudio.h" #include "verblib.h" #ifdef __cplusplus @@ -39,4 +40,4 @@ MA_API void ma_reverb_node_uninit(ma_reverb_node* pReverbNode, const ma_allocati #ifdef __cplusplus } #endif -#endif /* ma_reverb_node_h */ +#endif /* miniaudio_reverb_node_h */ diff --git a/extras/nodes/ma_reverb_node/ma_reverb_node_example.c b/extras/nodes/ma_reverb_node/ma_reverb_node_example.c index 5102ab07..5827641f 100644 --- a/extras/nodes/ma_reverb_node/ma_reverb_node_example.c +++ b/extras/nodes/ma_reverb_node/ma_reverb_node_example.c @@ -1,5 +1,4 @@ -#define MINIAUDIO_IMPLEMENTATION -#include "../../../miniaudio.h" +#include "../../../miniaudio.c" #include "ma_reverb_node.c" #include diff --git a/extras/nodes/ma_vocoder_node/ma_vocoder_node.c b/extras/nodes/ma_vocoder_node/ma_vocoder_node.c index 32462bb7..21c7268b 100644 --- a/extras/nodes/ma_vocoder_node/ma_vocoder_node.c +++ b/extras/nodes/ma_vocoder_node/ma_vocoder_node.c @@ -1,12 +1,16 @@ +#ifndef miniaudio_vocoder_node_c +#define miniaudio_vocoder_node_c #define VOCLIB_IMPLEMENTATION #include "ma_vocoder_node.h" +#include /* For memset(). */ + MA_API ma_vocoder_node_config ma_vocoder_node_config_init(ma_uint32 channels, ma_uint32 sampleRate) { ma_vocoder_node_config config; - MA_ZERO_OBJECT(&config); + memset(&config, 0, sizeof(config)); config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_vocoder_node_init(). */ config.channels = channels; config.sampleRate = sampleRate; @@ -30,8 +34,8 @@ static ma_node_vtable g_ma_vocoder_node_vtable = { ma_vocoder_node_process_pcm_frames, NULL, - 2, /* 2 input channels. */ - 1, /* 1 output channel. */ + 2, /* 2 input buses. */ + 1, /* 1 output bus. */ 0 }; @@ -46,7 +50,7 @@ MA_API ma_result ma_vocoder_node_init(ma_node_graph* pNodeGraph, const ma_vocode return MA_INVALID_ARGS; } - MA_ZERO_OBJECT(pVocoderNode); + memset(pVocoderNode, 0, sizeof(*pVocoderNode)); if (pConfig == NULL) { return MA_INVALID_ARGS; @@ -78,3 +82,5 @@ MA_API void ma_vocoder_node_uninit(ma_vocoder_node* pVocoderNode, const ma_alloc /* The base node must always be initialized first. */ ma_node_uninit(pVocoderNode, pAllocationCallbacks); } + +#endif /* miniaudio_vocoder_node_c */ diff --git a/extras/nodes/ma_vocoder_node/ma_vocoder_node.h b/extras/nodes/ma_vocoder_node/ma_vocoder_node.h index 12d232fe..23af4798 100644 --- a/extras/nodes/ma_vocoder_node/ma_vocoder_node.h +++ b/extras/nodes/ma_vocoder_node/ma_vocoder_node.h @@ -1,14 +1,14 @@ /* Include ma_vocoder_node.h after miniaudio.h */ -#ifndef ma_vocoder_node_h -#define ma_vocoder_node_h +#ifndef miniaudio_vocoder_node_h +#define miniaudio_vocoder_node_h +#include "../../../miniaudio.h" #include "voclib.h" #ifdef __cplusplus extern "C" { #endif - /* The vocoder node has two inputs and one output. Inputs: @@ -42,4 +42,4 @@ MA_API void ma_vocoder_node_uninit(ma_vocoder_node* pVocoderNode, const ma_alloc #ifdef __cplusplus } #endif -#endif /* ma_vocoder_node_h */ +#endif /* miniaudio_vocoder_node_h */ diff --git a/extras/nodes/ma_vocoder_node/ma_vocoder_node_example.c b/extras/nodes/ma_vocoder_node/ma_vocoder_node_example.c index 9e501005..1d29d011 100644 --- a/extras/nodes/ma_vocoder_node/ma_vocoder_node_example.c +++ b/extras/nodes/ma_vocoder_node/ma_vocoder_node_example.c @@ -6,8 +6,7 @@ called `ma_vocoder_node` is used to achieve the effect which can be found in the the miniaudio repository. The vocoder node uses https://github.com/blastbay/voclib to achieve the effect. */ -#define MINIAUDIO_IMPLEMENTATION -#include "../../../miniaudio.h" +#include "../../../miniaudio.c" #include "ma_vocoder_node.c" #include