// $Id: wavlength.cc 750 2006-08-26 18:41:32Z flaterco $ // Determine length in minutes:seconds of a collecton of 44.1 kHz wav files. // // Usage: wavlength file [file...] // // g++ -O2 -Wall -Wextra -pedantic -s -o wavlength wavlength.cc #include #include #include #include #include #include // Return length in seconds. double lengthofwav (char *fname) { struct stat s; if (stat (fname, &s) != 0) { perror (fname); exit (-1); } if (s.st_size < 44) { fprintf (stderr, "%s: too short to be a wav file\n", fname); exit (-1); } // wav files from sox and normalize have 44 bytes of header. // 1 second = 44100 samples * 2 channels * 16 bits = 176400 bytes. return (double)(s.st_size - 44) / 176400.0; } int main (int argc, char **argv) { if (argc < 2) { fprintf (stderr, "wavlength file [file...]\n"); exit (-1); } double len = 0.0; for (int i=1; i