-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #851 from edge-classic/real-reverb
Add verblib-based reverb node for Dynamic Reverb
- Loading branch information
Showing
12 changed files
with
960 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.