Last active
December 30, 2023 17:39
-
-
Save rbnpi/873043526efa45bab615b28080c7dc19 to your computer and use it in GitHub Desktop.
Sonify Euler's number e using Sonic Pi. Hear it on https://soundcloud.com/sp-rbn/sonifye
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
#sonification generated by the number E with steadily increasing precision | |
#from 1 to 60, written by Robin Newman, Dec 2023 | |
#The number is generated by BigMath.E(precision) | |
#I use each digit as a lookup index into a minor pentatonic scale | |
#I read the digits from each end of the current number, and play | |
#one of the two resulting notes, selected by a density funtion and a spread function | |
#which gives a bit of rhythm. | |
#These notes are underpinned by a base drone, which is layered as it has a longer | |
#release time and is generated increasingly as the base E string gets longer | |
#The idea for this was sparked from an interesting StackOverflow question | |
#https://stackoverflow.com/questions/28222394/how-to-get-the-nth-place-of-pi-using-ruby-bigmath | |
use_debug false | |
use_synth_defaults amp: 0.3 | |
require "bigdecimal/math" | |
define :e do |prec| | |
return "2" if prec==1 | |
return BigMath.E(prec).to_s[2..-3] | |
end | |
define :pent do |offset| | |
return scale(:e3,:minor_pentatonic,num_octaves: 2)[offset.to_i] | |
end | |
with_fx :reverb, room: 0.6,mix: 0.6 do | |
k=0 | |
for i in (1..60) do | |
base=[0,-5,7].choose | |
if e(i).length >k #only play if length increased | |
k=e(i).length | |
puts "E digits: (#{i}) #{e(i)}" | |
k.times do |x| #iterate through notes from pent lookup of E string | |
#play layered drone which will build in volume | |
synth :bass_foundation,note: pent(7)-36+base,release: (k-1)*0.1,amp: 0.2 | |
#use density and sporead for some rhythm | |
density dice(2) do | |
tick | |
#play notes starting at different ends of current E string | |
synth :tb303,note: base+pent(e(i).reverse[x]),release: 0.2,pan: -0.5,cutoff: rrand_i(80,110) if spread(5,8).look | |
synth :tb303,note: base-12+ pent(e(i)[x].to_i),release: 0.2,pan: 0.5,cutoff: rrand_i(80,110) if !spread(5,8).look | |
sleep 0.2 | |
end | |
end | |
end | |
sleep 0.2 | |
end | |
end#reverb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment