1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
12 #include <wx/stream.h>
17 #define wxSOUND_INFINITE_TIME ((unsigned long)-1)
23 class WXDLLEXPORT wxSoundRouterStream
: public wxSoundStreamCodec
{
25 wxSoundRouterStream(wxSoundStream
& sndio
);
26 ~wxSoundRouterStream();
28 wxSoundStream
& Read(void *buffer
, wxUint32 len
);
29 wxSoundStream
& Write(const void *buffer
, wxUint32 len
);
31 bool SetSoundFormat(const wxSoundFormatBase
& format
);
33 bool StartProduction(int evt
);
34 bool StopProduction();
36 wxUint32
GetBestSize() const;
39 wxSoundStream
*m_router
;
46 wxSOUND_FILE_RECORDING
50 // Base class for file coders/decoders
53 class wxSoundFileStream
: public wxSoundStream
{
55 wxSoundFileStream(wxInputStream
& stream
, wxSoundStream
& io_sound
);
56 wxSoundFileStream(wxOutputStream
& stream
, wxSoundStream
& io_sound
);
59 // Usual sound file calls (Play, Stop, ...)
61 bool Record(unsigned long time
);
66 // Functions which return the current state
67 bool IsStopped() const { return m_state
== wxSOUND_FILE_STOPPED
; }
68 bool IsPaused() const { return m_state
== wxSOUND_FILE_PAUSED
; }
70 // A user should not call these two functions. Several things must be done before calling them.
71 // Users should use Play(), ...
72 bool StartProduction(int evt
);
73 bool StopProduction();
75 // These three functions deals with the length, the position in the sound file.
76 // All the values are expressed in bytes. If you need the values expressed in terms of
77 // time, you have to use GetSoundFormat().GetTimeFromBytes(...)
79 wxUint32
GetPosition();
80 wxUint32
SetPosition(wxUint32 new_position
);
82 // These two functions use the sound format specified by GetSoundFormat(). All samples
83 // must be encoded in that format.
84 wxSoundStream
& Read(void *buffer
, wxUint32 len
);
85 wxSoundStream
& Write(const void *buffer
, wxUint32 len
);
87 // This function set the sound format of the file. !! It must be used only when you are
88 // in output mode (concerning the file) !! If you are in input mode (concerning the file)
89 // You can't use this function to modify the format of the samples returned by Read() !
90 // For this action, you must use wxSoundRouterStream applied to wxSoundFileStream.
91 bool SetSoundFormat(const wxSoundFormatBase
& format
);
93 // You should use this function to test whether this file codec can read the stream you passed
95 virtual bool CanRead() { return FALSE
; }
98 wxSoundRouterStream m_codec
;
99 wxSoundStream
*m_sndio
;
100 wxInputStream
*m_input
;
101 wxOutputStream
*m_output
;
103 wxSoundFileState m_state
, m_oldstate
;
104 wxUint32 m_length
, m_bytes_left
;
108 virtual bool PrepareToPlay() = 0;
109 virtual bool PrepareToRecord(unsigned long time
) = 0;
110 virtual bool FinishRecording() = 0;
111 void FinishPreparation(wxUint32 len
);
113 virtual wxUint32
GetData(void *buffer
, wxUint32 len
) = 0;
114 virtual wxUint32
PutData(const void *buffer
, wxUint32 len
) = 0;
116 void OnSoundEvent(int evt
);