-
Notifications
You must be signed in to change notification settings - Fork 0
/
CWaves.h
113 lines (98 loc) · 3.42 KB
/
CWaves.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Waves.h: interface for the CWaves class.
//
//////////////////////////////////////////////////////////////////////
#ifndef _CWAVES_H_
#define _CWAVES_H_
#include <windows.h>
#include <stdio.h>
#define MAX_NUM_WAVEID 1024
enum WAVEFILETYPE
{
WF_EX = 1,
WF_EXT = 2
};
enum WAVERESULT
{
WR_OK = 0,
WR_INVALIDFILENAME = - 1,
WR_BADWAVEFILE = - 2,
WR_INVALIDPARAM = - 3,
WR_INVALIDWAVEID = - 4,
WR_NOTSUPPORTEDYET = - 5,
WR_WAVEMUSTBEMONO = - 6,
WR_WAVEMUSTBEWAVEFORMATPCM = - 7,
WR_WAVESMUSTHAVESAMEBITRESOLUTION = - 8,
WR_WAVESMUSTHAVESAMEFREQUENCY = - 9,
WR_WAVESMUSTHAVESAMEBITRATE = -10,
WR_WAVESMUSTHAVESAMEBLOCKALIGNMENT = -11,
WR_OFFSETOUTOFDATARANGE = -12,
WR_FILEERROR = -13,
WR_OUTOFMEMORY = -14,
WR_INVALIDSPEAKERPOS = -15,
WR_INVALIDWAVEFILETYPE = -16,
WR_NOTWAVEFORMATEXTENSIBLEFORMAT = -17
};
#ifndef _WAVEFORMATEX_
#define _WAVEFORMATEX_
typedef struct tWAVEFORMATEX
{
WORD wFormatTag;
WORD nChannels;
DWORD nSamplesPerSec;
DWORD nAvgBytesPerSec;
WORD nBlockAlign;
WORD wBitsPerSample;
WORD cbSize;
} WAVEFORMATEX;
#endif /* _WAVEFORMATEX_ */
#ifndef _WAVEFORMATEXTENSIBLE_
#define _WAVEFORMATEXTENSIBLE_
typedef struct {
WAVEFORMATEX Format;
union {
WORD wValidBitsPerSample; /* bits of precision */
WORD wSamplesPerBlock; /* valid if wBitsPerSample==0 */
WORD wReserved; /* If neither applies, set to zero. */
} Samples;
DWORD dwChannelMask; /* which channels are */
/* present in stream */
GUID SubFormat;
} WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE;
#endif // !_WAVEFORMATEXTENSIBLE_
typedef struct
{
WAVEFILETYPE wfType;
WAVEFORMATEXTENSIBLE wfEXT; // For non-WAVEFORMATEXTENSIBLE wavefiles, the header is stored in the Format member of wfEXT
char *pData;
unsigned long ulDataSize;
FILE *pFile;
unsigned long ulDataOffset;
} WAVEFILEINFO, *LPWAVEFILEINFO;
typedef int (__cdecl *PFNALGETENUMVALUE)( const char *szEnumName );
typedef int WAVEID;
class CWaves
{
public:
CWaves();
virtual ~CWaves();
WAVERESULT LoadWaveFile(const char *szFilename, WAVEID *WaveID);
WAVERESULT OpenWaveFile(const char *szFilename, WAVEID *WaveID);
WAVERESULT ReadWaveData(WAVEID WaveID, void *pData, unsigned long ulDataSize, unsigned long *pulBytesWritten);
WAVERESULT SetWaveDataOffset(WAVEID WaveID, unsigned long ulOffset);
WAVERESULT GetWaveDataOffset(WAVEID WaveID, unsigned long *pulOffset);
WAVERESULT GetWaveType(WAVEID WaveID, WAVEFILETYPE *pwfType);
WAVERESULT GetWaveFormatExHeader(WAVEID WaveID, WAVEFORMATEX *pWFEX);
WAVERESULT GetWaveFormatExtensibleHeader(WAVEID WaveID, WAVEFORMATEXTENSIBLE *pWFEXT);
WAVERESULT GetWaveData(WAVEID WaveID, void **ppAudioData);
WAVERESULT GetWaveSize(WAVEID WaveID, unsigned long *pulDataSize);
WAVERESULT GetWaveFrequency(WAVEID WaveID, unsigned long *pulFrequency);
WAVERESULT GetWaveALBufferFormat(WAVEID WaveID, PFNALGETENUMVALUE pfnGetEnumValue, unsigned long *pulFormat);
WAVERESULT DeleteWaveFile(WAVEID WaveID);
char *GetErrorString(WAVERESULT wr, char *szErrorString, unsigned long nSizeOfErrorString);
bool IsWaveID(WAVEID WaveID);
private:
WAVERESULT ParseFile(const char *szFilename, LPWAVEFILEINFO pWaveInfo);
WAVEID InsertWaveID(LPWAVEFILEINFO pWaveFileInfo);
LPWAVEFILEINFO m_WaveIDs[MAX_NUM_WAVEID];
};
#endif // _CWAVES_H_