Documentation of SFML 2.2

Warning: this page refers to an old version of SFML. Click here to switch to the latest version.
SoundBuffer.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2014 Laurent Gomila (laurent.gom@gmail.com)
5 //
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.
8 //
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:
12 //
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.
17 //
18 // 2. Altered source versions must be plainly marked as such,
19 // and must not be misrepresented as being the original software.
20 //
21 // 3. This notice may not be removed or altered from any source distribution.
22 //
24 
25 #ifndef SFML_SOUNDBUFFER_HPP
26 #define SFML_SOUNDBUFFER_HPP
27 
29 // Headers
31 #include <SFML/Audio/Export.hpp>
32 #include <SFML/System/Time.hpp>
33 #include <string>
34 #include <vector>
35 #include <set>
36 
37 
38 namespace sf
39 {
40 namespace priv
41 {
42  class SoundFile;
43 }
44 
45 class Sound;
46 class InputStream;
47 
52 class SFML_AUDIO_API SoundBuffer
53 {
54 public:
55 
60  SoundBuffer();
61 
68  SoundBuffer(const SoundBuffer& copy);
69 
74  ~SoundBuffer();
75 
90  bool loadFromFile(const std::string& filename);
91 
107  bool loadFromMemory(const void* data, std::size_t sizeInBytes);
108 
123  bool loadFromStream(InputStream& stream);
124 
141  bool loadFromSamples(const Int16* samples, std::size_t sampleCount, unsigned int channelCount, unsigned int sampleRate);
142 
157  bool saveToFile(const std::string& filename) const;
158 
171  const Int16* getSamples() const;
172 
184  std::size_t getSampleCount() const;
185 
198  unsigned int getSampleRate() const;
199 
211  unsigned int getChannelCount() const;
212 
221  Time getDuration() const;
222 
231  SoundBuffer& operator =(const SoundBuffer& right);
232 
233 private:
234 
235  friend class Sound;
236 
245  bool initialize(priv::SoundFile& file);
246 
256  bool update(unsigned int channelCount, unsigned int sampleRate);
257 
264  void attachSound(Sound* sound) const;
265 
272  void detachSound(Sound* sound) const;
273 
275  // Types
277  typedef std::set<Sound*> SoundList;
278 
280  // Member data
282  unsigned int m_buffer;
283  std::vector<Int16> m_samples;
284  Time m_duration;
285  mutable SoundList m_sounds;
286 };
287 
288 } // namespace sf
289 
290 
291 #endif // SFML_SOUNDBUFFER_HPP
292 
293 
Abstract class for custom file input streams.
Definition: InputStream.hpp:40
Definition: Listener.hpp:35
Represents a time value.
Definition: Time.hpp:40
Storage for audio samples defining a sound.
Definition: SoundBuffer.hpp:52
Regular sound that can be played in the audio environment.
Definition: Sound.hpp:45