AudioConverterComplexInputDataProc only works with NSLog

601 views Asked by At

I have the following AudioConverterComplexInputDataProc. the problem is, if I remove the NSLog() call the callback stalls on the 4th or so iteration and won't continue.

OSStatus MyAudioConverterComplexInputDataProc (
                                         AudioConverterRef             inAudioConverter,
                                         UInt32                        *ioNumberDataPackets,
                                         AudioBufferList               *ioData,
                                         AudioStreamPacketDescription  **outDataPacketDescription,
                                         void                          *inUserData
                                         )
{
    NSLog(@"Callback");

    BSAACEncoder *This = (__bridge BSAACEncoder*)inUserData;

    UInt32 framesAvailable = TPCircularBufferPeek(This->inputBuffer, NULL, This.audioFormat);

    int numBytes = MIN(*ioNumberDataPackets * This.audioFormat->mBytesPerPacket, framesAvailable * This.audioFormat->mBytesPerFrame);

    UInt32 framesToFetch = numBytes / This.audioFormat->mBytesPerFrame;

    AudioBufferList *sourceBuffer;
    if (framesToFetch > 0)
    {
        sourceBuffer = AllocateABL(This.audioFormat->mChannelsPerFrame, This.audioFormat->mBytesPerFrame, NO, framesToFetch);
        TPCircularBufferDequeueBufferListFrames(This->inputBuffer, &framesToFetch, sourceBuffer, NULL, This.audioFormat);
    }

    for (int i = 0; i < This.audioFormat->mChannelsPerFrame; i++)
    {
        ioData->mBuffers[i].mNumberChannels = 1;
        ioData->mBuffers[i].mData           = (numBytes > 0) ? sourceBuffer->mBuffers[i].mData : NULL;
        ioData->mBuffers[i].mDataByteSize   = numBytes;
    }

    *ioNumberDataPackets = numBytes / This.audioFormat->mBytesPerPacket;

    return noErr;
}
1

There are 1 answers

0
Anthony Myatt On

Got it working.

if (framesToFetch == 0)
{
    *ioNumberDataPackets = 0;
    return 100; // Keep asking for data
}

Apparently if you return no data, you must also return '100' to indicate that more information will be available.