2

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")

    }


}
Paul R
  • 208,748
  • 37
  • 389
  • 560
norbu
  • 301
  • 1
  • 3
  • 7

1 Answers1

2

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
Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159