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