ftp.nice.ch/pub/next/unix/audio/cmix.s.tar.gz#/cmix/lpc/weighttest.c

This is weighttest.c in view mode; [Download] [Up]

#include "../H/ugens.h"
#include <stdio.h>
#define RESIDAMP     0
#define RMSAMP       1
#define THRESH       2
#define PITCH	     3
/* values in locs 0-3 of frame*/

#define MAXPOLES 32
int framsize;
int fprec;
int recsize;
int bprec;
int bpframe;
int npolem1;
int anal;
int i;
float cq,outold;
float FloatJunk;
float pow();
char dataset_name[80];
float thresh,randamp,randoff,unvoiced_rate;
int npoles;
float risetime,decaytime;

lpcplay(p,n_args)
float *p;
{
	float amp,si,hn,phs,*f,srd2,magic,d,warpset();
	float c[MAXPOLES+4],past[MAXPOLES*2],frames,frameno,ampmlt,errno;
	int frame1;
	float ballpole(),alpvals[2048],buzvals[2048],pchval[2048];
	float *cpoint;
	float x,transposition,newpch;
	float shift_();
	int jcount,seed,i,nsamps,counter;
	int nn,lastfr;
	float transp,lasttr,tranincr;
	float cps,tblvals[2],weight();
	float rsnetc[9];
	int reson_is_on;
	float cf_fact,bw_fact;
	float evals[5]; 
	float *f1;
	float actualdeviation,actualcps,actualweight;
	float peak;
	int jj;
	float deviation();

	if(anal <=0 ) {
		printf("%d !!!No open dataset!",anal);
		closesf();
	}
	for(jj=0,i=p[3]; i<= p[4]; i++,jj++) {
		d = i;
		getfr(d,c);
		pchval[jj] = c[PITCH];
	}
	printf("weight = %f\n",actualweight=weight(p[3],p[4],thresh));
	printf("average deviation = %f\n",actualdeviation = deviation(p[3],p[4],actualweight,thresh));
	/*
	adjust(actualdeviation,p[2],actualweight,pchval,p[3],p[4]);
	*/
}

getfr(frameno,c)
float frameno,*c;
{
	int frame,i,j;
	static float array[22*(MAXPOLES+4)];
	float fraction;
	static int oldframe = 0;
	static int endframe = 0;
	frame = (int)frameno;
	fraction = frameno - (float)frame;
	if(!((frame >= 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<framsize; i++,j++)  
		*(c+j) = *(array+i) + fraction * (*(array+i+framsize) 
		    - *(array+i));
	return(0);
}
float weight(frame1,frame2,throsh)
float frame1,frame2,throsh;
{
	float c[MAXPOLES+4];
	int i;
	float xweight,sum;
	xweight = sum = 0;
	for(i=(int)frame1; i<(int)frame2; i++) {
		getfr((float)i,c);
		if((c[THRESH] <= throsh) || (throsh < 0.)) {
			xweight += c[RMSAMP];
			sum += (c[PITCH] * c[RMSAMP]);
		}
	}
	return(sum/xweight);
}

dataset(p,n_args)
/* p1=dataset name, p2=npoles */
float *p;
int n_args;
{
	char *name;
	int i;

	fprec=22;
	if(n_args>1) {
		npoles=p[1];
		npolem1=npoles-1;
		framsize=npoles+4;
		recsize=fprec*framsize;
		bprec=recsize*FLOAT;
		bpframe=framsize*FLOAT;
	}
	lpcinit();
	i=(int)p[0];
	name=(char *)i;
	if(strcmp(name,dataset_name)== 0) {
		printf("\n%s is already open.\n",name);
		return;
	}
	strcpy(dataset_name,name);
	if((anal = open(name,0)) <= 0) {
		printf("Can't open %s\n",name);
		closesf();
	}
	printf("\nOpened dataset %s.\n",name);
	printf("anal is %d",anal);
}

lpcstuff(p,n_args)
/* p0=thresh, p1=random amp, p2=unvoiced rate p3= rise, p4= dec*/
float *p;
int n_args;
{
	risetime=.01; decaytime=.1;
	if(n_args>0) thresh=p[0];
	if(n_args>1) randamp=p[1];
	if(n_args>2) unvoiced_rate=p[2];
	if(n_args>3) risetime=p[3];
	if(n_args>4) decaytime=p[4];
	printf("\nAdjusting settings for %s.\n",dataset_name);
	printf(" --------------------------------------- \n");
	printf("Thresh: %f     Randamp: %f\n",thresh,randamp);
	if(unvoiced_rate == 1)
		printf("Unvoiced frames played at normal rate.\n\n");
	else
		printf("Unvoiced frames played at same rate as voiced 'uns.\n\n");
}

lpcinit()
{
	recsize=framsize*fprec;
	bprec=recsize*FLOAT;
	bpframe=framsize*FLOAT;
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.