0

In the new iOS 9.1 when sets the AudioSession requesting a fix buffer size, the OS returns a smaller buffer. Why does that happen?? In the early versions <9.1 it worked as a charm

// Create a new audio input queue
OSStatus result = AudioQueueNewInput(&mAudioFormat,
                                     IOSAudioRecorder::RecorderCallback,
                                     this,                  // userData
                                     nullptr,               // run loop
                                     kCFRunLoopCommonModes, // run loop mode
                                     0,                     // flags
                                     &mAudioQueue);
if (result != 0)
{
    Logger::Error(this, "Failed to create new audio input queue, result: ", result);
    mAudioQueue = nullptr;
}
else
{
    // Allocate memory for the buffers
    for (unsigned int i = 0; i < mNumBuffers; i++)
    {
        AudioQueueAllocateBuffer(mAudioQueue, mBufferFrames * sizeof(short), &mInputBuffer[i]);
        mOutputBuffer[i] = new short[mBufferFrames];
    }
}

And in the "RecorderCallback" I receive buffers smaller than the requested.

Any clue why does that happen?

Loebre
  • 615
  • 2
  • 8
  • 23

1 Answers1

1

The buffer size specified by this Audio Queue allocation call is a maximum of what can be returned. The iOS device hardware is free to return less data. You app has to accommodate this potentially smaller size, and/or may have to concatenate several returned buffers (in a lock-free circular FIFO for example) if you need a fixed length chunk of data.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • 1
    yes, that is what I did, I implemented a circular buffer. It's just annoyed me that it didn't return what I asked for. Thank for your answer – Loebre Nov 07 '15 at 10:51
  • Do you have the sample code for the circular buffer? @Loebre – mAyA Dec 09 '20 at 19:19
  • 1
    If you google "iOS circular buffer GitHub" you will get multiple samples. – hotpaw2 Dec 09 '20 at 20:36
  • I did. Most of them came for Swift sample code. I needed an Objective C conversion. – mAyA Dec 10 '20 at 02:53