Csound Csound-dev Csound-tekno Search About

[Csnd] PVSBIN question / issue

Date2022-05-29 21:21
FromRobert Gerard Pietrusko
Subject[Csnd] PVSBIN question / issue
Dear Community,

I'm having difficulty with a code snippet and am hoping to get your eyes on it. For every k-rate pass, I would like to scan a subset of bins within a *.pvx and grab the bin with the largest amplitude. The code shows how I was approaching this:


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

iBinS   =      p4    ; pvx bin to start scanning from
iBinE   =      p5    ; pvx bin to stop  scanning after
kbindx  =      iBinS ; bin indexer

kArgMax =          0 ; argmax, the bin number with max amp
kAMax   =       -9.0 ; ampMax, init with arbitrary impossible negative amp.
kFMax   =       00.0 ; frq of bin with max amp


;; PVX stuff
ifDurs  =       9
kIdx    phasor      1/ifDurs
fStest  pvsfread    kIdx*ifDurs, "test.pvx"


;; LOOP
scanBins: ; loop through bins in range iBinS - iBinE

ka,kf   pvsbin fStest, kbindx

if      ( ka > kAMax ) then ;;if ka is max, update max values
kAMax   =      ka
kFMax   =      kf
kArgMax =      kbindx
endif

loop_le  kbindx, 1, iBinE, scanBins ;; loop back to scanBins


printk  0.5,  kArgMax
printk  0.5,  kAMax
printk  0.5,  kFMax

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Seems simple enough. The code runs without error but I am not getting the expected results. No matter what values I use for iBinS (start bin) and iBinE (end bin), the result is always kArgMax == iBinS.

I initially thought the loop wasn't executing correctly. I placed a counter inside and it is stepping through all of the kbindx values as it should.

I think the issue is with my understanding of PVSBIN's k-rate operation.

http://www.csounds.com/manual/html/pvsbin.html

It appears to accept the first assignment of kbin, but then does not update when given other values. Does this only work across k-rate passes, and not within them?

Thanks for any help you can offer. I'd love to get this working.


Best regards
Bobby

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Date2022-05-29 22:33
From"Jeanette C."
SubjectRe: [Csnd] PVSBIN question / issue
Hi Robert,
I sympathise, I think this is a pitfall in which I stepped frequently. There
are a few solutions. The problem is: the loop runs over one k-cycle, it uses 
the same instance of pvsbins. I think this only runs once in the km-cycle and 
will only output one bin for one index. I think it's the first index.

Solutions:
You might use pvsftw in the main program, then step through the bin values 
using tab or some other table reading opcode.

Or you could try pvstrace, which "retains only the N loudest bins" of an 
f-rate signal:
fOutput [, kBins[]] pvstrace fInput, kN [, iSort, iMin, iMax]
I think iMin and iMax are equivalent to your iBinS and iBinE. The sorting 
option allows to sort reported bins in the k-rate array by decreasing 
amplitude. The arra output is optional, but might help you to do particular 
things to those bins.

HTH.

Best wishes,

Jeanette

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

With you I get so high
Lost in the crystal sky
You are this melody
That's where you take me <3
(Britney Spears)

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2022-05-30 07:24
Fromjoachim heintz
SubjectRe: [Csnd] PVSBIN question / issue
yes i think this is the way to go.  in addition to what jeanette 
suggests: there is an example in the csound floss manual which you can 
adapt for your needs: 03E07 in 
https://flossmanual.csound.com/csound-language/arrays#operations-on-arrays

best -
	joachim



On 29/05/2022 23:33, Jeanette C. wrote:
> Hi Robert,
> I sympathise, I think this is a pitfall in which I stepped frequently. 
> There
> are a few solutions. The problem is: the loop runs over one k-cycle, it 
> uses the same instance of pvsbins. I think this only runs once in the 
> km-cycle and will only output one bin for one index. I think it's the 
> first index.
> 
> Solutions:
> You might use pvsftw in the main program, then step through the bin 
> values using tab or some other table reading opcode.
> 
> Or you could try pvstrace, which "retains only the N loudest bins" of an 
> f-rate signal:
> fOutput [, kBins[]] pvstrace fInput, kN [, iSort, iMin, iMax]
> I think iMin and iMax are equivalent to your iBinS and iBinE. The 
> sorting option allows to sort reported bins in the k-rate array by 
> decreasing amplitude. The arra output is optional, but might help you to 
> do particular things to those bins.
> 
> HTH.
> 
> Best wishes,
> 
> Jeanette
> 

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here