1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // --------------------------------------------------------------------------
12 #include "wx/stream.h"
13 #include "wx/mmedia/sndbase.h"
14 #include "wx/mmedia/sndcodec.h"
16 #define wxSOUND_INFINITE_TIME ((wxUint32)-1)
22 class WXDLLEXPORT wxSoundRouterStream
: public wxSoundStreamCodec
{
24 wxSoundRouterStream(wxSoundStream
& sndio
);
25 ~wxSoundRouterStream();
27 wxSoundStream
& Read(void *buffer
, wxUint32 len
);
28 wxSoundStream
& Write(const void *buffer
, wxUint32 len
);
30 bool SetSoundFormat(const wxSoundFormatBase
& format
);
32 bool StartProduction(int evt
);
33 bool StopProduction();
35 wxUint32
GetBestSize() const;
38 wxSoundStream
*m_router
;
45 wxSOUND_FILE_RECORDING
49 // Base class for file coders/decoders
52 class wxSoundFileStream
: public wxSoundStream
{
54 wxSoundFileStream(wxInputStream
& stream
, wxSoundStream
& io_sound
);
55 wxSoundFileStream(wxOutputStream
& stream
, wxSoundStream
& io_sound
);
58 // Usual sound file calls (Play, Stop, ...)
60 bool Record(wxUint32 time
);
65 // Functions which return the current state
66 bool IsStopped() const { return m_state
== wxSOUND_FILE_STOPPED
; }
67 bool IsPaused() const { return m_state
== wxSOUND_FILE_PAUSED
; }
69 // A user should not call these two functions.
70 // 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
77 // in terms of 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().
83 // All samples 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
88 // when you are in output mode (concerning the file) !! If you are in
89 // input mode (concerning the file) you can't use this function to modify
90 // the format of the samples returned by Read() !
91 // For this action, you must use wxSoundRouterStream applied to wxSoundFileStream.
92 bool SetSoundFormat(const wxSoundFormatBase
& format
);
94 // This function returns the Codec name. This is useful for those who want to build
95 // a player (But also in some other case).
96 virtual wxString
GetCodecName() const;
98 // You should use this function to test whether this file codec can read
99 // the stream you passed to it.
100 virtual bool CanRead() { return FALSE
; }
103 wxSoundRouterStream m_codec
;
104 wxSoundStream
*m_sndio
;
105 wxInputStream
*m_input
;
106 wxOutputStream
*m_output
;
108 wxSoundFileState m_state
, m_oldstate
;
109 wxUint32 m_length
, m_bytes_left
;
113 virtual bool PrepareToPlay() = 0;
114 virtual bool PrepareToRecord(wxUint32 time
) = 0;
115 virtual bool FinishRecording() = 0;
116 virtual bool RepositionStream(wxUint32 position
) = 0;
117 void FinishPreparation(wxUint32 len
);
119 virtual wxUint32
GetData(void *buffer
, wxUint32 len
) = 0;
120 virtual wxUint32
PutData(const void *buffer
, wxUint32 len
) = 0;
122 void OnSoundEvent(int evt
);