Documentation de SFML 2.6.1

Loading...
Searching...
No Matches
SoundBuffer.hpp
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
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
39namespace sf
40{
41class Sound;
42class InputSoundFile;
43class InputStream;
44
49class SFML_AUDIO_API SoundBuffer : AlResource
50{
51public:
52
58
66
72
86 bool loadFromFile(const std::string& filename);
87
102 bool loadFromMemory(const void* data, std::size_t sizeInBytes);
103
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
215
224 SoundBuffer& operator =(const SoundBuffer& right);
225
226private:
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
Base class for classes that require an OpenAL context.
Provide read access to sound files.
Abstract class for custom file input streams.
Storage for audio samples defining a sound.
SoundBuffer()
Default constructor.
unsigned int getChannelCount() const
Get the number of channels used by the sound.
Time getDuration() const
Get the total duration of the sound.
bool loadFromFile(const std::string &filename)
Load the sound buffer from a file.
unsigned int getSampleRate() const
Get the sample rate of the sound.
const Int16 * getSamples() const
Get the array of audio samples stored in the buffer.
bool loadFromSamples(const Int16 *samples, Uint64 sampleCount, unsigned int channelCount, unsigned int sampleRate)
Load the sound buffer from an array of audio samples.
bool saveToFile(const std::string &filename) const
Save the sound buffer to an audio file.
SoundBuffer(const SoundBuffer &copy)
Copy constructor.
bool loadFromStream(InputStream &stream)
Load the sound buffer from a custom stream.
~SoundBuffer()
Destructor.
Uint64 getSampleCount() const
Get the number of samples stored in the buffer.
bool loadFromMemory(const void *data, std::size_t sizeInBytes)
Load the sound buffer from a file in memory.
Regular sound that can be played in the audio environment.
Definition Sound.hpp:46
Represents a time value.
Definition Time.hpp:41