]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/sndulaw.cpp
1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
8 // --------------------------------------------------------------------------
10 #include "wx/wxprec.h"
20 #include "wx/mmedia/sndbase.h"
21 #include "wx/mmedia/sndfile.h"
22 #include "wx/mmedia/sndpcm.h"
23 #include "wx/mmedia/sndulaw.h"
24 #include "wx/mmedia/internal/g72x.h"
26 // --------------------------------------------------------------------------
28 // --------------------------------------------------------------------------
30 wxSoundFormatUlaw::wxSoundFormatUlaw()
31 : m_srate(22050), m_channels(1)
35 wxSoundFormatUlaw::~wxSoundFormatUlaw()
39 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate
)
44 wxUint32
wxSoundFormatUlaw::GetSampleRate() const
49 wxUint8
wxSoundFormatUlaw::GetChannels() const
54 void wxSoundFormatUlaw::SetChannels(wxUint8 nchannels
)
56 m_channels
= nchannels
;
59 wxSoundFormatBase
*wxSoundFormatUlaw::Clone() const
61 wxSoundFormatUlaw
*ulaw
= new wxSoundFormatUlaw();
63 ulaw
->m_srate
= m_srate
;
64 ulaw
->m_channels
= m_channels
;
68 wxUint32
wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes
) const
70 return (bytes
/ m_srate
);
73 wxUint32
wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time
) const
75 return time
* m_srate
;
78 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase
& frmt2
) const
80 wxSoundFormatUlaw
*ulaw
= (wxSoundFormatUlaw
*)&frmt2
;
82 if (frmt2
.GetType() != wxSOUND_ULAW
)
85 return (ulaw
->m_srate
!= m_srate
);
88 // --------------------------------------------------------------------------
90 // --------------------------------------------------------------------------
91 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream
& sndio
)
92 : wxSoundStreamCodec(sndio
)
95 m_router
= new wxSoundRouterStream(sndio
);
98 wxSoundStreamUlaw::~wxSoundStreamUlaw()
103 wxSoundStream
& wxSoundStreamUlaw::Read(void *buffer
, wxUint32 len
)
105 wxUint16
*old_linear
;
106 register wxUint16
*linear_buffer
;
107 register const wxUint8
*ulaw_buffer
;
108 register wxUint32 countdown
;
110 old_linear
= linear_buffer
= new wxUint16
[len
*2];
111 ulaw_buffer
= (const wxUint8
*)buffer
;
113 m_router
->Read(linear_buffer
, len
* 2);
115 m_lastcount
= countdown
= m_router
->GetLastAccess() / 2;
116 m_snderror
= m_router
->GetError();
117 if (m_snderror
!= wxSOUND_NOERROR
)
120 while (countdown
> 0) {
121 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
130 wxSoundStream
& wxSoundStreamUlaw::Write(const void *buffer
, wxUint32 len
)
132 wxUint16
*old_linear
;
133 register wxUint16
*linear_buffer
;
134 register const wxUint8
*ulaw_buffer
;
135 register wxUint32 countdown
= len
;
137 old_linear
= linear_buffer
= new wxUint16
[len
*2];
138 ulaw_buffer
= (const wxUint8
*)buffer
;
140 while (countdown
> 0) {
141 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
145 m_router
->Write(old_linear
, len
* 2);
152 wxUint32
wxSoundStreamUlaw::GetBestSize() const
154 return m_sndio
->GetBestSize() / 2;
157 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase
& format
)
159 if (format
.GetType() != wxSOUND_ULAW
) {
160 m_snderror
= wxSOUND_INVFRMT
;
164 // As the codec only support 16 bits, Mono we must use a wxSoundRouter
165 // to filter the data and to translate them to a format supported
166 // by the sound card.
168 wxSoundFormatPcm pcm
;
169 wxSoundFormatUlaw
*ulaw
;
171 wxSoundStreamCodec::SetSoundFormat(format
);
173 ulaw
= (wxSoundFormatUlaw
*)m_sndformat
;
175 pcm
.SetSampleRate(ulaw
->GetSampleRate());
177 pcm
.SetChannels(ulaw
->GetChannels());
179 pcm
.SetOrder(wxBYTE_ORDER
);
181 m_router
->SetSoundFormat(pcm
);