将 UnsafeMutablePointer 的实部提取为 Float 并将其存储在数组中
Extracting the real part of an UnsafeMutablePointer as a Float and storing that on an array
我有这个功能
func arrayForPointer<T>(_ pointer: UnsafePointer<T>, count: Int) -> [T] {
let buffer = UnsafeBufferPointer<T>(start: pointer, count: count)
return Array(buffer)
}
和这个电话
let arrayComplex = self.arrayForPointer(&output, count: 4)
我想通过 arrayComplex
枚举并将实部提取到常规数组中,例如
var arrayReal: [Float] = []
for item in arrayComplex {
let myFloat = item.realp \ get the real part of item
arrayReal.append(myFloat)
}
行
let myFloat = item.realp \ get the real part of item
不正确。
item
是一个 UnsafeMutablePointer<Float>
天哪,我该怎么做?
谢谢。
=======================
这是output
var A = [Float](repeating:0, count:samples/2);
var B = [Float](repeating:0, count:samples/2)
var output = DSPSplitComplex(realp: &A, imagp: &B)
试试这个。
修复您的函数调用:
let arrayComplex = arrayForPointer(output.realp, count: 4)
然后在你的循环中修复这一行:
let myFloat = item \ get the real part of item
我有这个功能
func arrayForPointer<T>(_ pointer: UnsafePointer<T>, count: Int) -> [T] {
let buffer = UnsafeBufferPointer<T>(start: pointer, count: count)
return Array(buffer)
}
和这个电话
let arrayComplex = self.arrayForPointer(&output, count: 4)
我想通过 arrayComplex
枚举并将实部提取到常规数组中,例如
var arrayReal: [Float] = []
for item in arrayComplex {
let myFloat = item.realp \ get the real part of item
arrayReal.append(myFloat)
}
行
let myFloat = item.realp \ get the real part of item
不正确。
item
是一个 UnsafeMutablePointer<Float>
天哪,我该怎么做?
谢谢。
=======================
这是output
var A = [Float](repeating:0, count:samples/2);
var B = [Float](repeating:0, count:samples/2)
var output = DSPSplitComplex(realp: &A, imagp: &B)
试试这个。
修复您的函数调用:
let arrayComplex = arrayForPointer(output.realp, count: 4)
然后在你的循环中修复这一行:
let myFloat = item \ get the real part of item