Class: Deftones::Effects::AutoFilter

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

Defined Under Namespace

Classes: FilterProxy

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: 1.0, base_frequency: 200.0, octaves: 2.5, depth: 1.0, type: :sine, filter_type: :lowpass, q: 0.8, filter: nil, context: Deftones.context, **options) ⇒ AutoFilter

Returns a new instance of AutoFilter.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/deftones/effect/auto_filter.rb', line 13

def initialize(
  frequency: 1.0,
  base_frequency: 200.0,
  octaves: 2.5,
  depth: 1.0,
  type: :sine,
  filter_type: :lowpass,
  q: 0.8,
  filter: nil,
  context: Deftones.context,
  **options
)
  super(context: context, wet: 1.0, **options)
  @frequency = frequency.to_f
  @base_frequency = base_frequency.to_f
  @octaves = octaves.to_f
  @depth = depth.to_f
  @type = normalize_modulation_type(type)
  @filter = resolve_filter(filter, filter_type: filter_type, q: q)
  @phase = 0.0
  @biquads = []
  initialize_modulation_control
end

Instance Attribute Details

#base_frequencyObject Also known as: baseFrequency

Returns the value of attribute base_frequency.



10
11
12
# File 'lib/deftones/effect/auto_filter.rb', line 10

def base_frequency
  @base_frequency
end

#depthObject

Returns the value of attribute depth.



10
11
12
# File 'lib/deftones/effect/auto_filter.rb', line 10

def depth
  @depth
end

#filterObject (readonly)

Returns the value of attribute filter.



11
12
13
# File 'lib/deftones/effect/auto_filter.rb', line 11

def filter
  @filter
end

#frequencyObject

Returns the value of attribute frequency.



10
11
12
# File 'lib/deftones/effect/auto_filter.rb', line 10

def frequency
  @frequency
end

#octavesObject

Returns the value of attribute octaves.



10
11
12
# File 'lib/deftones/effect/auto_filter.rb', line 10

def octaves
  @octaves
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/deftones/effect/auto_filter.rb', line 10

def type
  @type
end

Instance Method Details

#baseFrequency=(value) ⇒ Object



47
48
49
# File 'lib/deftones/effect/auto_filter.rb', line 47

def baseFrequency=(value)
  self.base_frequency = value
end

#ensure_biquads(channels) ⇒ Object (private)



84
85
86
87
88
89
# File 'lib/deftones/effect/auto_filter.rb', line 84

def ensure_biquads(channels)
  required = [channels.to_i, 1].max
  while @biquads.length < required
    @biquads << DSP::Biquad.new
  end
end

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/deftones/effect/auto_filter.rb', line 53

def process_effect_block(input_block, num_frames, start_frame, _cache)
  ensure_biquads(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) * @depth.clamp(0.0, 1.0)
    cutoff = @base_frequency * (2.0**(modulation * @octaves))
    input_block.channel_data.each_with_index do |channel, channel_index|
      biquad = @biquads[channel_index]
      biquad.update(
        type: @filter.type,
        frequency: cutoff,
        q: @filter.q,
        gain_db: 0.0,
        sample_rate: context.sample_rate
      )
      output[channel_index][index] = biquad.process_sample(channel[index])
    end
  end

  Core::AudioBlock.from_channel_data(output)
end

#qObject



37
38
39
# File 'lib/deftones/effect/auto_filter.rb', line 37

def q
  @filter.q
end

#q=(value) ⇒ Object



41
42
43
# File 'lib/deftones/effect/auto_filter.rb', line 41

def q=(value)
  @filter.q = value.to_f
end

#resolve_filter(filter, filter_type:, q:) ⇒ Object (private)



78
79
80
81
82
# File 'lib/deftones/effect/auto_filter.rb', line 78

def resolve_filter(filter, filter_type:, q:)
  return filter if filter.respond_to?(:type) && filter.respond_to?(:q)

  FilterProxy.new(type: filter_type.to_sym, q: q.to_f, rolloff: -12)
end