]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndfrmt.cpp
750f17c83b34effe4bee52b089c4a07d070184e2
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()
168 if (m_mode
!= WAITING
)
172 void wxSoundCodec::InitIO(const wxSoundDataFormat
& format
)
174 m_io_format
= format
;
177 void wxSoundCodec::InitMode(ModeType mode
)
179 wxStreamBuffer
*buf_snd
;
182 if (!m_chain_codec
) {
183 if (m_mode
== ENCODING
) {
184 m_out_sound
= new wxStreamBuffer(*this, wxStreamBuffer::write
);
185 m_out_sound
->SetBufferIO(1024);
187 m_in_sound
= new wxStreamBuffer(*this, wxStreamBuffer::read
);
188 m_in_sound
->SetBufferIO(1024);
192 if (m_chain_before
) {
193 m_chain_codec
->SetInStream(m_in_sound
);
194 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
195 buf_snd
->Fixed(FALSE
);
196 m_chain_codec
->SetOutStream(buf_snd
);
197 m_chain_codec
->Decode();
198 buf_snd
->Seek(0, wxFromStart
);
199 m_in_sound
= buf_snd
;
201 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
202 buf_snd
->Fixed(FALSE
);
204 m_chain_codec
->SetInStream(buf_snd
);
205 m_chain_codec
->SetOutStream(m_out_sound
);
206 m_out_sound
= buf_snd
;
208 buf_snd
->Seek(0, wxFromStart
);
213 void wxSoundCodec::ExitMode()
216 if (m_chain_before
) {
218 m_in_sound
= m_chain_codec
->GetInStream();
221 m_out_sound
= m_chain_codec
->GetOutStream();
227 bool wxSoundCodec::ChainCodecBefore(wxSoundDataFormat
& format
)
229 m_chain_codec
= format
.GetCodec();
234 m_chain_before
= TRUE
;
238 bool wxSoundCodec::ChainCodecAfter(wxSoundDataFormat
& format
)
240 m_chain_codec
= format
.GetCodec();
245 m_chain_before
= FALSE
;
249 void wxSoundCodec::CopyToOutput()
251 m_out_sound
->Write(m_in_sound
);
254 size_t wxSoundCodec::Available()
256 return m_io_sndbuf
->Available();
259 size_t wxSoundCodec::OnSysRead(void *buffer
, size_t bsize
)
262 m_io_sndbuf
->OnNeedOutputData((char *)buffer
, s
);
266 size_t wxSoundCodec::OnSysWrite(const void *buffer
, size_t bsize
)
269 m_io_sndbuf
->OnBufferInFinished((char *)buffer
, s
);
273 wxSoundCodec
*wxSoundCodec::Get(int no
)
275 if (no
< 0 || no
>= l_nb_formats
)
278 if (!l_sound_formats
[no
])
281 return (wxSoundCodec
*)l_sound_formats
[no
]->CreateObject();