home *** CD-ROM | disk | FTP | other *** search
/ Over Load / MAXIWIN7.ISO / programs / display / samples / rec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-14  |  2.5 KB  |  102 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. too sort ==> too much interrupts per second. */
  16. #define N 200
  17.  
  18. /* sampling rate */
  19. /*#define SRATE 8000*/
  20. #define SRATE 7500  /* shareware version only supports this */
  21.  
  22. /* samples to record */
  23. #define NSAMPLES 31345
  24.  
  25. /* raw binary audio file to play */
  26. #define FNAME "audio.raw"
  27.  
  28. /**********************************************************/
  29.  
  30. int main( void )
  31. {
  32.     FILE *f;
  33.     int err;
  34.     UINT32 nrec;  /* samples left to rec */
  35.     INT16 * p;  /* far pointer to 16 bit integer */
  36.  
  37.     printf("This programs just records a fixed number of mono\n"
  38.         "16 bit signed audio samples to a file named " FNAME ".\n"
  39.         "Use the example named PLAY.C to play this file.\n"
  40.         "Press ENTER to continue...");
  41.     fgetc(stdin);
  42.  
  43.     f = fopen(FNAME,"wb");
  44.     if (f==NULL) {
  45.         printf("can't open file!\n");
  46.         return 1;
  47.     }
  48.  
  49.     /* sane state for SB16 */
  50.     xsnd16_initialize();
  51.  
  52.     /* allocate SB16 resources */
  53.     /* The interrupt time callback is not used. Pooling mode
  54.     is used instead. */
  55.     err=xsnd16_open(XSND_RECORD,  /* record */
  56.             SRATE,       /* sampling rate */
  57.             XSND_MONO,   /* mono recording */
  58.             N,          /* block length */
  59.             4,          /* number of blocks */
  60.             NULL);    /* no user callback */
  61.  
  62.     if (err) {    /* if error */
  63.         printf("can't open sb16!\n");
  64.         return 1;
  65.     }
  66.  
  67.     nrec = NSAMPLES; /* initialize samples left */
  68.  
  69.     /* first we add as many free blocks to the recording queue as
  70.     possible. */
  71.     while (!xsnd16_addblk());
  72.  
  73.     xsnd16_start();  /* start recording */
  74.  
  75.     while (1) {
  76.         /* try to get a recorded block (NULL if not ready yet) */
  77.         p = xsnd16_getblk();
  78.  
  79.         /* if we got a valid block, save it */
  80.         if (p) {
  81.             if (nrec>N) {  /* save the whole block if nrec>N */
  82.                 fwrite(p,sizeof(INT16),N,f);
  83.                 nrec -= N;
  84.             }
  85.             else {  /* save the last block (posibly sorter than N) */
  86.                 fwrite(p,sizeof(INT16),(UINT16)nrec,f);
  87.                 break;
  88.             }
  89.         /* after saving the block, put it again to the recording queue */
  90.         xsnd16_addblk();
  91.         }
  92.     }
  93.  
  94.     /* free resources */
  95.     xsnd16_close();
  96.     fclose(f);
  97.  
  98.     return 0;
  99. }
  100.  
  101. /**********************************************************/
  102.