home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / prg / dsik205 / dsik.dat / EXAMPLES / EXAMP09.C < prev    next >
C/C++ Source or Header  |  1995-04-10  |  2KB  |  88 lines

  1. /****************************************************************************
  2. *
  3. *                   Digital Sound Interface Kit (DSIK)
  4. *                            Version 2.00
  5. *
  6. *                           by Carlos Hasan
  7. *
  8. * Filename:     example9.c
  9. * Version:      Revision 1.0
  10. *
  11. * Language:     WATCOM C
  12. * Environment:  IBM PC (DOS/4GW)
  13. *
  14. * Description:  Play a music module file. This example show how to load
  15. *               a module file from a big resource file.
  16. *
  17. ****************************************************************************/
  18.  
  19. #include <io.h>
  20. #include <fcntl.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <conio.h>
  24. #include "audio.h"
  25. #include "import.h"
  26.  
  27. #define MODPATH "SONG.DSM"
  28. #define MODFORM FORM_DSM
  29. #define MODSEEK 0L
  30. #define MODSIZE 50697L
  31.  
  32. DSM *XLoadModule(char *Filename, long SeekPos, long Length, int Form)
  33. {
  34.     int Handle;
  35.     DSM *Module;
  36.  
  37.     /* For your programs you should search the filename in the resource
  38.      * file directory and get the file offset and length from there.
  39.      * Also, you can use directly dLoadModuleFile to load RIFF/DSMF files
  40.      * instead of using the dImportModuleFile import routines (see below).
  41.      */
  42.  
  43.     /* open the resource file */
  44.     if ((Handle = open(Filename,O_BINARY|O_RDONLY)) < 0) {
  45.         dError = ERR_NOFILE;
  46.         return NULL;
  47.     }
  48.     /* seek the module file */
  49.     if (lseek(Handle,SeekPos,SEEK_SET) < 0) {
  50.         dError = ERR_FILEIO;
  51.         close(Handle);
  52.         return NULL;
  53.     }
  54.     /* load module file */
  55.     Module = dImportModuleFile(Handle,Length,Form);
  56.     close(Handle);
  57.     return Module;
  58. }
  59.  
  60. int main(void)
  61. {
  62.     SoundCard SC;
  63.     DSM *M;
  64.  
  65.     dRegisterDrivers();
  66.     if (dLoadSetup(&SC,"SETUP.CFG")) {
  67.         printf("Please run SETUP.EXE to configure.\n");
  68.         exit(EXIT_FAILURE);
  69.     }
  70.     if (dInit(&SC)) {
  71.         printf("Error initializing the sound system.\n");
  72.         exit(EXIT_FAILURE);
  73.     }
  74.     atexit((void(*)(void))dDone);
  75.     if (!(M = XLoadModule(MODPATH,MODSEEK,MODSIZE,MODFORM))) {
  76.         printf("Error (%03d) loading %s module file: %s.\n",
  77.             dError, MODPATH, dErrorMsg[dError]);
  78.         exit(EXIT_FAILURE);
  79.     }
  80.     dSetupVoices(M->Header.NumTracks,M->Header.MasterVolume);
  81.     dPlayMusic(M);
  82.     printf("Playing module. Press any key to continue.\n");
  83.     while (!kbhit()) dPoll();
  84.     dStopMusic();
  85.     dFreeModule(M);
  86.     return 0;
  87. }
  88.