powershape — Waveshapes a signal by raising it to a variable exponent.

The *powershape* opcode raises an input signal to a power with pre- and post-scaling of the signal so that the output will be in a predictable range. It also processes negative inputs in a symmetrical way to positive inputs, calculating a dynamic transfer function that is useful for waveshaping.

*ifullscale* -- optional parameter specifying the range of input values from -*ifullscale* to *ifullscale*. Defaults to 1.0 -- you should set this parameter to the maximum expected input value.

*ain* -- the input signal to be shaped.

*aout* -- the output signal.

*kShapeAmount* -- the amount of the shaping effect applied to the input; equal to the power that the input signal is raised.

The *powershape* opcode is very similar to the *pow* unit generators for calculating the mathematical "power of" operation. However, it introduces a couple of twists that can make it much more useful for waveshaping audio-rate signals. The *kShapeAmount* parameter is the exponent to which the input signal is raised.

To avoid discontinuities, the *powershape* opcode treats all input values as positive (by taking their absolute value) but preserves their original sign in the output signal. This allows for smooth shaping of any input signal while varying the exponent over any range. (*powershape* also (hopefully) deals intelligently with discontinuities that could arise when the exponent and input are both zero. Note though that negative exponents will usually cause the signal to exceed the maximum amplitude specified by the ifullscale parameter and should normally be avoided).

The other adaptation involves the *ifullscale* parameter. The input signal is divided by *ifullscale* before being raised to *kShapeAmount* and then multiplied by *ifullscale* before being output. This normalizes the input signal to the interval [-1,1], guaranteeing that the output (before final scaling) will also be within this range for positive shaping amounts and providing a smoothly evolving transfer function while varying the amount of shaping. Values of *kShapeAmount* between (0,1) will make the signal more "convex" while values greater than 1 will make it more "concave". A value of exactly 1.0 will produce no change in the input signal.

Here is an example of the powershape opcode. It uses the file *powershape.csd*.

**Example 625. Example of the powershape opcode.**

See the sections *Real-time Audio* and *Command Line Flags* for more information on using command line flags.

<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform ; Audio out Audio in -odac -iadc ;;;RT audio I/O ; For Non-realtime ouput leave only the line below: ; -o abs.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> instr 1 imaxamp = 10000 kshapeamt line p5, p3, p6 aosc oscili 1.0, cpspch(p4), 1 aout powershape aosc, kshapeamt adeclick linseg 0.0, 0.01, 1.0, p3 - 0.06, 1.0, 0.05, 0.0 out aout * adeclick * imaxamp endin </CsInstruments> <CsScore> f1 0 32768 10 1 i1 0 1 7.00 0.000001 0.8 i1 + 0.5 7.02 0.01 1.0 i1 + . 7.05 0.5 1.0 i1 + . 7.07 4.0 1.0 i1 + . 7.09 1.0 10.0 i1 + 2 7.06 1.0 25.0 e </CsScore> </CsoundSynthesizer>