Class: Deftones::Effects::StereoWidener

Inherits:
Core::Effect show all
Defined in:
lib/deftones/effect/stereo_widener.rb

Instance Attribute Summary collapse

Attributes inherited from Core::Effect

#wet

Instance Method Summary collapse

Methods inherited from Core::Effect

#multichannel_process?, #normalize_channel_output, #process, #process_effect

Constructor Details

#initialize(width: 0.5, context: Deftones.context, **options) ⇒ StereoWidener

Returns a new instance of StereoWidener.



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

def initialize(width: 0.5, context: Deftones.context, **options)
  super(context: context, **options)
  @width = width.to_f
end

Instance Attribute Details

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#process_effect_block(input_block, num_frames, _start_frame, _cache) ⇒ Object (private)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/deftones/effect/stereo_widener.rb', line 15

def process_effect_block(input_block, num_frames, _start_frame, _cache)
  stereo_input = input_block.fit_channels(2)
  width = @width.to_f.clamp(0.0, 1.0)
  left = Array.new(num_frames)
  right = Array.new(num_frames)

  num_frames.times do |index|
    left_sample = stereo_input.channel_data[0][index]
    right_sample = stereo_input.channel_data[1][index]
    mid = (left_sample + right_sample) * (1.0 - width)
    side = (left_sample - right_sample) * width
    left[index] = mid + side
    right[index] = mid - side
  end

  Core::AudioBlock.from_channel_data([left, right])
end