SoundFile.hpp
1 //
3 // SFML - Simple and Fast Multimedia Library
4 // Copyright (C) 2007-2009 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_SOUNDFILE_HPP
26 #define SFML_SOUNDFILE_HPP
27 
29 // Headers
31 #include <SFML/System/NonCopyable.hpp>
32 #include <string>
33 
34 
35 namespace sf
36 {
37 namespace priv
38 {
43 class SoundFile : NonCopyable
44 {
45 public :
46 
58  static SoundFile* CreateRead(const std::string& Filename);
59 
72  static SoundFile* CreateRead(const char* Data, std::size_t SizeInBytes);
73 
84  static SoundFile* CreateWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
85 
90  virtual ~SoundFile();
91 
98  std::size_t GetSamplesCount() const;
99 
106  unsigned int GetChannelsCount() const;
107 
114  unsigned int GetSampleRate() const;
115 
122  bool Restart();
123 
133  virtual std::size_t Read(Int16* Data, std::size_t NbSamples);
134 
142  virtual void Write(const Int16* Data, std::size_t NbSamples);
143 
144 protected :
145 
150  SoundFile();
151 
152 private :
153 
165  virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
166 
179  virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
180 
191  virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
192 
194  // Member data
196  std::size_t myNbSamples;
197  unsigned int myChannelsCount;
198  unsigned int mySampleRate;
199  std::string myFilename;
200  const char* myData;
201  std::size_t mySize;
202 };
203 
204 } // namespace priv
205 
206 } // namespace sf
207 
208 
209 #endif // SFML_SOUNDFILE_HPP