diff --git a/Release/Tests/sound_pool_test.ngt b/Release/Tests/sound_pool_test.ngt index a24307a..a905d9b 100644 --- a/Release/Tests/sound_pool_test.ngt +++ b/Release/Tests/sound_pool_test.ngt @@ -7,7 +7,7 @@ update_window_freq=0; while(!quit_requested){ wait_event(); if(key_repeat(KEY_SPACE)){ -sp.play_1d("/mnt/c/windows/media/Windows Default.wav", 0, 20, false); +sp.play_1d("c:/windows/media/Windows Default.wav", 0, 20, false); sp.update_listener_position(20, 0, 0); } } diff --git a/SRC/main.cpp b/SRC/main.cpp index da4f68d..822af4b 100644 --- a/SRC/main.cpp +++ b/SRC/main.cpp @@ -104,7 +104,9 @@ LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS* exceptionInfo) { free(symbol); alert("NGTRuntimeError", ss.str()); exit(1); + return 0; } + #else #include #include diff --git a/SRC/sound.cpp b/SRC/sound.cpp index c012e2c..ca6f298 100644 --- a/SRC/sound.cpp +++ b/SRC/sound.cpp @@ -1,4 +1,4 @@ -//NGTAUDIO +// NGTAUDIO #define NOMINMAX #include "MemoryStream.h" #include "ngt.h" @@ -16,10 +16,10 @@ using namespace std; #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h" #include /* Required for uint32_t which is used by STEAMAUDIO_VERSION. That dependency needs to be removed from Steam Audio - use IPLuint32 or "unsigned int" instead! */ -#include +#include #include "phonon.h" /* Steam Audio */ #include "pack.h" -#define FORMAT ma_format_f32 /* Must be floating point. */ +#define FORMAT ma_format_f32 /* Must be floating point. */ int SAMPLE_RATE = 44100; int CHANNELS = 2; #include "fx/freeverb.h" @@ -28,7 +28,8 @@ int CHANNELS = 2; #include "fx/verblib.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif /* @@ -37,7 +38,7 @@ extern "C" { 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 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; @@ -49,15 +50,14 @@ extern "C" { 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); + 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 } @@ -67,7 +67,7 @@ MA_API ma_reverb_node_config ma_reverb_node_config_init(ma_uint32 channels, ma_u 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.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_reverb_node_init(). */ config.channels = channels; config.channels = channels; config.sampleRate = sampleRate; @@ -81,10 +81,9 @@ MA_API ma_reverb_node_config ma_reverb_node_config_init(ma_uint32 channels, ma_u return config; } - -static void ma_reverb_node_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut) +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; + ma_reverb_node *pReverbNode = (ma_reverb_node *)pNode; (void)pFrameCountIn; @@ -92,30 +91,32 @@ static void ma_reverb_node_process_pcm_frames(ma_node* pNode, const float** ppFr } 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 -}; + { + ma_reverb_node_process_pcm_frames, + NULL, + 1, /* 1 input channel. */ + 1, /* 1 output channel. */ + MA_NODE_FLAG_CONTINUOUS_PROCESSING}; -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 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) { + if (pReverbNode == NULL) + { return MA_INVALID_ARGS; } MA_ZERO_OBJECT(pReverbNode); - if (pConfig == NULL) { + if (pConfig == NULL) + { return MA_INVALID_ARGS; } - if (verblib_initialize(&pReverbNode->reverb, (unsigned long)pConfig->sampleRate, (unsigned int)pConfig->channels) == 0) { + if (verblib_initialize(&pReverbNode->reverb, (unsigned long)pConfig->sampleRate, (unsigned int)pConfig->channels) == 0) + { return MA_INVALID_ARGS; } @@ -125,29 +126,29 @@ MA_API ma_result ma_reverb_node_init(ma_node_graph* pNodeGraph, const ma_reverb_ baseConfig.pOutputChannels = &pConfig->channels; result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pReverbNode->baseNode); - if (result != MA_SUCCESS) { + 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) +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); } - /* Include ma_vocoder_node.h after miniaudio.h */ #define VOCLIB_IMPLEMENTATION #include "fx/voclib.h" #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif - /* The vocoder node has two inputs and one output. Inputs: @@ -160,35 +161,33 @@ extern "C" { 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_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_uint32 sampleRate; - ma_uint32 bands; /* Defaults to 16. */ - ma_uint32 filtersPerBand; /* Defaults to 6. */ + ma_uint32 bands; /* Defaults to 16. */ + ma_uint32 filtersPerBand; /* Defaults to 6. */ } ma_vocoder_node_config; MA_API ma_vocoder_node_config ma_vocoder_node_config_init(ma_uint32 channels, ma_uint32 sampleRate); - typedef struct { ma_node_base baseNode; voclib_instance voclib; } ma_vocoder_node; - MA_API ma_result ma_vocoder_node_init(ma_node_graph* pNodeGraph, const ma_vocoder_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_vocoder_node* pVocoderNode); - MA_API void ma_vocoder_node_uninit(ma_vocoder_node* pVocoderNode, const ma_allocation_callbacks* pAllocationCallbacks); + MA_API ma_result ma_vocoder_node_init(ma_node_graph *pNodeGraph, const ma_vocoder_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_vocoder_node *pVocoderNode); + MA_API void ma_vocoder_node_uninit(ma_vocoder_node *pVocoderNode, const ma_allocation_callbacks *pAllocationCallbacks); #ifdef __cplusplus } #endif - 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); - config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_vocoder_node_init(). */ + config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_vocoder_node_init(). */ config.channels = channels; config.sampleRate = sampleRate; config.bands = 16; @@ -197,10 +196,9 @@ MA_API ma_vocoder_node_config ma_vocoder_node_config_init(ma_uint32 channels, ma return config; } - -static void ma_vocoder_node_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut) +static void ma_vocoder_node_process_pcm_frames(ma_node *pNode, const float **ppFramesIn, ma_uint32 *pFrameCountIn, float **ppFramesOut, ma_uint32 *pFrameCountOut) { - ma_vocoder_node* pVocoderNode = (ma_vocoder_node*)pNode; + ma_vocoder_node *pVocoderNode = (ma_vocoder_node *)pNode; (void)pFrameCountIn; @@ -208,38 +206,40 @@ static void ma_vocoder_node_process_pcm_frames(ma_node* pNode, const float** ppF } static ma_node_vtable g_ma_vocoder_node_vtable = -{ - ma_vocoder_node_process_pcm_frames, - NULL, - 2, /* 2 input channels. */ - 1, /* 1 output channel. */ - 0 -}; + { + ma_vocoder_node_process_pcm_frames, + NULL, + 2, /* 2 input channels. */ + 1, /* 1 output channel. */ + 0}; -MA_API ma_result ma_vocoder_node_init(ma_node_graph* pNodeGraph, const ma_vocoder_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_vocoder_node* pVocoderNode) +MA_API ma_result ma_vocoder_node_init(ma_node_graph *pNodeGraph, const ma_vocoder_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_vocoder_node *pVocoderNode) { ma_result result; ma_node_config baseConfig; ma_uint32 inputChannels[2]; ma_uint32 outputChannels[1]; - if (pVocoderNode == NULL) { + if (pVocoderNode == NULL) + { return MA_INVALID_ARGS; } MA_ZERO_OBJECT(pVocoderNode); - if (pConfig == NULL) { + if (pConfig == NULL) + { return MA_INVALID_ARGS; } - if (voclib_initialize(&pVocoderNode->voclib, (unsigned char)pConfig->bands, (unsigned char)pConfig->filtersPerBand, (unsigned int)pConfig->sampleRate, (unsigned char)pConfig->channels) == 0) { + if (voclib_initialize(&pVocoderNode->voclib, (unsigned char)pConfig->bands, (unsigned char)pConfig->filtersPerBand, (unsigned int)pConfig->sampleRate, (unsigned char)pConfig->channels) == 0) + { return MA_INVALID_ARGS; } - inputChannels[0] = pConfig->channels; /* Source/carrier. */ - inputChannels[1] = 1; /* Excite/modulator. Must always be single channel. */ - outputChannels[0] = pConfig->channels; /* Output channels is always the same as the source/carrier. */ + inputChannels[0] = pConfig->channels; /* Source/carrier. */ + inputChannels[1] = 1; /* Excite/modulator. Must always be single channel. */ + outputChannels[0] = pConfig->channels; /* Output channels is always the same as the source/carrier. */ baseConfig = pConfig->nodeConfig; baseConfig.vtable = &g_ma_vocoder_node_vtable; @@ -247,20 +247,22 @@ MA_API ma_result ma_vocoder_node_init(ma_node_graph* pNodeGraph, const ma_vocode baseConfig.pOutputChannels = outputChannels; result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pVocoderNode->baseNode); - if (result != MA_SUCCESS) { + if (result != MA_SUCCESS) + { return result; } return MA_SUCCESS; } -MA_API void ma_vocoder_node_uninit(ma_vocoder_node* pVocoderNode, const ma_allocation_callbacks* pAllocationCallbacks) +MA_API void ma_vocoder_node_uninit(ma_vocoder_node *pVocoderNode, const ma_allocation_callbacks *pAllocationCallbacks) { /* The base node must always be initialized first. */ ma_node_uninit(pVocoderNode, pAllocationCallbacks); } #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif /* @@ -275,7 +277,6 @@ extern "C" { MA_API ma_ltrim_node_config ma_ltrim_node_config_init(ma_uint32 channels, float threshold); - typedef struct { ma_node_base baseNode; @@ -283,8 +284,8 @@ extern "C" { ma_bool32 foundStart; } ma_ltrim_node; - MA_API ma_result ma_ltrim_node_init(ma_node_graph* pNodeGraph, const ma_ltrim_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_ltrim_node* pTrimNode); - MA_API void ma_ltrim_node_uninit(ma_ltrim_node* pTrimNode, const ma_allocation_callbacks* pAllocationCallbacks); + MA_API ma_result ma_ltrim_node_init(ma_node_graph *pNodeGraph, const ma_ltrim_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_ltrim_node *pTrimNode); + MA_API void ma_ltrim_node_uninit(ma_ltrim_node *pTrimNode, const ma_allocation_callbacks *pAllocationCallbacks); #ifdef __cplusplus } @@ -294,17 +295,16 @@ MA_API ma_ltrim_node_config ma_ltrim_node_config_init(ma_uint32 channels, float ma_ltrim_node_config config; MA_ZERO_OBJECT(&config); - config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_ltrim_node_init(). */ + config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_ltrim_node_init(). */ config.channels = channels; config.threshold = threshold; return config; } - -static void ma_ltrim_node_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut) +static void ma_ltrim_node_process_pcm_frames(ma_node *pNode, const float **ppFramesIn, ma_uint32 *pFrameCountIn, float **ppFramesOut, ma_uint32 *pFrameCountOut) { - ma_ltrim_node* pTrimNode = (ma_ltrim_node*)pNode; + ma_ltrim_node *pTrimNode = (ma_ltrim_node *)pNode; ma_uint32 framesProcessedIn = 0; ma_uint32 framesProcessedOut = 0; ma_uint32 channelCount = ma_node_get_input_channels(pNode, 0); @@ -313,21 +313,27 @@ static void ma_ltrim_node_process_pcm_frames(ma_node* pNode, const float** ppFra If we haven't yet found the start, skip over every input sample until we find a frame outside of the threshold. */ - if (pTrimNode->foundStart == MA_FALSE) { - while (framesProcessedIn < *pFrameCountIn) { + if (pTrimNode->foundStart == MA_FALSE) + { + while (framesProcessedIn < *pFrameCountIn) + { ma_uint32 iChannel = 0; - for (iChannel = 0; iChannel < channelCount; iChannel += 1) { + for (iChannel = 0; iChannel < channelCount; iChannel += 1) + { float sample = ppFramesIn[0][framesProcessedIn * channelCount + iChannel]; - if (sample < -pTrimNode->threshold || sample > pTrimNode->threshold) { + if (sample < -pTrimNode->threshold || sample > pTrimNode->threshold) + { pTrimNode->foundStart = MA_TRUE; break; } } - if (pTrimNode->foundStart) { - break; /* The start has been found. Get out of this loop and finish off processing. */ + if (pTrimNode->foundStart) + { + break; /* The start has been found. Get out of this loop and finish off processing. */ } - else { + else + { framesProcessedIn += 1; } } @@ -345,26 +351,27 @@ static void ma_ltrim_node_process_pcm_frames(ma_node* pNode, const float** ppFra } static ma_node_vtable g_ma_ltrim_node_vtable = -{ - ma_ltrim_node_process_pcm_frames, - NULL, - 1, /* 1 input channel. */ - 1, /* 1 output channel. */ - MA_NODE_FLAG_DIFFERENT_PROCESSING_RATES -}; + { + ma_ltrim_node_process_pcm_frames, + NULL, + 1, /* 1 input channel. */ + 1, /* 1 output channel. */ + MA_NODE_FLAG_DIFFERENT_PROCESSING_RATES}; -MA_API ma_result ma_ltrim_node_init(ma_node_graph* pNodeGraph, const ma_ltrim_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_ltrim_node* pTrimNode) +MA_API ma_result ma_ltrim_node_init(ma_node_graph *pNodeGraph, const ma_ltrim_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_ltrim_node *pTrimNode) { ma_result result; ma_node_config baseConfig; - if (pTrimNode == NULL) { + if (pTrimNode == NULL) + { return MA_INVALID_ARGS; } MA_ZERO_OBJECT(pTrimNode); - if (pConfig == NULL) { + if (pConfig == NULL) + { return MA_INVALID_ARGS; } @@ -377,20 +384,22 @@ MA_API ma_result ma_ltrim_node_init(ma_node_graph* pNodeGraph, const ma_ltrim_no baseConfig.pOutputChannels = &pConfig->channels; result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pTrimNode->baseNode); - if (result != MA_SUCCESS) { + if (result != MA_SUCCESS) + { return result; } return MA_SUCCESS; } -MA_API void ma_ltrim_node_uninit(ma_ltrim_node* pTrimNode, const ma_allocation_callbacks* pAllocationCallbacks) +MA_API void ma_ltrim_node_uninit(ma_ltrim_node *pTrimNode, const ma_allocation_callbacks *pAllocationCallbacks) { /* The base node is always uninitialized first. */ ma_node_uninit(pTrimNode, pAllocationCallbacks); } #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif typedef struct @@ -401,15 +410,13 @@ extern "C" { 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); - + 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 } @@ -419,32 +426,31 @@ MA_API ma_channel_combiner_node_config ma_channel_combiner_node_config_init(ma_u 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.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) +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; + 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]); + 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_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_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; @@ -452,18 +458,21 @@ MA_API ma_result ma_channel_combiner_node_init(ma_node_graph* pNodeGraph, const ma_uint32 outputChannels[1]; ma_uint32 iChannel; - if (pCombinerNode == NULL) { + if (pCombinerNode == NULL) + { return MA_INVALID_ARGS; } MA_ZERO_OBJECT(pCombinerNode); - if (pConfig == NULL) { + if (pConfig == NULL) + { return MA_INVALID_ARGS; } /* All input channels are mono. */ - for (iChannel = 0; iChannel < pConfig->channels; iChannel += 1) { + for (iChannel = 0; iChannel < pConfig->channels; iChannel += 1) + { inputChannels[iChannel] = 1; } @@ -476,20 +485,22 @@ MA_API ma_result ma_channel_combiner_node_init(ma_node_graph* pNodeGraph, const baseConfig.pOutputChannels = outputChannels; result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pCombinerNode->baseNode); - if (result != MA_SUCCESS) { + 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) +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); } #ifdef __cplusplus -extern "C" { +extern "C" +{ #endif typedef struct @@ -500,14 +511,13 @@ extern "C" { MA_API ma_channel_separator_node_config ma_channel_separator_node_config_init(ma_uint32 channels); - typedef struct { ma_node_base baseNode; } ma_channel_separator_node; - MA_API ma_result ma_channel_separator_node_init(ma_node_graph* pNodeGraph, const ma_channel_separator_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_channel_separator_node* pSeparatorNode); - MA_API void ma_channel_separator_node_uninit(ma_channel_separator_node* pSeparatorNode, const ma_allocation_callbacks* pAllocationCallbacks); + MA_API ma_result ma_channel_separator_node_init(ma_node_graph *pNodeGraph, const ma_channel_separator_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_channel_separator_node *pSeparatorNode); + MA_API void ma_channel_separator_node_uninit(ma_channel_separator_node *pSeparatorNode, const ma_allocation_callbacks *pAllocationCallbacks); #ifdef __cplusplus } @@ -517,32 +527,31 @@ MA_API ma_channel_separator_node_config ma_channel_separator_node_config_init(ma ma_channel_separator_node_config config; MA_ZERO_OBJECT(&config); - config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_channel_separator_node_init(). */ + config.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_channel_separator_node_init(). */ config.channels = channels; return config; } - -static void ma_channel_separator_node_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut) +static void ma_channel_separator_node_process_pcm_frames(ma_node *pNode, const float **ppFramesIn, ma_uint32 *pFrameCountIn, float **ppFramesOut, ma_uint32 *pFrameCountOut) { - ma_channel_separator_node* pSplitterNode = (ma_channel_separator_node*)pNode; + ma_channel_separator_node *pSplitterNode = (ma_channel_separator_node *)pNode; (void)pFrameCountIn; - ma_deinterleave_pcm_frames(ma_format_f32, ma_node_get_input_channels(pSplitterNode, 0), *pFrameCountOut, (const void*)ppFramesIn[0], (void**)ppFramesOut); + ma_deinterleave_pcm_frames(ma_format_f32, ma_node_get_input_channels(pSplitterNode, 0), *pFrameCountOut, (const void *)ppFramesIn[0], (void **)ppFramesOut); } static ma_node_vtable g_ma_channel_separator_node_vtable = -{ - ma_channel_separator_node_process_pcm_frames, - NULL, - 1, /* 1 input bus. */ - MA_NODE_BUS_COUNT_UNKNOWN, /* Output bus count is determined by the channel count and is unknown until the node instance is initialized. */ - 0 /* Default flags. */ + { + ma_channel_separator_node_process_pcm_frames, + NULL, + 1, /* 1 input bus. */ + MA_NODE_BUS_COUNT_UNKNOWN, /* Output bus count is determined by the channel count and is unknown until the node instance is initialized. */ + 0 /* Default flags. */ }; -MA_API ma_result ma_channel_separator_node_init(ma_node_graph* pNodeGraph, const ma_channel_separator_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_channel_separator_node* pSeparatorNode) +MA_API ma_result ma_channel_separator_node_init(ma_node_graph *pNodeGraph, const ma_channel_separator_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_channel_separator_node *pSeparatorNode) { ma_result result; ma_node_config baseConfig; @@ -550,24 +559,28 @@ MA_API ma_result ma_channel_separator_node_init(ma_node_graph* pNodeGraph, const ma_uint32 outputChannels[MA_MAX_NODE_BUS_COUNT]; ma_uint32 iChannel; - if (pSeparatorNode == NULL) { + if (pSeparatorNode == NULL) + { return MA_INVALID_ARGS; } MA_ZERO_OBJECT(pSeparatorNode); - if (pConfig == NULL) { + if (pConfig == NULL) + { return MA_INVALID_ARGS; } - if (pConfig->channels > MA_MAX_NODE_BUS_COUNT) { + if (pConfig->channels > MA_MAX_NODE_BUS_COUNT) + { return MA_INVALID_ARGS; /* Channel count cannot exceed the maximum number of buses. */ } inputChannels[0] = pConfig->channels; /* All output channels are mono. */ - for (iChannel = 0; iChannel < pConfig->channels; iChannel += 1) { + for (iChannel = 0; iChannel < pConfig->channels; iChannel += 1) + { outputChannels[iChannel] = 1; } @@ -578,14 +591,15 @@ MA_API ma_result ma_channel_separator_node_init(ma_node_graph* pNodeGraph, const baseConfig.pOutputChannels = outputChannels; result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pSeparatorNode->baseNode); - if (result != MA_SUCCESS) { + if (result != MA_SUCCESS) + { return result; } return MA_SUCCESS; } -MA_API void ma_channel_separator_node_uninit(ma_channel_separator_node* pSeparatorNode, const ma_allocation_callbacks* pAllocationCallbacks) +MA_API void ma_channel_separator_node_uninit(ma_channel_separator_node *pSeparatorNode, const ma_allocation_callbacks *pAllocationCallbacks) { /* The base node is always uninitialized first. */ ma_node_uninit(pSeparatorNode, pAllocationCallbacks); @@ -601,11 +615,13 @@ ma_engine sound_default_mixer; ma_device sound_mixer_device; ma_engine_config engineConfig; asUINT period_size = 256; -static void sound_mixer_device_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { +static void sound_mixer_device_callback(ma_device *pDevice, void *pOutput, const void *pInput, ma_uint32 frameCount) +{ ma_engine_read_pcm_frames(&sound_default_mixer, pOutput, frameCount, nullptr); (void)pInput; } -struct AudioDevice { +struct AudioDevice +{ std::string name; ma_device_id id; }; @@ -614,20 +630,24 @@ static std::vector GetOutputAudioDevices() std::vector audioDevices; ma_result result; ma_context context; - ma_device_info* pPlaybackDeviceInfos; + ma_device_info *pPlaybackDeviceInfos; ma_uint32 playbackDeviceCount; ma_uint32 iPlaybackDevice; - if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) { - return audioDevices;; + if (ma_context_init(NULL, 0, NULL, &context) != MA_SUCCESS) + { + return audioDevices; + ; } result = ma_context_get_devices(&context, &pPlaybackDeviceInfos, &playbackDeviceCount, nullptr, nullptr); - if (result != MA_SUCCESS) { + if (result != MA_SUCCESS) + { return audioDevices; } - for (iPlaybackDevice = 0; iPlaybackDevice < playbackDeviceCount; ++iPlaybackDevice) { - const char* name = pPlaybackDeviceInfos[iPlaybackDevice].name; + for (iPlaybackDevice = 0; iPlaybackDevice < playbackDeviceCount; ++iPlaybackDevice) + { + const char *name = pPlaybackDeviceInfos[iPlaybackDevice].name; std::string name_str(name); AudioDevice ad; ad.id = pPlaybackDeviceInfos[iPlaybackDevice].id; @@ -639,35 +659,45 @@ static std::vector GetOutputAudioDevices() return audioDevices; } std::vector devs; -CScriptArray* get_output_audio_devices() { - if (!g_SoundInitialized)soundsystem_init(); - asIScriptContext* ctx = asGetActiveContext(); - asIScriptEngine* engine = ctx->GetEngine(); - asITypeInfo* arrayType = engine->GetTypeInfoById(engine->GetTypeIdByDecl("array")); - CScriptArray* array = CScriptArray::Create(arrayType, (asUINT)0); +CScriptArray *get_output_audio_devices() +{ + if (!g_SoundInitialized) + soundsystem_init(); + asIScriptContext *ctx = asGetActiveContext(); + asIScriptEngine *engine = ctx->GetEngine(); + asITypeInfo *arrayType = engine->GetTypeInfoById(engine->GetTypeIdByDecl("array")); + CScriptArray *array = CScriptArray::Create(arrayType, (asUINT)0); devs = GetOutputAudioDevices(); - if (devs.size() == 0)return array; + if (devs.size() == 0) + return array; array->Reserve(devs.size()); - for (asUINT i = 0; i < devs.size(); i++) { + for (asUINT i = 0; i < devs.size(); i++) + { array->InsertLast(&devs[i].name); } return array; } void mixer_start(); void mixer_stop(); -bool set_output_audio_device(asUINT id) { - if (!g_SoundInitialized)soundsystem_init(); - if (devs.size() == 0)devs = GetOutputAudioDevices(); - mixer_stop();// Need to reset and uninitialize audio_device +bool set_output_audio_device(asUINT id) +{ + if (!g_SoundInitialized) + soundsystem_init(); + if (devs.size() == 0) + devs = GetOutputAudioDevices(); + mixer_stop(); // Need to reset and uninitialize audio_device ma_device_uninit(&sound_mixer_device); - ma_device_config devConfig = ma_device_config_init(ma_device_type_playback);; + ma_device_config devConfig = ma_device_config_init(ma_device_type_playback); + ; devConfig.playback.pDeviceID = &devs[id].id; devConfig.periodSizeInFrames = period_size; devConfig.playback.channels = CHANNELS; + devConfig.playback.format = FORMAT; devConfig.sampleRate = SAMPLE_RATE; devConfig.noClip = MA_TRUE; devConfig.dataCallback = sound_mixer_device_callback; - if (ma_device_init(nullptr, &devConfig, &sound_mixer_device) != MA_SUCCESS)return false; + if (ma_device_init(nullptr, &devConfig, &sound_mixer_device) != MA_SUCCESS) + return false; mixer_start(); return true; } @@ -675,27 +705,28 @@ static ma_result ma_result_from_IPLerror(IPLerror error) { switch (error) { - case IPL_STATUS_SUCCESS: return MA_SUCCESS; - case IPL_STATUS_OUTOFMEMORY: return MA_OUT_OF_MEMORY; + case IPL_STATUS_SUCCESS: + return MA_SUCCESS; + case IPL_STATUS_OUTOFMEMORY: + return MA_OUT_OF_MEMORY; case IPL_STATUS_INITIALIZATION: case IPL_STATUS_FAILURE: - default: return MA_ERROR; + default: + return MA_ERROR; } } - typedef struct { ma_node_config nodeConfig; ma_uint32 channelsIn; IPLAudioSettings iplAudioSettings; IPLContext iplContext; - IPLHRTF iplHRTF; /* There is one HRTF object to many binaural effect objects. */ + IPLHRTF iplHRTF; /* There is one HRTF object to many binaural effect objects. */ } ma_steamaudio_binaural_node_config; MA_API ma_steamaudio_binaural_node_config ma_steamaudio_binaural_node_config_init(ma_uint32 channelsIn, IPLAudioSettings iplAudioSettings, IPLContext iplContext, IPLHRTF iplHRTF); - typedef struct { ma_node_base baseNode; @@ -704,16 +735,15 @@ typedef struct IPLHRTF iplHRTF; IPLBinauralEffect iplEffect; ma_vec3f direction; - float* ppBuffersIn[2]; /* Each buffer is an offset of _pHeap. */ - float* ppBuffersOut[2]; /* Each buffer is an offset of _pHeap. */ - void* _pHeap; + float *ppBuffersIn[2]; /* Each buffer is an offset of _pHeap. */ + float *ppBuffersOut[2]; /* Each buffer is an offset of _pHeap. */ + void *_pHeap; ma_sound handle_; } ma_steamaudio_binaural_node; -MA_API ma_result ma_steamaudio_binaural_node_init(ma_node_graph* pNodeGraph, const ma_steamaudio_binaural_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_steamaudio_binaural_node* pBinauralNode); -MA_API void ma_steamaudio_binaural_node_uninit(ma_steamaudio_binaural_node* pBinauralNode, const ma_allocation_callbacks* pAllocationCallbacks); -MA_API ma_result ma_steamaudio_binaural_node_set_direction(ma_steamaudio_binaural_node* pBinauralNode, float x, float y, float z); - +MA_API ma_result ma_steamaudio_binaural_node_init(ma_node_graph *pNodeGraph, const ma_steamaudio_binaural_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_steamaudio_binaural_node *pBinauralNode); +MA_API void ma_steamaudio_binaural_node_uninit(ma_steamaudio_binaural_node *pBinauralNode, const ma_allocation_callbacks *pAllocationCallbacks); +MA_API ma_result ma_steamaudio_binaural_node_set_direction(ma_steamaudio_binaural_node *pBinauralNode, float x, float y, float z); MA_API ma_steamaudio_binaural_node_config ma_steamaudio_binaural_node_config_init(ma_uint32 channelsIn, IPLAudioSettings iplAudioSettings, IPLContext iplContext, IPLHRTF iplHRTF) { @@ -730,17 +760,19 @@ MA_API ma_steamaudio_binaural_node_config ma_steamaudio_binaural_node_config_ini } float spatial_blend_max_distance = 2.0f; -void set_spatial_blend_max_distance(float distance) { +void set_spatial_blend_max_distance(float distance) +{ spatial_blend_max_distance = distance; } -float get_spatial_blend_max_distance() { +float get_spatial_blend_max_distance() +{ return spatial_blend_max_distance; } -static void ma_steamaudio_binaural_node_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut) +static void ma_steamaudio_binaural_node_process_pcm_frames(ma_node *pNode, const float **ppFramesIn, ma_uint32 *pFrameCountIn, float **ppFramesOut, ma_uint32 *pFrameCountOut) { - ma_steamaudio_binaural_node* pBinauralNode = (ma_steamaudio_binaural_node*)pNode; + ma_steamaudio_binaural_node *pBinauralNode = (ma_steamaudio_binaural_node *)pNode; IPLBinauralEffectParams binauralParams; IPLAudioBuffer inputBufferDesc; IPLAudioBuffer outputBufferDesc; @@ -751,15 +783,15 @@ static void ma_steamaudio_binaural_node_process_pcm_frames(ma_node* pNode, const binauralParams.direction.z = pBinauralNode->direction.y; ma_vec3f listener = ma_engine_listener_get_position(&sound_default_mixer, ma_sound_get_listener_index(&pBinauralNode->handle_)); float distance = sqrt((listener.x + binauralParams.direction.x) * (listener.x + binauralParams.direction.x) + - (listener.y + binauralParams.direction.y) * (listener.y + binauralParams.direction.y) + - (listener.z - binauralParams.direction.z) * (listener.z - binauralParams.direction.z)); - if (listener.x == binauralParams.direction.x && listener.y == binauralParams.direction.y && listener.z == binauralParams.direction.z) { + (listener.y + binauralParams.direction.y) * (listener.y + binauralParams.direction.y) + + (listener.z - binauralParams.direction.z) * (listener.z - binauralParams.direction.z)); + if (listener.x == binauralParams.direction.x && listener.y == binauralParams.direction.y && listener.z == binauralParams.direction.z) + { binauralParams.interpolation = IPL_HRTFINTERPOLATION_NEAREST; - } - else { + else + { binauralParams.interpolation = IPL_HRTFINTERPOLATION_BILINEAR; - } float normalizedDistance = distance / spatial_blend_max_distance; @@ -775,19 +807,23 @@ static void ma_steamaudio_binaural_node_process_pcm_frames(ma_node* pNode, const outputBufferDesc.numChannels = 2; outputBufferDesc.data = pBinauralNode->ppBuffersOut; - while (totalFramesProcessed < totalFramesToProcess) { + while (totalFramesProcessed < totalFramesToProcess) + { ma_uint32 framesToProcessThisIteration = totalFramesToProcess - totalFramesProcessed; - if (framesToProcessThisIteration > (ma_uint32)pBinauralNode->iplAudioSettings.frameSize) { + if (framesToProcessThisIteration > (ma_uint32)pBinauralNode->iplAudioSettings.frameSize) + { framesToProcessThisIteration = (ma_uint32)pBinauralNode->iplAudioSettings.frameSize; } - if (inputBufferDesc.numChannels == 1) { + if (inputBufferDesc.numChannels == 1) + { /* Fast path. No need for deinterleaving since it's a mono stream. */ - pBinauralNode->ppBuffersIn[0] = (float*)ma_offset_pcm_frames_const_ptr_f32(ppFramesIn[0], totalFramesProcessed, 1); + pBinauralNode->ppBuffersIn[0] = (float *)ma_offset_pcm_frames_const_ptr_f32(ppFramesIn[0], totalFramesProcessed, 1); } - else { + else + { /* Slow path. Need to deinterleave the input data. */ - ma_deinterleave_pcm_frames(ma_format_f32, inputBufferDesc.numChannels, framesToProcessThisIteration, ma_offset_pcm_frames_const_ptr_f32(ppFramesIn[0], totalFramesProcessed, inputBufferDesc.numChannels), (void**)pBinauralNode->ppBuffersIn); + ma_deinterleave_pcm_frames(ma_format_f32, inputBufferDesc.numChannels, framesToProcessThisIteration, ma_offset_pcm_frames_const_ptr_f32(ppFramesIn[0], totalFramesProcessed, inputBufferDesc.numChannels), (void **)pBinauralNode->ppBuffersIn); } inputBufferDesc.data = pBinauralNode->ppBuffersIn; @@ -795,28 +831,27 @@ static void ma_steamaudio_binaural_node_process_pcm_frames(ma_node* pNode, const /* Apply the effect. */ iplBinauralEffectApply(pBinauralNode->iplEffect, &binauralParams, &inputBufferDesc, &outputBufferDesc); - //iplDirectEffectApply(pBinauralNode->effect, ¶ms, &inputBufferDesc, &outputBufferDesc); + // iplDirectEffectApply(pBinauralNode->effect, ¶ms, &inputBufferDesc, &outputBufferDesc); /* Interleave straight into the output buffer. */ - ma_interleave_pcm_frames(ma_format_f32, 2, framesToProcessThisIteration, (const void**)pBinauralNode->ppBuffersOut, ma_offset_pcm_frames_ptr_f32(ppFramesOut[0], totalFramesProcessed, 2)); + ma_interleave_pcm_frames(ma_format_f32, 2, framesToProcessThisIteration, (const void **)pBinauralNode->ppBuffersOut, ma_offset_pcm_frames_ptr_f32(ppFramesOut[0], totalFramesProcessed, 2)); /* Advance. */ totalFramesProcessed += framesToProcessThisIteration; } - (void)pFrameCountIn; /* Unused. */ + (void)pFrameCountIn; /* Unused. */ } static ma_node_vtable g_ma_steamaudio_binaural_node_vtable = -{ - ma_steamaudio_binaural_node_process_pcm_frames, - NULL, - 1, /* 1 input channel. */ -1 , /* 1 output channel. */ - 0 -}; + { + ma_steamaudio_binaural_node_process_pcm_frames, + NULL, + 1, /* 1 input channel. */ + 1, /* 1 output channel. */ + 0}; -MA_API ma_result ma_steamaudio_binaural_node_init(ma_node_graph* pNodeGraph, const ma_steamaudio_binaural_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_steamaudio_binaural_node* pBinauralNode) +MA_API ma_result ma_steamaudio_binaural_node_init(ma_node_graph *pNodeGraph, const ma_steamaudio_binaural_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_steamaudio_binaural_node *pBinauralNode) { ma_result result; ma_node_config baseConfig; @@ -826,30 +861,34 @@ MA_API ma_result ma_steamaudio_binaural_node_init(ma_node_graph* pNodeGraph, con IPLDirectEffectSettings effectSettings{}; size_t heapSizeInBytes; - if (pBinauralNode == NULL) { + if (pBinauralNode == NULL) + { return MA_INVALID_ARGS; } MA_ZERO_OBJECT(pBinauralNode); - if (pConfig == NULL || pConfig->iplAudioSettings.frameSize == 0 || pConfig->iplContext == NULL || pConfig->iplHRTF == NULL) { + if (pConfig == NULL || pConfig->iplAudioSettings.frameSize == 0 || pConfig->iplContext == NULL || pConfig->iplHRTF == NULL) + { return MA_INVALID_ARGS; } /* Steam Audio only supports mono and stereo input. */ - if (pConfig->channelsIn < 1 || pConfig->channelsIn > 2) { + if (pConfig->channelsIn < 1 || pConfig->channelsIn > 2) + { return MA_INVALID_ARGS; } channelsIn = pConfig->channelsIn; - channelsOut = 2; /* Always stereo output. */ + channelsOut = 2; /* Always stereo output. */ baseConfig = ma_node_config_init(); baseConfig.vtable = &g_ma_steamaudio_binaural_node_vtable; baseConfig.pInputChannels = &channelsIn; baseConfig.pOutputChannels = &channelsOut; result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pBinauralNode->baseNode); - if (result != MA_SUCCESS) { + if (result != MA_SUCCESS) + { return result; } @@ -861,7 +900,8 @@ MA_API ma_result ma_steamaudio_binaural_node_init(ma_node_graph* pNodeGraph, con iplBinauralEffectSettings.hrtf = pBinauralNode->iplHRTF; result = ma_result_from_IPLerror(iplBinauralEffectCreate(pBinauralNode->iplContext, &pBinauralNode->iplAudioSettings, &iplBinauralEffectSettings, &pBinauralNode->iplEffect)); - if (result != MA_SUCCESS) { + if (result != MA_SUCCESS) + { ma_node_uninit(&pBinauralNode->baseNode, pAllocationCallbacks); return result; } @@ -873,31 +913,34 @@ MA_API ma_result ma_steamaudio_binaural_node_init(ma_node_graph* pNodeGraph, con use the frame size from the IPLAudioSettings structure as a basis for the size of the buffer. */ heapSizeInBytes += sizeof(float) * channelsOut * pBinauralNode->iplAudioSettings.frameSize; /* Output buffer. */ - heapSizeInBytes += sizeof(float) * channelsIn * pBinauralNode->iplAudioSettings.frameSize; /* Input buffer. */ + heapSizeInBytes += sizeof(float) * channelsIn * pBinauralNode->iplAudioSettings.frameSize; /* Input buffer. */ pBinauralNode->_pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks); - if (pBinauralNode->_pHeap == NULL) { + if (pBinauralNode->_pHeap == NULL) + { iplBinauralEffectRelease(&pBinauralNode->iplEffect); ma_node_uninit(&pBinauralNode->baseNode, pAllocationCallbacks); return MA_OUT_OF_MEMORY; } - pBinauralNode->ppBuffersOut[0] = (float*)pBinauralNode->_pHeap; - pBinauralNode->ppBuffersOut[1] = (float*)ma_offset_ptr(pBinauralNode->_pHeap, sizeof(float) * pBinauralNode->iplAudioSettings.frameSize); + pBinauralNode->ppBuffersOut[0] = (float *)pBinauralNode->_pHeap; + pBinauralNode->ppBuffersOut[1] = (float *)ma_offset_ptr(pBinauralNode->_pHeap, sizeof(float) * pBinauralNode->iplAudioSettings.frameSize); { ma_uint32 iChannelIn; - for (iChannelIn = 0; iChannelIn < channelsIn; iChannelIn += 1) { - pBinauralNode->ppBuffersIn[iChannelIn] = (float*)ma_offset_ptr(pBinauralNode->_pHeap, sizeof(float) * pBinauralNode->iplAudioSettings.frameSize * (channelsOut + iChannelIn)); + for (iChannelIn = 0; iChannelIn < channelsIn; iChannelIn += 1) + { + pBinauralNode->ppBuffersIn[iChannelIn] = (float *)ma_offset_ptr(pBinauralNode->_pHeap, sizeof(float) * pBinauralNode->iplAudioSettings.frameSize * (channelsOut + iChannelIn)); } } return MA_SUCCESS; } -MA_API void ma_steamaudio_binaural_node_uninit(ma_steamaudio_binaural_node* pBinauralNode, const ma_allocation_callbacks* pAllocationCallbacks) +MA_API void ma_steamaudio_binaural_node_uninit(ma_steamaudio_binaural_node *pBinauralNode, const ma_allocation_callbacks *pAllocationCallbacks) { - if (pBinauralNode == NULL) { + if (pBinauralNode == NULL) + { return; } @@ -912,9 +955,10 @@ MA_API void ma_steamaudio_binaural_node_uninit(ma_steamaudio_binaural_node* pBin ma_free(pBinauralNode->_pHeap, pAllocationCallbacks); } -MA_API ma_result ma_steamaudio_binaural_node_set_direction(ma_steamaudio_binaural_node* pBinauralNode, float x, float y, float z) +MA_API ma_result ma_steamaudio_binaural_node_set_direction(ma_steamaudio_binaural_node *pBinauralNode, float x, float y, float z) { - if (pBinauralNode == NULL) { + if (pBinauralNode == NULL) + { return MA_INVALID_ARGS; } @@ -925,20 +969,24 @@ MA_API ma_result ma_steamaudio_binaural_node_set_direction(ma_steamaudio_binaura return MA_SUCCESS; } -bool soundsystem_init() { - if (g_SoundInitialized == true)return true; +bool soundsystem_init() +{ + if (g_SoundInitialized == true) + return true; engineConfig = ma_engine_config_init(); engineConfig.noDevice = MA_TRUE; engineConfig.channels = CHANNELS; engineConfig.sampleRate = SAMPLE_RATE; - ma_device_config devConfig = ma_device_config_init(ma_device_type_playback);; + ma_device_config devConfig = ma_device_config_init(ma_device_type_playback); + ; devConfig.noClip = MA_TRUE; devConfig.periodSizeInFrames = period_size; devConfig.playback.channels = CHANNELS; devConfig.sampleRate = SAMPLE_RATE; devConfig.playback.format = FORMAT; devConfig.dataCallback = sound_mixer_device_callback; - if (ma_device_init(nullptr, &devConfig, &sound_mixer_device) != MA_SUCCESS)return false; + if (ma_device_init(nullptr, &devConfig, &sound_mixer_device) != MA_SUCCESS) + return false; mixer_start(); ma_engine_init(&engineConfig, &sound_default_mixer); MA_ZERO_OBJECT(&iplAudioSettings); @@ -946,7 +994,6 @@ bool soundsystem_init() { iplAudioSettings.frameSize = devConfig.periodSizeInFrames; - /* IPLContext */ MA_ZERO_OBJECT(&iplContextSettings); iplContextSettings.version = STEAMAUDIO_VERSION; @@ -959,8 +1006,10 @@ bool soundsystem_init() { ma_result_from_IPLerror(iplHRTFCreate(iplContext, &iplAudioSettings, &iplHRTFSettings, &iplHRTF)); return true; } -void soundsystem_free() { - if (g_SoundInitialized == false)return; +void soundsystem_free() +{ + if (g_SoundInitialized == false) + return; iplHRTFRelease(&iplHRTF); iplContextRelease(&iplContext); ma_device_uninit(&sound_mixer_device); @@ -968,115 +1017,139 @@ void soundsystem_free() { g_SoundInitialized = false; } void mixer_reinit(int channels, int sample_rate); -void set_audio_period_size(asUINT size) { +void set_audio_period_size(asUINT size) +{ period_size = size; - if (g_SoundInitialized)mixer_reinit(CHANNELS, SAMPLE_RATE); + if (g_SoundInitialized) + mixer_reinit(CHANNELS, SAMPLE_RATE); } string sound_path; -pack* sound_pack = nullptr; -void set_sound_storage(const string& path) { +pack *sound_pack = nullptr; +void set_sound_storage(const string &path) +{ sound_path = path; sound_pack = nullptr; } -string get_sound_storage() { +string get_sound_storage() +{ return sound_path; } -void set_sound_pack(pack* p) { - if (p == nullptr)return; +void set_sound_pack(pack *p) +{ + if (p == nullptr) + return; sound_pack = p; sound_path = ""; } -pack* get_sound_pack() { +pack *get_sound_pack() +{ return sound_pack; } -void set_master_volume(float volume) { - if (volume > 0 or volume < -100)return; +void set_master_volume(float volume) +{ + if (volume > 0 or volume < -100) + return; ma_engine_set_gain_db(&sound_default_mixer, volume); } -float get_master_volume() { +float get_master_volume() +{ return ma_engine_get_gain_db(&sound_default_mixer); - } -void mixer_start() { +void mixer_start() +{ ma_device_start(&sound_mixer_device); } -void mixer_stop() { +void mixer_stop() +{ ma_device_stop(&sound_mixer_device); } -bool mixer_play_sound(const string& filename) { - if (!g_SoundInitialized) { - if (!soundsystem_init()) { +bool mixer_play_sound(const string &filename) +{ + if (!g_SoundInitialized) + { + if (!soundsystem_init()) + { return false; } g_SoundInitialized = true; } string result; - if (sound_path != "") { + if (sound_path != "") + { result = sound_path + "/" + filename.c_str(); } - else { + else + { result = filename; } ma_result r; r = ma_engine_play_sound(&sound_default_mixer, result.c_str(), nullptr); if (r != MA_SUCCESS) - return false; + return false; return true; } -void mixer_reinit(int channels = 2, int sample_rate = 44100) { +void mixer_reinit(int channels = 2, int sample_rate = 44100) +{ CHANNELS = channels; SAMPLE_RATE = sample_rate; - if (g_SoundInitialized)soundsystem_free(); + if (g_SoundInitialized) + soundsystem_free(); soundsystem_init(); } bool sound_global_hrtf = false; - -std::vector load_audio_from_url(const std::string& url) { +std::vector load_audio_from_url(const std::string &url) +{ Poco::URI uri(url); int redirectCount = 0; const std::string userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"; Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort() == -1 ? (uri.getScheme() == "https" ? 443 : 80) : uri.getPort()); - while (redirectCount < 5) { + while (redirectCount < 5) + { Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uri.getPathAndQuery()); request.set("User-Agent", userAgent); Poco::Net::HTTPResponse response; - try { + try + { session.sendRequest(request); - std::istream& rs = session.receiveResponse(response); + std::istream &rs = session.receiveResponse(response); - if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK) { + if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK) + { std::vector audioData; audioData.reserve(response.getContentLength()); audioData.insert(audioData.end(), std::istreambuf_iterator(rs), std::istreambuf_iterator()); return audioData; } else if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_FOUND || - response.getStatus() == Poco::Net::HTTPResponse::HTTP_MOVED_PERMANENTLY) { + response.getStatus() == Poco::Net::HTTPResponse::HTTP_MOVED_PERMANENTLY) + { std::string location = response.get("Location"); uri = Poco::URI(location); redirectCount++; } - else { - asIScriptContext* ctx = asGetActiveContext(); + else + { + asIScriptContext *ctx = asGetActiveContext(); std::string text = std::to_string(response.getStatus()) + " " + response.getReasonForStatus(response.getStatus()); ctx->SetException(text.c_str()); return {}; } } - catch (const Poco::Exception& ex) { - asIScriptContext* ctx = asGetActiveContext(); + catch (const Poco::Exception &ex) + { + asIScriptContext *ctx = asGetActiveContext(); ctx->SetException(ex.displayText().c_str()); return {}; } } - asIScriptContext* ctx = asGetActiveContext(); + asIScriptContext *ctx = asGetActiveContext(); ctx->SetException(""); return {}; } @@ -1084,9 +1157,9 @@ std::vector load_audio_from_url(const std::string& url) { 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 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 playbackSpeed; /* Playback speed multiplier. */ + float playbackSpeed; /* Playback speed multiplier. */ } ma_playback_speed_node_config; typedef struct { @@ -1094,31 +1167,32 @@ typedef struct ma_playback_speed_node_config conf; } ma_playback_speed_node; - MA_API ma_playback_speed_node_config ma_playback_speed_node_config_init(ma_uint32 channels, ma_uint32 sampleRate) { ma_playback_speed_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.nodeConfig = ma_node_config_init(); /* Input and output channels will be set in ma_reverb_node_init(). */ config.channels = channels; config.sampleRate = sampleRate; return config; } -static void ma_playback_speed_node_process_pcm_frames(ma_node* pNode, const float** ppFramesIn, ma_uint32* pFrameCountIn, float** ppFramesOut, ma_uint32* pFrameCountOut) +static void ma_playback_speed_node_process_pcm_frames(ma_node *pNode, const float **ppFramesIn, ma_uint32 *pFrameCountIn, float **ppFramesOut, ma_uint32 *pFrameCountOut) { - ma_playback_speed_node* pPlaybackSpeedNode = (ma_playback_speed_node*)pNode; + ma_playback_speed_node *pPlaybackSpeedNode = (ma_playback_speed_node *)pNode; float playbackSpeed = pPlaybackSpeedNode->conf.playbackSpeed; - for (ma_uint32 i = 0; i < *pFrameCountOut; i++) { + for (ma_uint32 i = 0; i < *pFrameCountOut; i++) + { float t = (float)i / playbackSpeed; int index = (int)t; float fraction = t - index; - for (ma_uint32 j = 0; j < pPlaybackSpeedNode->conf.channels; j++) { + for (ma_uint32 j = 0; j < pPlaybackSpeedNode->conf.channels; j++) + { int inputIndex1 = index * pPlaybackSpeedNode->conf.channels + j; int inputIndex2 = (index + 1) * pPlaybackSpeedNode->conf.channels + j; int outputIndex = i * pPlaybackSpeedNode->conf.channels + j; @@ -1126,28 +1200,29 @@ static void ma_playback_speed_node_process_pcm_frames(ma_node* pNode, const floa *ppFramesOut[outputIndex] = *ppFramesIn[inputIndex1] + fraction * (ppFramesIn[inputIndex2] - ppFramesIn[inputIndex1]); } } - } static ma_node_vtable g_ma_playback_speed_node_vtable = -{ - ma_playback_speed_node_process_pcm_frames, - NULL, - 1, /* 1 input channel. */ - 1, /* 1 output channel. */ - MA_NODE_FLAG_CONTINUOUS_PROCESSING }; -MA_API ma_result ma_playback_speed_node_init(ma_node_graph* pNodeGraph, const ma_playback_speed_node_config* pConfig, const ma_allocation_callbacks* pAllocationCallbacks, ma_playback_speed_node* pPlaybackSpeedNode) + { + ma_playback_speed_node_process_pcm_frames, + NULL, + 1, /* 1 input channel. */ + 1, /* 1 output channel. */ + MA_NODE_FLAG_CONTINUOUS_PROCESSING}; +MA_API ma_result ma_playback_speed_node_init(ma_node_graph *pNodeGraph, const ma_playback_speed_node_config *pConfig, const ma_allocation_callbacks *pAllocationCallbacks, ma_playback_speed_node *pPlaybackSpeedNode) { ma_result result; ma_node_config baseConfig; - if (pPlaybackSpeedNode == NULL) { + if (pPlaybackSpeedNode == NULL) + { return MA_INVALID_ARGS; } MA_ZERO_OBJECT(pPlaybackSpeedNode); - if (pConfig == NULL) { + if (pConfig == NULL) + { return MA_INVALID_ARGS; } @@ -1157,40 +1232,39 @@ MA_API ma_result ma_playback_speed_node_init(ma_node_graph* pNodeGraph, const ma baseConfig.pOutputChannels = &pConfig->channels; result = ma_node_init(pNodeGraph, &baseConfig, pAllocationCallbacks, &pPlaybackSpeedNode->baseNode); - if (result != MA_SUCCESS) { + if (result != MA_SUCCESS) + { return result; } return MA_SUCCESS; } -MA_API void ma_playback_speed_node_uninit(ma_playback_speed_node* pPlaybackSpeedNode, const ma_allocation_callbacks* pAllocationCallbacks) +MA_API void ma_playback_speed_node_uninit(ma_playback_speed_node *pPlaybackSpeedNode, const ma_allocation_callbacks *pAllocationCallbacks) { /* The base node is always uninitialized first. */ ma_node_uninit(pPlaybackSpeedNode, pAllocationCallbacks); } - - - -class MINIAUDIO_IMPLEMENTATION sound { +class MINIAUDIO_IMPLEMENTATION sound +{ public: bool is_3d_; bool playing = false, paused = false, active = false; - ma_sound* handle_ = nullptr; + ma_sound *handle_ = nullptr; ma_decoder decoder; bool decoderInitialized = false; - ma_steamaudio_binaural_node m_binauralNode; /* The echo effect is achieved using a delay node. */ - ma_reverb_node m_reverbNode; /* The reverb node. */ + ma_steamaudio_binaural_node m_binauralNode; /* The echo effect is achieved using a delay node. */ + ma_reverb_node m_reverbNode; /* The reverb node. */ ma_reverb_node_config reverbNodeConfig; - ma_vocoder_node m_vocoderNode; /* The vocoder node. */ + ma_vocoder_node m_vocoderNode; /* The vocoder node. */ ma_vocoder_node_config vocoderNodeConfig; - ma_delay_node m_delayNode; /* The delay node. */ + ma_delay_node m_delayNode; /* The delay node. */ ma_delay_node_config delayNodeConfig; - ma_ltrim_node m_trimNode; /* The trim node. */ + ma_ltrim_node m_trimNode; /* The trim node. */ ma_ltrim_node_config trimNodeConfig; - ma_channel_separator_node m_separatorNode; /* The separator node. */ - ma_channel_combiner_node m_combinerNode; /* The combiner node. */ + ma_channel_separator_node m_separatorNode; /* The separator node. */ + ma_channel_combiner_node m_combinerNode; /* The combiner node. */ ma_channel_separator_node_config separatorNodeConfig; ma_channel_combiner_node_config combinerNodeConfig; ma_hpf_node highpass; @@ -1202,16 +1276,18 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_playback_speed_node m_playback_speed_node; ma_playback_speed_node_config m_speed_config; ma_steamaudio_binaural_node_config binauralNodeConfig; - std::map effects; + std::map effects; ma_audio_buffer m_buffer; bool buffer_initialized = false; mutable int ref = 0; string file; - ngtvector* source_position = nullptr; - ngtvector* listener_position = nullptr; - sound(const string& filename = "") { + ngtvector *source_position = nullptr; + ngtvector *listener_position = nullptr; + sound(const string &filename = "") + { ref = 1; - if (!g_SoundInitialized) { + if (!g_SoundInitialized) + { g_SoundInitialized = soundsystem_init(); } if (filename != "") @@ -1222,36 +1298,49 @@ class MINIAUDIO_IMPLEMENTATION sound { listener_position->reset(); source_position->reset(); } - ~sound() { + ~sound() + { } - void add() { + void add() + { ref += 1; } - void release() { - if (--ref < 1) { - if (active)this->close(); - if (listener_position)delete listener_position; - if (source_position)delete source_position; + void release() + { + if (--ref < 1) + { + if (active) + this->close(); + if (listener_position) + delete listener_position; + if (source_position) + delete source_position; delete this; } } - bool load(const string& filename) { + bool load(const string &filename) + { string result; - if (sound_path != "") { + if (sound_path != "") + { result = sound_path + "/" + filename.c_str(); } - else { + else + { result = filename; } - if (active)this->close(); - if (sound_pack != nullptr and sound_pack->active()) { + if (active) + this->close(); + if (sound_pack != nullptr and sound_pack->active()) + { string file = sound_pack->get_file(filename); size_t size = sound_pack->get_file_size(filename); return this->load_from_memory(file, size); } handle_ = new ma_sound; ma_result loading_result = ma_sound_init_from_file(&sound_default_mixer, result.c_str(), 0, NULL, NULL, handle_); - if (loading_result != MA_SUCCESS) { + if (loading_result != MA_SUCCESS) + { delete handle_; active = false; return false; @@ -1267,13 +1356,17 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_sound_set_rolloff(handle_, 2); return true; } - bool load_from_memory(string data, size_t stream_size) { - if (active)this->close(); + bool load_from_memory(string data, size_t stream_size) + { + if (active) + this->close(); handle_ = new ma_sound; ma_result r = ma_decoder_init_memory(data.c_str(), stream_size, NULL, &decoder); - if (r != MA_SUCCESS)return false; + if (r != MA_SUCCESS) + return false; ma_result loading_result = ma_sound_init_from_data_source(&sound_default_mixer, &decoder, 0, 0, handle_); - if (loading_result != MA_SUCCESS) { + if (loading_result != MA_SUCCESS) + { delete handle_; active = false; return false; @@ -1289,21 +1382,26 @@ class MINIAUDIO_IMPLEMENTATION sound { return active; } - bool load_pcm(string data, size_t size, int channels, int sample_rate) { - if (active)this->close(); + bool load_pcm(string data, size_t size, int channels, int sample_rate) + { + if (active) + this->close(); handle_ = new ma_sound; - if (buffer_initialized) { + if (buffer_initialized) + { ma_audio_buffer_uninit(&m_buffer); buffer_initialized = false; } - ma_audio_buffer_config bufferConfig = ma_audio_buffer_config_init(FORMAT, channels, size / 2, (const void*)data.c_str(), nullptr); + ma_audio_buffer_config bufferConfig = ma_audio_buffer_config_init(FORMAT, channels, size / 2, (const void *)data.c_str(), nullptr); bufferConfig.sampleRate = sample_rate; bufferConfig.channels = channels; ma_result result = ma_audio_buffer_init(&bufferConfig, &m_buffer); - if (result != MA_SUCCESS)return false; + if (result != MA_SUCCESS) + return false; buffer_initialized = true; ma_result loading_result = ma_sound_init_from_data_source(&sound_default_mixer, &m_buffer, 0, 0, handle_); - if (loading_result != MA_SUCCESS) { + if (loading_result != MA_SUCCESS) + { delete handle_; active = false; return false; @@ -1318,20 +1416,22 @@ class MINIAUDIO_IMPLEMENTATION sound { this->set_hrtf(true); return active; - - } - bool stream(const string& filename) { + bool stream(const string &filename) + { string result; - if (sound_path != "") { + if (sound_path != "") + { result = sound_path + "/" + filename.c_str(); } - else { + else + { result = filename; } handle_ = new ma_sound; ma_result loading_result = ma_sound_init_from_file(&sound_default_mixer, result.c_str(), MA_SOUND_FLAG_STREAM, NULL, NULL, handle_); - if (loading_result != MA_SUCCESS) { + if (loading_result != MA_SUCCESS) + { delete handle_; active = false; return false; @@ -1347,15 +1447,18 @@ class MINIAUDIO_IMPLEMENTATION sound { return true; } - bool load_url(const string& url) { + bool load_url(const string &url) + { handle_ = new ma_sound; vector audio = load_audio_from_url(url.c_str()); ma_result init_result = ma_decoder_init_memory(audio.data(), audio.size(), NULL, &decoder); - if (init_result != MA_SUCCESS) { + if (init_result != MA_SUCCESS) + { return false; } ma_result loading_result = ma_sound_init_from_data_source(&sound_default_mixer, &decoder, 0, 0, handle_); - if (loading_result != MA_SUCCESS) { + if (loading_result != MA_SUCCESS) + { delete handle_; active = false; return false; @@ -1368,25 +1471,33 @@ class MINIAUDIO_IMPLEMENTATION sound { return active; } - const void* push_memory() { - if (!active)return""; + const void *push_memory() + { + if (!active) + return ""; return ma_sound_get_data_source(handle_); } - string get_file_path() { + string get_file_path() + { return this->file; } - void set_faid_time(float volume_beg, float volume_end, float time) { + void set_faid_time(float volume_beg, float volume_end, float time) + { ma_sound_set_fade_in_milliseconds(handle_, volume_beg / 100, volume_end / 100, static_cast(time)); } - bool play() { - if (!active)return false; + bool play() + { + if (!active) + return false; ma_sound_set_looping(handle_, false); ma_sound_start(handle_); this->paused = false; return true; } - bool play_looped() { - if (!active)return false; + bool play_looped() + { + if (!active) + return false; ma_sound_set_looping(handle_, true); ma_sound_start(handle_); @@ -1394,81 +1505,93 @@ class MINIAUDIO_IMPLEMENTATION sound { return true; } - bool pause() { - if (!active)return false; + bool pause() + { + if (!active) + return false; ma_sound_stop(handle_); this->paused = true; return true; } - bool play_wait() { + bool play_wait() + { this->play(); - while (true) { + while (true) + { wait(1); bool ac = sound::is_playing(); - if (ac == false) { + if (ac == false) + { break; } } return true; } - bool stop() { - if (!active)return false; + bool stop() + { + if (!active) + return false; ma_sound_stop(handle_); ma_sound_seek_to_pcm_frame(handle_, 0); return true; } - bool close() { - if (!is_active())return false; - if (effects.find("reverb") != effects.end()) { + bool close() + { + if (!is_active()) + return false; + if (effects.find("reverb") != effects.end()) + { ma_reverb_node_uninit(&m_reverbNode, NULL); effects["reverb"] = nullptr; effects.erase("reverb"); } - if (effects.find("vocoder") != effects.end()) { + if (effects.find("vocoder") != effects.end()) + { ma_vocoder_node_uninit(&m_vocoderNode, NULL); effects["vocoder"] = nullptr; effects.erase("vocoder"); - } - if (effects.find("delay") != effects.end()) { + if (effects.find("delay") != effects.end()) + { ma_delay_node_uninit(&m_delayNode, NULL); effects["delay"] = nullptr; effects.erase("delay"); - } - if (effects.find("ltrim") != effects.end()) { + if (effects.find("ltrim") != effects.end()) + { ma_ltrim_node_uninit(&m_trimNode, NULL); effects["ltrim"] = nullptr; effects.erase("ltrim"); - } - if (effects.find("combiner") != effects.end()) { + if (effects.find("combiner") != effects.end()) + { ma_channel_combiner_node_uninit(&m_combinerNode, NULL); effects["combiner"] = nullptr; effects.erase("combiner"); - } - if (effects.find("separator") != effects.end()) { + if (effects.find("separator") != effects.end()) + { ma_channel_separator_node_uninit(&m_separatorNode, NULL); effects["separator"] = nullptr; effects.erase("separator"); - } - if (effects.find("highpass") != effects.end()) { + if (effects.find("highpass") != effects.end()) + { ma_hpf_node_uninit(&highpass, NULL); effects["highpass"] = nullptr; effects.erase("highpass"); - } - if (effects.find("lowpass") != effects.end()) { + if (effects.find("lowpass") != effects.end()) + { ma_lpf_node_uninit(&lowpass, NULL); effects["lowpass"] = nullptr; effects.erase("lowpass"); } - if (effects.find("notch") != effects.end()) { + if (effects.find("notch") != effects.end()) + { ma_notch_node_uninit(¬ch, NULL); effects["notch"] = nullptr; @@ -1477,30 +1600,38 @@ class MINIAUDIO_IMPLEMENTATION sound { this->set_hrtf(false); effects["Default"] = nullptr; effects.clear(); - if (decoderInitialized) { + if (decoderInitialized) + { ma_decoder_uninit(&decoder); decoderInitialized = false; } - if (buffer_initialized) { + if (buffer_initialized) + { ma_audio_buffer_uninit(&m_buffer); buffer_initialized = false; } - if (handle_ != nullptr) { + if (handle_ != nullptr) + { ma_sound_uninit(handle_); delete handle_; } - if (!file.empty())file.clear(); + if (!file.empty()) + file.clear(); listener_position->reset(); source_position->reset(); handle_ = nullptr; active = false; return true; } - void set_fx(const string& fx) { - if (!active)return; - if (effects.find(fx) != effects.end())return; - if (fx == "reverb") { + void set_fx(const string &fx) + { + if (!active) + return; + if (effects.find(fx) != effects.end()) + return; + if (fx == "reverb") + { reverbNodeConfig = ma_reverb_node_config_init(engineConfig.channels, engineConfig.sampleRate, 100, 100, 100); ma_reverb_node_init(ma_engine_get_node_graph(&sound_default_mixer), &reverbNodeConfig, NULL, &m_reverbNode); auto last = --effects.end(); @@ -1508,7 +1639,8 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_node_attach_output_bus(handle_, 0, &m_reverbNode, 0); effects[fx] = &m_reverbNode; } - if (fx == "vocoder") { + if (fx == "vocoder") + { vocoderNodeConfig = ma_vocoder_node_config_init(engineConfig.channels, engineConfig.sampleRate); ma_vocoder_node_init(ma_engine_get_node_graph(&sound_default_mixer), &vocoderNodeConfig, NULL, &m_vocoderNode); auto last = --effects.end(); @@ -1517,7 +1649,8 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_node_attach_output_bus(handle_, 0, &m_vocoderNode, 0); effects[fx] = &m_vocoderNode; } - if (fx == "delay") { + if (fx == "delay") + { delayNodeConfig = ma_delay_node_config_init(engineConfig.channels, engineConfig.sampleRate, (100 * engineConfig.sampleRate) / 1000, 0.5f); ma_delay_node_init(ma_engine_get_node_graph(&sound_default_mixer), &delayNodeConfig, NULL, &m_delayNode); auto last = --effects.end(); @@ -1526,7 +1659,8 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_node_attach_output_bus(handle_, 0, &m_delayNode, 0); effects[fx] = &m_delayNode; } - if (fx == "ltrim") { + if (fx == "ltrim") + { trimNodeConfig = ma_ltrim_node_config_init(engineConfig.channels, 0); trimNodeConfig.threshold = 0.3; ma_ltrim_node_init(ma_engine_get_node_graph(&sound_default_mixer), &trimNodeConfig, NULL, &m_trimNode); @@ -1535,9 +1669,9 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_node_attach_output_bus(&m_trimNode, 0, last->second, 0); ma_node_attach_output_bus(handle_, 0, &m_trimNode, 0); effects[fx] = &m_trimNode; - } - if (fx == "channelsplit") { + if (fx == "channelsplit") + { combinerNodeConfig = ma_channel_combiner_node_config_init(engineConfig.channels); ma_channel_combiner_node_init(ma_engine_get_node_graph(&sound_default_mixer), &combinerNodeConfig, NULL, &m_combinerNode); ma_node_attach_output_bus(&m_combinerNode, 0, ma_engine_get_endpoint(&sound_default_mixer), 0); @@ -1545,7 +1679,8 @@ class MINIAUDIO_IMPLEMENTATION sound { separatorNodeConfig = ma_channel_separator_node_config_init(engineConfig.channels); ma_channel_separator_node_init(ma_engine_get_node_graph(&sound_default_mixer), &separatorNodeConfig, NULL, &m_separatorNode); MA_ASSERT(ma_node_get_output_bus_count(&m_separatorNode) == ma_node_get_input_bus_count(&m_combinerNode)); - for (ma_uint32 iChannel = 0; iChannel < ma_node_get_output_bus_count(&m_separatorNode); iChannel += 1) { + for (ma_uint32 iChannel = 0; iChannel < ma_node_get_output_bus_count(&m_separatorNode); iChannel += 1) + { ma_node_attach_output_bus(&m_separatorNode, iChannel, &m_combinerNode, iChannel); } @@ -1553,7 +1688,8 @@ class MINIAUDIO_IMPLEMENTATION sound { effects["separator"] = &m_separatorNode; effects[fx] = &m_separatorNode; } - if (fx == "highpass") { + if (fx == "highpass") + { highpassConfig = ma_hpf_node_config_init(engineConfig.channels, engineConfig.sampleRate, 600, -10); ma_hpf_node_init(ma_engine_get_node_graph(&sound_default_mixer), &highpassConfig, NULL, &highpass); auto last = --effects.end(); @@ -1561,9 +1697,9 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_node_attach_output_bus(&highpass, 0, last->second, 0); ma_node_attach_output_bus(handle_, 0, &highpass, 0); effects[fx] = &highpass; - } - if (fx == "lowpass") { + if (fx == "lowpass") + { lowpassConfig = ma_lpf_node_config_init(engineConfig.channels, engineConfig.sampleRate, 600, -10); ma_lpf_node_init(ma_engine_get_node_graph(&sound_default_mixer), &lowpassConfig, NULL, &lowpass); auto last = --effects.end(); @@ -1571,9 +1707,9 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_node_attach_output_bus(&lowpass, 0, last->second, 0); ma_node_attach_output_bus(handle_, 0, &lowpass, 0); effects[fx] = &lowpass; - } - if (fx == "notch") { + if (fx == "notch") + { notchConfig = ma_notch_node_config_init(engineConfig.channels, engineConfig.sampleRate, 0, 300); ma_notch_node_init(ma_engine_get_node_graph(&sound_default_mixer), ¬chConfig, NULL, ¬ch); auto last = --effects.end(); @@ -1581,40 +1717,47 @@ class MINIAUDIO_IMPLEMENTATION sound { ma_node_attach_output_bus(¬ch, 0, last->second, 0); ma_node_attach_output_bus(handle_, 0, ¬ch, 0); effects[fx] = ¬ch; - } } - void delete_fx(const string& fx) { - if (!active)return; - if (effects.find(fx) == effects.end())return; - if (fx == "reverb") { + void delete_fx(const string &fx) + { + if (!active) + return; + if (effects.find(fx) == effects.end()) + return; + if (fx == "reverb") + { ma_reverb_node_uninit(&m_reverbNode, NULL); } - if (fx == "vocoder") { + if (fx == "vocoder") + { ma_vocoder_node_uninit(&m_vocoderNode, NULL); } - if (fx == "delay") { + if (fx == "delay") + { ma_delay_node_uninit(&m_delayNode, NULL); } - if (fx == "ltrim") { + if (fx == "ltrim") + { ma_ltrim_node_uninit(&m_trimNode, NULL); } - if (fx == "channelsplit") { + if (fx == "channelsplit") + { combinerNodeConfig = ma_channel_combiner_node_config_init(engineConfig.channels); ma_channel_combiner_node_uninit(&m_combinerNode, NULL); ma_channel_separator_node_uninit(&m_separatorNode, NULL); } - if (fx == "highpass") { + if (fx == "highpass") + { ma_hpf_node_uninit(&highpass, NULL); - } - if (fx == "lowpass") { + if (fx == "lowpass") + { ma_lpf_node_uninit(&lowpass, NULL); - } - if (fx == "notch") { + if (fx == "notch") + { ma_notch_node_uninit(¬ch, NULL); - } effects[fx] = nullptr; effects.erase(fx); @@ -1622,27 +1765,34 @@ class MINIAUDIO_IMPLEMENTATION sound { auto last = --effects.end(); ma_node_attach_output_bus(handle_, 0, last->second, 0); - if (last->first == "hrtf") { + if (last->first == "hrtf") + { this->set_hrtf(false); this->set_hrtf(true); } } - void set_reverb_parameters(float dry, float wet, float room_size, float damping, float mode) { - if (!active)return; + void set_reverb_parameters(float dry, float wet, float room_size, float damping, float mode) + { + if (!active) + return; verblib_set_dry(&m_reverbNode.reverb, dry); verblib_set_wet(&m_reverbNode.reverb, wet); verblib_set_room_size(&m_reverbNode.reverb, room_size); verblib_set_damping(&m_reverbNode.reverb, damping); verblib_set_mode(&m_reverbNode.reverb, mode); } - void set_delay_parameters(float dry, float wet, float dcay) { - if (!active)return; + void set_delay_parameters(float dry, float wet, float dcay) + { + if (!active) + return; ma_delay_node_set_dry(&m_delayNode, dry); ma_delay_node_set_wet(&m_delayNode, wet); ma_delay_node_set_decay(&m_delayNode, dcay); } - void set_position(float listener_x, float listener_y, float listener_z, float source_x, float source_y, float source_z, double theta, float pan_step, float volume_step, float behind_pitch_decrease, float start_pan, float start_volume, float start_pitch) { - if (!active) return; + void set_position(float listener_x, float listener_y, float listener_z, float source_x, float source_y, float source_z, double theta, float pan_step, float volume_step, float behind_pitch_decrease, float start_pan, float start_volume, float start_pitch) + { + if (!active) + return; float delta_x = 0; float delta_y = 0; float delta_z = 0; @@ -1651,7 +1801,7 @@ class MINIAUDIO_IMPLEMENTATION sound { float final_pitch = start_pitch; float rotational_source_x = source_x; float rotational_source_y = source_y; - // First, we calculate the x and y based on the theta the listener is facing. + // First, we calculate the x and y based on the theta the listener is facing. if (theta > 0.0) { rotational_source_x = (cos(theta) * (source_x - listener_x)) - (sin(theta) * (source_y - listener_y)) + listener_x; @@ -1722,15 +1872,22 @@ class MINIAUDIO_IMPLEMENTATION sound { source_position->y = source_y; source_position->z = source_z; } - void set_position(const ngtvector* listener, const ngtvector* source, double theta, float pan_step, float volume_step, float behind_pitch_decrease, float start_pan, float start_volume, float start_pitch) { - if (!active)return; - if (source == nullptr || listener == nullptr)return; + void set_position(const ngtvector *listener, const ngtvector *source, double theta, float pan_step, float volume_step, float behind_pitch_decrease, float start_pan, float start_volume, float start_pitch) + { + if (!active) + return; + if (source == nullptr || listener == nullptr) + return; this->set_position(listener->x, listener->y, listener->z, source->x, source->y, source->z, theta, pan_step, volume_step, behind_pitch_decrease, start_pan, start_volume, start_pitch); } - void set_hrtf(bool hrtf) { - if (!active)return; - if (hrtf) { - if (effects.find("hrtf") != effects.end())return; + void set_hrtf(bool hrtf) + { + if (!active) + return; + if (hrtf) + { + if (effects.find("hrtf") != effects.end()) + return; binauralNodeConfig = ma_steamaudio_binaural_node_config_init(CHANNELS, iplAudioSettings, iplContext, iplHRTF); @@ -1743,8 +1900,10 @@ class MINIAUDIO_IMPLEMENTATION sound { effects["hrtf"] = &m_binauralNode; ma_sound_set_directional_attenuation_factor(handle_, 0); } - else { - if (effects.find("hrtf") != effects.end()) { + else + { + if (effects.find("hrtf") != effects.end()) + { ma_steamaudio_binaural_node_uninit(&m_binauralNode, NULL); effects["hrtf"] = nullptr; @@ -1754,38 +1913,48 @@ class MINIAUDIO_IMPLEMENTATION sound { auto last = --effects.end(); ma_node_attach_output_bus(handle_, 0, last->second, 0); - } - } } - bool get_hrtf() { + bool get_hrtf() + { return effects.find("hrtf") != effects.end(); } - ngtvector* get_listener_position() { + ngtvector *get_listener_position() + { listener_position->add_ref(); return listener_position; } - ngtvector* get_source_position() { + ngtvector *get_source_position() + { source_position->add_ref(); return source_position; } - void set_volume_step(float volume_step) { - if (!active)return; + void set_volume_step(float volume_step) + { + if (!active) + return; ma_sound_set_rolloff(handle_, volume_step); } - void set_pan_step(float pan_step) { - if (!active)return; + void set_pan_step(float pan_step) + { + if (!active) + return; ma_sound_set_directional_attenuation_factor(handle_, pan_step); } - void set_pitch_step(float pitch_step) { - if (!active)return; + void set_pitch_step(float pitch_step) + { + if (!active) + return; ma_sound_set_doppler_factor(handle_, pitch_step); } - bool seek(float new_position) { - if (!active) return false; + bool seek(float new_position) + { + if (!active) + return false; - if (new_position > this->get_length() || new_position <= 0.0f) return false; + if (new_position > this->get_length() || new_position <= 0.0f) + return false; // Convert milliseconds to PCM frames for seeking ma_uint64 pcm_frame = static_cast((new_position / 1000.0f) * SAMPLE_RATE); @@ -1794,79 +1963,107 @@ class MINIAUDIO_IMPLEMENTATION sound { return true; } - void set_looping(bool looping) { - if (!active)return; + void set_looping(bool looping) + { + if (!active) + return; ma_sound_set_looping(handle_, looping); } - bool get_looping()const { - if (!active)return false; + bool get_looping() const + { + if (!active) + return false; return ma_sound_is_looping(handle_); } - float get_pan() const { - if (!active)return -17435; + float get_pan() const + { + if (!active) + return -17435; float pan = 0; pan = ma_sound_get_pan(handle_); return pan * 100; } - void set_pan(float pan) { - if (!active)return; + void set_pan(float pan) + { + if (!active) + return; ma_sound_set_pan(handle_, pan / 100); } - float get_volume() const { - if (!active)return -17435; + float get_volume() const + { + if (!active) + return -17435; float volume = 0; volume = ma_sound_get_volume(handle_); return ma_volume_linear_to_db(volume); } - void set_volume(float volume) { - if (!active)return; - if (volume > 0 or volume < -100)return; + void set_volume(float volume) + { + if (!active) + return; + if (volume > 0 or volume < -100) + return; ma_sound_set_volume(handle_, ma_volume_db_to_linear(volume)); } - float get_pitch() const { - if (!active)return -17435; + float get_pitch() const + { + if (!active) + return -17435; float pitch = 0; pitch = ma_sound_get_pitch(handle_); return pitch * 100; } - void set_pitch(float pitch) { - if (!active)return; + void set_pitch(float pitch) + { + if (!active) + return; ma_sound_set_pitch(handle_, pitch / 100); } - void set_speed(float speed) { + void set_speed(float speed) + { } - float get_speed()const { + float get_speed() const + { return m_speed_config.playbackSpeed * 100; } - bool is_active() const { + bool is_active() const + { return active; } - bool is_playing() const { - if (!active)return false; + bool is_playing() const + { + if (!active) + return false; return ma_sound_is_playing(handle_); } - bool is_paused() const { - if (!active)return false; + bool is_paused() const + { + if (!active) + return false; return this->paused; } - float get_position() { - if (!active)return -17435; + float get_position() + { + if (!active) + return -17435; ma_uint64 position = 0; ma_sound_get_cursor_in_pcm_frames(handle_, &position); return static_cast(position) / SAMPLE_RATE * 1000.0f; } - float get_length() { - if (!active) return -17435; + float get_length() + { + if (!active) + return -17435; ma_uint64 length = 0; ma_sound_get_length_in_pcm_frames(handle_, &length); @@ -1875,86 +2072,107 @@ class MINIAUDIO_IMPLEMENTATION sound { return static_cast(length) / SAMPLE_RATE * 1000.0f; } - void set_length(float length = 0.0f) { - if (!active) return; + void set_length(float length = 0.0f) + { + if (!active) + return; - if (length > this->get_length()) return; + if (length > this->get_length()) + return; // Convert milliseconds back to PCM frames for setting stop time ma_uint64 pcm_frames = static_cast((length / 1000.0f) * SAMPLE_RATE); ma_sound_set_stop_time_in_pcm_frames(handle_, pcm_frames); } - float get_sample_rate() const { + float get_sample_rate() const + { float rate = SAMPLE_RATE; return rate; } }; -void set_sound_global_hrtf(bool hrtf) { +void set_sound_global_hrtf(bool hrtf) +{ sound_global_hrtf = hrtf; } -bool get_sound_global_hrtf() { +bool get_sound_global_hrtf() +{ return sound_global_hrtf; } -ma_result ma_encoder_write_callback(ma_encoder* encoder, const void* buffer, size_t bytesToWrite, size_t* pBytesWritten) { - if (encoder == nullptr) { +ma_result ma_encoder_write_callback(ma_encoder *encoder, const void *buffer, size_t bytesToWrite, size_t *pBytesWritten) +{ + if (encoder == nullptr) + { return MA_INVALID_ARGS; } - MemoryStream* stream = reinterpret_cast(encoder->pUserData); - if (buffer == nullptr || stream == nullptr)return MA_INVALID_ARGS; - stream->write((const char*)buffer, bytesToWrite); + MemoryStream *stream = reinterpret_cast(encoder->pUserData); + if (buffer == nullptr || stream == nullptr) + return MA_INVALID_ARGS; + stream->write((const char *)buffer, bytesToWrite); return MA_SUCCESS; } - - -ma_result ma_encoder_seek_callback(ma_encoder* pEncoder, ma_int64 offset, ma_seek_origin origin) { - MemoryStream* stream = reinterpret_cast(pEncoder->pUserData); +ma_result ma_encoder_seek_callback(ma_encoder *pEncoder, ma_int64 offset, ma_seek_origin origin) +{ + MemoryStream *stream = reinterpret_cast(pEncoder->pUserData); seek_origin so; - switch (origin) { - case ma_seek_origin_start: { + switch (origin) + { + case ma_seek_origin_start: + { so = seek_origin_start; break; } - case ma_seek_origin_current: { + case ma_seek_origin_current: + { so = seek_origin_current; break; } - case ma_seek_origin_end: { + case ma_seek_origin_end: + { so = seek_origin_end; break; } - default:return MA_ERROR; + default: + return MA_ERROR; } stream->seek(so, offset); return MA_SUCCESS; } -class MINIAUDIO_IMPLEMENTATION audio_encoder { +class MINIAUDIO_IMPLEMENTATION audio_encoder +{ public: MemoryStream stream; ma_encoder_config encoderConfig; ma_encoder encoder; - void AddRef()const { + void AddRef() const + { ref += 1; } - void Release() { - if (--ref < 1) { + void Release() + { + if (--ref < 1) + { delete this; } } - audio_encoder() : stream(0), ref(1) { + audio_encoder() : stream(0), ref(1) + { encoderConfig = ma_encoder_config_init(ma_encoding_format_wav, ma_format_s16, 2, 44100); ma_encoder_init(ma_encoder_write_callback, ma_encoder_seek_callback, &stream, &encoderConfig, &encoder); } - ~audio_encoder() { + ~audio_encoder() + { ma_encoder_uninit(&encoder); } - void encode(const std::string& audio_data) { + void encode(const std::string &audio_data) + { ma_encoder_write_pcm_frames(&encoder, audio_data.c_str(), audio_data.size(), nullptr); } - std::string get_data() { + std::string get_data() + { stream.seek(0); size_t dataSize = stream.size(); std::vector buffer(dataSize); @@ -1966,20 +2184,23 @@ class MINIAUDIO_IMPLEMENTATION audio_encoder { mutable int ref = 0; }; -void audio_recorder_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { - audio_encoder* encoder = static_cast(pDevice->pUserData); +void audio_recorder_callback(ma_device *pDevice, void *pOutput, const void *pInput, ma_uint32 frameCount) +{ + audio_encoder *encoder = static_cast(pDevice->pUserData); ma_encoder_write_pcm_frames(&encoder->encoder, pInput, frameCount, nullptr); (void)pOutput; } -class MINIAUDIO_IMPLEMENTATION audio_recorder { +class MINIAUDIO_IMPLEMENTATION audio_recorder +{ public: audio_encoder encoder; ma_device_config deviceConfig; ma_device recording_device; - void start() { + void start() + { deviceConfig = ma_device_config_init(ma_device_type_capture); deviceConfig.capture.format = ma_format_s16; deviceConfig.capture.channels = 2; @@ -1991,34 +2212,39 @@ class MINIAUDIO_IMPLEMENTATION audio_recorder { ma_device_start(&recording_device); } - void stop() { + void stop() + { ma_encoder_uninit(&encoder.encoder); ma_device_uninit(&recording_device); } - std::string get_data() { + std::string get_data() + { return encoder.get_data(); } }; - -ma_result audio_stream_callback(ma_decoder* pDecoder, void* buffer, size_t bytesToRead, size_t* pBytesRead) { - string temp((char*)buffer, bytesToRead); +ma_result audio_stream_callback(ma_decoder *pDecoder, void *buffer, size_t bytesToRead, size_t *pBytesRead) +{ + string temp((char *)buffer, bytesToRead); temp.resize(bytesToRead); - string* data = (string*)pDecoder->pUserData; + string *data = (string *)pDecoder->pUserData; *data = temp; return MA_SUCCESS; } -ma_result audio_stream_seek_callback(ma_decoder* pDecoder, ma_int64 byteOffset, ma_seek_origin origin) { +ma_result audio_stream_seek_callback(ma_decoder *pDecoder, ma_int64 byteOffset, ma_seek_origin origin) +{ return MA_SUCCESS; } -class audio_stream { +class audio_stream +{ public: ma_device_config deviceConfig; ma_device device; ma_decoder decoder; - audio_stream() { + audio_stream() + { deviceConfig = ma_device_config_init(ma_device_type_playback); deviceConfig.playback.format = ma_format_f32; deviceConfig.playback.channels = 2; @@ -2027,16 +2253,15 @@ class audio_stream { deviceConfig.pUserData = &decoder; // ma_device_init(NULL, &deviceConfig, &recording_device); - } }; +sound *fsound(const string &filename) { return new sound(filename); } +audio_recorder *faudio_recorder() { return new audio_recorder; } +audio_encoder *faudio_encoder() { return new audio_encoder; } -sound* fsound(const string& filename) { return new sound(filename); } -audio_recorder* faudio_recorder() { return new audio_recorder; } -audio_encoder* faudio_encoder() { return new audio_encoder; } - -void register_sound(asIScriptEngine* engine) { +void register_sound(asIScriptEngine *engine) +{ engine->RegisterFuncdef("void sound_end_callback(const ?&in=null)"); engine->RegisterGlobalFunction("void set_audio_period_size(uint)property", asFUNCTION(set_audio_period_size), asCALL_CDECL); engine->RegisterGlobalFunction("void set_sound_storage(const string &in folder_name)property", asFUNCTION(set_sound_storage), asCALL_CDECL); @@ -2082,7 +2307,7 @@ void register_sound(asIScriptEngine* engine) { engine->RegisterObjectMethod(_O("sound"), "void set_delay_parameters(float dry, float wet, float dcay)const", asMETHOD(sound, set_delay_parameters), asCALL_THISCALL); engine->RegisterObjectMethod(_O("sound"), "void set_position(float listener_x, float listener_y, float listener_z, float source_x, float source_y, float source_z, double theta = 0.0, float pan_step = 5, float volume_step = 0.5, float behind_pitch_decrease = 0.0, float start_pan = 0, float start_volume = 0, float start_pitch = 0)const", asMETHODPR(sound, set_position, (float listener_x, float listener_y, float listener_z, float source_x, float source_y, float source_z, double theta, float pan_step, float volume_step, float behind_pitch_decrease, float start_pan, float start_volume, float start_pitch), void), asCALL_THISCALL); - engine->RegisterObjectMethod(_O("sound"), "void set_position(const vector@ listener = null, const vector@ source = null, double theta = 0.0, float pan_step = 5, float volume_step = 0.5, float behind_pitch_decrease = 0.0, float start_pan = 0, float start_volume = 0, float start_pitch = 0)const", asMETHODPR(sound, set_position, (const ngtvector*, const ngtvector*, double theta, float pan_step, float volume_step, float behind_pitch_decrease, float start_pan, float start_volume, float start_pitch), void), asCALL_THISCALL); + engine->RegisterObjectMethod(_O("sound"), "void set_position(const vector@ listener = null, const vector@ source = null, double theta = 0.0, float pan_step = 5, float volume_step = 0.5, float behind_pitch_decrease = 0.0, float start_pan = 0, float start_volume = 0, float start_pitch = 0)const", asMETHODPR(sound, set_position, (const ngtvector *, const ngtvector *, double theta, float pan_step, float volume_step, float behind_pitch_decrease, float start_pan, float start_volume, float start_pitch), void), asCALL_THISCALL); engine->RegisterObjectMethod(_O("sound"), "void set_hrtf(bool hrtf = true)const property", asMETHOD(sound, set_hrtf), asCALL_THISCALL); engine->RegisterObjectMethod(_O("sound"), "bool get_hrtf()const property", asMETHOD(sound, get_hrtf), asCALL_THISCALL); @@ -2113,5 +2338,4 @@ void register_sound(asIScriptEngine* engine) { engine->RegisterGlobalFunction("bool get_sound_global_hrtf()property", asFUNCTION(get_sound_global_hrtf), asCALL_CDECL); engine->RegisterGlobalFunction("void set_spatial_blend_max_distance(float)property", asFUNCTION(set_spatial_blend_max_distance), asCALL_CDECL); engine->RegisterGlobalFunction("float get_spatial_blend_max_distance()property", asFUNCTION(get_spatial_blend_max_distance), asCALL_CDECL); - }