Sha256: 73e05e39712ecf1cf6e229be04d8007111265d52aeb30213bb18ffde9a5a8ead
Contents?: true
Size: 755 Bytes
Versions: 2
Compression:
Stored size: 755 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 REFERENCE_FREQUENCY = 440.0 REFERENCE_PITCH_NAME = 'A4' attr_reader :reference_pitch, :reference_frequency def initialize(reference_pitch: nil, reference_frequency: nil) @reference_pitch = reference_pitch || HeadMusic::Pitch.get(REFERENCE_PITCH_NAME) @reference_frequency = reference_frequency || REFERENCE_FREQUENCY end def frequency_for(pitch) pitch = HeadMusic::Pitch.get(pitch) unless pitch.is_a?(HeadMusic::Pitch) reference_frequency * (2**(1.0 / 12))**(pitch - reference_pitch).semitones end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
head_music-0.20.0 | lib/head_music/tuning.rb |
head_music-0.19.2 | lib/head_music/tuning.rb |