Class: RoadToRubykaigi::Audio::RoughTriangleOscillator

Inherits:
Object
  • Object
show all
Includes:
Phasor
Defined in:
lib/road_to_rubykaigi/audio/oscillator.rb

Constant Summary collapse

TABLE_SIZE =
32

Instance Method Summary collapse

Methods included from Phasor

#gain, #sample_rate

Instance Method Details

#generate(frequencies:) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/road_to_rubykaigi/audio/oscillator.rb', line 47

def generate(frequencies:)
  samples = frequencies.map do |frequency|
    phase = tick(frequency: frequency)
    index = (TABLE_SIZE * phase).floor % TABLE_SIZE
    @table[index]
  end
  samples.sum / samples.size
end