【问题标题】:audiokit: playing two oscillators simultaneouslyaudiokit:同时播放两个振荡器
【发布时间】:2016-08-07 20:03:51
【问题描述】:

您好,我正在使用 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()
    }

}

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

【问题讨论】:

  • AudioKit.output 需要什么?我不知道图书馆,但我认为它会是AudioKit.output = oscillator + osc2?
  • @yun.cloud 它需要一个 AKNode(audioKit 节点),所以必须有一种方法可以将它们组合起来或链接它们...感谢您的建议,Xcode 正在回复:)

标签: ios audio trigonometry mixer audiokit


【解决方案1】:

试试 AKMixer 节点:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 2015-11-30
    • 1970-01-01
    相关资源
    最近更新 更多