Sample-and-Hold Processor — v1.4 User Guide

Interval-based amplitude processing with six control modes: alternating gate, intensity gate, sampled AM, pitch gate, numeric pattern gate, and power-linked spectral-centroid gate. Each interval produces one held control value; an optional transition stage then shapes changes between intervals.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 1.4 (2026) License: MIT License Repo: Praat AudioTools
Contents:

What this does

Sample-and-Hold Processor v1.4 divides the selected Sound into consecutive intervals of Sample_period_s. For every interval it computes one control value. That value is held for the interval, mapped to gain, optionally smoothed at interval boundaries, and then multiplied into the original Sound.

Core sample-and-hold structure

interval i: t0 = sourceStart + i * Sample_period_s t1 = min(t0 + Sample_period_s, sourceEnd) control[i] = mode-specific measurement or pattern value non-AM modes: gain[i] = 1 if control[i] >= Gate_threshold = Mute_level otherwise AM mode: gain[i] = sampled AM value directly held gain → optional smoothing → output = input × gain(t)

The processor is offline: it analyses and modifies an existing Praat Sound. It is not a hardware sample-and-hold model and it does not hold audio sample values. What is held is the control/gain value assigned to each time interval.

Absolute Sound time is preserved. All analysis intervals, the gain envelope, AM phase origin, and visualization use the Sound's own xmin/xmax. A Sound beginning at 5 s is processed correctly in that time domain rather than being silently treated as if it began at 0.

The output is a copy of the input Sound, so duration, sampling frequency, channel count, and Sound time domain are preserved. The final object is named <source>_SH.

Quick start

  1. Select exactly one Sound in Praat.
  2. Run Sample-and-Hold_Processor.praat.
  3. Choose a preset, or leave Custom and select one of the six Control_mode options.
  4. Set Sample_period_s. This is the control update period, not an audio resampling rate.
  5. For gating modes, adjust Gate_threshold and Mute_level. For AM, set frequency and depth.
  6. Choose Crossfade ramp for explicit transition length, or Low-pass for the legacy zero-phase smoothing behavior.
  7. Leave Peak_normalize_output off when absolute gain relationships matter.
  8. Run the script. The output is created as <source>_SH; visualization and playback follow their switches.
Useful starting points: Rhythmic Chop for regular chopping, Dynamics Gate for median-based level gating, Tremolo/Flutter for sampled AM, Voiced Only for pitch-based selection, Bright Only for spectral-centroid selection, and Morse Code for a repeating numeric pattern.

Presets

The seven named presets override only the working control mode and the mode-specific values shown below. They do not override Gate_threshold, Mute_level, smoothing mode/time, peak normalization, visualization, or playback.

PresetModePeriodAdditional values
Rhythmic Chop (binary)Binary50 msAlternating 1 / 0 control
Dynamics Gate (intensity)Intensity20 msIntensity threshold = 0 → automatic median
Tremolo (AM slow)Amplitude Modulation10 ms4 Hz, depth 0.8
Flutter (AM fast)Amplitude Modulation5 ms12 Hz, depth 1.0
Voiced Only (pitch-gate)Pitch Gate20 msPitch threshold 80 Hz
Bright Only (centroid)Spectral Centroid30 msCentroid threshold 2000 Hz
Morse Code (pattern)Custom Pattern100 ms1 1 1 0 1 0 1 0 0

Control modes

1. Binary (alternating)

Control values alternate 1, 0, 1, 0.... They are then compared with Gate_threshold. With the default threshold 0.5, even-numbered intervals pass and odd-numbered intervals use Mute_level.

2. Intensity-based

Each interval is extracted with a rectangular window and queried with Praat Get intensity (dB). This is Praat's acoustic intensity scale relative to 20 µPa; it is not dBFS. An interval passes when:

interval_intensity_dB >= Intensity_threshold_dB

Setting Intensity_threshold_dB = 0 activates automatic thresholding. The script measures every interval, sorts the values, and uses the true median: the middle value for an odd number of intervals or the mean of the two middle values for an even number. Undefined interval intensity is treated as −100 dB.

Constant-level material: because the comparison is >=, intervals exactly equal to the median pass rather than being gated shut.

3. Amplitude Modulation

The AM controller is sampled once at the start of each hold interval. It is therefore a sampled-and-held modulation curve, not a continuously evaluated sine tremolo.

phase[i] = 2π * AM_frequency_Hz * (i * Sample_period_s) sine[i] = (sin(phase[i]) + 1) / 2 control[i] = 1 - AM_depth * (1 - sine[i]) gain[i] = control[i]

The phase is relative to the beginning of the Sound, so changing xmin does not change the modulation's starting phase. Mute_level and Gate_threshold are not used for AM. The script enforces the control-rate Nyquist condition AM_frequency_Hz ≤ 1 / (2 × Sample_period_s).

4. Pitch-gated

The full Sound is analysed once with Praat To Pitch. Each interval queries the Pitch object at its midpoint. A voiced value passes only when:

pitch is defined AND pitch > Pitch_threshold_Hz

The normal floor is 75 Hz, but short Sounds require a higher floor. v1.4 derives an effective floor from file duration using approximately 3.2 / duration, with a 600 Hz ceiling. If the file is too short for any usable floor below the ceiling, the script stops with an explicit message. If the chosen threshold is below the forced analysis floor, the gate effectively becomes voiced/unvoiced detection.

5. Custom Pattern

Pattern is a whitespace-separated numeric sequence that repeats cyclically. Each value is compared with Gate_threshold. Typical values are 0 and 1, but v1.4 intentionally accepts any numeric values: values below the threshold mute, and values at or above it pass. Non-numeric tokens are rejected.

pattern index = (interval index mod pattern length) + 1 control = Pattern[index] gain = 1 if control >= Gate_threshold = Mute_level otherwise

6. Spectral Centroid Gate

Each interval is extracted with a Hann window before spectral analysis. For mono material, the interval is converted directly to a Spectrum. For multichannel material, each channel is transformed separately and the per-bin powers are summed; the channels are not arithmetically downmixed, avoiding cancellation of anti-phase content.

The script then queries Get centre of gravity: 2, i.e. a power-weighted spectral centroid. The interval passes when the centroid is defined and strictly above Centroid_threshold_Hz.

Held gain and transition smoothing

After all interval decisions are made, v1.4 builds a mono gain Sound at the audio sample rate over exactly the input Sound's time domain. The same gain curve is applied to every channel, so multichannel relationships are preserved while the control is channel-linked.

Crossfade ramp (default)

Whenever two adjacent intervals have different held gains, the step is replaced by a raised-cosine transition centred on the interval boundary. Smoothing_ms is the requested total transition length.

g(x) = g0 + (g1 - g0) * [0.5 - 0.5 cos(πu)] where u runs from 0 to 1 across the transition window

The requested smoothing length is capped at one sample period so neighbouring transitions cannot overwrite one another. At file edges, a transition may be shortened because there is not enough audio on both sides; the script counts and reports such cases.

Low-pass (legacy time constant)

This retains the v1.1 behavior: the held gain Sound is filtered with a zero-phase Hann low-pass. The cutoff is:

cutoff = 1000 / (2π * Smoothing_ms) Hz

Here Smoothing_ms is a time constant, not an exact ramp duration. The visible/audible transition is roughly wider than that value and, because the filter is zero-phase, extends before as well as after the nominal boundary. Filter overshoot is clamped back into the original gain range.

Parameters

ParameterDefaultBehavior
PresetCustomCustom or one of seven named recipes.
Control_modeBinaryBinary, Intensity, AM, Pitch Gate, Custom Pattern, or Spectral Centroid.
Sample_period_s0.02 sControl update/hold interval. Must be at least one audio sample. Maximum interval count is 200,000.
Gate_threshold0.50…1. Used to convert Binary/Pattern and already-binary analysis results to open/closed gain. Not used by AM.
Intensity_threshold_dB0Intensity gate threshold on Praat's dB intensity scale. Exactly 0 selects automatic median thresholding.
AM_frequency_Hz4 HzFrequency of the sampled sine controller. Must not exceed half the control update rate.
AM_depth1.00…1. At depth 1, sampled gain spans approximately 0…1; at depth 0, gain is always 1.
Pitch_threshold_Hz100 HzPitch values strictly above this threshold pass; undefined pitch is muted.
Centroid_threshold_Hz1000 HzPower-weighted spectral centroid must be strictly above this value to pass.
Pattern1 0 1 1 0 1 0 1Repeating numeric sequence for Custom Pattern.
Mute_level0.00…1 gain used by closed intervals in every non-AM mode. 0 = silence; 1 = no attenuation.
Smoothing_modeCrossfade rampExact-length raised-cosine transition or legacy zero-phase low-pass time constant.
Smoothing_ms2 msRamp length in Crossfade mode; time constant in Low-pass mode. Capped at one sample period.
Peak_normalize_outputOffIf enabled and output is non-silent, peak-normalizes the final Sound to 0.95.
VisualizeOnDraws Input, total applied gain, Output, and summary.
PlayOnPlays the completed result.

Output, normalization, and reproducibility

The result is a direct copy of the selected Sound before gain processing, so channel count, sampling frequency, duration, and original Sound time coordinates are retained. The output is named <source>_SH.

Peak normalization

Peak_normalize_output is Off by default. If enabled, any non-silent result is scaled so its absolute peak becomes 0.95. This is unconditional peak normalization: it can attenuate a hot output or amplify a quiet one.

Normalization changes the absolute effect depth. If a gate has reduced most material to Mute_level = 0.1, or AM has deliberately lowered the whole file, peak-normalizing afterward may raise the complete result again. Leave normalization off when absolute gain or attenuation is part of the intended result.

Determinism

The processor contains no random generator. Given the same Sound, parameters, and Praat analysis behavior, the processing itself is deterministic.

Visualization

When Visualize = On, v1.4 draws a suite-style diagnostic page with four areas:

Amplitude-scale note: Input and Output waveforms are drawn with Praat autoscaling; they are diagnostic waveform panels, not a shared-scale before/after level comparison. Use the reported peaks and the Applied gain panel when absolute level change matters.

Limits and interpretation