Class: SynthBlocks::Mod::Envelope

Inherits:
Object
  • Object
show all
Defined in:
lib/synth_blocks/mod/envelope.rb

Overview

Simple Attack / Release envelope

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attackObject

attack time in seconds



8
9
10
# File 'lib/synth_blocks/mod/envelope.rb', line 8

def attack
  @attack
end

#releaseObject

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