home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / windows3 / mtlabsnd.zip / SKEL.C < prev    next >
Text File  |  1993-04-26  |  3KB  |  136 lines

  1. /*
  2.  * July 5, 1991
  3.  * Copyright 1991 Lance Norskog 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.  * Lance Norskog And Sundry Contributors are not responsible for 
  7.  * the consequences of using this software.
  8.  */
  9.  
  10. /*
  11.  * Sound Tools skeleton file format driver.
  12.  */
  13.  
  14. #include "st.h"
  15.  
  16. /* Private data for SKEL file */
  17. typedef struct skelstuff {
  18.     int    rest;            /* bytes remaining in current block */
  19. } *skel_t;
  20.  
  21. extern float volume, amplitude;
  22. extern int summary, verbose;
  23.  
  24. /*
  25.  * Do anything required before you start reading samples.
  26.  * Read file header. 
  27.  *    Find out sampling rate, 
  28.  *    size and style of samples, 
  29.  *    mono/stereo/quad.
  30.  */
  31. skelstartread(ft) 
  32. ft_t ft;
  33. {
  34.     skel_t sk = (skel_t) ft->priv;
  35.  
  36.     /* If you need to seek around the input file. */
  37.     if (! ft->seekable)
  38.         fail("SKEL input file must be a file, not a pipe");
  39.  
  40.     /*
  41.      * If your format specifies or your file header contains
  42.      * any of the following information. 
  43.      */
  44.     ft->rate = 
  45.     ft->size = BYTE or WORD ...;
  46.     ft->style = UNSIGNED or SIGN2 ...;
  47.     ft->channels = 1 or 2 or 4;
  48. }
  49.  
  50. /*
  51.  * Read up to len samples from file.
  52.  * Convert to signed longs.
  53.  * Place in buf[].
  54.  * Return number of samples read.
  55.  */
  56.  
  57. skelread(ft, buf, len) 
  58. ft_t ft;
  59. long *buf, len;
  60. {
  61.     skel_t sk = (skel_t) ft->priv;
  62.     int abs;
  63.     float amp;
  64.     int done = 0;
  65.     
  66.     char c;
  67.     unsigned char uc;
  68.     short s;
  69.     unsigned short us;
  70.     long l;
  71.     unsigned long ul;
  72.     float f;
  73.     double d;
  74.  
  75.     for(; done < len; done++) {
  76.         if no more samples
  77.             break
  78.         get a sample
  79.         l = sample converted to signed long
  80.         *buf++ = l;
  81.     }
  82.     return done;
  83. }
  84.  
  85. /*
  86.  * Do anything required when you stop reading samples.  
  87.  * Don't close input file! 
  88.  */
  89. skelstopread(ft) 
  90. ft_t ft;
  91. {
  92. }
  93.  
  94. skelstartwrite(ft) 
  95. ft_t ft;
  96. {
  97.     skel_t sk = (skel_t) ft->priv;
  98.  
  99.     /* If you have to seek around the output file */
  100.     if (! ft->seekable)
  101.         fail("Output .skel file must be a file, not a pipe");
  102.  
  103.     /* If your format specifies any of the following info. */
  104.     ft->rate = 
  105.     ft->size = BYTE or WORD ...;
  106.     ft->style = UNSIGNED or SIGN2 ...;
  107.     ft->channels = 1 or 2 or 4;
  108.     /* Write file header, if any */
  109.     
  110. }
  111.  
  112. skelwrite(ft, buf, len) 
  113. ft_t ft;
  114. long *buf, len;
  115. {
  116.     skel_t sk = (skel_t) ft->priv;
  117.     register int datum;
  118.     int abs;
  119.     int done = 0;
  120.  
  121.     while(len--)
  122.         putc((*buf++ >> 24) ^ 0x80, ft->fp);
  123.     /* If you cannot write out all of the supplied samples, */
  124.     /*    fail("SKEL: Can't write all samples to %s", ft->filename); */
  125.     
  126. }
  127.  
  128. skelstopwrite(ft) 
  129. ft_t ft;
  130. {
  131.     /* All samples are already written out. */
  132.     /* If file header needs fixing up, for example it needs the */
  133.      /* the number of samples in a field, seek back and write them here. */
  134. }
  135.  
  136.