创建UnsafeMutablePointer <unsafemutablepointer <float>&gt; Swift 3中的参数

时间:2016-09-11 22:39:40

标签: swift signal-processing

Accelerate框架vDSP_biquadm()函数的Swift签名包括UnsafeMutablePointer<UnsafePointer<Float>>UnsafeMutablePointer<UnsafeMutablePointer<Float>>的参数类型。

如何在Swift 3中声明和创建这样的类型,然后使用对[Float]类型的几个Swift数组的引用来填充这些指针数组。

1 个答案:

答案 0 :(得分:1)

当您需要为UnsafeMutablePointer<T>参数传递多个值时,需要声明类型为[T]的变量(又名Array<T>)并将其作为inout参数传递。在您的情况下,TUnsafeMutablePointer<Float>

所以,如果你想从[Float]开始,你可能需要写这样的东西:

let input: [Float] = [/*...*/]
var output: [Float] = Array(repeating: 0, count: outputTotalSize)
input.withUnsafeBufferPointer {inBuf in
    let inputPtr = inBuf.baseAddress!
    output.withUnsafeMutableBufferPointer {outBuf in
        let outputPtr = outBuf.baseAddress!
        var pInputs: [UnsafePointer<Float>] = [inputPtr,/*...*/]
        var pOutputs: [UnsafeMutablePointer<Float>] = [outputPtr/*...*/]
        vDSP_biquadm(setup, &pInputs, inStride, &pOutputs, outStride, length)
    }
}