Sha256: 560941a7354899514317f2d100e0e231531cbc6851e45e2635f773b199ae43e7

Contents?: true

Size: 630 Bytes

Versions: 21

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true

# A tuning has a reference pitch and frequency and provides frequencies for all pitches
# The base class assumes equal temperament tuning. By default, A4 = 440.0 Hz
class HeadMusic::Tuning
  attr_accessor :reference_pitch

  delegate :pitch, :frequency, to: :reference_pitch, prefix: true

  def initialize(reference_pitch: :a440)
    @reference_pitch = HeadMusic::ReferencePitch.get(reference_pitch)
  end

  def frequency_for(pitch)
    pitch = HeadMusic::Pitch.get(pitch)
    reference_pitch_frequency * (2**(1.0 / 12))**(pitch - reference_pitch.pitch).semitones
  end
end

# TODO: other tunings

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
head_music-0.24.0 lib/head_music/tuning.rb