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-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
38namespace sf
39{
40namespace priv
41{
42 class SoundFile;
43}
44
45class Sound;
46class InputStream;
47
53{
54public:
55
61
69
75
90 bool loadFromFile(const std::string& filename);
91
107 bool loadFromMemory(const void* data, std::size_t sizeInBytes);
108
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
222
231 SoundBuffer& operator =(const SoundBuffer& right);
232
233private:
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
#define SFML_AUDIO_API
Abstract class for custom file input streams.
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.
std::size_t getSampleCount() const
Get the number of samples stored in the buffer.
const Int16 * getSamples() const
Get the array of audio samples stored in the buffer.
friend class Sound
bool loadFromSamples(const Int16 *samples, std::size_t 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.
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
signed short Int16
Definition Config.hpp:174