]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndfrmt.cpp
a489109d1e2388db27ef61798341980b2e54f4e9
2 #pragma implementation "sndfrmt.h"
8 // ----------------------------------------------------------------------------
10 // ----------------------------------------------------------------------------
12 wxSoundDataFormat::wxSoundDataFormat()
23 wxSoundDataFormat::wxSoundDataFormat(const wxSoundDataFormat
& format
)
25 m_srate
= format
.m_srate
;
27 m_channels
= format
.m_channels
;
28 m_codno
= format
.m_codno
;
29 m_sign
= format
.m_sign
;
30 m_byteorder
= format
.m_byteorder
;
36 wxSoundDataFormat::~wxSoundDataFormat()
41 void wxSoundDataFormat::SetChannels(int channels
)
43 m_channels
= channels
;
46 void wxSoundDataFormat::SetBps(int bps
)
52 void wxSoundDataFormat::SetSign(int sign
)
58 void wxSoundDataFormat::SetByteOrder(int byteorder
)
60 m_byteorder
= byteorder
;
64 void wxSoundDataFormat::SetCodecNo(int codno
)
71 wxSoundCodec
*wxSoundDataFormat::GetCodec()
83 m_codec
= wxSoundCodec::Get(m_codno
);
88 void wxSoundDataFormat::CodecChange()
90 wxSoundCodec
*codec
= GetCodec();
97 wxSoundPcmCodec
*pcm_codec
= (wxSoundPcmCodec
*)codec
;
99 pcm_codec
->SetBits(m_bps
);
100 pcm_codec
->SetByteOrder(m_byteorder
);
101 pcm_codec
->SetSign(m_sign
);
109 wxSoundDataFormat
& wxSoundDataFormat::operator =(const wxSoundDataFormat
& format
)
113 m_srate
= format
.m_srate
;
114 m_bps
= format
.m_bps
;
115 m_channels
= format
.m_channels
;
116 m_codno
= format
.m_codno
;
117 m_sign
= format
.m_sign
;
118 m_byteorder
= format
.m_byteorder
;
123 bool wxSoundDataFormat::operator ==(const wxSoundDataFormat
& format
) const
125 if (m_codno
!= format
.m_codno
|| m_srate
!= format
.m_srate
||
126 m_bps
!= format
.m_bps
|| m_channels
!= format
.m_channels
)
129 if (m_codno
== WXSOUND_PCM
&&
130 (m_sign
!= format
.m_sign
|| m_byteorder
!= format
.m_byteorder
))
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
141 //#include "sndadpcm.h"
142 //#include "sndalaw.h"
143 #include "sndmulaw.h"
145 static wxClassInfo
*l_sound_formats
[] = {
147 CLASSINFO(wxSoundPcmCodec
),
148 NULL
, // CLASSINFO(wxSoundAdpcmCodec),
152 NULL
, // CLASSINFO(wxSoundAlawCodec),
153 NULL
// CLASSINFO(wxSoundMulawCodec)
156 static int l_nb_formats
= WXSIZEOF(l_sound_formats
);
158 wxSoundCodec::wxSoundCodec()
163 m_chain_codec
= NULL
;
166 wxSoundCodec::~wxSoundCodec()
170 void wxSoundCodec::InitIO(const wxSoundDataFormat
& format
)
172 m_io_format
= format
;
175 void wxSoundCodec::InitMode(int mode
)
177 wxStreamBuffer
*buf_snd
;
179 m_mode
= (mode
== 0) ? ENCODING
: DECODING
;
180 if (!m_chain_codec
) {
181 if (mode
== ENCODING
) {
182 m_out_sound
= new wxStreamBuffer(*this, wxStreamBuffer::write
);
183 m_out_sound
->SetBufferIO(1024);
185 m_in_sound
= new wxStreamBuffer(*this, wxStreamBuffer::read
);
186 m_in_sound
->SetBufferIO(1024);
190 if (m_chain_before
) {
191 m_chain_codec
->SetInStream(m_in_sound
);
192 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
193 buf_snd
->Fixed(FALSE
);
194 m_chain_codec
->SetOutStream(buf_snd
);
195 m_chain_codec
->Decode();
196 buf_snd
->Seek(0, wxFromStart
);
197 m_in_sound
= buf_snd
;
199 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
200 buf_snd
->Fixed(FALSE
);
202 m_chain_codec
->SetInStream(buf_snd
);
203 m_chain_codec
->SetOutStream(m_out_sound
);
204 m_out_sound
= buf_snd
;
206 buf_snd
->Seek(0, wxFromStart
);
211 void wxSoundCodec::ExitMode()
214 if (m_chain_before
) {
216 m_in_sound
= m_chain_codec
->GetInStream();
219 m_out_sound
= m_chain_codec
->GetOutStream();
224 bool wxSoundCodec::ChainCodecBefore(wxSoundDataFormat
& format
)
226 m_chain_codec
= format
.GetCodec();
231 m_chain_before
= TRUE
;
235 bool wxSoundCodec::ChainCodecAfter(wxSoundDataFormat
& format
)
237 m_chain_codec
= format
.GetCodec();
242 m_chain_before
= FALSE
;
246 void wxSoundCodec::CopyToOutput()
248 m_out_sound
->Write(m_in_sound
);
251 size_t wxSoundCodec::Available()
253 return m_io_sndbuf
->Available();
256 size_t wxSoundCodec::OnSysRead(void *buffer
, size_t bsize
)
259 m_io_sndbuf
->OnNeedOutputData((char *)buffer
, s
);
263 size_t wxSoundCodec::OnSysWrite(const void *buffer
, size_t bsize
)
266 m_io_sndbuf
->OnBufferInFinished((char *)buffer
, s
);
270 wxSoundCodec
*wxSoundCodec::Get(int no
)
272 if (no
< 0 || no
>= l_nb_formats
)
275 if (!l_sound_formats
[no
])
278 return (wxSoundCodec
*)l_sound_formats
[no
]->CreateObject();