Stores a polynomial whose coefficients derive from the Chebyshev polynomials of the first kind.
Uses Chebyshev coefficients to generate stored polynomial functions which, under waveshaping, can be used to split a sinusoid into harmonic partials having a pre-definable spectrum.
Syntax
f#timesize13xintxamph0h1h2...
Initialization
size -- number of points in the table. Must be a power of 2 or a power-of-2 plus 1 (see f statement). The normal value is power-of-2 plus 1.
xint -- provides the left and right values [-xint, +xint] of the x interval over which the polynomial is to be drawn. These subroutines both call GEN03 to draw their functions; the p5 value here is therefor expanded to a negative-positive p5, p6 pair before GEN03 is actually called. The normal value is 1.
xamp -- amplitude scaling factor of the sinusoid input that is expected to produce the following spectrum.
h0, h1, h2, etc. -- relative strength of partials 0 (DC), 1 (fundamental), 2 ... that will result when a sinusoid of amplitude
xamp * int(size/2)/xint
is waveshaped using this function table. These values thus describe a frequency spectrum associated with a particular factor xamp of the input signal.
GEN13 is the function generator normally employed in standard waveshaping. It stores a polynomial whose coefficients derive from the Chebyshev polynomials of the first kind, so that a driving sinusoid of strength xamp will exhibit the specified spectrum at output. Note that the evolution of this spectrum is generally not linear with varying xamp. However, it is bandlimited (the only partials to appear will be those specified at generation time); and the partials will tend to occur and to develop in ascending order (the lower partials dominating at low xamp, and the spectral richness increasing for higher values of xamp). A negative hn value implies a 180 degree phase shift of that partial; the requested full-amplitude spectrum will not be affected by this shift, although the evolution of several of its component partials may be. The pattern +,+,-,-,+,+,... for h0,h1,h2... will minimize the normalization problem for low xamp values (see above), but does not necessarily provide the smoothest pattern of evolution.
Examples
Here is an example of the GEN13 generator. It uses the file gen13.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 gen13.wav -W ;;; for file output any platform</CsOptions><CsInstruments>sr=44100ksmps=32nchnls=20dbfs=1;example by Russell Pinkston - Univ. of Texas (but slightly modified)gisineftgen0,0,16384,10,1;sine waveinstr1ihertz=cpspch(p4)ipkamp=p5iwsfn=p6;waveshaping functioninmfn=p7;normalization functionagatelinen1,.01,p3,.1;overall amp envelopekctrllinen.99,2,p3,2;waveshaping index controlaindexposcilkctrl/2,ihertz,gisine;sine wave to be distortedasignaltablei.5+aindex,iwsfn,1;waveshapingknormaltableikctrl,inmfn,1;amplitude normalizationasig=asignal*knormal*ipkamp*agateoutsasig,asigendin</CsInstruments><CsScore>; This proves the statement in Dodge (p. 147) that Chebyshev polynomials; of order K have "only the kth harmonic." This is only true when the ; waveshaping index is at the maximum - i.e., when the entire transfer; function is being accessed. RP.;--------------------------------------------------------------------------------------------------------------------------------------------; quasi sawtooth transfer function: ; h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19 h20f1051313110100-50-332520-16.7-14.212.511.1-10-9.098.3337.69-7.14-6.676.255.88-5.55-5.265f20257411; normalizing function with midpoint bipolar offset; st dur pch amp wsfn nmfni1046.00.712i14.7.00.i18.8.00.;-------------------------------------------------------------------------------------------------------------------------------------------- ; quasi square wave transfer function: ; h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19f30513131101000-330200-14.2011.10-9.0907.690-6.6705.880-5.26f40257431; normalizing function with midpoint bipolar offset; st dur pch amp wsfn nmfni11646.00.734i120.7.00.i124.8.00.;-------------------------------------------------------------------------------------------------------------------------------------------- ; quasi triangle wave transfer function: ; h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19f50513131101000-11.11040-2.0401.230-.8260.590-.4440.3460-.277f60257451; normalizing function with midpoint bipolar offset; st dur pch amp wsfn nmfni13246.00.756i136.7.00.i140.8.00.;--------------------------------------------------------------------------------------------------------------------------------------------; transfer function1: h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16f70513131101-.80.6000.40000.1-.2-.3.5f80257471; normalizing function with midpoint bipolar offset; st dur pch amp wsfn nmfni14845.00.778i152.6.00.i156.7.00.;--------------------------------------------------------------------------------------------------------------------------------------------;=========================================================================;; This demonstrates the use of high partials, sometimes without a ;; fundamental, to get quasi-inharmonic spectra from waveshaping. ;;=========================================================================;; transfer function2: h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16f905131311000-.10.30-.50.70-.9010-10f100257491; normalizing function with midpoint bipolar offset; st dur pch amp wsfn nmfni16445.00.7910i168.6.00.i172.7.00.;--------------------------------------------------------------------------------------------------------------------------------------------; transfer function3: h0 h1 h2 h3 h4 h5 h6 h7 h8 h9 h10 h11 h12 h13 h14 h15 h16 h17 h18 h19 h17 h18 h19 h20f11051313110000000-10100-.10.10-.2.30-.70.20-.1f1202574111; normalizing function with midpoint bipolar offset; st dur pch amp wsfn nmfni18045.00.71112i184.5.06.i188.6.00.;--------------------------------------------------------------------------------------------------------------------------------------------;=========================================================================;; split a sinusoid into 3 odd-harmonic partials of relative strength 5:3:1;=========================================================================;;--------------------------------------------------------------------------------------------------------------------------------------------; transfer function4: h0 h1 h2 h3 h4 h5f1305131311050301f1402574131; normalizing function with midpoint bipolar offset; st dur pch amp wsfn nmfni19645.00.71314i1100.5.06.i1104.6.00.e</CsScore></CsoundSynthesizer>
These are the diagrams of the waveforms of the GEN13 routines, as used in the example: