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

  1. /* ------------------------------------------------------------------------ */
  2. /*  @@ Source Documentation                            *** TC Version ***   */
  3. /*                                                                          */
  4. /*  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   */
  5. /*                                                                          */
  6. /*   TITLE       : DEMOVDP.C                                                */
  7. /*                                                                          */
  8. /*   DESCRIPTION :                                                          */
  9. /*       This program demostrates how to perform voice out using the        */
  10. /*       CTVDSK.DRV driver. The voice out is using the Disk Double          */
  11. /*       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.                             OutputFile("DEMO.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. /*   OutputFile (char *szFilename)                                          */
  77. /*                                                                          */
  78. /*   DESCRIPTION:                                                           */
  79. /*       Output voice with the filename specified.                          */
  80. /*                                                                          */
  81. /*   ENTRY:                                                                 */
  82. /*       szFilename :- filename to be output.                               */
  83. /*                                                                          */
  84. /*   EXIT:                                                                  */
  85. /*       None.                                                              */
  86. /*                                                                          */
  87. /* ------------------------------------------------------------------------ */
  88.  
  89. OutputFile (char *szFilename)
  90. {
  91.     int     Handle ;
  92.  
  93.  
  94.     /* Open and play the voice file */
  95.     if ( (Handle=_open(szFilename, O_RDONLY)) != -1 )
  96.     {
  97.         ctvd_speaker(1) ;
  98.  
  99.         if ( ctvd_output(Handle) == NO_ERROR )
  100.         {
  101.             PlayVoiceInBkgnd () ;
  102.  
  103.             if ( ctvd_drv_error () )
  104.                 ShowError () ;
  105.             else
  106.                 printf ("Voice output ended.\n") ;
  107.         }
  108.         else
  109.             ShowError () ;
  110.  
  111.         _close (Handle) ;
  112.     }
  113.     else
  114.         printf ( "Open %s file error\n", szFilename ) ;
  115. }
  116.  
  117.  
  118. /* ------------------------------------------------------------------------ */
  119. /*  @@ Usage                                                                */
  120. /*                                                                          */
  121. /*   PlayVoiceInBkgnd (void)                                                */
  122. /*                                                                          */
  123. /*   DESCRIPTION:                                                           */
  124. /*       Control voice plaing at the background using keyboard.             */
  125. /*                                                                          */
  126. /*   ENTRY:                                                                 */
  127. /*       None.                                                              */
  128. /*                                                                          */
  129. /*   EXIT:                                                                  */
  130. /*       None.                                                              */
  131. /*                                                                          */
  132. /* ------------------------------------------------------------------------ */
  133.  
  134. #pragma loop_opt(off)    /* turn off loop optimiaztion */
  135. PlayVoiceInBkgnd (void)
  136. {
  137.     /* Polls for hot key while playing voice file */
  138.     while ( ct_voice_status )
  139.     {
  140.         if ( bioskey(1) )
  141.         {
  142.             switch ( bioskey(0) & 0xff )
  143.             {
  144.                 case 0x1b : ctvd_stop () ;
  145.                             printf ("Voice stopped.\n") ;
  146.                             break ;
  147.  
  148.                 case ' '  : ctvd_pause () ;
  149.                             printf ( "Pause...\n"
  150.                                      "Pressed any key to continue.\n" );
  151.                             bioskey(0) ;
  152.                             ctvd_continue () ;
  153.                             break ;
  154.  
  155.                 case 0x0d : ctvd_break_loop(1) ;
  156.                             printf( "Break-out takes place immediately\n") ;
  157.                             break ;
  158.  
  159.                 case 0x9  : ctvd_break_loop(0) ;
  160.                             printf( "Break-out takes place after the current"
  161.                                     " loop finishes\n" ) ;
  162.                             break ;
  163.             }
  164.         }
  165.     }
  166. }
  167. #pragma loop_opt()
  168.  
  169.  
  170. /* ------------------------------------------------------------------------ */
  171. /*  @@ Usage                                                                */
  172. /*                                                                          */
  173. /*   ShowError (void)                                                       */
  174. /*                                                                          */
  175. /*   DESCRIPTION:                                                           */
  176. /*       Display error occurred during the process of voice I/O.            */
  177. /*                                                                          */
  178. /*   ENTRY:                                                                 */
  179. /*       None.                                                              */
  180. /*                                                                          */
  181. /*   EXIT:                                                                  */
  182. /*       None.                                                              */
  183. /*                                                                          */
  184. /* ------------------------------------------------------------------------ */
  185.  
  186. ShowError (void)
  187. {
  188.     int     Err ;
  189.  
  190.  
  191.     /* Show the driver error and the DOS extended error code */
  192.     Err = ctvd_drv_error() ;
  193.  
  194.     printf("Driver error = %2d\n", Err) ;
  195.  
  196.     Err = ctvd_ext_error();
  197.     if ( Err != 0 )
  198.         printf ("DOS error = %2d\n", Err) ;
  199. }
  200.  
  201.