#include "MusimatChapter9.h"Go to the source code of this file.
Functions | |
| MusimatChapter9Section (C091201f) | |
| Real | linearInterpolate (Real x, Real xMin, Real xMax, Real yMin, Real yMax) |
| Static Void | para1 () |
| IntegerList | stretch (IntegerList L, Integer yMin, Integer yMax) |
| Static Void | para2 () |
| Real linearInterpolate | ( | Real | x, | |
| Real | xMin, | |||
| Real | xMax, | |||
| Real | yMin, | |||
| Real | yMax | |||
| ) |
| MusimatChapter9Section | ( | C091201f | ) |
Definition at line 2 of file C091201f.cpp.
References para1(), and para2().
00002 { 00003 Print("*** Linear Interpolation ***"); 00004 /***************************************************************************** 00005 00006 Linear Interpolation 00007 00008 Linear interpolation allows us to map a range of values so that it covers 00009 a proportionately wider or narrower range. Figure 9.14 shows linear interpolation from the range 00010 1–4 on the left being mapped to the range 3–9 on the right. The value 3 on the left corresponds by 00011 linear interpolation to 7 on the right. Linear interpolation maintains the linear proportions of the 00012 two number lines: 3 is two-thirds of the way from 1 to 4, and 7 is two-thirds of the way from 3 to 9. 00013 00014 Linear interpolation is a slight generalization of unit interpolation, as follows. If xMax is 00015 the upper bound and xMin is the lower bound, and x is a parameter in the range xmin <= x <= xmax, then 00016 00017 x - xMin 00018 y = ----------- (yMax - yMin) + yMin 00019 xMax - xMin 00020 00021 sets y to a position within the range yMin <= y <= yMax that is proportional to the position of x within 00022 its range. Below is the definition of linear interpolation in Musimat: 00023 *****************************************************************************/ 00024 para1(); // Step into this function to continue. 00025 para2(); // Step into this function to continue. 00026 }
| Static Void para1 | ( | ) |
Definition at line 40 of file C091201f.cpp.
References linearInterpolate().
00040 { 00041 /***************************************************************************** 00042 Here is an example of linear interpolation: 00043 *****************************************************************************/ 00044 00045 Print("*** Linear Interpolation ***"); 00046 Print("linearInterpolate(3.0, 1.0, 4.0, 3.0, 9.0) = ", linearInterpolate(3.0, 1.0, 4.0, 3.0, 9.0)); 00047 00048 /***************************************************************************** 00049 We also can use linear interpolation to map an entire function to a different range. We do so by 00050 applying linear interpolation to every point on the function. For example, we can scale a chromatic 00051 melody to occupy a wider or narrower tessatura as follows: 00052 *****************************************************************************/ 00053 }
| Static Void para2 | ( | ) |
Definition at line 64 of file C091201f.cpp.
References stretch().
00064 { 00065 /***************************************************************************** 00066 For example, if the input is 00067 *****************************************************************************/ 00068 00069 Print("*** Stretch ***"); 00070 IntegerList L(0, 8, 10, 6, 7, 5, 9, 1, 3, 2, 11, 4); 00071 Print("Source list: ", L); 00072 00073 /***************************************************************************** 00074 invoking stretch() with these arguments 00075 *****************************************************************************/ 00076 00077 Print("stretch(L, 24, 47)=", stretch(L, 24, 47)); 00078 00079 /***************************************************************************** 00080 will scale the row to cover a two-octave range and offset it upward by one octave. 00081 Then x will be {24, 40, 44, 36, 38, 34, 42, 26, 30, 28, 47, 32}. It can also be used to com- 00082 press rows. With the same input, 00083 *****************************************************************************/ 00084 00085 Print("stretch(L, 0, 5)=", stretch(L, 0, 5)); 00086 00087 /***************************************************************************** 00088 will produce {0, 3, 4, 2, 3, 2, 4, 0, 1, 0, 5, 1}. 00089 *****************************************************************************/ 00090 }}
| IntegerList stretch | ( | IntegerList | L, | |
| Integer | yMin, | |||
| Integer | yMax | |||
| ) |
Definition at line 55 of file C091201f.cpp.
References linearInterpolate().
00055 { 00056 Integer xMin = Integer(Min(L)); // find the list’s minimum 00057 Integer xMax = Integer(Max(L)); // find the list’s maximum 00058 For (Integer i = 0; i < Length(L); i = i + 1) { 00059 L[i] = Integer(linearInterpolate(L[i], xMin, xMax, yMin, yMax)); 00060 } 00061 Return(L); 00062 }
1.4.7