0

我正在用 Swift 编写一个音频应用程序 - 一项任务包括对给定信号(麦克风输入或声音文件)的频率调制 - 因此我正在遍历缓冲区的所有帧,例如

let leftSourceData = readBuffer.floatChannelData?[0]
let rightSourceData = readBuffer.floatChannelData?[1]

let leftTargetData = renderBuffer.floatChannelData?[0]
let rightTargetData = renderBuffer.floatChannelData?[1]

for i in 0..<Int(readBuffer.frameLength) {

   // TODO: perform frequency modulation on source data, writing the results to target data
   leftTargetData[i] = ???
   rightTargetData[i] = ???
                   
}

频率调制的方程式很清楚 - 你可以在 Internet 上找到 s.th。像那样:

 f(t) = A sin(2*pi*fc*t + I * sin(2*pi*fm*t))
 with fc = carrier frequency, fm = modulation frequency
 and I = modulation index.

上述等式仅涵盖正弦输入信号-无论如何,我想调制任意信号-因此... 不同于纯正弦波。

对于幅度调制,我使用了以下算法(在循环内),它适用于 Swift 和 iOS:

let val: Double = sin(Double(2 * modulationFrequency) * Double(index) * Double.pi / Double(renderBuffer.format.sampleRate))
leftTargetData?[i] = Float(val) * (leftSourceData?[i] ?? 0)
rightTargetData?[i] = Float(val) * (rightSourceData?[i] ?? 0)

我怎样才能为 FM 做同样的事情?

4

0 回答 0