linen
Applies a straight line rise and decay pattern to an input amp signal.
Syntax
Initialization
irise -- rise time in seconds. A zero or negative value signifies no rise modification.
idur -- overall duration in seconds. A zero or negative value will cause initialization to be skipped.
idec -- decay time in seconds. Zero disables decay during idur, but the output still falls if the instrument continues beyond that time. An idec > idur will cause a truncated decay. See the compatibility notes below.
Performance
kamp, xamp -- input amplitude signal.
Rise modifications are applied for the first irise seconds, and decay from time idur - idec. If these periods are separated in time there will be a steady state during which amp will be unmodified. If linen rise and decay periods overlap then both modifications will be in effect for that time. If the overall duration idur is exceeded in performance, the final decay will continue on in the same direction, going negative.
Compatibility notes
linen can still have a nonzero envelope value at idur. Its decay calculation includes an extra half sample or control cycle in the divisor. For example, a decay lasting four control cycles, with no rise and an input of 1, leaves about 0.111111 at idur. The audio-rate form has the same result for a four-sample decay. Longer decays leave a smaller residual in this case.
Csound preserves this historical behavior for compatibility with existing scores. Fractional durations can also shift the decay start because the start count and the slope use different rounding.
linen does not hold zero after idur. With a positive decay, it keeps falling and eventually becomes negative. With zero decay, it keeps the decay factor at 1 through idur, then reduces it by 1 on each following sample or control cycle. Do not use zero decay to hold a constant level beyond idur.
Alternative with a zero endpoint
Use linseg when the envelope must reach zero and stay there. This example gives a 0.01-second rise, a 0.39-second sustain and a 0.1-second decay. Multiply it by the signal you want to shape.
linseg holds its last value after the segments finish. Segment times still follow the sample or control-cycle grid. Use positive segment durations. This example does not reproduce linen's overlapping rise and decay behavior.
For a release that starts at note-off, consider linsegr.
Examples
Here is an example of the linen opcode. It uses the file linen.csd.
Compare the decay endpoint
This example uses ten control cycles per second and a four-cycle decay. At step 4, linen prints about 0.111111 while linseg prints 0. Later, linen becomes negative while linseg stays at 0. The instrument deliberately lasts longer than the envelope so these values can be read.
It uses linen_endpoint.csd.