Class: Deftones::Effects::Tremolo
- Inherits:
-
Core::Effect
- Object
- Core::Effect
- Deftones::Effects::Tremolo
- Includes:
- ModulationControl
- Defined in:
- lib/deftones/effect/tremolo.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#spread ⇒ Object
Returns the value of attribute spread.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Core::Effect
Instance Method Summary collapse
- #channel_gain_for_phase(phase) ⇒ Object private
- #channel_phase_offset(channel_index, channels) ⇒ Object private
-
#initialize(frequency: 5.0, depth: 0.8, spread: 0.0, type: :sine, context: Deftones.context, **options) ⇒ Tremolo
constructor
A new instance of Tremolo.
- #process_effect_block(input_block, num_frames, start_frame, _cache) ⇒ Object private
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: 5.0, depth: 0.8, spread: 0.0, type: :sine, context: Deftones.context, **options) ⇒ Tremolo
Returns a new instance of Tremolo.
10 11 12 13 14 15 16 17 18 |
# File 'lib/deftones/effect/tremolo.rb', line 10 def initialize(frequency: 5.0, depth: 0.8, spread: 0.0, type: :sine, context: Deftones.context, **) super(context: context, wet: 1.0, **) @frequency = frequency.to_f @depth = depth.to_f @spread = spread.to_f @type = normalize_modulation_type(type) @phase = 0.0 initialize_modulation_control end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
8 9 10 |
# File 'lib/deftones/effect/tremolo.rb', line 8 def depth @depth end |
#frequency ⇒ Object
Returns the value of attribute frequency.
8 9 10 |
# File 'lib/deftones/effect/tremolo.rb', line 8 def frequency @frequency end |
#spread ⇒ Object
Returns the value of attribute spread.
8 9 10 |
# File 'lib/deftones/effect/tremolo.rb', line 8 def spread @spread end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/deftones/effect/tremolo.rb', line 8 def type @type end |
Instance Method Details
#channel_gain_for_phase(phase) ⇒ Object (private)
46 47 48 49 |
# File 'lib/deftones/effect/tremolo.rb', line 46 def channel_gain_for_phase(phase) modulation = unipolar_modulation_value(phase, default: 1.0) 1.0 - (@depth * (1.0 - modulation)) end |
#channel_phase_offset(channel_index, channels) ⇒ Object (private)
40 41 42 43 44 |
# File 'lib/deftones/effect/tremolo.rb', line 40 def channel_phase_offset(channel_index, channels) return 0.0 if channels <= 1 (@spread / 360.0) * (channel_index.to_f / [channels - 1, 1].max) end |
#process_effect_block(input_block, num_frames, start_frame, _cache) ⇒ Object (private)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/deftones/effect/tremolo.rb', line 22 def process_effect_block(input_block, num_frames, start_frame, _cache) output_channels = [input_block.channels, 2].max source = input_block.fit_channels(output_channels) output = Array.new(output_channels) { Array.new(num_frames, 0.0) } num_frames.times do |index| current_time = (start_frame + index).to_f / context.sample_rate base_phase = modulation_phase_for(current_time) output_channels.times do |channel_index| phase = base_phase.nil? ? nil : base_phase + channel_phase_offset(channel_index, output_channels) output[channel_index][index] = source.channel_data[channel_index][index] * channel_gain_for_phase(phase) end end Core::AudioBlock.from_channel_data(output) end |