home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / playadlb / play.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-05  |  1.4 KB  |  79 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3.  
  4. #include "convert.h"
  5. #include "bank.h"
  6.  
  7. extern   char musRunning;                   /* != 0 if music is playing             */
  8.  
  9. #include  <malloc.h>
  10. #include  <string.h>
  11. #define   rlsmem(x,y)    free(x)
  12. #define   getmem(x)      malloc(x)
  13. #define   setmem(x,y,z)  memset(x,z,y)
  14. #define   movmem(x,y,z)  memmove(y,x,z)
  15. #define   max(x,y)       ((x > y) ? x:y)
  16.  
  17.  
  18. /*
  19.     Simple demonstration.
  20.     Syntax:     play <musfile.mus> <bankfile.snd>
  21. */
  22.  
  23. main( argc, argv)
  24.     int argc;
  25.     char * argv[];
  26.     {
  27.     struct MusHeader mH;
  28.     int meloFile;
  29.     char * music;
  30.     unsigned len;
  31.     BankPtr theBank;
  32.  
  33.     if( argc < 3) {
  34.         exit( 1);
  35.         }
  36.  
  37.     /* Perform some initialisations ... */
  38.     InitSnd();
  39.  
  40.     if( NULL == ( theBank = OpenBank( argv[ 2], 0))) {
  41.         Terminate();
  42.         exit( 1);
  43.         }
  44.     if( !LoadBank( theBank)) {
  45.         Terminate();
  46.         exit( 1);
  47.         }
  48.     meloFile = open( argv[ 1], O_RDONLY + O_BINARY);
  49.     if( -1 == meloFile) {
  50.         Terminate();
  51.         exit( 1);
  52.         }
  53.  
  54.     /* read the music file's header: */
  55.     read( meloFile, &mH, sizeof( struct MusHeader));
  56.     len = mH.dataSize;
  57.     music = (char *) getmem( (unsigned) len);
  58.     if( music == NULL) {
  59.         exit( 1);
  60.         }
  61.  
  62.     /* load all the data in memory: */
  63.     read( meloFile, music, len);
  64.  
  65.     /* Start playing: */
  66.     StartMelo( &mH, music, len, theBank);
  67.  
  68.     /* wait until end.... */
  69.     WaitEndMelo();
  70.  
  71.     /* uninstall the clock driver: */
  72.     Terminate();
  73.  
  74.     rlsmem( music, len);
  75.     CloseBank( theBank);
  76.     }    /* main() */
  77.  
  78.  
  79.