Audio Processing

The Wolfram Language provides support for the manipulation of audio data. Sounds can be synthesized, manipulated, and analyzed.

Audio Playback

ListPlay[{a1,a2,}]play a sound with a sequence of amplitude levels
Play[f,{t,tmin,tmax}]play a sound with amplitude f as a function of time t in seconds
Sound[prims]play a set of sound primitives prims
EmitSound[snd]emit the sound snd when evaluated

Playing functions, lists, and primitives.

Sound can be created in several ways. One way is to simply write a series of amplitude values using ListPlay.

Play noise generated from random values.
In[75]:=
Click for copyable input
Out[75]=

Sounds can also be created using a function over time.

Generate a sine wave at 440 Hz.
In[76]:=
Click for copyable input
Out[76]=

ListPlay and Play are sound primitives that can be passed to Sound.

Play noise and then a sine tone successively.
In[77]:=
Click for copyable input
Out[77]=
Play noise and the sine tone overlapped.
In[78]:=
Click for copyable input
Out[78]=

EmitSound can be used to play the sound without a playback object.

In[5]:=
Click for copyable input

Sound Primitives

SampledSoundList[{a1,a2,},r]underlying representation of ListPlay
SampledSoundFunction[f,n,r]underlying representation of Play

Lower-level representations of sound.

Create a SampledSoundList from a numeric list, with a sample rate of 8000.
In[79]:=
Click for copyable input
Out[79]=
Extract the SampledSoundList from a ListPlay object.
In[80]:=
Click for copyable input
Out[80]//Short=
Extract the SampledSoundFunction from a Play object.
In[81]:=
Click for copyable input
Out[81]=
These can also be used as primitives.
In[82]:=
Click for copyable input
Out[82]=

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[83]:=
Click for copyable input
Out[83]=

Use Export to write a sound to disk.

This example takes the first second of the sound above and writes it to disk.
In[57]:=
Click for copyable input
Out[57]=

Synthesis

Additive Synthesis

Synthesizing audio data is relatively simple in the Wolfram Language. In the example below, a Manipulate is created that controls the amplitudes of the first five harmonics of a 440 Hz fundamental. Basically, any Wolfram Language function can be used to create audio data.

A simple additive synthesizer.
In[85]:=
Click for copyable input
Out[85]=Play Animation

Amplitude Modulation

An example of amplitude modulation (AM), where carrier amplitude is controlled by another oscillator.
In[103]:=
Click for copyable input
Out[103]=Play Animation

Frequency Modulation

An example of frequency modulation (FM), where carrier frequency is controlled by another oscillator.
In[106]:=
Click for copyable input
Out[106]=Play Animation

Granular Synthesis

Granular synthesis is a basic technique that takes small samples from a sound file, called grains, and layers and rearranges them in different ways.

An example of granular synthesis, where multiple grain streams are created from the original sample.
In[22]:=
Click for copyable input
Out[27]=

Audio Manipulation

Delay Effects

Create an echo effect.
In[25]:=
Click for copyable input
Out[31]=
Create a chorus effect.
In[93]:=
Click for copyable input
Out[93]=

Filtering

SampledSoundList, which contains audio data, can be used as input to many functions in the Wolfram Language signal processing suite.

LowpassFilter[data,ωc]apply a lowpass filter with a cutoff frequency to an array of data
HighpassFilter[data,ωc]apply a highpass filter with a cutoff frequency to an array of data
BandstopFilter[data,{ω1,ω2}]apply a bandstop filter with cutoff frequencies and to an array of data
BandpassFilter[data,{ω1,ω2}]apply a bandpass filter with cutoff frequencies and to an array of data

Some filters can be directly applied to audio signals.

Lowpass filtering of a noisy sound, using a cutoff frequency of 3000 Hz.
In[6]:=
Click for copyable input
Out[9]=
Highpass filtering of a noisy sound.
In[14]:=
Click for copyable input
Out[17]=
Bandstop and bandpass filtering of a sound.
In[16]:=
Click for copyable input
Out[16]=
Out[17]=
Out[18]=

Equalization

Create an equalizer, using a set of bandpass filters.
In[29]:=
Click for copyable input
Out[29]=

Fourier Analysis

Spectrograms and Periodograms

Spectrogram[list]plot the spectrogram of list
SpectrogramArray[list]return the spectrogram data of list
Periodogram[list]plot the squared magnitude of the discrete Fourier transform (power spectrum) of list
PeriodogramArray[list]return the squared magnitude of the discrete Fourier transform (power spectrum) of list

Spectral visualization and analysis.

A spectrogram of a sound and the corresponding data.
In[19]:=
Click for copyable input
Out[20]=
A periodogram of a sound and the corresponding data.
In[86]:=
Click for copyable input
Out[87]=

Spectral Noise Gate

A spectral noise gate.
In[7]:=
Click for copyable input
In[17]:=
Click for copyable input
Out[17]=
Out[24]=
Translate this page: