I am working on a fft analysis in swift with ezaudio.
My problem is how can i get the all fft data from ezaudio.
I would make a algorithm to look is a frequency present when yes how much strong.
Example:
I looking in the FFT Data is the Frequency 2000Hz present, is this Frequency present how much energy it have.
Here my code:
import UIKit
import Accelerate
class ViewController: UIViewController, EZMicrophoneDelegate, EZAudioFFTDelegate{
private let ViewControllerFFTWindowSize: vDSP_Length = 4096
var microphone: EZMicrophone!
var fft: EZAudioFFTRolling!
override func loadView() {
super.loadView()
//setup audio session
let session = AVAudioSession.sharedInstance()
do{
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try session.setActive(true)
}catch{
print("Audio Session setup Fails")
}
microphone = EZMicrophone(delegate: self, startsImmediately: true)
fft = EZAudioFFTRolling(windowSize: ViewControllerFFTWindowSize, sampleRate: Float(microphone.audioStreamBasicDescription().mSampleRate), delegate: self)
microphone.startFetchingAudio()
}
func microphone(microphone: EZMicrophone!, hasAudioReceived buffer: UnsafeMutablePointer<UnsafeMutablePointer<Float>>, withBufferSize bufferSize: UInt32, withNumberOfChannels numberOfChannels: UInt32) {
fft.computeFFTWithBuffer(buffer[0], withBufferSize: bufferSize)
}
func fft(fft: EZAudioFFT!, updatedWithFFTData fftData: UnsafeMutablePointer<Float>, bufferSize: vDSP_Length) {
var maxF = fft.fftData
print(maxF)
var data = fft.fftData
print(data)
//here coming my algorithm
}
}
With this code its giving a strange output on console:
var data = fft.fftData
print(data)
Output: 0x00000001119be000
Many Many thanks for help