swtaddsyn
Resynthesises an SWT stream using per-subband additive oscillators.
Syntax
Performance
wswt -- SWT stream produced by swtanal, swtset, or an equivalent source.
kratio -- frequency multiplier for each subband. 1 leaves the estimated frequencies unchanged; 2 raises them by an octave.
kstretch -- frequency stretch across subbands. Band b is scaled by kratio * kstretch^b, where b = 0 is the approximation band and larger indices approach the finest detail band. 1 gives no stretch. Negative values are treated as their absolute value.
kshift -- frequency shift in Hz added to every subband after kratio and kstretch have been applied. It may be positive or negative.
kthresh -- amplitude gate for frequency estimation. When a subband's instantaneous amplitude is below this value, its frequency estimate is held instead of being updated, reducing phase-noise artifacts during near-silent intervals. A subband that starts below this threshold stays silent until it first exceeds it. Negative values are treated as their absolute value.
kslew -- frequency smoothing coefficient in the range 0 to 1. 1 follows the instantaneous frequency immediately; 0 holds the current estimate. Values outside the range are clamped.
swtaddsyn does not perform an inverse SWT. For every audio sample it takes the current coefficient of each subband and passes it through a dual allpass Hilbert network to obtain a quadrature pair. It derives amplitude and instantaneous phase from that pair, unwraps the phase difference to estimate frequency, gates and smooths the estimate, applies the three frequency controls, and accumulates amplitude * cos(phase) into the output. The oscillator frequency is clamped to just under Nyquist (±0.49 * sr).
Frames are consumed in publication order from the SWT history at their scheduled sample positions. Each frame supplies hopsize samples; when a control block covers several published frames, none are skipped or replayed, and a frame spanning multiple control blocks continues from the same sample index. If no frame is available, the output is zero.
The stream must be initialised before use, and its frame size, hop size, and level count must remain unchanged while swtaddsyn is running. A stream restart with the same layout resets the filter and oscillator state and consumes frames already published by the restarted stream; a layout change or history overrun is reported as a performance error. Only direct mode (H == N, no window) is supported; an overlap-add stream is rejected at initialisation. Samples before the note starts or after it ends within a control block are zero.
Examples
Here is an example of the swtaddsyn opcode. It uses the file swtaddsyn.csd.