SoundFileDefault.hpp
1
2//
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_SOUNDFILEDEFAULT_HPP
26#define SFML_SOUNDFILEDEFAULT_HPP
27
29// Headers
31#include <SFML/Audio/SoundFile.hpp>
32#include <sndfile.h>
33
34
35namespace sf
36{
37namespace priv
38{
43class SoundFileDefault : public SoundFile
44{
45public :
46
51 SoundFileDefault();
52
57 ~SoundFileDefault();
58
68 static bool IsFileSupported(const std::string& Filename, bool Read);
69
79 static bool IsFileSupported(const char* Data, std::size_t SizeInBytes);
80
85 virtual std::size_t Read(Int16* Data, std::size_t NbSamples);
86
91 virtual void Write(const Int16* Data, std::size_t NbSamples);
92
93private :
94
99 virtual bool OpenRead(const std::string& Filename, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
100
105 virtual bool OpenRead(const char* Data, std::size_t SizeInBytes, std::size_t& NbSamples, unsigned int& ChannelsCount, unsigned int& SampleRate);
106
111 virtual bool OpenWrite(const std::string& Filename, unsigned int ChannelsCount, unsigned int SampleRate);
112
122 static int GetFormatFromFilename(const std::string& Filename);
123
128 static sf_count_t MemoryGetLength(void* UserData);
129 static sf_count_t MemoryRead(void* Ptr, sf_count_t Count, void* UserData);
130 static sf_count_t MemorySeek(sf_count_t Offset, int Whence, void* UserData);
131 static sf_count_t MemoryTell(void* UserData);
132 static sf_count_t MemoryWrite(const void* Ptr, sf_count_t Count, void* UserData);
133
137 struct MemoryInfos
138 {
139 const char* DataStart;
140 const char* DataPtr;
141 sf_count_t TotalSize;
142 };
143
145 // Member data
147 SNDFILE* myFile;
148 MemoryInfos myMemory;
149};
150
151} // namespace priv
152
153} // namespace sf
154
155
156#endif // SFML_SOUNDFILEDEFAULT_HPP