]>
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 | ||
17 | enum { | |
18 | wxSOUND_INPUT = 1, | |
19 | wxSOUND_OUTPUT = 2, | |
20 | wxSOUND_DUPLEX = wxSOUND_INPUT | wxSOUND_OUTPUT, | |
21 | }; | |
22 | ||
23 | typedef enum { | |
24 | wxSOUND_NOFORMAT, | |
25 | wxSOUND_PCM, | |
9baf15ce GL |
26 | wxSOUND_ULAW, |
27 | wxSOUND_G72X | |
526ddb13 GL |
28 | } wxSoundFormatType; |
29 | ||
30 | typedef enum { | |
31 | wxSOUND_NOERR, | |
32 | wxSOUND_IOERR, | |
33 | wxSOUND_INVFRMT, | |
34 | wxSOUND_INVDEV, | |
35 | wxSOUND_NOTEXACT, | |
36 | wxSOUND_INVSTRM, | |
37 | wxSOUND_NOCODEC, | |
38 | wxSOUND_MEMERR | |
39 | } wxSoundError; | |
40 | ||
41 | class WXDLLEXPORT wxSoundStream; | |
42 | ||
43 | typedef void (*wxSoundCallback)(wxSoundStream *stream, int evt, | |
44 | char *cdata); | |
45 | ||
46 | // | |
47 | // Base class for sound format specification | |
48 | // | |
49 | ||
50 | class WXDLLEXPORT wxSoundFormatBase { | |
51 | public: | |
52 | wxSoundFormatBase(); | |
53 | virtual ~wxSoundFormatBase(); | |
54 | ||
55 | virtual wxSoundFormatType GetType() const { return wxSOUND_NOFORMAT; } | |
56 | virtual wxSoundFormatBase *Clone() const; | |
57 | ||
622e48cb GL |
58 | virtual wxUint32 GetTimeFromBytes(wxUint32 bytes) const = 0; |
59 | virtual wxUint32 GetBytesFromTime(wxUint32 time) const = 0; | |
526ddb13 GL |
60 | |
61 | virtual bool operator !=(const wxSoundFormatBase& frmt2) const; | |
62 | }; | |
63 | ||
64 | // | |
65 | // Base class for sound streams | |
66 | // | |
67 | ||
68 | class wxSoundStream { | |
69 | public: | |
70 | wxSoundStream(); | |
71 | virtual ~wxSoundStream(); | |
72 | ||
73 | // Reads "len" bytes from the sound stream. | |
0662cd32 | 74 | virtual wxSoundStream& Read(void *buffer, wxUint32 len) = 0; |
526ddb13 | 75 | // Writes "len" byte to the sound stream. |
0662cd32 | 76 | virtual wxSoundStream& Write(const void *buffer, wxUint32 len) = 0; |
526ddb13 GL |
77 | // Returns the best size for IO calls |
78 | virtual wxUint32 GetBestSize() const { return 1024; } | |
79 | ||
80 | // SetSoundFormat returns TRUE when the format can be handled. | |
81 | virtual bool SetSoundFormat(const wxSoundFormatBase& format); | |
82 | ||
83 | // GetSoundFormat returns the current sound format. | |
84 | wxSoundFormatBase& GetSoundFormat() const { return *m_sndformat; } | |
85 | ||
86 | // Register a callback for a specified async event. | |
87 | void Register(int evt, wxSoundCallback cbk, char *cdata); | |
88 | ||
89 | // Starts the async notifier. | |
90 | virtual bool StartProduction(int evt) = 0; | |
91 | // Stops the async notifier. | |
92 | virtual bool StopProduction() = 0; | |
93 | // Sets the event handler: if it is non-null, all events are routed to it. | |
94 | void SetEventHandler(wxSoundStream *handler) { m_handler = handler; } | |
95 | ||
96 | // Initializes the full duplex mode. | |
97 | virtual void SetDuplexMode(bool duplex) = 0; | |
98 | ||
99 | wxSoundError GetError() const { return m_snderror; } | |
0662cd32 | 100 | wxUint32 GetLastAccess() const { return m_lastcount; } |
526ddb13 | 101 | |
503aa33d GL |
102 | // This is only useful for device (I think). |
103 | virtual bool QueueFilled() const { return TRUE; } | |
104 | ||
526ddb13 GL |
105 | protected: |
106 | // Current sound format | |
107 | wxSoundFormatBase *m_sndformat; | |
108 | ||
109 | // Last error | |
110 | wxSoundError m_snderror; | |
111 | ||
112 | // Last access | |
0662cd32 | 113 | wxUint32 m_lastcount; |
526ddb13 GL |
114 | |
115 | // Event handler | |
116 | wxSoundStream *m_handler; | |
117 | ||
118 | wxSoundCallback m_callback[2]; | |
119 | char *m_cdata[2]; | |
120 | ||
121 | protected: | |
122 | // Do the async stuff. | |
123 | void DoAsyncStuff(int evt); | |
124 | ||
125 | // Handles event | |
126 | virtual void OnSoundEvent(int evt); | |
127 | }; | |
128 | ||
129 | #endif |