Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:58:13

0001 ////////////////////////////////////////////////////////////
0002 //
0003 // SFML - Simple and Fast Multimedia Library
0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
0005 //
0006 // This software is provided 'as-is', without any express or implied warranty.
0007 // In no event will the authors be held liable for any damages arising from the use of this software.
0008 //
0009 // Permission is granted to anyone to use this software for any purpose,
0010 // including commercial applications, and to alter it and redistribute it freely,
0011 // subject to the following restrictions:
0012 //
0013 // 1. The origin of this software must not be misrepresented;
0014 //    you must not claim that you wrote the original software.
0015 //    If you use this software in a product, an acknowledgment
0016 //    in the product documentation would be appreciated but is not required.
0017 //
0018 // 2. Altered source versions must be plainly marked as such,
0019 //    and must not be misrepresented as being the original software.
0020 //
0021 // 3. This notice may not be removed or altered from any source distribution.
0022 //
0023 ////////////////////////////////////////////////////////////
0024 
0025 #ifndef SFML_SOUNDBUFFERRECORDER_HPP
0026 #define SFML_SOUNDBUFFERRECORDER_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Audio/Export.hpp>
0032 #include <SFML/Audio/SoundBuffer.hpp>
0033 #include <SFML/Audio/SoundRecorder.hpp>
0034 #include <vector>
0035 
0036 
0037 namespace sf
0038 {
0039 ////////////////////////////////////////////////////////////
0040 /// \brief Specialized SoundRecorder which stores the captured
0041 ///        audio data into a sound buffer
0042 ///
0043 ////////////////////////////////////////////////////////////
0044 class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder
0045 {
0046 public:
0047 
0048     ////////////////////////////////////////////////////////////
0049     /// \brief destructor
0050     ///
0051     ////////////////////////////////////////////////////////////
0052     ~SoundBufferRecorder();
0053 
0054     ////////////////////////////////////////////////////////////
0055     /// \brief Get the sound buffer containing the captured audio data
0056     ///
0057     /// The sound buffer is valid only after the capture has ended.
0058     /// This function provides a read-only access to the internal
0059     /// sound buffer, but it can be copied if you need to
0060     /// make any modification to it.
0061     ///
0062     /// \return Read-only access to the sound buffer
0063     ///
0064     ////////////////////////////////////////////////////////////
0065     const SoundBuffer& getBuffer() const;
0066 
0067 protected:
0068 
0069     ////////////////////////////////////////////////////////////
0070     /// \brief Start capturing audio data
0071     ///
0072     /// \return True to start the capture, or false to abort it
0073     ///
0074     ////////////////////////////////////////////////////////////
0075     virtual bool onStart();
0076 
0077     ////////////////////////////////////////////////////////////
0078     /// \brief Process a new chunk of recorded samples
0079     ///
0080     /// \param samples     Pointer to the new chunk of recorded samples
0081     /// \param sampleCount Number of samples pointed by \a samples
0082     ///
0083     /// \return True to continue the capture, or false to stop it
0084     ///
0085     ////////////////////////////////////////////////////////////
0086     virtual bool onProcessSamples(const Int16* samples, std::size_t sampleCount);
0087 
0088     ////////////////////////////////////////////////////////////
0089     /// \brief Stop capturing audio data
0090     ///
0091     ////////////////////////////////////////////////////////////
0092     virtual void onStop();
0093 
0094 private:
0095 
0096     ////////////////////////////////////////////////////////////
0097     // Member data
0098     ////////////////////////////////////////////////////////////
0099     std::vector<Int16> m_samples; //!< Temporary sample buffer to hold the recorded data
0100     SoundBuffer        m_buffer;  //!< Sound buffer that will contain the recorded data
0101 };
0102 
0103 } // namespace sf
0104 
0105 #endif // SFML_SOUNDBUFFERRECORDER_HPP
0106 
0107 
0108 ////////////////////////////////////////////////////////////
0109 /// \class sf::SoundBufferRecorder
0110 /// \ingroup audio
0111 ///
0112 /// sf::SoundBufferRecorder allows to access a recorded sound
0113 /// through a sf::SoundBuffer, so that it can be played, saved
0114 /// to a file, etc.
0115 ///
0116 /// It has the same simple interface as its base class (start(), stop())
0117 /// and adds a function to retrieve the recorded sound buffer
0118 /// (getBuffer()).
0119 ///
0120 /// As usual, don't forget to call the isAvailable() function
0121 /// before using this class (see sf::SoundRecorder for more details
0122 /// about this).
0123 ///
0124 /// Usage example:
0125 /// \code
0126 /// if (sf::SoundBufferRecorder::isAvailable())
0127 /// {
0128 ///     // Record some audio data
0129 ///     sf::SoundBufferRecorder recorder;
0130 ///     recorder.start();
0131 ///     ...
0132 ///     recorder.stop();
0133 ///
0134 ///     // Get the buffer containing the captured audio data
0135 ///     const sf::SoundBuffer& buffer = recorder.getBuffer();
0136 ///
0137 ///     // Save it to a file (for example...)
0138 ///     buffer.saveToFile("my_record.ogg");
0139 /// }
0140 /// \endcode
0141 ///
0142 /// \see sf::SoundRecorder
0143 ///
0144 ////////////////////////////////////////////////////////////