| User-Defined Opcode Database |
|---|
Calcucaltes a Y value from a given X and 2 pairs of X/Y points, at init-time
Download UDO FilePerforms a simple linear equation at init-time. The x-range is given by two points x1 and x2; the y-range by y1 and y2. The function returns the y value for a given x.
See the example below for a practical application (instr 1).
iy Y_x4p_i ix, ix1, ix2, iy1, iy2
ix1, iy1 - two points related to each other
ix2, iy2 - two other points related to each other
ix - another x value
iy - y value related to ix
opcode Y_x4p_i, i, iiiii
ix, ix1, ix2, iy1, iy2 xin
imm = (iy2-iy1) / (ix2-ix1)
inn = iy1 - imm*ix1
iy = imm*ix + inn
xout iy
endop
<CsoundSynthesizer>
<CsOptions>
-m0 -n
</CsOptions>
<CsInstruments>
opcode Y_x4p_i, i, iiiii
;calculates y from two given points in x dimension, two in y dimension, and an x input, at i-rate
ix, ix1, ix2, iy1, iy2 xin
imm = (iy2-iy1) / (ix2-ix1)
inn = iy1 - imm*ix1
iy = imm*ix + inn
xout iy
endop
opcode Y_x4p_k, k, kkkkk
;calculates y from two given points in x dimension, two in y dimension, and an x input, at i-rate
kx, kx1, kx2, ky1, ky2 xin
kmm = (ky2-ky1) / (kx2-kx1)
knn = ky1 - kmm*kx1
ky = kmm*kx + knn
xout ky
endop
instr 1
;having a db input range from -20 to -40 ...
idblow = -40
idbhigh = -20
;... and a related transposition range from 100 to 500 cents
ictlow = 100
icthigh = 500
;which is the transposition for an input of -35 db?
idb = -35
icnt Y_x4p_i idb, idblow, idbhigh, ictlow, icthigh
prints "i-rate:%n"
prints "Input = %f dB -> Transposition = %f Cents.%n", idb, icnt
endin
instr 2
;having a db input range from -20 to -40 ...
idblow = -40
idbhigh = -20
;... and a related transposition range from 100 to 500 cents
ictlow = 100
icthigh = 500
;calculate a moving transposition for a live input
kdb random -40, -20
kcnt Y_x4p_k kdb, idblow, idbhigh, ictlow, icthigh
prints "k-rate:%n"
printks "Input = %f dB -> Transposition = %f Cents.%n", 1, kdb, kcnt
endin
</CsInstruments>
<CsScore>
i 1 0 0
i 2 0 5
</CsScore>
</CsoundSynthesizer>
joachim heintz 2011
| Previous | Home | Next |
| vowgen | Y_x4p_k |