fa4ac4cd80b137ffe917e5056c22392512b922da
[TDDC76_proj.git] /
1 ////////////////////////////////////////////////////////////
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
5 //
6 // This software is provided 'as-is', without any express or implied warranty.
7 // In no event will the authors be held liable for any damages arising from the use of this software.
8 //
9 // Permission is granted to anyone to use this software for any purpose,
10 // including commercial applications, and to alter it and redistribute it freely,
11 // subject to the following restrictions:
12 //
13 // 1. The origin of this software must not be misrepresented;
14 // you must not claim that you wrote the original software.
15 // If you use this software in a product, an acknowledgment
16 // in the product documentation would be appreciated but is not required.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
23 ////////////////////////////////////////////////////////////
24
25 #ifndef SFML_SOUNDBUFFERRECORDER_HPP
26 #define SFML_SOUNDBUFFERRECORDER_HPP
27
28 ////////////////////////////////////////////////////////////
29 // Headers
30 ////////////////////////////////////////////////////////////
31 #include <SFML/Audio/Export.hpp>
32 #include <SFML/Audio/SoundBuffer.hpp>
33 #include <SFML/Audio/SoundRecorder.hpp>
34 #include <vector>
35
36
37 namespace sf
38 {
39 ////////////////////////////////////////////////////////////
40 /// \brief Specialized SoundRecorder which stores the captured
41 /// audio data into a sound buffer
42 ///
43 ////////////////////////////////////////////////////////////
44 class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
45 {
46 public :
47
48 ////////////////////////////////////////////////////////////
49 /// \brief Get the sound buffer containing the captured audio data
50 ///
51 /// The sound buffer is valid only after the capture has ended.
52 /// This function provides a read-only access to the internal
53 /// sound buffer, but it can be copied if you need to
54 /// make any modification to it.
55 ///
56 /// \return Read-only access to the sound buffer
57 ///
58 ////////////////////////////////////////////////////////////
59 const SoundBuffer& getBuffer() const;
60
61 protected:
62
63 ////////////////////////////////////////////////////////////
64 /// \brief Start capturing audio data
65 ///
66 /// \return True to start the capture, or false to abort it
67 ///
68 ////////////////////////////////////////////////////////////
69 virtual bool onStart();
70
71 ////////////////////////////////////////////////////////////
72 /// \brief Process a new chunk of recorded samples
73 ///
74 /// \param samples Pointer to the new chunk of recorded samples
75 /// \param sampleCount Number of samples pointed by \a samples
76 ///
77 /// \return True to continue the capture, or false to stop it
78 ///
79 ////////////////////////////////////////////////////////////
80 virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount);
81
82 ////////////////////////////////////////////////////////////
83 /// \brief Stop capturing audio data
84 ///
85 ////////////////////////////////////////////////////////////
86 virtual void onStop();
87
88 private :
89
90 ////////////////////////////////////////////////////////////
91 // Member data
92 ////////////////////////////////////////////////////////////
93 std::vector<Int16> m_samples; ///< Temporary sample buffer to hold the recorded data
94 SoundBuffer m_buffer; ///< Sound buffer that will contain the recorded data
95 };
96
97 } // namespace sf
98
99 #endif // SFML_SOUNDBUFFERRECORDER_HPP
100
101
102 ////////////////////////////////////////////////////////////
103 /// \class sf::SoundBufferRecorder
104 /// \ingroup audio
105 ///
106 /// sf::SoundBufferRecorder allows to access a recorded sound
107 /// through a sf::SoundBuffer, so that it can be played, saved
108 /// to a file, etc.
109 ///
110 /// It has the same simple interface as its base class (start(), stop())
111 /// and adds a function to retrieve the recorded sound buffer
112 /// (getBuffer()).
113 ///
114 /// As usual, don't forget to call the isAvailable() function
115 /// before using this class (see sf::SoundRecorder for more details
116 /// about this).
117 ///
118 /// Usage example:
119 /// \code
120 /// if (sf::SoundBufferRecorder::isAvailable())
121 /// {
122 /// // Record some audio data
123 /// sf::SoundBufferRecorder recorder;
124 /// recorder.start();
125 /// ...
126 /// recorder.stop();
127 ///
128 /// // Get the buffer containing the captured audio data
129 /// const sf::SoundBuffer& buffer = recorder.getBuffer();
130 ///
131 /// // Save it to a file (for example...)
132 /// buffer.saveToFile("my_record.ogg");
133 /// }
134 /// \endcode
135 ///
136 /// \see sf::SoundRecorder
137 ///
138 ////////////////////////////////////////////////////////////