]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndsnd.h
new makefiles (part I)
[wxWidgets.git] / utils / wxMMedia / sndsnd.h
1 /* Real -*- C++ -*- */
2 // /////////////////////////////////////////////////////////////////////////////
3 // Name: sndsnd.h
4 // Purpose: wxMMedia
5 // Author: Guilhem Lavaux
6 // Created: 1997
7 // Updated: 1998
8 // Copyright: (C) 1997, 1998, Guilhem Lavaux
9 // License: wxWindows license
10 // /////////////////////////////////////////////////////////////////////////////
11 #ifndef __WX_SND_SOUND_H__
12 #define __WX_SND_SOUND_H__
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #ifdef WX_PRECOMP
18 #include "wx_prec.h"
19 #else
20 #include "wx/wx.h"
21 #endif
22 #include <wx/thread.h>
23 #include "sndfrmt.h"
24 #include "mmtype.h"
25
26 class wxSound;
27 class wxSndBuffer;
28
29 typedef enum {
30 wxSND_OUTPUT,
31 wxSND_INPUT,
32 wxSND_DUPLEX,
33 wxSND_OTHER_IO
34 } /// The possible sound output modes
35 wxSndMode;
36
37 typedef enum {
38 wxSND_NOERROR = 0,
39 wxSND_NOCAPS,
40 wxSND_CANTOPEN,
41 wxSND_NOMEM,
42 wxSND_READERR,
43 wxSND_WRITEERR,
44 wxSND_CANTSET
45 } /// Sound errors
46 wxSndError;
47
48 /// Sound callback
49 typedef void (*wxSndCallback)(wxSound&, wxSndBuffer&, char *);
50
51 /// Sound flags
52 typedef wxUint16 wxSndFlags;
53
54 /** @name Sound buffer flags */
55 /// buffer ready
56 #define wxSND_BUFREADY 0x0001
57 /// an error occured
58 #define wxSND_BUFERR 0x0002
59 /// buffer is in use
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
65 ///
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
71 /// buffer will loop
72 #define wxSND_LOOP 0x0100
73
74 /** @name Sound data format */
75 /// little endian
76 #define wxSND_SAMPLE_LE 0
77 /// big endian
78 #define wxSND_SAMPLE_BE 1
79 /// unsigned samples
80 #define wxSND_SAMPLE_UNSIGNED 0
81 /// signed samples
82 #define wxSND_SAMPLE_SIGNED 1
83
84 /** @name wxSndBuffer
85 * @memo wxSndBuffer is the basic class for all the sound codec.
86 * @author Guilhem Lavaux
87 */
88 class wxSndBuffer : public wxObject {
89 /// It is an abstract class
90 DECLARE_ABSTRACT_CLASS(wxSndBuffer)
91 protected:
92 wxMutex m_mutex;
93 /// output mode
94 wxSndMode m_sndmode;
95 /// last error
96 wxSndError m_snderror;
97 /// some flag
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;
105 public:
106 /** @name constructor and destructor */
107 //@{
108 /// Construct an uninitialized wxSndBuffer
109 wxSndBuffer();
110 /// Destroy
111 virtual ~wxSndBuffer();
112 //@}
113
114 /** @name Functions returning the current state */
115 //@{
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;
124
125 /** enable the specified flags
126 * @param flags
127 */
128 void Set(wxSndFlags flags);
129 /** disable the specified flags
130 * @param flags
131 */
132 inline void Clear(wxSndFlags flags)
133 { m_sndflags &= ~flags; }
134 /** Check if the specified flags is set
135 * @param flags
136 * @return TRUE if all flags is set
137 */
138 inline bool IsSet(wxSndFlags flags) const
139 { return ((m_sndflags & flags) == flags); }
140 /** Check if the specified flags is not set
141 * @param flags
142 * @return TRUE if at least one flag is not set
143 */
144 inline bool IsNotSet(wxSndFlags flags) const
145 { return ((m_sndflags & flags) != flags); }
146 /** Check if the buffer is currently being played
147 * @return TRUE
148 if the buffer is being played
149 */
150 inline bool IsPlaying() const
151 { return IsSet(wxSND_BUFLOCKED); }
152 //@}
153
154 ///
155 inline void SetOutput(wxSound& snd)
156 { m_sndoutput = &snd; }
157 ///
158 inline wxSoundCodec *GetCurrentCodec() const
159 { return m_sndcodec; }
160 ///
161 void HardLock();
162 ///
163 void HardUnlock();
164
165 ///
166 wxSndError GetError();
167 ///
168 void SetError(wxSndError err);
169
170 ///
171 virtual bool Wait();
172 ///
173 virtual bool RestartBuffer(wxSndMode mode) = 0;
174 ///
175 virtual bool Abort() { return TRUE; }
176
177 ///
178 virtual void OnPlayFinished();
179
180 /** Data exchanging functions */
181 //@{
182 ///
183 virtual void OnNeedOutputData(char *io_buf, wxUint32& size) = 0;
184 ///
185 virtual void OnBufferOutFinished();
186 ///
187 virtual void OnBufferInFinished(char *iobuf, wxUint32& size);
188 //@}
189
190 protected:
191 void ChangeCodec(int no);
192 };
193
194 class wxSndSimpleBuffer : public wxSndBuffer {
195 DECLARE_DYNAMIC_CLASS(wxSndSimpleBuffer)
196 protected:
197 /// sound buffer
198 char *m_sndbuf;
199 /// size of the sound buffer
200 wxUint32 m_sndsize;
201 /// current position in the sound buffer
202 wxUint32 m_sndptr;
203 public:
204 wxSndSimpleBuffer(char *buffer = NULL, wxUint32 bufsize = 0,
205 wxSndMode mode = wxSND_OUTPUT);
206 virtual ~wxSndSimpleBuffer();
207
208 void SetData(char *buffer, wxUint32 bufsize,
209 wxSndMode mode = wxSND_OUTPUT);
210 inline void SetSoundFormat(const wxSoundDataFormat& format);
211
212 void OnNeedOutputData(char *io_buf, wxUint32& size);
213 void OnNeedInputData(wxUint32& size);
214
215 void OnBufferOutFinished();
216 void OnBufferInFinished(char *iobuf, wxUint32& size);
217
218 bool RestartBuffer(wxSndMode mode);
219 wxUint32 GetSize() const;
220 wxUint32 Available() const;
221 };
222
223 ///
224 class wxSound : public wxObject {
225 ///
226 DECLARE_ABSTRACT_CLASS(wxSound)
227 protected:
228 friend class wxFragmentBuffer;
229
230 ///
231 wxSndBuffer *m_lastbuf;
232 ///
233 wxList m_buffers;
234 ///
235 wxSndCallback m_sndcbk;
236 ///
237 wxSndError m_snderror;
238 ///
239 char *m_cdata;
240 public:
241 ///
242 wxSound();
243 ///
244 virtual ~wxSound();
245
246 ///
247 virtual bool QueueBuffer(wxSndBuffer& buf);
248 ///
249 virtual bool UnqueueBuffer(wxSndBuffer& buf);
250 ///
251 inline wxSndBuffer *LastBufferPlayed()
252 { return m_lastbuf; }
253
254 ///
255 wxSndError GetError() { return m_snderror; }
256
257 ///
258 void Callback(wxSndCallback cbk);
259 ///
260 void SetClientData(char *cdata);
261 ///
262 virtual void OnPlayBuffer(wxSndBuffer& buf);
263 protected:
264 ///
265 virtual bool Wakeup(wxSndBuffer& buf) = 0;
266 ///
267 virtual void StopBuffer(wxSndBuffer& buf) = 0;
268
269 ///
270 virtual inline bool OnSetupDriver(wxSndBuffer& WXUNUSED(buf),
271 wxSndMode WXUNUSED(mode))
272 { return TRUE; }
273 };
274
275 #endif