diff
Modify a signal by differentiation.
Syntax
Initialization
iskip (optional, default=0) -- zero clears the saved input at initialization. A non-zero value keeps the previous input.
Performance
diff subtracts the previous input from the current input. It does this once per audio sample or control cycle, and saves the current input for the next step. After a reset, the previous input is zero.
For a sine wave at frequency f, the amplitude gain is 2 * sin(pi * f / sr) at audio rate, or 2 * sin(pi * f / kr) at control rate. The approximation 2 * pi * f / sr applies only at frequencies much lower than sr; use kr for the control-rate form.
integ and diff reverse each other's operations in exact arithmetic. Rounding can prevent exact reconstruction of the input.
Examples
Here is an example of the diff opcode. It uses the file diff.csd.