]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/sndulaw.cpp
1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
8 // --------------------------------------------------------------------------
10 #pragma implementation "sndulaw.cpp"
13 #include "wx/wxprec.h"
23 #include "wx/mmedia/sndbase.h"
24 #include "wx/mmedia/sndfile.h"
25 #include "wx/mmedia/sndpcm.h"
26 #include "wx/mmedia/sndulaw.h"
27 #include "wx/mmedia/internal/g72x.h"
29 // --------------------------------------------------------------------------
31 // --------------------------------------------------------------------------
33 wxSoundFormatUlaw::wxSoundFormatUlaw()
34 : m_srate(22050), m_channels(1)
38 wxSoundFormatUlaw::~wxSoundFormatUlaw()
42 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate
)
47 wxUint32
wxSoundFormatUlaw::GetSampleRate() const
52 wxUint8
wxSoundFormatUlaw::GetChannels() const
57 void wxSoundFormatUlaw::SetChannels(wxUint8 nchannels
)
59 m_channels
= nchannels
;
62 wxSoundFormatBase
*wxSoundFormatUlaw::Clone() const
64 wxSoundFormatUlaw
*ulaw
= new wxSoundFormatUlaw();
66 ulaw
->m_srate
= m_srate
;
67 ulaw
->m_channels
= m_channels
;
71 wxUint32
wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes
) const
73 return (bytes
/ m_srate
);
76 wxUint32
wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time
) const
78 return time
* m_srate
;
81 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase
& frmt2
) const
83 wxSoundFormatUlaw
*ulaw
= (wxSoundFormatUlaw
*)&frmt2
;
85 if (frmt2
.GetType() != wxSOUND_ULAW
)
88 return (ulaw
->m_srate
!= m_srate
);
91 // --------------------------------------------------------------------------
93 // --------------------------------------------------------------------------
94 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream
& sndio
)
95 : wxSoundStreamCodec(sndio
)
98 m_router
= new wxSoundRouterStream(sndio
);
101 wxSoundStreamUlaw::~wxSoundStreamUlaw()
106 wxSoundStream
& wxSoundStreamUlaw::Read(void *buffer
, wxUint32 len
)
108 wxUint16
*old_linear
;
109 register wxUint16
*linear_buffer
;
110 register const wxUint8
*ulaw_buffer
;
111 register wxUint32 countdown
;
113 old_linear
= linear_buffer
= new wxUint16
[len
*2];
114 ulaw_buffer
= (const wxUint8
*)buffer
;
116 m_router
->Read(linear_buffer
, len
* 2);
118 m_lastcount
= countdown
= m_router
->GetLastAccess() / 2;
119 m_snderror
= m_router
->GetError();
120 if (m_snderror
!= wxSOUND_NOERROR
)
123 while (countdown
> 0) {
124 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
133 wxSoundStream
& wxSoundStreamUlaw::Write(const void *buffer
, wxUint32 len
)
135 wxUint16
*old_linear
;
136 register wxUint16
*linear_buffer
;
137 register const wxUint8
*ulaw_buffer
;
138 register wxUint32 countdown
= len
;
140 old_linear
= linear_buffer
= new wxUint16
[len
*2];
141 ulaw_buffer
= (const wxUint8
*)buffer
;
143 while (countdown
> 0) {
144 *linear_buffer
++ = ulaw2linear(*ulaw_buffer
++);
148 m_router
->Write(old_linear
, len
* 2);
155 wxUint32
wxSoundStreamUlaw::GetBestSize() const
157 return m_sndio
->GetBestSize() / 2;
160 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase
& format
)
162 if (format
.GetType() != wxSOUND_ULAW
) {
163 m_snderror
= wxSOUND_INVFRMT
;
167 // As the codec only support 16 bits, Mono we must use a wxSoundRouter
168 // to filter the data and to translate them to a format supported
169 // by the sound card.
171 wxSoundFormatPcm pcm
;
172 wxSoundFormatUlaw
*ulaw
;
174 wxSoundStreamCodec::SetSoundFormat(format
);
176 ulaw
= (wxSoundFormatUlaw
*)m_sndformat
;
178 pcm
.SetSampleRate(ulaw
->GetSampleRate());
180 pcm
.SetChannels(ulaw
->GetChannels());
182 pcm
.SetOrder(wxBYTE_ORDER
);
184 m_router
->SetSoundFormat(pcm
);