]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia2/lib/sndfile.h
Major changes in wxVidXANIM (support for output filtering)
[wxWidgets.git] / utils / wxMMedia2 / lib / sndfile.h
CommitLineData
526ddb13
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$
7// --------------------------------------------------------------------------
8#ifndef _WX_SNDFILE_H
9#define _WX_SNDFILE_H
10
11#include <wx/defs.h>
12#include <wx/stream.h>
13#include <stdlib.h>
14#include "sndbase.h"
15#include "sndcodec.h"
16
17#define wxSOUND_INFINITE_TIME ((unsigned long)-1)
18
19//
20// Codec router class
21//
22
23class WXDLLEXPORT wxSoundRouterStream: public wxSoundStreamCodec {
24 public:
25 wxSoundRouterStream(wxSoundStream& sndio);
26 ~wxSoundRouterStream();
27
0662cd32
GL
28 wxSoundStream& Read(void *buffer, wxUint32 len);
29 wxSoundStream& Write(const void *buffer, wxUint32 len);
526ddb13
GL
30
31 bool SetSoundFormat(const wxSoundFormatBase& format);
32
33 bool StartProduction(int evt);
34 bool StopProduction();
35
56dc1ffd
GL
36 wxUint32 GetBestSize() const;
37
526ddb13
GL
38 protected:
39 wxSoundStream *m_router;
40};
41
42typedef enum {
43 wxSOUND_FILE_STOPPED,
44 wxSOUND_FILE_PAUSED,
45 wxSOUND_FILE_PLAYING,
46 wxSOUND_FILE_RECORDING
47} wxSoundFileState;
48
49//
50// Base class for file coders/decoders
51//
52
53class wxSoundFileStream: public wxSoundStream {
54 public:
55 wxSoundFileStream(wxInputStream& stream, wxSoundStream& io_sound);
56 wxSoundFileStream(wxOutputStream& stream, wxSoundStream& io_sound);
57 ~wxSoundFileStream();
58
d73dd2b2 59 // Usual sound file calls (Play, Stop, ...)
526ddb13
GL
60 bool Play();
61 bool Record(unsigned long time);
62 bool Stop();
63 bool Pause();
64 bool Resume();
65
d73dd2b2 66 // Functions which return the current state
526ddb13 67 bool IsStopped() const { return m_state == wxSOUND_FILE_STOPPED; }
5bee458a 68 bool IsPaused() const { return m_state == wxSOUND_FILE_PAUSED; }
526ddb13 69
d73dd2b2
GL
70 // A user should not call these two functions. Several things must be done before calling them.
71 // Users should use Play(), ...
526ddb13
GL
72 bool StartProduction(int evt);
73 bool StopProduction();
74
d73dd2b2
GL
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(...)
a31c84f3
GL
78 wxUint32 GetLength();
79 wxUint32 GetPosition();
d73dd2b2 80 wxUint32 SetPosition(wxUint32 new_position);
526ddb13 81
d73dd2b2
GL
82 // These two functions use the sound format specified by GetSoundFormat(). All samples
83 // must be encoded in that format.
0662cd32
GL
84 wxSoundStream& Read(void *buffer, wxUint32 len);
85 wxSoundStream& Write(const void *buffer, wxUint32 len);
526ddb13 86
d73dd2b2
GL
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.
526ddb13
GL
91 bool SetSoundFormat(const wxSoundFormatBase& format);
92
2018e574
GL
93 // This function returns the Codec name. This is useful for those who want to build
94 // a player (But also in some other case).
95 virtual wxString GetCodecName() const;
96
d73dd2b2
GL
97 // You should use this function to test whether this file codec can read the stream you passed
98 // to it.
56dc1ffd 99 virtual bool CanRead() { return FALSE; }
526ddb13
GL
100
101 protected:
102 wxSoundRouterStream m_codec;
103 wxSoundStream *m_sndio;
104 wxInputStream *m_input;
105 wxOutputStream *m_output;
106
107 wxSoundFileState m_state, m_oldstate;
a31c84f3
GL
108 wxUint32 m_length, m_bytes_left;
109 bool m_prepared;
526ddb13
GL
110
111 protected:
112 virtual bool PrepareToPlay() = 0;
113 virtual bool PrepareToRecord(unsigned long time) = 0;
114 virtual bool FinishRecording() = 0;
a31c84f3 115 void FinishPreparation(wxUint32 len);
526ddb13 116
0662cd32
GL
117 virtual wxUint32 GetData(void *buffer, wxUint32 len) = 0;
118 virtual wxUint32 PutData(const void *buffer, wxUint32 len) = 0;
526ddb13
GL
119
120 void OnSoundEvent(int evt);
121};
122
123#endif