1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
12 #include "wx/stream.h"
13 #include "wx/mmedia/defs.h"
14 #include "wx/mmedia/sndbase.h"
15 #include "wx/mmedia/sndcodec.h"
17 #define wxSOUND_INFINITE_TIME ((wxUint32)-1)
23 class WXDLLIMPEXP_MMEDIA 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(wxUint32 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.
71 // Several things must be done before calling them.
72 // Users should use Play(), ...
73 bool StartProduction(int evt
);
74 bool StopProduction();
76 // These three functions deals with the length, the position in the sound file.
77 // All the values are expressed in bytes. If you need the values expressed
78 // in terms of time, you have to use GetSoundFormat().GetTimeFromBytes(...)
80 wxUint32
GetPosition();
81 wxUint32
SetPosition(wxUint32 new_position
);
83 // These two functions use the sound format specified by GetSoundFormat().
84 // All samples must be encoded in that format.
85 wxSoundStream
& Read(void *buffer
, wxUint32 len
);
86 wxSoundStream
& Write(const void *buffer
, wxUint32 len
);
88 // This function set the sound format of the file. !! It must be used only
89 // when you are in output mode (concerning the file) !! If you are in
90 // input mode (concerning the file) you can't use this function to modify
91 // the format of the samples returned by Read() !
92 // For this action, you must use wxSoundRouterStream applied to wxSoundFileStream.
93 bool SetSoundFormat(const wxSoundFormatBase
& format
);
95 // This function returns the Codec name. This is useful for those who want to build
96 // a player (But also in some other case).
97 virtual wxString
GetCodecName() const;
99 // You should use this function to test whether this file codec can read
100 // the stream you passed to it.
101 virtual bool CanRead() { return FALSE
; }
104 wxSoundRouterStream m_codec
;
105 wxSoundStream
*m_sndio
;
106 wxInputStream
*m_input
;
107 wxOutputStream
*m_output
;
109 wxSoundFileState m_state
, m_oldstate
;
110 wxUint32 m_length
, m_bytes_left
;
114 virtual bool PrepareToPlay() = 0;
115 virtual bool PrepareToRecord(wxUint32 time
) = 0;
116 virtual bool FinishRecording() = 0;
117 virtual bool RepositionStream(wxUint32 position
) = 0;
118 void FinishPreparation(wxUint32 len
);
120 virtual wxUint32
GetData(void *buffer
, wxUint32 len
) = 0;
121 virtual wxUint32
PutData(const void *buffer
, wxUint32 len
) = 0;
123 void OnSoundEvent(int evt
);