|
|
|||
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_SOUNDFILEREADER_HPP 0026 #define SFML_SOUNDFILEREADER_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Audio/Export.hpp> 0032 #include <string> 0033 0034 0035 namespace sf 0036 { 0037 class InputStream; 0038 0039 //////////////////////////////////////////////////////////// 0040 /// \brief Abstract base class for sound file decoding 0041 /// 0042 //////////////////////////////////////////////////////////// 0043 class SFML_AUDIO_API SoundFileReader 0044 { 0045 public: 0046 0047 //////////////////////////////////////////////////////////// 0048 /// \brief Structure holding the audio properties of a sound file 0049 /// 0050 //////////////////////////////////////////////////////////// 0051 struct Info 0052 { 0053 Uint64 sampleCount; //!< Total number of samples in the file 0054 unsigned int channelCount; //!< Number of channels of the sound 0055 unsigned int sampleRate; //!< Samples rate of the sound, in samples per second 0056 }; 0057 0058 //////////////////////////////////////////////////////////// 0059 /// \brief Virtual destructor 0060 /// 0061 //////////////////////////////////////////////////////////// 0062 virtual ~SoundFileReader() {} 0063 0064 //////////////////////////////////////////////////////////// 0065 /// \brief Open a sound file for reading 0066 /// 0067 /// The provided stream reference is valid as long as the 0068 /// SoundFileReader is alive, so it is safe to use/store it 0069 /// during the whole lifetime of the reader. 0070 /// 0071 /// \param stream Source stream to read from 0072 /// \param info Structure to fill with the properties of the loaded sound 0073 /// 0074 /// \return True if the file was successfully opened 0075 /// 0076 //////////////////////////////////////////////////////////// 0077 virtual bool open(InputStream& stream, Info& info) = 0; 0078 0079 //////////////////////////////////////////////////////////// 0080 /// \brief Change the current read position to the given sample offset 0081 /// 0082 /// The sample offset takes the channels into account. 0083 /// If you have a time offset instead, you can easily find 0084 /// the corresponding sample offset with the following formula: 0085 /// `timeInSeconds * sampleRate * channelCount` 0086 /// If the given offset exceeds to total number of samples, 0087 /// this function must jump to the end of the file. 0088 /// 0089 /// \param sampleOffset Index of the sample to jump to, relative to the beginning 0090 /// 0091 //////////////////////////////////////////////////////////// 0092 virtual void seek(Uint64 sampleOffset) = 0; 0093 0094 //////////////////////////////////////////////////////////// 0095 /// \brief Read audio samples from the open file 0096 /// 0097 /// \param samples Pointer to the sample array to fill 0098 /// \param maxCount Maximum number of samples to read 0099 /// 0100 /// \return Number of samples actually read (may be less than \a maxCount) 0101 /// 0102 //////////////////////////////////////////////////////////// 0103 virtual Uint64 read(Int16* samples, Uint64 maxCount) = 0; 0104 }; 0105 0106 } // namespace sf 0107 0108 0109 #endif // SFML_SOUNDFILEREADER_HPP 0110 0111 0112 //////////////////////////////////////////////////////////// 0113 /// \class sf::SoundFileReader 0114 /// \ingroup audio 0115 /// 0116 /// This class allows users to read audio file formats not natively 0117 /// supported by SFML, and thus extend the set of supported readable 0118 /// audio formats. 0119 /// 0120 /// A valid sound file reader must override the open, seek and write functions, 0121 /// as well as providing a static check function; the latter is used by 0122 /// SFML to find a suitable writer for a given input file. 0123 /// 0124 /// To register a new reader, use the sf::SoundFileFactory::registerReader 0125 /// template function. 0126 /// 0127 /// Usage example: 0128 /// \code 0129 /// class MySoundFileReader : public sf::SoundFileReader 0130 /// { 0131 /// public: 0132 /// 0133 /// static bool check(sf::InputStream& stream) 0134 /// { 0135 /// // typically, read the first few header bytes and check fields that identify the format 0136 /// // return true if the reader can handle the format 0137 /// } 0138 /// 0139 /// virtual bool open(sf::InputStream& stream, Info& info) 0140 /// { 0141 /// // read the sound file header and fill the sound attributes 0142 /// // (channel count, sample count and sample rate) 0143 /// // return true on success 0144 /// } 0145 /// 0146 /// virtual void seek(sf::Uint64 sampleOffset) 0147 /// { 0148 /// // advance to the sampleOffset-th sample from the beginning of the sound 0149 /// } 0150 /// 0151 /// virtual sf::Uint64 read(sf::Int16* samples, sf::Uint64 maxCount) 0152 /// { 0153 /// // read up to 'maxCount' samples into the 'samples' array, 0154 /// // convert them (for example from normalized float) if they are not stored 0155 /// // as 16-bits signed integers in the file 0156 /// // return the actual number of samples read 0157 /// } 0158 /// }; 0159 /// 0160 /// sf::SoundFileFactory::registerReader<MySoundFileReader>(); 0161 /// \endcode 0162 /// 0163 /// \see sf::InputSoundFile, sf::SoundFileFactory, sf::SoundFileWriter 0164 /// 0165 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|