Math CHOP

From TouchDesigner 088 Wiki

MathCHOP 05.jpg MathCHOPIntermediate.jpg

Summary

The Math CHOP performs arithmetic operations on channels. The channels of a CHOP can be combined into one channel, and several CHOPs can be combined into one CHOP.

The OP page lets you pre-operate on each sample, like making all samples positive or taking the square of each sample.

Using Combine Channels, for an input CHOP with multi-channels, you can multiply the samples of one channel by the samples in the other channels, reducing N channels down to one. You can combine them by multiplying, adding, finding the maximum, etc..

Using Combine CHOPs, where there are two or more CHOP inputs, you can multiply (or add, etc.) the channels in one CHOP with the channels in all the other CHOPs, reducing N CHOPs to 1. (otherwise channels of multi-inputs are just merged)

You can then post-operate on the resulting samples - negate, square root, etc.

Then using the Mult-Add page it can offset and scale the values of each sample.

More conveniently you can use the Range page to do linear scaling as well by setting an output low-high range for a certain input low-high range.

Finally, you can round the resulting values off to an integer.

NOTE: To do logic operations (and, or, ...) between channels or CHOPs, use the Logic CHOP.

PythonIcon.png mathCHOP_Class

Parameters - OP Page

The four steps are performed in the following order:

Channel Pre OP - Unary operations can be performed on individual channels. A menu of unary operations (as described above) that are performed on each channel as it comes in to the Math CHOP include:

  • Off - Don't do anything to the channel.
  • Negate - Take the negative value of each sample of the channel.
  • Positive - Make negative values of the channel positive (absolute).
  • Root - Take the square root of all values in the channel.
  • Square - Square all the values in the channel.
  • Inverse - Take the inverse (1/x) of all values in the channel.

Combine Channels - A choice of operations is performed between the channels of an input CHOP, for each input. The Nth sample of one channel is combined with the Nth sample of other channels:

  • Off - Don't combine the channels.
  • Add - Sum all the channels.
  • Subtract - Subtract all the channels from the first.
  • Multiply - Take the product of all the channels.
  • Divide - Divide the first channel by all the rest.
  • Average - Take the average of all the channels.
  • Maximum - Take the maximum value of all the channels.
  • Minimum - Take the minimum value of all the channels.
  • Length - Assume the channels are a vector and compute its length.

Combine CHOPs - A menu of operations that is performed between the input CHOPs, combining several CHOPs into one.

  • Off - Don't combine the channels.
  • Add - Sum all the channels.
  • Subtract - Subtract all the channels from the first.
  • Multiply - Take the product of all the channels.
  • Divide - Divide the first channel by all the rest.
  • Average - Take the average of all the channels.
  • Maximum - Take the maximum value of all the channels.
  • Minimum - Take the minimum value of all the channels.
  • Length - Assume the channels are a vector and compute its length.

Channel Post OP - A menu (same as Channel Pre OP) is performed as the finale stage upon the channels resulting from the above operations.

Integer - The resulting values can be converted to integer. The ceil(), floor() and round() expressions do the same.

  • Off - Don't affect the value.
  • Ceiling - Round a value up to the next integer.
  • Floor - Round a value down to the next integer. (Remove the fractional part of the number.)
  • Round - Round a value to the nearest integer.

Match By - Match channels between inputs by name or number.

Align - How to align channels from different inputs. See Align Option.

Parameters - Mult-Add Page

The three steps are next performed in the following order:

Pre-Add /preoff - First, add the value to each sample of each channel.

Multiply /gain - Then multiply by this value.

Post-Add /postoff - Then add this value.

Parameters - Range Page

This is the final step prior to output.

From Range / To Range /fromrange[1-2] / torange[1-2] - Another way to multiply/add. Converts from one low-high range to another range.

How the Math CHOP determines its Output Frame Range

The Math CHOP now assures that the time interval of the output is not too long when their inputs' frame ranges are different. When one input is at frame 1 and another is time sliced, the Math CHOP previously output a constant-value CHOP that started at frame one and ended at the current frame.

Now if the inputs are constants, it outputs a small time sliced interval ending at the current frame. This is the new default Align Option called Auto. It will trim to the current Time Slice if there are any Time Slices, else it will do as before using Extend Min/Max.

Standard Options and Local Variables