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