Class: SynthBlocks::Mod::Envelope
- Inherits:
-
Object
- Object
- SynthBlocks::Mod::Envelope
- Defined in:
- lib/synth_blocks/mod/envelope.rb
Overview
Simple Attack / Release envelope
Instance Attribute Summary collapse
-
#attack ⇒ Object
attack time in seconds.
-
#release ⇒ Object
release time in seconds.
Instance Method Summary collapse
-
#initialize(attack, release) ⇒ Envelope
constructor
create new attack/release envelope.
-
#run(t, a = @attack, r = @release) ⇒ Object
run the attack/release envelope You can override attack and decay.
Constructor Details
#initialize(attack, release) ⇒ Envelope
create new attack/release envelope
15 16 17 18 |
# File 'lib/synth_blocks/mod/envelope.rb', line 15 def initialize(attack,release) @attack = attack @release = release end |
Instance Attribute Details
#attack ⇒ Object
attack time in seconds
8 9 10 |
# File 'lib/synth_blocks/mod/envelope.rb', line 8 def attack @attack end |
#release ⇒ Object
release time in seconds
12 13 14 |
# File 'lib/synth_blocks/mod/envelope.rb', line 12 def release @release end |
Instance Method Details
#run(t, a = @attack, r = @release) ⇒ Object
run the attack/release envelope You can override attack and decay
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/synth_blocks/mod/envelope.rb', line 22 def run(t, a=@attack, r=@release) @a = a @r = r if t > @a + @r return 0 elsif t > @a #release return 1 - ((1 / @r) * (t - @a)) else # attack return 1 / @a * t end end |