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.
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
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.
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
- Select exactly one Sound in Praat.
- Run
Sample-and-Hold_Processor.praat. - Choose a preset, or leave Custom and select one of the six
Control_modeoptions. - Set
Sample_period_s. This is the control update period, not an audio resampling rate. - For gating modes, adjust
Gate_thresholdandMute_level. For AM, set frequency and depth. - Choose Crossfade ramp for explicit transition length, or Low-pass for the legacy zero-phase smoothing behavior.
- Leave
Peak_normalize_outputoff when absolute gain relationships matter. - Run the script. The output is created as
<source>_SH; visualization and playback follow their switches.
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.
| Preset | Mode | Period | Additional values |
|---|---|---|---|
| Rhythmic Chop (binary) | Binary | 50 ms | Alternating 1 / 0 control |
| Dynamics Gate (intensity) | Intensity | 20 ms | Intensity threshold = 0 → automatic median |
| Tremolo (AM slow) | Amplitude Modulation | 10 ms | 4 Hz, depth 0.8 |
| Flutter (AM fast) | Amplitude Modulation | 5 ms | 12 Hz, depth 1.0 |
| Voiced Only (pitch-gate) | Pitch Gate | 20 ms | Pitch threshold 80 Hz |
| Bright Only (centroid) | Spectral Centroid | 30 ms | Centroid threshold 2000 Hz |
| Morse Code (pattern) | Custom Pattern | 100 ms | 1 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:
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.
>=, 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.
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:
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.
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.
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:
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
| Parameter | Default | Behavior |
|---|---|---|
| Preset | Custom | Custom or one of seven named recipes. |
| Control_mode | Binary | Binary, Intensity, AM, Pitch Gate, Custom Pattern, or Spectral Centroid. |
| Sample_period_s | 0.02 s | Control update/hold interval. Must be at least one audio sample. Maximum interval count is 200,000. |
| Gate_threshold | 0.5 | 0…1. Used to convert Binary/Pattern and already-binary analysis results to open/closed gain. Not used by AM. |
| Intensity_threshold_dB | 0 | Intensity gate threshold on Praat's dB intensity scale. Exactly 0 selects automatic median thresholding. |
| AM_frequency_Hz | 4 Hz | Frequency of the sampled sine controller. Must not exceed half the control update rate. |
| AM_depth | 1.0 | 0…1. At depth 1, sampled gain spans approximately 0…1; at depth 0, gain is always 1. |
| Pitch_threshold_Hz | 100 Hz | Pitch values strictly above this threshold pass; undefined pitch is muted. |
| Centroid_threshold_Hz | 1000 Hz | Power-weighted spectral centroid must be strictly above this value to pass. |
| Pattern | 1 0 1 1 0 1 0 1 | Repeating numeric sequence for Custom Pattern. |
| Mute_level | 0.0 | 0…1 gain used by closed intervals in every non-AM mode. 0 = silence; 1 = no attenuation. |
| Smoothing_mode | Crossfade ramp | Exact-length raised-cosine transition or legacy zero-phase low-pass time constant. |
| Smoothing_ms | 2 ms | Ramp length in Crossfade mode; time constant in Low-pass mode. Capped at one sample period. |
| Peak_normalize_output | Off | If enabled and output is non-silent, peak-normalizes the final Sound to 0.95. |
| Visualize | On | Draws Input, total applied gain, Output, and summary. |
| Play | On | Plays 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.
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:
- Input — the original Sound waveform.
- Applied gain — the gain Sound that was actually multiplied into the audio, after
Mute_levelmapping and smoothing. If peak normalization is enabled, its constant normalization gain is folded into this plotted envelope as well. - Output — the processed waveform.
- Summary — preset/mode, relevant mode parameter, mute level, smoothing, sample period, channel count, output peak, and normalization state.
Limits and interpretation
- Control values, not audio samples, are held. The processor is a stepped/held gain controller applied to otherwise continuous audio.
- AM is sampled. A high AM frequency with a long hold period cannot represent the requested sine correctly; the script therefore enforces a Nyquist limit based on the control update rate.
- Intensity is not dBFS. Manual intensity thresholds use Praat's acoustic dB intensity convention.
- Pitch analysis is optimized for periodic material. Noisy/unvoiced intervals return undefined pitch and are gated shut; very short files force a higher pitch floor.
- Centroid uses interval spectra. Hann-windowing reduces leakage, and multichannel power is linked before the centroid is queried, but the value still depends strongly on interval length and source spectrum.
- Hard chopping can click without smoothing. The default crossfade ramp is designed to soften gain discontinuities while keeping their nominal locations.
- Very long jobs are bounded. More than 200,000 hold intervals are refused to avoid excessive scripted processing.
- A period longer than the Sound is legal. It produces one held interval and therefore no time-varying sample-and-hold pattern.