SFML 2.6.2

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

Loading...
Searching...
No Matches
SoundBuffer.hpp
Go to the documentation of this file.
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
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
AlResource.hpp
Export.hpp
SFML_AUDIO_API
#define SFML_AUDIO_API
Definition Audio/Export.hpp:43
Time.hpp
sf::AlResource
Base class for classes that require an OpenAL context.
Definition AlResource.hpp:41
sf::InputSoundFile
Provide read access to sound files.
Definition InputSoundFile.hpp:48
sf::InputStream
Abstract class for custom file input streams.
Definition InputStream.hpp:42
sf::SoundBuffer
Storage for audio samples defining a sound.
Definition SoundBuffer.hpp:50
sf::SoundBuffer::SoundBuffer
SoundBuffer()
Default constructor.
sf::SoundBuffer::getChannelCount
unsigned int getChannelCount() const
Get the number of channels used by the sound.
sf::SoundBuffer::getDuration
Time getDuration() const
Get the total duration of the sound.
sf::SoundBuffer::loadFromFile
bool loadFromFile(const std::string &filename)
Load the sound buffer from a file.
sf::SoundBuffer::getSampleRate
unsigned int getSampleRate() const
Get the sample rate of the sound.
sf::SoundBuffer::getSamples
const Int16 * getSamples() const
Get the array of audio samples stored in the buffer.
sf::SoundBuffer::loadFromSamples
bool loadFromSamples(const Int16 *samples, Uint64 sampleCount, unsigned int channelCount, unsigned int sampleRate)
Load the sound buffer from an array of audio samples.
sf::SoundBuffer::saveToFile
bool saveToFile(const std::string &filename) const
Save the sound buffer to an audio file.
sf::SoundBuffer::SoundBuffer
SoundBuffer(const SoundBuffer &copy)
Copy constructor.
sf::SoundBuffer::loadFromStream
bool loadFromStream(InputStream &stream)
Load the sound buffer from a custom stream.
sf::SoundBuffer::~SoundBuffer
~SoundBuffer()
Destructor.
sf::SoundBuffer::getSampleCount
Uint64 getSampleCount() const
Get the number of samples stored in the buffer.
sf::SoundBuffer::loadFromMemory
bool loadFromMemory(const void *data, std::size_t sizeInBytes)
Load the sound buffer from a file in memory.
sf::Sound
Regular sound that can be played in the audio environment.
Definition Sound.hpp:46
sf::Time
Represents a time value.
Definition Time.hpp:41
sf
Definition AlResource.hpp:35
sf::Int16
signed short Int16
Definition Config.hpp:222
sf::Uint64
unsigned long long Uint64
Definition Config.hpp:239