Compare
Turn any signal into a gate or trigger by comparing it to a threshold or to another signal, lane by lane, with hysteresis and tolerance.
- Utility
- Since 0.2.0
- compare
- threshold
- gate
- trigger
- comparator
- utility
Compare turns a signal into 1 or 0 by comparing A with B, lane by lane. It works on audio and on control lanes.
What it does#
Operation chooses the test: Greater, Less, Greater or equal, Less or equal, Equal or Not equal. B is the threshold: either the signal on the B input or, when B is not connected, B when unconnected on every lane.
The ordering tests use hysteresis so a signal hovering at the threshold does not flicker: Greater switches on when A rises above B and off only when A falls below B minus Hysteresis. Equal treats A and B as equal when they are within Tolerance of each other.
Mode chooses the output. Gate stays at 1 while the test is true. Trigger is 1 only on each rising edge: for one sample when the output is audio, for one block when it is control. Each lane keeps its own state, so every channel or lane switches independently.
Rate and width follow the cables the same way as in Math: audio on A or B makes an audio output, otherwise the output is control.
When to use it#
Use it at control rate to turn a smooth control into an event: open an envelope when an LFO passes a level, step a Counter or fire a Sample and hold. At audio rate it is a comparator: a crude square shaper, or a gate that shows when a signal goes over a level.
Ports#
| Port | Direction | Signal | Lanes |
|---|---|---|---|
a | Input | Audio or control (follows the cable) | Inferred from the cable |
b | Input | Audio or control (follows the cable) | Inferred from the cable |
out | Output | Audio or control (follows the cable) | Inferred from the cable |
Parameters#
| Parameter | Label | Range | Default | Unit | Scale | Notes |
|---|---|---|---|---|---|---|
op | Operation | 0 to 5 | 0 | linear | How A is tested against B. The output is 1 while the test holds and 0 otherwise. Choices: 0 Greater, 1 Less, 2 Greater or equal, 3 Less or equal, 4 Equal, 5 Not equal. | |
b_default | B when unconnected | -8 to 8 | 0.5 | linear | Threshold used for every lane of B when nothing is connected to it. | |
hysteresis | Hysteresis | 0 to 1 | 0.05 | linear | How far A must cross back past B before an ordering test switches off again, so noisy signals do not chatter. Shown when op is 0 or 1 or 2 or 3. | |
epsilon | Tolerance | 0 to 1 | 0.001 | linear | Largest difference between A and B that still counts as equal. Shown when op is 4 or 5. | |
mode | Mode | 0 to 1 | 0 | linear | Gate stays at 1 while the test holds; Trigger is 1 for one block (control) or one sample (audio) on each rising edge. Choices: 0 Gate, 1 Trigger. |
Operation (op)#
The test, a discrete choice: Greater, Less, Greater or equal, Less or equal, Equal or Not equal.
B when unconnected (b_default)#
The threshold used on every lane when nothing is connected to B, from -8 to 8. Audio swings between -1 and 1 and control lanes usually between 0 and 1, so useful thresholds sit in those ranges. Changes are smoothed over 5 ms.
Hysteresis (hysteresis)#
For the ordering tests, how far A must move back past the threshold before the output switches off, from 0 to 1. Larger values ignore more noise but react later. Shown for Greater, Less, Greater or equal and Less or equal.
Tolerance (epsilon)#
For Equal and Not equal, how close A and B must be, from 0 to 1. A tolerance of 0 asks for exact equality, which continuous signals almost never reach.
Mode (mode)#
Gate or Trigger, a discrete choice. A trigger is short: one sample at audio rate, one block at control rate, so it needs a destination that reacts to rising edges.
Tips#
- To turn a threshold into a gate for an envelope, compare a control lane with Greater and connect the output to the envelope's Gate socket.
- Start with a Hysteresis of about 0.05 and raise it if the output chatters.
- A gate at audio rate is a 0 to 1 signal at full scale. Put a Gain after it before you listen.
- Compare an audio signal with a threshold near 1 to make a gate that is on while the signal clips.
See also#
Math, Counter, Sample and hold, Envelope, Control lanes.
Help patches
Each help patch is an ordinary Toy that teaches one idea. The diagram shows the Patch; the preview shows its Frame. Open it in TuneToys to play and edit it.
1. Gate from a wave
beginner Teaches: op, b_default, mode
A triangle wave compared with a threshold becomes an audible pulse wave.
Connections as text
- Oscillator audio output connected to Compare a input
- Compare out output connected to Gain audio input
- Gain audio output connected to Patch outputs audio input
- The wave is audio, so the gate is audio too: 1 while the wave is above Threshold, else 0.
- Move Threshold to change how long the gate stays on. You hear it as a changing pulse width.
- Trigger keeps only the rising edges: one sample of 1 per cycle, a thin click.
- Gain keeps the 0 to 1 gate quiet. A raw gate is full scale.
2. Hysteresis and triggers
intermediate Teaches: hysteresis, mode
A slow control wave crosses a threshold and plays an envelope on each crossing.
Connections as text
- Oscillator audio output connected to Envelope audio input
- Envelope audio output connected to Patch outputs audio input
- Control LFO control output connected to Compare a input
- Compare out output connected to Envelope @gate input
- The LFO is control, so Compare runs once per block and its output is a control lane.
- Gate holds the envelope open while the LFO is above 0.5; it closes only below 0.5 minus Hysteresis.
- Trigger sends one block of 1 on each rising edge: one short note per cycle.
Related nodes
- Math Arithmetic on any signal, lane by lane: add, multiply, divide, power and more on audio or control operands. The output runs at the rate of its fastest input.
- Counter Count rising edges of a trigger lane, with step, limit, wrap and reset. Lane 1 is the normalised count, lane 2 the raw count.
- Sample and hold Capture the input lanes whenever the trigger lane rises and hold them until the next trigger.