TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Raspberry Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me
WHAT DOES PI SOUND LIKE? What does a mathematical number sound like?  Is it musical, does it have a melody?  This is what I wanted to explore, how does a famous mathematical number sound. Having worked with the Raspberry Pi at Picademy I was introduced to Sonic Pi 2, it seemed logic to pick Pi  as the value.  Pi as you will know is and infinite number and although possible  to program every value I would never complete it!  I decided to limit Pi to 10 decimal places. 3.1415926535.

1. What Does Pi Sound Like?


My first step was to assign a musical note to each of the separate digits in Pi.  I initially started at note E as this is the first note on the first musical stave, I then assigned the values, E = 1, F = 2, G = 3, A = 4, B =5, C = 6,  D = 7, E =8, F = 9.   I looked up the MIDI values for each note and then using Sonic Pi 2 I coded each of the notes in the order 3 1415926535.  So the note E had a value of 52 and F 53.  I added a sleep(1) between each note to ensure that they played separately -  
Original Code:
# Welcome to Sonic Pi v2.0
#3.14159265359 first attempt from note E
#MIDI E52 F53 G55 A57 B59 C60 D62 E64 F65
#Position 1=52, 2=53, 3=55, 4=57, 5=59, 6=60, 7=62, 8=64, 9=65
use_synth :mod_saw
2.times do
  play 55 #3
  sleep(1)
  play 52 #1
  sleep(1)
  play 57 #4
  sleep(1)
  play 52 #1
  sleep(1)
  play 59 #5
  sleep(1)
  play 65 #9
  sleep(1)
  play 62 #2
  sleep(1)
  play 60 #6
  sleep(1)
  play 59 #5
  sleep(1)
  play 55 #3
  sleep(1)
  play 59 #5
  sleep(1)
  play 65 #9
  sleep(1)
 end 

2. Using Middle C


The tune is fairly basic and maybe not that melodic. I then realised two things.  1) Programming languages start from O not 1, therefore my whole range of notes was out by one.  Also our musical notes start from middle C  which is 60 on the MIDI values.  Therefore the notes should be coded as follows: C=60, D=62, E=64, F=65, and so on.  Again I looked up the MIDI values and converted them.  This created a more tuneful musical phrase -
Second Code:
# Welcome to Sonic Pi v2.0
#3.14159265359 adding the zero value
#Pi digit = note position, maybe length?
#MIDI E52 F53 G55 A57 B59 C60 D62 E64 F65
#Position 0=60, 1=62, 2=64, 3=65, 4=67, 5=69, 6=71, 7=72, 8=74, 9=76
use_synth :mod_saw
2.times do
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end

3. Symphonic Pi


This sounds better?  I then thought about what the tune would sound like if it was combined. Playing all 10 tunes together would just create a unison din, but what about if the start of each melody was delayed?   But how much should the start of each play through be delayed for.  The obvious delay seemed to come from the value of Pi itself.  A delay of 3 seconds, then play the tune, then a delay of 1 second then starts the tune again, a delay of 4 then play the tune and so on until all 10 decimal place values had been used as a delay time.

I created nine versions of the previous tune each one with the relevant delay, 1 second, 2 seconds up to the final tune with a delay of 9 seconds.  Then using the Sonic Pi threading code, all nine definitions where loaded up and played simultaneously.

Unfortunately no secret portal opened up but here is the final composition of what Pi sounds like to 10 decimal places. 
Final Code:
#Welcome to Sonic Pi v2.0
####OVER LAY - from 0 to 9 values
#3.14159265359
#Pi digit = note position, maybe length? 
#MIDI E52 F53 G55 A57 B59 C60 D62 E64 F65
##Position 0=60, 1=62, 2=64, 3=65, 4=67, 5=69, 6=71, 7=72, 8=74, 9=76

###ORGINAL###
#Define the function
use_bpm 60
set_sched_ahead_time! 5
use_synth :pretty_bell ###1
define :tune do
  #sleep(1)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end 

define :tune2 do ###2
  use_synth :pretty_bell
  sleep(2)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end 
 
define :tune3 do ###3
  sleep(3)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end

define :tune4 do ###4
  sleep(4)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end

define :tune5 do ###4
  sleep(5)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end 
 
 define :tune6 do ###6
  sleep(6)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end 
 
 define :tune7 do ###7
  sleep(7)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end  
 
 define :tune8 do ###8
  sleep(8)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end  
 
define :tune9 do ###9
  sleep(9)
  play 65 #3
  sleep(1)
  play 62 #1
  sleep(1)
  play 67 #4
  sleep(1)
  play 62 #1
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
  play 64 #2
  sleep(1)
  play 71 #6
  sleep(1)
  play 69 #5
  sleep(1)
  play 65 #3
  sleep(1)
  play 69 #5
  sleep(1)
  play 76 #9
  sleep(1)
 end 
 
#3.141592653 59
tune
#3
in_thread do
  tune3
end 
#1
in_thread do
sleep(1)
  tune
end 
#4
in_thread do
  tune4
end 
#1
in_thread do
sleep(1)
  tune
end 
#5
in_thread do
  tune5
end 
#9
in_thread do
  tune9
end 
#2
in_thread do
  tune2
end 
#6
in_thread do
  tune6
end 
#5
in_thread do
  tune5
end 
#3
in_thread do
  tune3
end 
#5
in_thread do
  tune5
end 
#9
in_thread do
  tune9
end
Picture
Copyright 2020 TeCoEd @dan_aldred