有没有办法淡化AKOperationGenerator的声音?
E.g。在下面的代码中.start()以全振幅开始,点击一下。
let whiteNoiseGenerator = AKOperationGenerator { _ in
let white = AKOperation.whiteNoise()
return white
}
AudioKit.output = whiteNoiseGenerator
whiteNoiseGenerator.start()
答案 0 :(得分:5)
有很多方法可以给这只猫上皮。我会给你一对夫妇:
一种方法是将噪音发生器包装在AKBooster中:
let volumeControl = AKBooster(whiteNoiseGenerator)
volumeControl.gain = 0
volumeControl.rampTime = 1 // number of seconds to fade in/out
AudioKit.output = volumeControl
AudioKit.start() // Don't forget this, I assume you just didn't paste it in
whiteNoiseGenerator.start() // nothing will be heard
然后通过设置
来启动和停止声音volumeControl.gain = 1 // or 0 for stopping
或者,我知道您想知道如何在操作的上下文中执行此操作,因此您可以通过提供增益和滑音时间的操作参数来实现:
let whiteNoiseGenerator = AKOperationGenerator { parameters in
let white = AKOperation.whiteNoise() * parameters[0].portamento(halfDuration: parameters[1])
return white
}
whiteNoiseGenerator.parameters = [0,0.1] // first number is gain, second is portamento time
AudioKit.output = whiteNoiseGenerator
AudioKit.start()
whiteNoiseGenerator.start()
然后,当你想打开噪音时,请执行以下操作:
whiteNoiseGenerator.parameters[0] = 1
您将在0.1秒内获得完整音量的平滑变化。
HTH!