#include #include #include #include #define nmax 100000 #define pi 3.14159265358979 FILE *out,*in; /* file of input parameter (*.txt) must be written as follows: .... where frequency as Hz, level as -dBV, decrement rate as -dBV/sec, and phase as radian. */ int header(unsigned long ssize); int main(int argc, char *argv[]){ int k,kj,kmax; double *ofr,*level,*redu,*ph,*cullevel,*culofr,*culredu,*first; double param1,param2,param3,param4; double amax,u; signed short int is; double levelsum,stdlevel; unsigned char table[1]; char outputfile[80],paramfile[80]; u=(2.9999999*2.0)/pow(2.0,16.0); levelsum=0.0; switch (argc) { case 1 : /* read parameters from Console */ printf("Input WAVE File Name.(Don't input extensions)\n"); scanf("%s",outputfile); printf("Input number of specturum\n"); scanf("%d",&kmax); if ((ofr=malloc(kmax*sizeof(double)))==NULL){ printf("\nOut of Memory Error!\n"); exit(1);}; if ((level=malloc(kmax*sizeof(double)))==NULL){ printf("\nOut of Memory Error!\n"); exit(1);}; if ((redu=malloc(kmax*sizeof(double)))==NULL){ printf("\nOut of Memory Error!\n"); exit(1);}; if ((ph=malloc(kmax*sizeof(double)))==NULL){ printf("\nOut of Memory Error!\n"); exit(1);}; printf("Input Freq, Level, R, phase\n"); for (kj=0; kj=0; k--){ amax=0; for (kj=0; kj> 8; table[0]=(unsigned char)is; fwrite(table,sizeof(short),1,out); } /* main decay */ for (k=1; k<=nmax-1765; k++){ amax=0; for (kj=0; kj> 8; table[0]=(unsigned char)is; fwrite(table,sizeof(short),1,out); } close(out); free(ofr); free(level); free(redu); free(ph); free(cullevel); free(culofr); free(culredu); free(first); return(0); } int header(unsigned long ssize){ /* Microsoft Windows Waveform File Header */ unsigned char ckSize[3],vchar[1],vdchar[3]; unsigned long vdw; unsigned short vw; char ck[5]; char *str1 = "RIFF"; char *str2 = "WAVE"; char *str3 = "fmt "; char *str4 = "data"; /* RIFF chank */ strcpy(ck,str1); fwrite(ck,sizeof(long),1,out); ckSize[0]=(unsigned char)(ssize*2+36); ckSize[1]=(ssize*2+16) >> 8; ckSize[2]=(ssize*2+16) >> 16; ckSize[3]=(ssize*2+16) >> 24; fwrite(ckSize,sizeof(long),1,out); /* WAVE chank */ strcpy(ck,str2); fwrite(ck,sizeof(int),1,out); /* format chank */ strcpy(ck,str3); fwrite(ck,sizeof(int),1,out); vdw=16; ckSize[0]=(unsigned char)vdw; ckSize[1]=vdw >> 8; ckSize[2]=vdw >> 16; ckSize[3]=vdw >> 24; fwrite(ckSize,sizeof(long),1,out); /* Wave Format */ vw=1; /* wFormatTag */ vchar[0]=(unsigned char)vw; vchar[1]=vw >> 8; fwrite(vchar,sizeof(short),1,out); vw=1; /* nChannels */ vchar[0]=(unsigned char)vw; vchar[1]=vw >> 8; fwrite(vchar,sizeof(short),1,out); vdw=44100; /* nSamplesPerSec */ vdchar[0]=(unsigned char)vdw; vdchar[1]=vdw >> 8; vdchar[2]=vdw >> 16; vdchar[3]=vdw >> 24; fwrite(vdchar,sizeof(long),1,out); vdw=88200; /* nAvgBytesPerSec */ vdchar[0]=(unsigned char)vdw; vdchar[1]=vdw >> 8; vdchar[2]=vdw >> 16; vdchar[3]=vdw >> 24; fwrite(vdchar,sizeof(long),1,out); vw=2; /* nBlockAlign */ vchar[0]=(unsigned char)vw; vchar[1]=vw >> 8; fwrite(vchar,sizeof(short),1,out); /* FormatSpecific */ vw=16; /* nBitsPerSample */ vchar[0]=(unsigned char)vw; vchar[1]=vw >> 8; fwrite(vchar,sizeof(short),1,out); /* data chank */ strcpy(ck,str4); fwrite(ck,sizeof(int),1,out); ckSize[0]=(unsigned char)(ssize*2); ckSize[1]=(ssize*2) >> 8; ckSize[2]=(ssize*2) >> 16; ckSize[3]=(ssize*2) >> 24; fwrite(ckSize,sizeof(long),1,out); return (0); }