mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-24 09:14:04 +02:00
Relax restrictions on the maximum input and output buses for nodes.
Previously this was restricted to 2 input buses and 2 output buses, but this has been lifted to 254. When the number exceeds 2, internal data structures will be allocated on the heap, otherwise they'll use a local array contained within the ma_node structure. This commit changes the node configuration. Previously there was a fixed sized array for specifying the channel counts for each bus. This array must now be defined outside of the config by the caller. The following config variables have been renamed: * inputChannels > pInputChannels * outputChannels > pOutputChannels This commit also adds the ability to configure input and output bus counts on a per-instance basis rather than via the node vtable. To do this, set the bus count in the vtable to MA_NODE_BUS_COUNT_UNKNOWN. This will tell miniaudio to look at the node config to determine the bus count rather than the vtable. It's an error to specify this in the node config if the vtable specifies anything other than MA_NODE_BUS_COUNT_UNKNOWN.
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
|
||||
#include "ma_channel_combiner_node.h"
|
||||
|
||||
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);
|
||||
config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_channel_combiner_node_init(). */
|
||||
config.channels = channels;
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
static void ma_channel_combiner_node_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut)
|
||||
{
|
||||
ma_channel_combiner_node* pCombinerNode = (ma_channel_combiner_node*)pNode;
|
||||
|
||||
(void)pFrameCountIn;
|
||||
|
||||
ma_interleave_pcm_frames(ma_format_f32, ma_node_get_output_channels(pCombinerNode, 0), *pFrameCountOut, (const void**)ppFramesIn, (void*)ppFramesOut[0]);
|
||||
}
|
||||
|
||||
static ma_node_vtable g_ma_channel_combiner_node_vtable =
|
||||
{
|
||||
ma_channel_combiner_node_process_pcm_frames,
|
||||
NULL,
|
||||
MA_NODE_BUS_COUNT_UNKNOWN, /* Input bus count is determined by the channel count and is unknown until the node instance is initialized. */
|
||||
1, /* 1 output bus. */
|
||||
0 /* Default flags. */
|
||||
};
|
||||
|
||||
MA_API ma_result ma_channel_combiner_node_init(ma_node_graph* pNodeGraph, const ma_channel_combiner_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_channel_combiner_node* pCombinerNode)
|
||||
{
|
||||
ma_result result;
|
||||
ma_node_config baseConfig;
|
||||
ma_uint32 inputChannels[MA_MAX_NODE_BUS_COUNT];
|
||||
ma_uint32 outputChannels[1];
|
||||
ma_uint32 iChannel;
|
||||
|
||||
if (pCombinerNode == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
MA_ZERO_OBJECT(pCombinerNode);
|
||||
|
||||
if (pConfig == NULL) {
|
||||
return MA_INVALID_ARGS;
|
||||
}
|
||||
|
||||
/* All input channels are mono. */
|
||||
for (iChannel = 0; iChannel < pConfig->channels; iChannel += 1) {
|
||||
inputChannels[iChannel] = 1;
|
||||
}
|
||||
|
||||
outputChannels[0] = pConfig->channels;
|
||||
|
||||
baseConfig = pConfig->nodeConfig;
|
||||
baseConfig.vtable = &g_ma_channel_combiner_node_vtable;
|
||||
baseConfig.inputBusCount = pConfig->channels; /* The vtable has an unknown channel count, so must specify it here. */
|
||||
baseConfig.pInputChannels = inputChannels;
|
||||
baseConfig.pOutputChannels = outputChannels;
|
||||
|
||||
result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pCombinerNode->baseNode);
|
||||
if (result != MA_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return MA_SUCCESS;
|
||||
}
|
||||
|
||||
MA_API void ma_channel_combiner_node_uninit(ma_channel_combiner_node* pCombinerNode, const ma_allocation_callbacks* pAllocationCallbacks)
|
||||
{
|
||||
/* The base node is always uninitialized first. */
|
||||
ma_node_uninit(pCombinerNode, pAllocationCallbacks);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Include ma_reverb_node.h after miniaudio.h */
|
||||
#ifndef ma_channel_combiner_node_h
|
||||
#define ma_channel_combiner_node_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ma_node_config nodeConfig;
|
||||
ma_uint32 channels; /* The number of channels of the source, which will be the same as the output. Must be 1 or 2. The excite bus must always have one channel. */
|
||||
} ma_channel_combiner_node_config;
|
||||
|
||||
MA_API ma_channel_combiner_node_config ma_channel_combiner_node_config_init(ma_uint32 channels);
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ma_node_base baseNode;
|
||||
} ma_channel_combiner_node;
|
||||
|
||||
MA_API ma_result ma_channel_combiner_node_init(ma_node_graph* pNodeGraph, const ma_channel_combiner_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_channel_combiner_node* pSeparatorNode);
|
||||
MA_API void ma_channel_combiner_node_uninit(ma_channel_combiner_node* pSeparatorNode, const ma_allocation_callbacks* pAllocationCallbacks);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* ma_reverb_node_h */
|
||||
@@ -0,0 +1,2 @@
|
||||
/* The channel separtor example also demonstrates how to use the combiner. */
|
||||
#include "../ma_channel_separator_node/ma_channel_separator_node_example.c"
|
||||
Reference in New Issue
Block a user