Skip to content

Commit

Permalink
Merge pull request #851 from edge-classic/real-reverb
Browse files Browse the repository at this point in the history
Add verblib-based reverb node for Dynamic Reverb
  • Loading branch information
dashodanger authored Jan 20, 2025
2 parents 44dbebd + b698f2c commit 4b91ded
Show file tree
Hide file tree
Showing 12 changed files with 960 additions and 30 deletions.
76 changes: 76 additions & 0 deletions libraries/miniaudio/ma_reverb_node.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "ma_reverb_node.h"

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);
config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_reverb_node_init(). */
config.channels = channels;
config.sampleRate = sampleRate;
config.roomSize = verblib_initialroom;
config.damping = verblib_initialdamp;
config.width = verblib_initialwidth;
config.wetVolume = verblib_initialwet;
config.dryVolume = verblib_initialdry;
config.mode = verblib_initialmode;

return config;
}


static void ma_reverb_node_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut)
{
ma_reverb_node* pReverbNode = (ma_reverb_node*)pNode;

(void)pFrameCountIn;

verblib_process(&pReverbNode->reverb, ppFramesIn[0], ppFramesOut[0], *pFrameCountOut);
}

static ma_node_vtable g_ma_reverb_node_vtable =
{
ma_reverb_node_process_pcm_frames,
NULL,
1, /* 1 input channel. */
1, /* 1 output channel. */
MA_NODE_FLAG_CONTINUOUS_PROCESSING /* Reverb requires continuous processing to ensure the tail get's processed. */
};

MA_API ma_result ma_reverb_node_init(ma_node_graph* pNodeGraph, const ma_reverb_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_reverb_node* pReverbNode)
{
ma_result result;
ma_node_config baseConfig;

if (pReverbNode == NULL) {
return MA_INVALID_ARGS;
}

MA_ZERO_OBJECT(pReverbNode);

if (pConfig == NULL) {
return MA_INVALID_ARGS;
}

if (verblib_initialize(&pReverbNode->reverb, (unsigned long)pConfig->sampleRate, (unsigned int)pConfig->channels) == 0) {
return MA_INVALID_ARGS;
}

baseConfig = pConfig->nodeConfig;
baseConfig.vtable = &g_ma_reverb_node_vtable;
baseConfig.pInputChannels = &pConfig->channels;
baseConfig.pOutputChannels = &pConfig->channels;

result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pReverbNode->baseNode);
if (result != MA_SUCCESS) {
return result;
}

return MA_SUCCESS;
}

MA_API void ma_reverb_node_uninit(ma_reverb_node* pReverbNode, const ma_allocation_callbacks* pAllocationCallbacks)
{
/* The base node is always uninitialized first. */
ma_node_uninit(pReverbNode, pAllocationCallbacks);
}
42 changes: 42 additions & 0 deletions libraries/miniaudio/ma_reverb_node.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Include ma_reverb_node.h after miniaudio.h */
#ifndef ma_reverb_node_h
#define ma_reverb_node_h

#include "verblib.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
The reverb node has one input and one output.
*/
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. */
ma_uint32 sampleRate;
float roomSize;
float damping;
float width;
float wetVolume;
float dryVolume;
float mode;
} ma_reverb_node_config;

MA_API ma_reverb_node_config ma_reverb_node_config_init(ma_uint32 channels, ma_uint32 sampleRate);


typedef struct
{
ma_node_base baseNode;
verblib reverb;
} ma_reverb_node;

MA_API ma_result ma_reverb_node_init(ma_node_graph* pNodeGraph, const ma_reverb_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_reverb_node* pReverbNode);
MA_API void ma_reverb_node_uninit(ma_reverb_node* pReverbNode, const ma_allocation_callbacks* pAllocationCallbacks);

#ifdef __cplusplus
}
#endif
#endif /* ma_reverb_node_h */
4 changes: 3 additions & 1 deletion libraries/miniaudio/miniaudio.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
// We use our own custom minivorbis decoder
#define MA_NO_VORBIS
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"
#include "miniaudio.h"
#define VERBLIB_IMPLEMENTATION
#include "ma_reverb_node.cc"
Loading

0 comments on commit 4b91ded

Please sign in to comment.