ios - audiokit:同时播放两个振荡器

标签 ios audio trigonometry mixer audiokit

你好,我正在使用 AudioKit——它是一个出色的框架,到目前为止我很高兴能够学习它。我正在研究一个 HelloWorld 示例,其中有一个 UI 按钮的代码,该按钮以某个频率与振荡器互动...

我的问题是:如果我想同时播放两个振荡器音调,例如 432Hz 和以上纯五度音(比例为 3:2,即 648Hz),我如何让它们同时播放?为出现的每个“音调”设置一个新节点是正确的设计模式吗?

class ViewController: UIViewController {

    var oscillator = AKOscillator()
    var osc2 = AKOscillator()

    override func viewDidLoad() {
        super.viewDidLoad()

        AudioKit.output = oscillator
        AudioKit.start()
    }

    @IBAction func toggleSound(sender: UIButton) {
        if oscillator.isPlaying {
            oscillator.stop()
            sender.setTitle("Play Sine Wave", forState: .Normal)
        } else {
          oscillator.amplitude = 1 //was:: random(0.5, 1)
          oscillator.frequency = 432 //was:: random(220, 880)
          osc2.amplitude = 1
          osc2.frequency = 648 //3:2 from 432Hz
            sender.setTitle("Stop Sine Wave at \(Int(oscillator.frequency))Hz", forState: .Normal)
        }
        sender.setNeedsDisplay()
    }

}

如何将两个振荡器链接在一起,以便它们一起唱歌?

最佳答案

尝试 AKMixer 节点:

var mixer = new AKMixer(oscillator, osc2)
AudioKit.output = mixer
try! AudioKit.start()

关于ios - audiokit:同时播放两个振荡器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36654083/

相关文章:

python - pocketsphinx python gstreamer 音频速率

android - 从 Android 设备流式传输到 shoutcast(上行)

python - 关于Python中正弦、余弦、正切函数的问题

c++ - 调试时的奇怪值

ios - 如何在 iPad 中调用 UIPopViewController 上的函数关闭

ios - 应用程序旋转为横向和纵向,但不会颠倒旋转

android - iOS Android 上的回声消除?

c++ - 用勾股方程画圆

ios - UITest:架构 armv7 的 undefined symbol

ios - 无法在模态 Controller View 前面添加 View