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