• Main Page
  • Files
  • File List
  • File Members

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

Go to the documentation of this file.
00001 #include "MusimatTutorial.h"
00002 MusimatTutorialSection(B0201b) {
00003         Print("*** Pythagorean Chromatic Scale ***");
00004         /*****************************************************************************
00005          
00006          Pythagorean Chromatic Scale
00007          
00008          We can compute the frequency of a Pitch in Pythagorean 
00009          chromatic tuning, assuming a reference such as A4 equals 440 Hz. We start by computing the fre-
00010          quency of Pythagorean middle C from the reference frequency, using equation (3.11).
00011          *****************************************************************************/
00012         
00013         para1();  // Step into this function to continue the tutorial
00014         para2();  // Step into this function to continue the tutorial
00015 }
00016 
00017 
00018 /*****************************************************************************
00019  Next, referring to figure 3.7, we tabulate the ratios of the Pythagorean chromatic scale in 
00020  Musimat using a RealList:
00021  *****************************************************************************/
00022 
00023 RealList pythagoreanChromatic( 
00024         1.0/1.0, 256.0/243.0, 9.0/8.0, 32.0/27.0,
00025         81.0/64.0, 4.0/3.0, 1024.0/729.0, 3.0/2.0,
00026         128.0/81.0, 27.0/16.0, 16.0/9.0, 243.0/128.0
00027 );
00028 
00029 Static Void para1() {
00030         
00031         /*****************************************************************************
00032          Last, we define a variation of the pitchToHz() function. This version has the same name but 
00033          takes three arguments instead of one. When supplied with a certain Pitch p, it returns the fre-
00034          quency corresponding to its Pythagorean intonation as a Real value in hertz.
00035          *****************************************************************************/
00036         
00037         para2();
00038 }
00039 
00040 Real pitchToHz( 
00041                            Pitch p,                                                                             // pitch
00042                            Real refC,                                                                           // reference frequency
00043                            RealList scale                                                                       // ratios of scale degrees
00044                            ) {
00045         Integer key = PitchClass(p) + Accidental(p);    // get key from pitch
00046         Real oct = Octave(p);                                                   // get octave from pitch
00047         Return(refC * scale[key] * Pow(2.0, (oct - 4)));// compute frequency
00048 }  
00049 
00050 Static Void para2() {
00051         
00052         /*****************************************************************************
00053          The Return() statement calculates the frequency of the key from the reference frequency 
00054          times the ratio for that degree, then adjusts it for the proper octave.
00055          
00056          We define the reference frequencies in Musimat as follows:
00057          *****************************************************************************/
00058         
00059         Real R = 440.0;
00060         Real cPi4 = R * 16.0/27.0; // Pythagorean middle C, 260.74 Hz
00061         
00062         /*****************************************************************************
00063          Finally, we call pitchToHz() with the pitch we want, the Pythagorean reference
00064          frequency, and the ratios of the Pythagorean scale:
00065          *****************************************************************************/
00066         
00067         Print("Pythagorian A4=",  pitchToHz(A4 , cPi4, pythagoreanChromatic));
00068         
00069         /*****************************************************************************
00070          This prints A4=440.0, and
00071          *****************************************************************************/
00072         
00073         Print("Pythagorian C4=",  pitchToHz(C4 , cPi4, pythagoreanChromatic));
00074         
00075         /*****************************************************************************
00076          prints C4=260.74, as expected.
00077          *****************************************************************************/
00078 }
00079 
00081 /* $Revision: 1.3 $ $Date: 2006/09/05 08:03:08 $ $Author: dgl $ $Name:  $ $Id: B0201b.cpp,v 1.3 2006/09/05 08:03:08 dgl Exp $ */
00082 // The Musimat Tutorial � 2006 Gareth Loy
00083 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" � 2006 Gareth Loy 
00084 // and published exclusively by The MIT Press.
00085 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00086 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00087 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00088 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00089 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00090 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00091 // The Musimat website:                 http://www.musimat.com/
00092 // This program is released under the terms of the GNU General Public License
00093 // available here:                      http://www.gnu.org/licenses/gpl.txt
00094 

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