1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
12 #pragma interface "sndbase.h"
17 // ------------------------------------------------------------------------
20 // ---------------------
21 // Sound streaming mode:
22 // - wxSOUND_INPUT: simple recording mode
23 // - wxSOUND_OUTPUT: simple playing mode
24 // - wxSOUND_DUPLEX: full duplex record/play at the same time
25 // ---------------------
29 wxSOUND_DUPLEX
= wxSOUND_INPUT
| wxSOUND_OUTPUT
,
32 // ---------------------
33 // wxSoundFormatType: it specifies the format family of the sound data
34 // which will be passed to the stream.
35 // ---------------------
44 // ---------------------
46 // - wxSOUND_NOERR: No error occured
47 // - wxSOUND_IOERR: an input/output error occured, it may concern either
49 // - wxSOUND_INVFRMT: the sound format passed to the function is invalid.
50 // Generally, it means that you passed out of range values
51 // to the codec stream or you don't pass the right sound
52 // format object to the right sound codec stream.
53 // - wxSOUND_INVDEV: Invalid device. Generally, it means that the sound stream
54 // didn't manage to open the device driver due to an invalid// parameter or to the fact that sound is not supported on
56 // - wxSOUND_NOEXACT: No exact matching sound codec has been found for
57 // this sound format. It means that the sound driver didn't
58 // manage to setup the sound card with the specified
60 // - wxSOUND_NOCODEC: No matching codec has been found. Generally, it
61 // may happen when you call
62 // wxSoundRouterStream::SetSoundFormat().
63 // - wxSOUND_MEMERR: Not enough memory.
64 // - wxSOUND_NOTSTARTED: You did not start the production using
66 // ---------------------
79 class WXDLLEXPORT wxSoundStream
;
81 // ---------------------
82 // wxSoundCallback(stream, evt, cdata): C callback for sound event.
83 // - stream: current wxSoundStream
84 // - evt: the sound event which has occured, it may be wxSOUND_INPUT,
85 // wxSOUND_OUTPUT or wxSOUND_DUPLEX
86 // - cdata: User callback data
87 // ---------------------
88 typedef void (*wxSoundCallback
)(wxSoundStream
*stream
, int evt
,
92 // Base class for sound format specification
95 class WXDLLEXPORT wxSoundFormatBase
{
98 virtual ~wxSoundFormatBase();
100 // It returns a "standard" format type.
101 virtual wxSoundFormatType
GetType() const { return wxSOUND_NOFORMAT
; }
102 // It clones the current format.
103 virtual wxSoundFormatBase
*Clone() const;
105 virtual wxUint32
GetTimeFromBytes(wxUint32 bytes
) const = 0;
106 virtual wxUint32
GetBytesFromTime(wxUint32 time
) const = 0;
108 virtual bool operator !=(const wxSoundFormatBase
& frmt2
) const;
112 // Base class for sound streams
115 class WXDLLEXPORT wxSoundStream
{
118 virtual ~wxSoundStream();
120 // Reads "len" bytes from the sound stream.
121 virtual wxSoundStream
& Read(void *buffer
, wxUint32 len
) = 0;
122 // Writes "len" byte to the sound stream.
123 virtual wxSoundStream
& Write(const void *buffer
, wxUint32 len
) = 0;
124 // Returns the best size for IO calls
125 virtual wxUint32
GetBestSize() const { return 1024; }
127 // SetSoundFormat returns TRUE when the format can be handled.
128 virtual bool SetSoundFormat(const wxSoundFormatBase
& format
);
130 // GetSoundFormat returns the current sound format.
131 wxSoundFormatBase
& GetSoundFormat() const { return *m_sndformat
; }
133 // Register a callback for a specified async event.
134 void SetCallback(int evt
, wxSoundCallback cbk
, void *cdata
);
136 // Starts the async notifier. After this call, the stream begins either
137 // recording or playing or the two at the same time.
138 virtual bool StartProduction(int evt
) = 0;
139 // Stops the async notifier.
140 virtual bool StopProduction() = 0;
141 // Sets the event handler: if it is non-null, all events are routed to it.
142 void SetEventHandler(wxSoundStream
*handler
) { m_handler
= handler
; }
144 wxSoundError
GetError() const { return m_snderror
; }
145 wxUint32
GetLastAccess() const { return m_lastcount
; }
147 // This is only useful for device (I think).
148 virtual bool QueueFilled() const { return TRUE
; }
151 // Current sound format
152 wxSoundFormatBase
*m_sndformat
;
155 wxSoundError m_snderror
;
158 wxUint32 m_lastcount
;
161 wxSoundStream
*m_handler
;
163 wxSoundCallback m_callback
[2];
168 virtual void OnSoundEvent(int evt
);