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