home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / dmkit / flat / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-31  |  6.4 KB  |  202 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 "support.h"      // Include header file for basic support functions.
  51. #include "loader.h"       // Include header for midpak/digpak dynamic loader
  52. #include "midpak.h"       // Include header for link layer to MIDPAK functions.
  53. #include "digplay.h"      // Include header for link layer to DIGPAK functions.
  54. #include "doscalls.h"     // Include header to assembly DOS support functions.
  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. void main(void)
  78. {
  79.     long int siz;
  80.     char *fname;
  81.  
  82.     if ( !LoadDigPak("SOUNDRV.COM") )
  83.     {
  84.         printf("Failed to load sound driver.\n");
  85.         exit(1);
  86.     }
  87.  
  88.     if ( !InitDigPak() )
  89.     {
  90.         UnLoadDigPak();
  91.         printf("Failed to initialize sound driver.\n");
  92.         exit(1);
  93.     }
  94.  
  95.     if ( LoadMidPak("MIDPAK.COM", "MIDPAK.ADV", "MIDPAK.AD") )
  96.     {
  97.         printf("Loaded MIDPAK.COM MIDPAK.ADV and MIDPAK.AD into Low Mem\n");
  98.         if ( InitMidPak() )
  99.         {
  100.             printf("MIDPAK driver initialized.\n");
  101.             fname = floadlow("TEST.XMI",&siz);
  102.             if ( fname )
  103.             {
  104.                 printf("Loaded TEST.XMI %d bytes long.\n",siz);
  105.                 RegisterXmidi(fname,siz);
  106.                 printf("Sequence registered, now playing.\n");
  107.                 PlaySequence(0);
  108.                 SegueSequence(1,-1);
  109.             }
  110.         }
  111.         else
  112.             printf("Failed to initialize MIDPAK driver.\n");
  113.     }
  114.  
  115.     TestDigPak();
  116.  
  117.     UnLoadMidPak();
  118.     UnLoadDigPak();
  119.     RemoveVectorLoader();
  120. }
  121.  
  122. void TestDigPak(void)
  123. {
  124.     int i,key,sound;
  125.  
  126.   printf("Loading digital sound effects.\n");
  127.     if ( LoadSounds() )
  128.   {
  129.         printf("Select an sound effect to play. [ESC] when finished playing around.\n");
  130.         for (i=0; i<NOBJ; i++)
  131.         {
  132.             printf("%c %s\n",i+'A',Names[i]);
  133.         }
  134.         do
  135.         {
  136.             if ( keystat() )
  137.             {
  138.                 key = getkey();
  139.                 if ( key >= 'a' && key <= 'z') key-=32;
  140.                 if ( key >= 'A' && key <= 'Z')
  141.                 {
  142.                     sound = key-'A';
  143.                     if ( sound < NOBJ ) PlaySound(sound);
  144.                 }
  145.             }
  146.         } while ( key != 27 );
  147.         UnloadSounds();
  148.     }
  149. }
  150.  
  151. // Load all of the sound files into memory.
  152. int LoadSounds(void)
  153. {
  154.   int fph;
  155.   long int siz,end;
  156.   int i,handle,j;
  157.   int select;
  158.  
  159.   for (i=0; i<NOBJ; i++)
  160.   {
  161.     Sounds[i] = fload(Names[i], &siz);
  162.     if ( !Sounds[i] )
  163.     {
  164.       printf("File '%s' not found.\n",Names[i]);
  165.       return(0);
  166.     }
  167.     ssize[i] = siz;
  168.     printf("Sound Loaded '%s'.\n",Names[i]);
  169.   }
  170.     return(1);
  171. }
  172.  
  173. void UnloadSounds(void)
  174. {
  175.     int i;
  176.  
  177.     for (i=0; i<NALLOC; i++) memfree(Sounds[i]);
  178.     if ( soundbuffer )
  179.     {
  180.         realfree(snd);
  181.         realfree(soundbuffer);
  182.     }
  183.     NALLOC=0;
  184. }
  185.  
  186.  
  187. void PlaySound(int sound)
  188. {
  189.     if ( !soundbuffer )
  190.     {
  191.         snd = (SNDSTRUC *) realalloc(sizeof(SNDSTRUC));
  192.         snd->frequency = 11000;
  193.         soundbuffer = realalloc(65535);
  194.     }
  195.     StopSound(); // Wait for previous sound to complete.
  196.     memorymove(soundbuffer,Sounds[sound],ssize[sound]);  // Copy sound effect into first 1mb address space.
  197.     snd->sound = RealPtr(soundbuffer); // Convert soundbuffer into offset:segment formate.
  198.     snd->sndlen = ssize[sound]; // Specify length of sound effect in bytes.
  199.     DigPlay(snd); // Massage and Play the sound effect.
  200. }
  201.  
  202.