Commit feea2649 authored by David Reid's avatar David Reid

Update Steam Audio example.

parent d36a2ef6
...@@ -8,17 +8,11 @@ By implementing this as a node, it can be plugged into any position within the g ...@@ -8,17 +8,11 @@ By implementing this as a node, it can be plugged into any position within the g
channel count of this node is always stereo. channel count of this node is always stereo.
Steam Audio requires fixed sized processing, the size of which must be specified at initialization Steam Audio requires fixed sized processing, the size of which must be specified at initialization
time of the IPLBinauralEffect and IPLHRTF objects. This creates a problem because the node graph time of the IPLBinauralEffect and IPLHRTF objects. To ensure miniaudio and Steam Audio are
will at times need to break down processing into smaller chunks for it's internal processing. The consistent, you must set the period size in the engine config to be consistent with the frame size
node graph internally will read into a temporary buffer which is then mixed into the final output you specify in your IPLAudioSettings object. If for some reason you want the period size of the
buffer. This temporary buffer is allocated on the stack and is a fixed size. However, variability engine to be different to that of your Steam Audio configuration, you'll need to implement a sort
comes into play because the channel count of the node is variable. It's not safe to just blindly of buffering solution to your node.
process the effect with the frame count specified in miniaudio's node processing callback. Doing so
results in glitching. To work around this, this example is just setting the update size to a known
value that works (256). If it's set to something too big it'll exceed miniaudio's processing size
used by the node graph. Alternatively you could use some kind of intermediary cache which
accumulates input data until enough is available and then do the processing. Ideally, Steam Audio
would support variable sized updates which would avoid this whole mess entirely.
*/ */
#define MINIAUDIO_IMPLEMENTATION #define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h" #include "../miniaudio.h"
...@@ -285,8 +279,16 @@ int main(int argc, char** argv) ...@@ -285,8 +279,16 @@ int main(int argc, char** argv)
/* The engine needs to be initialized first. */ /* The engine needs to be initialized first. */
engineConfig = ma_engine_config_init(); engineConfig = ma_engine_config_init();
engineConfig.channels = CHANNELS; engineConfig.channels = CHANNELS;
engineConfig.sampleRate = SAMPLE_RATE; engineConfig.sampleRate = SAMPLE_RATE;
/*
Steam Audio requires processing in fixed sized chunks. Setting the period size in the engine config will
ensure our updates happen in predicably sized chunks as required by Steam Audio.
Note that the configuration of Steam Audio below (IPLAudioSettings) will use this variable to specify the
update size to ensure it remains consistent.
*/
engineConfig.periodSizeInFrames = 256; engineConfig.periodSizeInFrames = 256;
result = ma_engine_init(&engineConfig, &g_engine); result = ma_engine_init(&engineConfig, &g_engine);
...@@ -306,6 +308,9 @@ int main(int argc, char** argv) ...@@ -306,6 +308,9 @@ int main(int argc, char** argv)
be documented. If this is for some kind of buffer management with FFT or something, then this be documented. If this is for some kind of buffer management with FFT or something, then this
need not be exposed to the public API. There should be no need for the public API to require a need not be exposed to the public API. There should be no need for the public API to require a
fixed sized update. fixed sized update.
It's important that this be set to the periodSizeInFrames specified in the engine config above.
This ensures updates on both the miniaudio side and the Steam Audio side are consistent.
*/ */
iplAudioSettings.frameSize = engineConfig.periodSizeInFrames; iplAudioSettings.frameSize = engineConfig.periodSizeInFrames;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment