Generates a stored function table by evaluating a polynomial in x over a fixed interval and with specified coefficients.
Syntax
f#timesize3xval1xval2c0c1c2...cn
Initialization
size -- number of points in the table. Must be a power of 2 or a power-of-2 plus 1.
xval1, xval2 -- left and right values of the x interval over which the polynomial is defined (xval1 < xval2). These will produce the 1st stored value and the (power-of-2 plus l)th stored value respectively in the generated function table.
c0, c1, c2, ..., cn -- coefficients of the nth-order polynomial
C0 + C1x + C2x2 + . . . + Cnxn
Coefficients may be positive or negative real numbers; a zero denotes a missing term in the polynomial. The coefficient list begins in p7, providing a current upper limit of 144 terms.
Note
The defined segment [fn(xval1), fn(xval2)] is evenly distributed. Thus a 512-point table over the interval [-1,1] will have its origin at location 257 (at the start of the 2nd half). Provided the extended guard point is requested, both fn(-1) and fn(1) will exist in the table.
GEN03 is useful in conjunction with table or tablei for audio waveshaping (sound modification by non-linear distortion). Coefficients to produce a particular formant from a sinusoidal lookup index of known amplitude can be determined at preprocessing time using algorithms such as Chebyshev formulae. See also GEN13.
Examples
Here is an example of the GEN03 generator. It uses the file gen03.csd.
<CsoundSynthesizer><CsOptions>; Select audio/midi flags here according to platform-odac ;;;realtime audio out;-iadc ;;;uncomment -iadc if realtime audio input is needed too; For Non-realtime ouput leave only the line below:; -o gen03.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1;example by Russell Pinkston - Univ. of Texas (but slightly modified)gisineftgen1,0,16384,10,1;sine waveinstr1ihertz=cpspch(p4)ipkamp=p5iwsfn=p6;waveshaping functioninmfn=p7;normalization functionaenvlinen1,.01,p3,.1;overall amp envelopeactrllinen1,2,p3,2;waveshaping index controlaindexposcilactrl/2,ihertz,gisine;sine wave to be distortedasignaltablei.5+aindex,iwsfn,1;waveshapinganormaltableiactrl,inmfn,1;amplitude normalizationasig=asignal*anormal*ipkamp*aenvasigdcblock2asig;get rid of possible DC outsasig,asigendin</CsInstruments><CsScore>; first four notes are specific Chebyshev polynomials using gen03. The values were obtained from Dodge page 147f405133-1101; First-order Chebyshev: xf50257441; Normalizing function for fn4f605133-11-102; Second-order Chebyshev: 2x2 - 1f70257461; Normalizing function for fn6f805133-110-304; Third-order Chebyshev: 4x3 - 3xf90257481; Normalizing function for fn8f1005133-1100-70560-112064; Seventh-order Chebyshev: 64x7 - 112x5 + 56x3 - 7xf1102574101; Normalizing function for fn10f1205133-11543221; a 4th order polynomial function over the x-interval -1 to 1f1302574121; Normalizing function for fn12; five notes with same fundamental, different waveshape & normalizing functions; pch amp wsfn nmfni1038.00.745i1+...67i1+...89i1+...1011i1+...1213e</CsScore></CsoundSynthesizer>
These are the diagrams of the waveforms of the GEN03 routines, as used in the example: