]> git.saurik.com Git - wxWidgets.git/blame - contrib/include/wx/mmedia/sndfile.h
[ 1176516 ] argv datatype has changed (char in docs but really wxChar)
[wxWidgets.git] / contrib / include / wx / mmedia / sndfile.h
CommitLineData
e8482f24
GL
1// --------------------------------------------------------------------------
2// Name: sndfile.h
3// Purpose:
4// Date: 08/11/1999
5// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
6// CVSID: $Id$
05aa8cf3 7// License: wxWindows license
e8482f24
GL
8// --------------------------------------------------------------------------
9#ifndef _WX_SNDFILE_H
10#define _WX_SNDFILE_H
11
12#include "wx/defs.h"
13#include "wx/stream.h"
15e8daec 14#include "wx/mmedia/defs.h"
e8482f24
GL
15#include "wx/mmedia/sndbase.h"
16#include "wx/mmedia/sndcodec.h"
17
18#define wxSOUND_INFINITE_TIME ((wxUint32)-1)
19
20//
21// Codec router class
22//
23
15e8daec 24class WXDLLIMPEXP_MMEDIA wxSoundRouterStream: public wxSoundStreamCodec {
e8482f24
GL
25 public:
26 wxSoundRouterStream(wxSoundStream& sndio);
27 ~wxSoundRouterStream();
28
29 wxSoundStream& Read(void *buffer, wxUint32 len);
30 wxSoundStream& Write(const void *buffer, wxUint32 len);
31
32 bool SetSoundFormat(const wxSoundFormatBase& format);
33
34 bool StartProduction(int evt);
35 bool StopProduction();
36
37 wxUint32 GetBestSize() const;
38
39 protected:
40 wxSoundStream *m_router;
41};
42
43typedef enum {
44 wxSOUND_FILE_STOPPED,
45 wxSOUND_FILE_PAUSED,
46 wxSOUND_FILE_PLAYING,
47 wxSOUND_FILE_RECORDING
48} wxSoundFileState;
49
50//
51// Base class for file coders/decoders
52//
53
54class wxSoundFileStream: public wxSoundStream {
55public:
56 wxSoundFileStream(wxInputStream& stream, wxSoundStream& io_sound);
57 wxSoundFileStream(wxOutputStream& stream, wxSoundStream& io_sound);
58 ~wxSoundFileStream();
59
60 // Usual sound file calls (Play, Stop, ...)
61 bool Play();
62 bool Record(wxUint32 time);
63 bool Stop();
64 bool Pause();
65 bool Resume();
66
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; }
70
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();
76
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(...)
80 wxUint32 GetLength();
81 wxUint32 GetPosition();
82 wxUint32 SetPosition(wxUint32 new_position);
83
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);
88
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);
95
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;
99
100 // You should use this function to test whether this file codec can read
101 // the stream you passed to it.
dea7e44a 102 virtual bool CanRead() { return false; }
e8482f24
GL
103
104protected:
105 wxSoundRouterStream m_codec;
106 wxSoundStream *m_sndio;
107 wxInputStream *m_input;
108 wxOutputStream *m_output;
109
110 wxSoundFileState m_state, m_oldstate;
111 wxUint32 m_length, m_bytes_left;
112 bool m_prepared;
113
114protected:
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);
120
121 virtual wxUint32 GetData(void *buffer, wxUint32 len) = 0;
122 virtual wxUint32 PutData(const void *buffer, wxUint32 len) = 0;
123
124 void OnSoundEvent(int evt);
125};
126
127#endif