Class: Deftones::Component::Gate
- Inherits:
-
Deftones::Core::AudioNode
- Object
- Deftones::Core::AudioNode
- Deftones::Component::Gate
- Defined in:
- lib/deftones/component/gate.rb
Instance Attribute Summary collapse
-
#release ⇒ Object
Returns the value of attribute release.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Attributes inherited from Deftones::Core::AudioNode
Instance Method Summary collapse
- #ensure_gain_state(channels) ⇒ Object private
- #gate(sample, channel_index) ⇒ Object private
-
#initialize(threshold: -40.0,, release: 0.05, context: Deftones.context) ⇒ Gate
constructor
A new instance of Gate.
- #multichannel_process? ⇒ Boolean
- #process(input_block, num_frames, _start_frame, _cache) ⇒ Object
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(threshold: -40.0,, release: 0.05, context: Deftones.context) ⇒ Gate
Returns a new instance of Gate.
8 9 10 11 12 13 |
# File 'lib/deftones/component/gate.rb', line 8 def initialize(threshold: -40.0, release: 0.05, context: Deftones.context) super(context: context) @threshold = threshold.to_f @release = release.to_f @gain = [] end |
Instance Attribute Details
#release ⇒ Object
Returns the value of attribute release.
6 7 8 |
# File 'lib/deftones/component/gate.rb', line 6 def release @release end |
#threshold ⇒ Object
Returns the value of attribute threshold.
6 7 8 |
# File 'lib/deftones/component/gate.rb', line 6 def threshold @threshold end |
Instance Method Details
#ensure_gain_state(channels) ⇒ Object (private)
40 41 42 43 |
# File 'lib/deftones/component/gate.rb', line 40 def ensure_gain_state(channels) required = [channels.to_i, 1].max @gain.fill(0.0, @gain.length...required) end |
#gate(sample, channel_index) ⇒ Object (private)
30 31 32 33 34 35 36 37 38 |
# File 'lib/deftones/component/gate.rb', line 30 def gate(sample, channel_index) level_db = 20.0 * Math.log10([sample.abs, 1.0e-9].max) target = level_db >= @threshold ? 1.0 : 0.0 smoothing = 1.0 / [(@release * context.sample_rate), 1.0].max gain = @gain[channel_index] gain += (target - gain) * smoothing @gain[channel_index] = gain sample * gain end |
#multichannel_process? ⇒ Boolean
15 16 17 |
# File 'lib/deftones/component/gate.rb', line 15 def multichannel_process? true end |
#process(input_block, num_frames, _start_frame, _cache) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/deftones/component/gate.rb', line 19 def process(input_block, num_frames, _start_frame, _cache) ensure_gain_state(input_block.channels) Core::AudioBlock.from_channel_data( input_block.channel_data.each_with_index.map do |channel, channel_index| Array.new(num_frames) { |index| gate(channel[index], channel_index) } end ) end |