diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-02-10 21:18:49 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-02-10 21:18:49 +0000 |
| commit | 869547c55d6b082f34cca274bf0b978d5a7bdba8 (patch) | |
| tree | 5ec5e9183d90e2f953b79b456546406997db269a /lib/envelope.moon | |
| parent | add doc, import, import*, defn (diff) | |
| download | alive-869547c55d6b082f34cca274bf0b978d5a7bdba8.tar.gz alive-869547c55d6b082f34cca274bf0b978d5a7bdba8.zip | |
envelopes
Diffstat (limited to 'lib/envelope.moon')
| -rw-r--r-- | lib/envelope.moon | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/envelope.moon b/lib/envelope.moon new file mode 100644 index 0000000..0129eb4 --- /dev/null +++ b/lib/envelope.moon @@ -0,0 +1,29 @@ +import Const, Op, Scope, eval from require 'core' + +class ar_core extends Op + @doc: "(ar-core attack release gate) +((ar attack release) gate) - AR envelope + +goes from 0 to 1 in attack seconds, holds while gate is on, then goes back to 0 in release seconds." + + new: (...) => + super ... + @value = 0 + + setup: (@a, @r, @gate) => + assert @a, "ar requires an attack value" + assert @r, "ar requires a release value" + assert @gate, "ar requires a gate value" + + update: (dt) => + @a\update dt + @r\update dt + @gate\update dt + + slope = if @gate\get! then @a\getc! else -@r\getc! + + @value = math.min 1, math.max 0, @value + dt / slope + +scope = Scope.from_table { 'ar-core': ar_core } +scope\set 'ar', eval '(fn (a r) (fn (gate) (ar-core a r gate)))', scope +scope |
