home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / PASCAL / DIGPAK / TEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-06  |  7.3 KB  |  235 lines

  1. /*****************************************************************************/
  2. /* TEST.C     DIGPAK & MIDPAK test application. Dynmically loads DIGPAK and      */
  3. /*                    MIDPAK drivers, SOUNDRV.COM and MIDPAK.COM/MIDPAK.ADV/MIDPAK.AD  */
  4. /*                    then plays the MIDI file TEST.XMI and allows you to play sound     */
  5. /*                    effects TEST1.SND and TEST2.SND                                                                  */
  6. /*****************************************************************************/
  7. /*        Written by John W. Ratcliff (c) 1994                                                                     */
  8. /*             Compuserve: 70253,3237                                                                                          */
  9. /*             Genie: J.RATCLIFF3                                                                                                  */
  10. /*             BBS: 1-314-939-0200                                                                                                 */
  11. /*             Addresss:                                                                                                                     */
  12. /*                     747 Napa Lane                                                                                                     */
  13. /*                     St. Charles, MO 63304                                                                                     */
  14. /*                                                                                                                                                     */
  15. /*        A $500 per product license fee applies to all commercial software          */
  16. /*        products distributed with ANY DIGPAK and another $500 for MIDPAK             */
  17. /*        drivers.    That's a total of $1,000 if your product uses BOTH DIGPAK    */
  18. /*        and MIDPAK drivers.  If you distribute any commercial title with DIGPAK*/
  19. /*        and/or MIDPAK drivers resident then this license fee applies.                  */
  20. /*                                                                                                                                                     */
  21. /*        To pay a license, simply write a check for $500 for just DIGPAK              */
  22. /*        $500 for just MIDPAK, or $1,000 for both DIGPAK and MIDPAK single          */
  23. /*        product distribution license payable to:                                                             */
  24. /*                The Audio Solution, 747 Napa Lane, St. Charles, MO 63304                     */
  25. /*                with a copy of your commerical product.  You will receive a signed */
  26. /*                license agreement from The Audio Solution shortly thereafter.          */
  27. /*                This license fee applies specifically to the inclusion with your     */
  28. /*                distribution disk any of the DIGPAK and/or MIDPAK drivers.                 */
  29. /*                These drivers are copyrighted works, created by me, to enhance the */
  30. /*                use of sound and music in DOS based commercial software.    The          */
  31. /*                license fees collected are used to maintain the drivers and keep     */
  32. /*                the BBS running.                                                                                                     */
  33. /*                                                                                                                                                     */
  34. /*                WARNING!!!!!!  You would be ill-advised to distribute a commercial */
  35. /*                product containing either DIGPAK and/or MIDPAK drivers without         */
  36. /*                having paid the distribution license fee.  Since your product would*/
  37. /*                contain unlicensed copyrighted software from The Audio Solution,     */
  38. /*                your product could be required to be immediately removed from retail*/
  39. /*                distribution.  I doubt this is going to be a problem.  Clearly if  */
  40. /*                your product is enhanced by the use of these drivers, your company */
  41. /*                can easily afford a nominal license fee of $1,000 in exchange for  */
  42. /*                getting the use of several man-years of software engineering             */
  43. /*                resources.                                                                                                                 */
  44. /*****************************************************************************/
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <malloc.h>
  48.  
  49. #include "keys.h"         // Include #define's for keyboard commands
  50. #include "loader.h"       // Include header for midpak/digpak dynamic loader
  51. #include "midpak.h"       // Include header for link layer to MIDPAK functions.
  52. #include "digplay.h"      // Include header for link layer to DIGPAK functions.
  53. #include "doscalls.h"     // Include header to assembly DOS support functions.
  54. #include "sbdetect.h"     // SoundBlaster auto-detect routines.
  55.  
  56. #define NOBJ 4
  57.  
  58. static char *Names[NOBJ] =
  59. {
  60.     "TEST1.SND",
  61.     "TEST2.SND",
  62.     "PEND.SND",
  63.     "TEST.SND"
  64. };
  65.  
  66. static SNDSTRUC snd;
  67. static char *soundbuffer=0;
  68. static long int ssize[NOBJ];
  69. static int NALLOC=0;
  70. char *Sounds[NOBJ]; // addresses of all the beauty sounds.
  71.  
  72. void UnloadSounds(void);
  73. int  LoadSounds(void);
  74. void PlaySound(int sound);
  75. void TestDigPak(void);
  76.  
  77. // Define memory allocation functions.    If using DOS memory allocation
  78. // functions, provided through DOSCALLS, then set the conditional compilation
  79. // 'DOSALLOC' to true.  If using C compiler library function memory allocation
  80. // set 'DOSALLOC' to zero.  MUST BE SET TO 1 for RECURSE, because most memory
  81. // allocation has to be on a paragraph boundary!
  82.  
  83. #define DOSALLOC 0
  84. // Redirect memory allocation to either DOS memory allocate functions located
  85. // in DOSCALLS or to C library far memory allocation functions.
  86. unsigned char far * far memalloc(long int siz)
  87. {
  88.     unsigned char far *mem;
  89.  
  90.     #if DOSALLOC
  91.         mem = fmalloc(siz);  // DOS far memory allocation functions
  92.     #else
  93.         mem = farmalloc(siz); // C's far memory allocation functions.
  94.     #endif
  95.     return(mem);
  96. }
  97.  
  98. void far memfree(char far *memory)
  99. {
  100.     #if DOSALLOC
  101.         ffree(memory);
  102.     #else
  103.         farfree(memory);
  104.     #endif
  105. }
  106.  
  107.  
  108. void main(void)
  109. {
  110.     long int siz;
  111.     char *fname;
  112.     int baseadr,irq;
  113.  
  114.     if ( !DetectBlaster(&baseadr,&irq) )
  115.     {
  116.         printf("No SoundBlaster or compatible detected.\n");
  117.         exit(1);
  118.     }
  119.  
  120.     if ( !LoadDigPak("SOUNDRV.COM") )
  121.     {
  122.         printf("Failed to load sound driver.\n");
  123.         exit(1);
  124.     }
  125.  
  126.     PokeDigPak(baseadr,irq);    // Poke the autodetected values into the driver.
  127.  
  128.     if ( !InitDigPak() )
  129.     {
  130.         UnLoadDigPak();
  131.         printf("Failed to initialize sound driver.\n");
  132.         exit(1);
  133.     }
  134.  
  135.     if ( LoadMidPak("MIDPAK.COM", "MIDPAK.ADV", "MIDPAK.AD") )
  136.     {
  137.         PokeMidPak(baseadr,irq); // Poke the autodetect values into the driver.
  138.         printf("Loaded MIDPAK.COM MIDPAK.ADV and MIDPAK.AD.\n");
  139.         if ( InitMidPak() )
  140.         {
  141.             printf("MIDPAK driver initialized.\n");
  142.             fname = fload("TEST.XMI",&siz);
  143.             if ( fname )
  144.             {
  145.                 printf("Loaded TEST.XMI %d bytes long.\n",siz);
  146.                 RegisterXmidi(fname,siz);
  147.                 printf("Sequence registered, now playing.\n");
  148.                 PlaySequence(0);
  149.                 SegueSequence(1,-1);
  150.             }
  151.         }
  152.         else
  153.             printf("Failed to initialize MIDPAK driver.\n");
  154.     }
  155.  
  156.     TestDigPak();
  157.  
  158.     UnLoadMidPak();
  159.     UnLoadDigPak();
  160. }
  161.  
  162. void TestDigPak(void)
  163. {
  164.     int i,key,sound;
  165.  
  166.   printf("Loading digital sound effects.\n");
  167.     if ( LoadSounds() )
  168.   {
  169.         printf("Select an sound effect to play. [ESC] when finished playing around.\n");
  170.         for (i=0; i<NOBJ; i++)
  171.         {
  172.             printf("%c %s\n",i+'A',Names[i]);
  173.         }
  174.         do
  175.         {
  176.             if ( keystat() )
  177.             {
  178.                 key = getkey();
  179.                 if ( key >= 'a' && key <= 'z') key-=32;
  180.                 if ( key >= 'A' && key <= 'Z')
  181.                 {
  182.                     sound = key-'A';
  183.                     if ( sound < NOBJ ) PlaySound(sound);
  184.                 }
  185.             }
  186.         } while ( key != 27 );
  187.         UnloadSounds();
  188.     }
  189. }
  190.  
  191. // Load all of the sound files into memory.
  192. int LoadSounds(void)
  193. {
  194.   int fph;
  195.   long int siz,end;
  196.   int i,handle,j;
  197.   int select;
  198.  
  199.   for (i=0; i<NOBJ; i++)
  200.   {
  201.     Sounds[i] = fload(Names[i], &siz);
  202.     if ( !Sounds[i] )
  203.     {
  204.       printf("File '%s' not found.\n",Names[i]);
  205.       return(0);
  206.     }
  207.     ssize[i] = siz;
  208.         snd.frequency = 11000;
  209.         snd.sound = Sounds[i];
  210.         snd.sndlen = ssize[i]; // Specify length of sound effect in bytes.
  211.         MassageAudio(&snd);
  212.     printf("Sound Loaded '%s'.\n",Names[i]);
  213.   }
  214.     return(1);
  215. }
  216.  
  217. void UnloadSounds(void)
  218. {
  219.     int i;
  220.  
  221.     for (i=0; i<NALLOC; i++) memfree(Sounds[i]);
  222.     NALLOC=0;
  223. }
  224.  
  225.  
  226. void PlaySound(int sound)
  227. {
  228.     StopSound(); // Wait for previous sound to complete.
  229.     snd.frequency = 11000;
  230.     snd.sound = Sounds[sound];
  231.     snd.sndlen = ssize[sound]; // Specify length of sound effect in bytes.
  232.     DigPlay2(&snd); // play preformated sound effect.
  233. }
  234.  
  235.