mirror of
https://github.com/mackron/miniaudio.git
synced 2026-04-22 00:06:59 +02:00
Update documentation.
This commit is contained in:
@@ -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's engine API.
|
||||
</p>
|
||||
<p>
|
||||
|
||||
In this example we'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'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'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.</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">"../miniaudio.h"</span>
|
||||
|
||||
<span style="color:#666666">#include</span> <span style="color:#cc3300"><phonon.h></span> <span style="color:#009900">/* Steam Audio */</span>
|
||||
<span style="color:#666666">#include</span> <span style="color:#cc3300"><stdint.h></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"><stdint.h></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 "unsigned int" 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'll need to use some
|
||||
intermediary buffers. We'll allocate one big buffer on the heap and then use offsets. We'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->iplAudioSettings.frameSize; <span style="color:#009900">/* Output buffer. */</span>
|
||||
|
||||
<span style="color:#009900">/* Only need input buffers if we're not using mono input. */</span>
|
||||
<span style="color:#0033ff">if</span> (channelsIn > 1) {
|
||||
heapSizeInBytes += <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * channelsIn * pBinauralNode->iplAudioSettings.frameSize;
|
||||
}
|
||||
heapSizeInBytes += <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * channelsOut * pBinauralNode->iplAudioSettings.frameSize; <span style="color:#009900">/* Output buffer. */</span>
|
||||
heapSizeInBytes += <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * channelsIn * pBinauralNode->iplAudioSettings.frameSize; <span style="color:#009900">/* Input buffer. */</span>
|
||||
|
||||
pBinauralNode->_pHeap = ma_malloc(heapSizeInBytes, pAllocationCallbacks);
|
||||
<span style="color:#0033ff">if</span> (pBinauralNode->_pHeap == NULL) {
|
||||
@@ -461,7 +474,7 @@ MA_API <span style="color:#0099cc">ma_result</span> ma_steamaudio_binaural_node_
|
||||
pBinauralNode->ppBuffersOut[0] = (<span style="color:#0033ff">float</span>*)pBinauralNode->_pHeap;
|
||||
pBinauralNode->ppBuffersOut[1] = (<span style="color:#0033ff">float</span>*)ma_offset_ptr(pBinauralNode->_pHeap, <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * pBinauralNode->iplAudioSettings.frameSize);
|
||||
|
||||
<span style="color:#0033ff">if</span> (channelsIn > 1) {
|
||||
{
|
||||
<span style="color:#0099cc">ma_uint32</span> iChannelIn;
|
||||
<span style="color:#0033ff">for</span> (iChannelIn = 0; iChannelIn < channelsIn; iChannelIn += 1) {
|
||||
pBinauralNode->ppBuffersIn[iChannelIn] = (<span style="color:#0033ff">float</span>*)ma_offset_ptr(pBinauralNode->_pHeap, <span style="color:#0033ff">sizeof</span>(<span style="color:#0033ff">float</span>) * pBinauralNode->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->playback.internalPeriodSizeInFrames;
|
||||
iplAudioSettings.frameSize = engineConfig.periodSizeInFrames;
|
||||
|
||||
|
||||
<span style="color:#009900">/* IPLContext */</span>
|
||||
|
||||
Reference in New Issue
Block a user