我正试图从AVAudioPCMBufferSwift中生成一个谱图.我安装了一个tap AVAudioMixerNode并接收带有音频缓冲区的回调.我想将缓冲区中的信号转换为[Float:Float]字典,其中键表示频率,值表示相应频率上的音频幅度.
我尝试使用Apple的Accelerate框架,但我得到的结果似乎很可疑.我确定这只是我转换信号的方式.
我查看了这篇博客文章以供参考.
这是我有的:
self.audioEngine.mainMixerNode.installTapOnBus(0, bufferSize: 1024, format: nil, block: { buffer, when in
let bufferSize: Int = Int(buffer.frameLength)
// Set up the transform
let log2n = UInt(round(log2(Double(bufferSize))))
let fftSetup = vDSP_create_fftsetup(log2n, Int32(kFFTRadix2))
// Create the complex split value to hold the output of the transform
var realp = [Float](count: bufferSize/2, repeatedValue: 0)
var imagp = [Float](count: bufferSize/2, repeatedValue: 0)
var output = DSPSplitComplex(realp: &realp, imagp: &imagp)
// Now I need to …Run Code Online (Sandbox Code Playgroud)