title: Audio Units: getting generated audio into a render callback
body: <p>I've been trying without success to manipulate the samples produced by kAudioUnitType_Generator audio units by attaching an AURenderCallbackStruct to the input of the audio unit right after.  I managed to get this working on OS X using the following simple graph:</p>
  
  <pre><code>(input callback) -&gt; multichannel mixer -&gt; (intput callback) -&gt; default output
  </code></pre>
  
  <p>But I've failed with the following (even simpler) graphs that start with a generator unit:</p>
  
  <pre><code>speech synthesis -&gt; (intput callback) -&gt; default output           | fails in render callback with kAudioUnitErr_Uninitialized
  audiofile player -&gt; (intput callback) -&gt; default output           | fails when scheduling file region with kAudioUnitErr_Uninitialized
  </code></pre>
  
  <p>I've tried just about everything I can think of, from setting ASBD format to sample rates, but I always get these errors.  Does anyone know how to setup a graph where we can manipulate samples from these nice generator units?</p>
  
  <p>Below is the failing render callback function and graph instantiation method for the attempt using speech synthesis.  The audiofile player is almost identical for this, except setting up the file playback, of course.  Both of these setups work if I remove the callback and add an AUGraphConnectNodeInput in it's place...</p>
  
  <pre><code>static OSStatus RenderCallback(void *inRefCon,
                                      AudioUnitRenderActionFlags *ioActionFlags,
                                      const AudioTimeStamp *inTimeStamp,
                                      UInt32 inBusNumber,
                                      UInt32 inNumberFrames,
                                      AudioBufferList *ioData) {
  
      AppDelegate *app = (AppDelegate *)inRefCon;
      AudioUnit inputUnit = app-&gt;_speechUnit;
      OSStatus status = noErr;
  
      status = AudioUnitRender(inputUnit, ioActionFlags, inTimeStamp, 0, inNumberFrames, ioData);
      // *** ERROR *** kAudioUnitErr_Uninitialized, code: -10867
  
      // ... insert processing code here...
  
      return status;
  }
  
  - (int)createSynthGraph {
      AUGRAPH_CHECK( NewAUGraph( &amp;_graph ) );
  
      AUNode speechNode, outputNode;
  
      // speech synthesizer
      AudioComponentDescription speechCD = {0};
      speechCD.componentType = kAudioUnitType_Generator;
      speechCD.componentSubType = kAudioUnitSubType_SpeechSynthesis;
      speechCD.componentManufacturer = kAudioUnitManufacturer_Apple;
  
      // output device (speakers)
      AudioComponentDescription outputCD = {0};
      outputCD.componentType = kAudioUnitType_Output;
      outputCD.componentSubType = kAudioUnitSubType_DefaultOutput;
      outputCD.componentManufacturer = kAudioUnitManufacturer_Apple;
  
      AUGRAPH_CHECK( AUGraphAddNode( _graph, &amp;outputCD, &amp;outputNode ) );
      AUGRAPH_CHECK( AUGraphAddNode( _graph, &amp;speechCD, &amp;speechNode ) );
  
      AUGRAPH_CHECK( AUGraphOpen( _graph ) );
      AUGRAPH_CHECK( AUGraphNodeInfo( _graph, outputNode, NULL, &amp;_outputUnit ) );
      AUGRAPH_CHECK( AUGraphNodeInfo( _graph, speechNode, NULL, &amp;_speechUnit ) );
  
      // setup stream formats:
      AudioStreamBasicDescription streamFormat = [self streamFormat];
      AU_CHECK( AudioUnitSetProperty( _speechUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 0, &amp;streamFormat, sizeof(streamFormat) ) );
  
      // setup callback:
      AURenderCallbackStruct callback;
      callback.inputProc = RenderCallback;
      callback.inputProcRefCon = self;
      AUGRAPH_CHECK( AUGraphSetNodeInputCallback ( _graph, outputNode, 0, &amp;callback ) );
  
      // init and start
      AUGRAPH_CHECK( AUGraphInitialize( _graph ) );
      AUGRAPH_CHECK( AUGraphStart( _graph ) );
      return 0;
  }
  </code></pre>