Try now in the
Open Cloud »
(no sign-in required)

The Sound of Pi

Play melodies based on the digits of Pi.

Run the code to play a musical note. Try other note numbers:

SHOW/HIDE DETAILS

SoundNote denotes a musical note. Pitch 0 is middle C:

In[1]:=
X

SoundNote by itself doesnt make a sound. Put it inside Sound to make a playable note (click the Play button to play the note):

In[2]:=
X
Out[2]=

Play the note immediately with EmitSound:

In[3]:=
X

HIDE DETAILS
In[1]:=
X

Play a melody. Try other sequences of notes:

SHOW/HIDE DETAILS

Play a sequence of notes by putting them in a list (indicated by the curly braces):

In[1]:=
X

If you dont specify otherwise, each note is played for 1 second. To make the melody play faster, specify the duration of the entire sequence in seconds:

In[2]:=
X

A more compact way of writing a sequence of notes uses /@ (Map):

In[3]:=
X
Out[3]=

Play a sequence of notes using Map:

In[4]:=
X

This is how the note numbers correspond to piano keys:

Out[4]=

HIDE DETAILS
In[1]:=
X

Get the first 12 digits of Pi. Try longer or shorter sequences:

SHOW/HIDE DETAILS

This gives a list of the first 12 digits of π (in base 10), plus the number of digits to the left of the decimal point:

In[1]:=
X
Out[1]=

Use First to get just the digits:

In[2]:=
X
Out[2]=

HIDE DETAILS
In[1]:=
X
Out[1]=

Play the first 12 digits of Pi. Try longer or shorter sequences:

SHOW/HIDE DETAILS

This plays a sequence of 3 notes:

In[1]:=
X

Replace the note sequence with the digits of Pi to play them as notes:

In[2]:=
X

HIDE DETAILS
In[1]:=
X

Play the digits of Pi on a marimba. Try other instruments, such as Clarinet, Trumpet, or ElectricPiano:

SHOW/HIDE DETAILS

Use Style to specify what instrument to play the notes on:

In[1]:=
X

Heres a list of the available instruments:

Out[1]=

HIDE DETAILS
In[1]:=
X