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

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

#include <stdio.h>
#define FLOAT 4

main()
{
        int j,length,fft,npoints,i;
        char array[80];
	int range = 72;
	float xmax,xmin,freq,sr;
	float vals[2048]; 
	char  output[32];

	fprintf(stderr," Enter name of fft file\t");
	scanf("%s",output);

	if((fft = open(output,0)) < 0) {
		fprintf(stderr," Can't open fft file\n");
		exit(1);
		}
	fprintf(stderr," Enter length of fft\t");
	scanf("%d",&length);
	fprintf(stderr," Enter sampling rate\t");
	scanf("%f",&sr);
	if(read(fft,(char *)vals,length*FLOAT) != length*FLOAT) {
			printf(" bad read\n");
			exit(1);
			}
	xmax=0;
	xmin=99999999.;
	for(i=0;i<length;i++) {
		if(vals[i] > xmax) xmax = vals[i];
		if(vals[i] < xmin) xmin = vals[i];
		}
	for(i=0;i<length;i++) {
		npoints = ((vals[i]-xmin)/(xmax-xmin)) * range;
		freq =((float)i/length)* (sr/2.);
		printf("%6.2f",freq);
		for(j=0;j<npoints;j++) printf("-");
		printf("\n");
		}

	for(i=0;i<length;i++) printf("%d %f\n",i,vals[i]);
}

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