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