]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/sndbase.cpp
some more (apparently harmless) changes from Klass Holwerda
[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 // --------------------------------------------------------------------------
8 #ifdef __GNUG__
9 #pragma implementation "sndbase.cpp"
10 #endif
11
12 #include <wx/wxprec.h>
13 #include "wx/mmedia/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
46 // Reset all variables to their neutral value.
47 m_sndformat = NULL;
48 m_handler = NULL;
49 m_snderror = wxSOUND_NOERROR;
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
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 // --------------------------------------------------------------------------
70 bool wxSoundStream::SetSoundFormat(const wxSoundFormatBase& format)
71 {
72 // delete the previous prepared format
73 if (m_sndformat)
74 delete m_sndformat;
75
76 // create a new one by cloning the format passed in parameter
77 m_sndformat = format.Clone();
78 return TRUE;
79 }
80
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 // --------------------------------------------------------------------------
88 void wxSoundStream::SetCallback(int evt, wxSoundCallback cbk, void *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
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 // --------------------------------------------------------------------------
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 }