Class: Ruck::UGen::Generators::SinOsc

Inherits:
Object
  • Object
show all
Includes:
Oscillator, Source
Defined in:
lib/ruck/ugen/oscillators.rb

Constant Summary

Constants included from Oscillator

Oscillator::TWO_PI

Instance Attribute Summary

Attributes included from UGenBase

#name

Instance Method Summary collapse

Methods included from Oscillator

included, #phase_forward

Methods included from UGenBase

#to_s

Methods included from Source

#<<, #>>, #last, #out, #out_channels

Constructor Details

#initialize(attrs = {}) ⇒ SinOsc

Returns a new instance of SinOsc.



34
35
36
37
38
39
# File 'lib/ruck/ugen/oscillators.rb', line 34

def initialize(attrs = {})
  parse_attrs({ :freq => 440.0,
                :gain => 1.0 }.merge(attrs))
  @phase = 0.0
  @last = 0.0
end

Instance Method Details

#attr_namesObject



49
50
51
# File 'lib/ruck/ugen/oscillators.rb', line 49

def attr_names
  [:freq, :gain, :phase]
end

#next(now) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/ruck/ugen/oscillators.rb', line 41

def next(now)
  return @last if @now == now
  @now = now
  @last = gain * Math.sin(phase * TWO_PI)
  phase_forward
  @last
end