]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/sndulaw.cpp
1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
9 #pragma implementation "sndulaw.cpp"
12 #include "wx/wxprec.h"
22 #include "wx/mmedia/sndbase.h"
23 #include "wx/mmedia/sndfile.h"
24 #include "wx/mmedia/sndpcm.h"
25 #include "wx/mmedia/sndulaw.h"
26 #include "wx/mmedia/internal/g72x.h"
28 // --------------------------------------------------------------------------
30 // --------------------------------------------------------------------------
32 wxSoundFormatUlaw::wxSoundFormatUlaw()
33 : m_srate(22050), m_channels(1)
37 wxSoundFormatUlaw::~wxSoundFormatUlaw()
41 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate
)
46 wxUint32
wxSoundFormatUlaw::GetSampleRate() const
51 wxUint8
wxSoundFormatUlaw::GetChannels() const
56 void wxSoundFormatUlaw::SetChannels(wxUint8 nchannels
)
58 m_channels
= nchannels
;
61 wxSoundFormatBase
*wxSoundFormatUlaw::Clone() const
63 wxSoundFormatUlaw
*ulaw
= new wxSoundFormatUlaw();
65 ulaw
->m_srate
= m_srate
;
66 ulaw
->m_channels
= m_channels
;
70 wxUint32
wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes
) const
72 return (bytes
/ m_srate
);
75 wxUint32
wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time
) const
77 return time
* m_srate
;
80 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase
& frmt2
) const
82 wxSoundFormatUlaw
*ulaw
= (wxSoundFormatUlaw
*)&frmt2
;
84 if (frmt2
.GetType() != wxSOUND_ULAW
)
87 return (ulaw
->m_srate
!= m_srate
);
90 // --------------------------------------------------------------------------
92 // --------------------------------------------------------------------------
93 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream
& sndio
)
94 : wxSoundStreamCodec(sndio
)
97 m_router
= new wxSoundRouterStream(sndio
);
100 wxSoundStreamUlaw::~wxSoundStreamUlaw()
105 wxSoundStream
& wxSoundStreamUlaw::Read(void *buffer
, wxUint32 len
)
107 wxUint16
*old_linear
;
108 register wxUint16
*linear_buffer
;
109 register const wxUint8
*ulaw_buffer
;
110 register wxUint32 countdown
;
112 old_linear
= linear_buffer
= new wxUint16
[len
*2];
113 ulaw_buffer
= (const wxUint8
*)buffer
;
115 m_router
->Read(linear_buffer
, len
* 2);
117 m_lastcount
= countdown
= m_router
->GetLastAccess() / 2;
118 m_snderror
= m_router
->GetError();
119 if (m_snderror
!= wxSOUND_NOERROR
)
122 while (countdown
> 0) {
123 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
132 wxSoundStream
& wxSoundStreamUlaw::Write(const void *buffer
, wxUint32 len
)
134 wxUint16
*old_linear
;
135 register wxUint16
*linear_buffer
;
136 register const wxUint8
*ulaw_buffer
;
137 register wxUint32 countdown
= len
;
139 old_linear
= linear_buffer
= new wxUint16
[len
*2];
140 ulaw_buffer
= (const wxUint8
*)buffer
;
142 while (countdown
> 0) {
143 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
147 m_router
->Write(old_linear
, len
* 2);
154 wxUint32
wxSoundStreamUlaw::GetBestSize() const
156 return m_sndio
->GetBestSize() / 2;
159 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase
& format
)
161 if (format
.GetType() != wxSOUND_ULAW
) {
162 m_snderror
= wxSOUND_INVFRMT
;
166 // As the codec only support 16 bits, Mono we must use a wxSoundRouter
167 // to filter the data and to translate them to a format supported
168 // by the sound card.
170 wxSoundFormatPcm pcm
;
171 wxSoundFormatUlaw
*ulaw
;
173 wxSoundStreamCodec::SetSoundFormat(format
);
175 ulaw
= (wxSoundFormatUlaw
*)m_sndformat
;
177 pcm
.SetSampleRate(ulaw
->GetSampleRate());
179 pcm
.SetChannels(ulaw
->GetChannels());
181 pcm
.SetOrder(wxBYTE_ORDER
);
183 m_router
->SetSoundFormat(pcm
);