]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/mmedia/sndbase.h
Warning fixes, source cleaning.
[wxWidgets.git] / contrib / include / wx / mmedia / sndbase.h
1 // --------------------------------------------------------------------------
2 // Name: sndbase.h
3 // Purpose:
4 // Date: 08/11/1999
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
6 // CVSID: $Id$
7 // --------------------------------------------------------------------------
8 #ifndef _WX_SNDBASE_H
9 #define _WX_SNDBASE_H
10
11 #ifdef __GNUG__
12 #pragma interface "sndbase.h"
13 #endif
14
15 #include "wx/defs.h"
16 #include "wx/mmedia/defs.h"
17
18 // ------------------------------------------------------------------------
19 // DEFINITIONS
20
21 // ---------------------
22 // Sound streaming mode:
23 // - wxSOUND_INPUT: simple recording mode
24 // - wxSOUND_OUTPUT: simple playing mode
25 // - wxSOUND_DUPLEX: full duplex record/play at the same time
26 // ---------------------
27 enum {
28 wxSOUND_INPUT = 1,
29 wxSOUND_OUTPUT = 2,
30 wxSOUND_DUPLEX = wxSOUND_INPUT | wxSOUND_OUTPUT,
31 };
32
33 // ---------------------
34 // wxSoundFormatType: it specifies the format family of the sound data
35 // which will be passed to the stream.
36 // ---------------------
37 typedef enum {
38 wxSOUND_NOFORMAT,
39 wxSOUND_PCM,
40 wxSOUND_ULAW,
41 wxSOUND_G72X,
42 wxSOUND_MSADPCM
43 } wxSoundFormatType;
44
45 // ---------------------
46 // wxSoundError:
47 // - wxSOUND_NOERR: No error occured
48 // - wxSOUND_IOERR: an input/output error occured, it may concern either
49 // a driver or a file
50 // - wxSOUND_INVFRMT: the sound format passed to the function is invalid.
51 // Generally, it means that you passed out of range values
52 // to the codec stream or you don't pass the right sound
53 // format object to the right sound codec stream.
54 // - wxSOUND_INVDEV: Invalid device. Generally, it means that the sound stream
55 // didn't manage to open the device driver due to an invalid// parameter or to the fact that sound is not supported on
56 // this computer.
57 // - wxSOUND_NOEXACT: No exact matching sound codec has been found for
58 // this sound format. It means that the sound driver didn't
59 // manage to setup the sound card with the specified
60 // values.
61 // - wxSOUND_NOCODEC: No matching codec has been found. Generally, it
62 // may happen when you call
63 // wxSoundRouterStream::SetSoundFormat().
64 // - wxSOUND_MEMERR: Not enough memory.
65 // - wxSOUND_NOTSTARTED: You did not start the production using
66 // StartProduction()
67 // ---------------------
68 typedef enum {
69 wxSOUND_NOERROR,
70 wxSOUND_IOERROR,
71 wxSOUND_INVFRMT,
72 wxSOUND_INVDEV,
73 wxSOUND_NOEXACT,
74 wxSOUND_INVSTRM,
75 wxSOUND_NOCODEC,
76 wxSOUND_MEMERROR,
77 wxSOUND_NOTSTARTED
78 } wxSoundError;
79
80 class WXDLLIMPEXP_MMEDIA wxSoundStream;
81
82 // ---------------------
83 // wxSoundCallback(stream, evt, cdata): C callback for sound event.
84 // - stream: current wxSoundStream
85 // - evt: the sound event which has occured, it may be wxSOUND_INPUT,
86 // wxSOUND_OUTPUT or wxSOUND_DUPLEX
87 // - cdata: User callback data
88 // ---------------------
89 typedef void (*wxSoundCallback)(wxSoundStream *stream, int evt,
90 void *cdata);
91
92 //
93 // Base class for sound format specification
94 //
95
96 class WXDLLIMPEXP_MMEDIA wxSoundFormatBase {
97 public:
98 wxSoundFormatBase();
99 virtual ~wxSoundFormatBase();
100
101 // It returns a "standard" format type.
102 virtual wxSoundFormatType GetType() const { return wxSOUND_NOFORMAT; }
103 // It clones the current format.
104 virtual wxSoundFormatBase *Clone() const;
105
106 virtual wxUint32 GetTimeFromBytes(wxUint32 bytes) const = 0;
107 virtual wxUint32 GetBytesFromTime(wxUint32 time) const = 0;
108
109 virtual bool operator !=(const wxSoundFormatBase& frmt2) const;
110 };
111
112 //
113 // Base class for sound streams
114 //
115
116 class WXDLLIMPEXP_MMEDIA wxSoundStream {
117 public:
118 wxSoundStream();
119 virtual ~wxSoundStream();
120
121 // Reads "len" bytes from the sound stream.
122 virtual wxSoundStream& Read(void *buffer, wxUint32 len) = 0;
123 // Writes "len" byte to the sound stream.
124 virtual wxSoundStream& Write(const void *buffer, wxUint32 len) = 0;
125 // Returns the best size for IO calls
126 virtual wxUint32 GetBestSize() const { return 1024; }
127
128 // SetSoundFormat returns true when the format can be handled.
129 virtual bool SetSoundFormat(const wxSoundFormatBase& format);
130
131 // GetSoundFormat returns the current sound format.
132 wxSoundFormatBase& GetSoundFormat() const { return *m_sndformat; }
133
134 // Register a callback for a specified async event.
135 void SetCallback(int evt, wxSoundCallback cbk, void *cdata);
136
137 // Starts the async notifier. After this call, the stream begins either
138 // recording or playing or the two at the same time.
139 virtual bool StartProduction(int evt) = 0;
140 // Stops the async notifier.
141 virtual bool StopProduction() = 0;
142 // Sets the event handler: if it is non-null, all events are routed to it.
143 void SetEventHandler(wxSoundStream *handler) { m_handler = handler; }
144
145 wxSoundError GetError() const { return m_snderror; }
146 wxUint32 GetLastAccess() const { return m_lastcount; }
147
148 // This is only useful for device (I think).
149 virtual bool QueueFilled() const { return true; }
150
151 protected:
152 // Current sound format
153 wxSoundFormatBase *m_sndformat;
154
155 // Last error
156 wxSoundError m_snderror;
157
158 // Last access
159 wxUint32 m_lastcount;
160
161 // Event handler
162 wxSoundStream *m_handler;
163
164 wxSoundCallback m_callback[2];
165 void *m_cdata[2];
166
167 protected:
168 // Handles event
169 virtual void OnSoundEvent(int evt);
170 };
171
172 #endif