#include #include void main(argc, argv) int argc; char *argv[]; { FILE *f, *g; short words[16384]; int a, start=0, end=0; /* try to open the audio file */ if(argc != 3) exit(1); if(!(f=fopen(argv[1], "r"))) { perror(argv[1]); exit(1); } if(!(g=fopen(argv[2], "w"))) { perror(argv[2]); exit(1); } fseek(f, 100, SEEK_SET); while(!start && fread(words, 2, 16384, f)) for(a=0;a<16384;a+=2) if(words[a] < -500 || words[a] > 500 || words[a+1] < -500 || words[a+1] > 500) { start=ftell(f)-(32768-(a*2)); break; } fseek(f, -32768, SEEK_END); while(!end) { fread(words, 2, 16384, f); for(a=16382;a>=0;a-=2) if(words[a] < -500 || words[a] > 500 || words[a+1] < -500 || words[a+1] > 500) { end=(ftell(f)-(32768-(a*2)))-start; break; } fseek(f, -65536, SEEK_CUR); } printf("Start: %d. Length: %d\n", start, end); fseek(f, start, SEEK_SET); while((a=fread(words, 1, (end > 32768)?32768:end, f))) { fwrite(words, 1, a, g); if((end-=32768) < 0) end=0; } fflush(g); }