| Here’s what I meant with the other code showing just the relevant lines
kph = int(((kph * kdiv) % 1) * klen) // <—— this assigns to kph
kout = kvals[kph] // <— this reads kph
No matter where you put a line
kph init 0
initialising kph, it won’t make a difference. This is because the first lines above
run *only* at perf time and the initialisaiton *only* at init time.
So the initial value of kph will always be overwritten before it is used. If you
reverse the lines, then you have a chance to use the initial value before
it gets changed.
In any case, it is normal practice to update the state of a phase integrator after
you use it. So you start with an initial value, use it, then increment it.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland
> On 4 Feb 2023, at 10:51, Jacopo Greco d'Alceo <00000c641a512f08-dmarc-request@LISTSERV.HEANET.IE> wrote:
>
> Mh.. Thank you Victor, but TBH i’m not sure I understood what u were telling.
> Anyway, this is the solution to add inside the code in order to “simulate” a first step init to get the first value of the array:
>
> kinit init 1
> if kinit == 1 then
> kinit = 0
> kout = kvals[0]
> endif
>
> Thanks to Johann Philippe,
> best.
>
>
>
>> On 4 Feb 2023, at 11:02, Victor Lazzarini wrote:
>>
>> Maybe the issue is that no matter how you initialiase kph, you are setting it immediately before you use it, so any initialisation is moot.
>>
>> Maybe reordering the operations, that is setting kph after you use it, might help.
>>
>> Prof. Victor Lazzarini
>> Maynooth University
>> Ireland
>>
>>> On 4 Feb 2023, at 00:41, coooooooordeliaa <00000c641a512f08-dmarc-request@listserv.heanet.ie> wrote:
>>>
>>> *Warning*
>>>
>>> This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>>>
>>> Hi,
>>>
>>> I have this nice and juicy opcode that simply has the function of reading some values in an array and get them according to a phasor (embodying the tempo of livecoding).
>>> Here it is:
>>>
>>> opcode pump, k, kk[]
>>> kdiv, kvals[] xin
>>>
>>> kdiv init i(kdiv)
>>>
>>> klen lenarray kvals
>>>
>>> kph chnget "PHASOR_IN_ANOTHER_INSTR"
>>> kph = int(((kph * kdiv) % 1) * klen)
>>>
>>> ktrig changed2 kph
>>>
>>> if ktrig == 1 then
>>> kout = kvals[kph]
>>> endif
>>>
>>> xout kout
>>> endop
>>>
>>> The very big problem is that sometimes kout doesn't get the values I need and csound do not appreciate it. Typically I use this for iterating some GEN tables (tuning system or envelope) and here if there's not a GEN value csound is stuck.
>>>
>>> I think it's due to a lack of initialisation, but I tried everything: ktrig init -1, kph init 0, kout init kvals[0] (in this last one Csound gets super nervous). I need to tell csound to get the first value in the init state. How can I do it?
>>> Thanks ❤️
>>>
>>> Csound mailing list
>>> Csound@listserv.heanet.ie
>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7C3c599302c44c43e68cc408db069dd4b9%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638111047202595902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RxodTYUiyaFzUK6RvjaKsqs67tV0iQySJRy3Ti%2BDZag%3D&reserved=0
>>> Send bugs reports to
>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7C3c599302c44c43e68cc408db069dd4b9%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638111047202595902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=cK%2FnaijfYg%2BY%2FWZNeV%2BaOQQukgyErpdCER8DzLfH4OU%3D&reserved=0
>>> Discussions of bugs and features can be posted here
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7C3c599302c44c43e68cc408db069dd4b9%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638111047202595902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RxodTYUiyaFzUK6RvjaKsqs67tV0iQySJRy3Ti%2BDZag%3D&reserved=0
>> Send bugs reports to
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7C3c599302c44c43e68cc408db069dd4b9%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638111047202595902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=cK%2FnaijfYg%2BY%2FWZNeV%2BaOQQukgyErpdCER8DzLfH4OU%3D&reserved=0
>> Discussions of bugs and features can be posted here
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7C3c599302c44c43e68cc408db069dd4b9%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638111047202595902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RxodTYUiyaFzUK6RvjaKsqs67tV0iQySJRy3Ti%2BDZag%3D&reserved=0
> Send bugs reports to
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7C3c599302c44c43e68cc408db069dd4b9%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638111047202595902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=cK%2FnaijfYg%2BY%2FWZNeV%2BaOQQukgyErpdCER8DzLfH4OU%3D&reserved=0
> Discussions of bugs and features can be posted here
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
|