SHAPE - input sound waveshaping instrument
SHAPE(outskip, inskip, indur, ampmult, mindist, maxdist, ampnorm_table [, inchan, stereoloc ])
Function table 1 gives amplitude curve.
Function table 2 gives waveshaping transfer function.
Function table 3 gives distortion index curve.
Function table ampnorm_table gives amplitude normalization function.
SHAPE does a table-lookup waveshaping (distortion) on an arbitrary input soundfile. The WAVESHAPE instrument uses a similar approach, but does synthesis instead of signal-processing. SHAPE accepts input from a file, a real-time audio device, or from a bus. It also offers a different way of performing amplitude normalization than WAVESHAPE. SHAPE accomplishes this by applying a waveshaping transfer function to the input source. (See Dodge and Jerse, or any other computer music text, for a detailed explanation of this process.)
SHAPE uses the curve provided in function table 1 to scale the amplitude of the output. Use setline, setexp, or makegen to create function table 1. If this table has not been created, no amplitude scaling will occur.
SHAPE uses function table 2 as the waveshaping transfer function. Use gen 17 to get the Chebyshev polynomials that let you predict the frequencies and amplitudes of harmonic partials. Or use any other table type for arbitrary distortion effects.
Function table 3 describes the path between mindist and maxdist.
If you want to perform amplitude normalization, set ampnorm_table to the number of the function table giving the normalization curve. Otherwise, set ampnorm_table to zero. The amplitude normalization function allows you to decouple amplitude and timbral change, to some extent. (Read about this in the Roads "Computer Music Tutorial'' chapter on waveshaping.) The table maps incoming signal amplitudes, on the X axis, to amplitude multipliers, on the Y axis. The multipliers should be from 0 to 1. The amplitude multipliers are applied to the output signal, along with whatever overall amplitude curve is in effect. Generally, you'll want a curve that starts high and moves lower for the higher signal amplitudes. This will keep the bright and dark timbres more equal in amplitude. But anything is possible.
The output of SHAPE can be either stereo or mono.
rtsetparams(44100, 2) load("WAVETABLE") load("SHAPE") bus_config("WAVETABLE", "aux 0 out") bus_config("SHAPE", "aux 0 in", "out 0") dur = 10 amp = 10000 freq = 200 makegen(2, 10, 2000, 1) start = 0 WAVETABLE(start, dur, amp, freq) setline(0,0, 9,1, 10,0) makegen(2, 17, 1000, 0.9, 0.3, -0.2, 0.6, -0.7, 0.9, -0.1) makegen(3, 25, 1000, 1) /* bell curve */ min = 0; max = 3.0 SHAPE(start, inskip = 0, dur, amp = 0.5, min, max, 0)The second sample scorefile:
rtsetparams(44100, 2) load("WAVETABLE") load("SHAPE") bus_config("WAVETABLE", "aux 0 out") bus_config("SHAPE", "aux 0 in", "out 0-1") dur = 20 freq = 60 amp = 20000 makegen(2, 10, 2000, 1, .3, .1) WAVETABLE(start=0, dur, amp, freq) /* square wave transfer function */ makegen(2, 10, 1000, 1, 0, 1/3, 0, 1/5, 0, 1/7, 0, 1/9, 0, 1/11, 0, 1/13) /* sample-and-hold distortion index */ speed = 7 /* sh changes per second */ shsize = dur * speed makegen(3, 20, shsize, 0, seed=1) copygen(3, 3, 4000, 0) /* avoid interpolation btw. rand vals */ minidx = 0.0 maxidx = 3.0 makegen(99, 4, 1000, 0,1,-1, 1,.3) /* normalization function */ amp = 0.8 setline(0,1, dur-.03,1, dur,0) reset(20000) SHAPE(start, inskip=0, dur, amp, minidx, maxidx, 99, 0, 1) /* vary distortion index for other channel */ makegen(3, 20, shsize, 0, seed + 1) copygen(3, 3, 4000, 0) SHAPE(start, inskip=0, dur, amp, minidx, maxidx, 99, 0, 0)
setline, setexp, makegen, gen17, WAVESHAPE, DISTORT
John Gibson <johgibso at indiana edu>