最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - Abrupt release for AmplitudeEnvelope - Stack Overflow

programmeradmin5浏览0评论

I've made a little project where I play an Oscillator through an AmplitudeEnvelope, and what I'm looking for is the traditional ADSR amplitude curve with a distinct attack, sustain and release part. However, I neither hear an attack nor release part of the curve. It is as if it's stuck in sustain mode. So instead of a nice release, I get a "pop" or click sound when the sound is cut off.

I guess envelope.stop() is not the right way to make a release happen, but what is? And what is the right way to start the envelope so I can hear an attack?

The code is basically like so:

    let engine = AudioEngine()
    var oscillator: Oscillator!
    var envelope: AmplitudeEnvelope!

    init() {
        oscillator = Oscillator(waveform: Table(.sine))
        oscillator.frequency = 415
        oscillator.amplitude = 0.5

        envelope = AmplitudeEnvelope(oscillator)
        envelope.attackDuration = 0.1
        envelope.decayDuration = 0.3
        envelope.sustainLevel = 0.7
        envelope.releaseDuration = 0.6

        engine.output = envelope

        try? engine.start()
        oscillator.start()
        startTriggerTimer()
    }

    func startTriggerTimer() {
        envelope.start()

        // Schedule release after 3 seconds
        DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in
            self?.envelope.stop()
            print("Releasing oscillator")
        }
        
        // Trigger every 5 seconds
        timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { [weak self] _ in
            self?.startTriggerTimer()
        }
    }

This is with AudioKit 5.6.5

I've made a little project where I play an Oscillator through an AmplitudeEnvelope, and what I'm looking for is the traditional ADSR amplitude curve with a distinct attack, sustain and release part. However, I neither hear an attack nor release part of the curve. It is as if it's stuck in sustain mode. So instead of a nice release, I get a "pop" or click sound when the sound is cut off.

I guess envelope.stop() is not the right way to make a release happen, but what is? And what is the right way to start the envelope so I can hear an attack?

The code is basically like so:

    let engine = AudioEngine()
    var oscillator: Oscillator!
    var envelope: AmplitudeEnvelope!

    init() {
        oscillator = Oscillator(waveform: Table(.sine))
        oscillator.frequency = 415
        oscillator.amplitude = 0.5

        envelope = AmplitudeEnvelope(oscillator)
        envelope.attackDuration = 0.1
        envelope.decayDuration = 0.3
        envelope.sustainLevel = 0.7
        envelope.releaseDuration = 0.6

        engine.output = envelope

        try? engine.start()
        oscillator.start()
        startTriggerTimer()
    }

    func startTriggerTimer() {
        envelope.start()

        // Schedule release after 3 seconds
        DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) { [weak self] in
            self?.envelope.stop()
            print("Releasing oscillator")
        }
        
        // Trigger every 5 seconds
        timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { [weak self] _ in
            self?.startTriggerTimer()
        }
    }

This is with AudioKit 5.6.5

Share Improve this question asked Mar 23 at 23:23 niklassaersniklassaers 8,86021 gold badges105 silver badges157 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Setting the parameters as part of the constructor made release work the way I expected them to

Update: https://www.audiokit.io/AudioKit/documentation/audiokit/parameter says "Note that we don’t allow initialization of Parameters to values because we don’t yet have an underlying AUParameter."

发布评论

评论列表(0)

  1. 暂无评论