home *** CD-ROM | disk | FTP | other *** search
/ Over Load / MAXIWIN7.ISO / programs / display / samples / test2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-14  |  2.9 KB  |  94 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. /* #define N 400 */
  18. #define N 4096  /* shareware version only supports this */
  19.  
  20. /* sampling rate */
  21. /*#define SRATE 8000*/
  22. #define SRATE 7500  /* shareware version only supports this */
  23.  
  24. /**********************************************************/
  25. /* callback function. whenever a new block (length N) is full,
  26. this callback is called (at interrupt-time, so be carefull with
  27. what you do!). */
  28.  
  29. void mifunc( void )
  30. {
  31.     UINT i;
  32.     INT8 * v8;
  33.     INT16 * v16;
  34.  
  35.     v8 = sb16io_get8(SB16IO_NOWAIT);  /* get SB 8 bits buffer */
  36.     v16 = sb16io_get16(SB16IO_NOWAIT);  /* get SB 16 bits buffer */
  37.     /* we have used NOWAIT mode, because we are at interrupt time!!
  38.     moreover, this callback has been called because there is a new
  39.     recorded buffer. */
  40.  
  41.  
  42.     /* copy input to output, but alternate inverts one sample
  43.     (+ - + - + - ...) This is equivalent to a Nyquist freq.
  44.     modulation, so the frequency spectrum is inverted (low
  45.     frequencies become high, and high frec. become low). */
  46.     for (i=0; i<N; i++) {  /* we asume N is even!! */
  47.         v16[i] = (((INT16)v8[i]) << 8);
  48.         i++;
  49.         v16[i] = -(((INT16)v8[i]) << 8);
  50.     }
  51. }
  52.  
  53. /**********************************************************/
  54.  
  55. int main( void )
  56. {
  57.     int err;
  58.  
  59.     printf("Sample program to record & play concurrently using SB16.\n"
  60.         "In this program, recording is done using 8 bit signed samples, and\n"
  61.         "playback uses 16 bit signed samples. The playback signal is a\n"
  62.         "spectrum-inverted copy of the input signal (low freqs. goes\n"
  63.         "to high freqs. and viceversa).\n"
  64.         "Press ENTER to continue...");
  65.     fgetc(stdin);
  66.  
  67.     /* prepare sb16 */
  68.     err = sb16io_open(SB16IO_RECORD8,  /* 8 bit record & 16 bit playback */
  69.             SRATE,    /* sampling rate (must be the same for 8 & 16 bits) */
  70.             SB16IO_MONO8,  /* mono 8 bit (recording) */
  71.             SB16IO_MONO16,  /* mono 16 bit (playback) */
  72.             N,             /* basic block length */
  73.             mifunc);      /* user callback to process basic blocks */
  74.  
  75.     if (err) {  /* sb16io_open() returns 0 if no error */
  76.         printf("error initializing\n");
  77.         return 1;
  78.     }
  79.  
  80.     sb16io_start();  /* start record&play */
  81.  
  82.     /* now do whatever you want, sb is working in background */
  83.     printf("press ENTER to stop...");
  84.     fgetc(stdin);
  85.  
  86.     /* stop & free sb16 */
  87.     sb16io_close();
  88.  
  89.     return 0;
  90. }
  91.  
  92. /**********************************************************/
  93.  
  94.