Skip to content

Instantly share code, notes, and snippets.

@tad-iizuka
Created November 3, 2016 04:34
Show Gist options
  • Save tad-iizuka/f5644933b55c91c78a0c729831a90fdd to your computer and use it in GitHub Desktop.
Save tad-iizuka/f5644933b55c91c78a0c729831a90fdd to your computer and use it in GitHub Desktop.
AVAudioEngine Reverb On/Off
func reverbControl(onoff: Bool) {
let status = playerNode.isPlaying
offsetFrame = Int(self.slider.value)
if status {
playerNode.pause()
playerNode.stop()
engine.stop()
}
if onoff {
engine.connect(playerNode, to: reverb, format: audioFile.processingFormat)
engine.connect(reverb, to: engine.mainMixerNode, format: audioFile.processingFormat)
playerNode.scheduleSegment(audioFile,
startingFrame: AVAudioFramePosition(self.slider.value),
frameCount: AVAudioFrameCount(audioFile.length) - UInt32(self.slider.value),
at: nil,
completionHandler: self.completion)
} else {
engine.connect(playerNode, to: engine.mainMixerNode, format: audioFile.processingFormat)
playerNode.scheduleSegment(audioFile,
startingFrame: AVAudioFramePosition(self.slider.value),
frameCount: AVAudioFrameCount(audioFile.length) - UInt32(self.slider.value),
at: nil,
completionHandler: self.completion)
}
if status {
do {
try engine.start()
} catch {
print(error)
}
playerNode.play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment