home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / audio / SoundTime.lzh / SoundTime / src / SoundTime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-08  |  1.6 KB  |  77 lines

  1. #include <stdio.h>
  2. #include <utils.h>
  3. #include <fcntl.h>
  4.  
  5. char **nav, **opts;
  6. void bye();
  7.  
  8. main(int ac, char **av)
  9. {
  10.     int fp, nac, x, optnum;
  11.     char ftb[35], btw[40];
  12.     int byte1, byte2, sps, manual = 0;
  13.     float Ptime;
  14.  
  15.     if (ac < 2 || INQUIRY)    {
  16.         fprintf(stderr, "Usage: SoundTime [-s<sps>] <file> [file] ...\n");
  17.         exit(0);
  18.     }
  19.     if (!(nav = (char **)calloc(100, sizeof(char *))))    {
  20.         fprintf(stderr, "No mem for file array.\n");
  21.         exit(0);
  22.     }
  23.     if (!(opts = (char **)calloc(50, sizeof(char *))))    {
  24.         fprintf(stderr, "No mem for option array.\n");
  25.         bye();
  26.     }
  27.  
  28.     nac = match_args(ac, av, nav, 0, opts);
  29.     if (nac == -1)    {
  30.         fprintf(stderr, "CRITICAL memory shortage.  REBOOT.\n");
  31.         bye();
  32.     }
  33.     if (!nac)    {
  34.         fprintf(stderr, "No files specified.\n");
  35.         bye();
  36.     }
  37.  
  38.     if ((optnum = Opt(opts, "s")) != -1)    {
  39.         sps = atoi(OPTDATA(opts, optnum));
  40.         manual = 1;
  41.     }
  42.     else
  43.         sps = -1;
  44.     if (!sps)    {
  45.         fprintf(stderr, "%s is an invalid sps\n", OPTDATA(opts, optnum));
  46.         bye();
  47.     }
  48.     for (x = 0; x < nac; ++ x)    {
  49.         fp = open(nav[x], O_RDONLY);
  50.         if (fp == -1)    {
  51.             complain("%s: %s", av[0], nav[x]);
  52.             continue;
  53.         }
  54.         read(fp, ftb, 35);
  55.         if (strncmp(&ftb[0], "FORM", 4) && strncmp(&ftb[8], "8SVX", 4))    {
  56.             fprintf(stderr, "%s: %s: Not an 8SVX sound\n", av[0], nav[x]);
  57.             close(fp);
  58.             continue;
  59.         }
  60.         byte1 = ftb[32];
  61.         byte2 = ftb[33];
  62.         if (sps == -1)
  63.             sps = byte1 * 256 + byte2;
  64.         Ptime = (float)((float)SIZE(fp) / (float)sps);
  65.         sprintf(btw, " (at %d samples per second)", sps);
  66.         printf("%s: Playing time: %.2f seconds%s\n", nav[x], Ptime,
  67.          manual ? btw : "");
  68.         close(fp);
  69.     }
  70.     bye();
  71. }
  72. void bye()
  73. {
  74.     FREE_ARR(nav); FREE_ARR(opts);
  75.     exit(0);
  76. }
  77.