#include #include #include #include /* ================================================================= */ #define FRAMESIZE 80 #define OBSDIM 25 #define OBSTYPE 454 /* MFCC_E_D_N */ #define SAMPRATE 8000.0 #define SAMPSIZE sizeof(short) /* --- Defines the ISOLET header structure --- */ /**/ typedef struct { short hdrsize; short version; short channels; short rate; int nsamples; short endian; } header; header ISOLET; /* The ISOLET database's header */ /* ================================================================= */ main(argc,argv) int argc; char *argv[]; { FILE *fpi; FILE *fpo; struct stat filerec; char *infile; char *outfile; short *inbuf; short *outbuf; short *vcflag,x; float samprate; double srate=8000.0; /* default sampling frequency */ int sampsize; int framesize; int numsamples; int numobs; int obsdim; short osize=2; /* Bytes per sample */ short otype=0; /* Waveform type */ int isolet=0; int oflag=0; int rint=0, NBYTES=0; int sint=0; int sflag=0; int tflag=0; int i,j,k,m; /* === parse the command line === */ if (argc==1){ printf("Usage: adheader [options] infile outfile\n\n"); printf("Options Default\n"); printf("-r F Set sampling frequency to F 8000 Hz\n"); printf("-t Add an ISOLET header HTK\n"); printf("-s K Skip K bytes 0\n\n"); exit(1); } if(!scanargs(argc,argv,"adheader r%-srate!F s%-bytes!D t%- infile!s outfile!s",&rint,&srate,&sint,&NBYTES,&isolet,&infile,&outfile)) exit(1); /* === open output observation file === */ fpi = fopen(infile,"rb"); if (fpi == NULL) { printf("Error: Unable to open input observation file (%s).\n",infile); exit(1); } /* === compute number of samples in file === */ k = fileno(fpi); fstat(k,&filerec); numsamples = filerec.st_size/sizeof(short); /* === open output file === */ fpo = fopen(outfile,"wb"); if (fpo == NULL) { printf("Error: Unable to create observation file (%s).\n",outfile); exit(1); } if (sint==1) /* Skip bytes */{ fseek(fpi,NBYTES,0); numsamples = numsamples-NBYTES*2; } /* === allocate space for observations and read them === */ inbuf = (short *) malloc(numsamples*sizeof(short)); k=fread(inbuf,sizeof(short),numsamples,fpi); /* === write observation file header === */ if (isolet) { ISOLET.nsamples = numsamples; x= 1000000.0/(srate*0.25); ISOLET.rate=x; ISOLET.hdrsize=8; ISOLET.version=1; ISOLET.channels=1; ISOLET.endian=0; fwrite(&ISOLET,1,sizeof(ISOLET),fpo); } else { fwrite(&numsamples,sizeof(int),1,fpo); /* number of observations */ i = 10.0e+6/srate; fwrite(&i,sizeof(int),1,fpo); /* frame rate sec/frm (x100 nS) */ fwrite(&osize,sizeof(short),1,fpo); /* bytes per feature */ fwrite(&otype,sizeof(short),1,fpo); /* (htk) type of feature */ } /* === write output file === */ fwrite(inbuf,numsamples,sizeof(short),fpo); fclose(fpo); }