GEN17

GEN17 — Creates a step function from given x-y pairs.

Description

This subroutine creates a step function from given x-y pairs.

Syntax

f # time size 17 x1 a x2 b x3 c  ...

Initialization

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

x1, x2, x3, etc. -- x-ordinate values, in ascending order, 0 first.

a, b, c, etc. -- y-values at those x-ordinates, held until the next x-ordinate.

[Note] Note

This subroutine creates a step function of x-y pairs whose y-values are held to the right. The right-most y-value is then held to the end of the table. The function is useful for mapping one set of data values onto another, such as MIDI note numbers onto sampled sound ftable numbers ( see loscil).

Examples

f  1  0  128  -17   0  1   12  2   24  3   36  4   48  5  60  6   72  7   84  8

This describes a step function with 8 successively increasing levels, each 12 locations wide except the last which extends its value to the end of the table. Rescaling is inhibited. Indexing into this table with a MIDI note-number would retrieve a different value every octave up to the eighth, above which the value returned would remain the same.

Here is a complete example of the GEN17 routine. It uses the files gen17.csd.

Example 1317. An example of the GEN17 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 gen17.wav -W ;;; for file output any platform
; By Stefano Cucchi & Menno Knevel - 2021
</CsOptions>
<CsInstruments>

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

instr 1 
gisqre ftgen 2, 0, 16384, 10, 1, 0 , .33, 0, .2 , 0, .14, 0 , .11, 0, .09 ;odd harmonics

knoteleft oscil 1, 0.5, 10       ; index to table 10 - gen 17 - every 2 seconds reads all the values in the table n. 10
printks2 "note left  = %d\n", knoteleft
knoteright oscil 1, 1, 10        ; index to table 10 - gen 17 - every  second reads all the values in the table n. 10
printks2 "note right = %d\n", knoteright

ixmode =    1
ixoff =     0
iwrap =     1
aphasor1 phasor knoteleft        ; the values in table 10 become the frequency of the oscillator
asig1 tablei aphasor1, gisqre, ixmode, ixoff, iwrap ; oscillator generating sound in the left channel (table 10 every 2 seconds)
aphasor2 phasor knoteright       ; the values in table 10 become the frequency of the oscillator
asig2 tablei aphasor2, gisqre, ixmode, ixoff, iwrap ; oscillator generating sound in the right channel (table 10 every second)
kgenenv linseg 0, 0.3, 0.4, p3-0.6, 0.4, 0.3, 0     ; envelope
         outs asig1 * kgenenv, asig2 * kgenenv
endin

</CsInstruments>
<CsScore>
; table with gen17 - At point 0 pitch 300 Hz, at point 12 pitch 350 Hz, etc...
f  10  0  128  -17   0  300   12  350   20  400   41  434   48  563  67  589   72  632   79  678  100 712 120 789

i1 0 10 
e
</CsScore>
</CsoundSynthesizer>


See Also

GEN02