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

  1. /**********************************************************/
  2. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  3. /*
  4. CAUTION: Compile using LARGE memory model!!!!!
  5. */
  6. /*/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  7. /**********************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <conio.h>  /* for kbhit() */
  11.  
  12. #include "sb16io.h"
  13.  
  14. /**********************************************************/
  15. /* basic block length (samples per block):
  16. too sort ==> too much interrupts per second.
  17. too long ==> too much record-to-playback delay.  */
  18. /* #define N 400 */
  19. #define N 400  /* Shareware version only supports this */
  20.  
  21. /* sampling rate */
  22. /*#define SRATE 8000*/
  23. #define SRATE 7500  /* shareware version only supports this */
  24.  
  25. /**********************************************************/
  26.  
  27. int main( void )
  28. {
  29.     int err;
  30.     UINT i;
  31.     INT8 * v8;
  32.     INT16 * v16;
  33.  
  34.     printf("Sample program to record & play concurrently using SB16.\n"
  35.         "In this program, recording is done using 8 bit signed samples, the\n"
  36.         "recorded buffer is promoted to 16 bit signed samples, and then it is\n"
  37.         "played.  So you must hear just what you record (with a delay).\n"
  38.         "This program is similar to TEST1.C, but will not use the interrupt\n"
  39.         "time callback function.\n"
  40.         "Press ENTER to continue...");
  41.     fgetc(stdin);
  42.  
  43.     /* prepare sb16 */
  44.     err = sb16io_open(SB16IO_RECORD8,  /* 8 bit record & 16 bit playback */
  45.             SRATE,    /* sampling rate (must be the same for 8 & 16 bits) */
  46.             SB16IO_MONO8,  /* mono 8 bit (recording) */
  47.             SB16IO_MONO16,  /* mono 16 bit (playback) */
  48.             N,             /* basic block length */
  49.             SB16IO_NOUSRPROC);  /* no user callback */
  50.  
  51.     if (err) {  /* sb16io_open() returns 0 if no error */
  52.         printf("error initializing\n");
  53.         return 1;
  54.     }
  55.  
  56.     /* Set record-to-playback delay as sort as posible: 1 buffer.
  57.     This is close to the limit!
  58.     delay 0 produces clicks. If we use delay 1, we must generate a
  59.     playback buffer in a sort time after recording one, and maybe
  60.     we hear some clicks. delay 2 is safe: no clicks, but long delay.
  61.     If sb16io_setdelay() is not called, the default 2 is used. */
  62.     sb16io_setdelay(1);
  63.  
  64.     sb16io_start();  /* start record&play */
  65.  
  66.     printf("press any key to stop...");
  67.  
  68.     while (!kbhit()) {  /* while no key is pressed */
  69.         /* get SB 8 bits buffer, but in WAITNEW mode, that waits until
  70.         a block different to the previous one is ready. */
  71.         v8 = sb16io_get8(SB16IO_WAITNEW);
  72.         v16 = sb16io_get16(SB16IO_WAITNEW);  /* get SB 16 bits buffer */
  73.         /* just copy from record (8 bits) to play (16 bits) buffer.
  74.         We copy to the 8 msb of the 16 bit word. */
  75.         for (i=0; i<N; i++)
  76.             v16[i] = (((INT16)v8[i]) << 8);
  77.     }
  78.  
  79.     /* stop & free sb16 */
  80.     sb16io_close();
  81.  
  82.     return 0;
  83. }
  84.  
  85. /**********************************************************/
  86.  
  87.