Class: Deftones::Component::Filter
- Inherits:
-
Deftones::Core::AudioNode
- Object
- Deftones::Core::AudioNode
- Deftones::Component::Filter
- Defined in:
- lib/deftones/component/filter.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#detune ⇒ Object
Returns the value of attribute detune.
-
#frequency ⇒ Object
readonly
Returns the value of attribute frequency.
-
#gain ⇒ Object
readonly
Returns the value of attribute gain.
-
#q ⇒ Object
readonly
Returns the value of attribute q.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Deftones::Core::AudioNode
Instance Method Summary collapse
- #ensure_biquads(channels) ⇒ Object private
-
#initialize(type: :lowpass, frequency: 350.0, q: 1.0, gain: 0.0, detune: 0.0, context: Deftones.context) ⇒ Filter
constructor
A new instance of Filter.
- #multichannel_process? ⇒ Boolean
- #normalize_type(type) ⇒ Object private
- #process(input_block, num_frames, start_frame, _cache) ⇒ Object
- #reset! ⇒ Object
- #update_filter(biquad, frequency, detune, q, gain) ⇒ Object private
Methods inherited from Deftones::Core::AudioNode
#>>, #attach_destination, #attach_source, #block_time, #chain, #channel_count, #channel_count_mode, #channel_interpretation, #connect, #connected?, #default_input_channels, #default_output_channels, #destination_for_connection, #detach_all_destinations, #detach_destination, #detach_source, #disconnect, #dispose, #disposed?, #fan, #get, #immediate, #input_for_index, #inputs, #mix_source_blocks, #name, #normalize_connection_index, #normalize_output_block, #now, #number_of_inputs, #number_of_outputs, #output, #output_for_connection, #output_for_index, #outputs, #raise_connection_index_error!, #reaches_node?, #render, #render_block, #sample_time, #set, #to_destination, #to_frequency, #to_master, #to_midi, #to_output, #to_s, #to_seconds, #to_ticks, #uses_legacy_render_for_block?, #validate_connectable!, #validate_connection_index!
Constructor Details
#initialize(type: :lowpass, frequency: 350.0, q: 1.0, gain: 0.0, detune: 0.0, context: Deftones.context) ⇒ Filter
Returns a new instance of Filter.
10 11 12 13 14 15 16 17 18 |
# File 'lib/deftones/component/filter.rb', line 10 def initialize(type: :lowpass, frequency: 350.0, q: 1.0, gain: 0.0, detune: 0.0, context: Deftones.context) super(context: context) @biquads = [] self.type = type @frequency = Core::Signal.new(value: frequency, units: :frequency, context: context) @q = Core::Signal.new(value: q, units: :number, context: context) @gain = Core::Signal.new(value: gain, units: :number, context: context) @detune = Core::Signal.new(value: detune, units: :number, context: context) end |
Instance Attribute Details
#detune ⇒ Object
Returns the value of attribute detune.
8 9 10 |
# File 'lib/deftones/component/filter.rb', line 8 def detune @detune end |
#frequency ⇒ Object (readonly)
Returns the value of attribute frequency.
8 9 10 |
# File 'lib/deftones/component/filter.rb', line 8 def frequency @frequency end |
#gain ⇒ Object (readonly)
Returns the value of attribute gain.
8 9 10 |
# File 'lib/deftones/component/filter.rb', line 8 def gain @gain end |
#q ⇒ Object (readonly)
Returns the value of attribute q.
8 9 10 |
# File 'lib/deftones/component/filter.rb', line 8 def q @q end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/deftones/component/filter.rb', line 8 def type @type end |
Instance Method Details
#ensure_biquads(channels) ⇒ Object (private)
71 72 73 74 75 |
# File 'lib/deftones/component/filter.rb', line 71 def ensure_biquads(channels) required = [channels.to_i, 1].max missing = required - @biquads.length missing.times { @biquads << DSP::Biquad.new } if missing.positive? end |
#multichannel_process? ⇒ Boolean
32 33 34 |
# File 'lib/deftones/component/filter.rb', line 32 def multichannel_process? true end |
#normalize_type(type) ⇒ Object (private)
77 78 79 80 81 82 |
# File 'lib/deftones/component/filter.rb', line 77 def normalize_type(type) normalized = type.to_sym return normalized if TYPES.include?(normalized) raise ArgumentError, "Unsupported filter type: #{type}" end |
#process(input_block, num_frames, start_frame, _cache) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/deftones/component/filter.rb', line 36 def process(input_block, num_frames, start_frame, _cache) ensure_biquads(input_block.channels) frequencies = @frequency.process(num_frames, start_frame) detunes = @detune.process(num_frames, start_frame) q_values = @q.process(num_frames, start_frame) gain_values = @gain.process(num_frames, start_frame) Core::AudioBlock.from_channel_data( input_block.channel_data.each_with_index.map do |channel, channel_index| biquad = @biquads[channel_index] Array.new(num_frames) do |index| update_filter(biquad, frequencies[index], detunes[index], q_values[index], gain_values[index]) biquad.process_sample(channel[index]) end end ) end |
#reset! ⇒ Object
54 55 56 57 |
# File 'lib/deftones/component/filter.rb', line 54 def reset! @biquads.each(&:reset!) self end |
#update_filter(biquad, frequency, detune, q, gain) ⇒ Object (private)
61 62 63 64 65 66 67 68 69 |
# File 'lib/deftones/component/filter.rb', line 61 def update_filter(biquad, frequency, detune, q, gain) biquad.update( type: normalize_type(@type), frequency: frequency * (2.0**(detune / 1200.0)), q: q, gain_db: gain * 24.0, sample_rate: context.sample_rate ) end |