我正在尝试分析声音文件(.m4a)以获取随时间变化的幅度并制作图表。我在网上找到了一些效果很好的代码(如下)。但是,我想另外过滤掉所有不在目标频率范围内的声音。例如,我只想绘制 1900-2100 Hz 之间的声音。我怎样才能做到这一点?
var processingBuffer = [Float](repeating: 0.0, count: Int(readFile.arrayFloatValues.count))
let sampleCount = vDSP_Length(readFile.arrayFloatValues.count)
vDSP_vabs(readFile.arrayFloatValues, 1, &processingBuffer, 1, sampleCount);
let samplesPerPixel = 1
let filter = [Float](repeating: 1.0 / Float(samplesPerPixel), count: Int(samplesPerPixel))
let downSampledLength = Int(readFile.arrayFloatValues.count / samplesPerPixel)
var downSampledData = [Float](repeating:0.0, count:downSampledLength)
vDSP_desamp(processingBuffer,
vDSP_Stride(samplesPerPixel),
filter, &downSampledData,
vDSP_Length(downSampledLength),
vDSP_Length(samplesPerPixel))
readFile.points = downSampledData.map{CGFloat($0)}
编辑
录音实际上是在更早的时间从设备的麦克风录制的。在录制阶段应用过滤器是否更容易?