title: OSX CoreAudio play through, no Graph API, no CAPublicUtility
body: <p>This question is not about AU plugins, but about integrating audio units as building blocks of standalone application programs. After much trying I can't figure out what would be the simplest "graphless" connection of two AudioUnits, which would function as a "playthrough".</p>
  
  <p>I understand how powerful and sufficient a single audio unit of subtype <strong><em>kAudioUnitSubType_HALOutput</em></strong> can be in capturing, rendering, live-processing and forwarding of any audio input data. However, <strong>play through</strong> seems functional as long as working with either full-duplex audio hardware or creating  aggregate i/o device from built-in devices on user level.
  However, built-in devices are not full duplex and "aggregating" them also has certain disadvantage. Therefore I've decided to study a hard-coded two-unit connection possibility (<strong>without</strong> plunging into Graph API), and test its behavior with non-full-duplex hardware.</p>
  
  <p>Unfortunately, I have found neither comprehensive documentation nor example code for creating a simplest two-unit play through using only the straightforward connecting paradigm, as suggested in Apple Technical Note <strong>TN2091</strong>:</p>
  
  <pre class="lang-c prettyprint-override"><code>AudioUnitElement halUnitOutputBus    = 1; //1 suggested by TN2091 (else 0)
  AudioUnitElement outUnitInputElement = 1; //1 suggested by TN2091 (else 0)
  
  AudioUnitConnection halOutToOutUnitIn;
  halOutToOutUnitIn.sourceAudioUnit    = halAudioUnit;
  halOutToOutUnitIn.sourceOutputNumber = halUnitOutputBus;
  halOutToOutUnitIn.destInputNumber    = outUnitInputElement;
  
  AudioUnitSetProperty (outAudioUnit,                       // connection destination
                        kAudioUnitProperty_MakeConnection,  // property key
                        kAudioUnitScope_Input,              // destination scope
                        outUnitInputElement,                // destination element
                        &amp;halOutToOutUnitIn,                 // connection definition
                        sizeof (halOutToOutUnitIn)
                        );
  </code></pre>
  
  <p>My task is to keep off involving Graphs if possible, or even worse, CARingBuffers from so-called PublicUtility, which used to be plagued by bugs and latency issues for years and involve some ambitious assumptions, such as:</p>
  
  <pre class="lang-c prettyprint-override"><code>#if TARGET_OS_WIN32
  #include &lt;windows.h&gt;
  #include &lt;intrin.h&gt;
  #pragma intrinsic(_InterlockedOr)
  #pragma intrinsic(_InterlockedAnd)
  #else
  #include &lt;CoreFoundation/CFBase.h&gt;
  #include &lt;libkern/OSAtomic.h&gt;
  #endif
  </code></pre>
  
  <p>Thanks in advance for any hint which may point me in the right direction.</p>