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