Class: Deftones::Effects::Chorus
- Inherits:
-
Core::Effect
- Object
- Core::Effect
- Deftones::Effects::Chorus
- Includes:
- ModulationControl
- Defined in:
- lib/deftones/effect/chorus.rb
Instance Attribute Summary collapse
-
#delay_time ⇒ Object
Returns the value of attribute delay_time.
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#feedback ⇒ Object
Returns the value of attribute feedback.
-
#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_phase_offset(channel_index, channels) ⇒ Object private
- #ensure_delay_lines(channels) ⇒ Object private
-
#initialize(frequency: 1.5, depth: 0.003, delay_time: 0.015, feedback: 0.0, spread: 180.0, type: :sine, context: Deftones.context, **options) ⇒ Chorus
constructor
A new instance of Chorus.
- #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: 1.5, depth: 0.003, delay_time: 0.015, feedback: 0.0, spread: 180.0, type: :sine, context: Deftones.context, **options) ⇒ Chorus
Returns a new instance of Chorus.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/deftones/effect/chorus.rb', line 10 def initialize( frequency: 1.5, depth: 0.003, delay_time: 0.015, feedback: 0.0, spread: 180.0, type: :sine, context: Deftones.context, ** ) super(context: context, **) @frequency = frequency.to_f @depth = depth.to_f @delay_time = delay_time.to_f @feedback = feedback.to_f @spread = spread.to_f @type = normalize_modulation_type(type) @phase = 0.0 @delay_lines = [] initialize_modulation_control end |
Instance Attribute Details
#delay_time ⇒ Object
Returns the value of attribute delay_time.
8 9 10 |
# File 'lib/deftones/effect/chorus.rb', line 8 def delay_time @delay_time end |
#depth ⇒ Object
Returns the value of attribute depth.
8 9 10 |
# File 'lib/deftones/effect/chorus.rb', line 8 def depth @depth end |
#feedback ⇒ Object
Returns the value of attribute feedback.
8 9 10 |
# File 'lib/deftones/effect/chorus.rb', line 8 def feedback @feedback end |
#frequency ⇒ Object
Returns the value of attribute frequency.
8 9 10 |
# File 'lib/deftones/effect/chorus.rb', line 8 def frequency @frequency end |
#spread ⇒ Object
Returns the value of attribute spread.
8 9 10 |
# File 'lib/deftones/effect/chorus.rb', line 8 def spread @spread end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/deftones/effect/chorus.rb', line 8 def type @type end |
Instance Method Details
#channel_phase_offset(channel_index, channels) ⇒ Object (private)
66 67 68 69 70 |
# File 'lib/deftones/effect/chorus.rb', line 66 def channel_phase_offset(channel_index, channels) return 0.0 if channels <= 1 || channel_index.zero? (@spread / 360.0) * (channel_index.to_f / [channels - 1, 1].max) end |
#ensure_delay_lines(channels) ⇒ Object (private)
59 60 61 62 63 64 |
# File 'lib/deftones/effect/chorus.rb', line 59 def ensure_delay_lines(channels) required = [channels.to_i, 1].max while @delay_lines.length < required @delay_lines << DSP::DelayLine.new((0.1 * context.sample_rate).ceil) end end |
#process_effect_block(input_block, num_frames, start_frame, _cache) ⇒ Object (private)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/deftones/effect/chorus.rb', line 34 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) ensure_delay_lines(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) modulation = unipolar_modulation_value(phase, default: 0.5) delay = (@delay_time + (@depth * modulation)) * context.sample_rate output[channel_index][index] = @delay_lines[channel_index].tap( delay, input_sample: source.channel_data[channel_index][index], feedback: @feedback ) end end Core::AudioBlock.from_channel_data(output) end |