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