As the title suggests.
There is an old solution in Swift here. But I have hard time converting to Objective-C. Seems there is no Objective-C equivalent of UnsafeBufferPointer
As the title suggests.
There is an old solution in Swift here. But I have hard time converting to Objective-C. Seems there is no Objective-C equivalent of UnsafeBufferPointer
Objective-C has unsafe pointers built right into the language, so the conversion simply becomes:
- (NSData *)bufferToNSData:(AVAudioPCMBuffer *)buffer {
return [[NSData alloc] initWithBytes:buffer.floatChannelData[0] length:buffer.frameLength * 4];
}
N.B. this assumes mono 32 bit float data in the buffer. More work needs to be done to serialize all supported AVAudioPCMBuffer
formats to NSData
.