This is lpcplay.c in view mode; [Download] [Up]
#include "../macros/macros.h"
#define NPOLE 32
#define FRAMSIZE (NPOLE+4)
#define FPREC 22
#define RECSIZE (FPREC*FRAMSIZE)
#define BPREC (RECSIZE*FLOAT)
#define BPFRAME (FRAMSIZE*FLOAT)
int anal;
float allpole(x,jcount,npoles,past,c)
float x,*past,*c;
int *jcount,npoles;
{
int j,nfint;
for(j= *jcount, nfint=0; nfint<npoles; nfint++,j++)
x += (*(c+nfint) * *(past+j));
*(past+ *jcount) = *(past+*jcount+npoles) = x;
*jcount = (*jcount + 1) % npoles;
return(x);
}
float buzz(amp,si,hn,f,phs)
float amp,si,hn,*f,*phs;
{
int j,k;
float q,d,h2n,h2np1;
j = *phs;
k = (j+1) % 1024;
h2n = 2. * hn;
h2np1 = h2n + 1.;
q = (int)((*phs - (float)j) * h2np1)/h2np1;
d = *(f+j);
d += (*(f+k)-d)*q;
if(!d) q = amp;
else {
k = (long)(h2np1 * *phs) % 1024;
q = amp * (*(f+k)/d - 1.)/h2n;
}
*phs += si;
while(*phs >= 1024.)
*phs -= 1024.;
return(q);
}
/*
* ugens.h: define unit generator structure
*/
#define UG_NSIZ 7 /* Max len of UG name */
#define UG_NULL (struct ug_item *)0
#define NAMESIZE 128 /* Max size of file name */
#define FLOAT (sizeof(float)) /* nbytes in floating point word*/
#define INT (sizeof(short)) /* nbytes in integer word */
#define SHORT (sizeof(short))
#define LONG (sizeof(long))
#define NFILES 4 /* maximum number of opened files */
struct ug_item {
struct ug_item *ug_next;
int (*ug_ptr)(); /* Pointer to the function */
char *ug_name;
};
typedef struct ug_item ug_t;
extern ug_t *ug_list;
extern addfunc();
#define UG_INTRO(flabel,func) \
{ extern func(); \
static ug_t this_ug = { UG_NULL, func, flabel }; \
if (addfunc(&this_ug) == -1) merror(flabel); }
#define PI2 6.2831853
#define PI 3.141592654
extern float SR;
#ifndef MAIN
extern int aargc;
extern char *aargv[]; /* to pass commandline args to subroutines */
#endif
/* structure to pass to gen routines */
struct gen {
int size; /* size of array to load up */
int nargs; /* number of arguments passed in p array */
float *pvals; /* address of array of p values */
float *array; /* address of array to be loaded up */
};
#ifndef SOUND
extern int (*addoutpointer[NFILES])();
extern int (*layoutpointer[NFILES])();
extern int (*wipeoutpointer[NFILES])();
extern int (*getinpointer[NFILES])();
extern int (*bwipeoutpointer[NFILES])();
#define ADDOUT(x,y) (*addoutpointer[y])(x,y)
#define LAYOUT(x,l,y) (*layoutpointer[y])(x,l,y)
#define WIPEOUT(x,y) (*wipeoutpointer[y])(x,y)
#define GETIN(x,y) (*getinpointer[y])(x,y)
#define BWIPEOUT(x,y,z) (*bwipeoutpointer[y])(x,y,z)
#endif SOUND
/* declarations of units */
long setnot();
float reson(),oscil(),oscili(),osciln(),oscilni(),evp(),table(),tablei();
float cpspch(),pchcps(),cpsoct(),octcps(),pchoct();
float delget(),dliget(),boost(),rrand();
float octpch(),*floc();
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 *ballpole(),*bbuzz(),*brandf(),alpvals[2048],buzvals[2048];
float buzz(),allpole();
int jcount = 0;
long seed,i,nsamps;
int counter,flag;
float thresh,randamp,randoff;
float *cpoint;
for(i=0; i<NPOLE*2; i++) past[i] = 0;
anal = open("data/wasting13",0);
/* p0=start,p1=dur,p2=8ve.pch,p3=frame1,p4=frame2,p5=amp*/
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 = (float *)floc(1);
randamp = .1/randoff;
seed = 1;
thresh = p[6];
srand(1);
counter = 0;
cpoint = c + 4;
ramp = ampmlt = errno = 0; /* to make tcc happy */
i=nsamps;
while(i--) {
if(!counter--) {
frameno = ((float)(nsamps - i)/nsamps)*frames + frame1;
getfr(frameno,c);
ampmlt = amp * c[0];
errno = (c[2] > thresh) ? 0 : 1;
ramp = ampmlt * randamp;
si = c[3] * magic;
hn = (int)(srd2/c[3]);
counter = (float)(SR/c[3]);
counter = (counter > i) ? i : counter;
}
if(errno)
val = buzz(ampmlt,si,hn,f,&phs);
/*
{BUZZ(val,ampmlt,si,hn,f,phs);}
*/
else
val = (float)(rand()-randoff) * ramp;
val = allpole(val,&jcount,NPOLE,past,cpoint);
/*
ALLPOLE(val,jcount,NPOLE,past,cpoint);
*/
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));
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.