Download 1.9.13 Special Topic: Sound

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Dynamic range compression wikipedia , lookup

Chirp spectrum wikipedia , lookup

Loudspeaker wikipedia , lookup

Studio monitor wikipedia , lookup

Fade (audio engineering) wikipedia , lookup

Sound recording and reproduction wikipedia , lookup

Electronic musical instrument wikipedia , lookup

Sound reinforcement system wikipedia , lookup

Sound level meter wikipedia , lookup

Public address system wikipedia , lookup

Transcript
1. A Practical Introduction to Mathematica
204
1.9.13 Special Topic: Sound
On some computer systems, Mathematica can produce not only graphics but also sound. Mathematica
treats graphics and sound in a closely analogous way.
For example, just as you can use Plot f, {x, xmin, xmax}] to plot a function, so also you can use
Play f, {t, 0, tmax}] to “play” a function. Play takes the function to define the waveform for a
sound: the values of the function give the amplitude of the sound as a function of time.
Play f, {t, 0, tmax}]
play a sound with amplitude f as a function of time t in
seconds
Playing a function.
On a suitable computer system, this
plays a pure tone with a frequency of
440 hertz for one second.
In 1]:= Play Sin 2Pi 440 t], {t, 0, 1}]
Out 1]= -Sound-
Sounds produced by Play can have any waveform. They do not, for example, have to consist of
a collection of harmonic pieces. In general, the amplitude function you give to Play specifies the instantaneous signal associated with the sound. This signal is typically converted to a voltage, and ultimately to a displacement. Note that amplitude is sometimes defined to be the peak signal associated
with a sound; in Mathematica, it is always the instantaneous signal as a function of time.
This plays a more complex sound.
In 2]:= Play Sin 700 t + 25 t Sin 350 t]], {t, 0, 4} ]
Out 2]= -Sound-
Play is set up so that the time variable that appears in it is always measured in absolute seconds.
When a sound is actually played, its amplitude is sampled a certain number of times every second.
You can specify the sample rate by setting the option SampleRate.
Play f, {t, 0, tmax}, SampleRate -> r]
play a sound, sampling it r times a second
Specifying the sample rate for a sound.
In general, the higher the sample rate, the better high-frequency components in the sound will be
rendered. A sample rate of r typically allows frequencies up to r=2 hertz. The human auditory system
can typically perceive sounds in the frequency range 20 to 22000 hertz (depending somewhat on age
and sex). The fundamental frequencies for the 88 notes on a piano range from 27.5 to 4096 hertz.
The standard sample rate used for compact disk players is 44100. The effective sample rate in a
typical telephone system is around 8000. On most computer systems, the default sample rate used by
Mathematica is around 8000.
Web sample page from The Mathematica Book, Second Edition, by Stephen Wolfram, published by Addison-Wesley Publishing Company (hardcover ISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact Wolfram Research: [email protected];
http://www.wolfram.com/; 1-800-441-6284.
 1991 Wolfram Research, Inc.
Permission is hereby granted for web users to make one paper copy of this page for their personal use. Further reproduction, or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited.
1.9 Graphics and Sound
205
You can use Play {f1 , f2 }, ... ] to produce stereo sound. In general, Mathematica supports any
number of sound channels.
ListPlay {a1 , a2 , ... }, SampleRate -> r]
play a sound with a sequence of amplitude levels
Playing sampled sounds.
The function ListPlay allows you simply to give a list of values which are taken to be sound amplitudes sampled at a certain rate.
When sounds are actually rendered by Mathematica, only a certain range of amplitudes is allowed.
The option PlayRange in Play and ListPlay specifies how the amplitudes you give should be scaled
to fit in the allowed range. The settings for this option are analogous to those for the PlotRange graphics option discussed on page 166.
PlayRange -> Automatic (default)
use an internal procedure to scale amplitudes
PlayRange -> All
PlayRange -> {amin, amax}
scale so that all amplitudes fit in the allowed range
make amplitudes between amin and amax fit in the allowed
range, and clip others
Specifying the scaling of sound amplitudes.
While it is often convenient to use the default setting PlayRange -> Automatic, you should realize that Play may run significantly faster if you give an explicit PlayRange specification, so it does not
have to derive one.
Show sound]
replay a sound object
Replaying a sound object.
Both Play and ListPlay return Sound objects which contain procedures for synthesizing sounds.
You can replay a particular Sound object using the function Show that is also used for redisplaying
graphics.
The internal structure of Sound objects is discussed in Section 2.9.18.
Web sample page from The Mathematica Book, Second Edition, by Stephen Wolfram, published by Addison-Wesley Publishing Company (hardcover ISBN 0-201-51502-4; softcover ISBN 0-201-51507-5). To order Mathematica or this book contact Wolfram Research: [email protected];
http://www.wolfram.com/; 1-800-441-6284.
 1991 Wolfram Research, Inc.
Permission is hereby granted for web users to make one paper copy of this page for their personal use. Further reproduction, or any copying of machine-readable files (including this one) to any server computer, is strictly prohibited.