Class: Deftones::Effects::AutoPanner

Inherits:
Core::Effect show all
Includes:
ModulationControl
Defined in:
lib/deftones/effect/auto_panner.rb

Instance Attribute Summary collapse

Attributes inherited from Core::Effect

#wet

Instance Method Summary collapse

Methods included from ModulationControl

#bipolar_modulation_value, #cancel_stop, #clear_modulation_event, #dispose, #initialize_modulation_control, #modulation_active_at?, #modulation_frequency, #modulation_phase_for, #modulation_sample_for, #modulation_type, #normalize_modulation_type, #resolve_modulation_time, #resolve_modulation_transport_time, #restart, #schedule_modulation_event, #start, #state, #stop, #sync, #synced?, #unipolar_modulation_value, #unsync

Methods inherited from Core::Effect

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

Constructor Details

#initialize(frequency: 2.0, depth: 0.5, type: :sine, context: Deftones.context, **options) ⇒ AutoPanner

Returns a new instance of AutoPanner.



10
11
12
13
14
15
16
17
# File 'lib/deftones/effect/auto_panner.rb', line 10

def initialize(frequency: 2.0, depth: 0.5, type: :sine, context: Deftones.context, **options)
  super(context: context, wet: 1.0, **options)
  @frequency = frequency.to_f
  @depth = depth.to_f
  @type = normalize_modulation_type(type)
  @phase = 0.0
  initialize_modulation_control
end

Instance Attribute Details

#depthObject

Returns the value of attribute depth.



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

def depth
  @depth
end

#frequencyObject

Returns the value of attribute frequency.



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

def frequency
  @frequency
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#angle_for(pan) ⇒ Object (private)



52
53
54
# File 'lib/deftones/effect/auto_panner.rb', line 52

def angle_for(pan)
  ((pan.to_f.clamp(-1.0, 1.0) + 1.0) * Math::PI) * 0.25
end

#left_gain(pan) ⇒ Object (private)



44
45
46
# File 'lib/deftones/effect/auto_panner.rb', line 44

def left_gain(pan)
  Math.cos(angle_for(pan))
end

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



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

def process_effect_block(input_block, num_frames, start_frame, _cache)
  output = Array.new(2) { Array.new(num_frames, 0.0) }
  stereo_input = input_block.fit_channels(2)
  mono_input = input_block.mono

  num_frames.times do |index|
    current_time = (start_frame + index).to_f / context.sample_rate
    phase = modulation_phase_for(current_time)
    modulation = bipolar_modulation_value(phase, default: 0.0) * @depth.clamp(0.0, 1.0)
    if input_block.channels == 1
      sample = mono_input[index]
      output[0][index] = sample * left_gain(modulation)
      output[1][index] = sample * right_gain(modulation)
      next
    end

    output[0][index] = stereo_input.channel_data[0][index] * left_gain(modulation)
    output[1][index] = stereo_input.channel_data[1][index] * right_gain(modulation)
  end

  Core::AudioBlock.from_channel_data(output)
end

#right_gain(pan) ⇒ Object (private)



48
49
50
# File 'lib/deftones/effect/auto_panner.rb', line 48

def right_gain(pan)
  Math.sin(angle_for(pan))
end