GEN04
Prev | Score Statements and GEN Routines | Next

## GEN04

GEN04 — Generates a normalizing function.

## Description

This subroutine generates a normalizing function by examining the contents of an existing table.

## Syntax

    f  #  time  size  4  source#  sourcemode

## Initialization

size -- number of points in the table. Should be power-of-2 plus 1. Must not exceed (except by 1) the size of the source table being examined; limited to just half that size if the sourcemode is of type offset (see below).

source # -- table number of stored function to be examined.

sourcemode -- a coded value, specifying how the source table is to be scanned to obtain the normalizing function. Zero indicates that the source is to be scanned from left to right. Non-zero indicates that the source has a bipolar structure; scanning will begin at the mid-point and progress outwards, looking at pairs of points equidistant from the center.

| Note

- The normalizing function derives from the progressive absolute maxima of the source table being scanned. The new table is created left-to-right, with stored values equal to 1/(absolute maximum so far scanned). Stored values will thus begin with 1/(first value scanned), then get progressively smaller as new maxima are encountered. For a source table which is normalized (values <= 1), the derived values will range from 1/(first value scanned) down to 1. If the first value scanned is zero, that inverse will be set to 1.

- The normalizing function from GEN04 is not itself normalized.

- GEN04 is useful for scaling a table-derived signal so that it has a consistent peak amplitude. A particular application occurs in waveshaping when the carrier (or indexing) signal is less than full amplitude.

## Examples

Here is a simple example of the GEN04 routine. It uses the files gen04.csd.

Example 1040. An example of the GEN04 routine.

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

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

    gisine   ftgen 0, 0, 16384, 10, 1						;sine wave

    instr   1

    ihertz = cpspch(p4)
    ipkamp = p5
    iwsfn  = p6									;waveshaping function
    inmfn  = p7									;normalization function
    agate   linen   1, .01, p3, .1            					;overall amp envelope
    kctrl   linen  	.9, 2, p3, 2							;waveshaping index control
    aindex  poscil  kctrl/2, ihertz, gisine						;sine wave to be distorted
    asignal tablei  .5+aindex, iwsfn, 1						;waveshaping
    knormal tablei  1/kctrl, inmfn , 1						;amplitude normalization
            outs    asignal*knormal*ipkamp*agate, asignal*knormal*ipkamp*agate

    endin
    </CsInstruments>
    <CsScore>
    f1 0 64 21 6	;Gaussian (random) distribution
    f2 0 33 4 1 1	;normalizing function with midpoint bipolar offset

    s
    ;	st	dur	pch	amp   wsfn inmfn
    i1      0       4      6.00    .7      1     2
    i1      4       .      7.00    .
    i1      8       .      8.00    .
    ;-------------------------------------------------------------------------------------
    f3 0 1025 13 1 1 0 5 0 5 0 10	;Chebyshev algorithm
    f4 0 513 4 3 1			;normalizing function with midpoint bipolar offset
    s
    ;	st	dur	pch	amp   wsfn inmfn
    i1      0       4      6.00    .9      3     4
    i1      4       .      7.00    .
    i1      8       .      8.00    .
    e
    </CsScore>
    </CsoundSynthesizer>

These are the diagrams of the waveforms of the GEN04 routines, as used in the example:

f1 0 64 21 6 - Gaussian (random) distribution

f2 0 33 4 1 1 - AND its normalizing function with midpoint bipolar offset

f3 0 1025 13 1 1 0 5 0 5 0 10 - Chebyshev algorithm

f4 0 513 4 3 1 - AND its normalizing function with midpoint bipolar offset

Prev | Up | Next
GEN03 | Home | GEN05