]>
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>
23 // --------------------------------------------------------------------------
25 // --------------------------------------------------------------------------
27 wxSoundFormatUlaw::wxSoundFormatUlaw()
32 wxSoundFormatUlaw::~wxSoundFormatUlaw()
36 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate
)
41 wxUint32
wxSoundFormatUlaw::GetSampleRate() const
46 wxSoundFormatBase
*wxSoundFormatUlaw::Clone() const
48 wxSoundFormatUlaw
*ulaw
= new wxSoundFormatUlaw();
50 ulaw
->m_srate
= m_srate
;
54 wxUint32
wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes
) const
56 return (bytes
/ m_srate
);
59 wxUint32
wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time
) const
61 return time
* m_srate
;
64 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase
& frmt2
) const
66 wxSoundFormatUlaw
*ulaw
= (wxSoundFormatUlaw
*)&frmt2
;
68 if (frmt2
.GetType() != wxSOUND_ULAW
)
71 return (ulaw
->m_srate
!= m_srate
);
74 // --------------------------------------------------------------------------
76 // --------------------------------------------------------------------------
77 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream
& sndio
)
78 : wxSoundStreamCodec(sndio
)
81 m_router
= new wxSoundRouterStream(sndio
);
84 wxSoundStreamUlaw::~wxSoundStreamUlaw()
89 wxSoundStream
& wxSoundStreamUlaw::Read(void *buffer
, wxUint32 len
)
95 wxSoundStream
& wxSoundStreamUlaw::Write(const void *buffer
, wxUint32 len
)
98 register wxUint16
*linear_buffer
;
99 register const wxUint8
*ulaw_buffer
;
100 register wxUint32 countdown
= len
;
102 old_linear
= linear_buffer
= new wxUint16
[len
*2];
103 ulaw_buffer
= (const wxUint8
*)buffer
;
105 while (countdown
!= 0) {
106 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
110 m_router
->Write(old_linear
, len
* 2);
117 wxUint32
wxSoundStreamUlaw::GetBestSize() const
119 return m_sndio
->GetBestSize() / 2;
122 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase
& format
)
124 if (format
.GetType() != wxSOUND_ULAW
) {
125 m_snderror
= wxSOUND_INVFRMT
;
129 wxSoundFormatPcm pcm
;
130 wxSoundFormatUlaw
*ulaw
;
132 wxSoundStreamCodec::SetSoundFormat(format
);
134 ulaw
= (wxSoundFormatUlaw
*)m_sndformat
;
136 pcm
.SetSampleRate(ulaw
->GetSampleRate());
140 pcm
.SetOrder(wxBYTE_ORDER
);
142 m_router
->SetSoundFormat(pcm
);