| User-Defined Opcode Database |
|---|
Scales an incoming a-signal from a certain range to another range.
Download UDO FileScales the incoming signal aval in the range between kinmin and kinmax linear to the range between koutmin and koutmax. It works exactly the same as the "scale" object in Max/MSP, but at audio-rate.
aout Scala aval, kinmin, kinmax, koutmin, koutmax
aval - incoming audio signal
kinim - minimum range of input value
kinmax - maximum range of input value
koutmin - minimum range of output value
koutmax - maximum range of output value
opcode Scala, a, akkkk aval, kinmin, kinmax, koutmin, koutmax xin ares = (((koutmax - koutmin) / (kinmax - kinmin)) * (aval - kinmin)) + koutmin xout ares endop
<CsoundSynthesizer>
<CsOptions>
-n
</CsOptions>
<CsInstruments>
opcode Scali, i, iiiii
;scales the incoming value ival in the range between iinmin and iinmax linear to the range between ioutmin and ioutmax
ival, iinmin, iinmax, ioutmin, ioutmax xin
ires = (((ioutmax - ioutmin) / (iinmax - iinmin)) * (ival - iinmin)) + ioutmin
xout ires
endop
opcode Scalk, k, kkkkk
;scales the incoming value kval in the range between kinmin and kinmax linear to the range between koutmin and koutmax
kval, kinmin, kinmax, koutmin, koutmax xin
kres = (((koutmax - koutmin) / (kinmax - kinmin)) * (kval - kinmin)) + koutmin
xout kres
endop
opcode Scala, a, akkkk
;scales the incoming value aval in the range between ainmin and ainmax linear to the range between aoutmin and aoutmax
aval, kinmin, kinmax, koutmin, koutmax xin
ares = (((koutmax - koutmin) / (kinmax - kinmin)) * (aval - kinmin)) + koutmin
xout ares
endop
instr 1 ;scales i-rate values from 0/100 to -1/1
icount = 0
loop:
iin random 0, 100
iout Scali iin, 0, 100, -1, 1
prints "in = %f, out = %f\n", iin, iout
loop_lt icount, 1, 5, loop
endin
instr 2 ;scales k-rate values from 0/1 to 0/127
kin random 0, 1
kout Scalk kin, 0, 1, 0, 127
printks "in = %f, out = %f\n", .1, kin, kout
endin
instr 3 ;scales a-rate values from -100/-10 to -1/1
ktrig metro 10
ain random -100, -10
kmaxin max_k ain, ktrig, 2
kminin max_k ain, ktrig, 3
aout Scala ain, -100, -10, -1, 1
kmaxout max_k aout, ktrig, 2
kminout max_k aout, ktrig, 3
printks "minin = %f, minout = %f, maxin = %f, maxout = %f\n", .1, kminin, kminout, kmaxin, kmaxout
endin
</CsInstruments>
<CsScore>
i 1 0 0
i 2 0 1
i 3 1 1
</CsScore>
</CsoundSynthesizer>
joachim heintz sept 2010
| Previous | Home | Next |
| sampleSlicer | scale |