Sha256: bb164ff3f3c4185b9579d64bc235e98d85dfca96c3a11a904378e09b8f7736af

Contents?: true

Size: 515 Bytes

Versions: 23

Compression:

Stored size: 515 Bytes

Contents

# frozen_string_literal: true

module ColtraneSynth
  class Synth
    attr_reader :freq, :nominal_rate

    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

    def phase(freq)
      Math::PI * 2.0 * freq / nominal_rate
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
coltrane-3.0.0.rc1 lib/coltrane/synth/synth.rb
coltrane-3.0.0.pre lib/coltrane/synth/synth.rb
coltrane-2.2.1 lib/coltrane_synth/synth.rb