2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: sound.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxSound
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-16 22:47:34 -04:00
|
|
|
|
|
|
|
#define wxSOUND_SYNC 0
|
|
|
|
#define wxSOUND_ASYNC 1
|
|
|
|
#define wxSOUND_LOOP 2
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
@class wxSound
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This class represents a short sound (loaded from Windows WAV file), that
|
2008-10-05 07:24:00 -04:00
|
|
|
can be stored in memory and played.
|
|
|
|
|
2017-11-19 16:51:51 -05:00
|
|
|
Currently this class is implemented on Windows and Unix and can use either
|
|
|
|
Open Sound System (OSS) or Simple DirectMedia Layer (SDL) under the latter.
|
|
|
|
Notice that OSS is not provided any more by most, and maybe even all,
|
|
|
|
Linux systems in 2017 and osspd (OSS Proxy Daemon) package typically needs
|
|
|
|
to be installed to make it work.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxadv}
|
2009-02-20 06:34:52 -05:00
|
|
|
@category{media}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxSound : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
2008-10-05 07:24:00 -04:00
|
|
|
/**
|
|
|
|
Default ctor.
|
|
|
|
*/
|
|
|
|
wxSound();
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Constructs a wave object from a file or, under Windows, from a Windows
|
2008-10-05 07:24:00 -04:00
|
|
|
resource. Call IsOk() to determine whether this succeeded.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param fileName
|
2008-03-09 08:33:59 -04:00
|
|
|
The filename or Windows resource.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param isResource
|
2008-03-09 08:33:59 -04:00
|
|
|
@true if fileName is a resource, @false if it is a filename.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
wxSound(const wxString& fileName, bool isResource = false);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2011-09-21 11:08:02 -04:00
|
|
|
Constructs a wave object from in-memory data.
|
|
|
|
|
|
|
|
@param size
|
|
|
|
Size of the buffer pointer to by @a data.
|
|
|
|
@param data
|
|
|
|
The buffer containing the sound data in WAV format.
|
|
|
|
*/
|
|
|
|
wxSound(size_t size, const void* data);
|
|
|
|
|
|
|
|
/**
|
2008-03-08 08:52:38 -05:00
|
|
|
Destroys the wxSound object.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxSound();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Constructs a wave object from a file or resource.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 09:43:31 -05:00
|
|
|
@param fileName
|
2008-03-09 08:33:59 -04:00
|
|
|
The filename or Windows resource.
|
2008-03-08 09:43:31 -05:00
|
|
|
@param isResource
|
2008-03-09 08:33:59 -04:00
|
|
|
@true if fileName is a resource, @false if it is a filename.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return @true if the call was successful, @false otherwise.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 08:33:59 -04:00
|
|
|
bool Create(const wxString& fileName, bool isResource = false);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2012-05-16 22:47:34 -04:00
|
|
|
/**
|
|
|
|
Constructs a wave object from in-memory data.
|
|
|
|
|
|
|
|
@param size
|
|
|
|
Size of the buffer pointer to by @a data.
|
|
|
|
@param data
|
|
|
|
The buffer containing the sound data in WAV format.
|
|
|
|
*/
|
|
|
|
bool Create(size_t size, const void* data);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
|
|
|
Returns @true if the object contains a successfully loaded file or resource,
|
|
|
|
@false otherwise.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
bool IsOk() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if a sound is played at the moment.
|
2012-02-20 16:56:22 -05:00
|
|
|
|
|
|
|
This method is currently not available under Windows and may not be
|
|
|
|
always implemented in Unix ports depending on the compilation options
|
|
|
|
used (in this case it just always returns @false).
|
|
|
|
|
|
|
|
@onlyfor{wxgtk,wxosx}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-01-10 17:10:54 -05:00
|
|
|
static bool IsPlaying();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
//@{
|
|
|
|
/**
|
|
|
|
Plays the sound file. If another sound is playing, it will be interrupted.
|
2008-10-05 07:24:00 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Returns @true on success, @false otherwise. Note that in general it is
|
2008-10-05 07:24:00 -04:00
|
|
|
possible to delete the object which is being asynchronously played any time
|
|
|
|
after calling this function and the sound would continue playing, however this
|
2008-03-08 08:52:38 -05:00
|
|
|
currently doesn't work under Windows for sound objects loaded from memory data.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-10-05 07:24:00 -04:00
|
|
|
The possible values for @a flags are:
|
|
|
|
- wxSOUND_SYNC: @c Play will block and wait until the sound is replayed.
|
|
|
|
- wxSOUND_ASYNC: Sound is played asynchronously, @c Play returns immediately.
|
|
|
|
- wxSOUND_ASYNC|wxSOUND_LOOP: Sound is played asynchronously and loops
|
|
|
|
until another sound is played, Stop() is
|
|
|
|
called or the program terminates.
|
2008-03-20 09:45:17 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
The static form is shorthand for this code:
|
2008-10-05 07:24:00 -04:00
|
|
|
@code
|
|
|
|
wxSound(filename).Play(flags);
|
|
|
|
@endcode
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-10-05 07:24:00 -04:00
|
|
|
bool Play(unsigned flags = wxSOUND_ASYNC) const;
|
|
|
|
static bool Play(const wxString& filename,
|
|
|
|
unsigned flags = wxSOUND_ASYNC);
|
2008-03-08 08:52:38 -05:00
|
|
|
//@}
|
|
|
|
|
|
|
|
/**
|
|
|
|
If a sound is played, this function stops it.
|
|
|
|
*/
|
|
|
|
static void Stop();
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|