I am using the Accelerate Framework in Swift to perform FFT on an audio file. I am trying to find the fundamental frequencies of a polyphonic audio file using a Fast Fourier Transform.
I have performed a fast fourier transform on the audio file (correctly I think, but correct me if i'm wrong); although, I'm not sure where to go from here. Here is the code i'm using to perform the FFT:
let log2n = UInt(round(log2(Double(frameCount))))
let bufferSizePOT = Int(1 << log2n)
// Set up the transform
let fftSetup = vDSP_create_fftsetup(log2n, Int32(kFFTRadix2))
// create packed real input
var realp = [Float](count: bufferSizePOT/2, repeatedValue: 0)
var imagp = [Float](count: bufferSizePOT/2, repeatedValue: 0)
var output = DSPSplitComplex(realp: &realp, imagp: &imagp)
vDSP_ctoz(UnsafePointer<DSPComplex>(buffer.floatChannelData.memory), 2, &output, 1, UInt(bufferSizePOT / 2))
// Do the fast Fourier forward transform, packed input to packed output
vDSP_fft_zrip(fftSetup, &output, 1, log2n, Int32(FFT_FORWARD))
var fft = [Float](count:Int(bufferSizePOT / 2), repeatedValue:0.0)
let bufferOver2: vDSP_Length = vDSP_Length(bufferSizePOT / 2)
vDSP_zvmags(&output, 1, &fft, 1, bufferOver2)
// Release the setup
vDSP_destroy_fftsetup(fftSetup)
How do I find the fundamental frequencies from here? Thanks.
EDIT: From the research i've done, it seems like autocorrelation would be the best method for this task. Any ideas on how to perform an autocorrelation with this code?