Music Package

The functions defined in allow you to make conversions between cents and hertz, and play scales in one of the common tuning systems, or in a userspecified tuning system. In addition, a set of equaltempered pitch/frequency equivalents is defined.

When you try the examples in this documentation, your computer display may not look exactly the same, since the graphic displays accompanying the Wolfram Language's sound generation vary from platform to platform.

MusicScale[ilist,freq,dur]create a Sound object that is a sequence of pitches corresponding to ilist, a list of intervals measured in cents, starting at freq hertz and lasting dur seconds

Creating a scale.

MusicScale creates a pitch sequence from a predefined interval list or an arbitrary list of numbers interpreted as intervals measured in cents.

This loads the package.
In[1]:=
Click for copyable input
JustMajor is an interval list. This plays a major scale in just intonation that starts at 440 Hz and lasts for 3 seconds.
In[2]:=
Click for copyable input
Out[2]=
The list of intervals does not have to be in ascending or descending order. Here the starting frequency is 880 Hz.
In[3]:=
Click for copyable input
Out[3]=

Predefined interval lists measured in cents.

HertzToCents[flist]convert a list of frequencies measured in Hertz to a list of intervals measured in cents
CentsToHertz[ilist]convert a list of intervals measured in cents to a list of frequencies measured in Hertz, beginning at frequency 440 Hertz
CentsToHertz[ilist,f]convert a list of intervals measured in cents to a list of frequencies measured in Hertz, beginning at frequency f

Converting between Hertz and cents.

The two functions HertzToCents and CentsToHertz convert a list of one type to its complementary type.

This takes a list of frequencies in Hertz and gives the distance from one frequency to the next in cents.
In[4]:=
Click for copyable input
Out[4]=
Here is a list consisting of the frequencies in a oneoctave, equaltempered chromatic scale starting at 440 Hertz.
In[5]:=
Click for copyable input
Out[5]=
This confirms that the distance between adjacent pairs of frequencies in is 100 cents.
In[6]:=
Click for copyable input
Out[6]=
This gives the frequency that is 600 cents above the default frequency, 440 Hertz, or in musical terminology, onehalf octave above the pitch A4.
In[7]:=
Click for copyable input
Out[7]=
Here is a list of all the frequencies of equaltempered halfsteps between 880 and 1760 Hertz.
In[8]:=
Click for copyable input
Out[8]=
Here are the frequencies of a 36tone octave, starting at 660 Hertz.
In[9]:=
Click for copyable input
Out[9]=

The package provides a list of equaltempered pitch/frequency equivalents. Pitches are named in pitch class/octave notation, where the pitch class is given by a letter from A to G, and the octave is an integer from 0 and 7. The names of flat and sharp notes are written as , , and so on.

Most chromatic equivalences are available; for example, Cflat is the same as B, and Esharp is the same as F. Doubleflats and doublesharps are not defined.

The difference between Aflat4 and Eflat5 is 700 cents in equal temperament.
In[10]:=
Click for copyable input
Out[10]=
This plays a perfect fifth.
In[11]:=
Click for copyable input
Out[11]=