Skip to content

swtsynth

Resynthesises an SWT stream as audio.

Syntax

aout = swtsynth(wswt)
aout swtsynth wswt

Performance

wswt -- SWT stream produced by swtanal, swtset, or an equivalent source.

swtsynth uses the frame size, hop size, number of levels, wavelet, and synthesis mode stored in the stream. It reads the newest frame available at each k-cycle and reconstructs audio from the flat coefficient vector [cA_J | cD_J | ... | cD_1].

Output for frame m starts at sample m * H + N, where H is the analysis hop and N is the frame size. The first N samples are therefore the analysis latency. Samples before the note starts or after it ends within a control block are zero.

When the analysis used direct mode (H == N and no window), synthesis applies the inverse transform without windowing. When it used overlap-add mode, synthesis applies the matching square-root Hann window and divides by the accumulated window power. This allows coefficient edits made with swtset to be heard while keeping overlap-add reconstruction continuous.

The stream must be initialised and its metadata must remain unchanged after swtsynth starts. An uninitialised frame or incompatible metadata is reported as an initialisation error.

Examples

Here is a simple analysis and resynthesis example. It uses the file swtanal.csd.

Example of the swtanal and swtsynth opcodes.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in
-odac    ;;;RT audio I/O
; For non-realtime output leave only the line below:
; -o swtanal.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 32
nchnls = 1
0dbfs = 1

instr 1
  iN = 512
  iH = 128
  iFamily = 1          ; Daubechies
  iOrder = 4
  iLevels = 4
  iBoundary = 0        ; periodic
  iWindow = 1          ; square-root Hann
  iOla = 2             ; overlap-add

  aInput = 0.2 * oscili(1, 440) + 0.05
  wIn:swt swtanal aInput, iN, iH, iFamily, iOrder, iLevels, iBoundary, iWindow, iOla
  aOut = swtsynth(wIn)
  out aOut
endin

</CsInstruments>
<CsScore>
i 1 0 3
e
</CsScore>
</CsoundSynthesizer>

See also