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