1 ////////////////////////////////////////////////////////////
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com)
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.
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:
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.
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
21 // 3. This notice may not be removed or altered from any source distribution.
23 ////////////////////////////////////////////////////////////
25 #ifndef SFML_SOUNDBUFFERRECORDER_HPP
26 #define SFML_SOUNDBUFFERRECORDER_HPP
28 ////////////////////////////////////////////////////////////
30 ////////////////////////////////////////////////////////////
31 #include <SFML/Audio/Export.hpp>
32 #include <SFML/Audio/SoundBuffer.hpp>
33 #include <SFML/Audio/SoundRecorder.hpp>
39 ////////////////////////////////////////////////////////////
40 /// \brief Specialized SoundRecorder which stores the captured
41 /// audio data into a sound buffer
43 ////////////////////////////////////////////////////////////
44 class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
48 ////////////////////////////////////////////////////////////
49 /// \brief Get the sound buffer containing the captured audio data
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.
56 /// \return Read-only access to the sound buffer
58 ////////////////////////////////////////////////////////////
59 const SoundBuffer& getBuffer() const;
63 ////////////////////////////////////////////////////////////
64 /// \brief Start capturing audio data
66 /// \return True to start the capture, or false to abort it
68 ////////////////////////////////////////////////////////////
69 virtual bool onStart();
71 ////////////////////////////////////////////////////////////
72 /// \brief Process a new chunk of recorded samples
74 /// \param samples Pointer to the new chunk of recorded samples
75 /// \param sampleCount Number of samples pointed by \a samples
77 /// \return True to continue the capture, or false to stop it
79 ////////////////////////////////////////////////////////////
80 virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount);
82 ////////////////////////////////////////////////////////////
83 /// \brief Stop capturing audio data
85 ////////////////////////////////////////////////////////////
86 virtual void onStop();
90 ////////////////////////////////////////////////////////////
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
99 #endif // SFML_SOUNDBUFFERRECORDER_HPP
102 ////////////////////////////////////////////////////////////
103 /// \class sf::SoundBufferRecorder
106 /// sf::SoundBufferRecorder allows to access a recorded sound
107 /// through a sf::SoundBuffer, so that it can be played, saved
110 /// It has the same simple interface as its base class (start(), stop())
111 /// and adds a function to retrieve the recorded sound buffer
114 /// As usual, don't forget to call the isAvailable() function
115 /// before using this class (see sf::SoundRecorder for more details
120 /// if (sf::SoundBufferRecorder::isAvailable())
122 /// // Record some audio data
123 /// sf::SoundBufferRecorder recorder;
124 /// recorder.start();
128 /// // Get the buffer containing the captured audio data
129 /// const sf::SoundBuffer& buffer = recorder.getBuffer();
131 /// // Save it to a file (for example...)
132 /// buffer.saveToFile("my_record.ogg");
136 /// \see sf::SoundRecorder
138 ////////////////////////////////////////////////////////////