3

有没有办法淡入 AKOperationGenerator 的声音?

例如,在下面的代码中,.start() 通过单击以全幅度开始。

let whiteNoiseGenerator = AKOperationGenerator { _ in

    let white = AKOperation.whiteNoise()
    return white
}


AudioKit.output = whiteNoiseGenerator
whiteNoiseGenerator.start()
4

1 回答 1

6

有很多方法可以给这只猫剥皮。我给你一对:

一种是将噪声发生器包装在 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 秒内获得完整音量的平滑变化。

于 2017-10-16T19:40:45.527 回答