Audiokit: simultaneous playback of two oscillators

Hello, I work with AudioKit - it is a star structure, and I am very happy that I just learned it. I am working on a HelloWorld example, and there is code for a user interface button that includes a generator with a frequency ...

My question is: if I want to reproduce immediately two tones of the generator, for example 432 Hz and a perfect fifth level (3: 2 ratio, so 648 Hz), how can I make them play simultaneously at the same time? Does the correct design template have a new node for every “tone” going along?

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()
    }

}

How can I combine the two generators together so they can sing together?

+4
source share
1

AKMixer node:

var mixer = new AKMixer(oscillator, osc2)
AudioKit.output = mixer
AudioKit.start()
+9

All Articles