home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / m / m003_1 / sdk_dos.ddi / C / TC / EFFECT / DEMOFPV.C
Encoding:
C/C++ Source or Header  |  1991-11-06  |  11.6 KB  |  294 lines

  1. /* ------------------------------------------------------------------------ */
  2. /*  @@ Source Documentation                            *** TC Version ***   */
  3. /*                                                                          */
  4. /*  Copyright (c) Creative Technology Pte Ltd, 1991. All rights reserved.   */
  5. /*                                                                          */
  6. /*   TITLE       : DEMOFPV.C                                                */
  7. /*                                                                          */
  8. /*   DESCRIPTION :                                                          */
  9. /*       This program demostrates how to use the AUXDRV.DRV driver to       */
  10. /*       perform panning and fading effect on the playing voice.            */
  11. /*                                                                          */
  12. /*       You need to have a Sound Blaster Pro card to run this program.     */
  13. /*                                                                          */
  14. /*       Note that the BLASTER environment has to be set before executing   */
  15. /*       this program.                                                      */
  16. /*                                                                          */
  17. /* ------------------------------------------------------------------------ */
  18.  
  19. #include <dos.h>
  20. #include <bios.h>
  21. #include <stdio.h>
  22. #include <fcntl.h>
  23. #include <stdlib.h>
  24.  
  25. #include <sbc.h>
  26. #include <sbcvoice.h>
  27. #include <auxdrv.h>
  28.  
  29. #define   VOC_VOL   1
  30.  
  31. #include "loaddrv.c"
  32.  
  33. main ()
  34. {
  35.     extern  char far * near CTAuxDrv;
  36.     extern  char far * near ctvdsk_drv;
  37.     int     Handle;
  38.  
  39.  
  40.     /* Retrieve the BLASTER environment settings */
  41.     if ( ! GetEnvSetting() )
  42.     {
  43.         if (sbc_check_card() & 4)
  44.         {
  45.             if (sbc_test_int())
  46.             {
  47.                 if (sbc_test_dma() >= 0)
  48.                 {
  49.                     if ((ctvdsk_drv = LoadDriver("CTVDSK.DRV")) != 0)
  50.                     {
  51.                         if ((CTAuxDrv = LoadDriver("AUXDRV.DRV")) != 0)
  52.                         {
  53.                             if ( !ctvd_init(16) )
  54.                             {
  55.                                 if ( (Handle=GetFileHandle("DEMO1.VOC")) != 0 )
  56.                                 {
  57.                                     if ( OutputVoice(Handle) )
  58.                                     {
  59.                                         SoundEffect( ) ;
  60.                                     }
  61.  
  62.                                     _close (Handle) ;
  63.                                 }
  64.  
  65.                                 ctvd_terminate() ;
  66.                             }
  67.                             else
  68.                                 ShowError() ;
  69.                         }
  70.                     }
  71.                 }
  72.                 else
  73.                     printf("Error on DMA channel.\n");
  74.             }
  75.             else
  76.                 printf("Error on interrupt.\n");
  77.         }
  78.         else
  79.             printf("Sound Blaster Card not found or wrong I/O settings.\n") ;
  80.     }
  81.     else
  82.         printf("BLASTER environment not set or incomplete or invalid.\n");
  83. }
  84.  
  85.  
  86. /* ------------------------------------------------------------------------ */
  87. /*  @@ Usage                                                                */
  88. /*                                                                          */
  89. /*   SoundEffect (void)                                                     */
  90. /*                                                                          */
  91. /*   DESCRIPTION:                                                           */
  92. /*       Add sound effect on the playback digitized sound.                  */
  93. /*                                                                          */
  94. /*   ENTRY:                                                                 */
  95. /*       None                                                               */
  96. /*                                                                          */
  97. /*   EXIT:                                                                  */
  98. /*       None                                                               */
  99. /*                                                                          */
  100. /* ------------------------------------------------------------------------ */
  101.  
  102. SoundEffect (void)
  103. {
  104.     unsigned    key ;
  105.     unsigned    wPrevVol;
  106.  
  107.  
  108.     ctadInit( ) ;
  109.  
  110.     /* preserve the previous voice volume settings */
  111.     wPrevVol = ctadGetVolume( VOC_VOL ) ;
  112.  
  113.     /* set voice left/right volume to 0 */
  114.     ctadSetVolume( VOC_VOL, 0 ) ;
  115.  
  116.     /* Setup voice volume fading in mode 0 */
  117.     ctadFade( VOC_VOL, 0xf0f0, 5000, 0, 0 ) ;
  118.     ctadStartCtrl( ) ;
  119.     WaitEffectEnd( ) ;
  120.  
  121.  
  122.     /* Setup digitized sound for panning in mode 1  */
  123.     /* repeat for 5 counts                          */
  124.     ctadPan( VOC_VOL, 0, 255, 600, 1, 5 ) ;
  125.     ctadStartCtrl( ) ;
  126.     WaitEffectEnd( ) ;
  127.  
  128.  
  129.     /* set voice left/right volume to 0xf0f0 */
  130.     ctadSetVolume( VOC_VOL, 0xf0f0 ) ;
  131.  
  132.     /* Setup voice volume fading in mode 0 */
  133.     ctadFade( VOC_VOL, 0, 5000, 0, 0 ) ;
  134.     ctadStartCtrl( ) ;
  135.     WaitEffectEnd( ) ;
  136.  
  137.  
  138.     /* set voice left/right volume back to previous status */
  139.     ctadSetVolume( VOC_VOL, wPrevVol ) ;
  140.  
  141.     ctadTerminate( ) ;
  142. }
  143.  
  144.  
  145. /* ------------------------------------------------------------------------ */
  146. /*  @@ Usage                                                                */
  147. /*                                                                          */
  148. /*   WaitEffectEnd (void)                                                   */
  149. /*                                                                          */
  150. /*   DESCRIPTION:                                                           */
  151. /*       Control the Fading and Panning effect of the digitized sound.      */
  152. /*                                                                          */
  153. /*   ENTRY:                                                                 */
  154. /*       None                                                               */
  155. /*                                                                          */
  156. /*   EXIT:                                                                  */
  157. /*       None                                                               */
  158. /*                                                                          */
  159. /* ------------------------------------------------------------------------ */
  160.  
  161. #pragma loop_opt(off)   /* turn off loop optimiaztion */
  162. WaitEffectEnd (void)
  163. {
  164.     /* End of sound effect process ? */
  165.     while( CTFadeStatus || CTPanStatus )
  166.     {
  167.         /* Stop effect if no voice process */
  168.         if ( !ct_voice_status )
  169.             ctadStopCtrl();
  170.  
  171.         if ( bioskey(1) )
  172.         {
  173.             switch (  bioskey(0) & 0xff )
  174.             {
  175.                 case 0x1b :
  176.                     ctadStopCtrl( ) ;
  177.                     ctvd_stop( ) ;
  178.                     break ;
  179.  
  180.                 case 'P' :
  181.                 case 'p' :
  182.                     ctadPauseCtrl( ) ;
  183.                     ctvd_pause( ) ;
  184.                     break ;
  185.  
  186.                 case 'C' :
  187.                 case 'c' :
  188.                     ctadStartCtrl( ) ;
  189.                     ctvd_continue( ) ;
  190.                     break ;
  191.             }
  192.         }
  193.     }
  194. }
  195. #pragma loop_opt()
  196.  
  197.  
  198. /* ------------------------------------------------------------------------ */
  199. /*  @@ Usage                                                                */
  200. /*                                                                          */
  201. /*   GetFileHandle(char *szFilename)                                        */
  202. /*                                                                          */
  203. /*   DESCRIPTION:                                                           */
  204. /*       Get a file handle with the filename specified.                     */
  205. /*                                                                          */
  206. /*   ENTRY:                                                                 */
  207. /*       szFilename :- filename to be output.                               */
  208. /*                                                                          */
  209. /*   EXIT:                                                                  */
  210. /*       File handle if successful, else return 0.                          */
  211. /*                                                                          */
  212. /* ------------------------------------------------------------------------ */
  213.  
  214. GetFileHandle (char *szFilename)
  215. {
  216.     int     Handle ;
  217.  
  218.  
  219.     /* Open and play the voice file */
  220.     if ( (Handle=_open(szFilename, O_RDONLY)) == -1 )
  221.     {
  222.         Handle = 0;
  223.         printf ( "Open %s file error\n", szFilename ) ;
  224.     }
  225.  
  226.     return (Handle);
  227. }
  228.  
  229.  
  230. /* ------------------------------------------------------------------------ */
  231. /*  @@ Usage                                                                */
  232. /*                                                                          */
  233. /*   OutputVoice (int Handle)                                               */
  234. /*                                                                          */
  235. /*   DESCRIPTION:                                                           */
  236. /*       Output voice with the file handle specified.                       */
  237. /*                                                                          */
  238. /*   ENTRY:                                                                 */
  239. /*       Handle : handle of a file to be outputted.                         */
  240. /*                                                                          */
  241. /*   EXIT:                                                                  */
  242. /*       Non-zero if successful, else return 0.                             */
  243. /*                                                                          */
  244. /* ------------------------------------------------------------------------ */
  245.  
  246. OutputVoice (int Handle)
  247. {
  248.     int     OutOK = 1;
  249.  
  250.  
  251.     ctvd_speaker(1) ;
  252.  
  253.     if ( ctvd_output(Handle) != NO_ERROR )
  254.     {
  255.         OutOK = 0;
  256.         ShowError () ;
  257.     }
  258.  
  259.  
  260.     return (OutOK);
  261. }
  262.  
  263.  
  264. /* ------------------------------------------------------------------------ */
  265. /*  @@ Usage                                                                */
  266. /*                                                                          */
  267. /*   ShowError (void)                                                       */
  268. /*                                                                          */
  269. /*   DESCRIPTION:                                                           */
  270. /*       Display error occurred during the process of voice I/O.            */
  271. /*                                                                          */
  272. /*   ENTRY:                                                                 */
  273. /*       None.                                                              */
  274. /*                                                                          */
  275. /*   EXIT:                                                                  */
  276. /*       None.                                                              */
  277. /*                                                                          */
  278. /* ------------------------------------------------------------------------ */
  279.  
  280. ShowError (void)
  281. {
  282.     int     Err ;
  283.  
  284.  
  285.     /* Show the driver error and the DOS extended error code */
  286.     Err = ctvd_drv_error() ;
  287.  
  288.     printf("Driver error = %2d\n", Err) ;
  289.  
  290.     Err = ctvd_ext_error();
  291.     if ( Err )
  292.         printf ("DOS error = %2d\n", Err) ;
  293. }
  294.