Created
May 5, 2022 19:45
-
-
Save 0xabad1dea/e07cbb1293c0c1004c15dcd61d4acc5c to your computer and use it in GitHub Desktop.
Perfect Fourths Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# perfect fourths calculator for Geometric Elamite Musical Hypothesis | |
# 0xabad1dea (Melissa Elliott) May 5th 2022 | |
import math | |
# reference pitch | |
a4 = 440.0 | |
scalenames = ["A4", "Ab", "G", "Gb", "F", "E", "Eb", "D", "Db", "C", "B", "Bb", "A3"] | |
scale = [a4] | |
cents = [0] | |
# calculate a complete cycle of descending fourths | |
for i in range(0,12): | |
# descend exactly one octave (double length of string) | |
n = scale[i] / 2; | |
# go back up by half of half (string is 1.5x length of original string) | |
n = n + (n/2) | |
# fold into one octave (cut string in half) if necessary | |
if(n < a4/2): | |
n = n*2 | |
scale.append(n) | |
# put them in order from highest pitch to lowest | |
scale.sort(reverse=True) | |
# calculate the cents distribution over our octave | |
for i in range(0,12): | |
cents.append(1200 * math.log2(scale[i]/scale[i+1])) | |
# display | |
print("Note\tPitch\tStep c\tTotal cents") | |
for i in range(0,13): | |
print("%s\t%.2f\t%.2f\t%.2f" % (scalenames[i], scale[i], cents[i], sum(cents[0:i+1]))) | |
# the result will be very slightly off from equal temperament | |
# this is not an error. A3 should be exactly a pythagorean comma | |
# (23.46) short of a perfect 1200. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment