How to convert AVAudioPCMBuffer
to NSData
? If it should be done as
let data = NSData(bytes: buffer.floatChannelData, length: bufferLength)
then how to calculate bufferLength
?
And how to convert NSData
to AVAudioPCMBuffer
?
How to convert AVAudioPCMBuffer
to NSData
? If it should be done as
let data = NSData(bytes: buffer.floatChannelData, length: bufferLength)
then how to calculate bufferLength
?
And how to convert NSData
to AVAudioPCMBuffer
?
Copying the buffers is much easier if you copy via the audioBufferList API's. This also works no matter what the format is of the actual buffer.
Buffer length is frameCapacity * bytesPerFrame. Here are functions that can do conversion between NSData and AVAudioPCMBuffer.