]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/mmedia/sndmsad.cpp
wxHtmlHelpController made compatible with other controllers
[wxWidgets.git] / contrib / src / mmedia / sndmsad.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 "wx/mmedia/sndbase.h"
14 #include "wx/mmedia/sndfile.h"
15 #include "wx/mmedia/sndpcm.h"
16 #include "wx/mmedia/sndmsad.h"
17
18 // --------------------------------------------------------------------------
19 // wxSoundFormatMSAdpcm
20 // --------------------------------------------------------------------------
21
22 wxSoundFormatMSAdpcm::wxSoundFormatMSAdpcm()
23 : m_srate(22050)
24 {
25 m_coefs = new wxMSAdpcmCoefs();
26 }
27
28 wxSoundFormatMSAdpcm::~wxSoundFormatMSAdpcm()
29 {
30 delete m_coefs;
31 }
32
33 void wxSoundFormatMSAdpcm::SetSampleRate(wxUint32 srate)
34 {
35 m_srate = srate;
36 }
37
38 wxUint32 wxSoundFormatMSAdpcm::GetSampleRate() const
39 {
40 return m_srate;
41 }
42
43 wxSoundFormatBase *wxSoundFormatMSAdpcm::Clone() const
44 {
45 wxSoundFormatMSAdpcm *adpcm = new wxSoundFormatMSAdpcm();
46
47 adpcm->m_srate = m_srate;
48 adpcm->m_coefs = new wxMSAdpcmCoefs();
49 *(adpcm->m_coefs) = *m_coefs;
50 return adpcm;
51 }
52
53 wxUint32 wxSoundFormatMSAdpcm::GetTimeFromBytes(wxUint32 bytes) const
54 {
55 return 0;
56 }
57
58 wxUint32 wxSoundFormatMSAdpcm::GetBytesFromTime(wxUint32 time) const
59 {
60 return 0;
61 }
62
63 bool wxSoundFormatMSAdpcm::operator !=(const wxSoundFormatBase& frmt2) const
64 {
65 wxSoundFormatUlaw *adpcm = (wxSoundFormatMSAdpcm *)&frmt2;
66
67 if (frmt2.GetType() != wxSOUND_MSADPCM)
68 return TRUE;
69
70 return (adpcm->m_srate != m_srate) && 0;
71 }
72
73 // --------------------------------------------------------------------------
74 // wxSoundStreamMSAdpcm
75 // --------------------------------------------------------------------------
76 wxSoundStreamMSAdpcm::wxSoundStreamMSAdpcm(wxSoundStream& sndio)
77 : wxSoundStreamCodec(sndio)
78 {
79 // PCM converter
80 m_router = new wxSoundRouterStream(sndio);
81 m_got_header = FALSE;
82 }
83
84 wxSoundStreamMSAdpcm::~wxSoundStreamMSAdpcm()
85 {
86 delete m_router;
87 }
88
89 wxSoundStream& wxSoundStreamMSAdpcm::Read(void *buffer, wxUint32 len)
90 {
91 m_snderror = wxSOUND_NOCODEC;
92 m_lastcount = 0;
93 return *this;
94 }
95
96 static wxInt16 gl_ADPCMcoeff_delta[] = {
97 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230
98 };
99
100 static wxInt16 gl_ADPCMcoeff_1[] = {
101 256, 512, 0, 192, 240, 460, 392
102 };
103
104 static wxInt16 gl_ADPCMcoeff_2[] = {
105 0, -256, 0, 64, 0, -208, -232
106 };
107
108 wxSoundStream& wxSoundStreamMSAdpcm::Write(const void *buffer, wxUint32 len)
109 {
110 wxInt16 delta;
111 wxUint8 ADPCMdata;
112 wxUint16 *PCMdata;
113 wxInt16 coeff1, coeff2;
114
115 #define GET_DATA_16 (*ADPCMdata++ | ((wxUint32)(*ADPCMdata++) << 8);
116 #define GET_DATA_8 (*ADPCMdata++)
117
118 if (!m_got_header) {
119 i_predict = GET_DATA_8;
120 delta = GET_DATA_16;
121 samp1 = GET_DATA_16;
122 PCMdata = GET_DATA_16;
123 len -= 3*2 + 1;
124 m_got_header = TRUE;
125
126 coeff1 = gl_ADPCMcoeff_1[i_predict];
127 coeff2 = gl_ADPCMcoeff_2[i_predict];
128 }
129
130 while (len > 0) {
131 nyb1 = GET_DATA_8;
132 nyb0 = (nyb1 & 0xf0) >> 4;
133 nyb1 &= 0x0f;
134
135
136 return *this;
137 }
138
139 wxUint32 wxSoundStreamMSAdpcm::GetBestSize() const
140 {
141 return m_sndio->GetBestSize() / 2;
142 }
143
144 bool wxSoundStreamMSAdpcm::SetSoundFormat(const wxSoundFormatBase& format)
145 {
146 if (format.GetType() != wxSOUND_ULAW) {
147 m_snderror = wxSOUND_INVFRMT;
148 return FALSE;
149 }
150
151 wxSoundFormatPcm pcm;
152 wxSoundFormatUlaw *ulaw;
153
154 wxSoundStreamCodec::SetSoundFormat(format);
155
156 ulaw = (wxSoundFormatMSAdpcm *)m_sndformat;
157
158 pcm.SetSampleRate(adpcm->GetSampleRate());
159 pcm.SetBPS(16);
160 pcm.SetChannels(adpcm->GetChannels());
161 pcm.Signed(TRUE);
162 pcm.SetOrder(wxBYTE_ORDER);
163
164 m_router->SetSoundFormat(pcm);
165
166 return TRUE;
167 }
168