Не точный ответ, но я бы попробовал что-то вроде следующего:
func convertPacket(_ packet: AudioPacket) -> CMSampleBuffer? {
var data = packet.data
var asbd = packet.asbd
var magicCookie = packet.magicCookie
var blockBuffer: CMBlockBuffer?
var formatDescription: CMFormatDescription?
var sampleBuffer: CMSampleBuffer?
CMBlockBufferCreateWithMemoryBlock(
allocator: nil, memoryBlock: &data, blockLength: data.count,
blockAllocator: nil, customBlockSource: nil, offsetToData: 0,
dataLength: data.count, flags: 0, blockBufferOut: &blockBuffer
)
CMAudioFormatDescriptionCreate(
allocator: nil, asbd: &asbd, layoutSize: 0, layout: nil,
magicCookieSize: magicCookie.count, magicCookie: &magicCookie,
extensions: nil, formatDescriptionOut: &formatDescription
)
CMAudioSampleBufferCreateWithPacketDescriptions(
allocator: nil, dataBuffer: blockBuffer, dataReady: true,
makeDataReadyCallback: nil, refcon: nil, formatDescription: formatDescription!,
sampleCount: 1, // <- provide correct number
presentationTimeStamp: CMTime(seconds: packet.timestamp, preferredTimescale: 100),
packetDescriptions: nil, sampleBufferOut: &sampleBuffer
)
return sampleBuffer
}