#import "Evp.h"

@implementation Evp : Object
{
	float qzero,q1,q2,q3,q4;
	float *risef,*decayf;
}

+ create {
	id newInstance;
	newInstance = [self new];
	return newInstance;
}

-dur:(float)aDur 
 rise:(float)aRise 
 decay:(float)aDecay  
 risefunction:(float *)aFunction
 decayfunction:(float *) bFunction
 risesize:(int)aSize
 sr:(int)aSR  {
	float ris,dec;
	aRise= (aRise > 0.) ? aRise : -aRise * aDur;
	aDecay = (aDecay > 0.) ? aDecay : -aDecay * aDur;
	qzero = aDur * (float)aSR;
	q1 = (aDur-aDecay)/aDur;
	q2 = aRise/aDur;
	q3 = aSize;
	q4 = aDecay/aDur;
	risef = aFunction;
	decayf = bFunction;
}
-(float)getval:(int)nsample {
	 register jloc;
        float far = (float)(nsample)/ qzero;
        if( far > q1) {
                jloc = (1. - ((far - q1)/ q4)) * q3;
                return(*(decayf+jloc));
                }
        else
                if(far >= q2) return(1.);
        else    {
                jloc = far * q3/ q2;
                return(*(risef+jloc));
                }
}
@end
	

