]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndfrmt.cpp
1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
6 // Updated: December 1998
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "sndfrmt.h"
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
21 wxSoundDataFormat::wxSoundDataFormat()
32 wxSoundDataFormat::wxSoundDataFormat(const wxSoundDataFormat
& format
)
34 m_srate
= format
.m_srate
;
36 m_channels
= format
.m_channels
;
37 m_codno
= format
.m_codno
;
38 m_sign
= format
.m_sign
;
39 m_byteorder
= format
.m_byteorder
;
45 wxSoundDataFormat::~wxSoundDataFormat()
50 void wxSoundDataFormat::SetChannels(int channels
)
52 m_channels
= channels
;
55 void wxSoundDataFormat::SetBps(int bps
)
61 void wxSoundDataFormat::SetSign(int sign
)
67 void wxSoundDataFormat::SetByteOrder(int byteorder
)
69 m_byteorder
= byteorder
;
73 void wxSoundDataFormat::SetCodecNo(int codno
)
80 wxSoundCodec
*wxSoundDataFormat::GetCodec()
92 m_codec
= wxSoundCodec::Get(m_codno
);
98 void wxSoundDataFormat::CodecChange()
100 wxSoundCodec
*codec
= GetCodec();
107 wxSoundPcmCodec
*pcm_codec
= (wxSoundPcmCodec
*)codec
;
109 pcm_codec
->SetBits(m_bps
);
110 pcm_codec
->SetByteOrder(m_byteorder
);
111 pcm_codec
->SetSign(m_sign
);
119 wxSoundDataFormat
& wxSoundDataFormat::operator =(const wxSoundDataFormat
& format
)
123 m_srate
= format
.m_srate
;
124 m_bps
= format
.m_bps
;
125 m_channels
= format
.m_channels
;
126 m_codno
= format
.m_codno
;
127 m_sign
= format
.m_sign
;
128 m_byteorder
= format
.m_byteorder
;
133 bool wxSoundDataFormat::operator ==(const wxSoundDataFormat
& format
) const
135 if (m_codno
!= format
.m_codno
|| m_srate
!= format
.m_srate
||
136 m_bps
!= format
.m_bps
|| m_channels
!= format
.m_channels
)
139 if (m_codno
== WXSOUND_PCM
&&
140 (m_sign
!= format
.m_sign
|| m_byteorder
!= format
.m_byteorder
))
146 // ----------------------------------------------------------------------------
148 // ----------------------------------------------------------------------------
151 //#include "sndadpcm.h"
152 //#include "sndalaw.h"
153 #include "sndmulaw.h"
155 static wxClassInfo
*l_sound_formats
[] = {
157 CLASSINFO(wxSoundPcmCodec
),
158 NULL
, // CLASSINFO(wxSoundAdpcmCodec),
162 NULL
, // CLASSINFO(wxSoundAlawCodec),
163 NULL
// CLASSINFO(wxSoundMulawCodec)
166 static int l_nb_formats
= WXSIZEOF(l_sound_formats
);
168 wxSoundCodec::wxSoundCodec()
173 m_chain_codec
= NULL
;
176 wxSoundCodec::~wxSoundCodec()
178 if (m_mode
!= WAITING
)
182 void wxSoundCodec::InitIO(const wxSoundDataFormat
& format
)
184 m_io_format
= format
;
187 void wxSoundCodec::InitMode(ModeType mode
)
189 wxStreamBuffer
*buf_snd
;
192 if (!m_chain_codec
) {
193 if (m_mode
== ENCODING
) {
194 m_out_sound
= new wxStreamBuffer(*this, wxStreamBuffer::write
);
195 m_out_sound
->SetBufferIO(1024);
197 m_in_sound
= new wxStreamBuffer(*this, wxStreamBuffer::read
);
198 m_in_sound
->SetBufferIO(1024);
202 if (m_chain_before
) {
203 m_chain_codec
->SetInStream(m_in_sound
);
204 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
205 buf_snd
->Fixed(FALSE
);
206 m_chain_codec
->SetOutStream(buf_snd
);
207 m_chain_codec
->Decode();
208 buf_snd
->Seek(0, wxFromStart
);
209 m_in_sound
= buf_snd
;
211 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
212 buf_snd
->Fixed(FALSE
);
214 m_chain_codec
->SetInStream(buf_snd
);
215 m_chain_codec
->SetOutStream(m_out_sound
);
216 m_out_sound
= buf_snd
;
218 buf_snd
->Seek(0, wxFromStart
);
223 void wxSoundCodec::ExitMode()
226 if (m_chain_before
) {
228 m_in_sound
= m_chain_codec
->GetInStream();
231 m_out_sound
= m_chain_codec
->GetOutStream();
237 bool wxSoundCodec::ChainCodecBefore(wxSoundDataFormat
& format
)
239 m_chain_codec
= format
.GetCodec();
244 m_chain_before
= TRUE
;
248 bool wxSoundCodec::ChainCodecAfter(wxSoundDataFormat
& format
)
250 m_chain_codec
= format
.GetCodec();
255 m_chain_before
= FALSE
;
259 void wxSoundCodec::CopyToOutput()
261 m_out_sound
->Write(m_in_sound
);
264 size_t wxSoundCodec::Available()
266 return m_io_sndbuf
->Available();
269 size_t wxSoundCodec::OnSysRead(void *buffer
, size_t bsize
)
272 m_io_sndbuf
->OnNeedOutputData((char *)buffer
, s
);
276 size_t wxSoundCodec::OnSysWrite(const void *buffer
, size_t bsize
)
279 m_io_sndbuf
->OnBufferInFinished((char *)buffer
, s
);
283 wxSoundCodec
*wxSoundCodec::Get(int no
)
285 if (no
< 0 || no
>= l_nb_formats
)
288 if (!l_sound_formats
[no
])
291 return (wxSoundCodec
*)l_sound_formats
[no
]->CreateObject();