title: iOS - AudioUnitRender returned error -10876 on device, but running fine in simulator
body: <p>I encountered a problem which made me unable to capture input signal from microphone on the device (iPhone4). However, the code runs fine in the simulator.
  The code was originally adopted from Apple's MixerHostAudio class from MixerHost sample code. it runs fine both on device and in simulator before I started adding code for capturing mic input.
  Wondering if somebody could help me out. Thanks in advance!</p>
  
  <p>Here is my inputRenderCallback function which feeds signal into mixer input:</p>
  
  <pre><code>static OSStatus inputRenderCallback (
  
  void                        *inRefCon,
  AudioUnitRenderActionFlags  *ioActionFlags,
  const AudioTimeStamp        *inTimeStamp, 
  UInt32                      inBusNumber,
  UInt32                      inNumberFrames,
  AudioBufferList             *ioData) {
  recorderStructPtr recorderStructPointer     = (recorderStructPtr) inRefCon;
      // ....
          AudioUnitRenderActionFlags renderActionFlags;
          err = AudioUnitRender(recorderStructPointer-&gt;iOUnit, 
                                &amp;renderActionFlags, 
                                inTimeStamp, 
                                1, // bus number for input
                                inNumberFrames, 
                                recorderStructPointer-&gt;fInputAudioBuffer
                                );
                      // error returned is -10876
      // ....
  }
  </code></pre>
  
  <p>Here is my related initialization code:
  Now I keep only 1 input in the mixer, so the mixer seems redundant, but works fine before adding input capture code.</p>
  
  <pre><code>// Convenience function to allocate our audio buffers
  - (AudioBufferList *) allocateAudioBufferListByNumChannels:(UInt32)numChannels withSize:(UInt32)size {
      AudioBufferList*            list;
      UInt32                      i;
  
      list = (AudioBufferList*)calloc(1, sizeof(AudioBufferList) + numChannels * sizeof(AudioBuffer));
      if(list == NULL)
          return nil;
  
      list-&gt;mNumberBuffers = numChannels;
      for(i = 0; i &lt; numChannels; ++i) {
          list-&gt;mBuffers[i].mNumberChannels = 1;
          list-&gt;mBuffers[i].mDataByteSize = size;
          list-&gt;mBuffers[i].mData = malloc(size);
          if(list-&gt;mBuffers[i].mData == NULL) {
              [self destroyAudioBufferList:list];
              return nil;
          }
      }
      return list;
  }
  
  // initialize audio buffer list for input capture
  recorderStructInstance.fInputAudioBuffer = [self allocateAudioBufferListByNumChannels:1 withSize:4096];
  
  // I/O unit description
  AudioComponentDescription iOUnitDescription;
  iOUnitDescription.componentType          = kAudioUnitType_Output;
  iOUnitDescription.componentSubType       = kAudioUnitSubType_RemoteIO;
  iOUnitDescription.componentManufacturer  = kAudioUnitManufacturer_Apple;
  iOUnitDescription.componentFlags         = 0;
  iOUnitDescription.componentFlagsMask     = 0;
  
  // Multichannel mixer unit description
  AudioComponentDescription MixerUnitDescription;
  MixerUnitDescription.componentType          = kAudioUnitType_Mixer;
  MixerUnitDescription.componentSubType       = kAudioUnitSubType_MultiChannelMixer;
  MixerUnitDescription.componentManufacturer  = kAudioUnitManufacturer_Apple;
  MixerUnitDescription.componentFlags         = 0;
  MixerUnitDescription.componentFlagsMask     = 0;
  
  AUNode   iONode;         // node for I/O unit
  AUNode   mixerNode;      // node for Multichannel Mixer unit
  
  // Add the nodes to the audio processing graph
  result =    AUGraphAddNode (
                  processingGraph,
                  &amp;iOUnitDescription,
                  &amp;iONode);
  
  result =    AUGraphAddNode (
                  processingGraph,
                  &amp;MixerUnitDescription,
                  &amp;mixerNode
              );
  
  result = AUGraphOpen (processingGraph);
  
  // fetch mixer AudioUnit instance
  result =    AUGraphNodeInfo (
                  processingGraph,
                  mixerNode,
                  NULL,
                  &amp;mixerUnit
              );
  
  // fetch RemoteIO AudioUnit instance
  result =    AUGraphNodeInfo (
                               processingGraph,
                               iONode,
                               NULL,
                               &amp;(recorderStructInstance.iOUnit)
                               );
  
  
      // enable input of RemoteIO unit
  UInt32 enableInput = 1;
  AudioUnitElement inputBus = 1;
  result = AudioUnitSetProperty(recorderStructInstance.iOUnit, 
                                kAudioOutputUnitProperty_EnableIO, 
                                kAudioUnitScope_Input, 
                                inputBus, 
                                &amp;enableInput, 
                                sizeof(enableInput)
                                );
  // setup mixer inputs
  UInt32 busCount   = 1;
  
  result = AudioUnitSetProperty (
               mixerUnit,
               kAudioUnitProperty_ElementCount,
               kAudioUnitScope_Input,
               0,
               &amp;busCount,
               sizeof (busCount)
           );
  
  
  UInt32 maximumFramesPerSlice = 4096;
  
  result = AudioUnitSetProperty (
               mixerUnit,
               kAudioUnitProperty_MaximumFramesPerSlice,
               kAudioUnitScope_Global,
               0,
               &amp;maximumFramesPerSlice,
               sizeof (maximumFramesPerSlice)
           );
  
  
  for (UInt16 busNumber = 0; busNumber &lt; busCount; ++busNumber) {
  
      // set up input callback
      AURenderCallbackStruct inputCallbackStruct;
      inputCallbackStruct.inputProc        = &amp;inputRenderCallback;
  inputCallbackStruct.inputProcRefCon  = &amp;recorderStructInstance;
  
      result = AUGraphSetNodeInputCallback (
                   processingGraph,
                   mixerNode,
                   busNumber,
                   &amp;inputCallbackStruct
               );
  
              // set up stream format
      AudioStreamBasicDescription mixerBusStreamFormat;
      size_t bytesPerSample = sizeof (AudioUnitSampleType);
  
      mixerBusStreamFormat.mFormatID          = kAudioFormatLinearPCM;
      mixerBusStreamFormat.mFormatFlags       = kAudioFormatFlagsAudioUnitCanonical;
      mixerBusStreamFormat.mBytesPerPacket    = bytesPerSample;
      mixerBusStreamFormat.mFramesPerPacket   = 1;
      mixerBusStreamFormat.mBytesPerFrame     = bytesPerSample;
      mixerBusStreamFormat.mChannelsPerFrame  = 2;
      mixerBusStreamFormat.mBitsPerChannel    = 8 * bytesPerSample;
      mixerBusStreamFormat.mSampleRate        = graphSampleRate;
  
      result = AudioUnitSetProperty (
                                     mixerUnit,
                                     kAudioUnitProperty_StreamFormat,
                                     kAudioUnitScope_Input,
                                     busNumber,
                                     &amp;mixerBusStreamFormat,
                                     sizeof (mixerBusStreamFormat)
                                     );
  
  
  }
  
  // set sample rate of mixer output
  result = AudioUnitSetProperty (
               mixerUnit,
               kAudioUnitProperty_SampleRate,
               kAudioUnitScope_Output,
               0,
               &amp;graphSampleRate,
               sizeof (graphSampleRate)
           );
  
  
  // connect mixer output to RemoteIO
  result = AUGraphConnectNodeInput (
               processingGraph,
               mixerNode,         // source node
               0,                 // source node output bus number
               iONode,            // destination node
               0                  // desintation node input bus number
           );
  
  
  // initialize AudioGraph
  result = AUGraphInitialize (processingGraph);
  
  // start AudioGraph
  result = AUGraphStart (processingGraph);
  
  // enable mixer input
  result = AudioUnitSetParameter (
                       mixerUnit,
                       kMultiChannelMixerParam_Enable,
                       kAudioUnitScope_Input,
                       0, // bus number
                       1, // on
                       0
                    );
  </code></pre>