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
channel count of this node is always stereo.
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
will at times need to break down processing into smaller chunks for it's internal processing. The
node graph internally will read into a temporary buffer which is then mixed into the final output
buffer. This temporary buffer is allocated on the stack and is a fixed size. However, variability
comes into play because the channel count of the node is variable. It's not safe to just blindly
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.
time of the IPLBinauralEffect and IPLHRTF objects. To ensure miniaudio and Steam Audio are
consistent, you must set the period size in the engine config to be consistent with the frame size
you specify in your IPLAudioSettings object. If for some reason you want the period size of the
engine to be different to that of your Steam Audio configuration, you'll need to implement a sort
of buffering solution to your node.
*/
#define MINIAUDIO_IMPLEMENTATION
#include "../miniaudio.h"
......@@ -285,8 +279,16 @@ int main(int argc, char** argv)
/* The engine needs to be initialized first. */
engineConfig = ma_engine_config_init();
engineConfig.channels = CHANNELS;
engineConfig.sampleRate = SAMPLE_RATE;
engineConfig.channels = CHANNELS;
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;
result = ma_engine_init(&engineConfig, &g_engine);
......@@ -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
need not be exposed to the public API. There should be no need for the public API to require a
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;
......
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