0

I am quite new to AudioKit. I have an AKPluckedString that works, but unaltered it plays after a .trigger for MANY seconds. I want it to fade evenly over about 2 seconds. I've succeeded with the code below, but it seems quite clumsy. Before I found this method I explored using AKAmplitudeEnvelope, amplitudeRange, rampTime and a lot of other possibilities. How do I accomplish this using AK tools?

Also, the AudioKit.io docs do not seem to match what I have in my iOS framework dowloaded just a couple of weeks ago. Are those docs aspirational? Old?

        string = AKPluckedString()
        string.rampDuration = 1
        AudioKit.output = string
        try? AudioKit.start()

    func pluck() -> Void {
        string.trigger(frequency: 180, amplitude: 1.0)
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
            self.string.amplitude = 0.75
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
            self.string.amplitude = 0.5
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.2) {
            self.string.amplitude = 0.25
        }
        DispatchQueue.main.asyncAfter(deadline: .now() + 1.6) {
            self.string.amplitude = 0.0
        }
    }

XCode 11.7 iOS 13.6

LostInTheTrees
  • 1,135
  • 9
  • 19

1 Answers1

0

It was simpler than I thought. Set rampDuration to the fade time, then just change the amplitude. It takes rampDuration seconds to reach to the new aplitude.

pluckedString.rampDuration = 2.0
pluckedString.trigger(frequency: 440.0, amplitude: 2.0)
self.pluckedString.amplitude = 0.0
LostInTheTrees
  • 1,135
  • 9
  • 19