Class: Deftones::Component::Follower

Inherits:
Deftones::Core::AudioNode show all
Defined in:
lib/deftones/component/follower.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(smoothing: 0.05, context: Deftones.context) ⇒ Follower

Returns a new instance of Follower.



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

def initialize(smoothing: 0.05, context: Deftones.context)
  super(context: context)
  @smoothing = Core::Signal.new(value: smoothing, units: :time, context: context)
  @state = []
end

Instance Attribute Details

#smoothingObject

Returns the value of attribute smoothing.



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

def smoothing
  @smoothing
end

Instance Method Details

#ensure_state(channels) ⇒ Object (private)



49
50
51
52
# File 'lib/deftones/component/follower.rb', line 49

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

#multichannel_process?Boolean

Returns:

  • (Boolean)


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

def multichannel_process?
  true
end

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



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

def process(input_block, num_frames, start_frame, _cache)
  smoothing_values = @smoothing.process(num_frames, start_frame)
  ensure_state(input_block.channels)
  output_channels = input_block.channel_data.each_with_index.map do |channel, channel_index|
    Array.new(num_frames) do |index|
      coefficient = smoothing_coefficient(smoothing_values[index])
      magnitude = channel[index].abs
      @state[channel_index] += (1.0 - coefficient) * (magnitude - @state[channel_index])
      @state[channel_index]
    end
  end

  Core::AudioBlock.from_channel_data(output_channels)
end

#reset!Object



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

def reset!
  @state = []
  self
end

#smoothing_coefficient(duration) ⇒ Object (private)



44
45
46
47
# File 'lib/deftones/component/follower.rb', line 44

def smoothing_coefficient(duration)
  seconds = [duration.to_f, 1.0 / context.sample_rate].max
  Math.exp(-1.0 / (seconds * context.sample_rate))
end