title: How to simply play a CMSampleBufferRef audio data?
body: <p>I'm capturing audio within an <code>AVCaptureSession</code>, now I'm about to play it.</p>
  
  <p>I'm really not into lower level audio processing, so <a href="https://github.com/kstenerud/ObjectAL-for-iPhone" rel="nofollow"><strong><code>ObjectAL</code></strong></a> seems a fair choice for this, so I tried to get buffer pointer, some format information, then create an ObjectAL buffer.</p>
  
  <pre><code> -(void)captureOutput:(AVCaptureOutput*) captureOutput
  didOutputSampleBuffer:(CMSampleBufferRef) sampleBuffer
         fromConnection:(AVCaptureConnection*) connection
  {
      if ([captureOutput isKindOfClass:[AVCaptureAudioDataOutput class]])
      {
  
          // Get samples.
          CMBlockBufferRef audioBuffer = CMSampleBufferGetDataBuffer(sampleBuffer);
          size_t lengthAtOffset;
          size_t totalLength;
          char *samples;
          CMBlockBufferGetDataPointer(audioBuffer, 0, &amp;lengthAtOffset, &amp;totalLength, &amp;samples);
  
          // Get format.
          CMAudioFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuffer);
          const AudioStreamBasicDescription *description = CMAudioFormatDescriptionGetStreamBasicDescription(format);
  
          ALBuffer *openALbuffer = [ALBuffer bufferWithName:@"buffer just captured before"
                                                       data:sampleBuffer
                                                       size:totalLength
                                                     format:description-&gt;mFormatID
                                                  frequency:description-&gt;mSampleRate];
      }
  }
  </code></pre>
  
  <p>It says <code>Invalid Value</code>:</p>
  
  <pre><code>OAL Error: +[ALWrapper bufferDataStatic:format:data:size:frequency:]: Invalid Value (error code 0x0000a003)
  </code></pre>
  
  <p>ObjectAL actually hooks to some OpenAL stuff I did not get into, you may understand it better:<strong><a href="https://github.com/kstenerud/ObjectAL-for-iPhone/blob/master/ObjectAL/ObjectAL/OpenAL/ALBuffer.m" rel="nofollow"><code>ALBuffer.m</code></a></strong>, <a href="https://github.com/kstenerud/ObjectAL-for-iPhone/blob/master/ObjectAL/ObjectAL/OpenAL/ALWrapper.m#L1413" rel="nofollow"><strong><code>ALWrapper.m</code></strong></a></p>
  
  <h2><strong>Is there any format / buffer conversation</strong> I have to utilize before create such ObjectAL (OpenAL) buffer?</h2>