Play

Play[f,{t,tmin,tmax}]

creates an object that plays as a sound whose amplitude is given by f as a function of time t in seconds between tmin and tmax.

Details and Options

  • Play returns a Sound object, which displays in StandardForm as a button that can be clicked to play the sound.
  • Play treats the variable t as local, effectively using Block.
  • Play has attribute HoldAll, and evaluates f only after assigning specific numerical values to t.
  • In some cases it may be more efficient to use Evaluate to evaluate f symbolically before specific numerical values are assigned to t.
  • The following options can be given:
  • DisplayFunctionAutomaticfunction for generating output to display
    PlayRange Allthe range of amplitude levels to include
    SampleDepth8how many bits to use to represent each amplitude level
    SampleRate 8000how many times per second amplitude samples should be generated
  • Play[{f1,f2},{t,tmin,tmax}] produces stereo sound. The lefthand channel is given first.
  • Play[{f1,f2,},] generates sound output on any number of channels.

Examples

open allclose all

Basic Examples  (1)

Play a "middle A" sine wave for 1 second:

Scope  (5)

Play two sounds in sequence:

Play any function:

Frequency modulation:

Play a sawtooth function:

Play a square wave:

Generalizations & Extensions  (2)

Play on two different stereo channels:

Play on four channels:

Options  (2)

PlayRange  (1)

Automatically select the range of function values to use for amplitudes:

Take function values 0 through 50 to span the full range of amplitudes:

SampleRate  (1)

Lower sample rates lead to lower-quality sounds, but less data:

Applications  (6)

Generate beat notes:

Play the Riemann zeta function:

Play a sum of non-commensurate sine waves:

A simple function that gives a "sound effect":

Sum of pure tones with changing frequencies:

Make a vibrato-like effect:

Properties & Relations  (2)

Play a waveform and a note-based sound in sequence:

Play the waveform and note at the same approximate time:

Possible Issues  (2)

Frequency components higher than the sampling rate will be missed:

Bizarre aliasing can occur close to the sample rate:

Wolfram Research (1991), Play, Wolfram Language function, https://reference.wolfram.com/language/ref/Play.html (updated 2007).

Text

Wolfram Research (1991), Play, Wolfram Language function, https://reference.wolfram.com/language/ref/Play.html (updated 2007).

CMS

Wolfram Language. 1991. "Play." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2007. https://reference.wolfram.com/language/ref/Play.html.

APA

Wolfram Language. (1991). Play. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Play.html

BibTeX

@misc{reference.wolfram_2023_play, author="Wolfram Research", title="{Play}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/Play.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_play, organization={Wolfram Research}, title={Play}, year={2007}, url={https://reference.wolfram.com/language/ref/Play.html}, note=[Accessed: 19-March-2024 ]}