]>
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 wxDELETE(m_sndcodec
);
106 m_sndformat
.SetCodecNo(no
);
107 m_sndcodec
= m_sndformat
.GetCodec();
108 m_sndcodec
->SetIOBuffer(this);
111 // ----------------------------------------------------------------------------
112 // wxSndSimpleBuffer: the simplest sound buffer
113 // ----------------------------------------------------------------------------
116 wxSndSimpleBuffer::wxSndSimpleBuffer(char *buffer
, wxUint32 bufsize
,
127 wxSndSimpleBuffer::~wxSndSimpleBuffer()
131 void wxSndSimpleBuffer::OnNeedOutputData(char *iobuf
, wxUint32
& size
)
133 char *buf
= m_sndbuf
+ m_sndptr
;
134 wxUint32 nbdata_left
= m_sndsize
- m_sndptr
;
136 if (m_sndptr
>= m_sndsize
) {
141 if (size
> nbdata_left
)
146 memcpy(iobuf
, buf
, size
);
149 void wxSndSimpleBuffer::OnBufferOutFinished()
151 if (m_sndptr
>= m_sndsize
)
155 void wxSndSimpleBuffer::OnBufferInFinished(char *iobuf
, wxUint32
& size
)
157 char *raw_buf
= m_sndbuf
+ m_sndptr
;
158 wxUint32 data_left
= m_sndsize
- m_sndptr
;
165 if (size
> data_left
)
168 memcpy(raw_buf
, iobuf
, size
);
172 void wxSndSimpleBuffer::SetData(char *buffer
, wxUint32 bufsize
,
180 bool wxSndSimpleBuffer::RestartBuffer(wxSndMode mode
)
186 wxUint32
wxSndSimpleBuffer::GetSize() const
191 wxUint32
wxSndSimpleBuffer::Available() const
193 return m_sndsize
- m_sndptr
;
196 // ----------------------------------------------------------------------------
197 // wxSound: base sound driver implementation
198 // ----------------------------------------------------------------------------
202 m_lastbuf(NULL
), m_sndcbk(NULL
), m_snderror(wxSND_NOERROR
)
209 wxNode
*node
= m_buffers
.First();
212 wxSndBuffer
*buf
= (wxSndBuffer
*)node
->Data();
214 buf
->Clear(wxSND_BUFLOCKED
);
218 bool wxSound::QueueBuffer(wxSndBuffer
& buf
)
220 if (buf
.IsSet(wxSND_BUFLOCKED
) || buf
.IsNotSet(wxSND_BUFREADY
))
223 buf
.Set(wxSND_BUFLOCKED
);
224 buf
.SetOutput(*this);
226 m_buffers
.Append(&buf
);
230 bool wxSound::UnqueueBuffer(wxSndBuffer
& buf
)
234 if (buf
.IsNotSet(wxSND_BUFLOCKED
))
237 node
= m_buffers
.Member(&buf
);
242 node
= m_buffers
.Member(&buf
);
249 void wxSound::Callback(wxSndCallback cbk
)
254 void wxSound::SetClientData(char *cdata
)
259 void wxSound::OnPlayBuffer(wxSndBuffer
& buf
)
263 m_sndcbk(*this, buf
, m_cdata
);