title: swift FFT chunk audio file to get Amplitude
body: <p>i need your help. in want to use the FFT on my audio file. i want to cut my audio file in more little buffer array and use my FFT with all sub buffer. </p>
  
  <p>why ?? because i need to know and see (with plot data) how my fréquence have particularity. i want to know, how a noise start in my audio file.  </p>
  
  <p>that is my FFT code . i dont know what im doing wrong.</p>
  
  <p>thx for your help</p>
  
  <p>EDITING CODE</p>
  
  <pre><code>func FFT (buffer: AVAudioPCMBuffer){
  
      let frameCount = buffer.frameCapacity
      let log2n = UInt(round(log2(Double(frameCount))))
  
      print (" log2n \(log2n)");
  
      let bufferSizePOT = Int(1 &lt;&lt; log2n)
  
      print (" bufferSizePot \(bufferSizePOT)");
      let inputCount = bufferSizePOT / 2
      let fftSetup = vDSP_create_fftsetup(log2n, Int32(kFFTRadix2))
  
      var realp = [Float](repeating: 0, count: inputCount)
      var imagp = [Float](repeating: 0, count: inputCount)
      var output = DSPSplitComplex(realp: &amp;realp, imagp: &amp;imagp)
  
  
      let windowSize = bufferSizePOT
      var transferBuffer = [Float](repeating: 0, count: windowSize)
      var window = [Float](repeating: 0, count: windowSize)
  
      vDSP_hann_window(&amp;window, vDSP_Length(windowSize), Int32(vDSP_HANN_NORM))
      vDSP_vmul((buffer.floatChannelData?.pointee)!, 1, window,
                1, &amp;transferBuffer, 1, vDSP_Length(windowSize))
  
      let temp = UnsafePointer&lt;Float&gt;(transferBuffer)
  
      temp.withMemoryRebound(to: DSPComplex.self, capacity: transferBuffer.count) { (typeConvertedTransferBuffer) -&gt; Void in
          vDSP_ctoz(typeConvertedTransferBuffer, 2, &amp;output, 1, vDSP_Length(inputCount))
  
      }
  
      // Do the fast Fourier forward transform, packed input to packed output
      vDSP_fft_zrip(fftSetup!, &amp;output, 1, log2n, FFTDirection(FFT_FORWARD))
  
  
      //---------------------------------------------------
  
  
      var magnitudes = [Float](repeating: 0.0, count: inputCount)
      vDSP_zvmags(&amp;output, 1, &amp;magnitudes, 1, vDSP_Length(inputCount))
  
      var normalizedMagnitudes = [Float](repeating: 0.0, count: inputCount)
      vDSP_vsmul(sqrt(x: magnitudes), 1, [2.0 / Float(inputCount)],
                 &amp;normalizedMagnitudes, 1, vDSP_Length(inputCount))
  
  
      for f in 0..&lt;normalizedMagnitudes.count
      {
          print("\(f), \(normalizedMagnitudes[f])")
      }
  
  
      vDSP_destroy_fftsetup(fftSetup)
  
  }
  </code></pre>