# The Representation of Sound

"Sound" describes how you can take functions and lists of data and produce sounds from them. This tutorial discusses how sounds are represented in the Wolfram System.

The Wolfram System treats sounds much like graphics. In fact, the Wolfram System allows you to combine graphics with sound to create pictures with "sound tracks".

In analogy with graphics, sounds in the Wolfram System are represented by symbolic sound objects. The sound objects have head Sound, and contain a list of sound primitives, which represent sounds to be played in sequence.

 Sound[{s1,s2,…}] a sound object containing a list of sound primitives

The structure of a sound object.

The functions Play and ListPlay discussed in "Sound" return Sound objects.

Play returns a Sound object. On appropriate computer systems, it also produces sound.
 In[1]:=
 Out[1]=

## Sound Primitives

 SampledSoundList[{a1,a2,…},r] a sound with a sequence of amplitude levels, sampled at rate r SampledSoundFunction[f,n,r] a sound whose amplitude levels sampled at rate r are found by applying the function f to n successive integers SoundNote[n,t,"style"] a note-like sound with note n, time specification t, with the specified style

Wolfram System sound primitives.

At the lowest level, all sounds in the Wolfram System are represented as a sequence of amplitude samples, or as a sequence of MIDI events. In SampledSoundList, these amplitude samples are given explicitly in a list. In SampledSoundFunction, however, they are generated when the sound is output, by applying the specified function to a sequence of integer arguments. In both cases, all amplitude values obtained must be between and . In SoundNote, a note-like sound is represented as a sequence of MIDI events that represent the frequency, duration, amplitude, and styling of the note.

Create a SampledSoundList from a numeric list, with a sample rate of 8000.
 In[6]:=
 Out[6]=
 In[7]:=
 Out[7]=
Create a SampledSoundFunction from a function, with a sample rate of 8000.
 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=
Create a SoundNote.
 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

ListPlay generates SampledSoundList primitives, while Play generates SampledSoundFunction primitives. With the default option setting , Play will produce a SampledSoundFunction object containing a CompiledFunction.

Once you have generated a Sound object containing various sound primitives, you must then output it as a sound. Much as with graphics, the basic scheme is to take the Wolfram System representation of the sound and convert it to a lowerlevel form that can be handled by an external program, such as a Wolfram System front end.

Play multiple primitives successively.
 In[17]:=
 Out[17]=
Play multiple primitives overlapped.
 In[18]:=
 Out[18]=

The lowlevel representation of sampled sound used by the Wolfram System consists of a sequence of hexadecimal numbers specifying amplitude levels. Within the Wolfram System, amplitude levels are given as approximate real numbers between and . In producing the lowlevel form, the amplitude levels are "quantized". You can use the option SampleDepth to specify how many bits should be used for each sample. The default is SampleDepth->8, which yields 256 possible amplitude levels, sufficient for most purposes. The low-level representation of note-based sound is as a time-quantized byte stream of MIDI events that specify various parameters about the note objects. The quantization of time is determined automatically at playback.

You can use the option SampleDepth in Play and ListPlay. In sound primitives, you can specify the sample depth by replacing the sample rate argument by the list {rate,depth}.

## Import/Export

 Import["file"] import a sound Export["file.ext",expr] export a sound

Importing and exporting functions.

It is possible to import audio data from a file on the local file system or from any accessible remote location.

This imports a sound from the Wolfram Language documentation directory.
 In[45]:=
 Out[45]=

Use Export to write a sound to disk.

Write the imported Sound to disk.
 In[48]:=
 Out[48]=