InputSoundFile.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_INPUTSOUNDFILE_HPP
26 #define CPP3DS_INPUTSOUNDFILE_HPP
27 
29 // Headers
31 #include <cpp3ds/System/NonCopyable.hpp>
32 #include <cpp3ds/System/Time.hpp>
33 #include <string>
34 
35 
36 namespace cpp3ds
37 {
38 class InputStream;
39 class SoundFileReader;
40 
46 {
47 public:
48 
54 
60 
71  bool openFromFile(const std::string& filename);
72 
84  bool openFromMemory(const void* data, std::size_t sizeInBytes);
85 
96  bool openFromStream(InputStream& stream);
97 
108  bool openForWriting(const std::string& filename, unsigned int channelCount, unsigned int sampleRate);
109 
116  Uint64 getSampleCount() const;
117 
124  unsigned int getChannelCount() const;
125 
132  unsigned int getSampleRate() const;
133 
143  Time getDuration() const;
144 
158  void seek(Uint64 sampleOffset);
159 
172  void seek(Time timeOffset);
173 
183  Uint64 read(Int16* samples, Uint64 maxCount);
184 
185 private:
186 
191  void close();
192 
194  // Member data
196  SoundFileReader* m_reader;
197  InputStream* m_stream;
198  bool m_streamOwned;
199  Uint64 m_sampleCount;
200  unsigned int m_channelCount;
201  unsigned int m_sampleRate;
202 };
203 
204 } // namespace cpp3ds
205 
206 
207 #endif // CPP3DS_INPUTSOUNDFILE_HPP
208 
209 
Abstract class for custom file input streams.
Definition: InputStream.hpp:40
Time getDuration() const
Get the total duration of the sound file.
Uint64 read(Int16 *samples, Uint64 maxCount)
Read audio samples from the open file.
Uint64 getSampleCount() const
Get the total number of audio samples in the file.
bool openFromFile(const std::string &filename)
Open a sound file from the disk for reading.
Represents a time value.
Definition: Time.hpp:37
unsigned int getChannelCount() const
Get the number of channels used by the sound.
bool openFromMemory(const void *data, std::size_t sizeInBytes)
Open a sound file in memory for reading.
unsigned int getSampleRate() const
Get the sample rate of the sound.
Provide read access to sound files.
Utility class that makes any derived class non-copyable.
Definition: NonCopyable.hpp:35
~InputSoundFile()
Destructor.
void seek(Uint64 sampleOffset)
Change the current read position to the given sample offset.
bool openForWriting(const std::string &filename, unsigned int channelCount, unsigned int sampleRate)
Open the sound file from the disk for writing.
bool openFromStream(InputStream &stream)
Open a sound file from a custom stream for reading.
InputSoundFile()
Default constructor.
Abstract base class for sound file decoding.