00001 #include "MusimatTutorial.h" 00002 MusimatTutorialSection(B0204) { 00003 Print("*** B.2.4 Loudness ***"); 00004 /***************************************************************************** 00005 00006 B.2.4 Loudness 00007 00008 Loudness is expressed in common music notation using performance indications such as fortis- 00009 simo or piano (see section 2.7). But the performed intensity depends upon the acoustical power of 00010 the instrument and the interpretation of the performer. A better approach for the purpose here 00011 would be to define loudness in objective terms using decibels (see section 5.5.1). 00012 00013 Since microphones and loudspeakers measure and reproduce pressure waves, it is common to 00014 use dB SPL in audio work (see equation 5.32). It is also conventional in audio to take the loudest 00015 value that can be reproduced without distortion as a reference intensity of 0 dB (see section 4.24.2). 00016 Since measured intensities will be less intense than the reference, then by the definition of the deci- 00017 bel they will be expressed as negative decibel levels. We can write, for example, –6 dB to indicate 00018 an amplitude that is (very close to) one half of the amplitude of the 0 dB reference. 00019 00020 Restating (5.32), the equation for dB SPL, as 00021 00022 y dB = 20 Log10(A'/A) 00023 00024 and simplifying by letting x=A'/A, we have y dB = 20 Log10(x). Solving for x, we have 00025 00026 x = 10^(y/20). (B.1) 00027 00028 For example, setting y = -6 dB, we have x = 10^(-6/20) = 0.501. The value of x is the coefficient by 00029 which a signal must be multiplied to lower its amplitude by 6 dB. For another example, setting 00030 y = 0 dB, we have x = 10^(0/20) = 1. So multplying by 0 dB does not affect amplitude. Setting 00031 y = -120 dB, we have x = 10^(-120/20) = 0.000001, so multiplying a signal by –120 dB renders it vir- 00032 tually inaudible. Finally, if we wish to amplify a soft sound, scaling it by +6 dB makes it twice as 00033 loud. Thus, scaling sounds with decibel coefficients allows us to achieve arbitrary loudness levels 00034 for waveforms. So we define 00035 *****************************************************************************/ 00036 para1(); // Step into this function to continue the tutorial 00037 } 00038 00039 Real dB(Real y){ 00040 Return(Pow(10.0, y/20.0)); 00041 } 00042 00043 Static Void para1() { 00044 /***************************************************************************** 00045 For example, Print(dB(–6)) prints 0.501187, Print(dB(0)) prints 1.0, and 00046 Print(dB(–120)) prints 0.000001. 00047 00048 Suppose we have the following audio samples for a sound: 00049 *****************************************************************************/ 00050 00051 RealList mySound(0, 0.16, 0.192, -0.37, -0.45, -0.245, -0.43, 0.09); 00052 00053 /***************************************************************************** 00054 We wish to halve the sound’s amplitude. Then 00055 *****************************************************************************/ 00056 00057 RealList scaledSound = mySound * dB(-6); 00058 Print(scaledSound); 00059 00060 /***************************************************************************** 00061 prints {0.02, 0.08, 0.10, -0.19, -0.23, -0.12, -0.22, 0.05, . . .}. 00062 00063 See volume 2, chapter 1, for more about sampled signals. 00064 00065 Musimat provides built-in definitions for standard music dynamics levels based on figure 4.7. 00066 *****************************************************************************/ 00067 00068 Real ffff = dB(0), fff = dB(-10), ff = dB(-18), f = dB(-24), 00069 mf = dB(-32), mp = dB(-40), p = dB(-48), pp = dB(-56), 00070 ppp = dB(-64); 00071 00072 /***************************************************************************** 00073 Thus ffff does not change the amplitude of the signal, but all others attenuate it to varying 00074 degrees. 00075 00076 *****************************************************************************/ 00077 }} 00078 00080 /* $Revision: 1.4 $ $Date: 2006/09/12 17:38:02 $ $Author: dgl $ $Name: $ $Id: _b0204_8cpp-source.html,v 1.4 2006/09/12 17:38:02 dgl Exp $ */ 00081 // The Musimat Tutorial © 2006 Gareth Loy 00082 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 00083 // and published exclusively by The MIT Press. 00084 // This program is released WITHOUT ANY WARRANTY; without even the implied 00085 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00086 // For information on usage and redistribution, and for a DISCLAIMER OF ALL 00087 // WARRANTIES, see the file, "LICENSE.txt," in this distribution. 00088 // "Musimathics" is available here: http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916 00089 // Gareth Loy's Musimathics website: http://www.musimathics.com/ 00090 // The Musimat website: http://www.musimat.com/ 00091 // This program is released under the terms of the GNU General Public License 00092 // available here: http://www.gnu.org/licenses/gpl.txt 00093
1.4.7