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

  1. #ifdef    i386
  2. /*
  3.  * Copyright 1992 Rick Richardson
  4.  * Copyright 1991 Lance Norskog And Sundry Contributors
  5.  * This source code is freely redistributable and may be used for
  6.  * any purpose.  This copyright notice must be maintained. 
  7.  * Rick Richardson, Lance Norskog And Sundry Contributors are not
  8.  * responsible for the consequences of using this software.
  9.  */
  10.  
  11. /*
  12.  * Direct to Sound Blaster device driver.
  13.  */
  14.  
  15. #include "st.h"
  16. #include <sys/types.h>
  17. #include <sys/sb.h>
  18. #include <signal.h>
  19.  
  20. /* Private data for SKEL file */
  21. typedef struct sbdspstuff {
  22.     int    samples;        /* bytes remaining in current block */
  23. } *sbdsp_t;
  24.  
  25. extern float volume, amplitude;
  26. extern int summary, verbose;
  27.  
  28. static got_int = 0;
  29.  
  30. static void
  31. sigint(s)
  32. {
  33.     if (s) got_int = 1;
  34.     else signal(SIGINT, sigint);
  35. }
  36.  
  37. /*
  38.  * Do anything required before you start reading samples.
  39.  * Read file header. 
  40.  *    Find out sampling rate, 
  41.  *    size and style of samples, 
  42.  *    mono/stereo/quad.
  43.  */
  44. sbdspstartread(ft) 
  45. ft_t ft;
  46. {
  47.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  48.  
  49.     /* If you need to seek around the input file. */
  50.     if (0 && ! ft->seekable)
  51.         fail("SKEL input file must be a file, not a pipe");
  52.  
  53.     if (!ft->info.rate)
  54.         ft->info.rate = 11000;
  55.     ft->info.size = BYTE;
  56.     ft->info.style = UNSIGNED;
  57.     ft->info.channels = 1;
  58.     ioctl(fileno(ft->fp), DSP_IOCTL_RESET, 0);
  59.     ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, 0);
  60.     ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, ft->info.rate);
  61.     sigint(0);    /* Prepare to catch SIGINT */
  62. }
  63.  
  64. /*
  65.  * Read up to len samples from file.
  66.  * Convert to signed longs.
  67.  * Place in buf[].
  68.  * Return number of samples read.
  69.  */
  70.  
  71. sbdspread(ft, buf, len) 
  72. ft_t ft;
  73. long *buf, len;
  74. {
  75.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  76.     int        rc;
  77.  
  78.     if (got_int) return (0);
  79.     rc = rawread(ft, buf, len);
  80.     if (rc < 0) return 0;
  81.     return (rc);
  82. }
  83.  
  84. /*
  85.  * Do anything required when you stop reading samples.  
  86.  * Don't close input file! 
  87.  */
  88. sbdspstopread(ft) 
  89. ft_t ft;
  90. {
  91.     /* ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0); */
  92. }
  93.  
  94. sbdspstartwrite(ft) 
  95. ft_t ft;
  96. {
  97.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  98.  
  99.     /* If you have to seek around the output file */
  100.     if (0 && ! ft->seekable)
  101.         fail("Output .sbdsp file must be a file, not a pipe");
  102.  
  103.     if (!ft->info.rate)
  104.         ft->info.rate = 11000;
  105.     ft->info.size = BYTE;
  106.     ft->info.style = UNSIGNED;
  107.     ft->info.channels = 1;
  108.     ioctl(fileno(ft->fp), DSP_IOCTL_RESET, 0);
  109.     /* ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0); */
  110.     ioctl(fileno(ft->fp), DSP_IOCTL_VOICE, 1);
  111.     ioctl(fileno(ft->fp), DSP_IOCTL_SPEED, ft->info.rate);
  112. }
  113.  
  114. sbdspwrite(ft, buf, len) 
  115. ft_t ft;
  116. long *buf, len;
  117. {
  118.     sbdsp_t sbdsp = (sbdsp_t) ft->priv;
  119.  
  120.     if (len == 0) return 0;
  121.     return (rawwrite(ft, buf, len));
  122. }
  123.  
  124. sbdspstopwrite(ft) 
  125. ft_t ft;
  126. {
  127.     /* All samples are already written out. */
  128.     /* If file header needs fixing up, for example it needs the */
  129.      /* the number of samples in a field, seek back and write them here. */
  130.     fflush(ft->fp);
  131.     ioctl(fileno(ft->fp), DSP_IOCTL_FLUSH, 0);
  132. }
  133. #endif
  134.