Created
November 3, 2016 04:34
-
-
Save tad-iizuka/f5644933b55c91c78a0c729831a90fdd to your computer and use it in GitHub Desktop.
AVAudioEngine Reverb On/Off
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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