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_OUTPUTSOUNDFILE_HPP
0026 #define SFML_OUTPUTSOUNDFILE_HPP
0027 
0028 ////////////////////////////////////////////////////////////
0029 // Headers
0030 ////////////////////////////////////////////////////////////
0031 #include <SFML/Audio/Export.hpp>
0032 #include <SFML/System/NonCopyable.hpp>
0033 #include <string>
0034 
0035 
0036 namespace sf
0037 {
0038 class SoundFileWriter;
0039 
0040 ////////////////////////////////////////////////////////////
0041 /// \brief Provide write access to sound files
0042 ///
0043 ////////////////////////////////////////////////////////////
0044 class SFML_AUDIO_API OutputSoundFile : NonCopyable
0045 {
0046 public:
0047 
0048     ////////////////////////////////////////////////////////////
0049     /// \brief Default constructor
0050     ///
0051     ////////////////////////////////////////////////////////////
0052     OutputSoundFile();
0053 
0054     ////////////////////////////////////////////////////////////
0055     /// \brief Destructor
0056     ///
0057     /// Closes the file if it was still open.
0058     ///
0059     ////////////////////////////////////////////////////////////
0060     ~OutputSoundFile();
0061 
0062     ////////////////////////////////////////////////////////////
0063     /// \brief Open the sound file from the disk for writing
0064     ///
0065     /// The supported audio formats are: WAV, OGG/Vorbis, FLAC.
0066     ///
0067     /// \param filename     Path of the sound file to write
0068     /// \param sampleRate   Sample rate of the sound
0069     /// \param channelCount Number of channels in the sound
0070     ///
0071     /// \return True if the file was successfully opened
0072     ///
0073     ////////////////////////////////////////////////////////////
0074     bool openFromFile(const std::string& filename, unsigned int sampleRate, unsigned int channelCount);
0075 
0076     ////////////////////////////////////////////////////////////
0077     /// \brief Write audio samples to the file
0078     ///
0079     /// \param samples     Pointer to the sample array to write
0080     /// \param count       Number of samples to write
0081     ///
0082     ////////////////////////////////////////////////////////////
0083     void write(const Int16* samples, Uint64 count);
0084 
0085     ////////////////////////////////////////////////////////////
0086     /// \brief Close the current file
0087     ///
0088     ////////////////////////////////////////////////////////////
0089     void close();
0090 
0091 private:
0092 
0093     ////////////////////////////////////////////////////////////
0094     // Member data
0095     ////////////////////////////////////////////////////////////
0096     SoundFileWriter* m_writer; //!< Writer that handles I/O on the file's format
0097 };
0098 
0099 } // namespace sf
0100 
0101 
0102 #endif // SFML_OUTPUTSOUNDFILE_HPP
0103 
0104 
0105 ////////////////////////////////////////////////////////////
0106 /// \class sf::OutputSoundFile
0107 /// \ingroup audio
0108 ///
0109 /// This class encodes audio samples to a sound file. It is
0110 /// used internally by higher-level classes such as sf::SoundBuffer,
0111 /// but can also be useful if you want to create audio files from
0112 /// custom data sources, like generated audio samples.
0113 ///
0114 /// Usage example:
0115 /// \code
0116 /// // Create a sound file, ogg/vorbis format, 44100 Hz, stereo
0117 /// sf::OutputSoundFile file;
0118 /// if (!file.openFromFile("music.ogg", 44100, 2))
0119 ///     /* error */;
0120 ///
0121 /// while (...)
0122 /// {
0123 ///     // Read or generate audio samples from your custom source
0124 ///     std::vector<sf::Int16> samples = ...;
0125 ///
0126 ///     // Write them to the file
0127 ///     file.write(samples.data(), samples.size());
0128 /// }
0129 /// \endcode
0130 ///
0131 /// \see sf::SoundFileWriter, sf::InputSoundFile
0132 ///
0133 ////////////////////////////////////////////////////////////