]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndsnd.cpp
1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "sndsnd.h"
25 #define PROCESS_EVENT() wxYield()
26 // #define PROCESS_EVENT()
28 // ----------------------------------------------------------------------------
29 // wxSndBuffer: base sound buffer class
30 // ----------------------------------------------------------------------------
33 wxSndBuffer::wxSndBuffer()
34 : m_sndmode(wxSND_OUTPUT
), m_sndflags(0), m_sndoutput(NULL
), m_sndcodec(NULL
)
38 wxSndBuffer::~wxSndBuffer()
42 void wxSndBuffer::Set(wxSndFlags flags
)
46 if ((m_sndflags
& wxSND_BUFAUTO
) && (flags
& wxSND_BUFREADY
))
47 m_sndoutput
->QueueBuffer(*this);
50 void wxSndBuffer::SetError(wxSndError error
)
52 if (error
== wxSND_NOERROR
)
60 wxSndError
wxSndBuffer::GetError()
62 if (IsNotSet(wxSND_BUFERR
))
68 void wxSndBuffer::OnPlayFinished()
72 void wxSndBuffer::OnBufferOutFinished()
76 void wxSndBuffer::OnBufferInFinished(char *WXUNUSED(iobuf
),
77 wxUint32
& WXUNUSED(size
))
81 bool wxSndBuffer::Wait()
83 if (IsNotSet(wxSND_BUFLOCKED
))
86 while (IsSet(wxSND_BUFLOCKED
))
89 return IsNotSet(wxSND_BUFERR
);
92 void wxSndBuffer::HardLock()
97 void wxSndBuffer::HardUnlock()
102 void wxSndBuffer::ChangeCodec(int no
)
104 m_sndformat
.SetCodecNo(no
);
105 m_sndcodec
= m_sndformat
.GetCodec();
106 m_sndcodec
->SetIOBuffer(this);
109 // ----------------------------------------------------------------------------
110 // wxSndSimpleBuffer: the simplest sound buffer
111 // ----------------------------------------------------------------------------
114 wxSndSimpleBuffer::wxSndSimpleBuffer(char *buffer
, wxUint32 bufsize
,
125 wxSndSimpleBuffer::~wxSndSimpleBuffer()
129 void wxSndSimpleBuffer::OnNeedOutputData(char *iobuf
, wxUint32
& size
)
131 char *buf
= m_sndbuf
+ m_sndptr
;
132 wxUint32 nbdata_left
= m_sndsize
- m_sndptr
;
134 if (m_sndptr
>= m_sndsize
) {
139 if (size
> nbdata_left
)
144 memcpy(iobuf
, buf
, size
);
147 void wxSndSimpleBuffer::OnBufferOutFinished()
149 if (m_sndptr
>= m_sndsize
)
153 void wxSndSimpleBuffer::OnBufferInFinished(char *iobuf
, wxUint32
& size
)
155 char *raw_buf
= m_sndbuf
+ m_sndptr
;
156 wxUint32 data_left
= m_sndsize
- m_sndptr
;
163 if (size
> data_left
)
166 memcpy(raw_buf
, iobuf
, size
);
170 void wxSndSimpleBuffer::SetData(char *buffer
, wxUint32 bufsize
,
178 bool wxSndSimpleBuffer::RestartBuffer(wxSndMode mode
)
184 wxUint32
wxSndSimpleBuffer::GetSize() const
189 wxUint32
wxSndSimpleBuffer::Available() const
191 return m_sndsize
- m_sndptr
;
194 // ----------------------------------------------------------------------------
195 // wxSound: base sound driver implementation
196 // ----------------------------------------------------------------------------
200 m_lastbuf(NULL
), m_sndcbk(NULL
), m_snderror(wxSND_NOERROR
)
207 wxNode
*node
= m_buffers
.First();
210 wxSndBuffer
*buf
= (wxSndBuffer
*)node
->Data();
212 buf
->Clear(wxSND_BUFLOCKED
);
216 bool wxSound::QueueBuffer(wxSndBuffer
& buf
)
218 if (buf
.IsSet(wxSND_BUFLOCKED
) || buf
.IsNotSet(wxSND_BUFREADY
))
221 buf
.Set(wxSND_BUFLOCKED
);
222 buf
.SetOutput(*this);
224 m_buffers
.Append(&buf
);
228 bool wxSound::UnqueueBuffer(wxSndBuffer
& buf
)
232 if (buf
.IsNotSet(wxSND_BUFLOCKED
))
235 node
= m_buffers
.Member(&buf
);
240 node
= m_buffers
.Member(&buf
);
247 void wxSound::Callback(wxSndCallback cbk
)
252 void wxSound::SetClientData(char *cdata
)
257 void wxSound::OnPlayBuffer(wxSndBuffer
& buf
)
261 m_sndcbk(*this, buf
, m_cdata
);