Class: Deftones::Core::Effect

Inherits:
AudioNode
  • Object
show all
Defined in:
lib/deftones/core/effect.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wet: 1.0, context: Deftones.context) ⇒ Effect

Returns a new instance of Effect.



8
9
10
11
# File 'lib/deftones/core/effect.rb', line 8

def initialize(wet: 1.0, context: Deftones.context)
  super(context: context)
  @wet = Signal.new(value: wet, units: :number, context: context)
end

Instance Attribute Details

#wetObject

Returns the value of attribute wet.



6
7
8
# File 'lib/deftones/core/effect.rb', line 6

def wet
  @wet
end

Instance Method Details

#multichannel_process?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/deftones/core/effect.rb', line 17

def multichannel_process?
  true
end

#normalize_channel_output(output, num_frames) ⇒ Object (private)



58
59
60
61
62
63
# File 'lib/deftones/core/effect.rb', line 58

def normalize_channel_output(output, num_frames)
  normalized = Array(output).map(&:to_f)
  return normalized.first(num_frames) if normalized.length >= num_frames

  normalized + Array.new(num_frames - normalized.length, 0.0)
end

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/deftones/core/effect.rb', line 21

def process(input_block, num_frames, start_frame, cache)
  wet_values = @wet.process(num_frames, start_frame)
  wet_block = process_effect_block(input_block.dup, num_frames, start_frame, cache)
  output_channels = [input_block.channels, wet_block.channels].max
  dry_block = input_block.fit_channels(output_channels)
  wet_block = wet_block.fit_channels(output_channels)

  AudioBlock.from_channel_data(
    Array.new(output_channels) do |channel_index|
      Array.new(num_frames) do |frame_index|
        DSP::Helpers.mix(
          dry_block.channel_data[channel_index][frame_index],
          wet_block.channel_data[channel_index][frame_index],
          wet_values[frame_index].clamp(0.0, 1.0)
        )
      end
    end
  )
end

#process_effect(input_buffer, _num_frames, _start_frame, _cache, channel_index: 0) ⇒ Object (private)



54
55
56
# File 'lib/deftones/core/effect.rb', line 54

def process_effect(input_buffer, _num_frames, _start_frame, _cache, channel_index: 0)
  input_buffer
end

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



43
44
45
46
47
48
49
50
51
52
# File 'lib/deftones/core/effect.rb', line 43

def process_effect_block(input_block, num_frames, start_frame, cache)
  AudioBlock.from_channel_data(
    input_block.channel_data.each_with_index.map do |channel, channel_index|
      normalize_channel_output(
        process_effect(channel, num_frames, start_frame, cache, channel_index: channel_index),
        num_frames
      )
    end
  )
end