2

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?

user98874
  • 189
  • 1
  • 10
  • 1
    I haven't messed around with Accelerate framework outside of some matrix manipulation but you may want to look into the EZAudio framework (https://github.com/syedhali/EZAudio). Why reinvent the wheel when you don't have to :) – Russell Oct 15 '15 at 20:23
  • 1
    This is an obtuse comment, but I feel compelled to make it! The OP's question is not so much about re-inventing the wheel as making his own wheel, which (IMHO) is a Good Thing To Be Able To Do. Too many folks just rely on other folks' implementations. – Grimxn Oct 15 '15 at 23:04

1 Answers1

0

An FFT (alone) will not find just fundamental pitch frequencies within most polyphonic music. Instead, it will find all the overtones and harmonic frequencies as well, which may well dominate over any fundamental pitch frequencies. It may even miss some fundamental pitch frequencies buried in low frequency noise.

For algorithms more suitable than a bare FFT, there are many polyphonic pitch estimation research papers over on the MIREX forum: http://www.music-ir.org/mirex/wiki/2015:Multiple_Fundamental_Frequency_Estimation_%26_Tracking

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Thank you, I'll look into it. How would you suggest finding the fundamental frequencies? – user98874 Oct 19 '15 at 17:15
  • AFAIK, for the general case, that may still be an unsolved or only recently solved research topic. Thus, I suggest studying the latest research papers. – hotpaw2 Oct 19 '15 at 18:34