www.pudn.com > WAV_DAT.rar > WAV_DAT.CPP, change:1996-11-18,size:1444b


 
    /*--------------------------------------------------------------- 
 
		    C language program : WAV_DAT.CPP 
 
			Oct. 15, 1996 via B.C.C 
    -----------------------------------------------------------------*/ 
#include <stdio.h> 
#include <math.h> 
#include <stdlib.h> 
 
#define  FRAMESIZE   200 
 
/*--------------------- main progrom -----------------------------------*/ 
 
void main(int argc,char *argv[]) 
{ 
 FILE *fp1,*fp2; 
 int wav[44],x,speech[200],j; 
 float spe[200],sum,bias; 
 if(argc!=3) { 
 printf("you forgot to type your filename\n"); 
 exit(1); 
   } 
/*............ read in speech singal................*/ 
 
 if((fp1=fopen(argv[1],"rb"))==NULL) 
   { 
      printf("can't open the  input data file!\n"); 
      exit(1); 
    } 
 if((fp2=fopen(argv[2],"wb"))==NULL) 
   { 
     printf("can't open the output data file!\n"); 
     exit(1); 
   } 
 
  fread(wav,2,22,fp1); 
 
  while(!feof(fp1)) 
   { 
    for(j=0;j<FRAMESIZE;j++) 
    { 
      if(!feof(fp1)) 
      { 
	fread(&x,sizeof(int),1,fp1); 
	spe[j]=(float)x/16.0; 
	} 
      else exit(0); 
     } 
    sum=0.0; 
    for(j=0;j<FRAMESIZE;j++) 
     sum=sum+spe[j]; 
    bias=sum/FRAMESIZE; 
 
    for(j=0;j<FRAMESIZE;j++) 
    { 
     speech[j]=(int)(spe[j]-bias); 
     if(speech[j]<-2047) speech[j]=-2047; 
     if(speech[j]>2048)  speech[j]=2048; 
     } 
    fwrite(speech,sizeof(int),FRAMESIZE,fp2); 
      } 
   fclose(fp1); 
   fclose(fp2); 
    }