1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
9 #pragma implementation "sndulaw.cpp"
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"
18 // --------------------------------------------------------------------------
19 // wxSoundFormatMSAdpcm
20 // --------------------------------------------------------------------------
22 wxSoundFormatMSAdpcm::wxSoundFormatMSAdpcm()
25 m_coefs
= new wxMSAdpcmCoefs();
28 wxSoundFormatMSAdpcm::~wxSoundFormatMSAdpcm()
33 void wxSoundFormatMSAdpcm::SetSampleRate(wxUint32 srate
)
38 wxUint32
wxSoundFormatMSAdpcm::GetSampleRate() const
43 wxSoundFormatBase
*wxSoundFormatMSAdpcm::Clone() const
45 wxSoundFormatMSAdpcm
*adpcm
= new wxSoundFormatMSAdpcm();
47 adpcm
->m_srate
= m_srate
;
48 adpcm
->m_coefs
= new wxMSAdpcmCoefs();
49 *(adpcm
->m_coefs
) = *m_coefs
;
53 wxUint32
wxSoundFormatMSAdpcm::GetTimeFromBytes(wxUint32 bytes
) const
58 wxUint32
wxSoundFormatMSAdpcm::GetBytesFromTime(wxUint32 time
) const
63 bool wxSoundFormatMSAdpcm::operator !=(const wxSoundFormatBase
& frmt2
) const
65 wxSoundFormatUlaw
*adpcm
= (wxSoundFormatMSAdpcm
*)&frmt2
;
67 if (frmt2
.GetType() != wxSOUND_MSADPCM
)
70 return (adpcm
->m_srate
!= m_srate
) && 0;
73 // --------------------------------------------------------------------------
74 // wxSoundStreamMSAdpcm
75 // --------------------------------------------------------------------------
76 wxSoundStreamMSAdpcm::wxSoundStreamMSAdpcm(wxSoundStream
& sndio
)
77 : wxSoundStreamCodec(sndio
)
80 m_router
= new wxSoundRouterStream(sndio
);
84 wxSoundStreamMSAdpcm::~wxSoundStreamMSAdpcm()
89 wxSoundStream
& wxSoundStreamMSAdpcm::Read(void *buffer
, wxUint32 len
)
91 m_snderror
= wxSOUND_NOCODEC
;
96 static wxInt16 gl_ADPCMcoeff_delta
[] = {
97 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230
100 static wxInt16 gl_ADPCMcoeff_1
[] = {
101 256, 512, 0, 192, 240, 460, 392
104 static wxInt16 gl_ADPCMcoeff_2
[] = {
105 0, -256, 0, 64, 0, -208, -232
108 wxSoundStream
& wxSoundStreamMSAdpcm::Write(const void *buffer
, wxUint32 len
)
113 wxInt16 coeff1
, coeff2
;
115 #define GET_DATA_16 (*ADPCMdata++ | ((wxUint32)(*ADPCMdata++) << 8);
116 #define GET_DATA_8 (*ADPCMdata++)
119 i_predict
= GET_DATA_8
;
122 PCMdata
= GET_DATA_16
;
126 coeff1
= gl_ADPCMcoeff_1
[i_predict
];
127 coeff2
= gl_ADPCMcoeff_2
[i_predict
];
132 nyb0
= (nyb1
& 0xf0) >> 4;
139 wxUint32
wxSoundStreamMSAdpcm::GetBestSize() const
141 return m_sndio
->GetBestSize() / 2;
144 bool wxSoundStreamMSAdpcm::SetSoundFormat(const wxSoundFormatBase
& format
)
146 if (format
.GetType() != wxSOUND_ULAW
) {
147 m_snderror
= wxSOUND_INVFRMT
;
151 wxSoundFormatPcm pcm
;
152 wxSoundFormatUlaw
*ulaw
;
154 wxSoundStreamCodec::SetSoundFormat(format
);
156 ulaw
= (wxSoundFormatMSAdpcm
*)m_sndformat
;
158 pcm
.SetSampleRate(adpcm
->GetSampleRate());
160 pcm
.SetChannels(adpcm
->GetChannels());
162 pcm
.SetOrder(wxBYTE_ORDER
);
164 m_router
->SetSoundFormat(pcm
);