1

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.

vtruant
  • 273
  • 1
  • 12
  • I tried to use the mutableAudioBufferList to change the write destination using buffer[0].mData = myWritePtr but the convert method replace it with its original non mutableAudioBufferList data ptr. Any advice ? – vtruant Jun 20 '17 at 06:21

0 Answers0