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