]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/sound.h
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
; }
77 // Stop playing any sound
80 // Returns true if a sound is being played
81 static bool IsPlaying();
84 static void UnloadBackend();
87 bool DoPlay(unsigned flags
) const;
89 static void EnsureBackend();
91 bool LoadWAV(const wxUint8
*data
, size_t length
, bool copyData
);
93 static wxSoundBackend
*ms_backend
;
94 #if wxUSE_LIBSDL && wxUSE_PLUGINS
95 // FIXME - temporary, until we have plugins architecture
96 static wxDynamicLibrary
*ms_backendSDL
;
104 // ----------------------------------------------------------------------------
106 // ----------------------------------------------------------------------------
108 // This is interface to sound playing implementation. There are multiple
109 // sound architectures in use on Unix platforms and wxWindows can use several
110 // of them for playback, depending on their availability at runtime; hence
111 // the need for backends. This class is for use by wxWindows and people writing
112 // additional backends only, it is _not_ for use by applications!
114 // Structure that holds playback status information
115 struct wxSoundPlaybackStatus
117 // playback is in progress
119 // main thread called wxSound::Stop()
120 bool m_stopRequested
;
123 // Audio backend interface
127 virtual ~wxSoundBackend() {}
129 // Returns the name of the backend (e.g. "Open Sound System")
130 virtual wxString
GetName() const = 0;
132 // Returns priority (higher priority backends are tried first)
133 virtual int GetPriority() const = 0;
135 // Checks if the backend's audio system is available and the backend can
136 // be used for playback
137 virtual bool IsAvailable() const = 0;
139 // Returns true if the backend is capable of playing sound asynchronously.
140 // If false, then wxWindows creates a playback thread and handles async
141 // playback, otherwise it is left up to the backend (will usually be more
143 virtual bool HasNativeAsyncPlayback() const = 0;
145 // Plays the sound. flags are same flags as those passed to wxSound::Play.
146 // The function should periodically check the value of
147 // status->m_stopRequested and terminate if it is set to true (it may
148 // be modified by another thread)
149 virtual bool Play(wxSoundData
*data
, unsigned flags
,
150 volatile wxSoundPlaybackStatus
*status
) = 0;
152 // Stops playback (if something is played).
153 virtual void Stop() = 0;
155 // Returns true if the backend is playing anything at the moment.
156 // (This method is never called for backends that don't support async
158 virtual bool IsPlaying() const = 0;
162 #endif // wxUSE_SOUND