]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/sndbase.cpp
wxWinCE warning fix.
[wxWidgets.git] / contrib / src / mmedia / sndbase.cpp
1 // --------------------------------------------------------------------------
2 // Name: sndbase.cpp
3 // Purpose:
4 // Date: 08/11/1999
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999, 2000
6 // CVSID: $Id$
7 // wxWindows licence
8 // --------------------------------------------------------------------------
9
10 #include "wx/wxprec.h"
11
12 #ifndef WX_PRECOMP
13 #include "wx/defs.h"
14 #include "wx/string.h"
15 #include "wx/log.h"
16 #endif
17
18 #include "wx/mmedia/sndbase.h"
19
20
21 // ---------------------------------------------------------------------------
22 // wxSoundFormatBase
23 // ---------------------------------------------------------------------------
24
25 wxSoundFormatBase::wxSoundFormatBase()
26 {
27 }
28
29 wxSoundFormatBase::~wxSoundFormatBase()
30 {
31 }
32
33 wxSoundFormatBase *wxSoundFormatBase::Clone() const
34 {
35 wxLogFatalError(wxT("In wxSoundFormatBase::Clone() but I should")
36 wxT(" not be there"));
37 return NULL;
38 }
39
40 bool wxSoundFormatBase::operator!=(const wxSoundFormatBase& frmt2) const
41 {
42 return (GetType() != frmt2.GetType());
43 }
44
45 // ---------------------------------------------------------------------------
46 // wxSoundStream
47 // ---------------------------------------------------------------------------
48
49 wxSoundStream::wxSoundStream()
50 {
51 int i;
52
53 // Reset all variables to their neutral value.
54 m_sndformat = NULL;
55 m_handler = NULL;
56 m_snderror = wxSOUND_NOERROR;
57 m_lastcount = 0;
58 for (i=0;i<2;i++)
59 m_callback[i] = NULL;
60 }
61
62 wxSoundStream::~wxSoundStream()
63 {
64 if (m_sndformat)
65 delete m_sndformat;
66 }
67
68 // --------------------------------------------------------------------------
69 // SetSoundFormat(const wxSoundFormatBase& format) is one of the most
70 // important function of the wxSoundStream class. It prepares the stream to
71 // receive or send the data in a strict format. Normally, the sound stream
72 // should be ready to accept any format it is asked to manage but in certain
73 // cases, it really cannot: in that case it returns false. To have more
74 // details in the functionnalities of SetSoundFormat see
75 // wxSoundRouterStream::SetSoundFormat()
76 // --------------------------------------------------------------------------
77 bool wxSoundStream::SetSoundFormat(const wxSoundFormatBase& format)
78 {
79 // delete the previous prepared format
80 if (m_sndformat)
81 delete m_sndformat;
82
83 // create a new one by cloning the format passed in parameter
84 m_sndformat = format.Clone();
85 return true;
86 }
87
88
89 // --------------------------------------------------------------------------
90 // Register(int evt, ...) registers the callback for a specified async event.
91 // Warning ! Only one callback by event is supported. It means that if you
92 // call twice this function the previous registered callback is absolutely
93 // ignored.
94 // --------------------------------------------------------------------------
95 void wxSoundStream::SetCallback(int evt, wxSoundCallback cbk, void *cdata)
96 {
97 int c;
98
99 switch (evt) {
100 case wxSOUND_INPUT:
101 c = 0;
102 break;
103 case wxSOUND_OUTPUT:
104 c = 1;
105 break;
106 default:
107 return;
108 }
109 m_callback[c] = cbk;
110 m_cdata[c] = cdata;
111 }
112
113 // --------------------------------------------------------------------------
114 // OnSoundEvent(int evt) is called either when the driver is ready to receive
115 // a new block to play or when the driver has a new recorded buffer. You
116 // must be careful here and try not to spend a lot of time: this is a
117 // real-time call. In the case, an "event handler" was specified previously,
118 // it called him before everything.
119 // --------------------------------------------------------------------------
120 void wxSoundStream::OnSoundEvent(int evt)
121 {
122 int c;
123
124 if (m_handler) {
125 m_handler->OnSoundEvent(evt);
126 return;
127 }
128
129 switch (evt) {
130 case wxSOUND_INPUT:
131 c = 0;
132 break;
133 case wxSOUND_OUTPUT:
134 c = 1;
135 break;
136 default:
137 return;
138 }
139 if (m_callback[c])
140 m_callback[c](this, evt, m_cdata[c]);
141 }