Csound Csound-dev Csound-tekno Search About

[Csnd] linseg

Date2022-12-11 20:49
FromJohn
Subject[Csnd] linseg
Is this not a trivial fencepost issue? The target for the result is
the value at the end of the k-cycle, but the printing is from the
start of the cycle.  Just a thought.

==John ffitch

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-12-11 21:35
FromVictor Lazzarini
SubjectRe: [Csnd] [EXTERNAL] [Csnd] linseg
That is what it is. 

linsegr gets to (nearly) zero at the next kcycle, as the increment is applied after the envelope has been output. This is the relevant incr code

p->curinc = (segp->nxtpt - p->curval) / segp->cnt;

If segp->cnt is reduced by 1, then it gets very close to 0.

If the release time is longer, then the result will also be closer to 0.

As far as I can see that’s how it always worked. 
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 11 Dec 2022, at 20:49, John  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.
> 
> Is this not a trivial fencepost issue? The target for the result is
> the value at the end of the k-cycle, but the printing is from the
> start of the cycle.  Just a thought.
> 
> ==John ffitch
> 
> 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


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-12-12 23:50
FromRichard Knight
SubjectRe: [Csnd] [EXTERNAL] [Csnd] linseg
I have tried the change below which seems to work as desired. I am not 
sure if it is the best way to do it, so appreciate any feedback - it 
took me a while to work out the flow, and it seems the return by the 
comment 'seg Z now done all' is/was never actually reached.
Basically if releasing, segp->cnt is reduced by 1, then if in last 
segment and curcnt == 1 it sets rslt and segsrem to 0 to ensure the 
final value is as desired.


@@ -414,13 +414,19 @@ int32_t klnsegr(CSOUND *csound, LINSEG *p)
      *p->rslt = p->curval;                   /* put the cur value    */
      if (p->segsrem) {                       /* done if no more segs */
        SEG *segp;
-      if (p->h.insdshead->relesing && p->segsrem > 1) {
-        while (p->segsrem > 1) {           /* reles flag new:      */
-          segp = ++p->cursegp;             /*   go to last segment */
-          p->segsrem--;
-        }                                  /*   get univ relestim  */
-        segp->cnt = p->xtra>= 0 ? p->xtra : p->h.insdshead->xtratim;
-        goto newi;                         /*   and set new curinc */
+      if (p->h.insdshead->relesing) {
+        if (p->segsrem > 1) {
+          while (p->segsrem > 1) {           /* reles flag new:      */
+            segp = ++p->cursegp;             /*   go to last segment */
+            p->segsrem--;
+          }                                  /*   get univ relestim  */
+          segp->cnt = (p->xtra>= 0 ? p->xtra : p->h.insdshead->xtratim) 
- 1;
+          goto newi;                         /*   and set new curinc */
+        } else if (p->segsrem == 1 && p->curcnt == 1) { /* set final 
value */
+          *p->rslt = p->cursegp->nxtpt;
+          p->segsrem = 0;
+          return OK;
+        }



On 2022-12-11 21:35, Victor Lazzarini wrote:
> That is what it is.
> 
> linsegr gets to (nearly) zero at the next kcycle, as the increment is
> applied after the envelope has been output. This is the relevant incr
> code
> 
> p->curinc = (segp->nxtpt - p->curval) / segp->cnt;
> 
> If segp->cnt is reduced by 1, then it gets very close to 0.
> 
> If the release time is longer, then the result will also be closer to 
> 0.
> 
> As far as I can see that’s how it always worked.
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
> 
>> On 11 Dec 2022, at 20:49, John  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.
>> 
>> Is this not a trivial fencepost issue? The target for the result is
>> the value at the end of the k-cycle, but the printing is from the
>> start of the cycle.  Just a thought.
>> 
>> ==John ffitch
>> 
>> 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
> 
> 
> 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

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-12-13 06:28
FromVictor Lazzarini
SubjectRe: [Csnd] [EXTERNAL] [Csnd] linseg
Thanks, I have been working on a fix and have committed it to csound6, but there is a few things I have to check before I finish. The main issue appears to be a discrepancy by 1 kcycle between normal performance and xtratim. I am checking the origin of this before I complete the job and mainline it to develop.

Prof. Victor Lazzarini
Maynooth University
Ireland

> On 12 Dec 2022, at 23:51, Richard Knight  wrote:
> 
> I have tried the change below which seems to work as desired. I am not sure if it is the best way to do it, so appreciate any feedback - it took me a while to work out the flow, and it seems the return by the comment 'seg Z now done all' is/was never actually reached.
> Basically if releasing, segp->cnt is reduced by 1, then if in last segment and curcnt == 1 it sets rslt and segsrem to 0 to ensure the final value is as desired.
> 
> 
> @@ -414,13 +414,19 @@ int32_t klnsegr(CSOUND *csound, LINSEG *p)
>     *p->rslt = p->curval;                   /* put the cur value    */
>     if (p->segsrem) {                       /* done if no more segs */
>       SEG *segp;
> -      if (p->h.insdshead->relesing && p->segsrem > 1) {
> -        while (p->segsrem > 1) {           /* reles flag new:      */
> -          segp = ++p->cursegp;             /*   go to last segment */
> -          p->segsrem--;
> -        }                                  /*   get univ relestim  */
> -        segp->cnt = p->xtra>= 0 ? p->xtra : p->h.insdshead->xtratim;
> -        goto newi;                         /*   and set new curinc */
> +      if (p->h.insdshead->relesing) {
> +        if (p->segsrem > 1) {
> +          while (p->segsrem > 1) {           /* reles flag new:      */
> +            segp = ++p->cursegp;             /*   go to last segment */
> +            p->segsrem--;
> +          }                                  /*   get univ relestim  */
> +          segp->cnt = (p->xtra>= 0 ? p->xtra : p->h.insdshead->xtratim) - 1;
> +          goto newi;                         /*   and set new curinc */
> +        } else if (p->segsrem == 1 && p->curcnt == 1) { /* set final value */
> +          *p->rslt = p->cursegp->nxtpt;
> +          p->segsrem = 0;
> +          return OK;
> +        }
> 
> 
> 
>> On 2022-12-11 21:35, Victor Lazzarini wrote:
>> That is what it is.
>> linsegr gets to (nearly) zero at the next kcycle, as the increment is
>> applied after the envelope has been output. This is the relevant incr
>> code
>> p->curinc = (segp->nxtpt - p->curval) / segp->cnt;
>> If segp->cnt is reduced by 1, then it gets very close to 0.
>> If the release time is longer, then the result will also be closer to 0.
>> As far as I can see that’s how it always worked.
>> ========================
>> Prof. Victor Lazzarini
>> Maynooth University
>> Ireland
>>>> On 11 Dec 2022, at 20:49, John  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.
>>> Is this not a trivial fencepost issue? The target for the result is
>>> the value at the end of the k-cycle, but the printing is from the
>>> start of the cycle.  Just a thought.
>>> ==John ffitch
>>> 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%7C9bd2a7e0962048b06f0b08dadc9bbdf5%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638064858718007416%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dQhqncBIUEgZTzLzQEt9NHKqD%2BoqXIfXTUv6a8bH0pk%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%7C9bd2a7e0962048b06f0b08dadc9bbdf5%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638064858718007416%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=8fFkVaGlshGn9OacJU3Pt1i6OhbGoRTyuAYTGCA%2FgnM%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%7C9bd2a7e0962048b06f0b08dadc9bbdf5%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638064858718007416%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dQhqncBIUEgZTzLzQEt9NHKqD%2BoqXIfXTUv6a8bH0pk%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%7C9bd2a7e0962048b06f0b08dadc9bbdf5%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638064858718007416%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=8fFkVaGlshGn9OacJU3Pt1i6OhbGoRTyuAYTGCA%2FgnM%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%7C9bd2a7e0962048b06f0b08dadc9bbdf5%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638064858718007416%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dQhqncBIUEgZTzLzQEt9NHKqD%2BoqXIfXTUv6a8bH0pk%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%7C9bd2a7e0962048b06f0b08dadc9bbdf5%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638064858718007416%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=8fFkVaGlshGn9OacJU3Pt1i6OhbGoRTyuAYTGCA%2FgnM%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