]>
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
);
121 wxSoundDataFormat
& wxSoundDataFormat::operator =(const wxSoundDataFormat
& format
)
125 m_srate
= format
.m_srate
;
126 m_bps
= format
.m_bps
;
127 m_channels
= format
.m_channels
;
128 m_codno
= format
.m_codno
;
129 m_sign
= format
.m_sign
;
130 m_byteorder
= format
.m_byteorder
;
135 bool wxSoundDataFormat::operator ==(const wxSoundDataFormat
& format
) const
137 if (m_codno
!= format
.m_codno
|| m_srate
!= format
.m_srate
||
138 m_bps
!= format
.m_bps
|| m_channels
!= format
.m_channels
)
141 if (m_codno
== WXSOUND_PCM
&&
142 (m_sign
!= format
.m_sign
|| m_byteorder
!= format
.m_byteorder
))
148 // ----------------------------------------------------------------------------
150 // ----------------------------------------------------------------------------
153 //#include "sndadpcm.h"
154 //#include "sndalaw.h"
155 #include "sndmulaw.h"
157 static wxClassInfo
*l_sound_formats
[] = {
159 CLASSINFO(wxSoundPcmCodec
),
160 NULL
, // CLASSINFO(wxSoundAdpcmCodec),
164 NULL
, // CLASSINFO(wxSoundAlawCodec),
165 NULL
// CLASSINFO(wxSoundMulawCodec)
168 static int l_nb_formats
= WXSIZEOF(l_sound_formats
);
170 wxSoundCodec::wxSoundCodec()
175 m_chain_codec
= NULL
;
178 wxSoundCodec::~wxSoundCodec()
180 if (m_mode
!= WAITING
)
184 void wxSoundCodec::InitIO(const wxSoundDataFormat
& format
)
186 m_io_format
= format
;
189 void wxSoundCodec::InitMode(ModeType mode
)
191 wxStreamBuffer
*buf_snd
;
194 if (!m_chain_codec
) {
195 if (m_mode
== ENCODING
) {
196 m_out_sound
= new wxStreamBuffer(*this, wxStreamBuffer::write
);
197 m_out_sound
->SetBufferIO(1024);
199 m_in_sound
= new wxStreamBuffer(*this, wxStreamBuffer::read
);
200 m_in_sound
->SetBufferIO(1024);
204 if (m_chain_before
) {
205 m_chain_codec
->SetInStream(m_in_sound
);
206 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
207 buf_snd
->Fixed(FALSE
);
208 m_chain_codec
->SetOutStream(buf_snd
);
209 m_chain_codec
->Decode();
210 buf_snd
->Seek(0, wxFromStart
);
211 m_in_sound
= buf_snd
;
213 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
214 buf_snd
->Fixed(FALSE
);
216 m_chain_codec
->SetInStream(buf_snd
);
217 m_chain_codec
->SetOutStream(m_out_sound
);
218 m_out_sound
= buf_snd
;
220 buf_snd
->Seek(0, wxFromStart
);
225 void wxSoundCodec::ExitMode()
228 if (m_chain_before
) {
230 m_in_sound
= m_chain_codec
->GetInStream();
233 m_out_sound
= m_chain_codec
->GetOutStream();
239 bool wxSoundCodec::ChainCodecBefore(wxSoundDataFormat
& format
)
241 m_chain_codec
= format
.GetCodec();
246 m_chain_before
= TRUE
;
250 bool wxSoundCodec::ChainCodecAfter(wxSoundDataFormat
& format
)
252 m_chain_codec
= format
.GetCodec();
257 m_chain_before
= FALSE
;
261 void wxSoundCodec::CopyToOutput()
263 m_out_sound
->Write(m_in_sound
);
266 size_t wxSoundCodec::Available()
268 return m_io_sndbuf
->Available();
271 size_t wxSoundCodec::OnSysRead(void *buffer
, size_t bsize
)
274 m_io_sndbuf
->OnNeedOutputData((char *)buffer
, s
);
278 size_t wxSoundCodec::OnSysWrite(const void *buffer
, size_t bsize
)
281 m_io_sndbuf
->OnBufferInFinished((char *)buffer
, s
);
285 wxSoundCodec
*wxSoundCodec::Get(int no
)
287 if (no
< 0 || no
>= l_nb_formats
)
290 if (!l_sound_formats
[no
])
293 return (wxSoundCodec
*)l_sound_formats
[no
]->CreateObject();