Class: Synthesizer::Modulation::Lfo
- Inherits:
-
Object
- Object
- Synthesizer::Modulation::Lfo
- Defined in:
- lib/synthesizer/modulation/lfo.rb
Instance Method Summary collapse
- #amp_generator(note_perform, samplecount, depth, &block) ⇒ Object
- #balance_generator(note_perform, samplecount, depth, &block) ⇒ Object
- #generator(note_perform, samplecount, &block) ⇒ Object
-
#initialize(shape: Shape::Sine, delay: 0.0, attack: 0.0, attack_curve: Curve::Straight, phase: 0.0, rate: 0.3) ⇒ Lfo
constructor
A new instance of Lfo.
Constructor Details
#initialize(shape: Shape::Sine, delay: 0.0, attack: 0.0, attack_curve: Curve::Straight, phase: 0.0, rate: 0.3) ⇒ Lfo
Returns a new instance of Lfo.
11 12 13 14 15 16 17 18 |
# File 'lib/synthesizer/modulation/lfo.rb', line 11 def initialize(shape: Shape::Sine, delay: 0.0, attack: 0.0, attack_curve: Curve::Straight, phase: 0.0, rate: 0.3) @shape = shape @delay = AudioStream::Rate.sec(delay) @attack = AudioStream::Rate.sec(attack) @attack_curve = attack_curve @phase = phase.to_f @rate = AudioStream::Rate.sec(rate) end |
Instance Method Details
#amp_generator(note_perform, samplecount, depth, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/synthesizer/modulation/lfo.rb', line 48 def amp_generator(note_perform, samplecount, depth, &block) bottom = 1.0 - depth gen = generator(note_perform, samplecount) -> { val = (gen.next + 1) / 2 val * depth + bottom } end |
#balance_generator(note_perform, samplecount, depth, &block) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/synthesizer/modulation/lfo.rb', line 58 def balance_generator(note_perform, samplecount, depth, &block) gen = generator(note_perform, samplecount) -> { gen.next * depth } end |
#generator(note_perform, samplecount, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/synthesizer/modulation/lfo.rb', line 20 def generator(note_perform, samplecount, &block) soundinfo = note_perform.synth.soundinfo hz = @rate.freq(soundinfo) Enumerator.new do |yld| pos = ShapePos.new(soundinfo.samplerate / samplecount, @phase) # delay (@delay.sample(soundinfo) / samplecount).to_i.times {|i| yld << 0.0 } # attack attack_len = (@attack.sample(soundinfo) / samplecount).to_i attack_len.times {|i| x = i.to_f / attack_len y = @attack_curve[x] yld << @shape[pos.next(hz, 0.0, 0.0)] * y } # sustain loop { val = @shape[pos.next(hz, 0.0, 0.0)] yld << val } end.each(&block) end |