aboutsummaryrefslogtreecommitdiff
path: root/examples/simpletest/WaveFile.h
blob: b684b417a6fb8fddeafa030b55c3648ac8023843 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef WaveFile_h__
#define WaveFile_h__

#include <string>

///\note All meta data is undefined if IsLoaded() == false
class WaveFile
{
public:
	enum AudioFormat
	{
		PCM = 1,
        WAVE_FORMAT_IEEE_FLOAT = 3
	};

	WaveFile();
	WaveFile(const std::string &filename);
	~WaveFile();

	bool Load(const std::string &filename);
	void Unload();

	inline bool IsLoaded() const
	{
		return (data != nullptr && size != 0);
	}

	inline AudioFormat GetAudioFormat() const
	{
		return meta.audioFormat;
	}
	inline unsigned int GetNumChannels() const
	{
		return meta.numChannels;
	}
	inline unsigned int GetSampleRate() const
	{
		return meta.sampleRate;
	}
	inline unsigned int GetBitsPerSample() const
	{
		return meta.bitsPerSample;
	}

	inline const char *GetData() const
	{
		return data;
	}
	inline std::size_t GetDataSize() const
	{
		return size;
	}

private:
	struct Meta
	{
		AudioFormat audioFormat;
		unsigned int numChannels;
		unsigned int sampleRate;
		unsigned int bitsPerSample;
	} meta;
	char *data;
	std::size_t size;
};

#endif // WaveFile_h__