the frequency spectrum of an audio
Hum,I want to do an audio spectrum, I look for some information, it should be using FFT to get the job done. But I do not know hwo to use TAAE complete it.http://a4.mzstatic.com/us/r1000/117/Purple/v4/f5/11/8d/f5118df2-75ec-1839-3ef8-931e13177e15/mzl.tjcpmauv.320x480-75.jpg
Comments
There are some performant FFT functions in the accelerate framework. You should be able to google for some sample code.
One way to use TAAE would be to set up an AEAudioReceiver that processes the audio signal via FFT
Here's some (admittedly pretty basic) code I have lying around that'll pick the dominant frequency from audio samples - it also automatically buffers audio so it can perform the analysis in the appropriate-sized blocks. Note that this is just a chunk of code, you'll need to figure out what to do with it (but that's half the fun!):
Hey Matt,
Thanks a lot for the sample code, it's really helping me get a grasp on these functions, but I was wondering if you could explain why bin = (i+1)/2 instead of i+1?
Thanks,
Josh
Um...Mostly because I'm an idiot, @joshglick
I think I put that in while I was messing around and forgot to take it out. It means it was returning an octave lower than the actual frequency.
I've patched it up - and damn, that's a great catch!
I should also add that the above is an imprecise implementation, as the frequencies returned are truncated to just 1024 separate values. There's an approach you can then take to get the actual exact frequency by looking at the phase values, but I've not done that above.
Thanks for sharing this code. It's really helping me get a grasp on how to work with audio buffers.
The documentation for vDSP_ctoz says it takes complex interleaved data as the input. Is that the typical format of the incoming AudioBuffer in a playback callback? There's an audio format flag called kAudioFormatFlagIsNonInterleaved, but I think that's referring to whether the stereo channels are interleaved.
Also, how do you determine what strides to use for the two strides in vDSP_ctoz and the one in vDSP_fft_zrip?
Nevermind, I think I got it. vDSP_ctoz takes an input stride of two because it's treating linear real data as interleaved complex numbers, so it's taking all the odds and putting them into the imaginary component of the output.
I'm working on a spectrum analyzer and spectrum analyzer view if anybody is interested? Might be helpful.
I would definitely be interested in that, @RepublicOfApps would be a very handy addition!
@macguy - I'll let you know when it's available. I'll likely release it as a Cocoapod that depends on AmazingAudioEngine (which also comes as a cocoapod).
I'm about to dive into trying to build a pitch detector using FFT and phase detection Michael mentioned (roughly using this recently published blog post as my guide.) Has anyone's had success since this thread went dormant?
I think there's a mistake in setting discardBytes:
(Should
availableBytes
beavailableFrames
)Right you are, although I think it's meant to be: