How do I use CoreAudio's AudioConverter to encode AAC in real-time?

后端 未结 2 1096
花落未央
花落未央 2020-12-08 12:10

All the sample code I can find that uses AudioConverterRef focuses on use cases where I have all the data up-front (such as converting a file on disk). They com

2条回答
  •  暖寄归人
    2020-12-08 12:57

    For future reference, there is a way way easier option.

    The CoreAudio header's state:

    If the callback returns an error, it must return zero packets of data. AudioConverterFillComplexBuffer will stop producing output and return whatever output has already been produced to its caller, along with the error code. This mechanism can be used when an input proc has temporarily run out of data, but has not yet reached end of stream.

    So, do exactly that. Instead of returning noErr with *ioNumberDataPackets = 0, return any error (just make one up, I used -1), and the already converted data will be returned, while the Audio Converter stays alive and does not need to be reset.

提交回复
热议问题