Documentation de SFML 1.6

Attention: cette page se réfère à une ancienne version de SFML. Cliquez ici pour passer à la dernière version.
SoundBuffer.hpp
1 
2 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2009 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/System/Resource.hpp>
32 #include <SFML/Audio/AudioResource.hpp>
33 #include <string>
34 #include <vector>
35 #include <set>
36 
37 
38 namespace sf
39 {
40 class Sound;
41 
46 class SFML_API SoundBuffer : public AudioResource, public Resource<SoundBuffer>
47 {
48 public :
49 
54  SoundBuffer();
55 
62  SoundBuffer(const SoundBuffer& Copy);
63 
68  ~SoundBuffer();
69 
78  bool LoadFromFile(const std::string& Filename);
79 
89  bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);
90 
103  bool LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate);
104 
113  bool SaveToFile(const std::string& Filename) const;
114 
121  const Int16* GetSamples() const;
122 
129  std::size_t GetSamplesCount() const;
130 
137  unsigned int GetSampleRate() const;
138 
145  unsigned int GetChannelsCount() const;
146 
153  float GetDuration() const;
154 
163  SoundBuffer& operator =(const SoundBuffer& Other);
164 
165 private :
166 
167  friend class Sound;
168 
178  bool Update(unsigned int ChannelsCount, unsigned int SampleRate);
179 
186  void AttachSound(Sound* Instance) const;
187 
194  void DetachSound(Sound* Instance) const;
195 
197  // Types
199  typedef std::set<Sound*> SoundList;
200 
202  // Member data
204  unsigned int myBuffer;
205  std::vector<Int16> mySamples;
206  float myDuration;
207  mutable SoundList mySounds;
208 };
209 
210 } // namespace sf
211 
212 
213 #endif // SFML_SOUNDBUFFER_HPP