]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/sndulaw.cpp
1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
9 #pragma implementation "sndulaw.cpp"
12 #include <wx/wxprec.h>
19 // --------------------------------------------------------------------------
21 // --------------------------------------------------------------------------
23 wxSoundFormatUlaw::wxSoundFormatUlaw()
28 wxSoundFormatUlaw::~wxSoundFormatUlaw()
32 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate
)
37 wxUint32
wxSoundFormatUlaw::GetSampleRate() const
42 wxSoundFormatBase
*wxSoundFormatUlaw::Clone() const
44 wxSoundFormatUlaw
*ulaw
= new wxSoundFormatUlaw();
46 ulaw
->m_srate
= m_srate
;
50 wxUint32
wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes
) const
52 return (bytes
/ m_srate
);
55 wxUint32
wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time
) const
57 return time
* m_srate
;
60 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase
& frmt2
) const
62 wxSoundFormatUlaw
*ulaw
= (wxSoundFormatUlaw
*)&frmt2
;
64 if (frmt2
.GetType() != wxSOUND_ULAW
)
67 return (ulaw
->m_srate
!= m_srate
);
70 // --------------------------------------------------------------------------
72 // --------------------------------------------------------------------------
73 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream
& sndio
)
74 : wxSoundStreamCodec(sndio
)
77 m_router
= new wxSoundRouterStream(sndio
);
80 wxSoundStreamUlaw::~wxSoundStreamUlaw()
85 wxSoundStream
& wxSoundStreamUlaw::Read(void *buffer
, size_t len
)
90 wxSoundStream
& wxSoundStreamUlaw::Write(const void *buffer
, size_t len
)
93 register wxUint16
*linear_buffer
;
94 register const wxUint8
*ulaw_buffer
;
95 register size_t countdown
= len
;
97 old_linear
= linear_buffer
= new wxUint16
[len
*2];
98 ulaw_buffer
= (const wxUint8
*)buffer
;
100 while (countdown
!= 0) {
101 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
105 m_router
->Write(old_linear
, len
* 2);
112 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase
& format
)
114 if (format
.GetType() != wxSOUND_ULAW
) {
115 m_snderror
= wxSOUND_INVFRMT
;
119 wxSoundFormatPcm pcm
;
120 wxSoundFormatUlaw
*ulaw
;
122 wxSoundStreamCodec::SetSoundFormat(format
);
124 ulaw
= (wxSoundFormatUlaw
*)m_sndformat
;
126 pcm
.SetSampleRate(ulaw
->GetSampleRate());
130 pcm
.SetOrder(wxBYTE_ORDER
);
132 m_router
->SetSoundFormat(pcm
);