|
|
|||
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_SOUNDSOURCE_HPP 0026 #define SFML_SOUNDSOURCE_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Audio/Export.hpp> 0032 #include <SFML/Audio/AlResource.hpp> 0033 #include <SFML/System/Vector3.hpp> 0034 0035 0036 namespace sf 0037 { 0038 //////////////////////////////////////////////////////////// 0039 /// \brief Base class defining a sound's properties 0040 /// 0041 //////////////////////////////////////////////////////////// 0042 class SFML_AUDIO_API SoundSource : AlResource 0043 { 0044 public: 0045 0046 //////////////////////////////////////////////////////////// 0047 /// \brief Enumeration of the sound source states 0048 /// 0049 //////////////////////////////////////////////////////////// 0050 enum Status 0051 { 0052 Stopped, //!< Sound is not playing 0053 Paused, //!< Sound is paused 0054 Playing //!< Sound is playing 0055 }; 0056 0057 //////////////////////////////////////////////////////////// 0058 /// \brief Copy constructor 0059 /// 0060 /// \param copy Instance to copy 0061 /// 0062 //////////////////////////////////////////////////////////// 0063 SoundSource(const SoundSource& copy); 0064 0065 //////////////////////////////////////////////////////////// 0066 /// \brief Destructor 0067 /// 0068 //////////////////////////////////////////////////////////// 0069 virtual ~SoundSource(); 0070 0071 //////////////////////////////////////////////////////////// 0072 /// \brief Set the pitch of the sound 0073 /// 0074 /// The pitch represents the perceived fundamental frequency 0075 /// of a sound; thus you can make a sound more acute or grave 0076 /// by changing its pitch. A side effect of changing the pitch 0077 /// is to modify the playing speed of the sound as well. 0078 /// The default value for the pitch is 1. 0079 /// 0080 /// \param pitch New pitch to apply to the sound 0081 /// 0082 /// \see getPitch 0083 /// 0084 //////////////////////////////////////////////////////////// 0085 void setPitch(float pitch); 0086 0087 //////////////////////////////////////////////////////////// 0088 /// \brief Set the volume of the sound 0089 /// 0090 /// The volume is a value between 0 (mute) and 100 (full volume). 0091 /// The default value for the volume is 100. 0092 /// 0093 /// \param volume Volume of the sound 0094 /// 0095 /// \see getVolume 0096 /// 0097 //////////////////////////////////////////////////////////// 0098 void setVolume(float volume); 0099 0100 //////////////////////////////////////////////////////////// 0101 /// \brief Set the 3D position of the sound in the audio scene 0102 /// 0103 /// Only sounds with one channel (mono sounds) can be 0104 /// spatialized. 0105 /// The default position of a sound is (0, 0, 0). 0106 /// 0107 /// \param x X coordinate of the position of the sound in the scene 0108 /// \param y Y coordinate of the position of the sound in the scene 0109 /// \param z Z coordinate of the position of the sound in the scene 0110 /// 0111 /// \see getPosition 0112 /// 0113 //////////////////////////////////////////////////////////// 0114 void setPosition(float x, float y, float z); 0115 0116 //////////////////////////////////////////////////////////// 0117 /// \brief Set the 3D position of the sound in the audio scene 0118 /// 0119 /// Only sounds with one channel (mono sounds) can be 0120 /// spatialized. 0121 /// The default position of a sound is (0, 0, 0). 0122 /// 0123 /// \param position Position of the sound in the scene 0124 /// 0125 /// \see getPosition 0126 /// 0127 //////////////////////////////////////////////////////////// 0128 void setPosition(const Vector3f& position); 0129 0130 //////////////////////////////////////////////////////////// 0131 /// \brief Make the sound's position relative to the listener or absolute 0132 /// 0133 /// Making a sound relative to the listener will ensure that it will always 0134 /// be played the same way regardless of the position of the listener. 0135 /// This can be useful for non-spatialized sounds, sounds that are 0136 /// produced by the listener, or sounds attached to it. 0137 /// The default value is false (position is absolute). 0138 /// 0139 /// \param relative True to set the position relative, false to set it absolute 0140 /// 0141 /// \see isRelativeToListener 0142 /// 0143 //////////////////////////////////////////////////////////// 0144 void setRelativeToListener(bool relative); 0145 0146 //////////////////////////////////////////////////////////// 0147 /// \brief Set the minimum distance of the sound 0148 /// 0149 /// The "minimum distance" of a sound is the maximum 0150 /// distance at which it is heard at its maximum volume. Further 0151 /// than the minimum distance, it will start to fade out according 0152 /// to its attenuation factor. A value of 0 ("inside the head 0153 /// of the listener") is an invalid value and is forbidden. 0154 /// The default value of the minimum distance is 1. 0155 /// 0156 /// \param distance New minimum distance of the sound 0157 /// 0158 /// \see getMinDistance, setAttenuation 0159 /// 0160 //////////////////////////////////////////////////////////// 0161 void setMinDistance(float distance); 0162 0163 //////////////////////////////////////////////////////////// 0164 /// \brief Set the attenuation factor of the sound 0165 /// 0166 /// The attenuation is a multiplicative factor which makes 0167 /// the sound more or less loud according to its distance 0168 /// from the listener. An attenuation of 0 will produce a 0169 /// non-attenuated sound, i.e. its volume will always be the same 0170 /// whether it is heard from near or from far. On the other hand, 0171 /// an attenuation value such as 100 will make the sound fade out 0172 /// very quickly as it gets further from the listener. 0173 /// The default value of the attenuation is 1. 0174 /// 0175 /// \param attenuation New attenuation factor of the sound 0176 /// 0177 /// \see getAttenuation, setMinDistance 0178 /// 0179 //////////////////////////////////////////////////////////// 0180 void setAttenuation(float attenuation); 0181 0182 //////////////////////////////////////////////////////////// 0183 /// \brief Get the pitch of the sound 0184 /// 0185 /// \return Pitch of the sound 0186 /// 0187 /// \see setPitch 0188 /// 0189 //////////////////////////////////////////////////////////// 0190 float getPitch() const; 0191 0192 //////////////////////////////////////////////////////////// 0193 /// \brief Get the volume of the sound 0194 /// 0195 /// \return Volume of the sound, in the range [0, 100] 0196 /// 0197 /// \see setVolume 0198 /// 0199 //////////////////////////////////////////////////////////// 0200 float getVolume() const; 0201 0202 //////////////////////////////////////////////////////////// 0203 /// \brief Get the 3D position of the sound in the audio scene 0204 /// 0205 /// \return Position of the sound 0206 /// 0207 /// \see setPosition 0208 /// 0209 //////////////////////////////////////////////////////////// 0210 Vector3f getPosition() const; 0211 0212 //////////////////////////////////////////////////////////// 0213 /// \brief Tell whether the sound's position is relative to the 0214 /// listener or is absolute 0215 /// 0216 /// \return True if the position is relative, false if it's absolute 0217 /// 0218 /// \see setRelativeToListener 0219 /// 0220 //////////////////////////////////////////////////////////// 0221 bool isRelativeToListener() const; 0222 0223 //////////////////////////////////////////////////////////// 0224 /// \brief Get the minimum distance of the sound 0225 /// 0226 /// \return Minimum distance of the sound 0227 /// 0228 /// \see setMinDistance, getAttenuation 0229 /// 0230 //////////////////////////////////////////////////////////// 0231 float getMinDistance() const; 0232 0233 //////////////////////////////////////////////////////////// 0234 /// \brief Get the attenuation factor of the sound 0235 /// 0236 /// \return Attenuation factor of the sound 0237 /// 0238 /// \see setAttenuation, getMinDistance 0239 /// 0240 //////////////////////////////////////////////////////////// 0241 float getAttenuation() const; 0242 0243 //////////////////////////////////////////////////////////// 0244 /// \brief Overload of assignment operator 0245 /// 0246 /// \param right Instance to assign 0247 /// 0248 /// \return Reference to self 0249 /// 0250 //////////////////////////////////////////////////////////// 0251 SoundSource& operator =(const SoundSource& right); 0252 0253 //////////////////////////////////////////////////////////// 0254 /// \brief Start or resume playing the sound source 0255 /// 0256 /// This function starts the source if it was stopped, resumes 0257 /// it if it was paused, and restarts it from the beginning if 0258 /// it was already playing. 0259 /// 0260 /// \see pause, stop 0261 /// 0262 //////////////////////////////////////////////////////////// 0263 virtual void play() = 0; 0264 0265 //////////////////////////////////////////////////////////// 0266 /// \brief Pause the sound source 0267 /// 0268 /// This function pauses the source if it was playing, 0269 /// otherwise (source already paused or stopped) it has no effect. 0270 /// 0271 /// \see play, stop 0272 /// 0273 //////////////////////////////////////////////////////////// 0274 virtual void pause() = 0; 0275 0276 //////////////////////////////////////////////////////////// 0277 /// \brief Stop playing the sound source 0278 /// 0279 /// This function stops the source if it was playing or paused, 0280 /// and does nothing if it was already stopped. 0281 /// It also resets the playing position (unlike pause()). 0282 /// 0283 /// \see play, pause 0284 /// 0285 //////////////////////////////////////////////////////////// 0286 virtual void stop() = 0; 0287 0288 //////////////////////////////////////////////////////////// 0289 /// \brief Get the current status of the sound (stopped, paused, playing) 0290 /// 0291 /// \return Current status of the sound 0292 /// 0293 //////////////////////////////////////////////////////////// 0294 virtual Status getStatus() const; 0295 0296 protected: 0297 0298 //////////////////////////////////////////////////////////// 0299 /// \brief Default constructor 0300 /// 0301 /// This constructor is meant to be called by derived classes only. 0302 /// 0303 //////////////////////////////////////////////////////////// 0304 SoundSource(); 0305 0306 //////////////////////////////////////////////////////////// 0307 // Member data 0308 //////////////////////////////////////////////////////////// 0309 unsigned int m_source; //!< OpenAL source identifier 0310 }; 0311 0312 } // namespace sf 0313 0314 0315 #endif // SFML_SOUNDSOURCE_HPP 0316 0317 0318 //////////////////////////////////////////////////////////// 0319 /// \class sf::SoundSource 0320 /// \ingroup audio 0321 /// 0322 /// sf::SoundSource is not meant to be used directly, it 0323 /// only serves as a common base for all audio objects 0324 /// that can live in the audio environment. 0325 /// 0326 /// It defines several properties for the sound: pitch, 0327 /// volume, position, attenuation, etc. All of them can be 0328 /// changed at any time with no impact on performances. 0329 /// 0330 /// \see sf::Sound, sf::SoundStream 0331 /// 0332 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|