]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/sound.h
c85b0ef8666d7df02d6b4b369b3067c24b05c207
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSound class
4 // Author: Julian Smart, Vaclav Slavik
8 // Copyright: (c) Julian Smart, Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
19 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma interface "sound.h"
23 #include "wx/object.h"
25 // ----------------------------------------------------------------------------
26 // wxSound: simple audio playback class
27 // ----------------------------------------------------------------------------
31 class wxDynamicLibrary
;
33 /// Sound data, as loaded from .wav file:
37 wxSoundData() : m_refCnt(1) {}
41 // .wav header information:
42 unsigned m_channels
; // num of channels (mono:1, stereo:2)
43 unsigned m_samplingRate
;
44 unsigned m_bitsPerSample
; // if 8, then m_data contains unsigned 8bit
45 // samples (wxUint8), if 16 then signed 16bit
47 unsigned m_samples
; // length in samples:
51 wxUint8
*m_data
; // m_dataBytes bytes of data
56 wxUint8
*m_dataWithHeader
; // ditto, but prefixed with .wav header
61 /// Simple sound class:
62 class wxSound
: public wxSoundBase
66 wxSound(const wxString
& fileName
, bool isResource
= false);
67 wxSound(int size
, const wxByte
* data
);
70 // Create from resource or file
71 bool Create(const wxString
& fileName
, bool isResource
= false);
73 bool Create(int size
, const wxByte
* data
);
75 bool IsOk() const { return m_data
!= NULL
; }
78 static void UnloadBackend();
81 bool DoPlay(unsigned flags
);
83 static void EnsureBackend();
85 bool LoadWAV(const wxUint8
*data
, size_t length
, bool copyData
);
87 static wxSoundBackend
*ms_backend
;
88 #if wxUSE_LIBSDL && wxUSE_PLUGINS
89 // FIXME - temporary, until we have plugins architecture
90 static wxDynamicLibrary
*ms_backendSDL
;
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 // This is interface to sound playing implementation. There are multiple
103 // sound architectures in use on Unix platforms and wxWindows can use several
104 // of them for playback, depending on their availability at runtime; hence
105 // the need for backends. This class is for use by wxWindows and people writing
106 // additional backends only, it is _not_ for use by applications!
111 virtual ~wxSoundBackend() {}
113 // Returns the name of the backend (e.g. "Open Sound System")
114 virtual wxString
GetName() const = 0;
116 // Returns priority (higher priority backends are tried first)
117 virtual int GetPriority() const = 0;
119 // Checks if the backend's audio system is available and the backend can
120 // be used for playback
121 virtual bool IsAvailable() const = 0;
123 // Returns true if the backend is capable of playing sound asynchronously.
124 // If false, then wxWindows creates a playback thread and handles async
125 // playback, otherwise it is left up to the backend (will usually be more
127 virtual bool HasNativeAsyncPlayback() const = 0;
129 // Plays the sound. flags are same flags as those passed to wxSound::Play
130 virtual bool Play(wxSoundData
*data
, unsigned flags
) = 0;