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

  1. /**********************************************************/
  2. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  3. /*
  4. CAUTION: Compile using LARGE memory model!!!!!
  5. */
  6. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  7. /**********************************************************/
  8.  
  9. #include <stdio.h>
  10.  
  11. #include "sb16io.h"
  12.  
  13. /**********************************************************/
  14. /* basic block length (samples per block):
  15. too sort ==> too much interrupts per second.
  16. too long ==> too much record-to-playback delay.
  17.  
  18. The blockleght N implies 'logical samples', so that in stereo
  19. mode, N stereo logical 16bit samples are actually N*2 16 bit
  20. samples.
  21. A stereo logical sample is (left+right) channels sample. */
  22. /*#define N 200 */
  23. #define N 4096   /* Shareware version only supports this */
  24.  
  25. /* sampling rate */
  26. /*#define SRATE 8000*/
  27. #define SRATE 7500  /* Shareware version only supports this */
  28.  
  29. /**********************************************************/
  30. /* callback function. whenever a new block (length N) is full,
  31. this callback is called (at interrupt-time, so be carefull with
  32. what you do!). */
  33.  
  34. void mifunc( void )
  35. {
  36.     UINT i;
  37.     INT8 * v8;
  38.     INT16 * v16;
  39.  
  40.     v8 = sb16io_get8(SB16IO_NOWAIT);  /* get SB 8 bits buffer */
  41.     v16 = sb16io_get16(SB16IO_NOWAIT);  /* get SB 16 bits buffer */
  42.     /* we have used NOWAIT mode, because we are at interrupt time!!
  43.     moreover, this callback has been called because there is a new
  44.     recorded buffer. */
  45.  
  46.     /* copy half buffer to left channel, and the other half, to
  47.     right chanel */
  48.  
  49.     /* we asume N is even!! */
  50.  
  51.     /* first half buffer to left channel, and 0 to right channel */
  52.     for (i=0; i<N/2; i++) {
  53.         v16[i*2] = (((INT16)v8[i]) << 8);  /* left */
  54.         v16[i*2+1] = 0;                    /* right */
  55.     }
  56.     /* second half buffer to right channel, and 0 to left channel */
  57.     for (i=N/2; i<N; i++) {
  58.         v16[i*2] = 0;        /* left */
  59.         v16[i*2+1] = (((INT16)v8[i]) << 8);  /* right */
  60.     }
  61. }
  62.  
  63. /**********************************************************/
  64.  
  65. int main( void )
  66. {
  67.     int err;
  68.  
  69.     printf("Sample program to record & play concurrently using SB16.\n"
  70.         "In this program, recording is done using 8 bit MONO signed samples\n"
  71.         "and playback using 16 bit STEREO signed samples.\n"
  72.         "The recorded mono samples are alternatively sent to left\n"
  73.         "and right playback channel in short blocks.\n"
  74.         "Press ENTER to continue...");
  75.     fgetc(stdin);
  76.  
  77.     /* prepare sb16 */
  78.     err = sb16io_open(SB16IO_RECORD8,  /* 8 bit record & 16 bit playback */
  79.             SRATE,    /* sampling rate (must be the same for 8 & 16 bits) */
  80.             SB16IO_MONO8,  /* mono 8 bit (recording) */
  81.             SB16IO_STEREO16,  /* mono 16 bit (playback) */
  82.             N,             /* basic block length */
  83.             mifunc);      /* user callback to process basic blocks */
  84.  
  85.     if (err) {  /* sb16io_open() returns 0 if no error */
  86.         printf("error initializing\n");
  87.         return 1;
  88.     }
  89.  
  90.     sb16io_start();  /* start record&play */
  91.  
  92.     /* now do whatever you want, sb is working in background */
  93.     printf("press ENTER to stop...");
  94.     fgetc(stdin);
  95.  
  96.     /* stop & free sb16 */
  97.     sb16io_close();
  98.  
  99.     return 0;
  100. }
  101.  
  102. /**********************************************************/
  103.  
  104.