GEN08
Prev | Score Statements and GEN Routines | Next

## GEN08

GEN08 — Generate a piecewise cubic spline curve.

## Description

This subroutine will generate a piecewise cubic spline curve, the smoothest possible through all specified points.

## Syntax

    f # time size 8 a n1 b n2 c n3 d ...

## Initialization

size -- number of points in the table. Must be a power of 2 or power-of-2 plus 1 (see f statement).

a, b, c, etc. -- ordinate values of the function.

n1, n2, n3 ... -- length of each segment measured in stored values. May not be zero, but may be fractional. A particular segment may or may not actually store any values; stored values will be generated at integral points from the beginning of the function. The sum n1 + n2 + ... will normally equal size for fully specified functions.

| Note
GEN08 constructs a stored table from segments of cubic polynomial functions. Each segment runs between two specified points but depends as well on their neighbors on each side. Neighboring segments will agree in both value and slope at their common point. (The common slope is that of a parabola through that point and its two neighbors). The slope at the two ends of the function is constrained to be zero (flat). Hint: to make a discontinuity in slope or value in the function as stored, arrange a series of points in the interval between two stored values; likewise for a non-zero boundary slope.

## Examples

Here is a simple example of the GEN08 routine. It uses the file gen08.csd. It will create a curve with a smooth hump in the middle, going briefly negative outside the hump then flat at its ends. Here is its diagram:

Diagram of the waveform generated by GEN08.

Example 739. A simple example of the GEN08 routine.

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 gen08.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

    ; Initialize the global variables.
    sr = 44100
    kr = 4410
    ksmps = 10
    nchnls = 1

    ; Instrument #1.
    instr 1
      ; Create an index over the length of our entire note.
      kcps init 1/p3
      kndx phasor kcps

      ; Read Table #1 with our index.
      ifn = 1
      ixmode = 1
      kval table kndx, ifn, ixmode

      ; Generate a sine waveform, use our Table #1 value to
      ; vary its frequency by 100 Hz from its base frequency.
      ibasefreq = 440
      kfreq = kval * 100
      a1 oscil 20000, ibasefreq + kfreq, 2
      out a1
    endin

    </CsInstruments>
    <CsScore>

    ; Table #1: a curve with a smooth hump (using GEN08).
    f 1 0 65 8 0 16 0 16 1 16 0 16 0
    ; Table #2, a sine wave.
    f 2 0 16384 10 1

    ; Play Instrument #1 for two seconds.
    i 1 0 2
    e

    </CsScore>
    </CsoundSynthesizer>

## See Also

GEN05, GEN06, and GEN07

Prev | Up | Next
GEN07 | Home | GEN09