Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
「調和純正律で遊ぼう https://bit.ly/3j7KUpu 」純正律ハ長調の周波数比
#!/usr/bin/env ruby
#-*-ruby-*-
require "rational"
# 純正律ハ長調の周波数比の配列を求める。
def just_intonation_in_C_ratios
octave = Rational(2, 1)
perfect_fifth = Rational(3, 2)
major_third = Rational(5, 4)
# minor_third = perfect_fifth / major_third # (= 6/5)
# 主音から完全5度を、下に取ってFを、上に取ってGを得る。
c = Rational(1)
f = c / perfect_fifth * octave
g = c * perfect_fifth
# Gから上へ完全5度を取ってDを得る。
d = g * perfect_fifth / octave
# C,F,Gから上へ長3度を取ってE,A,Hを得る。
e = c * major_third
a = f * major_third
h = g * major_third
# p [c, d, e, f, g, a, h]
# A,D,Eから上へ長3度を取ってCis,Fis,Gisを得る。
# G,Dから下へ長3度を取ってEs,Bを得る。
cis = a * major_third / octave
es = g / major_third
fis = d * major_third
gis = e * major_third
b = d / major_third * octave
[c, cis, d, es, e, f, fis, g, gis, a, b, h]
end
puts "# 周波数比"
p just_intonation_in_C_ratios
puts "# 主音からのセント値"
p just_intonation_in_C_ratios.map { |ratio|
(1200 * Math.log2(ratio)).round(1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment