]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/sndulaw.cpp
d858bfacc4b68010cdb72002e9264c4c8a9261de
1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
9 #pragma implementation "sndulaw.cpp"
18 // --------------------------------------------------------------------------
20 // --------------------------------------------------------------------------
22 wxSoundFormatUlaw::wxSoundFormatUlaw()
27 wxSoundFormatUlaw::~wxSoundFormatUlaw()
31 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate
)
36 wxUint32
wxSoundFormatUlaw::GetSampleRate() const
41 wxSoundFormatBase
*wxSoundFormatUlaw::Clone() const
43 wxSoundFormatUlaw
*ulaw
= new wxSoundFormatUlaw();
45 ulaw
->m_srate
= m_srate
;
49 wxUint32
wxSoundFormatUlaw::GetTimeFromByte(wxUint32 bytes
) const
51 return (bytes
/ m_srate
);
54 wxUint32
wxSoundFormatUlaw::GetByteFromTime(wxUint32 time
) const
56 return time
* m_srate
;
59 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase
& frmt2
) const
61 wxSoundFormatUlaw
*ulaw
= (wxSoundFormatUlaw
*)&frmt2
;
63 if (frmt2
.GetType() != wxSOUND_ULAW
)
66 return (ulaw
->m_srate
!= m_srate
);
69 // --------------------------------------------------------------------------
71 // --------------------------------------------------------------------------
72 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream
& sndio
)
73 : wxSoundStreamCodec(sndio
)
76 m_router
= new wxSoundRouterStream(sndio
);
79 wxSoundStreamUlaw::~wxSoundStreamUlaw()
84 wxSoundStream
& wxSoundStreamUlaw::Read(void *buffer
, size_t len
)
89 wxSoundStream
& wxSoundStreamUlaw::Write(const void *buffer
, size_t len
)
92 register wxUint16
*linear_buffer
;
93 register const wxUint8
*ulaw_buffer
;
94 register size_t countdown
= len
;
96 old_linear
= linear_buffer
= new wxUint16
[len
*2];
97 ulaw_buffer
= (const wxUint8
*)buffer
;
99 while (countdown
!= 0) {
100 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
104 m_router
->Write(old_linear
, len
* 2);
111 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase
& format
)
113 if (format
.GetType() != wxSOUND_ULAW
) {
114 m_snderror
= wxSOUND_INVFRMT
;
118 wxSoundFormatPcm pcm
;
119 wxSoundFormatUlaw
*ulaw
;
121 wxSoundStreamCodec::SetSoundFormat(format
);
123 ulaw
= (wxSoundFormatUlaw
*)m_sndformat
;
125 pcm
.SetSampleRate(ulaw
->GetSampleRate());
129 pcm
.SetOrder(wxBYTE_ORDER
);
131 m_router
->SetSoundFormat(pcm
);