Class: Deftones::Analysis::DCMeter

Inherits:
Core::AudioNode show all
Defined in:
lib/deftones/analysis/dc_meter.rb

Instance Attribute Summary

Attributes inherited from Core::AudioNode

#context, #input

Instance Method Summary collapse

Methods inherited from 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.8, channels: 1, context: Deftones.context) ⇒ DCMeter

Returns a new instance of DCMeter.



6
7
8
9
10
11
# File 'lib/deftones/analysis/dc_meter.rb', line 6

def initialize(smoothing: 0.8, channels: 1, context: Deftones.context)
  super(context: context)
  @channels = [channels.to_i, 1].max
  @offsets = Array.new(@channels, 0.0)
  self.smoothing = smoothing
end

Instance Method Details

#get_valueObject Also known as: getValue



25
26
27
# File 'lib/deftones/analysis/dc_meter.rb', line 25

def get_value
  @offsets.length == 1 ? @offsets.first : @offsets.dup
end

#multichannel_process?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/deftones/analysis/dc_meter.rb', line 29

def multichannel_process?
  true
end

#offsetObject



13
14
15
# File 'lib/deftones/analysis/dc_meter.rb', line 13

def offset
  @offsets.length == 1 ? @offsets.first : @offsets.dup
end

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



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/deftones/analysis/dc_meter.rb', line 33

def process(input_block, num_frames, _start_frame, _cache)
  analysis_block = input_block.fit_channels(@channels)

  @channels.times do |channel_index|
    segment = analysis_block.channel_data[channel_index].first(num_frames)
    instantaneous_offset = segment.sum / [segment.length, 1].max
    @offsets[channel_index] = smooth(@offsets[channel_index], instantaneous_offset)
  end

  input_block
end

#smooth(previous, current) ⇒ Object (private)



49
50
51
52
53
# File 'lib/deftones/analysis/dc_meter.rb', line 49

def smooth(previous, current)
  return current if @smoothing.zero?

  (previous.to_f * @smoothing) + (current.to_f * (1.0 - @smoothing))
end

#smoothingObject



17
18
19
# File 'lib/deftones/analysis/dc_meter.rb', line 17

def smoothing
  @smoothing
end

#smoothing=(value) ⇒ Object



21
22
23
# File 'lib/deftones/analysis/dc_meter.rb', line 21

def smoothing=(value)
  @smoothing = Deftones::DSP::Helpers.clamp(value.to_f, 0.0, 1.0)
end