class ColtraneSynth::Synth

Attributes

freq[R]
nominal_rate[R]

Public Class Methods

new(buffer, freq, nominal_rate) click to toggle source
# File lib/coltrane/synth/synth.rb, line 7
def initialize(buffer, freq, nominal_rate)
  @freq = freq.to_f
  @nominal_rate = nominal_rate

  i = -1
  wav = NArray.sint(1024)

  while i += 1
    1024.times do |j|
      wav[j] = (0.4 * Math.sin(phase(freq) * (i * 1024 + j)) * 0x7FFF).round
    end
    buffer << wav
  end
end

Public Instance Methods

phase(freq) click to toggle source
# File lib/coltrane/synth/synth.rb, line 22
def phase(freq)
  Math::PI * 2.0 * freq / nominal_rate
end