AudioConverterComplexInputDataProc仅适用于NSLog

时间:2013-12-19 00:36:14

标签: objective-c core-audio nslog

我有以下AudioConverterComplexInputDataProc。 问题是,如果我删除NSLog()调用,回调在第4次迭代时停止并且不会继续。

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 个答案:

答案 0 :(得分:0)

搞定了。

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

显然,如果您不返回任何数据,则还必须返回“100”以表示可以获得更多信息。