]>
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()
28 : m_srate(22050), m_channels(1)
32 wxSoundFormatUlaw::~wxSoundFormatUlaw()
36 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate
)
41 wxUint32
wxSoundFormatUlaw::GetSampleRate() const
46 wxUint8
wxSoundFormatUlaw::GetChannels() const
51 void wxSoundFormatUlaw::SetChannels(wxUint8 nchannels
)
53 m_channels
= nchannels
;
56 wxSoundFormatBase
*wxSoundFormatUlaw::Clone() const
58 wxSoundFormatUlaw
*ulaw
= new wxSoundFormatUlaw();
60 ulaw
->m_srate
= m_srate
;
61 ulaw
->m_channels
= m_channels
;
65 wxUint32
wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes
) const
67 return (bytes
/ m_srate
);
70 wxUint32
wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time
) const
72 return time
* m_srate
;
75 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase
& frmt2
) const
77 wxSoundFormatUlaw
*ulaw
= (wxSoundFormatUlaw
*)&frmt2
;
79 if (frmt2
.GetType() != wxSOUND_ULAW
)
82 return (ulaw
->m_srate
!= m_srate
);
85 // --------------------------------------------------------------------------
87 // --------------------------------------------------------------------------
88 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream
& sndio
)
89 : wxSoundStreamCodec(sndio
)
92 m_router
= new wxSoundRouterStream(sndio
);
95 wxSoundStreamUlaw::~wxSoundStreamUlaw()
100 wxSoundStream
& wxSoundStreamUlaw::Read(void *buffer
, wxUint32 len
)
102 wxUint16
*old_linear
;
103 register wxUint16
*linear_buffer
;
104 register const wxUint8
*ulaw_buffer
;
105 register wxUint32 countdown
;
107 old_linear
= linear_buffer
= new wxUint16
[len
*2];
108 ulaw_buffer
= (const wxUint8
*)buffer
;
110 m_router
->Read(linear_buffer
, len
* 2);
112 m_lastcount
= countdown
= m_router
->GetLastAccess() / 2;
113 m_snderror
= m_router
->GetError();
114 if (m_snderror
!= wxSOUND_NOERROR
)
117 while (countdown
> 0) {
118 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
127 wxSoundStream
& wxSoundStreamUlaw::Write(const void *buffer
, wxUint32 len
)
129 wxUint16
*old_linear
;
130 register wxUint16
*linear_buffer
;
131 register const wxUint8
*ulaw_buffer
;
132 register wxUint32 countdown
= len
;
134 old_linear
= linear_buffer
= new wxUint16
[len
*2];
135 ulaw_buffer
= (const wxUint8
*)buffer
;
137 while (countdown
> 0) {
138 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
142 m_router
->Write(old_linear
, len
* 2);
149 wxUint32
wxSoundStreamUlaw::GetBestSize() const
151 return m_sndio
->GetBestSize() / 2;
154 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase
& format
)
156 if (format
.GetType() != wxSOUND_ULAW
) {
157 m_snderror
= wxSOUND_INVFRMT
;
161 // As the codec only support 16 bits, Mono we must use a wxSoundRouter to filter the data and
162 // to translate them to a format supported by the sound card.
164 wxSoundFormatPcm pcm
;
165 wxSoundFormatUlaw
*ulaw
;
167 wxSoundStreamCodec::SetSoundFormat(format
);
169 ulaw
= (wxSoundFormatUlaw
*)m_sndformat
;
171 pcm
.SetSampleRate(ulaw
->GetSampleRate());
173 pcm
.SetChannels(ulaw
->GetChannels());
175 pcm
.SetOrder(wxBYTE_ORDER
);
177 m_router
->SetSoundFormat(pcm
);