1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // License: wxWindows license
8 // --------------------------------------------------------------------------
13 #include "wx/mmedia/defs.h"
15 // ------------------------------------------------------------------------
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 // ---------------------
27 wxSOUND_DUPLEX
= wxSOUND_INPUT
| wxSOUND_OUTPUT
,
30 // ---------------------
31 // wxSoundFormatType: it specifies the format family of the sound data
32 // which will be passed to the stream.
33 // ---------------------
42 // ---------------------
44 // - wxSOUND_NOERR: No error occurred
45 // - wxSOUND_IOERR: an input/output error occurred, it may concern either
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
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
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
64 // ---------------------
77 class WXDLLIMPEXP_MMEDIA wxSoundStream
;
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
,
90 // Base class for sound format specification
93 class WXDLLIMPEXP_MMEDIA wxSoundFormatBase
{
96 virtual ~wxSoundFormatBase();
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;
103 virtual wxUint32
GetTimeFromBytes(wxUint32 bytes
) const = 0;
104 virtual wxUint32
GetBytesFromTime(wxUint32 time
) const = 0;
106 virtual bool operator !=(const wxSoundFormatBase
& frmt2
) const;
110 // Base class for sound streams
113 class WXDLLIMPEXP_MMEDIA wxSoundStream
{
116 virtual ~wxSoundStream();
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; }
125 // SetSoundFormat returns true when the format can be handled.
126 virtual bool SetSoundFormat(const wxSoundFormatBase
& format
);
128 // GetSoundFormat returns the current sound format.
129 wxSoundFormatBase
& GetSoundFormat() const { return *m_sndformat
; }
131 // Register a callback for a specified async event.
132 void SetCallback(int evt
, wxSoundCallback cbk
, void *cdata
);
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
; }
142 wxSoundError
GetError() const { return m_snderror
; }
143 wxUint32
GetLastAccess() const { return m_lastcount
; }
145 // This is only useful for device (I think).
146 virtual bool QueueFilled() const { return true; }
149 // Current sound format
150 wxSoundFormatBase
*m_sndformat
;
153 wxSoundError m_snderror
;
156 wxUint32 m_lastcount
;
159 wxSoundStream
*m_handler
;
161 wxSoundCallback m_callback
[2];
166 virtual void OnSoundEvent(int evt
);