Update documentation.

This commit is contained in:
David Reid
2022-01-07 21:08:07 +10:00
parent 27452d50ac
commit a547480277
24 changed files with 478 additions and 451 deletions
+25 -12
View File
@@ -245,25 +245,40 @@ a.doc-navigation-l4 {
<div style="background-color:#fff; padding-bottom:0em; border-top:solid 1px #003800; background-color:#eee;">
<table border="0" style="margin:0 auto; width:100%; border-collapse:collapse; border:solid 0px #000; table-layout:fixed;"><tr>
<td valign="top" style="width:20em; padding:0; margin:0; border-right:solid 0px #000;"><div style="position:relative; height:100%; width:100%; border:solid 0px #000; padding:0; margin:0;">
<a href="../index.html" class="doc-navigation">Documentation Home</a><a href="../manual/index.html" class="doc-navigation">Programming Manual</a><a href="index.html" class="doc-navigation ">Examples</a><a href="custom_backend.html" class="doc-navigation doc-navigation-l1 ">Custom Backend</a><a href="custom_decoder.html" class="doc-navigation doc-navigation-l1 ">Custom Decoder</a><a href="custom_decoder_engine.html" class="doc-navigation doc-navigation-l1 ">Custom Decoder Engine</a><a href="data_source_chaining.html" class="doc-navigation doc-navigation-l1 ">Data Source Chaining</a><a href="duplex_effect.html" class="doc-navigation doc-navigation-l1 ">Duplex Effect</a><a href="engine_advanced.html" class="doc-navigation doc-navigation-l1 ">Engine Advanced</a><a href="engine_effects.html" class="doc-navigation doc-navigation-l1 ">Engine Effects</a><a href="engine_hello_world.html" class="doc-navigation doc-navigation-l1 ">Engine Hello World</a><a href="engine_steamaudio.html" class="doc-navigation doc-navigation-l1 doc-navigation-active">Engine Steamaudio</a><a href="fixed_size_callback.html" class="doc-navigation doc-navigation-l1 ">Fixed Size Callback</a><a href="node_graph.html" class="doc-navigation doc-navigation-l1 ">Node Graph</a><a href="resource_manager.html" class="doc-navigation doc-navigation-l1 ">Resource Manager</a><a href="resource_manager_advanced.html" class="doc-navigation doc-navigation-l1 ">Resource Manager Advanced</a><a href="simple_capture.html" class="doc-navigation doc-navigation-l1 ">Simple Capture</a><a href="simple_duplex.html" class="doc-navigation doc-navigation-l1 ">Simple Duplex</a><a href="simple_enumeration.html" class="doc-navigation doc-navigation-l1 ">Simple Enumeration</a><a href="simple_loopback.html" class="doc-navigation doc-navigation-l1 ">Simple Loopback</a><a href="simple_looping.html" class="doc-navigation doc-navigation-l1 ">Simple Looping</a><a href="simple_mixing.html" class="doc-navigation doc-navigation-l1 ">Simple Mixing</a><a href="simple_playback.html" class="doc-navigation doc-navigation-l1 ">Simple Playback</a><a href="simple_playback_sine.html" class="doc-navigation doc-navigation-l1 ">Simple Playback Sine</a><a href="../api/index.html" class="doc-navigation" style="border-bottom:none;">API Reference</a></div></td><td valign="top" style="padding:1em; border-left:solid 1px #bbb;">
<a href="../index.html" class="doc-navigation">Documentation Home</a><a href="../manual/index.html" class="doc-navigation">Programming Manual</a><a href="index.html" class="doc-navigation ">Examples</a><a href="custom_backend.html" class="doc-navigation doc-navigation-l1 ">Custom Backend</a><a href="custom_decoder.html" class="doc-navigation doc-navigation-l1 ">Custom Decoder</a><a href="custom_decoder_engine.html" class="doc-navigation doc-navigation-l1 ">Custom Decoder Engine</a><a href="data_source_chaining.html" class="doc-navigation doc-navigation-l1 ">Data Source Chaining</a><a href="duplex_effect.html" class="doc-navigation doc-navigation-l1 ">Duplex Effect</a><a href="engine_advanced.html" class="doc-navigation doc-navigation-l1 ">Engine Advanced</a><a href="engine_effects.html" class="doc-navigation doc-navigation-l1 ">Engine Effects</a><a href="engine_hello_world.html" class="doc-navigation doc-navigation-l1 ">Engine Hello World</a><a href="engine_sdl.html" class="doc-navigation doc-navigation-l1 ">Engine Sdl</a><a href="engine_steamaudio.html" class="doc-navigation doc-navigation-l1 doc-navigation-active">Engine Steamaudio</a><a href="node_graph.html" class="doc-navigation doc-navigation-l1 ">Node Graph</a><a href="resource_manager.html" class="doc-navigation doc-navigation-l1 ">Resource Manager</a><a href="resource_manager_advanced.html" class="doc-navigation doc-navigation-l1 ">Resource Manager Advanced</a><a href="simple_capture.html" class="doc-navigation doc-navigation-l1 ">Simple Capture</a><a href="simple_duplex.html" class="doc-navigation doc-navigation-l1 ">Simple Duplex</a><a href="simple_enumeration.html" class="doc-navigation doc-navigation-l1 ">Simple Enumeration</a><a href="simple_loopback.html" class="doc-navigation doc-navigation-l1 ">Simple Loopback</a><a href="simple_looping.html" class="doc-navigation doc-navigation-l1 ">Simple Looping</a><a href="simple_mixing.html" class="doc-navigation doc-navigation-l1 ">Simple Mixing</a><a href="simple_playback.html" class="doc-navigation doc-navigation-l1 ">Simple Playback</a><a href="simple_playback_sine.html" class="doc-navigation doc-navigation-l1 ">Simple Playback Sine</a><a href="../api/index.html" class="doc-navigation" style="border-bottom:none;">API Reference</a></div></td><td valign="top" style="padding:1em; border-left:solid 1px #bbb;">
<h1>Engine Steamaudio</h1><p>
Demonstrates integration of Steam Audio with miniaudio&#39;s engine API.
</p>
<p>
In this example we&#39;ll apply a HRTF effect from Steam Audio. To do this a custom node will be
In this example a HRTF effect from Steam Audio will be applied. To do this a custom node will be
implemented which uses Steam Audio&#39;s IPLBinauralEffect and IPLHRTF objects.
</p>
<p>
By implementing this as a node, it can be plugged into any position within the graph. The output
channel count of this node is always stereo.</p>
channel count of this node is always stereo.
</p>
<p>
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&#39;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&#39;s not safe to just blindly
process the effect with the frame count specified in miniaudio&#39;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&#39;s set to something too big it&#39;ll exceed miniaudio&#39;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.</p>
<div style="font-family:monospace; border:solid 1px #003800; border-left:solid 0.5em #003800; margin:1em 0em; width:100%;"><pre style="margin:0.5em 1em; padding:0; line-height:125%; overflow-x:auto;">
<span style="color:#666666">#define</span> MINIAUDIO_IMPLEMENTATION
<span style="color:#666666">#include</span> <span style="color:#cc3300">&quot;../miniaudio.h&quot;</span>
<span style="color:#666666">#include</span> <span style="color:#cc3300">&lt;phonon.h&gt;</span> <span style="color:#009900">/* Steam Audio */</span>
<span style="color:#666666">#include</span> <span style="color:#cc3300">&lt;stdint.h&gt;</span> <span style="color:#009900">/* Required for uint32_t which is used by STEAMAUDIO_VERSION. */</span>
<span style="color:#666666">#include</span> <span style="color:#cc3300">&lt;stdint.h&gt;</span> <span style="color:#009900">/* Required for uint32_t which is used by STEAMAUDIO_VERSION. That dependency needs to be removed from Steam Audio - use IPLuint32 or &quot;unsigned int&quot; instead! */</span>
<span style="color:#666666">#define</span> FORMAT ma_format_f32 <span style="color:#009900">/* Must be floating point. */</span>
<span style="color:#666666">#define</span> CHANNELS 2 <span style="color:#009900">/* Must be stereo for this example. */</span>
@@ -439,17 +454,15 @@ MA_API <span style="color:#0099cc">ma_result</span> ma_steamaudio_binaural_node_
<span style="color:#0033ff">return</span> result;
}
heapSizeInBytes = 0;
<span style="color:#009900">/*
Unfortunately Steam Audio uses deinterleaved buffers for everything so we&#39;ll need to use some
intermediary buffers. We&#39;ll allocate one big buffer on the heap and then use offsets. We&#39;ll
use the frame size from the IPLAudioSettings structure as a basis for the size of the buffer.
*/</span>
heapSizeInBytes = <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * channelsOut * pBinauralNode-&gt;iplAudioSettings.frameSize; <span style="color:#009900">/* Output buffer. */</span>
<span style="color:#009900">/* Only need input buffers if we&#39;re not using mono input. */</span>
<span style="color:#0033ff">if</span> (channelsIn &gt; 1) {
heapSizeInBytes += <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * channelsIn * pBinauralNode-&gt;iplAudioSettings.frameSize;
}
heapSizeInBytes += <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * channelsOut * pBinauralNode-&gt;iplAudioSettings.frameSize; <span style="color:#009900">/* Output buffer. */</span>
heapSizeInBytes += <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * channelsIn * pBinauralNode-&gt;iplAudioSettings.frameSize; <span style="color:#009900">/* Input buffer. */</span>
pBinauralNode-&gt;_pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
<span style="color:#0033ff">if</span> (pBinauralNode-&gt;_pHeap == NULL) {
@@ -461,7 +474,7 @@ MA_API <span style="color:#0099cc">ma_result</span> ma_steamaudio_binaural_node_
pBinauralNode-&gt;ppBuffersOut[0] = (<span style="color:#0033ff">float</span>*)pBinauralNode-&gt;_pHeap;
pBinauralNode-&gt;ppBuffersOut[1] = (<span style="color:#0033ff">float</span>*)ma_offset_ptr(pBinauralNode-&gt;_pHeap, <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * pBinauralNode-&gt;iplAudioSettings.frameSize);
<span style="color:#0033ff">if</span> (channelsIn &gt; 1) {
{
<span style="color:#0099cc">ma_uint32</span> iChannelIn;
<span style="color:#0033ff">for</span> (iChannelIn = 0; iChannelIn &lt; channelsIn; iChannelIn += 1) {
pBinauralNode-&gt;ppBuffersIn[iChannelIn] = (<span style="color:#0033ff">float</span>*)ma_offset_ptr(pBinauralNode-&gt;_pHeap, <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * pBinauralNode-&gt;iplAudioSettings.frameSize * (channelsOut + iChannelIn));
@@ -547,7 +560,7 @@ MA_API <span style="color:#0099cc">ma_result</span> ma_steamaudio_binaural_node_
need not be exposed to the public API. There should be no need for the public API to require a
fixed sized update.
*/</span>
iplAudioSettings.frameSize = g_engine.pDevice-&gt;playback.internalPeriodSizeInFrames;
iplAudioSettings.frameSize = engineConfig.periodSizeInFrames;
<span style="color:#009900">/* IPLContext */</span>