/
WaveFile.h
49 lines (46 loc) · 1.33 KB
/
WaveFile.h
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
#ifndef _WAVEFILE_H_
#define _WAVEFILE_H_
#include "sndfile.h"
#ifdef WIN32
#ifdef USE_XAUDIO
#include <audiodefs.h>
#include <xaudio2.h>
#endif
#endif
/**
* Represents a wave file. Used for loading wave data from disk.
*/
class WaveFile
{
public:
bool Load( const char* filename );
bool Save( const char* filename );
WaveFile();
unsigned int GetSampleRate() { return _sampleRate; }
unsigned int GetBytesPerSample() { return _bitsPerSample / 8; }
unsigned short GetNumChannels() { return _numChannels; }
unsigned int GetNumSamples() { return _numSamples; }
unsigned short GetBitsPerSample() { return _bitsPerSample; }
unsigned short GetBlockAlign() { return _blockAlign; }
unsigned int GetDataLength() { return _dataLength; }
short* GetData();
SF_INFO* GetSFInfo() { return &_sfinfo; }
short* GetChunk( unsigned int start, unsigned int end );
static WaveFile* Load(const char* filename, bool allowNull );
#ifdef WIN32
#ifdef USE_XAUDIO
WAVEFORMATEX* GetWaveFormatEx();
XAUDIO2_BUFFER* GetXAudio2Buffer();
#endif
#endif
private:
SF_INFO _sfinfo;
SNDFILE* _soundFile;
unsigned int _dataLength;
unsigned int _sampleRate;
unsigned int _numSamples;
unsigned short _numChannels;
unsigned short _bitsPerSample;
unsigned short _blockAlign;
};
#endif