Csound Csound-dev Csound-tekno Search About

[Cs-dev] expseg bug fix

Date2007-09-09 09:04
FromJonathan Murphy
Subject[Cs-dev] expseg bug fix
Regarding:

http://www.nabble.com/differing-behaviour-of-linseg-and-expseg-with-xtratim-release-tf4400129.html

I believe that I have found the problem. Changing the following lines
in /OOps/ugens1.c:

  424       if (dur > FL(0.0)) {
  425         if (val * nxtval <= FL(0.0))
  426           goto experr;
  427         d = dur * csound->ekr;
  428         segp->val = val;
  429         segp->mlt = (MYFLT) pow((double)(nxtval / val), (1.0/(double)d));
  430         segp->cnt = (long) (d + FL(0.5));
  431       }
  432       else break;               /*  .. til 0 dur or done */
 
to read:

  if (val * nxtval <= FL(0.0))
  goto experr;
  d = dur * csound->ekr;
  segp->val = val;
  segp->mlt = (MYFLT) pow((double)(nxtval / val), (1.0/(double)d));
  segp->cnt = (long) (d + FL(0.5));

Fixes it. I think.

In order to obtain a steady state it is necessary to process values of
dur <= 0.0, meaning that code like this:

iatt = 0.01
ipeak = 1.0
idec = 0.1
isus = 0.5
irel = 1.0
aenv expseg 0.001, iatt, ipeak, idec, isus, -1, isus, irel, 0.001

will attain a steady state at isus, whereas at present this is not
possible.

Could someone with a deeper understanding of the code and CVS write
access please take a look at this and commit the change if it's deemed
appropriate?

Thanks in advance,
Jonathan.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-09-11 18:31
FromJonathan Murphy
SubjectRe: [Cs-dev] expseg bug fix
Here is a patch to ugens1.c. The basic problem is that expseg and
expsega don't tolerate indefinite durations, they are discarded by the 

if (...){
...}
else break;

statements. 

Jonathan. 

--- /csound5/OOps/ugens1.c.orig  2007-09-12 01:25:15.000000000 +0900
+++ /csound5/OOps/ugens1.c       2007-09-12 01:28:05.000000000 +0900
@@ -421,15 +421,12 @@
       val = nxtval;
       dur = **argp++;
       nxtval = **argp++;
-      if (dur > FL(0.0)) {
         if (val * nxtval <= FL(0.0))
           goto experr;
         d = dur * csound->ekr;
         segp->val = val;
         segp->mlt = (MYFLT) pow((double)(nxtval / val), (1.0/(double)d));
         segp->cnt = (long) (d + FL(0.5));
-      }
-      else break;               /*  .. til 0 dur or done */
     } while (--nsegs);
     segp->cnt = MAXPOS;         /* set last cntr to infin */
     return OK;
@@ -467,15 +464,12 @@
       val = nxtval;
       dur = **argp++;
       nxtval = **argp++;
-      if (dur > FL(0.0)) {
         if (val * nxtval <= FL(0.0))
           goto experr;
         d = dur * csound->esr;
         segp->val = val;
         segp->mlt = (MYFLT) pow((double)(nxtval / val), (1.0/(double)d));
         segp->cnt = (long) (d + FL(0.5));
-      }
-      else break;               /*  .. til 0 dur or done */
     } while (--nsegs);
     segp->cnt = MAXPOS;         /* set last cntr to infin */
     return OK;

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2007-09-12 14:13
FromVictor Lazzarini
SubjectRe: [Cs-dev] expseg bug fix
Jonathan,

thanks for this. I'd like to wait for John's return to integrate this,
as I think it's best if he takes a look at it before we do anything.

all the best

Victor

At 09:04 09/09/2007, you wrote:
>Regarding:
>
>http://www.nabble.com/differing-behaviour-of-linseg-and-expseg-with-xtratim-release-tf4400129.html
>
>I believe that I have found the problem. Changing the following lines
>in /OOps/ugens1.c:
>
>   424       if (dur > FL(0.0)) {
>   425         if (val * nxtval <= FL(0.0))
>   426           goto experr;
>   427         d = dur * csound->ekr;
>   428         segp->val = val;
>   429         segp->mlt = (MYFLT) pow((double)(nxtval / val), 
> (1.0/(double)d));
>   430         segp->cnt = (long) (d + FL(0.5));
>   431       }
>   432       else break;               /*  .. til 0 dur or done */
>
>to read:
>
>   if (val * nxtval <= FL(0.0))
>   goto experr;
>   d = dur * csound->ekr;
>   segp->val = val;
>   segp->mlt = (MYFLT) pow((double)(nxtval / val), (1.0/(double)d));
>   segp->cnt = (long) (d + FL(0.5));
>
>Fixes it. I think.
>
>In order to obtain a steady state it is necessary to process values of
>dur <= 0.0, meaning that code like this:
>
>iatt = 0.01
>ipeak = 1.0
>idec = 0.1
>isus = 0.5
>irel = 1.0
>aenv expseg 0.001, iatt, ipeak, idec, isus, -1, isus, irel, 0.001
>
>will attain a steady state at isus, whereas at present this is not
>possible.
>
>Could someone with a deeper understanding of the code and CVS write
>access please take a look at this and commit the change if it's deemed
>appropriate?
>
>Thanks in advance,
>Jonathan.
>
>-------------------------------------------------------------------------
>This SF.net email is sponsored by: Microsoft
>Defy all challenges. Microsoft(R) Visual Studio 2005.
>http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
>_______________________________________________
>Csound-devel mailing list
>Csound-devel@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/csound-devel

Victor Lazzarini
Music Technology Laboratory
Music Department
National University of Ireland, Maynooth


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net