Csound Csound-dev Csound-tekno Search About

Re: Re: [Csnd] UDO to have the max a signal amplitude as k variable

Date2013-08-22 23:07
From"vallste@libero.it"
SubjectRe: Re: [Csnd] UDO to have the max a signal amplitude as k variable
I was not aware of it, obviously, thank you

>----Messaggio originale----
>Da: Victor.Lazzarini@nuim.ie
>Data: 23/08/2013 0.00
>A: 
>Ogg: Re: [Csnd] UDO to have the max a signal amplitude as k variable
>
>you could also use vaget and a k-rate loop.
>
>Victor
>On 22 Aug 2013, at 22:42, vallste@libero.it wrote:
>
>> Hello,
>> I'm developing this udo to have a krate variable indicating the maximum 
value reached by a a-rate signal during a k-cycle.
>> As far as I've understood downsamp opcode performs some averaging (please 
correct me if I'm wrong) so not using it since I want the absolute maximum 
reached.
>> 
>> opcode MaxAmpInKCycle, k, ak
>> setksmps 1
>> ain, kperiod  xin ;ain - input signal, kperiod = kspms
>> kcounter init 0 ;count from 0 to ksmps
>> kout init 0 ;output value
>> aamp = abs(ain)
>> kamp downsamp aamp
>> ;if above previous value update
>> kout = (kamp > kout ? kamp : kout)
>> kcounter = kcounter + 1
>> if kcounter == kperiod then
>>     ;reset value and counter
>>     ;when reaching ksmps
>>     kout = 0
>>     kcounter = 0
>> endif
>> printk2 kcounter ; for testing
>> printk ksmps / sr, kout ; for testing
>> xout kout
>> endop
>> 
>> Not sure if it's working as expected, by printing values looks like that 
the program using this opcode
>> 
>> instr 1 
>> ainLH, ainRH diskin2 $INPUTFILE, 1, 0, 1
>> printk ksmps / sr, 123
>> kvalue MaxAmpInKCycle ainLH, 8 ; equal to ksmps
>> printk ksmps / sr, 456
>> printk ksmps / sr, kvalue
>> printk ksmps / sr, 789
>> endin
>> 
>> is somehow out of phase: after having printed 789 (from the main program), 
kcounter variable value (printed from inside the opcode) is not 0 (don't know 
if caused by some kind of "printing buffer") so if someone want give it a 
try/report results/find errors/have an idea of what's happening and want to 
share is more than welcome.
>> 
>> I'm using 5.17 double from Ubuntu repository
>> 
>> Bye
>> Stefano
>>  
>
>Dr Victor Lazzarini
>Senior Lecturer
>Dept. of Music
>NUI Maynooth Ireland
>tel.: +353 1 708 3545
>Victor dot Lazzarini AT nuim dot ie
>
>
>
>
>
>Send bugs reports to the Sourceforge bug trackers
>csound6:
>            https://sourceforge.net/p/csound/tickets/
>csound5:
>            https://sourceforge.net/p/csound/bugs/
>Discussions of bugs and features can be posted here
>To unsubscribe, send email sympa@lists.bath.ac.uk with body "unsubscribe 
csound"
>
>
>