]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia2/lib/sndulaw.cpp
Start xanim only when we are ready to play
[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 #include "sndbase.h"
14 #include "sndfile.h"
15 #include "sndpcm.h"
16 #include "sndulaw.h"
17 #include "g72x.h"
18
19 // --------------------------------------------------------------------------
20 // wxSoundFormatUlaw
21 // --------------------------------------------------------------------------
22
23 wxSoundFormatUlaw::wxSoundFormatUlaw()
24 : m_srate(22050)
25 {
26 }
27
28 wxSoundFormatUlaw::~wxSoundFormatUlaw()
29 {
30 }
31
32 void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate)
33 {
34 m_srate = srate;
35 }
36
37 wxUint32 wxSoundFormatUlaw::GetSampleRate() const
38 {
39 return m_srate;
40 }
41
42 wxSoundFormatBase *wxSoundFormatUlaw::Clone() const
43 {
44 wxSoundFormatUlaw *ulaw = new wxSoundFormatUlaw();
45
46 ulaw->m_srate = m_srate;
47 return ulaw;
48 }
49
50 wxUint32 wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes) const
51 {
52 return (bytes / m_srate);
53 }
54
55 wxUint32 wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time) const
56 {
57 return time * m_srate;
58 }
59
60 bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase& frmt2) const
61 {
62 wxSoundFormatUlaw *ulaw = (wxSoundFormatUlaw *)&frmt2;
63
64 if (frmt2.GetType() != wxSOUND_ULAW)
65 return TRUE;
66
67 return (ulaw->m_srate != m_srate);
68 }
69
70 // --------------------------------------------------------------------------
71 // wxSoundStreamUlaw
72 // --------------------------------------------------------------------------
73 wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream& sndio)
74 : wxSoundStreamCodec(sndio)
75 {
76 // PCM converter
77 m_router = new wxSoundRouterStream(sndio);
78 }
79
80 wxSoundStreamUlaw::~wxSoundStreamUlaw()
81 {
82 delete m_router;
83 }
84
85 wxSoundStream& wxSoundStreamUlaw::Read(void *buffer, wxUint32 len)
86 {
87 return *this;
88 }
89
90 wxSoundStream& wxSoundStreamUlaw::Write(const void *buffer, wxUint32 len)
91 {
92 wxUint16 *old_linear;
93 register wxUint16 *linear_buffer;
94 register const wxUint8 *ulaw_buffer;
95 register wxUint32 countdown = len;
96
97 old_linear = linear_buffer = new wxUint16[len*2];
98 ulaw_buffer = (const wxUint8 *)buffer;
99
100 while (countdown != 0) {
101 *linear_buffer++ = ulaw2linear(*ulaw_buffer++);
102 countdown--;
103 }
104
105 m_router->Write(old_linear, len * 2);
106
107 delete[] old_linear;
108
109 return *m_router;
110 }
111
112 bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase& format)
113 {
114 if (format.GetType() != wxSOUND_ULAW) {
115 m_snderror = wxSOUND_INVFRMT;
116 return FALSE;
117 }
118
119 wxSoundFormatPcm pcm;
120 wxSoundFormatUlaw *ulaw;
121
122 wxSoundStreamCodec::SetSoundFormat(format);
123
124 ulaw = (wxSoundFormatUlaw *)m_sndformat;
125
126 pcm.SetSampleRate(ulaw->GetSampleRate());
127 pcm.SetBPS(16);
128 pcm.SetChannels(1);
129 pcm.Signed(TRUE);
130 pcm.SetOrder(wxBYTE_ORDER);
131
132 m_router->SetSoundFormat(pcm);
133
134 return TRUE;
135 }