]>
Commit | Line | Data |
---|---|---|
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 | wxUint32 wxSoundStreamUlaw::GetBestSize() const | |
113 | { | |
114 | return m_sndio->GetBestSize() / 2; | |
115 | } | |
116 | ||
117 | bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase& format) | |
118 | { | |
119 | if (format.GetType() != wxSOUND_ULAW) { | |
120 | m_snderror = wxSOUND_INVFRMT; | |
121 | return FALSE; | |
122 | } | |
123 | ||
124 | wxSoundFormatPcm pcm; | |
125 | wxSoundFormatUlaw *ulaw; | |
126 | ||
127 | wxSoundStreamCodec::SetSoundFormat(format); | |
128 | ||
129 | ulaw = (wxSoundFormatUlaw *)m_sndformat; | |
130 | ||
131 | pcm.SetSampleRate(ulaw->GetSampleRate()); | |
132 | pcm.SetBPS(16); | |
133 | pcm.SetChannels(1); | |
134 | pcm.Signed(TRUE); | |
135 | pcm.SetOrder(wxBYTE_ORDER); | |
136 | ||
137 | m_router->SetSoundFormat(pcm); | |
138 | ||
139 | return TRUE; | |
140 | } |