1 // --------------------------------------------------------------------------
5 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
7 // License: wxWindows license
8 // --------------------------------------------------------------------------
13 #include "wx/stream.h"
14 #include "wx/mmedia/defs.h"
15 #include "wx/mmedia/sndbase.h"
16 #include "wx/mmedia/sndcodec.h"
18 #define wxSOUND_INFINITE_TIME ((wxUint32)-1)
24 class WXDLLIMPEXP_MMEDIA wxSoundRouterStream
: public wxSoundStreamCodec
{
26 wxSoundRouterStream(wxSoundStream
& sndio
);
27 ~wxSoundRouterStream();
29 wxSoundStream
& Read(void *buffer
, wxUint32 len
);
30 wxSoundStream
& Write(const void *buffer
, wxUint32 len
);
32 bool SetSoundFormat(const wxSoundFormatBase
& format
);
34 bool StartProduction(int evt
);
35 bool StopProduction();
37 wxUint32
GetBestSize() const;
40 wxSoundStream
*m_router
;
47 wxSOUND_FILE_RECORDING
51 // Base class for file coders/decoders
54 class wxSoundFileStream
: public wxSoundStream
{
56 wxSoundFileStream(wxInputStream
& stream
, wxSoundStream
& io_sound
);
57 wxSoundFileStream(wxOutputStream
& stream
, wxSoundStream
& io_sound
);
60 // Usual sound file calls (Play, Stop, ...)
62 bool Record(wxUint32 time
);
67 // Functions which return the current state
68 bool IsStopped() const { return m_state
== wxSOUND_FILE_STOPPED
; }
69 bool IsPaused() const { return m_state
== wxSOUND_FILE_PAUSED
; }
71 // A user should not call these two functions.
72 // Several things must be done before calling them.
73 // Users should use Play(), ...
74 bool StartProduction(int evt
);
75 bool StopProduction();
77 // These three functions deals with the length, the position in the sound file.
78 // All the values are expressed in bytes. If you need the values expressed
79 // in terms of time, you have to use GetSoundFormat().GetTimeFromBytes(...)
81 wxUint32
GetPosition();
82 wxUint32
SetPosition(wxUint32 new_position
);
84 // These two functions use the sound format specified by GetSoundFormat().
85 // All samples must be encoded in that format.
86 wxSoundStream
& Read(void *buffer
, wxUint32 len
);
87 wxSoundStream
& Write(const void *buffer
, wxUint32 len
);
89 // This function set the sound format of the file. !! It must be used only
90 // when you are in output mode (concerning the file) !! If you are in
91 // input mode (concerning the file) you can't use this function to modify
92 // the format of the samples returned by Read() !
93 // For this action, you must use wxSoundRouterStream applied to wxSoundFileStream.
94 bool SetSoundFormat(const wxSoundFormatBase
& format
);
96 // This function returns the Codec name. This is useful for those who want to build
97 // a player (But also in some other case).
98 virtual wxString
GetCodecName() const;
100 // You should use this function to test whether this file codec can read
101 // the stream you passed to it.
102 virtual bool CanRead() { return false; }
105 wxSoundRouterStream m_codec
;
106 wxSoundStream
*m_sndio
;
107 wxInputStream
*m_input
;
108 wxOutputStream
*m_output
;
110 wxSoundFileState m_state
, m_oldstate
;
111 wxUint32 m_length
, m_bytes_left
;
115 virtual bool PrepareToPlay() = 0;
116 virtual bool PrepareToRecord(wxUint32 time
) = 0;
117 virtual bool FinishRecording() = 0;
118 virtual bool RepositionStream(wxUint32 position
) = 0;
119 void FinishPreparation(wxUint32 len
);
121 virtual wxUint32
GetData(void *buffer
, wxUint32 len
) = 0;
122 virtual wxUint32
PutData(const void *buffer
, wxUint32 len
) = 0;
124 void OnSoundEvent(int evt
);