Class: Deftones::Source::ToneOscillatorNode
- Inherits:
-
Oscillator
- Object
- Core::Source
- Oscillator
- Deftones::Source::ToneOscillatorNode
- Defined in:
- lib/deftones/source/tone_oscillator_node.rb
Constant Summary
Constants inherited from Oscillator
Oscillator::GENERATORS, Oscillator::TYPES
Instance Attribute Summary collapse
-
#detune ⇒ Object
Returns the value of attribute detune.
-
#onended ⇒ Object
Returns the value of attribute onended.
Attributes inherited from Oscillator
Attributes inherited from Core::Source
Instance Method Summary collapse
- #cancel_stop ⇒ Object
- #detune_ratio(cents) ⇒ Object private
-
#initialize(detune: 0.0, context: Deftones.context, **options) ⇒ ToneOscillatorNode
constructor
A new instance of ToneOscillatorNode.
- #notify_ended(current_time) ⇒ Object private
- #process(_input_buffer, num_frames, start_frame, _cache) ⇒ Object
- #start(time = nil) ⇒ Object
- #state(time = context.current_time) ⇒ Object
Methods inherited from Oscillator
bandlimited_sawtooth, bandlimited_square, bandlimited_triangle, naive_triangle, #normalize_type, #phase, #phase=, poly_blep, poly_blep_end, poly_blep_start, sample, #sample_for
Methods inherited from Core::Source
#active_at?, #apply_volume!, #clear_transport_event, #dispose, #mute?, #notify_stop_in_window, #number_of_inputs, #render, #render_block, #resolve_time, #resolve_transport_time, #restart, #schedule_transport_event, #source_type, #stop, #sync, #synced?, #unsync, #uses_legacy_render_for_block?
Constructor Details
#initialize(detune: 0.0, context: Deftones.context, **options) ⇒ ToneOscillatorNode
Returns a new instance of ToneOscillatorNode.
9 10 11 12 13 14 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 9 def initialize(detune: 0.0, context: Deftones.context, **) super(context: context, **) @detune = Core::Signal.new(value: detune, units: :number, context: context) @onended = nil @ended_notified = false end |
Instance Attribute Details
#detune ⇒ Object
Returns the value of attribute detune.
7 8 9 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 7 def detune @detune end |
#onended ⇒ Object
Returns the value of attribute onended.
6 7 8 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 6 def onended @onended end |
Instance Method Details
#cancel_stop ⇒ Object
24 25 26 27 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 24 def cancel_stop @stop_time = nil self end |
#detune_ratio(cents) ⇒ Object (private)
54 55 56 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 54 def detune_ratio(cents) 2.0**(cents.to_f / 1200.0) end |
#notify_ended(current_time) ⇒ Object (private)
58 59 60 61 62 63 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 58 def notify_ended(current_time) return if @ended_notified @ended_notified = true @onended&.call(current_time) end |
#process(_input_buffer, num_frames, start_frame, _cache) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 34 def process(_input_buffer, num_frames, start_frame, _cache) oscillator_type = send(:normalize_type, @type) frequencies = @frequency.process(num_frames, start_frame) detunes = @detune.process(num_frames, start_frame) Array.new(num_frames) do |index| current_time = (start_frame + index).to_f / context.sample_rate notify_ended(current_time) if @stop_time && current_time >= @stop_time next 0.0 unless active_at?(current_time) frequency = frequencies[index] * detune_ratio(detunes[index]) phase_increment = frequency / context.sample_rate sample = sample_for(oscillator_type, @phase, phase_increment) @phase = (@phase + phase_increment) % 1.0 sample end end |
#start(time = nil) ⇒ Object
29 30 31 32 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 29 def start(time = nil) @ended_notified = false super end |
#state(time = context.current_time) ⇒ Object
20 21 22 |
# File 'lib/deftones/source/tone_oscillator_node.rb', line 20 def state(time = context.current_time) active_at?(resolve_time(time)) ? :started : :stopped end |