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