Class: Deftones::Component::LowpassCombFilter

Inherits:
FeedbackCombFilter
  • Object
show all
Defined in:
lib/deftones/component/lowpass_comb_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dampening: 3_000.0, **options) ⇒ LowpassCombFilter

Returns a new instance of LowpassCombFilter.



8
9
10
11
12
# File 'lib/deftones/component/lowpass_comb_filter.rb', line 8

def initialize(dampening: 3_000.0, **options)
  super(**options)
  @dampening = Core::Signal.new(value: dampening, units: :frequency, context: context)
  @filter_state = []
end

Instance Attribute Details

#dampeningObject

Returns the value of attribute dampening.



6
7
8
# File 'lib/deftones/component/lowpass_comb_filter.rb', line 6

def dampening
  @dampening
end

Instance Method Details

#ensure_filter_state(channels) ⇒ Object (private)



37
38
39
40
# File 'lib/deftones/component/lowpass_comb_filter.rb', line 37

def ensure_filter_state(channels)
  required = [channels.to_i, 1].max
  @filter_state.fill(0.0, @filter_state.length...required)
end

#feedback_coefficient(frequency) ⇒ Object (private)



32
33
34
35
# File 'lib/deftones/component/lowpass_comb_filter.rb', line 32

def feedback_coefficient(frequency)
  normalized = [[frequency.to_f, 1.0].max, (context.sample_rate * 0.49)].min
  Math.exp((-2.0 * Math::PI * normalized) / context.sample_rate)
end

#filtered_feedback(sample, index, start_frame, channel_index = 0) ⇒ Object (private)



25
26
27
28
29
30
# File 'lib/deftones/component/lowpass_comb_filter.rb', line 25

def filtered_feedback(sample, index, start_frame, channel_index = 0)
  ensure_filter_state(channel_index + 1)
  coefficient = feedback_coefficient(@dampening.process(1, start_frame + index).first)
  @filter_state[channel_index] += (1.0 - coefficient) * (sample - @filter_state[channel_index])
  @filter_state[channel_index]
end

#reset!Object



18
19
20
21
# File 'lib/deftones/component/lowpass_comb_filter.rb', line 18

def reset!
  @filter_state = []
  super
end