home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sdk_dos.ddi / C / TC / VOICE / DEMOVDR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-06  |  7.5 KB  |  183 lines

  1. /* ------------------------------------------------------------------------ */
  2. /*  @@ Source Documentation                            *** TC Version ***   */
  3. /*                                                                          */
  4. /*  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   */
  5. /*                                                                          */
  6. /*   TITLE       : DEMOVDR.C                                                */
  7. /*                                                                          */
  8. /*   DESCRIPTION :                                                          */
  9. /*       This program demostrates how to perform voice recording using      */
  10. /*       the CTVDSK.DRV driver. The voice recording is using the Disk       */
  11. /*       Double Buffering method.                                           */
  12. /*                                                                          */
  13. /*       The program checks BLASTER environment for the Card settings.      */
  14. /*       It also performs test base on BLASTER environment settings to      */
  15. /*       ensure they are tally with the hardware settings on the Card.      */
  16. /*                                                                          */
  17. /*       Note that the program included the module LOADDRV.C to load        */
  18. /*       the loadable CTVDSK.DRV into memory.                               */
  19. /*                                                                          */
  20. /* ------------------------------------------------------------------------ */
  21.  
  22. #include <dos.h>
  23. #include <bios.h>
  24. #include <stdio.h>
  25. #include <fcntl.h>
  26.  
  27. #include <sbc.h>
  28. #include <sbcvoice.h>
  29.  
  30. #include  "loaddrv.c"
  31.  
  32.  
  33. main ()
  34. {
  35.     extern  char far * near ctvdsk_drv;
  36.  
  37.  
  38.     /* Retrieve the BLASTER environment settings */
  39.     if ( ! GetEnvSetting() )
  40.     {
  41.         if (sbc_check_card() & 4)
  42.         {
  43.             if (sbc_test_int())
  44.             {
  45.                 if (sbc_test_dma() >= 0)
  46.                 {
  47.                     if ((ctvdsk_drv = LoadDriver("CTVDSK.DRV")) != 0)
  48.                     {
  49.                         if ( !ctvd_init(16) )
  50.                         {
  51.                             RecordFile("TEMP.VOC") ;
  52.  
  53.                             ctvd_terminate() ;
  54.                         }
  55.                         else
  56.                             ShowError() ;
  57.                     }
  58.                 }
  59.                 else
  60.                     printf("Error on DMA channel.\n");
  61.             }
  62.             else
  63.                 printf("Error on interrupt.\n");
  64.         }
  65.         else
  66.             printf("Sound Blaster Card not found or wrong I/O settings.\n") ;
  67.     }
  68.     else
  69.         printf("BLASTER environment not set or incomplete or invalid.\n");
  70. }
  71.  
  72.  
  73. /* ------------------------------------------------------------------------ */
  74. /*  @@ Usage                                                                */
  75. /*                                                                          */
  76. /*   RecordFile (char *szFilename)                                          */
  77. /*                                                                          */
  78. /*   DESCRIPTION:                                                           */
  79. /*       Record voice with the filename specified.                          */
  80. /*                                                                          */
  81. /*   ENTRY:                                                                 */
  82. /*       szFilename :- filename to be output.                               */
  83. /*                                                                          */
  84. /*   EXIT:                                                                  */
  85. /*       None.                                                              */
  86. /*                                                                          */
  87. /* ------------------------------------------------------------------------ */
  88.  
  89. RecordFile (char *szFilename)
  90. {
  91.     int     Handle ;
  92.  
  93.  
  94.     /* create and record a voice file */
  95.     if ( (Handle=_creat(szFilename, 0)) != -1 )
  96.     {
  97.         ctvd_speaker(0) ;
  98.  
  99.         if ( ctvd_input(Handle, 8000) == NO_ERROR )
  100.         {
  101.             RecordUntilStopped() ;
  102.  
  103.             if ( ctvd_drv_error() )
  104.                 ShowError() ;
  105.             else
  106.                 printf ("Voice record ended.\n") ;
  107.         }
  108.         else
  109.             ShowError () ;
  110.  
  111.         _close (Handle) ;
  112.     }
  113.     else
  114.         printf ("Create %s file error\n", szFilename ) ;
  115. }
  116.  
  117.  
  118. /* ------------------------------------------------------------------------ */
  119. /*  @@ Usage                                                                */
  120. /*                                                                          */
  121. /*   RecordUntilStopped (void)                                              */
  122. /*                                                                          */
  123. /*   DESCRIPTION:                                                           */
  124. /*       Starts voice recording. Press ESC key to terminate the recording.  */
  125. /*                                                                          */
  126. /*   ENTRY:                                                                 */
  127. /*       None.                                                              */
  128. /*                                                                          */
  129. /*   EXIT:                                                                  */
  130. /*       None.                                                              */
  131. /*                                                                          */
  132. /* ------------------------------------------------------------------------ */
  133.  
  134. #pragma loop_opt(off)    /* turn off loop optimiaztion */
  135. RecordUntilStopped (void)
  136. {
  137.     /* Polls for hot key while playing voice file */
  138.     while ( ct_voice_status )
  139.     {
  140.         if ( bioskey(1) )
  141.         {
  142.             /* check for ESC key */
  143.             if ( (bioskey(0) & 0xff) == 0x1b )
  144.                 ctvd_stop () ;
  145.         }
  146.     }
  147.  
  148.     printf ("Voice stopped.\n") ;
  149. }
  150. #pragma loop_opt()
  151.  
  152.  
  153. /* ------------------------------------------------------------------------ */
  154. /*  @@ Usage                                                                */
  155. /*                                                                          */
  156. /*   ShowError (void)                                                       */
  157. /*                                                                          */
  158. /*   DESCRIPTION:                                                           */
  159. /*       Display error occurred during the process of voice I/O.            */
  160. /*                                                                          */
  161. /*   ENTRY:                                                                 */
  162. /*       None.                                                              */
  163. /*                                                                          */
  164. /*   EXIT:                                                                  */
  165. /*       None.                                                              */
  166. /*                                                                          */
  167. /* ------------------------------------------------------------------------ */
  168.  
  169. ShowError (void)
  170. {
  171.     int     Err ;
  172.  
  173.  
  174.     /* Show the driver error and the DOS extended error code */
  175.     Err = ctvd_drv_error() ;
  176.  
  177.     printf("Driver error = %2d\n", Err) ;
  178.  
  179.     Err = ctvd_ext_error();
  180.     if ( Err != 0 )
  181.         printf ("DOS error = %2d\n", Err) ;
  182. }
  183.