]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndfrmt.h
1e4249bf9e889ab5ae769b1cfa9872c54456d84c
[wxWidgets.git] / utils / wxMMedia / sndfrmt.h
1 #ifndef __SNDFRMT_H__
2 #define __SNDFRMT_H__
3
4 #ifdef __GNUG__
5 #pragma interface
6 #endif
7
8 #include <wx/object.h>
9 #include <wx/stream.h>
10
11 class wxSndBuffer;
12
13 // Standard Microsoft types (why change ?)
14 #define WXSOUND_PCM 0x0001
15 #define WXSOUND_ADPCM 0x0002
16 #define WXSOUND_ALAW 0x0006
17 #define WXSOUND_ULAW 0x0007
18
19 class wxSoundCodec;
20 class wxSoundDataFormat {
21 public:
22 wxSoundDataFormat();
23 wxSoundDataFormat(const wxSoundDataFormat& format);
24 ~wxSoundDataFormat();
25
26 void SetSampleRate(int srate) { m_srate = srate; }
27 void SetChannels(int channels);
28 void SetStereo(bool on);
29 void SetCodecNo(int no);
30 void SetCodecCreate(bool create) { m_codcreate = create; }
31
32 int GetSampleRate() const { return m_srate; }
33 int GetChannels() const { return m_channels; }
34 bool GetStereo() const { return (m_channels == 2); }
35 int GetCodecNo() const { return m_codno; }
36
37 wxSoundCodec *GetCodec();
38
39 wxSoundDataFormat& operator =(const wxSoundDataFormat& format);
40 bool operator ==(const wxSoundDataFormat& format) const;
41 bool operator !=(const wxSoundDataFormat& format) const
42 { return !(operator ==(format)); }
43
44 /// PCM format
45 void SetByteOrder(int order);
46 void SetSign(int sign);
47 int GetByteOrder() const { return m_byteorder; }
48 int GetSign() const { return m_sign; }
49
50 void SetBps(int bps);
51 int GetBps() const { return m_bps; }
52
53 protected:
54 void CodecChange();
55
56 protected:
57 int m_srate, m_bps, m_channels, m_codno;
58 int m_byteorder, m_sign;
59 bool m_codchange, m_codcreate;
60 wxSoundCodec *m_codec;
61 };
62
63 class wxSoundCodec : public wxObject, public wxStreamBase {
64 DECLARE_ABSTRACT_CLASS(wxSoundCodec)
65 public:
66 wxSoundCodec();
67 virtual ~wxSoundCodec();
68
69 void SetIOBuffer(wxSndBuffer *sndbuf) { m_io_sndbuf = sndbuf; }
70 size_t Available();
71
72 void InitIO(const wxSoundDataFormat& format);
73 void InitMode(int mode);
74 void ExitMode();
75
76 inline void SetInStream(wxStreamBuffer *s)
77 { m_in_sound = s; }
78 inline void SetOutStream(wxStreamBuffer *s)
79 { m_out_sound = s; }
80 inline wxStreamBuffer *GetInStream() const { return m_in_sound; }
81 inline wxStreamBuffer *GetOutStream() const { return m_out_sound; }
82
83 inline bool StreamOk() const
84 { return (m_in_sound->Stream()->LastError() == wxStream_NOERROR) &&
85 (m_out_sound->Stream()->LastError() == wxStream_NOERROR); }
86
87 virtual size_t GetByteRate() const = 0;
88 virtual wxSoundDataFormat GetPreferredFormat(int codec = 0) const = 0;
89
90 virtual void Decode() = 0;
91 virtual void Encode() = 0;
92
93 static wxSoundCodec *Get(int no);
94
95 protected:
96 void CopyToOutput();
97
98 unsigned short Convert8_16(unsigned char s) { return (s & 0xff) << 8; }
99 unsigned char Convert16_8(unsigned short s) { return (s & 0xff00) >> 8; }
100
101 bool ChainCodecBefore(wxSoundDataFormat& cod_to);
102 bool ChainCodecAfter(wxSoundDataFormat& cod_to);
103
104 // -------------
105 // wxStream part
106 // -------------
107 size_t OnSysWrite(const void *buffer, size_t bsize);
108 size_t OnSysRead(void *buffer, size_t bsize);
109
110 protected:
111 wxSndBuffer *m_io_sndbuf;
112 wxSoundDataFormat m_io_format;
113 wxStreamBuffer *m_in_sound, *m_out_sound;
114 wxSoundCodec *m_chain_codec;
115 bool m_init, m_chain_before;
116
117 enum {
118 ENCODING = 0,
119 DECODING
120 } m_mode;
121 };
122
123 #endif