Hello I'm working with AudioKit -- it is a stellar framework and I'm very happy so far just learning it. I'm working through a HelloWorld example and there is code for a UI button that engages an oscillator at a frequency...
My question is: if I want to play two oscillator tones at once, such as 432Hz and a perfect fifth above (ratio of 3:2 so 648Hz) how can I have them both play simultaneously? Is the correct design pattern to have a new node for each "tone" coming 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 chain the two oscillators together so they can sing together?
Try the AKMixer node:
var mixer = new AKMixer(oscillator, osc2)
AudioKit.output = mixer
try! AudioKit.start()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With