]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/sndulaw.cpp
Removed unnecessary code from utilsunx.cpp
[wxWidgets.git] / utils / wxMMedia2 / lib / sndulaw.cpp
1 // --------------------------------------------------------------------------
2 // Name: sndulaw.cpp
3 // Purpose:
4 // Date: 08/11/1999
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
6 // CVSID: $Id$
7 // --------------------------------------------------------------------------
8 #ifdef __GNUG__
9 #pragma implementation "sndulaw.cpp"
10 #endif
11
12 #include <wx/wxprec.h>
13
14 #ifndef WX_PRECOMP
15 #endif
16
17 #include "sndbase.h"
18 #include "sndfile.h"
19 #include "sndpcm.h"
20 #include "sndulaw.h"
21 #include "g72x.h"
22
23 // --------------------------------------------------------------------------
24 // wxSoundFormatUlaw
25 // --------------------------------------------------------------------------
26
27 wxSoundFormatUlaw::wxSoundFormatUlaw()
28 : m_srate(22050)
29 {
30 }
31
32 wxSoundFormatUlaw::~wxSoundFormatUlaw()
33 {
34 }
35
36 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate)
37 {
38 m_srate = srate;
39 }
40
41 wxUint32 wxSoundFormatUlaw::GetSampleRate() const
42 {
43 return m_srate;
44 }
45
46 wxSoundFormatBase *wxSoundFormatUlaw::Clone() const
47 {
48 wxSoundFormatUlaw *ulaw = new wxSoundFormatUlaw();
49
50 ulaw->m_srate = m_srate;
51 return ulaw;
52 }
53
54 wxUint32 wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes) const
55 {
56 return (bytes / m_srate);
57 }
58
59 wxUint32 wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time) const
60 {
61 return time * m_srate;
62 }
63
64 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase& frmt2) const
65 {
66 wxSoundFormatUlaw *ulaw = (wxSoundFormatUlaw *)&frmt2;
67
68 if (frmt2.GetType() != wxSOUND_ULAW)
69 return TRUE;
70
71 return (ulaw->m_srate != m_srate);
72 }
73
74 // --------------------------------------------------------------------------
75 // wxSoundStreamUlaw
76 // --------------------------------------------------------------------------
77 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream& sndio)
78 : wxSoundStreamCodec(sndio)
79 {
80 // PCM converter
81 m_router = new wxSoundRouterStream(sndio);
82 }
83
84 wxSoundStreamUlaw::~wxSoundStreamUlaw()
85 {
86 delete m_router;
87 }
88
89 wxSoundStream& wxSoundStreamUlaw::Read(void *buffer, wxUint32 len)
90 {
91 // TODO
92 return *this;
93 }
94
95 wxSoundStream& wxSoundStreamUlaw::Write(const void *buffer, wxUint32 len)
96 {
97 wxUint16 *old_linear;
98 register wxUint16 *linear_buffer;
99 register const wxUint8 *ulaw_buffer;
100 register wxUint32 countdown = len;
101
102 old_linear = linear_buffer = new wxUint16[len*2];
103 ulaw_buffer = (const wxUint8 *)buffer;
104
105 while (countdown != 0) {
106 *linear_buffer++ = ulaw2linear(*ulaw_buffer++);
107 countdown--;
108 }
109
110 m_router->Write(old_linear, len * 2);
111
112 delete[] old_linear;
113
114 return *m_router;
115 }
116
117 wxUint32 wxSoundStreamUlaw::GetBestSize() const
118 {
119 return m_sndio->GetBestSize() / 2;
120 }
121
122 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase& format)
123 {
124 if (format.GetType() != wxSOUND_ULAW) {
125 m_snderror = wxSOUND_INVFRMT;
126 return FALSE;
127 }
128
129 wxSoundFormatPcm pcm;
130 wxSoundFormatUlaw *ulaw;
131
132 wxSoundStreamCodec::SetSoundFormat(format);
133
134 ulaw = (wxSoundFormatUlaw *)m_sndformat;
135
136 pcm.SetSampleRate(ulaw->GetSampleRate());
137 pcm.SetBPS(16);
138 pcm.SetChannels(1);
139 pcm.Signed(TRUE);
140 pcm.SetOrder(wxBYTE_ORDER);
141
142 m_router->SetSoundFormat(pcm);
143
144 return TRUE;
145 }