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