Class: Deftones::Effects::Vibrato

Inherits:
Core::Effect show all
Includes:
ModulationControl
Defined in:
lib/deftones/effect/vibrato.rb

Instance Attribute Summary collapse

Attributes inherited from Core::Effect

#wet

Instance Method Summary collapse

Methods included from ModulationControl

#bipolar_modulation_value, #cancel_stop, #clear_modulation_event, #dispose, #initialize_modulation_control, #modulation_active_at?, #modulation_frequency, #modulation_phase_for, #modulation_sample_for, #modulation_type, #normalize_modulation_type, #resolve_modulation_time, #resolve_modulation_transport_time, #restart, #schedule_modulation_event, #start, #state, #stop, #sync, #synced?, #unipolar_modulation_value, #unsync

Methods inherited from Core::Effect

#multichannel_process?, #normalize_channel_output, #process, #process_effect

Constructor Details

#initialize(frequency: 5.0, depth: 0.002, type: :sine, context: Deftones.context, **options) ⇒ Vibrato

Returns a new instance of Vibrato.



10
11
12
13
14
15
16
17
18
# File 'lib/deftones/effect/vibrato.rb', line 10

def initialize(frequency: 5.0, depth: 0.002, type: :sine, context: Deftones.context, **options)
  super(context: context, wet: 1.0, **options)
  @frequency = frequency.to_f
  @depth = depth.to_f
  @type = normalize_modulation_type(type)
  @phase = 0.0
  @delay_lines = []
  initialize_modulation_control
end

Instance Attribute Details

#depthObject

Returns the value of attribute depth.



8
9
10
# File 'lib/deftones/effect/vibrato.rb', line 8

def depth
  @depth
end

#frequencyObject

Returns the value of attribute frequency.



8
9
10
# File 'lib/deftones/effect/vibrato.rb', line 8

def frequency
  @frequency
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/deftones/effect/vibrato.rb', line 8

def type
  @type
end

Instance Method Details

#ensure_delay_lines(channels) ⇒ Object (private)



39
40
41
42
43
44
# File 'lib/deftones/effect/vibrato.rb', line 39

def ensure_delay_lines(channels)
  required = [channels.to_i, 1].max
  while @delay_lines.length < required
    @delay_lines << DSP::DelayLine.new((0.05 * context.sample_rate).ceil)
  end
end

#process_effect_block(input_block, num_frames, start_frame, _cache) ⇒ Object (private)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/deftones/effect/vibrato.rb', line 22

def process_effect_block(input_block, num_frames, start_frame, _cache)
  ensure_delay_lines(input_block.channels)
  output = Array.new(input_block.channels) { Array.new(num_frames, 0.0) }

  num_frames.times do |index|
    current_time = (start_frame + index).to_f / context.sample_rate
    phase = modulation_phase_for(current_time)
    modulation = unipolar_modulation_value(phase, default: 0.5)
    delay_samples = (0.01 + (@depth * modulation)) * context.sample_rate
    input_block.channel_data.each_with_index do |channel, channel_index|
      output[channel_index][index] = @delay_lines[channel_index].tap(delay_samples, input_sample: channel[index])
    end
  end

  Core::AudioBlock.from_channel_data(output)
end