i'm trying to get the float data of a realtime mic input with AVAudioEngine. To proceed a fft and a special algorithm after the fft.
When i compile the code im becoming this output on the console:0x0000000000000000
What i doing wrong? Many thanks for help
Here is my code to get the float data:
let audioEngine  = AVAudioEngine()
override func loadView() {
    super.loadView()
    let inputNode = audioEngine.inputNode
    let bus = 0
    inputNode!.installTapOnBus(bus, bufferSize: 2048, format: inputNode!.inputFormatForBus(bus)) {
        (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
        print(buffer.floatChannelData[50])
    }
    audioEngine.prepare()
    do{
        try audioEngine.start()
    }catch{
        print("Error")
    }
}
floatChannelData is a pointer to a pointer, so if you want the first channel (which is all you'll get on iOS unless you plug in a stereo microphone), you can do this:
Try
let firstChannel = buffer.floatChannelData[0]
let arr = Array(UnsafeBufferPointer(start: firstChannel, count: Int(buffer.frameLength)))
// Do something with your array of Floats
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With