I would like to use AVAudioConverter to convert AVAudioPCMFormatFloat32 non interleaved 44.1 KHz buffer to AVAudioPCMFormatInt16 interleaved 48 KHz.
The incoming AVAudioPCMBuffer have 800 samples and I need to return AVAudioPCMBuffer with 1920 capacity.
AVAudioConverterOutputStatus conversionStatus = [_audioConverter convertToBuffer:audioPCMBuffer error:&conversionError withInputFromBlock:^AVAudioBuffer * _Nullable(AVAudioPacketCount inNumberOfPackets, AVAudioConverterInputStatus * _Nonnull outStatus) {
AVAudioPCMBuffer *dequeuedBuffer = [self dequeueIncomingAudioBuffer];
if (dequeuedBuffer != nil) {
*outStatus = AVAudioConverterInputStatus_HaveData;
} else {
*outStatus = AVAudioConverterInputStatus_NoDataNow;
}
return [dequeuedBuffer autorelease];
}];
When I have some audio, but not enough, the audio supplied in the block is converted into the outputBuffer.
When more incoming audio became available, I call convertToBuffer again and reuse the same outputBuffer.
The problem is that the converter instead of appending converted audio to the end, overrides the existing content.
Is there a way to append audio at the end instead of overriding it ?
If not I'll have to wait for having the requested number of samples before returning any incoming audio buffer.
Any advice would be greatly appreciated.