home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / C / PlaySound.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-11  |  1.6 KB  |  60 lines

  1. /* Sound Effect Demo
  2. ** -----------------
  3. ** This is a simple demo that plays a sound effect.  Try changing the
  4. ** IFF file to another one on your hard drive and play that.
  5. **
  6. ** Press LMB to play the sound.
  7. ** Press RMB to exit the demo.
  8. */
  9.  
  10. #include <proto/games.h>
  11. #include <proto/exec.h>
  12. #include <exec/memory.h>
  13.  
  14. struct GMSBase *GMSBase;
  15. extern struct ExecBase *SysBase;
  16.  
  17. struct Sound Sound =
  18. {
  19.     SMV1,                          /* Structure version */
  20.     CHANNEL_ALL,                   /* Channel to play through */
  21.     1,                             /* Priority */
  22.     0,                             /* Sample header */
  23.     0,                             /* Sample address */
  24.     0,                             /* Sample length */
  25.     OCT_C0S,                       /* Sample period */
  26.     100,                           /* Sample volume */
  27.     0,                             /* Sound attributes */
  28.     "GAMESLIB:data/SND.Lightning"  /* Sound file */
  29. };
  30.  
  31. /*=========================================================================*/
  32.  
  33. void main(void)
  34. {
  35.    ULONG Mouse;
  36.  
  37.    if (GMSBase = (struct GMSBase *) OpenLibrary("games.library", 0)) {
  38.     if (AllocAudio() == ERR_OK) {
  39.      if (InitSound(&Sound) == ERR_OK) {
  40.  
  41.        do {
  42.           Mouse = ReadMouse(JPORT1);
  43.  
  44.           if (Mouse & MB_LMB) {
  45.              PlaySoundPri(&Sound);
  46.              Sound.Octave += 2;
  47.              if (Sound.Octave > OCT_A4)
  48.                 Sound.Octave = OCT_G0S;
  49.              while (ReadMouse(JPORT1) & MB_LMB) {}
  50.           }
  51.        } while (!(Mouse & MB_RMB));
  52.  
  53.      FreeSound(&Sound);
  54.      }
  55.     FreeAudio();
  56.     }
  57.    CloseLibrary((struct Library *)GMSBase);
  58.    }
  59. }
  60.