• Main Page
  • Files
  • File List
  • File Members

/Users/garethloy/Musimathics/Musimat1.2/MusimatTutorial/B0204.cpp

Go to the documentation of this file.
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, using standard mathematics symbols, is
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          (Note, in standard math, A' in English means "A prime", which means A' is like A, but is not
00029          necessarily the same.  Also, the operator "^" in standard math means exponentiation, so that
00030          2^2=4.  In modern programming languages, however, "^" means "exclusive-or".)
00031          
00032          For example, setting y = -6 dB, we have x = 10^(-6/20) = 0.501. The value of x is the coefficient by 
00033          which a signal must be multiplied to lower its amplitude by 6 dB. For another example, setting 
00034          y = 0 dB, we have x = 10^(0/20) = 1. So multplying by 0 dB does not affect amplitude. Setting 
00035          y = -120 dB, we have x = 10^(-120/20) = 0.000001, so multiplying a signal by -120 dB renders it vir-
00036          tually inaudible. Finally, if we wish to amplify a soft sound, scaling it by +6 dB makes it twice as 
00037          loud. Thus, scaling sounds with decibel coefficients allows us to achieve arbitrary loudness levels 
00038          for waveforms. So we define
00039          *****************************************************************************/
00040         
00041         para1();  // Step into this function to continue the tutorial
00042 }
00043 
00044 Real dB(Real y){ 
00045         Return(Pow(10.0, y/20.0)); 
00046 }
00047 
00048 Static Void para1() {
00049         
00050         /*****************************************************************************
00051          For example, Print(dB(-6)) prints 0.501187, Print(dB(0)) prints 1.0, and 
00052          Print(dB(-120)) prints 0.000001.
00053          
00054          Suppose we have the following audio samples for a sound:
00055          *****************************************************************************/
00056         
00057         RealList mySound(0, 0.16, 0.192, -0.37, -0.45, -0.245, -0.43, 0.09);
00058         
00059         /*****************************************************************************
00060          We wish to halve the sound's amplitude. Then
00061          *****************************************************************************/
00062         
00063         RealList scaledSound = mySound * dB(-6);
00064         Print(scaledSound);
00065         
00066         /*****************************************************************************
00067          prints {0.02, 0.08, 0.10, -0.19, -0.23, -0.12, -0.22, 0.05, . . .}.
00068          
00069          See volume 2, chapter 1, for more about sampled signals.
00070          
00071          Musimat provides built-in definitions for standard music dynamics levels based on figure 4.7.
00072          *****************************************************************************/
00073         
00074         Real ffff = dB(0), fff = dB(-10),  ff = dB(-18),  f = dB(-24),
00075         mf = dB(-32),  mp = dB(-40),  p = dB(-48),  pp = dB(-56),
00076         ppp = dB(-64);
00077         
00078         Print( ffff ); Print( fff ); Print(ff); Print(f); Print(mf); Print(mp); Print(mp); Print(p); Print(pp); Print(ppp);
00079         
00080         /*****************************************************************************
00081          Thus ffff does not change the amplitude of the signal, but all others attenuate it to varying 
00082          degrees.
00083          *****************************************************************************/
00084 }
00085 
00087 /* $Revision: 1.3 $ $Date: 2006/09/05 08:03:08 $ $Author: dgl $ $Name:  $ $Id: B0204.cpp,v 1.3 2006/09/05 08:03:08 dgl Exp $ */
00088 // The Musimat Tutorial © 2006 Gareth Loy
00089 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 
00090 // and published exclusively by The MIT Press.
00091 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00092 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00093 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00094 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00095 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00096 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00097 // The Musimat website:                 http://www.musimat.com/
00098 // This program is released under the terms of the GNU General Public License
00099 // available here:                      http://www.gnu.org/licenses/gpl.txt
00100 

Generated on Fri Nov 26 2010 16:18:25 for Musimat Tutorial by  doxygen 1.7.2