home *** CD-ROM | disk | FTP | other *** search
/ Over Load / MAXIWIN7.ISO / programs / display / samples / play.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-14  |  2.4 KB  |  94 lines

  1. /**********************************************************/
  2. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  3. /*
  4. CAUTION: Compile using LARGE memory model!!!!!
  5. */
  6. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  7. /**********************************************************/
  8.  
  9. #include <stdio.h>
  10.  
  11. #include "xsnd.h"
  12.  
  13. /**********************************************************/
  14. /* basic block length (samples per block) */
  15. #define N 400
  16.  
  17. /* sampling rate */
  18. /*#define SRATE 8000*/
  19. #define SRATE 7500  /* shareware version only supports this */
  20.  
  21. /* raw binary audio file to play */
  22. #define FNAME "audio.raw"
  23.  
  24. /**********************************************************/
  25.  
  26. int main( void )
  27. {
  28.     FILE *f;
  29.     int err;
  30.     size_t n;
  31.     INT16 * p;    /* far ponter to 16 bit integer  */
  32.  
  33.  
  34.     printf("This programs just plays the 16 bit mono signed audio file\n"
  35.         "called " FNAME ".\n"
  36.         "Press ENTER to continue...");
  37.     fgetc(stdin);
  38.  
  39.     f = fopen(FNAME,"rb");
  40.     if (f==NULL) {
  41.         printf("can't open file!\n");
  42.         return 1;
  43.     }
  44.  
  45.     /* hardware reset the card. Needed to bring SB16 to sane state */
  46.     xsnd16_initialize();
  47.  
  48.     /* allocate SB resources */
  49.     /* In this example the interrupt time callback is not used, and
  50.     pooling mode is used instead. */
  51.     err=xsnd16_open(XSND_PLAY,  /* playback */
  52.             SRATE,  /* sampling rate */
  53.             XSND_MONO,  /* mono playback */
  54.             N,   /* basic block length */
  55.             4,   /* number of blocks to allocate */
  56.             NULL);  /* no user callback */
  57.  
  58.  
  59.     if (err) { /* xsnd16_open() return != 0 if error */
  60.         printf("can't open sb16!\n");
  61.         return 1;
  62.     }
  63.     xsnd16_start();  /* begins D/A conversion */
  64.  
  65.     while (1) {
  66.         /* get a pointer to next free block (NULL if none) */
  67.         p = xsnd16_getblk();
  68.  
  69.         if (p) {  /* if we got a valid pointer */
  70.             n = fread(p,sizeof(INT16),N,f);  /* read block from file */
  71.             if (n==N)  /* if max. block size could be read */
  72.                 xsnd16_addblk();  /* queue the block */
  73.             else {   /* if block is shorter than max. block size */
  74.                 xsnd16_addlastblk(n);  /* add a last and shorter block */
  75.                 break;  /* and exit */
  76.             }
  77.         }
  78.     }
  79.  
  80.     /* do not end playback process until all the blocks have been
  81.     played, i.e., until xsnd16_addlastblk actually blocks the process */
  82.     while (!xsnd16_blocked()) {
  83.         /* nothing */
  84.     }
  85.  
  86.     /* free resources */
  87.     xsnd16_close();
  88.     fclose(f);
  89.  
  90.     return 0;
  91. }
  92.  
  93. /**********************************************************/
  94.