]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndfrmt.h
no message
[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 typedef enum {
67 WAITING = 0,
68 ENCODING,
69 DECODING
70 } ModeType;
71 public:
72 wxSoundCodec();
73 virtual ~wxSoundCodec();
74
75 void SetIOBuffer(wxSndBuffer *sndbuf) { m_io_sndbuf = sndbuf; }
76 size_t Available();
77
78 void InitIO(const wxSoundDataFormat& format);
79
80 inline void SetInStream(wxStreamBuffer *s)
81 { m_in_sound = s; }
82 inline void SetOutStream(wxStreamBuffer *s)
83 { m_out_sound = s; }
84 inline wxStreamBuffer *GetInStream() const { return m_in_sound; }
85 inline wxStreamBuffer *GetOutStream() const { return m_out_sound; }
86
87 inline bool StreamOk() const
88 { return (m_in_sound->Stream()->LastError() == wxStream_NOERROR) &&
89 (m_out_sound->Stream()->LastError() == wxStream_NOERROR); }
90
91 virtual size_t GetByteRate() const = 0;
92 virtual wxSoundDataFormat GetPreferredFormat(int codec = 0) const = 0;
93
94 virtual void InitMode(ModeType mode);
95 virtual void ExitMode();
96 virtual void Decode() = 0;
97 virtual void Encode() = 0;
98
99 static wxSoundCodec *Get(int no);
100
101 protected:
102 void CopyToOutput();
103
104 unsigned short Convert8_16(unsigned char s) { return (s & 0xff) << 8; }
105 unsigned char Convert16_8(unsigned short s) { return (s & 0xff00) >> 8; }
106
107 bool ChainCodecBefore(wxSoundDataFormat& cod_to);
108 bool ChainCodecAfter(wxSoundDataFormat& cod_to);
109
110 // -------------
111 // wxStream part
112 // -------------
113 size_t OnSysWrite(const void *buffer, size_t bsize);
114 size_t OnSysRead(void *buffer, size_t bsize);
115
116 protected:
117 wxSndBuffer *m_io_sndbuf;
118 wxSoundDataFormat m_io_format;
119 wxStreamBuffer *m_in_sound, *m_out_sound;
120 wxSoundCodec *m_chain_codec;
121 bool m_init, m_chain_before;
122 ModeType m_mode;
123 };
124
125 #endif