2 // /////////////////////////////////////////////////////////////////////////////
5 // Author: Guilhem Lavaux
8 // Copyright: (C) 1997, 1998, Guilhem Lavaux
9 // License: wxWindows license
10 // /////////////////////////////////////////////////////////////////////////////
11 #ifndef __WX_SND_SOUND_H__
12 #define __WX_SND_SOUND_H__
22 #include <wx/thread.h>
34 } /// The possible sound output modes
49 typedef void (*wxSndCallback
)(wxSound
&, wxSndBuffer
&, char *);
52 typedef wxUint16 wxSndFlags
;
54 /** @name Sound buffer flags */
56 #define wxSND_BUFREADY 0x0001
58 #define wxSND_BUFERR 0x0002
60 #define wxSND_BUFLOCKED 0x0004
61 /// the driver mustn't unqueue it
62 #define wxSND_KEEPQUEUED 0x0008
63 /// automatic: when BUFREADY is set play the buffer
64 #define wxSND_BUFAUTO 0x0010
66 #define wxSND_UNFINISHED 0x0020
67 /// buffer is nearly being unqueued
68 #define wxSND_UNQUEUEING 0x0040
69 /// driver wants the buffer stop
70 #define wxSND_BUFSTOP 0x0080
72 #define wxSND_LOOP 0x0100
74 /** @name Sound data format */
76 #define wxSND_SAMPLE_LE 0
78 #define wxSND_SAMPLE_BE 1
80 #define wxSND_SAMPLE_UNSIGNED 0
82 #define wxSND_SAMPLE_SIGNED 1
85 * @memo wxSndBuffer is the basic class for all the sound codec.
86 * @author Guilhem Lavaux
88 class wxSndBuffer
: public wxObject
{
89 /// It is an abstract class
90 DECLARE_ABSTRACT_CLASS(wxSndBuffer
)
96 wxSndError m_snderror
;
98 wxSndFlags m_sndflags
;
99 /// last sound driver used
100 wxSound
*m_sndoutput
;
101 /// sound data format
102 wxSoundDataFormat m_sndformat
;
103 /// current sound codec
104 wxSoundCodec
*m_sndcodec
;
106 /** @name constructor and destructor */
108 /// Construct an uninitialized wxSndBuffer
111 virtual ~wxSndBuffer();
114 /** @name Functions returning the current state */
116 /// @return current mode
117 inline wxSndMode
GetMode() const { return m_sndmode
; }
118 /// @return sound data format
119 inline wxSoundDataFormat
& GetFormat() { return m_sndformat
; }
120 /// @return the size of the buffer
121 virtual wxUint32
GetSize() const = 0;
122 /// @return bytes left
123 virtual wxUint32
Available() const = 0;
125 /** enable the specified flags
128 void Set(wxSndFlags flags
);
129 /** disable the specified flags
132 inline void Clear(wxSndFlags flags
)
133 { m_sndflags
&= ~flags
; }
134 /** Check if the specified flags is set
136 * @return TRUE if all flags is set
138 inline bool IsSet(wxSndFlags flags
) const
139 { return ((m_sndflags
& flags
) == flags
); }
140 /** Check if the specified flags is not set
142 * @return TRUE if at least one flag is not set
144 inline bool IsNotSet(wxSndFlags flags
) const
145 { return ((m_sndflags
& flags
) != flags
); }
146 /** Check if the buffer is currently being played
148 if the buffer is being played
150 inline bool IsPlaying() const
151 { return IsSet(wxSND_BUFLOCKED
); }
155 inline void SetOutput(wxSound
& snd
)
156 { m_sndoutput
= &snd
; }
158 inline wxSoundCodec
*GetCurrentCodec() const
159 { return m_sndcodec
; }
166 wxSndError
GetError();
168 void SetError(wxSndError err
);
173 virtual bool RestartBuffer(wxSndMode mode
) = 0;
175 virtual bool Abort() { return TRUE
; }
178 virtual void OnPlayFinished();
180 /** Data exchanging functions */
183 virtual void OnNeedOutputData(char *io_buf
, wxUint32
& size
) = 0;
185 virtual void OnBufferOutFinished();
187 virtual void OnBufferInFinished(char *iobuf
, wxUint32
& size
);
191 void ChangeCodec(int no
);
194 class wxSndSimpleBuffer
: public wxSndBuffer
{
195 DECLARE_DYNAMIC_CLASS(wxSndSimpleBuffer
)
199 /// size of the sound buffer
201 /// current position in the sound buffer
204 wxSndSimpleBuffer(char *buffer
= NULL
, wxUint32 bufsize
= 0,
205 wxSndMode mode
= wxSND_OUTPUT
);
206 virtual ~wxSndSimpleBuffer();
208 void SetData(char *buffer
, wxUint32 bufsize
,
209 wxSndMode mode
= wxSND_OUTPUT
);
210 inline void SetSoundFormat(const wxSoundDataFormat
& format
);
212 void OnNeedOutputData(char *io_buf
, wxUint32
& size
);
213 void OnNeedInputData(wxUint32
& size
);
215 void OnBufferOutFinished();
216 void OnBufferInFinished(char *iobuf
, wxUint32
& size
);
218 bool RestartBuffer(wxSndMode mode
);
219 wxUint32
GetSize() const;
220 wxUint32
Available() const;
224 class wxSound
: public wxObject
{
226 DECLARE_ABSTRACT_CLASS(wxSound
)
228 friend class wxFragmentBuffer
;
231 wxSndBuffer
*m_lastbuf
;
235 wxSndCallback m_sndcbk
;
237 wxSndError m_snderror
;
247 virtual bool QueueBuffer(wxSndBuffer
& buf
);
249 virtual bool UnqueueBuffer(wxSndBuffer
& buf
);
251 inline wxSndBuffer
*LastBufferPlayed()
252 { return m_lastbuf
; }
255 wxSndError
GetError() { return m_snderror
; }
258 void Callback(wxSndCallback cbk
);
260 void SetClientData(char *cdata
);
262 virtual void OnPlayBuffer(wxSndBuffer
& buf
);
265 virtual bool Wakeup(wxSndBuffer
& buf
) = 0;
267 virtual void StopBuffer(wxSndBuffer
& buf
) = 0;
270 virtual inline bool OnSetupDriver(wxSndBuffer
& WXUNUSED(buf
),
271 wxSndMode
WXUNUSED(mode
))