sound.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: sound.h
  3. // Purpose: interface of wxSound
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. #define wxSOUND_SYNC 0
  8. #define wxSOUND_ASYNC 1
  9. #define wxSOUND_LOOP 2
  10. /**
  11. @class wxSound
  12. This class represents a short sound (loaded from Windows WAV file), that
  13. can be stored in memory and played.
  14. Currently this class is implemented on Windows and Unix (and uses either
  15. Open Sound System or Simple DirectMedia Layer).
  16. @library{wxadv}
  17. @category{media}
  18. */
  19. class wxSound : public wxObject
  20. {
  21. public:
  22. /**
  23. Default ctor.
  24. */
  25. wxSound();
  26. /**
  27. Constructs a wave object from a file or, under Windows, from a Windows
  28. resource. Call IsOk() to determine whether this succeeded.
  29. @param fileName
  30. The filename or Windows resource.
  31. @param isResource
  32. @true if fileName is a resource, @false if it is a filename.
  33. */
  34. wxSound(const wxString& fileName, bool isResource = false);
  35. /**
  36. Constructs a wave object from in-memory data.
  37. @param size
  38. Size of the buffer pointer to by @a data.
  39. @param data
  40. The buffer containing the sound data in WAV format.
  41. */
  42. wxSound(size_t size, const void* data);
  43. /**
  44. Destroys the wxSound object.
  45. */
  46. virtual ~wxSound();
  47. /**
  48. Constructs a wave object from a file or resource.
  49. @param fileName
  50. The filename or Windows resource.
  51. @param isResource
  52. @true if fileName is a resource, @false if it is a filename.
  53. @return @true if the call was successful, @false otherwise.
  54. */
  55. bool Create(const wxString& fileName, bool isResource = false);
  56. /**
  57. Constructs a wave object from in-memory data.
  58. @param size
  59. Size of the buffer pointer to by @a data.
  60. @param data
  61. The buffer containing the sound data in WAV format.
  62. */
  63. bool Create(size_t size, const void* data);
  64. /**
  65. Returns @true if the object contains a successfully loaded file or resource,
  66. @false otherwise.
  67. */
  68. bool IsOk() const;
  69. /**
  70. Returns @true if a sound is played at the moment.
  71. This method is currently not available under Windows and may not be
  72. always implemented in Unix ports depending on the compilation options
  73. used (in this case it just always returns @false).
  74. @onlyfor{wxgtk,wxosx}
  75. */
  76. static bool IsPlaying();
  77. //@{
  78. /**
  79. Plays the sound file. If another sound is playing, it will be interrupted.
  80. Returns @true on success, @false otherwise. Note that in general it is
  81. possible to delete the object which is being asynchronously played any time
  82. after calling this function and the sound would continue playing, however this
  83. currently doesn't work under Windows for sound objects loaded from memory data.
  84. The possible values for @a flags are:
  85. - wxSOUND_SYNC: @c Play will block and wait until the sound is replayed.
  86. - wxSOUND_ASYNC: Sound is played asynchronously, @c Play returns immediately.
  87. - wxSOUND_ASYNC|wxSOUND_LOOP: Sound is played asynchronously and loops
  88. until another sound is played, Stop() is
  89. called or the program terminates.
  90. The static form is shorthand for this code:
  91. @code
  92. wxSound(filename).Play(flags);
  93. @endcode
  94. */
  95. bool Play(unsigned flags = wxSOUND_ASYNC) const;
  96. static bool Play(const wxString& filename,
  97. unsigned flags = wxSOUND_ASYNC);
  98. //@}
  99. /**
  100. If a sound is played, this function stops it.
  101. */
  102. static void Stop();
  103. };