Class: SynthBlocks::Fx::Delay

Inherits:
Object
  • Object
show all
Defined in:
lib/synth_blocks/fx/delay.rb

Overview

Simple delay with mix and feedback parameters Currently doesn’t really have a variable delay time, I’ll tackle that when I need it. It uses a simple ring buffer implementation and delay time is only exact down to the sample.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sample_rate, time: 0.2, mix: 0.5, feedback: 0.4, &block) ⇒ Delay

time is given in seconds

mix (0 = no delay, 1 = only delay)

feedback (0 = zero feedback, 1 = full feedback (not advised))

if given a block it will call the block from the run method to process the feedback signal



20
21
22
23
24
25
26
# File 'lib/synth_blocks/fx/delay.rb', line 20

def initialize(sample_rate, time: 0.2, mix: 0.5, feedback: 0.4, &block)
  @buffer = Array.new((sample_rate.to_f * time).floor)
  @block = block
  @pointer = 0
  @mix = mix
  @feedback = feedback
end

Instance Attribute Details

#feedbackObject (readonly)

:nodoc:



9
10
11
# File 'lib/synth_blocks/fx/delay.rb', line 9

def feedback
  @feedback
end

#mixObject (readonly)

:nodoc:



9
10
11
# File 'lib/synth_blocks/fx/delay.rb', line 9

def mix
  @mix
end

Instance Method Details

#run(input) ⇒ Object

run delay



30
31
32
33
34
35
36
37
38
39
# File 'lib/synth_blocks/fx/delay.rb', line 30

def run(input)
  old_pointer = @pointer
  @pointer = (@pointer + 1) % @buffer.length
  delayed = (@buffer[@pointer] || 0.0)
  if @block
    delayed = @block.call(delayed)
  end
  @buffer[old_pointer] = input + (feedback * delayed)
  input * (1.0 - mix) + delayed * mix
end