This is lpcwarpplay.c in view mode; [Download] [Up]
#include "../H/ugens.h" #include <math.h> #include "../macros/macros.h" #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) float FTEMP1,FTEMP2; int ITEMP1; #define WARPPOL(sig,past,d,c) \ FTEMP1 = past[NPOLEM1];\ past[NPOLEM1] = cq * outold - d * past[NPOLEM1];\ for(ITEMP1=NPOLE-2; ITEMP1>=0; ITEMP1--) {\ FTEMP2 = past[ITEMP1];\ past[ITEMP1] = d * (past[ITEMP1+1] - past[ITEMP1]) + FTEMP1;\ FTEMP1 = FTEMP2;\ }\ for(ITEMP1=0;ITEMP1<NPOLE;ITEMP1++) sig += c[ITEMP1] * past[ITEMP1];\ outold = sig int anal; float cq,outold; play(p,n_args) float *p; { float buzzamp,ramp,xamp,amp,si,hn,phs,*f,out[4],srd2,magic; float c[FRAMSIZE],past[NPOLE*2],val,frames,frame1,frameno,ampmlt,errno; float cl,warpset(),warppol(),warpval; float pchmult; int jcount = 0; long i,nsamps; int counter,flag; float thresh,randamp,randoff; float *cpoint; for(i=0; i<NPOLE*2; i++) past[i] = 0; anal = open("analysis",0); /* p0=start,p1=dur,p2=8ve.pch,p3=frame1,p4=frame2, p5=amp,p6=thresh,p7=warp,p8=tansp in semitones*/ amp = p[5]; si = cpspch(p[2])*512./SR; /* si just added now for counter */ hn = (int)(SR * .5/cpspch(p[2])); srd2 = SR/2.; magic = 512./SR; phs = 0; nsamps = setnote(p[0],p[1],0); frames = p[4] - p[3] + 1.; frame1 = p[3]; randoff = 32767./2.; f = floc(1); randamp = .1/randoff; thresh = p[6]; warpval = p[7]; pchmult = (float)pow((double)2.,(double)(p[8]/12.)); /* p8 gives transposition in semitones */ srand(1); warpinit(); counter = 0; cpoint = c + 4; for(i = 0; i<nsamps; i++) { if(!counter--) { frameno = ((float)i/nsamps) * frames + frame1; getfr(frameno,c); ampmlt = amp * c[0]; errno = c[2]; cl = warpset(warpval,c+4); xamp = errno/thresh; if(xamp > 1.) xamp= 1; buzzamp = (1.- xamp) * ampmlt; ramp = ampmlt * xamp * randamp; c[3] *= pchmult; si = c[3] * magic ; hn = (int)(srd2/c[3]); counter = (float)(SR/c[3]); } /* val = buzz(buzzamp,si,hn,f,&phs) + */ BUZZ(val,buzzamp,si,hn,f,phs); /* val += (float)(rand()-randoff) * ramp; */ WARPPOL(val,past,warpval,cpoint); val *= cl; WIPEOUT(&val,0); } endnote(0); } getfr(frameno,c) float frameno,*c; { int frame,i,j; static float array[RECSIZE]; float fraction; static int oldframe = 0; static int endframe = 0; frame = (int)frameno; fraction = frameno - (float)frame; if(!((frame >= oldframe) && (frame < endframe))) { lseek(anal,((long)frame*(long)BPFRAME),0); read(anal,(char *)array,BPREC); oldframe = frame; endframe = oldframe + FPREC - 1; } for(i=(frame-oldframe)*FRAMSIZE,j=0; j<FRAMSIZE; i++,j++) *(c+j) = *(array+i) + fraction * (*(array+i+FRAMSIZE) - *(array+i)); } float warppol(sig,past,d,c) float sig,*past,d,*c; { float temp1,temp2; register 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<NPOLE;n++) sig += c[n] * past[n]; outold = sig; return(sig); } float warpset(d,c) float d,*c; { register m; float cl; for(m=1; m<NPOLE; m++) c[m] += d * c[m-1]; cl = 1./(1.-d * c[NPOLEM1]); cq = cl * (1. - d * d); return(cl); } warpinit() { outold = 0; }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.