#include "../H/ugens.h"
#include "../macros/macros.h"
#include <stdio.h>
play(p,n_args)
 
float *p;

{
	int i,nsamps,unit;
	float val,out[2],q[9],dur,rise,decay,si,*f1,*f2,amp,phase;
	int len,risef,j,z,wave;

/* p0=start, p1=dur, p2=pitch, p3=amp, p4=riset, p5=decayt */
/* assumes function 1 is waveform and function 2 is envelope*/

	wave = 1; risef = 2;
	unit = 0;  /* writing to file 0*/
	nsamps = setnote(p[0],p[1],unit);

	evset(p[1],p[4],p[5],risef,q);

	f1 = floc(risef);
	f2 = floc(wave);
	len = fsize(wave);

	si = cpspch(p[2]) * fsize(1)/SR;
	z = SR/cpspch(p[2]);
	j = phase = 0;

	amp = p[3];

	for(i = 0; i < nsamps; i++) {
		if (!j--) {
                	val = amp * evp(i,f1,f1,q);
			j=z; 
		}


		OSCILI(out[0],val,si,f2,len,phase); 

		ADDOUT(out,unit); 
	}
	endnote(unit);
}
float oscil(amp,si,farray,len,phs)
float amp,si,*farray,*phs;
register len;
{
	register i =  *phs;   
	*phs += si;            
	while(*phs >= len)
	       *phs -= len;     
	return(*(farray+i) * amp);
}
