Class: Deftones::Component::MidSideMerge
- Inherits:
-
Deftones::Core::AudioNode
- Object
- Deftones::Core::AudioNode
- Deftones::Component::MidSideMerge
- Defined in:
- lib/deftones/component/mid_side_merge.rb
Constant Summary collapse
- SQRT_ONE_HALF =
Math.sqrt(0.5)
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#mid ⇒ Object
readonly
Returns the value of attribute mid.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
Attributes inherited from Deftones::Core::AudioNode
Instance Method Summary collapse
-
#initialize(context: Deftones.context) ⇒ MidSideMerge
constructor
A new instance of MidSideMerge.
- #render(num_frames, start_frame = 0, cache = {}) ⇒ Object
- #render_block(num_frames, start_frame = 0, 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, #multichannel_process?, #name, #normalize_connection_index, #normalize_output_block, #now, #number_of_inputs, #number_of_outputs, #output_for_connection, #output_for_index, #outputs, #process, #raise_connection_index_error!, #reaches_node?, #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(context: Deftones.context) ⇒ MidSideMerge
Returns a new instance of MidSideMerge.
10 11 12 13 14 15 16 |
# File 'lib/deftones/component/mid_side_merge.rb', line 10 def initialize(context: Deftones.context) super(context: context) @mid = Core::Gain.new(context: context) @side = Core::Gain.new(context: context) @input = @mid @output = self end |
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
8 9 10 |
# File 'lib/deftones/component/mid_side_merge.rb', line 8 def input @input end |
#mid ⇒ Object (readonly)
Returns the value of attribute mid.
8 9 10 |
# File 'lib/deftones/component/mid_side_merge.rb', line 8 def mid @mid end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/deftones/component/mid_side_merge.rb', line 8 def output @output end |
#side ⇒ Object (readonly)
Returns the value of attribute side.
8 9 10 |
# File 'lib/deftones/component/mid_side_merge.rb', line 8 def side @side end |
Instance Method Details
#render(num_frames, start_frame = 0, cache = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/deftones/component/mid_side_merge.rb', line 18 def render(num_frames, start_frame = 0, cache = {}) cache_key = [object_id, start_frame, num_frames] return cache.fetch(cache_key).dup if cache.key?(cache_key) mid_buffer = @mid.render(num_frames, start_frame, cache) side_buffer = @side.render(num_frames, start_frame, cache) output_buffer = Array.new(num_frames) do |index| left = (mid_buffer[index] + side_buffer[index]) * SQRT_ONE_HALF right = (mid_buffer[index] - side_buffer[index]) * SQRT_ONE_HALF (left + right) * 0.5 end cache[cache_key] = output_buffer output_buffer.dup end |
#render_block(num_frames, start_frame = 0, cache = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/deftones/component/mid_side_merge.rb', line 35 def render_block(num_frames, start_frame = 0, cache = {}) cache_key = [object_id, :block, start_frame, num_frames] return cache.fetch(cache_key).dup if cache.key?(cache_key) mid_block = @mid.send(:render_block, num_frames, start_frame, cache) side_block = @side.send(:render_block, num_frames, start_frame, cache) mid = mid_block.mono side = side_block.mono output = Core::AudioBlock.from_channel_data([ Array.new(num_frames) { |index| (mid[index] + side[index]) * SQRT_ONE_HALF }, Array.new(num_frames) { |index| (mid[index] - side[index]) * SQRT_ONE_HALF } ]) cache[cache_key] = output output.dup end |