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

Generated on Tue Sep 12 10:14:24 2006 for Musimat Tutorial by  doxygen 1.4.7