home *** CD-ROM | disk | FTP | other *** search
/ PC Loisirs 18 / cd.iso / sharewar / mikm202 / source / mikwav.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-18  |  2.6 KB  |  149 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <dos.h>
  5. #include <string.h>
  6.  
  7. #include "mtypes.h"
  8.  
  9. #include "mdriver.h"      // -> MD_Init,MD_Exit etc.
  10. #include "mwav.h"        // -> MW_LoadWavFN & MW_FreeWav
  11. #include "mems.h"        // -> EMS_Init
  12.  
  13.  
  14. /*
  15.     Declare external drivers:
  16. */
  17.  
  18. extern DRIVER gusdriver,sbdriver;
  19.  
  20.  
  21.  
  22. int breakhandler(void)
  23. {
  24.     return 1;
  25. }
  26.  
  27.  
  28.  
  29. void InitWasOkay(void)
  30. {
  31.     int t;
  32.     SAMPLE *s1,*s2;
  33.  
  34.     if((s1=MW_LoadWavFN("b1.wav"))==NULL){
  35.         printf("Wavload error: %s.\n",myerr);
  36.         return;
  37.     }
  38.  
  39.     if((s2=MW_LoadWavFN("b2.wav"))==NULL){
  40.         printf("Wavload error: %s.\n",myerr);
  41.         MW_FreeWav(s1);
  42.         return;
  43.     }
  44.  
  45.     md_numchn=4;
  46.     MD_PlayStart();
  47.  
  48.     puts("Press key 1,2,3,4 to play the wav files, press 'q' to quit.");
  49.  
  50.  
  51.     while(1){
  52.  
  53.         t=getch();
  54.  
  55.         if(t=='q') break;
  56.  
  57.         if(t=='1'){
  58.             MD_VoiceSetVolume(0,64);
  59.             MD_VoiceSetPanning(0,0);
  60.             MD_VoiceSetFrequency(0,12000);
  61.             MD_VoicePlay(0,s1->handle,0,s1->length,0,0,s1->flags);
  62.         }
  63.  
  64.         if(t=='2'){
  65.             MD_VoiceSetVolume(1,64);
  66.             MD_VoiceSetPanning(1,64);
  67.             MD_VoiceSetFrequency(1,13000);
  68.             MD_VoicePlay(1,s1->handle,0,s1->length,0,0,s1->flags);
  69.         }
  70.  
  71.         if(t=='3'){
  72.             MD_VoiceSetVolume(2,64);
  73.             MD_VoiceSetPanning(2,128);
  74.             MD_VoiceSetFrequency(2,10000);
  75.             MD_VoicePlay(2,s2->handle,0,s2->length,0,0,s2->flags);
  76.         }
  77.  
  78.         if(t=='4'){
  79.             MD_VoiceSetVolume(3,64);
  80.             MD_VoiceSetPanning(3,200);
  81.             MD_VoiceSetFrequency(3,12000);
  82.             MD_VoicePlay(3,s2->handle,0,s2->length,0,0,s2->flags);
  83.         }
  84.     }
  85.  
  86.     MD_PlayStop();
  87.     MW_FreeWav(s1);
  88.     MW_FreeWav(s2);
  89. }
  90.  
  91.  
  92. int main(int argc,char *argv[])
  93. {
  94.     puts(mikbanner);
  95.  
  96.     /*
  97.         Initialize soundcard parameters.. you _have_ to do this
  98.         before calling MD_Init(), and it's illegal to change them
  99.         after you've called MD_Init()
  100.     */
  101.  
  102.     md_mixfreq        =44100;                // standard mixing freq
  103.     md_dmabufsize    =4000;                // standard dma buf size
  104.     md_mode            =DMODE_16BITS|DMODE_STEREO;        // standard mixing mode
  105.     md_device        =0;                    // standard device: autodetect
  106.     md_bpm            =125;
  107.  
  108.     /*
  109.         Register the drivers we want to use:
  110.     */
  111.  
  112.     MD_RegisterDriver(&sbdriver);
  113.     MD_RegisterDriver(&gusdriver);
  114.  
  115.     /*
  116.         disable control-break by
  117.         installing a custom handler
  118.     */
  119.  
  120.     ctrlbrk(breakhandler);
  121.  
  122.     //  init ems
  123.  
  124.     EMS_Init();
  125.  
  126.     //    initialize soundcard
  127.  
  128.     if(!MD_Init()){
  129.         printf("Driver error: %s.\n",myerr);
  130.         return 0;
  131.     }
  132.  
  133.     printf("Using %s for %d bit %s sound at %u Hz\n\n",
  134.             md_driver->Name,
  135.             (md_mode&DMODE_16BITS) ? 16:8,
  136.             (md_mode&DMODE_STEREO) ? "stereo":"mono",
  137.             md_mixfreq);
  138.  
  139.     // call main program
  140.  
  141.     InitWasOkay();
  142.  
  143.     // and clean up
  144.  
  145.     MD_Exit();
  146.     return 0;
  147. }
  148.  
  149.