在某一时刻,我正在播放一个具有某些效果的音频文件。代码如下:
engine = AVAudioEngine()
playerB = AVAudioPlayerNode()
playerB.volume = 0.5
let path = Bundle.main.path(forResource: "ukulele", ofType: "wav")!
let url = NSURL.fileURL(withPath: path)
let file = try? AVAudioFile(forReading: url)
buffer = AVAudioPCMBuffer(pcmFormat: file!.processingFormat, frameCapacity: AVAudioFrameCount(file!.length))!
try! file!.read(into: buffer)
reverb.loadFactoryPreset(AVAudioUnitReverbPreset.cathedral)
reverb.wetDryMix = 50
distortion.loadFactoryPreset(AVAudioUnitDistortionPreset.speechRadioTower)
distortion.wetDryMix = 25
let delay = AVAudioUnitDistortion()
delay.loadFactoryPreset(AVAudioUnitDistortionPreset.speechAlienChatter)
delay.wetDryMix = 25
engine.attach(playerB)
engine.attach(reverb)
engine.attach(distortion)
engine.attach(delay)
engine.attach(pitch)
engine.attach(speedControl)
engine.connect(playerB, to: pitch, format: nil)
engine.connect(pitch, to: speedControl, format: nil)
engine.connect(speedControl, to: reverb, format: nil)
engine.connect(reverb, to: distortion, format: nil)
engine.connect(distortion, to: engine.mainMixerNode, format: buffer.format)
playerB.scheduleBuffer(buffer, at: nil, options: AVAudioPlayerNodeBufferOptions.loops, completionHandler: nil)
engine.prepare()
try! engine.start()我想要的是在发生特定操作时断开其中一个AVAudioUnit。但是,在移除AVAudioUnit之后,播放器完全处于静默状态。
例如,如果我想删除reverb,代码是:engine.disconnectNodeOutput(reverb),但是在这一行运行之后,播放器是静默的。
我做错了什么?我只想删除已经添加的一个效果。
发布于 2019-05-14 15:00:37
这是一条链子,你弄断了其中的一个链环。下面是你的代码:
engine.connect(pitch, to: speedControl, format: nil)
engine.connect(speedControl, to: reverb, format: nil)
engine.connect(reverb, to: distortion, format: nil)
engine.connect(distortion, to: engine.mainMixerNode, format: buffer.format)如果移除混响节点,现在速度控制和失真之间会有一个空洞。没有任何东西可以穿过那个洞。您需要将它们连接起来。
https://stackoverflow.com/questions/56124540
复制相似问题