]> git.sesse.net Git - casparcg/blob - dependencies64/sfml/include/SFML/Audio/SoundRecorder.hpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[casparcg] / dependencies64 / sfml / include / SFML / Audio / SoundRecorder.hpp
1 ////////////////////////////////////////////////////////////\r
2 //\r
3 // SFML - Simple and Fast Multimedia Library\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
5 //\r
6 // This software is provided 'as-is', without any express or implied warranty.\r
7 // In no event will the authors be held liable for any damages arising from the use of this software.\r
8 //\r
9 // Permission is granted to anyone to use this software for any purpose,\r
10 // including commercial applications, and to alter it and redistribute it freely,\r
11 // subject to the following restrictions:\r
12 //\r
13 // 1. The origin of this software must not be misrepresented;\r
14 //    you must not claim that you wrote the original software.\r
15 //    If you use this software in a product, an acknowledgment\r
16 //    in the product documentation would be appreciated but is not required.\r
17 //\r
18 // 2. Altered source versions must be plainly marked as such,\r
19 //    and must not be misrepresented as being the original software.\r
20 //\r
21 // 3. This notice may not be removed or altered from any source distribution.\r
22 //\r
23 ////////////////////////////////////////////////////////////\r
24 \r
25 #ifndef SFML_SOUNDRECORDER_HPP\r
26 #define SFML_SOUNDRECORDER_HPP\r
27 \r
28 ////////////////////////////////////////////////////////////\r
29 // Headers\r
30 ////////////////////////////////////////////////////////////\r
31 #include <SFML/System/Thread.hpp>\r
32 #include <vector>\r
33 \r
34 \r
35 namespace sf\r
36 {\r
37 ////////////////////////////////////////////////////////////\r
38 /// SoundRecorder is an interface for capturing sound data,\r
39 /// it is meant to be used as a base class\r
40 ////////////////////////////////////////////////////////////\r
41 class SFML_API SoundRecorder : private Thread\r
42 {\r
43 public :\r
44 \r
45     ////////////////////////////////////////////////////////////\r
46     /// Virtual destructor\r
47     ///\r
48     ////////////////////////////////////////////////////////////\r
49     virtual ~SoundRecorder();\r
50 \r
51     ////////////////////////////////////////////////////////////\r
52     /// Start the capture.\r
53     /// Warning : only one capture can happen at the same time\r
54     ///\r
55     /// \param SampleRate : Sound frequency (the more samples, the higher the quality)\r
56     ///                    (44100 by default = CD quality)\r
57     ///\r
58     ////////////////////////////////////////////////////////////\r
59     void Start(unsigned int SampleRate = 44100);\r
60 \r
61     ////////////////////////////////////////////////////////////\r
62     /// Stop the capture\r
63     ///\r
64     ////////////////////////////////////////////////////////////\r
65     void Stop();\r
66 \r
67     ////////////////////////////////////////////////////////////\r
68     /// Get the sample rate\r
69     ///\r
70     /// \return Frequency, in samples per second\r
71     ///\r
72     ////////////////////////////////////////////////////////////\r
73     unsigned int GetSampleRate() const;\r
74 \r
75     ////////////////////////////////////////////////////////////\r
76     /// Tell if the system supports sound capture.\r
77     /// If not, this class won't be usable\r
78     ///\r
79     /// \return True if audio capture is supported\r
80     ///\r
81     ////////////////////////////////////////////////////////////\r
82     static bool CanCapture();\r
83 \r
84 protected :\r
85 \r
86     ////////////////////////////////////////////////////////////\r
87     /// Default constructor\r
88     ///\r
89     ////////////////////////////////////////////////////////////\r
90     SoundRecorder();\r
91 \r
92 private :\r
93 \r
94     ////////////////////////////////////////////////////////////\r
95     /// Start recording audio data\r
96     ///\r
97     /// \return False to abort recording audio data, true to start\r
98     ///\r
99     ////////////////////////////////////////////////////////////\r
100     virtual bool OnStart();\r
101 \r
102     ////////////////////////////////////////////////////////////\r
103     /// Process a new chunk of recorded samples\r
104     ///\r
105     /// \param Samples :      Pointer to the new chunk of recorded samples\r
106     /// \param SamplesCount : Number of samples pointed by Samples\r
107     ///\r
108     /// \return False to stop recording audio data, true to continue\r
109     ///\r
110     ////////////////////////////////////////////////////////////\r
111     virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount) = 0;\r
112 \r
113     ////////////////////////////////////////////////////////////\r
114     /// Stop recording audio data\r
115     ///\r
116     ////////////////////////////////////////////////////////////\r
117     virtual void OnStop();\r
118 \r
119     ////////////////////////////////////////////////////////////\r
120     /// /see Thread::Run\r
121     ///\r
122     ////////////////////////////////////////////////////////////\r
123     virtual void Run();\r
124 \r
125     ////////////////////////////////////////////////////////////\r
126     /// Get the available captured samples and process them\r
127     ///\r
128     ////////////////////////////////////////////////////////////\r
129     void ProcessCapturedSamples();\r
130 \r
131     ////////////////////////////////////////////////////////////\r
132     /// Clean up the recorder internal resources\r
133     ///\r
134     ////////////////////////////////////////////////////////////\r
135     void CleanUp();\r
136 \r
137     ////////////////////////////////////////////////////////////\r
138     // Member data\r
139     ////////////////////////////////////////////////////////////\r
140     std::vector<Int16> mySamples;     ///< Buffer to store captured samples\r
141     unsigned int       mySampleRate;  ///< Sample rate\r
142     bool               myIsCapturing; ///< Capturing state\r
143 };\r
144 \r
145 } // namespace sf\r
146 \r
147 \r
148 #endif // SFML_SOUNDRECORDER_HPP\r