有很多方法来剥皮这只猫。我给你一对夫妇:
之一将是包裹噪声发生器在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!
第二个解决方案非常感谢。首先,我认为你的意思是:volumeControl.gain = 1 // 0或停止 –
我正在探索的另一种方法是使用合并的MPVolumeView,但这似乎在AKOperationGenerators之间切换时会导致应用程序崩溃。 –
你必须小心。理想情况下,您只需要一个音频引擎,根据需要启动和停止发生器,而不是启动和停止AudioKit。它可以是一个微妙的平衡。 –