This is fm.c in view mode; [Download] [Up]
#include "/musr/H/ugens.h"
#include "/musr/macros/macros.h"
fm(p,n_args)
float *p;
{
float sicar,simod,*xarray,*sine,val;
float evals[6],tabs[4],modphs,carphs;
float *risef,*decayf,index,amp,diff,val2,foscil();
int len1,len2,z,j;
long nsamps,i;
/* in Cmix pfields start with p0, which is the starting time */
/* p2 is pitch of carrier, p3 is pitch of mod, p4&5 index low&hi,
p6&7 rise and decay times p8 is amp */
sine = floc(1); /* function 1 is sine wave */
xarray = floc(2); /* function 2 is index guide */
decayf = risef = floc(3); /*function 3 is envlp shape */
len1 = fsize(1);
len2 = fsize(2);
sicar = cpspch(p[2]) * len1/SR; /* convert cps to si */
simod = cpspch(p[3]) * len1/SR;
sicar = cpspch(p[2]) * 2*PI/SR;
simod = cpspch(p[3]) * 2*PI/SR;
p[4] *= simod;
diff = (p[5] * simod) - p[4];
modphs = carphs = 0;
nsamps = setnote(p[0],p[1],0);
z = SR/400; /* interrupt 200 times per sec (control rate)*/
evset(p[9],p[6],p[7],3,evals);
tableset(p[9],len2,tabs);
for(j=0, i = 0; i<nsamps; i++) {
if(!j--) {
amp = evp(i,risef,decayf,evals) * p[8];
index = diff * tablei(i,xarray,tabs) + p[4];
//printf("index = %f amp = %f\n",index,amp);
j=z;
}
//OSCIL(val,index,simod,sine,len1,modphs);
//OSCILN(val2,amp,sicar+val,sine,len1,carphs);
//val = foscil(index,simod,&modphs);
//val2 = foscil(amp,sicar+val,&carphs);
modphs += simod;
val = sin(modphs) * index;
carphs += (sicar + val);
val2 = sin(carphs) * amp;
//printf("%f %f %f %f\n",carphs,sicar,val2,amp);
WIPEOUT(&val2,0);
}
endnote(0);
}
float foscil(amp,si,phs)
float amp,si,*phs;
{
*phs += si;
return(cos(*phs) * amp);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.