Class: Deftones::Component::EQ3

Inherits:
Deftones::Core::AudioNode show all
Defined in:
lib/deftones/component/eq3.rb

Instance Attribute Summary collapse

Attributes inherited from Deftones::Core::AudioNode

#context, #input

Instance Method Summary collapse

Methods inherited from Deftones::Core::AudioNode

#>>, #attach_destination, #attach_source, #block_time, #chain, #channel_count, #channel_count_mode, #channel_interpretation, #connect, #connected?, #default_input_channels, #default_output_channels, #destination_for_connection, #detach_all_destinations, #detach_destination, #detach_source, #disconnect, #dispose, #disposed?, #fan, #get, #immediate, #input_for_index, #inputs, #mix_source_blocks, #name, #normalize_connection_index, #normalize_output_block, #now, #number_of_inputs, #number_of_outputs, #output, #output_for_connection, #output_for_index, #outputs, #raise_connection_index_error!, #reaches_node?, #render, #render_block, #sample_time, #set, #to_destination, #to_frequency, #to_master, #to_midi, #to_output, #to_s, #to_seconds, #to_ticks, #uses_legacy_render_for_block?, #validate_connectable!, #validate_connection_index!

Constructor Details

#initialize(low: 0.0, mid: 0.0, high: 0.0, low_frequency: 400.0, high_frequency: 2_500.0, context: Deftones.context) ⇒ EQ3

Returns a new instance of EQ3.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/deftones/component/eq3.rb', line 9

def initialize(low: 0.0, mid: 0.0, high: 0.0, low_frequency: 400.0,
               high_frequency: 2_500.0, context: Deftones.context)
  super(context: context)
  @low = low.to_f
  @mid = mid.to_f
  @high = high.to_f
  @low_frequency = Core::Signal.new(value: low_frequency, units: :frequency, context: context)
  @high_frequency = Core::Signal.new(value: high_frequency, units: :frequency, context: context)
  @low_shelves = []
  @mid_peaks = []
  @high_shelves = []
end

Instance Attribute Details

#highObject

Returns the value of attribute high.



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

def high
  @high
end

#high_frequencyObject (readonly)

Returns the value of attribute high_frequency.



7
8
9
# File 'lib/deftones/component/eq3.rb', line 7

def high_frequency
  @high_frequency
end

#lowObject

Returns the value of attribute low.



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

def low
  @low
end

#low_frequencyObject (readonly)

Returns the value of attribute low_frequency.



7
8
9
# File 'lib/deftones/component/eq3.rb', line 7

def low_frequency
  @low_frequency
end

#midObject

Returns the value of attribute mid.



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

def mid
  @mid
end

Instance Method Details

#ensure_filter_banks(channels) ⇒ Object (private)



63
64
65
66
67
68
69
70
# File 'lib/deftones/component/eq3.rb', line 63

def ensure_filter_banks(channels)
  required = [channels.to_i, 1].max
  while @low_shelves.length < required
    @low_shelves << DSP::Biquad.new
    @mid_peaks << DSP::Biquad.new
    @high_shelves << DSP::Biquad.new
  end
end

#multichannel_process?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/deftones/component/eq3.rb', line 22

def multichannel_process?
  true
end

#process(input_block, num_frames, start_frame, _cache) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/deftones/component/eq3.rb', line 26

def process(input_block, num_frames, start_frame, _cache)
  update_filters(input_block.channels, start_frame)

  Core::AudioBlock.from_channel_data(
    input_block.channel_data.each_with_index.map do |channel, channel_index|
      low_shelf = @low_shelves[channel_index]
      mid_peak = @mid_peaks[channel_index]
      high_shelf = @high_shelves[channel_index]

      Array.new(num_frames) do |index|
        sample = channel[index]
        sample = low_shelf.process_sample(sample)
        sample = mid_peak.process_sample(sample)
        high_shelf.process_sample(sample)
      end
    end
  )
end

#update_filters(channels, start_frame) ⇒ Object (private)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/deftones/component/eq3.rb', line 47

def update_filters(channels, start_frame)
  ensure_filter_banks(channels)
  low_frequency = @low_frequency.process(1, start_frame).first
  high_frequency = @high_frequency.process(1, start_frame).first

  @low_shelves.each do |filter|
    filter.update(type: :lowshelf, frequency: low_frequency, q: 0.707, gain_db: @low, sample_rate: context.sample_rate)
  end
  @mid_peaks.each do |filter|
    filter.update(type: :peaking, frequency: Math.sqrt(low_frequency * high_frequency), q: 0.8, gain_db: @mid, sample_rate: context.sample_rate)
  end
  @high_shelves.each do |filter|
    filter.update(type: :highshelf, frequency: high_frequency, q: 0.707, gain_db: @high, sample_rate: context.sample_rate)
  end
end