title: Recording with remote I/O, AudioUnitRender -50 return code
body: <p>I've been working on a frequency detection application for iOS and I'm having an issue filling a user-defined AudioBufferList with audio samples from the microphone.</p>
  
  <p>I'm getting a return code of -50 when I call AudioUnitRender in my InputCallback method. I believe this means one of my parameters is invalid. I'm guessing it's the AudioBufferList, but I haven't been able to figure out what is wrong with it. I think I've set it up so it matches the data format I've specified in my ASBD. </p>
  
  <p>Below is the remote I/O setup and function calls that I believe could be incorrect:</p>
  
  <p>ASBD:</p>
  
  <pre><code>size_t bytesPerSample = sizeof(AudioUnitSampleType);
  AudioStreamBasicDescription localStreamFormat = {0};
  localStreamFormat.mFormatID = kAudioFormatLinearPCM;
  localStreamFormat.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical;
  localStreamFormat.mBytesPerPacket = bytesPerSample;
  localStreamFormat.mBytesPerFrame = bytesPerSample;
  localStreamFormat.mFramesPerPacket = 1;
  localStreamFormat.mBitsPerChannel = 8 * bytesPerSample;
  localStreamFormat.mChannelsPerFrame = 2;
  localStreamFormat.mSampleRate = sampleRate;
  </code></pre>
  
  <p>InputCallback Declaration:</p>
  
  <pre><code>err = AudioUnitSetProperty(ioUnit, kAudioOutputUnitProperty_SetInputCallback, 
                             kAudioUnitScope_Input, 
                             kOutputBus, &amp;callbackStruct, sizeof(callbackStruct));
  </code></pre>
  
  <p>AudioBufferList Declaration:</p>
  
  <pre><code>// Allocate AudioBuffers
  bufferList = (AudioBufferList *)malloc(sizeof(AudioBuffer));
  bufferList-&gt;mNumberBuffers = 1;
  bufferList-&gt;mBuffers[0].mNumberChannels = 2;
  
  bufferList-&gt;mBuffers[0].mDataByteSize = 1024;
  bufferList-&gt;mBuffers[0].mData = calloc(256, sizeof(uint32_t));
  </code></pre>
  
  <p>InputCallback Function:</p>
  
  <pre><code>AudioUnit rioUnit = THIS-&gt;ioUnit;
  OSStatus renderErr;
  UInt32 bus1 = 1;
  renderErr = AudioUnitRender(rioUnit, ioActionFlags, inTimeStamp, bus1, inNumberFrames, THIS-&gt;bufferList);
  </code></pre>
  
  <p>A few things to note:</p>
  
  <ul>
  <li>Sample Rate = 22050 Hz</li>
  <li>Since the canonical format of remote I/O data is 8.24-bit fixed point, I'm assuming the samples are 32 bits each (or 4 bytes). Since an unsigned int is 4 bytes, I'm using that to allocate my audio buffer.</li>
  <li>I can get the same code to render audio correctly if I implement the audio data flow as PassThru rather than input only.</li>
  <li>I've already looked at <a href="http://atastypixel.com/blog/using-remoteio-audio-unit/" rel="noreferrer">Michael Tyson's blog post</a> on Remote I/O. Didn't see anything there different from what I'm doing.</li>
  </ul>
  
  <p>Thanks again, you all are awesome!</p>
  
  <p>Demetri</p>