1 ////////////////////////////////////////////////////////////
\r
3 // SFML - Simple and Fast Multimedia Library
\r
4 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
\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
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
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
18 // 2. Altered source versions must be plainly marked as such,
\r
19 // and must not be misrepresented as being the original software.
\r
21 // 3. This notice may not be removed or altered from any source distribution.
\r
23 ////////////////////////////////////////////////////////////
\r
25 #ifndef SFML_SOUNDRECORDER_HPP
\r
26 #define SFML_SOUNDRECORDER_HPP
\r
28 ////////////////////////////////////////////////////////////
\r
30 ////////////////////////////////////////////////////////////
\r
31 #include <SFML/System/Thread.hpp>
\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
45 ////////////////////////////////////////////////////////////
\r
46 /// Virtual destructor
\r
48 ////////////////////////////////////////////////////////////
\r
49 virtual ~SoundRecorder();
\r
51 ////////////////////////////////////////////////////////////
\r
52 /// Start the capture.
\r
53 /// Warning : only one capture can happen at the same time
\r
55 /// \param SampleRate : Sound frequency (the more samples, the higher the quality)
\r
56 /// (44100 by default = CD quality)
\r
58 ////////////////////////////////////////////////////////////
\r
59 void Start(unsigned int SampleRate = 44100);
\r
61 ////////////////////////////////////////////////////////////
\r
62 /// Stop the capture
\r
64 ////////////////////////////////////////////////////////////
\r
67 ////////////////////////////////////////////////////////////
\r
68 /// Get the sample rate
\r
70 /// \return Frequency, in samples per second
\r
72 ////////////////////////////////////////////////////////////
\r
73 unsigned int GetSampleRate() const;
\r
75 ////////////////////////////////////////////////////////////
\r
76 /// Tell if the system supports sound capture.
\r
77 /// If not, this class won't be usable
\r
79 /// \return True if audio capture is supported
\r
81 ////////////////////////////////////////////////////////////
\r
82 static bool CanCapture();
\r
86 ////////////////////////////////////////////////////////////
\r
87 /// Default constructor
\r
89 ////////////////////////////////////////////////////////////
\r
94 ////////////////////////////////////////////////////////////
\r
95 /// Start recording audio data
\r
97 /// \return False to abort recording audio data, true to start
\r
99 ////////////////////////////////////////////////////////////
\r
100 virtual bool OnStart();
\r
102 ////////////////////////////////////////////////////////////
\r
103 /// Process a new chunk of recorded samples
\r
105 /// \param Samples : Pointer to the new chunk of recorded samples
\r
106 /// \param SamplesCount : Number of samples pointed by Samples
\r
108 /// \return False to stop recording audio data, true to continue
\r
110 ////////////////////////////////////////////////////////////
\r
111 virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount) = 0;
\r
113 ////////////////////////////////////////////////////////////
\r
114 /// Stop recording audio data
\r
116 ////////////////////////////////////////////////////////////
\r
117 virtual void OnStop();
\r
119 ////////////////////////////////////////////////////////////
\r
120 /// /see Thread::Run
\r
122 ////////////////////////////////////////////////////////////
\r
123 virtual void Run();
\r
125 ////////////////////////////////////////////////////////////
\r
126 /// Get the available captured samples and process them
\r
128 ////////////////////////////////////////////////////////////
\r
129 void ProcessCapturedSamples();
\r
131 ////////////////////////////////////////////////////////////
\r
132 /// Clean up the recorder internal resources
\r
134 ////////////////////////////////////////////////////////////
\r
137 ////////////////////////////////////////////////////////////
\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
148 #endif // SFML_SOUNDRECORDER_HPP
\r