home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / PROG / BWSB120A.ZIP / DEMO / PLAYC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-24  |  6.0 KB  |  178 lines

  1. /*──────────────────────────────────────────────────────────────────────────*/
  2. /*                     Bells, Whistles, and Sound Boards                    */
  3. /*       Copyright (c) 1993-95, Edward Schlunder. All Rights Reserved.      */
  4. /*══════════════════════════════════════════════════════════════════════════*/
  5. /* PLAYC.C - Example GDM module player.                                     */
  6. /*           Written by Edward Schlunder (1995)                             */
  7. /*                                                                          */
  8. /*──────────────────────────────────────────────────────────────────────────*/
  9.  
  10. #include <bwsb.h>                      /* Declare all BWSB subs & functions */
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <io.h>
  15. #include <conio.h>
  16. #include <stdlib.h>
  17. #include <ctype.h>
  18.  
  19. #include <process.h>
  20.  
  21. #include <dos.h>
  22. #include <fcntl.h>
  23.  
  24. typedef struct { 
  25.   unsigned int SoundCard;
  26.   unsigned int BaseIO;
  27.   unsigned int IRQ;
  28.   unsigned int DMA;
  29.   unsigned int SoundQuality;
  30. } MSEConfigFile;
  31.  
  32. void main(void) { 
  33.   int module;               /* handle of GDM file */
  34.   char modfile[80];         /* ASCIIZ filename of file to load */
  35.   char *comspec;            /* Command processor name and path */
  36.   char *msefile[] = { "GUS.MSE",
  37.                       "SB1X.MSE",
  38.                       "SB2X.MSE",
  39.                       "SBPRO.MSE",
  40.                       "SB16.MSE",
  41.                       "PAS.MSE"  };
  42.   GDMHeader modhead;
  43.   MSEConfigFile MSEConfig; /* Configuration for MSE */
  44.   char OverRate;
  45.   int BufferSize;
  46.   int ErrCode, j;
  47.   unsigned char channels;
  48.  
  49.   printf("\nBWSB Example Module Player\n");
  50.   printf("Copyright (c) 1993-95, Edward Schlunder\n\n");
  51.  
  52.   if ((module = open("MSE.CFG", O_RDONLY | O_BINARY)) == -1) {
  53.   MSEError:
  54.     printf("No Sound selected in SETUP. Please run SETUP.\n");
  55.     return;
  56.   }
  57.   read(module, &MSEConfig, 10);
  58.   if (MSEConfig.SoundCard==0) goto MSEError;
  59.  
  60.   MSEConfig.SoundCard--;
  61.   BufferSize = 4096;
  62.   OverRate = 45;
  63.  
  64.   ErrCode=LoadMSE(msefile[MSEConfig.SoundCard],
  65.                   0,                             /* File offset */
  66.                   OverRate,
  67.                   BufferSize,
  68.                   &MSEConfig.BaseIO,
  69.                   &MSEConfig.IRQ,
  70.                   &MSEConfig.DMA);
  71.   if (ErrCode)
  72.   { switch(ErrCode)
  73.     { case 1: printf("Base I/O address autodetection failure\n");
  74.               break;
  75.       case 2: printf("IRQ level autodetection failure\n");
  76.               break;
  77.       case 3: printf("DMA channel autodetection failure\n");
  78.               break;
  79.       case 4: printf("DMA channel not supported\n");
  80.               break;
  81.       case 6: printf("Sound device does not respond\n");
  82.               break;
  83.       case 7: printf("Memory control blocks destroyed\n");
  84.               break;
  85.       case 8: printf("Insufficient memory for mixing buffers\n");
  86.               break;
  87.       case 9: printf("Insufficient memory for MSE file\n");
  88.               break;
  89.       case 10: printf("MSE has invalid identification string (corrupt/non-existant)\n");
  90.                break;
  91.       case 11: printf("MSE disk read failure\n");
  92.                break;
  93.       case 12: printf("MVSOUND.SYS not loaded (required for PAS use)\n");
  94.                break;
  95.       default: printf("Unknown error on MSE startup %u\n", ErrCode);
  96.     }
  97.     return;
  98.   }
  99.  
  100.   /* Display name of sound device */
  101.   printf("Sound Device: %s\n", DeviceName());
  102.   /* Display the acutal settings *used* in the MSE. */
  103.   printf("Addr: %Xh  IRQ: %d  DMA: %d\n",
  104.          MSEConfig.BaseIO, MSEConfig.IRQ, MSEConfig.DMA);
  105.  
  106.   /* Ask for a module to load */
  107.   printf("Module file: ");
  108.   if (gets(modfile)==NULL) return;  /* abort if nothing entered */
  109.  
  110.   /* Append a '.GDM' if no extension specified */
  111.   if (strstr(modfile, ".")==NULL) strncat(modfile, ".GDM", 80);
  112.  
  113.   if ((module=open(modfile, O_RDONLY | O_BINARY)) == -1)
  114.   { printf("Can't find file %s\n", modfile);
  115.     return;
  116.   }
  117.  
  118.   printf("Loading Module: %s\n", modfile);
  119.   ErrCode = EmsExist() & 1;             /* Enable EMS use if EMS services found */
  120.   LoadGDM(module, 0, &ErrCode, &modhead);  /* Load our GDM */
  121.   close(module);
  122.  
  123.   if (ErrCode != 0)
  124.   { switch(ErrCode)
  125.     { case 1: printf("Module is corrupt\n");
  126.               break;
  127.       case 2: printf("Could not autodetect module type\n");
  128.               break;
  129.       case 3: printf("Bad format ID\n");
  130.               break;
  131.       case 4: printf("Out of memory\n");
  132.               break;
  133.       case 5: printf("Cannot unpack samples\n");
  134.               break;
  135.       case 6: printf("AdLib samples not supported\n");
  136.               break;
  137.       default: printf("Unknown load error: %u\n", ErrCode);
  138.      }
  139.     return;
  140.   }
  141.  
  142.   channels = 0;
  143.   /* Scan and count number of used music channels */
  144.   for (j = 0; j < 32; j++) {
  145.     if (modhead.PanMap[j] != 0xFF)
  146.        channels++;                     /* increment channels if in use */
  147.   }
  148.  
  149.   printf("\nChannels: %u  Song: %.32s", channels, modhead.SongTitle);
  150.   printf("\nOversampling: %u Hz\n", StartOutput(channels, 0));
  151.   printf("D for DOS Shell or any other key to quit\n\n");
  152.   StartMusic();
  153.  
  154.   comspec = getenv("COMSPEC");
  155.   if (comspec==NULL) comspec = "COMMAND.COM";
  156.   for (;;)
  157.   { while (!kbhit())
  158.     { printf("Playing Music ──> Order: %u  Pattern: %u  Row: %u   \r",
  159.              MusicOrder(0xFF),
  160.              MusicPattern(0xFF),
  161.              MusicRow());                                             }
  162.  
  163.     j = toupper(getch());
  164.     if (j=='D')
  165.     {  printf("\n\nType EXIT [enter] to return..");
  166.        spawnl(P_WAIT, comspec, NULL);
  167.     }
  168.     else break;
  169.   }
  170.  
  171.   StopMusic();                         /* Disable music processing */
  172.   StopOutput();                        /* Turn off sound output */
  173.   UnloadModule();                      /* Free module from memory */
  174.   StopBanner();                        /* Turn off that damn signoff banner ;) */
  175.   FreeMSE();                           /* Free MSE from memory */
  176. }
  177.  
  178.