Class: Deftones::Component::MultibandCompressor

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

Instance Attribute Summary collapse

Attributes inherited from Deftones::Core::AudioNode

#context

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, #multichannel_process?, #name, #normalize_connection_index, #normalize_output_block, #now, #number_of_inputs, #number_of_outputs, #output_for_connection, #output_for_index, #outputs, #process, #raise_connection_index_error!, #reaches_node?, #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_frequency: 400.0, high_frequency: 2_500.0, q: 1.0, low: {}, mid: {}, high: {}, context: Deftones.context) ⇒ MultibandCompressor

Returns a new instance of MultibandCompressor.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/deftones/component/multiband_compressor.rb', line 8

def initialize(low_frequency: 400.0, high_frequency: 2_500.0, q: 1.0, low: {}, mid: {}, high: {},
               context: Deftones.context)
  super(context: context)
  @split = MultibandSplit.new(
    low_frequency: low_frequency,
    high_frequency: high_frequency,
    q: q,
    context: context
  )
  @input = @split.input
  @output = self
  @low = Compressor.new(context: context, **compressor_options(low))
  @mid = Compressor.new(context: context, **compressor_options(mid))
  @high = Compressor.new(context: context, **compressor_options(high))
  @split.low >> @low
  @split.mid >> @mid
  @split.high >> @high
end

Instance Attribute Details

#highObject (readonly)

Returns the value of attribute high.



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

def high
  @high
end

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#lowObject (readonly)

Returns the value of attribute low.



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

def low
  @low
end

#midObject (readonly)

Returns the value of attribute mid.



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

def mid
  @mid
end

#outputObject (readonly)

Returns the value of attribute output.



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

def output
  @output
end

#splitObject (readonly)

Returns the value of attribute split.



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

def split
  @split
end

Instance Method Details

#compressor_options(options) ⇒ Object (private)



60
61
62
63
64
65
66
67
# File 'lib/deftones/component/multiband_compressor.rb', line 60

def compressor_options(options)
  {
    threshold: options.fetch(:threshold, -24.0),
    ratio: options.fetch(:ratio, 3.0),
    attack: options.fetch(:attack, 0.01),
    release: options.fetch(:release, 0.1)
  }
end

#high_frequencyObject



31
32
33
# File 'lib/deftones/component/multiband_compressor.rb', line 31

def high_frequency
  @split.high_frequency
end

#low_frequencyObject



27
28
29
# File 'lib/deftones/component/multiband_compressor.rb', line 27

def low_frequency
  @split.low_frequency
end

#qObject



35
36
37
# File 'lib/deftones/component/multiband_compressor.rb', line 35

def q
  @split.q
end

#render(num_frames, start_frame = 0, cache = {}) ⇒ Object



39
40
41
# File 'lib/deftones/component/multiband_compressor.rb', line 39

def render(num_frames, start_frame = 0, cache = {})
  render_block(num_frames, start_frame, cache).mono
end

#render_block(num_frames, start_frame = 0, cache = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/deftones/component/multiband_compressor.rb', line 43

def render_block(num_frames, start_frame = 0, cache = {})
  cache_key = [object_id, start_frame, num_frames]
  return cache.fetch(cache_key).dup if cache.key?(cache_key)

  low_buffer = @low.send(:render_block, num_frames, start_frame, cache)
  mid_buffer = @mid.send(:render_block, num_frames, start_frame, cache)
  high_buffer = @high.send(:render_block, num_frames, start_frame, cache)
  channels = [low_buffer.channels, mid_buffer.channels, high_buffer.channels].max
  output_buffer = Core::AudioBlock.silent(num_frames, channels)
  output_buffer.mix!(low_buffer).mix!(mid_buffer).mix!(high_buffer)

  cache[cache_key] = output_buffer
  output_buffer.dup
end