将"AudioStreamPacketDescription"的代码转换成swift3.2

Convert code of "AudioStreamPacketDescription" into swift3.2

我正在将 Audio Queues Service 代码转换为 swift3.2,但我卡住了 here.i 不知道如何在 swift 更新版本中编写这行代码.

我想将下面的代码转换成 swift 3.2

player.packetDescs = UnsafeMutablePointer<AudioStreamPacketDescription>(malloc(sizeof(AudioStreamPacketDescription) * Int(player.numPacketsToRead)))

其中 player 对象是 :

 class Player {
        var playbackFile: AudioFileID? = nil
        var packetPosition: Int64 = 0
        var numPacketsToRead: UInt32 = 0
        var packetDescs: UnsafeMutablePointer<AudioStreamPacketDescription>? = nil
        var isDone = false
    }

我试过了:

let j = MemoryLayout.size(ofValue: AudioStreamPacketDescription.self) * Int(player.numPacketsToRead)                
player.packetDescs = UnsafeMutablePointer<AudioStreamPacketDescription>(malloc(j))

但这给我错误:

Cannot invoke initializer for type 'UnsafeMutablePointer' with an argument list of type '(UnsafeMutableRawPointer!)'

好的试试这个

let sizeTmp = MemoryLayout.size(ofValue: AudioStreamPacketDescription.self) * Int(player.numPacketsToRead)
let tmpPointer = UnsafeMutablePointer<AudioStreamPacketDescription>.allocate(capacity: sizeTmp)
player.packetDescs = tmpPointer