Functions

/Users/garethloy/Musimathics/Musimat1.2/MusimatChapter9/C091201f.cpp File Reference

#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 ()

Function Documentation

Real linearInterpolate ( Real  x,
Real  xMin,
Real  xMax,
Real  yMin,
Real  yMax 
)

Definition at line 28 of file C091201f.cpp.

References a(), and b().

                  {
        Real a = (x - xMin) / (xMax - xMin);
        Real b = yMax - yMin;
        Return(a * b + yMin);
}
MusimatChapter9Section ( C091201f   )

Definition at line 2 of file C091201f.cpp.

References para1(), and para2().

                                 {
        Print("*** Linear Interpolation ***");
        /*****************************************************************************
         
         Linear Interpolation
         
         Linear interpolation allows us to map a range of values so that it covers 
         a proportionately wider or narrower range. Figure 9.14 shows linear interpolation from the range 
         1-4 on the left being mapped to the range 3-9 on the right. The value 3 on the left corresponds by 
         linear interpolation to 7 on the right. Linear interpolation maintains the linear proportions of the 
         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. 
         
         Linear interpolation is a slight generalization of unit interpolation, as follows. If xMax is 
         the upper bound and xMin is the lower bound, and x is a parameter in the range xmin <= x <= xmax, then 
         
              x - xMin
         y = ----------- (yMax - yMin) + yMin
             xMax - xMin
         
         sets y to a position within the range yMin <= y <= yMax that is proportional to the position of x within 
         its range. Below is the definition of linear interpolation in Musimat:
         *****************************************************************************/
        para1(); // Step into this function to continue.
        para2(); // Step into this function to continue.
}
Static Void para1 (  )

Definition at line 40 of file C091201f.cpp.

References linearInterpolate().

                    {
        /*****************************************************************************
         Here is an example of linear interpolation:
         *****************************************************************************/
        
        Print("*** Linear Interpolation ***");
        Print("linearInterpolate(3.0, 1.0, 4.0, 3.0, 9.0) = ", linearInterpolate(3.0, 1.0, 4.0, 3.0, 9.0));
        
        /*****************************************************************************
         We also can use linear interpolation to map an entire function to a different range. We do so by 
         applying linear interpolation to every point on the function. For example, we can scale a chromatic 
         melody to occupy a wider or narrower tessatura as follows:
         *****************************************************************************/
}
Static Void para2 (  )

Definition at line 64 of file C091201f.cpp.

References stretch().

                    {
        /*****************************************************************************
         For example, if the input is
         *****************************************************************************/
        
        Print("*** Stretch ***");
        IntegerList L(0, 8, 10, 6, 7, 5, 9, 1, 3, 2, 11, 4);
        Print("Source list: ", L);
        
        /*****************************************************************************
         invoking stretch() with these arguments
         *****************************************************************************/
        
        Print("stretch(L, 24, 47)=", stretch(L, 24, 47));
        
        /*****************************************************************************
         will scale the row to cover a two-octave range and offset it upward by one octave. 
         Then x will be {24, 40, 44, 36, 38, 34, 42, 26, 30, 28, 47, 32}. It can also be used to com-
         press rows. With the same input, 
         *****************************************************************************/
        
        Print("stretch(L, 0, 5)=", stretch(L, 0, 5));
        
        /*****************************************************************************
         will produce {0, 3, 4, 2, 3, 2, 4, 0, 1, 0, 5, 1}.
         *****************************************************************************/
}
IntegerList stretch ( IntegerList  L,
Integer  yMin,
Integer  yMax 
)

Definition at line 55 of file C091201f.cpp.

References linearInterpolate().

                                                               {
        Integer xMin = Integer(Min(L));                                                                         // find the list's minimum
        Integer xMax = Integer(Max(L));                                                                         // find the list's maximum
        For (Integer i = 0; i < Length(L); i = i + 1) {
                L[i] = Integer(linearInterpolate(L[i], xMin, xMax, yMin, yMax));
        }
        Return(L);
}