#include "../H/ugens.h" #include "../H/sfheader.h" #include extern int sfd[NFILES]; extern int pointer[NFILES]; extern char peakoff[NFILES]; extern int bufsize[NFILES]; extern char *sndbuf[NFILES]; extern char *peak[NFILES]; extern char *peakloc[NFILES]; extern SFHEADER sfdesc[NFILES]; /* a cmix routine to surgically alter segments of one or more channels in * a soundfile. Arguments are * p[0] starting time; * p[1] duration; * p[2] overall amp; * p[3] alter channel 0? 1 if yes, 0 if no; * p[4] " " 1? " " " " " " * p[5] " " 2? " " " " " " * p[6] " " 3? " " " " " " */ #define SIZE 2048 float array[SIZE],tabs[2]; int RESET = 200; /* times per sec to reinitialize envelope */ int lineset = 0; alter(p,n_args) float *p; int n_args; { long nsamps,i; int chlist[4],j,counter,non,skip,unit; float amp; unit = 0; if(!lineset) for(j=0;j= n_args) chlist[j] = 0; } if((non == 0) || (non > sfchans(&sfdesc[unit]))) { fprintf(stderr,"Something wrong with this card, check args\n"); return; } for (i=nsamps; i>0; i -= skip) { counter = i>skip? skip : i; amp=tablei(nsamps-i,array,tabs) * p[2]; bmultout(amp,chlist,unit,counter*sfchans(&sfdesc[unit])); } endnote(unit); } reset(p,n_args) float *p; { if(p[0]) RESET = p[0]; fprintf(stderr,"Envelope calls set to %d times per sec\n",RESET); } setline(p,n_args) float *p; { double increm; int i,j,k,points; if((n_args % 2) != 0) { fprintf(stderr,"Something wrong with phrase, check args\n"); closesf(); } lineset = 1; /* initialized array */ increm = (double)(p[n_args - 2] - p[0])/(double)SIZE; for(j=0,i=0; j < (n_args-2); j += 2) { points = (int)((double)(p[j+2] - p[j]) / increm +.5); if(p[j+2] != p[j]) { if(points <= 0) points = 1; if((p[j+2] < p[j]) || (points > SIZE)) { fprintf(stderr," confusion on phrase card\n"); closesf(); } for(k=0; k < points; k++) { array[i++] = ((float)k/(float)points) * (p[j+3] - p[j+1]) + p[j+1]; if(i == SIZE) return; } } } i--; while(i++ < SIZE) array[i] = array[i-1]; } bmultout(amp,chlist,fno,size) float amp; int *chlist; { int i,j; short *ibuf; float *fbuf; int todo,remains; int nchans; int len = bufsize[fno]; nchans = sfchans(&sfdesc[fno]); refill: todo = ((pointer[fno] + size) > len) ? len - pointer[fno] : size; if(sfclass(&sfdesc[fno]) == SF_SHORT) { for(i=0,ibuf = (short *)sndbuf[fno] + pointer[fno];i