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

  1. /****************************************************************************
  2. *
  3. *                   Digital Sound Interface Kit (DSIK)
  4. *                            Version 2.00
  5. *
  6. *                           by Carlos Hasan
  7. *
  8. * Filename:     example3.c
  9. * Version:      Revision 1.0
  10. *
  11. * Language:     WATCOM C
  12. * Environment:  IBM PC (DOS/4GW)
  13. *
  14. * Description:  Play a module and a sample file simultaneously.
  15. *
  16. ****************************************************************************/
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <ctype.h>
  21. #include <conio.h>
  22. #include "audio.h"
  23. #include "import.h"
  24.  
  25. #define MODPATH "SONG.DSM"
  26. #define MODFORM FORM_DSM
  27.  
  28. #define SMPPATH "SAMPLE.WAV"
  29. #define SMPFORM FORM_WAV
  30.  
  31.  
  32. int main(void)
  33. {
  34.     SoundCard SC;
  35.     DSM *M;
  36.     Sample *S;
  37.     int key,chan;
  38.  
  39.     dRegisterDrivers();
  40.     if (dLoadSetup(&SC,"SETUP.CFG")) {
  41.         printf("Please run SETUP.EXE to configure.\n");
  42.         exit(EXIT_FAILURE);
  43.     }
  44.     if (dInit(&SC)) {
  45.         printf("Error initializing the sound system.\n");
  46.         exit(EXIT_FAILURE);
  47.     }
  48.     atexit((void(*)(void))dDone);
  49.     if (!(M = dImportModule(MODPATH,MODFORM))) {
  50.         printf("Error (%03d) loading %s module file: %s.\n",
  51.             dError, MODPATH, dErrorMsg[dError]);
  52.         exit(EXIT_FAILURE);
  53.     }
  54.     if (!(S = dImportSample(SMPPATH,SMPFORM))) {
  55.         printf("Error (%03d) loading %s sample file: %s.\n",
  56.             dError, SMPPATH, dErrorMsg[dError]);
  57.         exit(EXIT_FAILURE);
  58.     }
  59.     /* The sound system needs M->Header.NumTracks voices to
  60.        playback the music module, and I need an extra voice to
  61.        play the WAVE sample file.
  62.      */
  63.     dSetupVoices(M->Header.NumTracks+1,M->Header.MasterVolume);
  64.  
  65.     /* Get the unused voice number to play the WAVE sample file */
  66.     chan = M->Header.NumTracks;
  67.     dPlayMusic(M);
  68.     dSetMusicVolume(160);
  69.     printf("Press keys 0-9 to play the module instruments,\n");
  70.     printf("SPACE to play the sample file or ESC to quit.\n");
  71.     do {
  72.         while (!kbhit()) dPoll();
  73.         if ((key = getch()) != 27) {
  74.             if (isdigit(key)) {
  75.                 key -= '0';
  76.                 if (key < M->Header.NumSamples) {
  77.                     dPlayVoice(chan,M->Samples[key]);
  78.                 }
  79.             }
  80.             else if (isspace(key)) {
  81.                 dPlayVoice(chan,S);
  82.             }
  83.         }
  84.     } while (key != 27);
  85.     dStopVoice(chan);
  86.     dStopMusic();
  87.     dFreeModule(M);
  88.     return 0;
  89. }
  90.