diff options
Diffstat (limited to 'lib/time.moon')
| -rw-r--r-- | lib/time.moon | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/time.moon b/lib/time.moon new file mode 100644 index 0000000..f2ad70c --- /dev/null +++ b/lib/time.moon @@ -0,0 +1,33 @@ +import Op, Const from require 'base' + +class lfo extends Op + tau = math.pi * 2 + new: (...) => + super ... + @phase = 0 + + setup: (@freq, @wave=Const 'sin') => + + update: (dt) => + @phase += dt * @freq\get! + @value = switch @wave\get! + when 'sin' then .5 + .5 * math.cos @phase * tau + when 'saw' then @phase % 1 + when 'tri' then math.abs (2*@phase % 2) - 1 + else error "unknown wave type" + +class tick extends Op + new: (...) => + super ... + @phase = 0 + + setup: (@freq) => + + update: (dt) => + @phase += dt / @freq\get! + @value = math.floor @phase + +{ + :lfo + :tick +} |
