MathSource Reviews: Mathematica in Your Ear
Author
Matthew M. Thomas
Title
MathSource Reviews: Mathematica in Your Ear
Description
-
Category
Academic Articles & Supplements
Keywords
URL
http://www.notebookarchive.org/2018-10-10nbbc8/
DOI
https://notebookarchive.org/2018-10-10nbbc8
Date Added
2018-10-02
Date Last Modified
2018-10-02
File Size
2.23 megabytes
Supplements
Rights
Redistribution rights reserved
This notebook has not been updated since 2019. 
MathSource Reviews
MathSource Reviews
Mathematica In Your Ear
Edited by Matthew M. Thomas
It is with more dread than usual that your reviewer tackles the topic of this quarter's Review. MathSource items tend to be crafted and contributed by workers who specialize in what they craft and contribute. Upon encountering these contributions, what can the non-specialist do but nod to the speciality, describe the contribution, and assess its strengths and shortcomings within a Mathematica context? But at least, in most cases, both the contribution and its assessment can be captured within the confines of these pages, two-dimensional though they may be. Shades of gray add another dimension, and -- once an issue, on the cover -- color is used to expand the boundaries of that added dimension. This added dimension proves indispensable when 3-D objects must be projected onto these pages. And what of those situations in which these objects change with time, or with yet some other dimension? Animation has been a Mathematica staple from the outset, but on the printed page, this sort of change is satisfactorily illustrated with multiple snapshots of the changing object. There is, alas, one case in which the printed page fails miserably to capture the essence of the contribution. That case -- our present case -- involves sound.
Unlike animation, sound generation was not a Mathematica capability from the outset; it became one only upon the introduction of the Play[] function with version 2.0. If (and only if) the host computer is equipped with the proper hardware for sound generation, Play[] will play; if not, not. But given the proper platform, Play[] can produce the aural analogue of mathematical functions even in stereo: One function to your left ear; another to your right. Conveying the essence of sound via the printed page poses the far greater challenge. A good-enough writer steeped in musical training can wax sufficiently rhapsodic to get the idea across. Consider Berlioz on the flute: "If it were required to give a sad air an accent of desolation and of humility and resignation at the same time, the feeble sounds of the flute's medium register would certainly produce the desired effect" [Miller 1916, p. 191]. Berlioz again: "Violins particularly are capable of a host of apparently inconsistent shades of expression. They possess as a whole force, lightness, grace, accents both gloomy and gay, thought, and passion" [Miller 1916, p. 196]. Now try waving the printed copy of this journal briskly through the air, so as to evoke desolation, humility, resignation, force, lightness, grace, gloom, gaiety, thought, passion, and others outside the realm of Berlioz' flute and violin. You will accomplish your impossible task more easily than the printed page will convey the essence of sound.
Would reverting to basics be helpful? Hardly. One cannot find a more basic musical phenomenon than the sine wave of frequency 440 Hz. This frequency has long offered the "standard pitch" for note A above middle C, to which the frequencies of all other notes are tuned [see Backus 1977, pp. 150-152, and Wood 1975, pp. 47-49 for that story]. Unleash Mathematica on this most basic phenomenon and behold:
In[]:=
Play[Sin[2 Pi 440 t],{t,0,1}]
Out[]=
⁃Sound⁃
Play this output and you hear one second of a 440 Hz sine wave. Look at this output and you are hard-pressed to identify it as 440 cycles of a sine wave in a one-second span: The output on the printed page bears a stronger resemblance to a stratified hodgepodge of pixels. Perhaps shortening the duration would lend clarity:
In[]:=
Play[Sin[2 Pi 440 t],{t,0,1/440}]
Out[]=
⁃Sound⁃
Look at this output and you see exactly one sine wave, with a period of one four-hundred fortieth of a second. Play this output and you are hard-pressed to identify it as one sine wave in a 1/440-second period: The duration is too short to do anything more than click your speakers. Perhaps an optimal duration can be found, to yield an output simple enough to be shown yet lengthy enough to be played. But ... such effort for this simplest of musical phenomena? And rendering the entire discussion moot is the inability of this printed page to convey either the full-second sine wave or the speaker click. Readers would have been better served tapping the 49th piano key or vibrating the last viola string to hear standard pitch. Reversion to basics is not helpful; conveying the essence of sound via the printed page remains daunting.
This MathSource Review examines the nine notebooks contributed by composer (and former Wolfram Researcher) Arun Chandra. Given the preceding: If ever there was a Review to be read while running Mathematica on a sound-generating computer, this one is it.
BACKGROUND
BACKGROUND
Dr. Arun Chandra contributed MathSource item /Applications/Audio/0202-217, "A Composer's Guide to Sound Production with Mathematica." This item comprises nine Mathematica notebooks; we will examine these notebooks in due course. First, however, a look at Dr. Chandra. According to an on-line biography dated 12 May 1998, he studied guitar in France and Italy, and conducting at the Mozarteum in Salzburg. He has a D.M.A. in Music Composition from the University of Illinois at Urbana-Champaign (UIUC). In the 1980s, he toured Europe and the U.S. as part of the Performers' Workshop Ensemble, and he was in residence for six months at the Hochschule für Musik in Germany. He has served as Associate Professor of Music Composition at the Institute of Applied Arts at National Chiao Tung University in Taiwan, where he directed the computer music studio, conducted the orchestra, and taught composition and theory. His compositions, such as "The Gift of Gab" (1997), have been performed at international festivals, such as the 1997 ThreeTwo Festival of New Music at the Greenwich House Music School in New York City. He also worked three years for Wolfram Research, developing the Music and Audio packages for Mathematica 2.x. His training warrants taking his music-based MathSource contributions seriously.
Visit the World-Wide Web and go to URL www.hlalapansi.demon.co.uk/Acoustics/MusicMaths/MusicMaths.html. There you will find "The Mathematics of Tuning and Temperament, with Audio Examples" by one David Bartlett on a site named "The Pyxidium." This site offers fifteen audio samples encoded at 16 kbps, in the controversial MPEG Layer 3 (MP3) format. These samples, when played, aurally illustrate a number of concepts involving mathematics and music; these concepts complement the Chandra notebooks to be examined. Also complementary, in that it too works with Play[], is a web site from none other than the editor of this journal; its URL is www.unl.edu/tcweb/Faculty/fowler/fourier/1141MSet.html. This site offers not only output from Play[], but also a QuickTime audio/video file, a cursory but intriguing comparison of brain waves to sound waves, and a nod to the role J. B. J. Fourier's work plays in sound waves (via Ohm's Law of Acoustics). These sites add perspective to the notebooks to be discussed; the serious student will want to review them.
A review of Harry F. Olson's Music, Physics and Engineering, 2nd ed. [Olson 1967] is also worthy of review. The longest chapter of this text provides not only a thorough description of all major string, wind, percussion, and electrical instruments, but also the corresponding mechanical networks, acoustical networks, and electrical analogies where appropriate. After first revieweing the physics of sound waves, the text then examines musical terminology and musical scales. The text then offers a nod to the role J. B. J. Fourier's work plays in sound waves, while managing to refer to neither Fourier nor Ohm. Atonement for these omissions comes through a offering of frequency spectra for many major instruments. (We see from these spectra that striking piano key forty-nine or vibrating the last viola string produces more frequencies than the fundamental 440 Hz. Nonetheless: Doing either remains preferable to examining Play[Sin[2 Pi 440 t],{t,0,1}] output on the printed page.) Olson's book also extensively probes sound reproduction systems -- hardly surprising in light of the author's vice-presidency with RCA Laboratories. Be it known that the serious student must augment any Chandra notebook dalliances with thorough study of the Olson text.
THE CHANDRA NOTEBOOKS
THE CHANDRA NOTEBOOKS
MathSource item /Applications/Audio/0202-217 comprises nine notebooks by Arun Chandra. These nine: 0.intro.nb (22 kB); 1.commands.nb (2.4 MB); 2.waveforms.nb (1.0 MB); 3.envelopes.nb (1.3 MB); 4.interfer.nb (2.1 MB); 5.am.nb (3.6 MB); 6.fm.nb (1.8 MB); 7.tuning.nb (2.2 MB); 8.references.nb (7 kB). The first and the last are bread, sandwiching the meat that is notebooks 1.commands.nb through 7.tuning.nb. The 0.intro.nb notebook simply outlines the content of the other notebooks. The 8.references.nb notebook cites eleven references, of which one is the book by Harry F. Olson.
The 1.commands.nb notebook begins by reviewing Play[] and ListPlay[] capabilities within Mathematica, and by presenting a CombinedSoundShow[] function (courtesy of Theo Gray) that plays a sequence of sounds in succession. The stereo output capability related to Play[] (assuming the proper sound generation hardware) is noted, and options such as SampleRate, SampleDepth, and PlayRange are explained. Apparent loudness and clipping/distortion are given their due, and the notebook dates itself with an outline of sound generation capabilities within NeXT and Apple (pre-iMac) computers.
The 2.waveforms.nb notebook first plays pure sawtooth, square, and triangle waves; it then does the same with the Fourier-synthesized versions of these waveforms. From the first part of this notebook, consider the pure sawtooth wave:
In[]:=
Fract[x_ ] := x - Floor[x]
In[]:=
SawPlay[Freq_,Dur_] := Play[Fract[-t * Freq],{t,0,Dur}, SampleRate->44100]
In[]:=
SawPlay[440,2]
Out[]=
⁃Sound⁃
The above is the two-second version at 440 Hz; your reviewer considers the sound somewhat strident. Let us move to the pure square wave:
In[]:=
SquarePlay[Freq_,Dur_] := Play[1/2(Sign[Fract[t * Freq]-1/2]+1),{t,0,Dur}, SampleRate->44100]
In[]:=
SquarePlay[440,2]
Out[]=
⁃Sound⁃
Same duration, same frequency; your reviewer considers this sound shrill and more strident and louder than its predecessor. Note: The Chandra notebook claims to have generated this sound through not SquarePlay[440,2] but SquarePlay[1,440,0.5]. While Chandra legitimately uses a 0.5-second duration in lieu of our two-second choice, how he fed three arguments successfully into a two-argument function is not quite clear. We end with the pure triangle wave:
In[]:=
TrianglePlay[Freq_, Dur_] := Play[2 * Abs[Fract[t * Freq] - 1/2],{t,0,Dur}, SampleRate->44100]
In[]:=
TrianglePlay[440,2]
Out[]=
⁃Sound⁃
Once again, we get a two-second version at 440 Hz; your reviewer deems this sound fuller and more resonant than Play[Sin[2 Pi 440 t],{t,0,2}], yet not as harsh as its two predecessors. This notebook has value as a framework for experimentation by music novices, who can compare pure waveforms to their Fourier-synthesized waveforms, and who can tweak harmonic count in the latter and gauge the resulting effects on the sound.
The 3.envelopes.nb notebook explores decay and growth envelopes of basic sound waves. In musical instruments, growth and decay characteristics tend to involve exponential functions. For the simple case, tone growth can be represented by p = p0 (1 - Exp[-kt]) and tone decay by p = p0 Exp[-kt], where p is sound pressure, p0 is that at steady state, k is an instrument constant, and t is time. Naturally, growth and decay time vary with instrument: The pipe organ has relatively long growth and decay time; the piano, short growth and long decay times; the guitar, very short growth and very long decay times [Olson 1967, pp. 247, 258]. Chandra considers both simple and complex time decay, and this example of the latter yields perhaps the most complex sound of any in the nine notebooks:
In[]:=
ComplexDecay[Amplitude_,Frequency_,Harmonics_, Decay_,Duration_] := Play[Evaluate[ Sum[Amplitude/i E^(-Decay t) * Sin[i * 2 Pi Frequency t], {i,1,Harmonics}]], {t,0,Duration}, PlayRange->All, SampleRate->44100]
In[]:=
ComplexDecay[1,440,22,3,2]
Out[]=
⁃Sound⁃
Your reviewer thinks that the resulting sound resembles a plucked string, with some measure of reverberation manifesting itself in the waning moments of the decay. The plot does not capture this reverberation, but it does at least illustrate the decay. Chandra's tone growth example is simpler:
In[]:=
Play[ (1 * (1 - E^(-3 t))) * Sin[ 2 Pi 440 t], {t,0,1}]
Out[]=
⁃Sound⁃
You can see the resulting growth envelope for yourself; your reviewer perceives the sound as a simple amplitude increase from silence to standard pitch, with no reverberation or other phenomena of interest. A connection to at least one actual musical instrument would have increased the value of this notebook; still, its examples are the most aesthetically pleasing of the lot.
The 4.interfer.nb notebook discusses interference due to phase relationships and beats. We shall not let its straightforward contents interfere with the course of this review. The 5.am.nb notebook examines both amplitude modulation and ring modulation. Let us look at -- and modify -- Chandra's example of simple amplitude modulation known as tremolo: The unmodulated "carrier" signal amplitude is unity; maximum (100%) modulation varies the carrier signal amplitude between 0 and 2; the carrier frequency is 470 Hz (which generates a more interesting plot than 440 Hz); the modulator frequency is 6 Hz; the duration is 2 seconds. Our result:
In[]:=
AM[Amp_, Mi_, Carrier_, Modulator_, Duration_] := Play[Evaluate[ Amp * (1 + Mi * Cos[2 Pi Modulator t]) * Cos[2 Pi Carrier t]], {t,0,Duration},PlayRange->All]
In[]:=
AM[1, 1, 470, 6, 2]
Out[]=
⁃Sound⁃
The resulting plot conveys at least some of the detail that your reviewer could hear. Observe the twelve complete cycles of growth-decay (including the start-decay and end-growth occurrences). They correspond to six cycles per second, or 6 Hz - the modulator frequency. What your reviewer heard but you cannot observe, alas, was the wax and wane of standard pitch + 30 Hz, as allowed by the growth-decay cycles, and as expected from the third argument of 470 Hz supplied to AM[]. Your reviewer could not tell if the amplitude at the end of growth/onset of decay was double that from, say, Play[Sin[2 Pi 470 t],{t,0,1}]; for that, we need equipment from Harry F. Olson's lab. Given its scope, range of examples, and clarifying commentary, this notebook is particularly well-crafted.
The 6.fm.nb notebook does for frequency modulation what 5.am.nb did for amplitude modulation, in terms of quality of crafting. Simple, complex, serial, and parallel frequency modulation are discussed. Let us examine the notebook example featuring unity amplitude, a 440 Hz carrier frequency, a 6 Hz (sub-audio) modulator frequency, a 36 Hz peak frequency deviation, and a two-second duration (double the notebook example duration):
In[]:=
FM[Amplitude_,Carrier_,PeakDeviation_,Modulator_,Duration_] := Play[Evaluate[ Amplitude * Sin[2 Pi Carrier t + PeakDeviation/Modulator * Sin[2 Pi Modulator t]]], {t,0,Duration}]
In[]:=
FM[1, 440, 36, 6, 2]
Out[]=
⁃Sound⁃
Note that the bottom portion of the resulting plot reveals 6 cycles per second, despite the uselessness of the top portion. Question: Are there six cycles because the modulator frequency is 6 Hz, or because the ratio of peak frequency deviation to modulator frequency is 36 Hz/6 Hz = 6? Tweaking these parameters reveals the former as the answer; however, the latter is directly proportional to the ratio of widest to narrowest parts of the bottom portion of the plot. In terms of sound generation, the 6 Hz modulator frequency corresponds to six frequency deviations per second from the 440 Hz carrier frequency. If we lower the carrier frequency to a barely audible 24 Hz, use a peak frequency deviation of 24 Hz (allowing for a 0 - 48 Hz frequency range), and use a modulator frequency of 3 Hz for a single-second duration, we get FM[] output that -- while not the most pleasing of notes -- features a much more illustrative plot.
In[]:=
FM[1,24,24,3,1]
Out[]=
⁃Sound⁃
As it was that Chandra's AM[] example aurally illustrated tremolo, so it is that his FM[] example aurally illustrates vibrato. Vibrato is used as an artistic embellishment by musicians, and is accompanied by an amplitude modulation at the modulating frequency; tremolo is a special case of vibrato. The 6.fm.nb would have been better had Chandra explored the effects of the aforementioned parameter tweaking.
Finally, the 7.tuning.nb notebook examines scales, the relationship between scales, and tuning. Pythagorean tuning, the scale of just intonation, and the scales of mean-time and equal temperament are discussed, with a helpful PlayScale[] function used to play notes from each. Chandra ends 7.tuning.nb with Harry Partch's 43 Tone Scale ... and with no commentary whatsoever on Partch. The inclusion is a nod to the eccentric: Partch, "who made many strange instruments whose sounds were as wonderful as their names, and which were often of somewhat uncertain pitch, had a harmonium justly tuned in the key of C. It sounded excellent in C, but dreadful when played in any other key" [Pierce 1983, p. 68].
ASSESSMENT
ASSESSMENT
Arun Chandra's introduction to this MathSource item notes that it has been "written by a musician, not a mathematician." The implication is that musicians focus on the quality and attributes of sound more so than the mathematics of sound production. Indeed, Chandra's credentials as a musician are impeccable, and in these notebooks he does for the most part maintain his focus. His faux pas in the 2.waveforms.nb notebook with SquarePlay[] can readily be excused, since it was so easily detectable (and probably the remnant of an earlier notebook draft). There are areas where more commentary from the musician's pen would have been enlightening, but the omissions do not change the fact that Chandra's is a well-crafted contribution to MathSource.
Not much seems to have happened with Play[] and its derivative functions in Mathematica over the years. Play[] (with ample support from Plot[] -- see the earlier commentary from your reviewer) remains the tool of the teacher and of the student ... one tool in a toolkit keeping the company of QuickTime and MPEG Layer 3 (see the Web sites cited earlier). The serious audio producer works not with Mathematica, but with tools such as Cool Edit from Syntrillium Software Corporation and Software Audio Workship (SAW) from Innovative Quality Software. These tools bury the mathematics within the user interface, allowing the user to accomplish high-quality audio production rapidly. Only with newly-released version 4.0 (and its ability to import/export sound files in AIFF, WAV, and other popular formats) can Mathematica interact with these tools. That interaction has great potential for fruitfulness.
REFERENCES
REFERENCES
BACKUS, JOHN. The Acoustical Foundations of Music, 2nd ed. W. W. Norton and Company, New York (1977).
MILLER, DAYTON CLARENCE. The Science of Musical Sounds. The Macmillan Company, New York (1916).
OLSON, HARRY F. Music, Physics and Engineering, 2nd ed. Dover Publications, New York (1967).
PIERCE, JOHN R. The Science of Musical Sound. Scientific American Books, New York (1983).
WOOD, ALEXANDER. The Physics of Music, 7th ed. (revised by J. M. Bowsher). Chapman and Hall, London (1975).
MILLER, DAYTON CLARENCE. The Science of Musical Sounds. The Macmillan Company, New York (1916).
OLSON, HARRY F. Music, Physics and Engineering, 2nd ed. Dover Publications, New York (1967).
PIERCE, JOHN R. The Science of Musical Sound. Scientific American Books, New York (1983).
WOOD, ALEXANDER. The Physics of Music, 7th ed. (revised by J. M. Bowsher). Chapman and Hall, London (1975).
ABOUT THE AUTHOR
ABOUT THE AUTHOR
Matthew M. Thomas wrote "Pillaging the Ivory Tower: A New-Millennium Strategy for Handling Academia" for the Proceedings of the 1999 Conference for Industry and Education Collaboration in Palm Springs, CA. The title was tongue-in-cheek.
thomas@wuche2.wustl.edu
thomas@wuche2.wustl.edu
Cite this as: Matthew M. Thomas, "MathSource Reviews: Mathematica in Your Ear" from the Notebook Archive (2019), https://notebookarchive.org/2018-10-10nbbc8
Download
