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