Class: Deftones::Source::AMOscillator
- Inherits:
-
Core::Source
- Object
- Core::Source
- Deftones::Source::AMOscillator
- Defined in:
- lib/deftones/source/am_oscillator.rb
Instance Attribute Summary collapse
-
#detune ⇒ Object
Returns the value of attribute detune.
-
#frequency ⇒ Object
readonly
Returns the value of attribute frequency.
-
#harmonicity ⇒ Object
readonly
Returns the value of attribute harmonicity.
Attributes inherited from Core::Source
Instance Method Summary collapse
-
#initialize(frequency: 440.0, harmonicity: 2.0, detune: 0.0, phase: 0.0, context: Deftones.context) ⇒ AMOscillator
constructor
A new instance of AMOscillator.
- #process(_input_buffer, num_frames, start_frame, _cache) ⇒ Object
Methods inherited from Core::Source
#active_at?, #apply_volume!, #cancel_stop, #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, #start, #state, #stop, #sync, #synced?, #unsync, #uses_legacy_render_for_block?
Constructor Details
#initialize(frequency: 440.0, harmonicity: 2.0, detune: 0.0, phase: 0.0, context: Deftones.context) ⇒ AMOscillator
Returns a new instance of AMOscillator.
8 9 10 11 12 13 14 15 |
# File 'lib/deftones/source/am_oscillator.rb', line 8 def initialize(frequency: 440.0, harmonicity: 2.0, detune: 0.0, phase: 0.0, context: Deftones.context) super(context: context) @frequency = Core::Signal.new(value: frequency, units: :frequency, context: context) @harmonicity = Core::Signal.new(value: harmonicity, units: :number, context: context) @detune = Core::Signal.new(value: detune, units: :number, context: context) @carrier_phase = phase.to_f % 1.0 @modulator_phase = phase.to_f % 1.0 end |
Instance Attribute Details
#detune ⇒ Object
Returns the value of attribute detune.
6 7 8 |
# File 'lib/deftones/source/am_oscillator.rb', line 6 def detune @detune end |
#frequency ⇒ Object (readonly)
Returns the value of attribute frequency.
6 7 8 |
# File 'lib/deftones/source/am_oscillator.rb', line 6 def frequency @frequency end |
#harmonicity ⇒ Object (readonly)
Returns the value of attribute harmonicity.
6 7 8 |
# File 'lib/deftones/source/am_oscillator.rb', line 6 def harmonicity @harmonicity end |
Instance Method Details
#process(_input_buffer, num_frames, start_frame, _cache) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/deftones/source/am_oscillator.rb', line 21 def process(_input_buffer, num_frames, start_frame, _cache) frequencies = @frequency.process(num_frames, start_frame) harmonicities = @harmonicity.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 next 0.0 unless active_at?(current_time) carrier_frequency = frequencies[index] * (2.0**(detunes[index].to_f / 1200.0)) modulator_frequency = carrier_frequency * harmonicities[index] carrier = Math.sin(2.0 * Math::PI * @carrier_phase) modulator = (Math.sin(2.0 * Math::PI * @modulator_phase) + 1.0) * 0.5 @carrier_phase = (@carrier_phase + (carrier_frequency / context.sample_rate)) % 1.0 @modulator_phase = (@modulator_phase + (modulator_frequency / context.sample_rate)) % 1.0 carrier * modulator end end |