Last active
March 15, 2016 23:50
-
-
Save Dillie-O/2ed76b997539e0002a4a to your computer and use it in GitHub Desktop.
Sonic Pi code file for playing a Pi melody on a decatonic scale
This file contains hidden or 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
# Sonic Pi synth file (with notes) for generating music | |
# on a decatonic scale with pi as the "melody" | |
# | |
# https://en.wikipedia.org/wiki/Piano_key_frequencies | |
# Middle C (C4) - 261 HZ | |
# High C (C5) - 523HZ | |
# Computing major notes in scale: | |
# | |
# (523-261) / 8 = 32.75 HZ between notes | |
# D = 261+32.75 = 293.75 HZ | |
# | |
# Converting into decotonic scale | |
# (523-261) / 10 = 26.2 HZ between notes | |
# New function to convert "note" to decotonic | |
# scale HZ and play as midi note | |
define :decplay do |x| | |
baseHz = 261 | |
decScaleDiff = (523-261) / 10 | |
decScaleHz = baseHz + (x * decScaleDiff) | |
play hz_to_midi(decScaleHz) | |
end | |
# Strip . from Pi | |
piValue = "3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360011330530548820466521384146951941511609" | |
piArrayRaw = piValue.split(//) | |
piDigits = piArrayRaw.size | |
print "PI: " << piValue << "\n" | |
print "PI Digit Count: " << String(piDigits) << "\n" | |
#Play pi | |
i = 0 | |
piDigits.times do | |
decplay(Integer(piArrayRaw[i])) | |
sleep 0.33 | |
i = i + 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment