Audio Processing
Mathematica 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.
| Out[19]= |  |
Sounds can also be created using a function over time.
Generate a sine wave at 440 Hz.
| Out[20]= |  |
ListPlay and Play are sound primitives that can be passed to Sound.
Play noise and then a sine tone successively.
| Out[21]= |  |
Play noise and the sine tone overlapped.
| Out[23]= |  |
EmitSound can be used to play the sound without a playback object.
Sound Primitives
Lower-level representations of sound.
| Out[24]= |  |
Out[29]//Short= |
| |  |
| Out[27]= |  |
These can also be used as primitives.
| Out[30]= |  |
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
Mathematica documentation directory.
| Out[56]= |  |
Use Export to write a sound to disk.
This example takes the first second of the sound above and writes it to disk.
| Out[57]= |  |
Synthesis
Additive Synthesis
Synthesizing audio data is relatively simple in Mathematica. In the example below, a Manipulate is created that controls the amplitudes of the first five harmonics of a 440 Hz fundamental. Basically, any Mathematica function can be used to create audio data.
A simple additive synthesizer.
Amplitude Modulation
An example of amplitude modulation (AM), where carrier amplitude is controlled by another oscillator.
Frequency Modulation
An example of frequency modulation (FM), where carrier frequency is controlled by another oscillator.
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.
| Out[27]= |  |
Audio Manipulation
Delay Effects
| Out[31]= |  |
| Out[93]= |  |
Filtering
SampledSoundList, which contains audio data, can be used as input to many functions in the Mathematica 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.
| Out[9]= |  |
Highpass filtering of a noisy sound.
| Out[17]= |  |
Bandstop and bandpass filtering of a sound.
| Out[16]= |  |
| Out[17]= |  |
| Out[18]= |  |
Equalization
Create an equalizer, using a set of bandpass filters.
| 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.
| Out[20]= |  |
A periodogram of a sound and the corresponding data.
| Out[22]= |  |
Spectral Noise Gate
| Out[17]= |  |
| Out[24]= |  |