Class: Synthesizer::ShapePos
- Inherits:
-
Object
- Object
- Synthesizer::ShapePos
- Defined in:
- lib/synthesizer/shape_pos.rb
Constant Summary collapse
- SEMITONE_RATIO =
2.0 ** (1.0 / 12.0)
Instance Method Summary collapse
-
#initialize(samplerate, init_phase) ⇒ ShapePos
constructor
A new instance of ShapePos.
- #next(hz, sym, sync) ⇒ Object
Constructor Details
#initialize(samplerate, init_phase) ⇒ ShapePos
Returns a new instance of ShapePos.
5 6 7 8 9 10 11 |
# File 'lib/synthesizer/shape_pos.rb', line 5 def initialize(samplerate, init_phase) @samplerate = samplerate.to_f init_phase = init_phase ? init_phase.to_f : Random.rand(1.0) @sync_phase = init_phase @shape_phase = init_phase end |
Instance Method Details
#next(hz, sym, sync) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/synthesizer/shape_pos.rb', line 13 def next(hz, sym, sync) if sync<0.0 sync = 0.0 end if 1.0<=@sync_phase @sync_phase %= 1.0 @shape_phase = @sync_phase end sync_hz = hz sync_delta = sync_hz / @samplerate @sync_phase += sync_delta shape_hz = hz * (SEMITONE_RATIO ** sync) shape_delta = shape_hz / @samplerate @shape_phase += shape_delta end |