-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSound.h
111 lines (82 loc) · 1.78 KB
/
Sound.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
#ifndef __SOUND__
#define __SOUND__
#include "PreHeader.h"
struct WaveHeaderType
{
char chunkId[4];
unsigned long chunkSize;
char format[4];
char subChunkId[4];
unsigned long subChunkSize;
unsigned short audioFormat;
unsigned short numChannels;
unsigned long sampleRate;
unsigned long bytesPerSecond;
unsigned short blockAlign;
unsigned short bitsPerSample;
char dataChunkId[4];
unsigned long dataSize;
};
class SoundMgr
{
public:
//单例
static SoundMgr* GetInstance();
~SoundMgr();
//初始化DirectSound设备和primaryBuffer
BOOL Init(HWND);
//销毁设备
void Shutdown();
//获得声卡设备,释放DirectSound设备和primaryBuffer
IDirectSound8 * GetDevice();
private:
SoundMgr();
SoundMgr(const SoundMgr&){};
private:
IDirectSound8* device;
IDirectSoundBuffer* primaryBuffer;
};
class Sound
{
private:
string fileName;
DWORD playPos;
IDirectSoundBuffer8* soundData;
public:
Sound();
~Sound();
//载入声音文件
BOOL LoadFile(const string);
//播放音频文件
void Play();
//暂停
void Pause();
//停止
void Stop();
//是否正在播放
BOOL IsPlaying();
//释放soundData
void Release();
};
class SoundBatch
{
private:
map<string, IDirectSoundBuffer8*> name2SoundTable;
public:
~SoundBatch();
//单例
static SoundBatch* GetInstance();
//加载wav格式音频文件
IDirectSoundBuffer8* LoadSound(const string &);
//按名取得wav格式音频文件
IDirectSoundBuffer8* GetSoundByName(const string &);
//清空
void Clear();
private:
SoundBatch(){};
SoundBatch(const SoundBatch &){};
SoundBatch & operator = (const SoundBatch &){};
//判断载入的文件格式是否合法
BOOL IsLegal(const WaveHeaderType &);
};
#endif