Skip to content

pvsbin

Read the amplitude and frequency of a PVS bin at control or audio rate.

Syntax

kamp, kfr = pvsbin(fsig, kbin)
aamp, afr = pvsbin(fsig, kbin)
kamp, kfr pvsbin fsig, kbin
aamp, afr pvsbin fsig, kbin

Performance

kamp, aamp -- bin amplitude at control or audio rate

kfr, afr -- bin frequency at control or audio rate

fsig -- an input pv stream

kbin -- bin number, counted from zero. Fractional values are truncated before selecting the amplitude/frequency pair. The value must be nonnegative and less than the number of bins (N/2 + 1 for an FFT size of N). Invalid values cause a performance error when the bin is selected.

For frame-based PVS streams, the opcode selects the bin only when a new frame arrives. A change to kbin between frame updates takes effect at the next frame. Both output forms hold the selected values between frames; audio output repeats those values over the active samples in each block.

For sliding PVS streams, audio output reads each active sample's spectrum. Control output reads the first active sample's spectrum. Audio samples outside the note's active range are zero.

Examples

Here is an example of the pvsbin opcode. It uses the file pvsbin.csd. This example uses realtime input, but you can also use it for soundfile input.

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

; by Richard Boulanger & Menno Knevel

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

instr 1

ifftsize = 1024
iwtype   = 1                                      
a1 diskin2 "fox.wav", 1
; to reduce artifacts, try a smaller hopsize, like ifftsize/8
; also using port on frequency and/or amplitude may smooth it if there spikes
fsig pvsanal a1, ifftsize, ifftsize/4, ifftsize, iwtype
kamp, kfr pvsbin fsig, p4

adm poscil3 kamp*4, kfr
outs adm, adm

endin

</CsInstruments>
<CsScore>
;           bin
i 1 0 2.7   15
i 1 3 .     35
i 1 6 .     65
i 1 9 .     95

i 1 13 2.7  15   ; chord
i 1 13 .    35
i 1 13 .    65
i 1 13 .    95
e
</CsScore>
</CsoundSynthesizer>

See also

Tools for Real-time Spectral Processing (pvs opcodes)

Credits

Author: Victor Lazzarini
August 2006