Class: Deftones::Effects::Phaser
- Inherits:
-
Core::Effect
- Object
- Core::Effect
- Deftones::Effects::Phaser
- Includes:
- ModulationControl
- Defined in:
- lib/deftones/effect/phaser.rb
Instance Attribute Summary collapse
-
#base_frequency ⇒ Object
Returns the value of attribute base_frequency.
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#octaves ⇒ Object
Returns the value of attribute octaves.
-
#q ⇒ Object
Returns the value of attribute q.
-
#stages ⇒ Object
Returns the value of attribute stages.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Core::Effect
Instance Method Summary collapse
-
#initialize(frequency: 0.5, octaves: 3.0, q: 0.8, base_frequency: 300.0, stages: 4, type: :sine, context: Deftones.context, **options) ⇒ Phaser
constructor
A new instance of Phaser.
- #process_effect_block(input_block, num_frames, start_frame, _cache) ⇒ Object private
- #stage_filters(channels) ⇒ 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: 0.5, octaves: 3.0, q: 0.8, base_frequency: 300.0, stages: 4, type: :sine, context: Deftones.context, **options) ⇒ Phaser
Returns a new instance of Phaser.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/deftones/effect/phaser.rb', line 11 def initialize( frequency: 0.5, octaves: 3.0, q: 0.8, base_frequency: 300.0, stages: 4, type: :sine, context: Deftones.context, ** ) super(context: context, **) @frequency = frequency.to_f @octaves = octaves.to_f @q = q.to_f @base_frequency = base_frequency.to_f @stages = stages.to_i @type = normalize_modulation_type(type) @phase = 0.0 @filters = [] initialize_modulation_control end |
Instance Attribute Details
#base_frequency ⇒ Object
Returns the value of attribute base_frequency.
8 9 10 |
# File 'lib/deftones/effect/phaser.rb', line 8 def base_frequency @base_frequency end |
#frequency ⇒ Object
Returns the value of attribute frequency.
8 9 10 |
# File 'lib/deftones/effect/phaser.rb', line 8 def frequency @frequency end |
#octaves ⇒ Object
Returns the value of attribute octaves.
8 9 10 |
# File 'lib/deftones/effect/phaser.rb', line 8 def octaves @octaves end |
#q ⇒ Object
Returns the value of attribute q.
8 9 10 |
# File 'lib/deftones/effect/phaser.rb', line 8 def q @q end |
#stages ⇒ Object
Returns the value of attribute stages.
9 10 11 |
# File 'lib/deftones/effect/phaser.rb', line 9 def stages @stages end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/deftones/effect/phaser.rb', line 8 def type @type end |
Instance Method Details
#process_effect_block(input_block, num_frames, start_frame, _cache) ⇒ Object (private)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/deftones/effect/phaser.rb', line 39 def process_effect_block(input_block, num_frames, start_frame, _cache) filter_banks = stage_filters(input_block.channels) output = Array.new(input_block.channels) { Array.new(num_frames, 0.0) } num_frames.times do |index| current_time = (start_frame + index).to_f / context.sample_rate phase = modulation_phase_for(current_time) modulation = unipolar_modulation_value(phase, default: 0.5) input_block.channel_data.each_with_index do |channel, channel_index| output[channel_index][index] = filter_banks[channel_index].each_with_index.reduce(channel[index]) do |sample, (filter, stage_index)| stage_position = @stages == 1 ? 0.0 : (stage_index.to_f / (@stages - 1)) - 0.5 cutoff = @base_frequency * (2.0**((modulation * @octaves) + (stage_position * 0.5))) filter.update(type: :notch, frequency: cutoff, q: @q, gain_db: 0.0, sample_rate: context.sample_rate) filter.process_sample(sample) end end end Core::AudioBlock.from_channel_data(output) end |
#stage_filters(channels) ⇒ Object (private)
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/deftones/effect/phaser.rb', line 60 def stage_filters(channels) required_channels = [channels.to_i, 1].max while @filters.length < required_channels @filters << Array.new(@stages) { DSP::Biquad.new } end @filters.map! do |bank| bank.length == @stages ? bank : Array.new(@stages) { DSP::Biquad.new } end @filters end |