1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
12 #pragma interface "sndbase.h"
16 #include "wx/mmedia/defs.h"
18 // ------------------------------------------------------------------------
21 // ---------------------
22 // Sound streaming mode:
23 // - wxSOUND_INPUT: simple recording mode
24 // - wxSOUND_OUTPUT: simple playing mode
25 // - wxSOUND_DUPLEX: full duplex record/play at the same time
26 // ---------------------
30 wxSOUND_DUPLEX
= wxSOUND_INPUT
| wxSOUND_OUTPUT
,
33 // ---------------------
34 // wxSoundFormatType: it specifies the format family of the sound data
35 // which will be passed to the stream.
36 // ---------------------
45 // ---------------------
47 // - wxSOUND_NOERR: No error occured
48 // - wxSOUND_IOERR: an input/output error occured, it may concern either
50 // - wxSOUND_INVFRMT: the sound format passed to the function is invalid.
51 // Generally, it means that you passed out of range values
52 // to the codec stream or you don't pass the right sound
53 // format object to the right sound codec stream.
54 // - wxSOUND_INVDEV: Invalid device. Generally, it means that the sound stream
55 // didn't manage to open the device driver due to an invalid// parameter or to the fact that sound is not supported on
57 // - wxSOUND_NOEXACT: No exact matching sound codec has been found for
58 // this sound format. It means that the sound driver didn't
59 // manage to setup the sound card with the specified
61 // - wxSOUND_NOCODEC: No matching codec has been found. Generally, it
62 // may happen when you call
63 // wxSoundRouterStream::SetSoundFormat().
64 // - wxSOUND_MEMERR: Not enough memory.
65 // - wxSOUND_NOTSTARTED: You did not start the production using
67 // ---------------------
80 class WXDLLIMPEXP_MMEDIA wxSoundStream
;
82 // ---------------------
83 // wxSoundCallback(stream, evt, cdata): C callback for sound event.
84 // - stream: current wxSoundStream
85 // - evt: the sound event which has occured, it may be wxSOUND_INPUT,
86 // wxSOUND_OUTPUT or wxSOUND_DUPLEX
87 // - cdata: User callback data
88 // ---------------------
89 typedef void (*wxSoundCallback
)(wxSoundStream
*stream
, int evt
,
93 // Base class for sound format specification
96 class WXDLLIMPEXP_MMEDIA wxSoundFormatBase
{
99 virtual ~wxSoundFormatBase();
101 // It returns a "standard" format type.
102 virtual wxSoundFormatType
GetType() const { return wxSOUND_NOFORMAT
; }
103 // It clones the current format.
104 virtual wxSoundFormatBase
*Clone() const;
106 virtual wxUint32
GetTimeFromBytes(wxUint32 bytes
) const = 0;
107 virtual wxUint32
GetBytesFromTime(wxUint32 time
) const = 0;
109 virtual bool operator !=(const wxSoundFormatBase
& frmt2
) const;
113 // Base class for sound streams
116 class WXDLLIMPEXP_MMEDIA wxSoundStream
{
119 virtual ~wxSoundStream();
121 // Reads "len" bytes from the sound stream.
122 virtual wxSoundStream
& Read(void *buffer
, wxUint32 len
) = 0;
123 // Writes "len" byte to the sound stream.
124 virtual wxSoundStream
& Write(const void *buffer
, wxUint32 len
) = 0;
125 // Returns the best size for IO calls
126 virtual wxUint32
GetBestSize() const { return 1024; }
128 // SetSoundFormat returns true when the format can be handled.
129 virtual bool SetSoundFormat(const wxSoundFormatBase
& format
);
131 // GetSoundFormat returns the current sound format.
132 wxSoundFormatBase
& GetSoundFormat() const { return *m_sndformat
; }
134 // Register a callback for a specified async event.
135 void SetCallback(int evt
, wxSoundCallback cbk
, void *cdata
);
137 // Starts the async notifier. After this call, the stream begins either
138 // recording or playing or the two at the same time.
139 virtual bool StartProduction(int evt
) = 0;
140 // Stops the async notifier.
141 virtual bool StopProduction() = 0;
142 // Sets the event handler: if it is non-null, all events are routed to it.
143 void SetEventHandler(wxSoundStream
*handler
) { m_handler
= handler
; }
145 wxSoundError
GetError() const { return m_snderror
; }
146 wxUint32
GetLastAccess() const { return m_lastcount
; }
148 // This is only useful for device (I think).
149 virtual bool QueueFilled() const { return true; }
152 // Current sound format
153 wxSoundFormatBase
*m_sndformat
;
156 wxSoundError m_snderror
;
159 wxUint32 m_lastcount
;
162 wxSoundStream
*m_handler
;
164 wxSoundCallback m_callback
[2];
169 virtual void OnSoundEvent(int evt
);