title: AudioQueue Output Callback only fires 3 times (nBuffers times)
body: <p>When I start an audio output process with <code>AudioQueueStart(out.queue, nil)</code>, the output callback only fires 3 times (which is the number of allocated buffers).</p>
  
  <p>Here is my Output callback code:</p>
  
  <pre><code>static void AQOutputCallback(void* aqr,
                               AudioQueueRef outQ,
                               AudioQueueBufferRef outQB)
  {
    AQCallbackStruct *aqc = (AQCallbackStruct *) aqr;
  
    NSLog(@"Out");
  
    // Check if AudioQueue is stopped
    if (!aqc-&gt;run) {
      NSLog(@"Stopped");
      return;
    }
  
    // Processing data
  
    // Check enqueue error
    int err = AudioQueueEnqueueBuffer(outQ, outQB, 0, NULL);
    if (err != noErr) NSLog(@"OutputCallback AudioQueueEnqueueBuffer() %d ", err);
    NSLog(@"Enqueued");
  }
  </code></pre>
  
  <p>I think it's due to the lack of buffers, but my output is:</p>
  
  <pre><code>Out
  Enqueued
  Out
  Enqueued
  Out
  Enqueued
  </code></pre>
  
  <p>So the first buffer is enqueued before the AudioQueue starts to fill the third one, it should not run out of buffers.</p>
  
  <p>What happens here ?</p>
  
  <h2>Edit: Setup code</h2>
  
  <pre><code>#define AUDIO_BUFFERS 3
  
  typedef struct AQCallbackStruct {
    AudioStreamBasicDescription mDataFormat;
    AudioQueueRef queue;
    AudioQueueBufferRef mBuffers[AUDIO_BUFFERS];
    unsigned long frameSize;
    BOOL *run;
  } AQCallbackStruct;
  
  // In some method
  AQCallbackStruct out;
  
  out.mDataFormat
  out.mDataFormat.mFormatID = kAudioFormatLinearPCM;
  out.mDataFormat.mSampleRate = 44100.0;
  out.mDataFormat.mChannelsPerFrame = 2;
  out.mDataFormat.mBitsPerChannel = 16;
  out.mDataFormat.mBytesPerPacket =
    out.mDataFormat.mBytesPerFrame =
      out.mDataFormat.mChannelsPerFrame * sizeof(short int);
  out.mDataFormat.mFramesPerPacket = 1;
  out.mDataFormat.mFormatFlags =
      kLinearPCMFormatFlagIsBigEndian
    | kLinearPCMFormatFlagIsSignedInteger
    | kLinearPCMFormatFlagIsPacked;
  
  out.frameSize = 735;
  
  int err;
  err = AudioQueueNewOutput(&amp;out.mDataFormat,
                            AQOutputCallback,
                            &amp;out,
                            CFRunLoopGetCurrent(),
                            kCFRunLoopCommonModes,
                            0,
                            &amp;out.queue);
  
  if (err != noErr) NSLog(@"AudioQueueNewOutput() error: %d", err);
  
  
  for (int i=0; i&lt;AUDIO_BUFFERS; i++) {         
    err = AudioQueueAllocateBuffer(out.queue, out.frameSize, &amp;out.mBuffers[i]);
    if (err != noErr) NSLog(@"Output AudioQueueAllocateBuffer() error: %d", err);
    out.mBuffers[i]-&gt;mAudioDataByteSize = out.frameSize;
  
    err = AudioQueueEnqueueBuffer(out.queue, out.mBuffers[i], 0, NULL);
    if (err != noErr) NSLog(@"Output AudioQueueEnqueueBuffer() error: %d", err);
  }
  
  AudioQueueStart(out.queue, nil);
  </code></pre>