polynomial
Prev | Orchestra Opcodes and Operators | Next

## polynomial

polynomial — Efficiently evaluates a polynomial of arbitrary order.

## Description

The polynomial opcode calculates a polynomial with a single a-rate input variable. The polynomial is a sum of any number of terms in the form kn*x^n where kn is the nth coefficient of the expression. These coefficients are k-rate values.

## Syntax

    aout polynomial ain, k0 [, k1 [, k2 [...]]]

## Performance

ain -- the input signal used as the independent variable of the polynomial ("x").

aout -- the output signal ("y").

k0, k1, k2, ... -- the coefficients for each term of the polynomial.

If we consider the input parameter ain to be "x" and the output aout to be "y", then the polynomial opcode calculates the following equation:

y = k0 + k1*x + k2*x^2 + k3*x^3 + ...

## Examples

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

Example 575. Example of the polynomial 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
    -odac  ;;;realtime audio
    ;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
    ; For Non-realtime ouput leave only the line below:
    ; -o polynomial.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    sr = 44100
    ksmps = 32
    nchnls = 2
    0dbfs  = 1

    ; The polynomial y=x^n where n is odd always produces a curve
    ; that traverses the range [-1, 1] when the input is within
    ; the same range.  Therefore, we can use one of these curves
    ; to make a nonlinear phasor that repeatedly reads a table
    ; from beginning to end like a linear phasor (maintaining
    ; continuity) but that distorts the waveform in the table.

    instr 4	; This instrument demonstrates phase distortion with x^3

    idur   = p3
    iamp   = p4
    ifreq  = p5
    itable = p6

    aenv linseg 0, .001, 1.0, idur - .051, 1.0, .05, 0	; declicking envelope
    aosc phasor ifreq					; create a linear phasor
    apd  polynomial aosc, 0, 0, 0, 1			; distort the phasor with x^3
    aout tablei apd, itable, 1				; read a sine table with the nonlinear phasor
         outs aenv*aout*iamp, aenv*aout*iamp

    endin

    instr 5	; This instrument demonstrates phase distortion with x^11

    idur   = p3
    iamp   = p4
    ifreq  = p5
    itable = p6

    aenv linseg 0, .001, 1.0, idur - .051, 1.0, .05, 0	; declicking envelope
    aosc phasor ifreq					; create a linear phasor
    apd  polynomial aosc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ; distort the phasor with x^11
    aout tablei apd, itable, 1				; read a sine table with the nonlinear phasor
         outs aenv*aout*iamp, aenv*aout*iamp

    endin

    instr 6 ; This instrument crossfades between a pure sine and one distorted with x^11

    idur   = p3
    iamp   = p4
    ifreq  = p5
    itable = p6

    aenv	linseg	0, .001, 1.0, idur - .051, 1.0, .05, 0	; declicking envelope
    aosc	phasor	ifreq					; create a linear phasor
    aout3	tablei	aosc, itable, 1				; read a sine table without the linear phasor
    apd11	polynomial aosc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ; distort the phasor with x^11
    aout11	tablei	apd11, itable, 1			; read a sine table with the nonlinear phasor
    kamount	linseg	1.0, 0.05, 0.9, 1.0, 0.0		; crossfade between two outputs
    aout	= aout3*kamount + aout11*(1.0 - kamount)
            outs aenv*aout*iamp, aenv*aout*iamp

    endin
    </CsInstruments>
    <CsScore>
    f1 0 16385 10 1	; sine wave

    ; descending "just blues" scale

    t 0 100
    i4 0 .333 .7 512     1
    i. + .    .  448
    i. + .    .  384
    i. + .    .  360
    i. + .    .  341.33
    i. + .    .  298.67
    i. + 2    .  256
    s

    t 0 100
    i5 0 .333 .7 512     1
    i. + .    .  448
    i. + .    .  384
    i. + .    .  360
    i. + .    .  341.33
    i. + .    .  298.67
    i. + 2    .  256
    s

    t 0 100
    i6 0 .333 .7 512     1
    i. + .    .  448
    i. + .    .  384
    i. + .    .  360
    i. + .    .  341.33
    i. + .    .  298.67
    i. + 2    .  256

    e

    </CsScore>
    </CsoundSynthesizer>

## See Also

chebyshevpoly, mac maca

## Credits

Author: Anthony Kozar
January 2008

New in Csound version 5.08

Prev | Up | Next
polyaft | Home | pop