Music.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2015 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 CPP3DS_MUSIC_HPP
26 #define CPP3DS_MUSIC_HPP
27 
29 // Headers
31 #include <cpp3ds/Audio/SoundStream.hpp>
32 #include <cpp3ds/Audio/InputSoundFile.hpp>
33 #include <cpp3ds/System/Mutex.hpp>
34 #include <cpp3ds/System/Time.hpp>
35 #include <string>
36 #include <vector>
37 
38 
39 namespace cpp3ds
40 {
41 class InputStream;
42 
47 class Music : public SoundStream
48 {
49 public:
50 
55  Music();
56 
61  ~Music();
62 
78  bool openFromFile(const std::string& filename);
79 
100  bool openFromMemory(const void* data, std::size_t sizeInBytes);
101 
121  bool openFromStream(InputStream& stream);
122 
129  Time getDuration() const;
130 
131 protected:
132 
144  virtual bool onGetData(Chunk& data);
145 
152  virtual void onSeek(Time timeOffset);
153 
154 private:
155 
160  void initialize();
161 
163  // Member data
165  InputSoundFile m_file;
166  Time m_duration;
167  std::vector<Int16> m_samples;
168  Mutex m_mutex;
169 };
170 
171 } // namespace cpp3ds
172 
173 
174 #endif // CPP3DS_MUSIC_HPP
175 
176 
Streamed music played from an audio file.
Definition: Music.hpp:47
Abstract class for custom file input streams.
Definition: InputStream.hpp:40
Abstract base class for streamed audio sources.
Definition: SoundStream.hpp:48
Represents a time value.
Definition: Time.hpp:37
Music()
Default constructor.
~Music()
Destructor.
bool openFromStream(InputStream &stream)
Open a music from an audio file in a custom stream.
virtual void onSeek(Time timeOffset)
Change the current playing position in the stream source.
Provide read access to sound files.
Blocks concurrent access to shared resources from multiple threads.
Definition: Mutex.hpp:44
bool openFromFile(const std::string &filename)
Open a music from an audio file.
Structure defining a chunk of audio data to stream.
Definition: SoundStream.hpp:56
virtual bool onGetData(Chunk &data)
Request a new chunk of audio samples from the stream source.
bool openFromMemory(const void *data, std::size_t sizeInBytes)
Open a music from an audio file in memory.
Time getDuration() const
Get the total duration of the music.