Skip to content

pvstrace

Process a PV stream by retaining only the N bins with the highest amplitude, zeroing the others.

Syntax

fsig = pvstrace(fsigin, kn)
fsig, kBins[] = pvstrace(fsigin, kn [, isort, imin, imax])
fsig pvstrace fsigin, kn
fsig, kBins[] pvstrace fsigin, kn [, isort, imin, imax]

Initialization

isort -- if nonzero, list the selected bins in decreasing amplitude order. Otherwise, list them in increasing bin-number order. Default: 0.

imin, imax -- search range in bin numbers, including imin and excluding imax. Bin numbers start at 0. An imax of 0 includes all bins from imin through Nyquist. Both default to 0, which searches the whole frame.

Csound discards fractional parts and limits values beyond the frame to its end. Negative limits cause an initialization error. If the resulting range is empty or reversed, the output is silent and the bin array contains zeros. For example, limits of 2 and 6 search bins 2, 3, 4, and 5.

Performance

fsig -- output PV stream. Selected bins retain their input amplitude and frequency or phase; all other bins are zero.

kBins[] -- array of fftsize/2 + 1 values. The first values list the selected bin numbers; the remaining values are zero. isort controls their order.

fsigin -- input PV stream in amplitude/frequency or amplitude/phase format. Sliding analyses are not supported.

kn -- number of bins to retain from the search range. Csound discards the fractional part, treats values below 1 as 1, and limits the count to the number of bins in the range.

When amplitudes tie, lower bin numbers take priority. Sorting the bin list does not change which bins the output retains.

⚠ Warning

It is unsafe to use the same f-variable for both input and output of pvs opcodes. Using the same one might lead to undefined behavior on some opcodes. Use a different one on the left and right sides of the opcode.

Examples

Here is an example of the use of the pvstrace opcode. It uses the file pvstrace.csd.

Example of the _pvstrace_ opcode.
<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
-odac  ;;;realtime audio out
;-iadc    ;;;uncomment -iadc if realtime audio input is needed too
; For Non-realtime ouput leave only the line below:
; -o pvstrace.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>

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

instr 1

kn = p4
asig  diskin2   "drumsMlp.wav", 1
fsig  pvsanal   asig, 1024, 256, 1024, 1; analyse it
ftps  pvstrace   fsig, kn               ; keep kn bins
atps  pvsynth   ftps                    ; synthesise it
      outs      atps, atps

endin
</CsInstruments>
<CsScore>

i1 0 2  5
i1 + 2  10
i1 + 2  20
i1 + 2  40
i1 + 2  80
i1 + 2  160
e
</CsScore>
</CsoundSynthesizer>

See also

Tools for Real-time Spectral Processing (pvs opcodes)

Credits

Author: Victor Lazzarini
2017

New plugin in version 6.09