Skip to main content

sah

sah(
@trigger 0
@duration 0
@thresh 0.5
@triggermode 0
) -> llll

Generates an audio process operation for applying sample-and-hold to a buffer. Use sah to capture (i.e., sample) and output (i.e., hold) a value from an input signal whenever a trigger signal satisfies a threshold value according to one of several trigger conditions. The default trigger mode (Ascending) requires the signal to go from being at or below the threshold value to above it. At the moment the trigger condition is satisfied, the input signal is sampled and held until the trigger condition is satisfied again, at which point the input is sampled again. Generally this allows one signal to be synchronized to the behavior of another.


Arguments

  • @trigger [int/float/llll]: Sample-and-hold trigger, either as a single number, envelope, or buffer. (default: 0).
  • @duration [int]: Duration in samples. Normally the signal output of sah remains constant. With a non-zero value for duration any new non-zero value will remain constant for a specified number samples, after which it will be 0. (default: 0).
  • @thresh [int/float]: Value of the trigger signal used to cause the input signal to be sampled and output. (default: 0.5).
  • @triggermode [int/float]: (default: 0).
    • 0: Ascending. Detects the trigger signal passing from below to above the threshold value. Useful with increasing ramps (such as phasor with a positive frequency).
    • 1: Descending. Detects trigger signal passing from above to below the threshold value. Useful with decreating ramps (such as phasor with a negative frequency).
    • 2: Ascending or descending. Detects trigger signal passing from below to above the threshold value or passing from above to below the threshold value. This mode may produce unexpected results with a phasor but might be more appropriate for a continuous trigger input such as a sine wave.
    • 3: Equals. Detects an exact value in the trigger signal value. This mode is not recommended for continuous functions that may never reach a specific value, but could be useful to detect impulses or other signals where a specific value is expected.
    • 4: Zero to non-zero. Detects a trigger signal that goes from a zero value to a non-zero value. This could be useful to detect the start of a ramp or incoming audio. The value of @thresh is ignored in this mode.
    • 5: Non-zero to zero. Detects a trigger signal that goes from a non-zero value to a zero value. This could be useful to detect a signal turning off. The value of @thresh is ignored in this mode.
    • 6: Phase. Phase mode treats the threshold value as a phase value using a phase detection algorithm. In Phase mode, sah detects resets in the output of the phasor function and defines those as triggers for a threshold value of 0. Phase mode works with both positive and negative phasor frequencies.

Output

Sample-and-hold operation [llll]


Usage

sah is meant to be used with the process function:

$buffer = phasor(11 @duration 1000); ## input buffer
$op = sah(phasor(8 @duration 1000)); ## processing operation
$buffer = $buffer.process($op); ## apply processing
$buffer.view('after sah process')