📄 shorten.c
字号:
#endif /* initialize the seek table header and trailer */ SeekTableHeader.data[0]='S'; SeekTableHeader.data[1]='E'; SeekTableHeader.data[2]='E'; SeekTableHeader.data[3]='K'; ulong_to_uchar_le(SeekTableHeader.data+4,0); ulong_to_uchar_le(SeekTableHeader.data+8,0); SeekTableTrailer.data[4]='S'; SeekTableTrailer.data[5]='H'; SeekTableTrailer.data[6]='N'; SeekTableTrailer.data[7]='A'; SeekTableTrailer.data[8]='M'; SeekTableTrailer.data[9]='P'; SeekTableTrailer.data[10]='S'; SeekTableTrailer.data[11]='K'; strcpy(SeekTableFilename,""); /* this block just processes the command line arguments */ { int c; hs_resetopt(); while((c = hs_getopt(argc, argv, "a:b:c:d:ekhilm:n:p:q:r:sS:t:uv:x")) != -1) switch(c) { case 'a': if((nskip = atoi(hs_optarg)) < 0) usage_exit(1, "number of bytes to copy must be positive\n"); break; case 'b': if((blocksize = atoi(hs_optarg)) <= 0) usage_exit(1, "block size must be greater than zero\n"); break; case 'c': if((nchan = atoi(hs_optarg)) <= 0) usage_exit(1, "number of channels must be greater than zero\n"); break; case 'd': if((ndiscard = atoi(hs_optarg)) < 0) usage_exit(1, "number of bytes to discard must be positive\n"); break; case 'e': saw_e_op = TRUE; break; case 'i': saw_i_op = TRUE; break; case 'h':#ifdef _WINDOWS {#endif#define PRINTF0(a) fprintf(stderr,a)#define PRINTF1(a,b) fprintf(stderr,a,b)#define PRINTF2(a,b,c) fprintf(stderr,a,b,c)#define PRINTF3(a,b,c,d) fprintf(stderr,a,b,c,d) PRINTF2("%s version %s: (c) 1992-1999 Tony Robinson and SoftSound Ltd\n", PACKAGE, VERSION); PRINTF0("Seek extensions by Wayne Stielau; UNIX maintenance by Jason Jordan\n");/* PRINTF0("for more information see http://www.softsound.com/Shorten.html\n");*/#ifdef OLDHELP PRINTF1("usage: %s [-hx] [-a #byte] [-b #sample] [-c #channel] [-d #discard]\n\t[-m #block] [-p #delay] [-q #bit] [-r #bit] [-s] [-t filetype]\n\t[input file] [output file]\n", argv0);#endif PRINTF1("Usage: %s {options} [input file] [output file]\n", argv0); PRINTF1(" -a %-5d bytes to copy verbatim to align file\n", DEFAULT_NSKIP); PRINTF1(" -b %-5d block size\n", DEFAULT_BLOCK_SIZE); PRINTF1(" -c %-5d number of channels\n", DEFAULT_NCHAN); PRINTF1(" -d %-5d number of bytes to discard before compression or decompression\n", DEFAULT_NDISCARD); PRINTF0(" -e erase seek table appended to input file\n"); PRINTF0(" -h help (this message)\n"); PRINTF0(" -i inquire as to whether a seek table is appended to input file\n"); PRINTF0(" -k append seek table information to existing shorten file\n"); PRINTF0(" -l print the license giving the distribution and usage conditions\n"); PRINTF1(" -m %-5d number of past block for mean estimation\n",(FORMAT_VERSION < 2) ? DEFAULT_V0NMEAN : DEFAULT_V2NMEAN); PRINTF2(" -n %-5d minimum signal to noise ratio in dB (%d == lossless coding)\n",DEFAULT_MINSNR, DEFAULT_MINSNR); PRINTF1(" -p %-5d maximum LPC predictor order (0 == fast polynomial predictor)\n", DEFAULT_MAXNLPC); PRINTF1(" -q %-5d acceptable quantisation error in bits\n",DEFAULT_QUANTERROR); PRINTF2(" -r %-5s maximum number of bits per sample (%s == lossless coding)\n",DEFAULT_MAXRESNSTR, DEFAULT_MAXRESNSTR); PRINTF0(" -s generate seek table information in separate file [input file].skt\n"); PRINTF0(" -S[name] generate seek table information in separate file given by [name]\n"); PRINTF0(" -t wav specify the bit packing and byte ordering of the sample file from\n {aiff,wav,ulaw,alaw,s8,u8,s16,u16,s16x,u16x,s16hl,u16hl,s16lh,u16lh}\n"); PRINTF0(" -u merge the two zero codes in ulaw files\n"); PRINTF1(" -v %-5d format version number (2: no seek info; 3: default)\n", MAX_SUPPORTED_VERSION); PRINTF0(" -x extract (all other options except -a, -d and -t are ignored)\n");#ifdef _WINDOWS#ifdef WINDOWS_MESSAGEBOX MessageBox(NULL,totalMessage,"Shorten Help",MB_OK | MB_ICONINFORMATION); basic_exit(0);#else error_exit("%s: usage: %s {options} [input file] [output file]\n",argv0, argv0);#endif }#else basic_exit(0);#endif#undef PRINTF0#undef PRINTF1#undef PRINTF2#undef PRINTF3 break; case 'k': saw_k_op = TRUE; AppendSeekInfo=TRUE; extract = 1; WriteWaveFile=FALSE; WriteSeekTable=TRUE; if (!strcmp(SeekTableFilename,"")) SeekTableFilename[0]=0; break; case 'l': license(); basic_exit(0); break; case 'm': if((nmean = atoi(hs_optarg)) < 0) usage_exit(1, "number of blocks for mean estimation must be positive\n"); break; case 'n': if((minsnr = atoi(hs_optarg)) < 0) usage_exit(1, "Useful signal to noise ratios are positive\n"); break; case 'p': maxnlpc = atoi(hs_optarg); if(maxnlpc < 0 || maxnlpc > MAX_LPC_ORDER) usage_exit(1, "linear prediction order must be in the range 0 ... %d\n", MAX_LPC_ORDER); break; case 'q': if((quanterror = atoi(hs_optarg)) < 0) usage_exit(1, "quantisation level must be positive\n"); break; case 'r': maxresnstr = hs_optarg; break; case 'S': saw_S_op = TRUE; if (argv[hs_optind-1][0] != '-' || argv[hs_optind-1][1] != 'S') usage_exit(1, "missing seek table filename for -S\n"); else strcpy(SeekTableFilename,hs_optarg); extract = 1; WriteWaveFile=FALSE; WriteSeekTable=TRUE; break; case 's': saw_s_op = TRUE; extract = 1; WriteWaveFile=FALSE; WriteSeekTable=TRUE; SeekTableFilename[0]=0; break; case 't': if(!strcmp(hs_optarg, "au")) ftype = TYPE_GENERIC_ULAW; else if(!strcmp(hs_optarg, "ulaw")) ftype = TYPE_GENERIC_ULAW; else if(!strcmp(hs_optarg, "alaw")) ftype = TYPE_GENERIC_ALAW; else if(!strcmp(hs_optarg, "s8")) ftype = TYPE_S8; else if(!strcmp(hs_optarg, "u8")) ftype = TYPE_U8; else if(!strcmp(hs_optarg, "s16")) ftype = hilo?TYPE_S16HL:TYPE_S16LH; else if(!strcmp(hs_optarg, "u16")) ftype = hilo?TYPE_U16HL:TYPE_U16LH; else if(!strcmp(hs_optarg, "s16x")) ftype = hilo?TYPE_S16LH:TYPE_S16HL; else if(!strcmp(hs_optarg, "u16x")) ftype = hilo?TYPE_U16LH:TYPE_U16HL; else if(!strcmp(hs_optarg, "s16hl")) ftype = TYPE_S16HL; else if(!strcmp(hs_optarg, "u16hl")) ftype = TYPE_U16HL; else if(!strcmp(hs_optarg, "s16lh")) ftype = TYPE_S16LH; else if(!strcmp(hs_optarg, "u16lh")) ftype = TYPE_U16LH; else if(!strcmp(hs_optarg, "wav")) ftype = TYPE_RIFF_WAVE; else if(!strncmp(hs_optarg, "aiff", 3)) ftype = TYPE_AIFF; else usage_exit(1, "unknown file type: %s\n", hs_optarg); break; case 'u': ulawZeroMerge = 1; break; case 'v': version = atoi(hs_optarg); if(version < 0 || version > MAX_SUPPORTED_VERSION) usage_exit(1, "currently supported versions are in the range %d ... %d\n",MIN_SUPPORTED_VERSION, MAX_SUPPORTED_VERSION); break; case 'x': saw_x_op = TRUE; WriteWaveFile=TRUE; WriteSeekTable=FALSE; AppendSeekInfo=FALSE; extract = 1; break; default:#ifdef _WINDOWS usage_exit(1, "apparently too many file names\n"); /* mrhmod */#else usage_exit(1, NULL);#endif break; }/* end switch */ } check_conflicting_options(); /* If user specifies -v 2, don't append seeking data */ if (version <= 2) want_seeking = 0; else if (version > FORMAT_VERSION) version = FORMAT_VERSION; if(nmean == UNDEFINED_UINT) nmean = (version < 2) ? DEFAULT_V0NMEAN : DEFAULT_V2NMEAN; /* a few sanity checks */ if(blocksize <= NWRAP) usage_exit(1, "blocksize must be greater than %d\n", NWRAP); if(maxnlpc >= blocksize) usage_exit(1, "the predictor order must be less than the block size\n"); if(ulawZeroMerge == 1 && ftype != TYPE_GENERIC_ULAW) usage_exit(1, "the -u flag is only applicable to ulaw coding\n"); /* this chunk just sets up the input and output files */ nfilename = argc - hs_optind; switch(nfilename) { case 0:#ifndef MSDOS filenamei = minusstr; filenameo = minusstr;#else usage_exit(1, "must specify both input and output file when running under DOS\n");#endif break; case 1: { int oldfilelen, newfilelen, suffixlen, maxlen, dots; char *p; filenamei = argv[argc - 1]; filenamei_orig = filenamei; oldfilelen = strlen(filenamei); if (extract) { suffixlen = strlen(FILESUFFIX); newfilelen = oldfilelen - suffixlen; maxlen = oldfilelen + suffixlen; tmpfilename = pmalloc((ulong) (maxlen + 1)); strcpy(tmpfilename, filenamei); if (strcmp(tmpfilename,minusstr)) { if (newfilelen >= 0 &&#if defined(MSDOS) || defined(_WINDOWS) !stricmp(tmpfilename + newfilelen, FILESUFFIX))#else !strcasecmp(tmpfilename + newfilelen, FILESUFFIX))#endif { p = tmpfilename + oldfilelen - 1; dots = 0; while (dots < 2 && p >= tmpfilename && '/' != *p) { if ('.' == *p) dots++; p--; } if (dots >= 2) { *(tmpfilename+newfilelen) = 0; } else { strcpy(tmpfilename+newfilelen,WAVESUFFIX); } } else { strcat(tmpfilename,WAVESUFFIX); } } } else { suffixlen = strlen(WAVESUFFIX); newfilelen = oldfilelen - suffixlen; maxlen = oldfilelen + suffixlen; tmpfilename = pmalloc((ulong) (maxlen + 1)); strcpy(tmpfilename, filenamei); if (strcmp(tmpfilename,minusstr)) { if (newfilelen >= 0 &&#if defined(MSDOS) || defined(_WINDOWS) !stricmp(tmpfilename + newfilelen, WAVESUFFIX))#else !strcasecmp(tmpfilename + newfilelen, WAVESUFFIX))#endif { strcpy(tmpfilename+newfilelen,FILESUFFIX); } else { strcat(tmpfilename,FILESUFFIX); } } } filenameo = tmpfilename;#if defined (MSDOS) || defined (_WINDOWS) if (!saw_e_op && !saw_i_op) usage_exit(1, "must specify both input and output file when running under DOS\n");#endif break; } case 2: if (saw_e_op || saw_i_op || saw_k_op || saw_s_op || saw_S_op) usage_exit(1, "-e, -i, -k, -s or -S can only be used on one file at a time\n"); filenamei = argv[argc - 2]; filenameo = argv[argc - 1]; break; default: usage_exit(1, "too many filenames\n"); }StartAgain: if(strcmp(filenamei, minusstr)) { if((filei = fopen(filenamei, readmode)) == NULL) usage_exit(1, "could not open file '%s' for input\n", filenamei); if (saw_e_op || saw_i_op) { if (saw_i_op) fprintf(stderr,"file '%s' %s seek information.\n",filenamei,FileContainsSeekInfo(filei)?"contains":"does not contain"); else { if (!FileContainsSeekInfo(filei)) usage_exit(1,"file '%s' does not contain seek information\n",filenamei); RemoveSeekInfo(filenamei); } exit(0); } if(WriteSeekTable && 0 == SeekTableFilename[0]) { strcpy(SeekTableFilename,filenamei); if(0 == strcmp(filenamei+strlen(filenamei)-strlen(FILESUFFIX),FILESUFFIX)) memcpy(SeekTableFilename+strlen(filenamei)-3,"skt",3); else strcat(SeekTableFilename,".skt"); } } else { if (isatty(0)) usage_exit(1, "will not input data from a tty\n"); if (saw_e_op || saw_k_op || saw_i_op) usage_exit(1, "cannot use -e, -k or -i with data on standard input\n"); if (saw_s_op) strcpy(SeekTableFilename,"stdin.skt"); filei = stdi; SETBINARY_IN(filei); } if(strcmp(filenameo, minusstr)) { if(WriteSeekTable && extract && AppendSeekInfo) { if(FileContainsSeekInfo(filei)) usage_exit(1, "file '%s' already contains seek information\n", filenamei); } if(WriteWaveFile || (*filenameo && 0==Pass && !extract)) { if((fileo = fopen(filenameo, writemode)) == NULL) usage_exit(1, "could not open file '%s' for output\n", filenameo); } } else { if (((WriteWaveFile && extract) || (!WriteWaveFile && !extract)) && isatty(1)) usage_exit(1, "will not output data to a tty\n"); fileo = stdo; SETBINARY_OUT(fileo); } /* discard header on input file - can't rely on fseek() here */ if(ndiscard != 0) { char discardbuf[BUFSIZ]; for(i = 0; i < ndiscard / BUFSIZ; i++) { if(fread(discardbuf, BUFSIZ, 1, filei) != 1) usage_exit(1, "EOF on input when discarding header\n"); bytes_read++; } if(ndiscard % BUFSIZ != 0) { if(fread(discardbuf, ndiscard % BUFSIZ, 1, filei) != 1) usage_exit(1, "EOF on input when discarding header\n"); bytes_read++; } } if(0 == extract) { float *maxresn; int nread, nscan = 0, vbyte = MAX_VERSION + 1; char xiff[4]; /* read magic for AIFF or RIFF WAVE, or if not committed */ if(ftype == TYPE_EOF || ftype == TYPE_AIFF || ftype == TYPE_RIFF_WAVE) { if (4 != fread(xiff, sizeof(char), 4, filei)) usage_exit(1, "error reading magic from input file\n"); } /* auto test type for AIFF or RIFF WAVE if not already committed */ if(ftype == TYPE_EOF) { if (!strncmp(xiff, "FORM", 4)) ftype = TYPE_AIFF; else if (!strncmp(xiff, "RIFF", 4)) ftype = TYPE_RIFF_WAVE; } if(ftype == TYPE_AIFF) { int wtype; wavhdr = aiff_prochdr(filei, &ftype, &nchan, &datalen, &wtype); if (wavhdr == NULL) { if (wtype == 0) /* the header must have been invalid */ usage_exit(1, "input file is not a valid AIFF file\n"); else /* the bit depth is unsupported */ usage_exit(1, "This AIFF has %d-bit samples, which is currently unsupported\n", wtype); ftype = TYPE_EOF; } else { /* we have a valid AIFF so override anything the user may have said to do with the alignment */ nskip = 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -