]>
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
->m_orig_format
.SetSampleRate(m_srate
);
110 pcm_codec
->m_orig_format
.SetBps(m_bps
);
111 pcm_codec
->m_orig_format
.SetChannels(m_channels
);
112 pcm_codec
->m_orig_format
.SetByteOrder(m_byteorder
);
113 pcm_codec
->m_orig_format
.SetSign(m_sign
);
117 codec
->InitWith(*this);
122 wxSoundDataFormat
& wxSoundDataFormat::operator =(const wxSoundDataFormat
& format
)
126 m_srate
= format
.m_srate
;
127 m_bps
= format
.m_bps
;
128 m_channels
= format
.m_channels
;
129 m_codno
= format
.m_codno
;
130 m_sign
= format
.m_sign
;
131 m_byteorder
= format
.m_byteorder
;
136 bool wxSoundDataFormat::operator ==(const wxSoundDataFormat
& format
) const
138 if (m_codno
!= format
.m_codno
|| m_srate
!= format
.m_srate
||
139 m_bps
!= format
.m_bps
|| m_channels
!= format
.m_channels
)
142 if (m_codno
== WXSOUND_PCM
&&
143 (m_sign
!= format
.m_sign
|| m_byteorder
!= format
.m_byteorder
))
149 // ----------------------------------------------------------------------------
151 // ----------------------------------------------------------------------------
154 #include "sndadpcm.h"
155 //#include "sndalaw.h"
156 #include "sndmulaw.h"
158 static wxClassInfo
*l_sound_formats
[] = {
160 CLASSINFO(wxSoundPcmCodec
),
161 CLASSINFO(wxSoundAdpcmCodec
),
165 NULL
, // CLASSINFO(wxSoundAlawCodec),
166 CLASSINFO(wxSoundMulawCodec
)
169 static int l_nb_formats
= WXSIZEOF(l_sound_formats
);
171 wxSoundCodec::wxSoundCodec()
176 m_chain_codec
= NULL
;
179 wxSoundCodec::~wxSoundCodec()
181 if (m_mode
!= WAITING
)
185 void wxSoundCodec::InitIO(const wxSoundDataFormat
& format
)
187 m_io_format
= format
;
190 void wxSoundCodec::InitMode(ModeType mode
)
192 wxStreamBuffer
*buf_snd
;
195 if (!m_chain_codec
) {
196 if (m_mode
== ENCODING
) {
197 m_out_sound
= new wxStreamBuffer(*this, wxStreamBuffer::write
);
198 m_out_sound
->SetBufferIO(1024);
200 m_in_sound
= new wxStreamBuffer(*this, wxStreamBuffer::read
);
201 m_in_sound
->SetBufferIO(1024);
205 if (m_chain_before
) {
206 m_chain_codec
->SetInStream(m_in_sound
);
207 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
208 buf_snd
->Fixed(FALSE
);
209 m_chain_codec
->SetOutStream(buf_snd
);
210 m_chain_codec
->Decode();
211 buf_snd
->Seek(0, wxFromStart
);
212 m_in_sound
= buf_snd
;
214 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
215 buf_snd
->Fixed(FALSE
);
217 m_chain_codec
->SetInStream(buf_snd
);
218 m_chain_codec
->SetOutStream(m_out_sound
);
219 m_out_sound
= buf_snd
;
221 buf_snd
->Seek(0, wxFromStart
);
226 void wxSoundCodec::ExitMode()
229 if (m_chain_before
) {
231 m_in_sound
= m_chain_codec
->GetInStream();
234 m_out_sound
= m_chain_codec
->GetOutStream();
240 bool wxSoundCodec::ChainCodecBefore(wxSoundDataFormat
& format
)
242 m_chain_codec
= format
.GetCodec();
247 m_chain_before
= TRUE
;
251 bool wxSoundCodec::ChainCodecAfter(wxSoundDataFormat
& format
)
253 m_chain_codec
= format
.GetCodec();
258 m_chain_before
= FALSE
;
262 void wxSoundCodec::CopyToOutput()
264 m_out_sound
->Write(m_in_sound
);
267 size_t wxSoundCodec::Available()
269 return m_io_sndbuf
->Available();
272 size_t wxSoundCodec::OnSysRead(void *buffer
, size_t bsize
)
275 m_io_sndbuf
->OnNeedOutputData((char *)buffer
, s
);
279 size_t wxSoundCodec::OnSysWrite(const void *buffer
, size_t bsize
)
282 m_io_sndbuf
->OnBufferInFinished((char *)buffer
, s
);
286 wxSoundCodec
*wxSoundCodec::Get(int no
)
288 if (no
< 0 || no
>= l_nb_formats
)
291 if (!l_sound_formats
[no
])
294 return (wxSoundCodec
*)l_sound_formats
[no
]->CreateObject();