]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/sndulaw.cpp
5fb3153f9cbe1f4d307c3bdf4b71490620eec8d8
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
, wxUint32 len
)
90 wxSoundStream
& wxSoundStreamUlaw::Write(const void *buffer
, wxUint32 len
)
93 register wxUint16
*linear_buffer
;
94 register const wxUint8
*ulaw_buffer
;
95 register wxUint32 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 wxUint32
wxSoundStreamUlaw::GetBestSize() const
114 return m_sndio
->GetBestSize() / 2;
117 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase
& format
)
119 if (format
.GetType() != wxSOUND_ULAW
) {
120 m_snderror
= wxSOUND_INVFRMT
;
124 wxSoundFormatPcm pcm
;
125 wxSoundFormatUlaw
*ulaw
;
127 wxSoundStreamCodec::SetSoundFormat(format
);
129 ulaw
= (wxSoundFormatUlaw
*)m_sndformat
;
131 pcm
.SetSampleRate(ulaw
->GetSampleRate());
135 pcm
.SetOrder(wxBYTE_ORDER
);
137 m_router
->SetSoundFormat(pcm
);