I am trying to convert aurioTouch sample code FFTHelper class into Swift 3 for a generating a spectrogram in an iOS app using Swift 3. I am facing issues with UnsafePointer as I am unable to initialise a variable of this type. Getting error similar to: 'init' is unavailable: use 'withMemoryRebound....'.
I tried using withMemoryRebound.. but it is still failing.. This is valid in Swift 2.2 but not in Swift 3 var inAudioData: UnsafePointer = UnsafePointer (buffer.floatChannelData!.pointee);
buffer is a AVAudioPCMBuffer with audio data.
Please help in converting the above line into in to Swift 3.
Even though the vDSP_fft_zip() routine in the iOS Accelerate framework asks for parameters of type UnsafePointer< DSPSplitComplex >, Swift 3 allows using regular Swift arrays of Floats inside the DSPSplitComplex type.
var dataReal = [Float](repeating: 0.0, count: dataLen)
var dataImaginary = [Float](repeating: 0.0, count: dataLen)
// ... fill the real Float array with your data or audio samples ....
var myComplexData : DSPSplitComplex?
myComplexData = DSPSplitComplex(realp: &dataReal, imagp: &dataImaginary)
vDSP_fft_zip(fftSetup!, &myComplexData!, 1, logLen, Int32(FFT_FORWARD))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.