#include "config.h" #include #include #include #include #include "hd24fs.h" #include #include #include #ifndef WINDOWS #include #endif #include #include #include #include "convertlib.h" #define HEADERSIZE 44 #define SAMPLES_IN_HALF_BUF 1024*1024 #define SAMPLES_IN_FULL_BUF 2*SAMPLES_IN_HALF_BUF #define BYTES_PER_SAM 3 #define BYTES_IN_HALF_BUF BYTES_PER_SAM*SAMPLES_IN_HALF_BUF #define BYTES_IN_FULL_BUF BYTES_PER_SAM*SAMPLES_IN_FULL_BUF char audiobuf[BYTES_IN_FULL_BUF]; char fixbuf[BYTES_IN_HALF_BUF]; string inputfile; string outputfile; int simple=0; FILE* infile; FILE* outfile; __uint64 writeoffset; void clearaudiobuf() { int i; for (i=0;i=(1<<23)) { samval-=(1<<24); } return samval; } int topos(int samval) { return samval+(1<<23); } bool fileexists (string* fname) { struct stat fi; if ((stat (fname->c_str(), &fi) != -1) && ((fi.st_mode & S_IFDIR) == 0)) { return true; } return false; } void hd24seek(FSHANDLE devhd24,__uint64 seekpos) { #if defined(LINUX) || defined(DARWIN) lseek(devhd24,seekpos,0); // lseek64(devhd24,seekpos,0); #endif #ifdef WINDOWS LARGE_INTEGER li; li.HighPart=seekpos>>32; li.LowPart=seekpos%((__uint64)1<<32); SetFilePointerEx(devhd24,li,NULL,FILE_BEGIN); #endif return; } int parsecommandline(int argc, char ** argv) { int invalid=0; inputfile=""; outputfile=""; for (int c=1;c0) { int writecount=fwrite((const void*)&buffer[0],1,HEADERSIZE,outfile); if (writecount==0) { cout << "Cannot write output file" << endl; } } return; } void copyaudio(FILE* infile,FILE* outfile) { int readcount; do { shiftaudiobuf(); readcount=fread((void*)&audiobuf[BYTES_IN_HALF_BUF],1,BYTES_IN_HALF_BUF,infile); for (int i=0; i0) { int writecount=fwrite( (void*)&audiobuf[BYTES_IN_HALF_BUF],1,readcount,outfile); if (writecount==0) { cout << "Cannot write output file" << endl; } } } while (readcount>0); return; } void simplecopyaudio(FILE* infile,FILE* outfile) { int readcount; do { readcount=fread((void*)&audiobuf[BYTES_IN_HALF_BUF],1,BYTES_IN_HALF_BUF,infile); for (int i=0; i0) { int writecount=fwrite( (void*)&audiobuf[BYTES_IN_HALF_BUF],1,readcount,outfile); if (writecount==0) { cout << "Cannot write output file" << endl; } } } while (readcount>0); return; } void dothefix(FILE* infile, FILE* outfile) { copyheader(infile,outfile); findmask(infile); if (simple==1) { simplecopyaudio(infile,outfile); } else { copyaudio(infile,outfile); } } int main (int argc,char ** argv) { int invalid=parsecommandline(argc,argv); if (invalid!=0) { return invalid; } if ((inputfile=="")||(outputfile=="")) { cout << "Usage: hd24wavefix [--simple] --input= --output=" << endl; return 1; } clearaudiobuf(); // Open files infile=fopen(inputfile.c_str(),"rb"); outfile=fopen(outputfile.c_str(),"wb"); dothefix(infile,outfile); fclose(outfile); fclose(infile); return 0; }