SFML - Simple and Fast Multimedia Library

SMFL 2.3.2

SoundBuffer.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2015 Laurent Gomila ([email protected])
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/Audio/AlResource.hpp>
33 #include <SFML/System/Time.hpp>
34 #include <string>
35 #include <vector>
36 #include <set>
37 
38 
39 namespace sf
40 {
41 class Sound;
42 class InputSoundFile;
43 class InputStream;
44 
49 class SFML_AUDIO_API SoundBuffer : AlResource
50 {
51 public:
52 
57  SoundBuffer();
58 
65  SoundBuffer(const SoundBuffer& copy);
66 
71  ~SoundBuffer();
72 
86  bool loadFromFile(const std::string& filename);
87 
102  bool loadFromMemory(const void* data, std::size_t sizeInBytes);
103 
117  bool loadFromStream(InputStream& stream);
118 
135  bool loadFromSamples(const Int16* samples, Uint64 sampleCount, unsigned int channelCount, unsigned int sampleRate);
136 
150  bool saveToFile(const std::string& filename) const;
151 
164  const Int16* getSamples() const;
165 
177  Uint64 getSampleCount() const;
178 
191  unsigned int getSampleRate() const;
192 
204  unsigned int getChannelCount() const;
205 
214  Time getDuration() const;
215 
224  SoundBuffer& operator =(const SoundBuffer& right);
225 
226 private:
227 
228  friend class Sound;
229 
238  bool initialize(InputSoundFile& file);
239 
249  bool update(unsigned int channelCount, unsigned int sampleRate);
250 
257  void attachSound(Sound* sound) const;
258 
265  void detachSound(Sound* sound) const;
266 
268  // Types
270  typedef std::set<Sound*> SoundList;
271 
273  // Member data
275  unsigned int m_buffer;
276  std::vector<Int16> m_samples;
277  Time m_duration;
278  mutable SoundList m_sounds;
279 };
280 
281 } // namespace sf
282 
283 
284 #endif // SFML_SOUNDBUFFER_HPP
285 
286 
Abstract class for custom file input streams.
Definition: InputStream.hpp:41
Base class for classes that require an OpenAL context.
Definition: AlResource.hpp:40
Represents a time value.
Definition: Time.hpp:40
Provide read access to sound files.
Regular sound that can be played in the audio environment.
Definition: Sound.hpp:45
Storage for audio samples defining a sound.
Definition: SoundBuffer.hpp:49