Я смотрел на примеры FFTs в Swift, и все они, похоже, ConstUnsafePointer при использовании vDSP_ctozD как в примере ниже:constUnsafePointer нерешенным идентификатор в Swift FFT
import Foundation
import Accelerate
internal func spectrumForValues(signal: [Double]) -> [Double] {
// Find the largest power of two in our samples
let log2N = vDSP_Length(log2(Double(signal.count)))
let n = 1 << log2N
let fftLength = n/2
// This is expensive; factor it out if you need to call this function a lot
let fftsetup = vDSP_create_fftsetupD(log2N, FFTRadix(kFFTRadix2))
var fft = [Double](count:Int(n), repeatedValue:0.0)
// Generate a split complex vector from the real data
var realp = [Double](count:Int(fftLength), repeatedValue:0.0)
var imagp = realp
withExtendedLifetimes(realp, imagp) {
var splitComplex = DSPDoubleSplitComplex(realp:&realp, imagp:&imagp)
// Take the fft
vDSP_fft_zripD(fftsetup, &splitComplex, 1, log2N, FFTDirection(kFFTDirection_Forward))
// Normalize
var normFactor = 1.0/Double(2 * n)
vDSP_vsmulD(splitComplex.realp, 1, &normFactor, splitComplex.realp, 1, fftLength)
vDSP_vsmulD(splitComplex.imagp, 1, &normFactor, splitComplex.imagp, 1, fftLength)
// Zero out Nyquist
splitComplex.imagp[0] = 0.0
// Convert complex FFT to magnitude
vDSP_zvmagsD(&splitComplex, 1, &fft, 1, fftLength)
}
// Cleanup
vDSP_destroy_fftsetupD(fftsetup)
return fft
}
// To get rid of the `() ->() in` casting
func withExtendedLifetime<T>(x: T, f:() ->()) {
return Swift.withExtendedLifetime(x, f)
}
// In the spirit of withUnsafePointers
func withExtendedLifetimes<A0, A1>(arg0: A0, arg1: A1, f:() ->()) {
return withExtendedLifetime(arg0) { withExtendedLifetime(arg1, f) }
}
Однако, когда я пытаюсь использовать его в моем проекте этот ConstUnsafePointer рассматривается как неразрешенный идентификатор. Любой ключ, как это исправить? Заранее спасибо.
Он компилируется сейчас, спасибо за помощь! Можете ли вы указать мне в правильном направлении, как заставить микрофон записывать аудиоданные с помощью AVAudioRecorder в эту функцию FFT? – MKW
Это звучит как отдельный вопрос. – rickster