#include #include #include void main( int argc, char *argv[ ]) { FILE *infile, *outfile; char prefix[4]; char fileFormat[8]; unsigned char ch; float byteValue; char ckID[4]; unsigned long nChunkSize; short int wFormatTag; short int nChannels; unsigned long nSamplesPerSecond; unsigned long nAvgBytesPerSecond; short int nBlockAlign; short int nBitsPerSample; unsigned long i; unsigned long byteCount, oldbyteCount; double factor, slideFactor; char *stopstring; /* Print a copyright. */ printf("WAV to Raw ASCII file Conversion Utility\n"); printf(" Copyright: Dan Kennedy. All are free to use this.\n\n"); /* Test for two files and a factor as arguments */ if (argc != 4) { printf("Usage: wav2raw sourceWavFile destRawFile dechirpFactor\n"); printf("Success returns errorlevel 0. Error return greater than zero.\n"); exit(1); } /* Open source for binary read (will fail if file does not exist) */ if( (infile = fopen( argv[1], "rb" )) == NULL ) { printf( "The source file %s was not opened\n",argv[1] ); exit(2); } else printf( "The source file %s was opened\n",argv[1] ); /* Open output for write */ if( (outfile = fopen( argv[2], "w" )) == NULL ) { printf( "The output file %s was not opened\n",argv[2] ); exit(3); } else printf( "The output file %s was opened\n",argv[2] ); factor = strtod(argv[3],&stopstring); /* Read the header bytes. */ /* The numeric values are distorted for big-endian processors. */ for ( i = 0; (i < 40);i++ ) { fscanf( infile, "%c", &ch ); fprintf(outfile,"%c",ch); } /* Scan in the 4 byte integer. */ nChunkSize = 0; for ( i = 0; (i < 4);i++ ) { fscanf( infile, "%c", &ch ); fprintf(outfile,"%c",ch); nChunkSize = (unsigned long)(nChunkSize + ch*pow(2,i*8)); } /* Testing on the file format variables would go here. */ /* At least ckID should say 'data' */ /* Scan and convert the bytes. */ byteCount = 0; oldbyteCount = 0; for( i = 0; (i < nChunkSize);i++ ) { slideFactor = (i/(double)nChunkSize)*factor; byteCount = (unsigned long) (i*(1+slideFactor)); fscanf( infile, "%1c", &ch ); if (byteCount>oldbyteCount) { do { fprintf(outfile,"%c",ch); oldbyteCount = oldbyteCount+1; } while (byteCount > oldbyteCount); } } /* All files are closed: */ _fcloseall( ); exit(0); }