home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Aktief 1995 #3 / CDA3.iso / sound / tnypl211.zip / EX0.C next >
C/C++ Source or Header  |  1994-06-21  |  2KB  |  80 lines

  1. /* ex0.c - example #0 */
  2.  
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <malloc.h>
  6. #include <io.h>
  7. #include <fcntl.h>
  8. #ifdef __BORLANDC__
  9. #include <dos.h>
  10. #else
  11. #include <i86.h>
  12. #endif
  13. #include "modplay.h"
  14.  
  15. /* the volume level goes from 0 to 255 */
  16.  
  17. #define MUSICVOLUME 192
  18.  
  19. void FadeInMusic(void)
  20. {
  21.     int Volume;
  22.     for (Volume = 0; Volume <= MUSICVOLUME; Volume++) {
  23.         MODSetMusicVolume(Volume);
  24.         delay(6);
  25.     }
  26. }
  27. void FadeOutMusic(void)
  28. {
  29.     int Volume;
  30.     for (Volume = MUSICVOLUME; Volume >= 0; Volume--) {
  31.         MODSetMusicVolume(Volume);
  32.         delay(10);
  33.     }
  34. }
  35.  
  36. void TestSample(void)
  37. {
  38.     Sample *Ding;
  39.     if ((Ding = MODLoadSample("SAMPLE.WAV")) != NULL) {
  40.         printf("Press any key to test the WAV file and ESC to exit.\n");
  41.         while (getch() != 27)
  42.             MODPlaySample(7,Ding);
  43.         MODFreeSample(Ding);
  44.     }
  45.     else {
  46.         printf("Error loading WAV file. Press any key to exit.\n");
  47.         getch();
  48.     }
  49. }
  50.  
  51. void main(void)
  52. {
  53.     Module *Song;
  54.     word Port;
  55.     byte IRQ,DRQ;
  56.  
  57.     if (MODDetectCard(&Port,&IRQ,&DRQ)) {
  58.         printf("Sound Blaster not found.\n");
  59.         return;
  60.     }
  61.     printf("Sound Blaster found at Addr:%03x IRQ:%d DMA:%d\n",Port,IRQ,DRQ);
  62.     if ((Song = MODLoadModule("TUNE.MOD")) != NULL) {
  63.         if (MODPlayModule(Song,8,22222,Port,IRQ,DRQ,PM_TIMER))
  64.             printf("Error initializing the sound system.\n");
  65.         else {
  66.             printf("Playing music...\n");
  67.             FadeInMusic();
  68.             TestSample();
  69.             FadeOutMusic();
  70.             MODStopModule();
  71.         }
  72.         MODFreeModule(Song);
  73.     }
  74.     else {
  75.         printf("Error loading modulefile.\n");
  76.     }
  77.     return;
  78. }
  79.  
  80.