Skip to content

scale2

Arbitrary signal scaling with optional smoothing.

Maps an input range to an output range, with optional smoothing.

Syntax

kscl = scale2(kinput, kmin, kmax [, kimin, kimax, ihtime])
kscl scale2 kinput, kmin, kmax [, kimin, kimax, ihtime]

Initialization

ihtime -- smoothing half-time in seconds. For a constant mapped value, this is the time needed to halve the remaining difference between the output and that value. Zero disables smoothing (the default). Negative values are not allowed.

Performance

kinput -- input value. Values below kimin or above kimax are clamped to those bounds before scaling.

kmin -- output value corresponding to kimin.

kmax -- output value corresponding to kimax. The output range may run in either direction.

kimin -- Optional; Minimum of the incoming value range, defaulting to zero.

kimax -- Optional; Maximum of the incoming value range, defaulting to one. It must be greater than kimin.

Smoothing starts from zero each time the opcode initializes. The output can therefore start outside the output range while it moves toward the mapped value. With smoothing disabled, the output is the mapped value immediately.

⚠ Warning

The argument order is minimum before maximum, which differs from scale.

Examples

Here is an example of the scale2 opcode. It uses the file scale2.csd.

Example of the scale2 opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in    Silent
-odac           -iadc     -d    ;;;realtime output
</CsOptions>
<CsInstruments>

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

/*--- ---*/

        instr   1       ; scale test

kmod    ctrl7   1, 1, 0, 1
        printk2 kmod

kout    scale2  kmod, -127, 0
        printk2 kout

        endin

/*--- ---*/
</CsInstruments>
<CsScore>

i1      0       8888

e
</CsScore>
</CsoundSynthesizer>

See also

Linear and Exponential Generators

Credits

Author: John ffitch after David Akbari
December
2020