how to restart an oscillator instantaneously in swift 3 using audiokit

206 views Asked by At

I am trying to make a button that plays an oscillator that has ADSR and if the button is pressed while the oscillator is already playing, I want it to override the already playing oscillator and replay the oscillator from the start.

This code achieves my goal, but the "sleep" is way too long; it needs to be instantaneous.

@IBAction func play(_ sender: UIButton) {
    envelope.stop()
    oscillator.stop()
    sleep(1)
    envelope.start()
    oscillator.start()
}
0

There are 0 answers