home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games 1996 October / Amiga_Games_Extra_CD_10-96.bin / userbox / publicdomain / grabkey / source / gk_audio.c next >
C/C++ Source or Header  |  1996-07-15  |  2KB  |  123 lines

  1. /*
  2. **    GrabKEY
  3. **
  4. **        © 1996 by Timo C. Nentwig
  5. **        All Rights Reserved !
  6. **
  7. **        Tcn@techbase.in-berlin.de
  8. **
  9. **
  10. */
  11.  
  12. /// #include
  13.  
  14. #include "gk_GST.h"
  15. #include "gk_Protos.h"
  16.  
  17. ///
  18. /// #define
  19.  
  20. #define    NOTIFY_SIGNAL    50
  21.  
  22. ///
  23. /// proto
  24.  
  25. proto Object *    LoadSound    (STRPTR Name);
  26. proto VOID        PlaySound    (STRPTR Name);
  27.  
  28. ///
  29.  
  30. /// LoadSound ()
  31.  
  32.     /*
  33.      *    FUNCTION    Load & return a sound Object *.
  34.      *
  35.      *    NOTE
  36.      *
  37.      *    EXAMPLE     LoadSound ("samples:my_sample.DT");
  38.      *
  39.      */
  40.  
  41.  
  42. Object *
  43. LoadSound (STRPTR Name)
  44. {
  45.  
  46.     if ( ! (StrEmpty (Name)))
  47.     {
  48.  
  49.         Object   *Sound;
  50.  
  51.         if (Sound = NewDTObject (Name, DTA_SourceType,    DTST_FILE,
  52.                                        DTA_GroupID,       GID_SOUND,
  53.                                        SDTA_Volume,       64,
  54.                                        SDTA_Cycles,       1,
  55.                                        SDTA_SignalTask,   (ULONG) FindTask (NULL),
  56.                                        SDTA_SignalBit,    (ULONG) NOTIFY_SIGNAL,
  57.                                        TAG_END))
  58.                                        {
  59.  
  60.                                            return (Sound);
  61.  
  62.                                        }
  63.                                        else
  64.                                        {
  65.  
  66.                                            LONG    ErrNum = IoErr();
  67.                                            UBYTE   ErrBuf [80];
  68.  
  69.                                            if (ErrNum >= DTERROR_UNKNOWN_DATATYPE)
  70.                                            {
  71.  
  72.                                                sprintf (ErrBuf, GetDTString (ErrNum), Name);
  73.  
  74.                                            }
  75.                                            else
  76.                                            {
  77.  
  78.                                                Fault (ErrNum, NULL, ErrBuf, sizeof (ErrBuf));
  79.  
  80.                                            }
  81.  
  82.                                            ErrorRequest ("OK", "%s %ld\n\n%s: %s", LocaleString (MSG_ERR_ERROR), ErrNum, Name, ErrBuf);
  83.  
  84.                                        }
  85.  
  86.     }
  87.  
  88.     return (NULL);
  89.  
  90. }
  91.  
  92. ///
  93. /// PlaySound ()
  94.  
  95.     /*
  96.      *    FUNCTION    Load & play a sound.
  97.      *
  98.      *    NOTE
  99.      *
  100.      *    EXAMPLE     PlaySound ();
  101.      *
  102.      */
  103.  
  104.  
  105. VOID
  106. PlaySound (STRPTR Name)
  107. {
  108.  
  109.     Object   *Sound = LoadSound (Name);
  110.  
  111.     if (Sound)
  112.     {
  113.  
  114.         DoMethod (Sound, DTM_TRIGGER, NULL, STM_PLAY, NULL);
  115.         Wait (NOTIFY_SIGNAL);
  116.         DisposeDTObject (Sound);
  117.  
  118.     }
  119.  
  120. }
  121.  
  122. ///
  123.