title: Convert sound in Core Audio (iOS): 1 buffer 2 channels to 2 buffers and each has 1 channel?
body: <p>I used OrigamiEngine to play flac files. But the problem is I need to convert its output data (it used standard Core Audio with a custom static function) in <a href="https://github.com/ap4y/OrigamiEngine/blob/0bbdc3c5344b631e039a67a0aff481746e1aded3/OrigamiEngine/ORGMOutputUnit.m" rel="nofollow">this file</a>.</p>
  
  <p>Code:</p>
  
  <pre><code>static OSStatus Sound_Renderer(void *inRefCon,
                                 AudioUnitRenderActionFlags *ioActionFlags,
                                 const AudioTimeStamp  *inTimeStamp,
                                 UInt32 inBusNumber,
                                 UInt32 inNumberFrames,
                                 AudioBufferList  *ioData) {
      ORGMOutputUnit *output = (ORGMOutputUnit *)inRefCon;
      OSStatus err = noErr;
      void *readPointer = ioData-&gt;mBuffers[0].mData;
  
      int amountToRead, amountRead;
  
      amountToRead = inNumberFrames * (output-&gt;_format.mBytesPerPacket);
      amountRead = [output readData:(readPointer) amount:amountToRead];
  
      if (amountRead &lt; amountToRead) {
          int amountRead2;
          amountRead2 = [output readData:(readPointer+amountRead) amount:amountToRead-amountRead];
          amountRead += amountRead2;
      }
  
      ioData-&gt;mBuffers[0].mDataByteSize = amountRead;
      ioData-&gt;mBuffers[0].mNumberChannels = output-&gt;_format.mChannelsPerFrame;
      ioData-&gt;mNumberBuffers = 1;
  
      return err;
  }
  </code></pre>
  
  <p>So <code>ioData</code> has 1 buffer and 2 channels but I need vice versa - 2 buffers when each of them contains 1 channel. Or simply:</p>
  
  <p><code>LRLRLR...</code> -> <code>LLL...</code> + <code>RRR...</code></p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>In general I need to achieve something like the following:</p>
  
  <pre><code>ioData-&gt;mBuffers[0].mDataByteSize = ...;
  ioData-&gt;mBuffers[0].mNumberChannels = 1;
  ioData-&gt;mBuffers[1].mDataByteSize = ...;
  ioData-&gt;mBuffers[1].mNumberChannels = 1;
  ioData-&gt;mNumberBuffers = 2;
  </code></pre>