]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndfrmt.cpp
2 #pragma implementation "sndfrmt.h"
9 // ----------------------------------------------------------------------------
11 // ----------------------------------------------------------------------------
13 wxSoundDataFormat::wxSoundDataFormat()
24 wxSoundDataFormat::~wxSoundDataFormat()
29 void wxSoundDataFormat::SetChannels(int channels
)
31 m_channels
= channels
;
34 void wxSoundDataFormat::SetBps(int bps
)
40 void wxSoundDataFormat::SetSign(int sign
)
46 void wxSoundDataFormat::SetByteOrder(int byteorder
)
48 m_byteorder
= byteorder
;
52 void wxSoundDataFormat::SetCodecNo(int codno
)
59 wxSoundCodec
*wxSoundDataFormat::GetCodec()
71 m_codec
= wxSoundCodec::Get(m_codno
);
76 void wxSoundDataFormat::CodecChange()
78 wxSoundCodec
*codec
= GetCodec();
85 wxSoundPcmCodec
*pcm_codec
= (wxSoundPcmCodec
*)codec
;
87 pcm_codec
->SetBits(m_bps
);
88 pcm_codec
->SetByteOrder(m_byteorder
);
89 pcm_codec
->SetSign(m_sign
);
97 wxSoundDataFormat
& wxSoundDataFormat::operator =(const wxSoundDataFormat
& format
)
101 m_srate
= format
.m_srate
;
102 m_bps
= format
.m_bps
;
103 m_channels
= format
.m_channels
;
104 m_codno
= format
.m_codno
;
105 m_sign
= format
.m_sign
;
106 m_byteorder
= format
.m_byteorder
;
111 bool wxSoundDataFormat::operator ==(const wxSoundDataFormat
& format
) const
113 if (m_codno
!= format
.m_codno
|| m_srate
!= format
.m_srate
||
114 m_bps
!= format
.m_bps
|| m_channels
!= format
.m_channels
)
117 if (m_codno
== WXSOUND_PCM
&&
118 (m_sign
!= format
.m_sign
|| m_byteorder
!= format
.m_byteorder
))
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
129 //#include "sndadpcm.h"
130 //#include "sndalaw.h"
131 #include "sndmulaw.h"
133 static wxClassInfo
*l_sound_formats
[] = {
135 CLASSINFO(wxSoundPcmCodec
),
136 NULL
, // CLASSINFO(wxSoundAdpcmCodec),
140 NULL
, // CLASSINFO(wxSoundAlawCodec),
141 NULL
// CLASSINFO(wxSoundMulawCodec)
144 static int l_nb_formats
= WXSIZEOF(l_sound_formats
);
146 wxSoundCodec::wxSoundCodec()
153 wxSoundCodec::~wxSoundCodec()
157 void wxSoundCodec::InitIO(const wxSoundDataFormat
& format
)
159 m_io_format
= format
;
162 void wxSoundCodec::InitMode(int mode
)
164 wxStreamBuffer
*buf_snd
;
166 m_mode
= (mode
== 0) ? ENCODING
: DECODING
;
167 if (!m_chain_codec
) {
168 if (mode
== ENCODING
) {
169 m_out_sound
= new wxStreamBuffer(*this, wxStreamBuffer::write
);
170 m_out_sound
->SetBufferIO(1024);
172 m_in_sound
= new wxStreamBuffer(*this, wxStreamBuffer::read
);
173 m_in_sound
->SetBufferIO(1024);
177 if (m_chain_before
) {
178 m_chain_codec
->SetInStream(m_in_sound
);
179 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
180 buf_snd
->Fixed(FALSE
);
181 m_chain_codec
->SetOutStream(buf_snd
);
182 m_chain_codec
->Decode();
183 buf_snd
->Seek(0, wxFromStart
);
184 m_in_sound
= buf_snd
;
186 buf_snd
= new wxStreamBuffer(wxStreamBuffer::read_write
);
187 buf_snd
->Fixed(FALSE
);
189 m_chain_codec
->SetInStream(buf_snd
);
190 m_chain_codec
->SetOutStream(m_out_sound
);
191 m_out_sound
= buf_snd
;
193 buf_snd
->Seek(0, wxFromStart
);
198 void wxSoundCodec::ExitMode()
201 if (m_chain_before
) {
203 m_in_sound
= m_chain_codec
->GetInStream();
206 m_out_sound
= m_chain_codec
->GetOutStream();
211 bool wxSoundCodec::ChainCodecBefore(wxSoundDataFormat
& format
)
213 m_chain_codec
= format
.GetCodec();
218 m_chain_before
= TRUE
;
222 bool wxSoundCodec::ChainCodecAfter(wxSoundDataFormat
& format
)
224 m_chain_codec
= format
.GetCodec();
229 m_chain_before
= FALSE
;
233 void wxSoundCodec::CopyToOutput()
235 m_out_sound
->Write(m_in_sound
);
238 size_t wxSoundCodec::Available()
240 return m_io_sndbuf
->Available();
243 size_t wxSoundCodec::OnSysRead(void *buffer
, size_t bsize
)
246 m_io_sndbuf
->OnNeedOutputData((char *)buffer
, s
);
250 size_t wxSoundCodec::OnSysWrite(const void *buffer
, size_t bsize
)
253 m_io_sndbuf
->OnBufferInFinished((char *)buffer
, s
);
257 wxSoundCodec
*wxSoundCodec::Get(int no
)
259 if (no
< 0 || no
>= l_nb_formats
)
262 if (!l_sound_formats
[no
])
265 return (wxSoundCodec
*)l_sound_formats
[no
]->CreateObject();