]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/mmedia/sndmsad.h
2f3804dc16ac576619eefd6a65a2ea7dd325adb0
[wxWidgets.git] / contrib / include / wx / mmedia / sndmsad.h
1 // --------------------------------------------------------------------------
2 // Name: sndmsad(pcm).h
3 // Purpose: MS ADPCM codec
4 // Date: 25/02/2000
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 2000
6 // CVSID: $Id$
7 // License: wxWindows license
8 // --------------------------------------------------------------------------
9 #ifndef _WX_SNDMSAD_H
10 #define _WX_SNDMSAD_H
11
12 #ifdef __GNUG__
13 #pragma interface "sndmsad.h"
14 #endif
15
16 #include "wx/defs.h"
17 #include "wx/dynarray.h"
18 #include "wx/mmedia/defs.h"
19 #include "wx/mmedia/sndcodec.h"
20 #include "wx/mmedia/sndbase.h"
21
22 WX_DEFINE_EXPORTED_ARRAY_INT(wxInt16, wxMSAdpcmCoeffs);
23
24 //
25 // MSADPCM format
26 //
27 class WXDLLIMPEXP_MMEDIA wxSoundFormatMSAdpcm: public wxSoundFormatBase {
28 public:
29 wxSoundFormatMSAdpcm();
30 ~wxSoundFormatMSAdpcm();
31
32 void SetSampleRate(wxUint32 srate);
33 wxUint32 GetSampleRate() const;
34
35 void SetCoefs(wxInt16 **coefs, wxUint16 ncoefs, wxUint16 coefs_len);
36 void GetCoefs(wxInt16 **&coefs, wxUint16& ncoefs,
37 wxUint16& coefs_len) const;
38
39 void SetBlockSize(wxUint16 block_size);
40 wxUint16 GetBlockSize() const;
41
42 void SetChannels(wxUint16 channels);
43 wxUint16 GetChannels() const;
44
45 wxSoundFormatType GetType() const { return wxSOUND_MSADPCM; }
46 wxSoundFormatBase *Clone() const;
47
48 wxUint32 GetTimeFromBytes(wxUint32 bytes) const;
49 wxUint32 GetBytesFromTime(wxUint32 time) const;
50
51 bool operator !=(const wxSoundFormatBase& frmt2) const;
52
53 protected:
54 wxUint32 m_srate, m_nchannels;
55 wxInt16 **m_coefs;
56 wxUint16 m_ncoefs, m_coefs_len;
57 wxUint16 m_block_size;
58 };
59
60 //
61 // MS ADPCM converter class
62 //
63 class WXDLLIMPEXP_MMEDIA wxSoundRouterStream;
64 class WXDLLIMPEXP_MMEDIA wxSoundStreamMSAdpcm: public wxSoundStreamCodec {
65 public:
66 wxSoundStreamMSAdpcm(wxSoundStream& sndio);
67 ~wxSoundStreamMSAdpcm();
68
69 wxSoundStream& Read(void *buffer, wxUint32 len);
70 wxSoundStream& Write(const void *buffer, wxUint32 len);
71
72 bool SetSoundFormat(const wxSoundFormatBase& format);
73
74 wxUint32 GetBestSize() const;
75
76 protected:
77 wxSoundRouterStream *m_router;
78
79 typedef struct {
80 wxInt32 predictor;
81 wxInt16 samp1;
82 wxInt16 samp2;
83 wxInt16 coeff[2];
84 wxInt32 iDelta;
85 } AdpcmState;
86
87 AdpcmState m_state[1];
88
89 bool m_got_header;
90 bool m_stereo;
91 wxInt16 **m_coefs;
92 wxUint16 m_block_size;
93 wxUint16 m_ncoefs;
94 wxUint16 m_next_block;
95
96 protected:
97 wxUint32 DecodeMonoADPCM(const void *in_buffer, void *out_buffer,
98 wxUint32 in_len);
99 wxUint32 DecodeStereoADPCM(const void *in_buffer, void *out_buffer,
100 wxUint32 in_len);
101 void Nibble(wxInt8 nyb,
102 AdpcmState *state,
103 wxInt16 **out_buffer);
104 };
105
106 #endif