home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Sound / SoX / Source / auto.c < prev    next >
C/C++ Source or Header  |  1999-07-18  |  2KB  |  84 lines

  1. /*
  2.  * May 19, 1992
  3.  * Copyright 1992 Guido van Rossum And Sundry Contributors
  4.  * This source code is freely redistributable and may be used for
  5.  * any purpose.  This copyright notice must be maintained. 
  6.  * Guido van Rossum And Sundry Contributors are not responsible for 
  7.  * the consequences of using this software.
  8.  */
  9.  
  10. /*
  11.  * A meta-handler that recognizes most file types by looking in the
  12.  * first part of the file.  The file must be seekable!
  13.  * (IRCAM sound files are not recognized -- these don't seem to be
  14.  * used any more -- but this is just laziness on my part.) 
  15.  */
  16.  
  17. #include "st.h"
  18. #include <string.h>
  19.  
  20. IMPORT void gettype();
  21.  
  22. void autostartread(ft)
  23. ft_t ft;
  24. {
  25.     char *type;
  26.     char header[132];
  27.     if (!ft->seekable)
  28.         fail("Type AUTO input must be a file, not a pipe");
  29.     if (fread(header, 1, sizeof header, ft->fp) != sizeof header)
  30.         fail("Type AUTO detects short file");
  31.     fseek(ft->fp, 0L - sizeof header, 1); /* Seek back */
  32.     type = 0;
  33.     if ((strncmp(header, ".snd", 4) == 0) ||
  34.         (strncmp(header, "dns.", 4) == 0) ||
  35.         ((header[0] == '\0') && (strncmp(header+1, "ds.", 3) == 0))) {
  36.         type = "au";
  37.     }
  38.     else if (strncmp(header, "FORM", 4) == 0) {
  39.         if (strncmp(header + 8, "AIFF", 4) == 0)
  40.             type = "aiff";
  41.         else if (strncmp(header + 8, "8SVX", 4) == 0)
  42.             type = "8svx";
  43.         else if (strncmp(header + 8, "MAUD", 4) == 0)
  44.             type = "maud";
  45.     }
  46.     else if (strncmp(header, "RIFF", 4) == 0 &&
  47.          strncmp(header + 8, "WAVE", 4) == 0) {
  48.         type = "wav";
  49.     }
  50.     else if (strncmp(header, "Creative Voice File", 19) == 0) {
  51.         type = "voc";
  52.     }
  53.     else if (strncmp(header+65, "FSSD", 4) == 0 &&
  54.          strncmp(header+128, "HCOM", 4) == 0) {
  55.         type = "hcom";
  56.     }
  57.     else if (strncmp(header, "SOUND", 5) == 0) {
  58.         type = "sndt";
  59.     }
  60.     else if (header[0] == 0 && header[1] == 0) {
  61.         int rate = (header[2] & 0xff) + ((header[3] & 0xff) << 8);
  62.         if (rate >= 4000 && rate <= 25000)
  63.             type = "sndr";
  64.     }
  65.       if (type == 0) {
  66.           printf("Type AUTO doesn't recognize this header\n");
  67.                 printf("Trying: -t raw -r 11000 -b -u\n\n");
  68.                 type = "raw";
  69.                 ft->info.rate = 11000;
  70.                 ft->info.size = BYTE;
  71.                 ft->info.style = UNSIGNED;
  72.                 }
  73.     report("Type AUTO changed to %s", type);
  74.     ft->filetype = type;
  75.     gettype(ft); /* Change ft->h to the new format */
  76.     (* ft->h->startread)(ft);
  77. }
  78.  
  79. void autostartwrite(ft) 
  80. ft_t ft;
  81. {
  82.     fail("Type AUTO can only be used for input!");
  83. }
  84.