1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // License: wxWindows license
8 // --------------------------------------------------------------------------
13 #pragma interface "sndbase.h"
17 #include "wx/mmedia/defs.h"
19 // ------------------------------------------------------------------------
22 // ---------------------
23 // Sound streaming mode:
24 // - wxSOUND_INPUT: simple recording mode
25 // - wxSOUND_OUTPUT: simple playing mode
26 // - wxSOUND_DUPLEX: full duplex record/play at the same time
27 // ---------------------
31 wxSOUND_DUPLEX
= wxSOUND_INPUT
| wxSOUND_OUTPUT
,
34 // ---------------------
35 // wxSoundFormatType: it specifies the format family of the sound data
36 // which will be passed to the stream.
37 // ---------------------
46 // ---------------------
48 // - wxSOUND_NOERR: No error occured
49 // - wxSOUND_IOERR: an input/output error occured, it may concern either
51 // - wxSOUND_INVFRMT: the sound format passed to the function is invalid.
52 // Generally, it means that you passed out of range values
53 // to the codec stream or you don't pass the right sound
54 // format object to the right sound codec stream.
55 // - wxSOUND_INVDEV: Invalid device. Generally, it means that the sound stream
56 // didn't manage to open the device driver due to an invalid// parameter or to the fact that sound is not supported on
58 // - wxSOUND_NOEXACT: No exact matching sound codec has been found for
59 // this sound format. It means that the sound driver didn't
60 // manage to setup the sound card with the specified
62 // - wxSOUND_NOCODEC: No matching codec has been found. Generally, it
63 // may happen when you call
64 // wxSoundRouterStream::SetSoundFormat().
65 // - wxSOUND_MEMERR: Not enough memory.
66 // - wxSOUND_NOTSTARTED: You did not start the production using
68 // ---------------------
81 class WXDLLIMPEXP_MMEDIA wxSoundStream
;
83 // ---------------------
84 // wxSoundCallback(stream, evt, cdata): C callback for sound event.
85 // - stream: current wxSoundStream
86 // - evt: the sound event which has occured, it may be wxSOUND_INPUT,
87 // wxSOUND_OUTPUT or wxSOUND_DUPLEX
88 // - cdata: User callback data
89 // ---------------------
90 typedef void (*wxSoundCallback
)(wxSoundStream
*stream
, int evt
,
94 // Base class for sound format specification
97 class WXDLLIMPEXP_MMEDIA wxSoundFormatBase
{
100 virtual ~wxSoundFormatBase();
102 // It returns a "standard" format type.
103 virtual wxSoundFormatType
GetType() const { return wxSOUND_NOFORMAT
; }
104 // It clones the current format.
105 virtual wxSoundFormatBase
*Clone() const;
107 virtual wxUint32
GetTimeFromBytes(wxUint32 bytes
) const = 0;
108 virtual wxUint32
GetBytesFromTime(wxUint32 time
) const = 0;
110 virtual bool operator !=(const wxSoundFormatBase
& frmt2
) const;
114 // Base class for sound streams
117 class WXDLLIMPEXP_MMEDIA wxSoundStream
{
120 virtual ~wxSoundStream();
122 // Reads "len" bytes from the sound stream.
123 virtual wxSoundStream
& Read(void *buffer
, wxUint32 len
) = 0;
124 // Writes "len" byte to the sound stream.
125 virtual wxSoundStream
& Write(const void *buffer
, wxUint32 len
) = 0;
126 // Returns the best size for IO calls
127 virtual wxUint32
GetBestSize() const { return 1024; }
129 // SetSoundFormat returns true when the format can be handled.
130 virtual bool SetSoundFormat(const wxSoundFormatBase
& format
);
132 // GetSoundFormat returns the current sound format.
133 wxSoundFormatBase
& GetSoundFormat() const { return *m_sndformat
; }
135 // Register a callback for a specified async event.
136 void SetCallback(int evt
, wxSoundCallback cbk
, void *cdata
);
138 // Starts the async notifier. After this call, the stream begins either
139 // recording or playing or the two at the same time.
140 virtual bool StartProduction(int evt
) = 0;
141 // Stops the async notifier.
142 virtual bool StopProduction() = 0;
143 // Sets the event handler: if it is non-null, all events are routed to it.
144 void SetEventHandler(wxSoundStream
*handler
) { m_handler
= handler
; }
146 wxSoundError
GetError() const { return m_snderror
; }
147 wxUint32
GetLastAccess() const { return m_lastcount
; }
149 // This is only useful for device (I think).
150 virtual bool QueueFilled() const { return true; }
153 // Current sound format
154 wxSoundFormatBase
*m_sndformat
;
157 wxSoundError m_snderror
;
160 wxUint32 m_lastcount
;
163 wxSoundStream
*m_handler
;
165 wxSoundCallback m_callback
[2];
170 virtual void OnSoundEvent(int evt
);