Skip to content

swtget

Reads one coefficient band from an SWT stream into a k-rate vector.

Syntax

kcoeffs:k[] = swtget(wswt, iband)
kcoeffs:k[] swtget wswt, iband

Initialization

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

iband -- band selector. The default, -1, selects the whole flat coefficient vector. 0 selects the approximation band cA_J. Values from 1 to the number of levels select detail bands cD_J to cD_1, in coarsest-to-finest order. Values greater than the number of levels are invalid.

A single band returns a vector of N coefficients, where N is the analysis frame size. Selector -1 returns all (levels + 1) * N coefficients in the layout [cA_J | cD_J | ... | cD_1].

Performance

swtget copies the current frame's selected coefficients to the output vector on each k-cycle. It does not consume frames and does not change the stream's frame count or revision.

If no new frame has been produced since the previous k-cycle, the same coefficients are copied again. Coefficient values are the values stored at analysis time, including any edits made by swtset.

Examples

Here is an example that reads the whole coefficient vector. It uses the file swtset.csd.

Example of the swtget and swtset 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 swtset.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr 1
  iN = 512
  iFamily = 1          ; Daubechies
  iOrder = 4
  iLevels = 4

  aInput = 0.2 * oscili(1, 220) + 0.05 * oscili(1, 1800)
  wIn:swt swtanal aInput, iN, iN, iFamily, iOrder, iLevels, 0, 0, 1

  kApprox:k[] swtget wIn, 0              ; read the approximation band
  kZeros:k[] init 512
  wDetails:swt swtset wIn, kZeros, 0     ; remove it from a copy

  aOut = swtsynth(wDetails)
  out aOut
endin

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

See also