#include "../H/ugens.h" #include #define RESIDAMP 0 #define RMSAMP 1 #define THRESH 2 #define PITCH 3 /* values in locs 0-3 of frame*/ #define NPOLE 32 #define NPOLEM1 31 #define FRAMSIZE (NPOLE+4) #define FPREC 22 #define RECSIZE (FPREC*FRAMSIZE) #define BPREC (RECSIZE*FLOAT) #define BPFRAME (FRAMSIZE*FLOAT) int anal; float cq,outold; lpcplay(p,n_args) float *p; { float amp,si,hn,phs,*f,srd2,magic,d,warpset(); float c[FRAMSIZE],past[NPOLE*2],frames,frame1,frameno,ampmlt,errno; float ballpole(),alpvals[2048],buzvals[2048],pchval[2048]; float thresh,randamp,randoff; float *cpoint; float x,transposition,newpch; int jcount,seed,i,nsamps,counter; float cps,tblvals[2],weight(); if(!n_args) { /* printf(" p[0]=starting time, p[1]=duration, p[2]=pitch,p[3]=frame1, p4=frame2 p[5]=amp, p[6]=thresh, p[7]=d\n"); */ return; } for(i=0; i0; i -=counter) { frameno = ((float)(nsamps - i)/nsamps)*frames + frame1; if(getfr(frameno,c) == -1) break; errno = (c[2] > thresh) ? 0 : 1; ampmlt = (errno) ? amp * c[0] : amp * c[0] * randamp; cps = tablei(nsamps-i,pchval,tblvals); newpch = cpsoct(octcps(cps)+transposition); si = newpch * magic; hn = (int)(srd2/newpch); counter = (float)(SR/newpch); counter = (counter > i) ? i : counter; if(counter <= 0) break; if(errno) bbuzz(ampmlt,si,hn,f,&phs,buzvals,counter); else brrand(ampmlt,buzvals,counter); if(d) { ampmlt *= warpset(d,cpoint); bwarppol(buzvals,past,d,cpoint,alpvals,counter); } else ballpole(buzvals,&jcount,NPOLE, past,cpoint,alpvals,counter); bwipeout(alpvals,0,counter); } endnote(0); } float warppol(sig,past,d,c) float sig,*past,d,*c; { float temp1,temp2; int n; temp1 = past[NPOLEM1]; past[NPOLEM1] = cq * outold - d * past[NPOLEM1]; for(n=NPOLE-2; n>=0; n--) { temp2 = past[n]; past[n] = d * (past[n+1] - past[n]) + temp1; temp1 = temp2; } for(n=0;n=0; n--) { temp2 = past[n]; past[n] = d * (past[n+1] - past[n]) + temp1; temp1 = temp2; } for(n=0;n= oldframe) && (frame < endframe))) { if(lseek(anal,((long)frame*(long)BPFRAME),0) == -1) { fprintf(stderr,"bad lseek on analysis file \n"); return(-1); } if(read(anal,(char *)array,BPREC) <= 0) { fprintf(stderr,"reached eof on analysis file \n"); return(-1); } oldframe = frame; endframe = oldframe + FPREC - 1; } for(i=(frame-oldframe)*FRAMSIZE,j=0; j= *(tab+1)) loc = *(tab+1); return(*(array + loc)); } float weight(newpch,frame1,frame2,thresh) float newpch,frame1,frame2; { float c[FRAMSIZE]; int i; float xweight,sum; xweight = sum = 0; for(i=(int)frame1; i<(int)frame2; i++) { getfr((float)i,c); if(c[THRESH] > thresh) continue; xweight += c[RMSAMP]; sum += (c[PITCH] * c[RMSAMP]); } return(sum/xweight); }