-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSoundManager.cpp
284 lines (253 loc) · 7.42 KB
/
SoundManager.cpp
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#include"main.h"
SoundManager* SoundManager::manager = nullptr;
void SoundManager::CreateSoundManager()
{
//オブジェクトが作成されていないならオブジェクトを作成する
if (manager == nullptr)
{
manager = new SoundManager();
}
//BGMの設定
SetBGM("bgm_title");
SetBGM("bgm_map");
SetBGM("bgm_weaponselection");
SetBGM("bgm_normal");
SetBGM("bgm_middleboss");
SetBGM("bgm_middleboss_end");
SetBGM("bgm_boss");
SetBGM("bgm_smith");
SetBGM("bgm_breakstage");
SetBGM("bgm_breaktime");
SetBGM("bgm_gameover");
SetBGM("bgm_gameclear");
//SEの設定
SetSE("se_system_Title_decision_sound"); //タイトルのカーソル決定音
SetSE("se_system_normal_decision"); //タイトル以外のカーソル決定音
SetSE("se_system_select_syu"); //カーソル移動音
SetSE("se_system_healing"); //回復の音
SetSE("se_system_blessing"); //祝福の音
SetSE("se_system_hammer");
SetSE("se_system_cancel");
SetSE("se_system_ng");
SetSE("se_player_move");
SetSE("se_player_avoidance");
SetSE("se_enemy_damage");
SetSE("se_enemy_shout");
SetSE("se_enemy_tackle");
SetSE("se_enemy_barrier_damage");
SetSE("se_enemy_barrier_open");
SetSE("se_enemy_barrier_close");
SetSE("se_enemy_spirit");
SetSE("se_enemy_teleportation");
SetSE("se_enemy_bossbullet");
SetSE("se_enemy_beam_charge");
SetSE("se_enemy_beam_fire");
SetSE("se_weapon_sword_swing");
SetSE("se_weapon_sword_Lv8");
SetSE("se_weapon_sword_Lv7");
SetSE("se_weapon_dagger_swing");
SetSE("se_weapon_dagger_Lv8");
SetSE("se_weapon_dagger_Lv7");
SetSE("se_weapon_greatsword_swing");
SetSE("se_weapon_greatsword_Lv8");
SetSE("se_weapon_spear_swing");
SetSE("se_weapon_spear_Lv8");
SetSE("se_weapon_frail_swig");
SetSE("se_weapon_frail_Lv8");
SetSE("se_weapon_frail");
SetSE("se_weapon_book_swing");
SetSE("se_weapon_book_Lv7");
SetSE("se_weapon_book_Lv8");
//音量の調整
SetVolumeBGMs(30);
SetVolumeSEs(65);
SetVolumeBGM("bgm_title", 35);
SetVolumeBGM("bgm_weaponselection", 45);
SetVolumeBGM("bgm_breakstage", 70);
SetVolumeBGM("bgm_normal", 30);
SetVolumeBGM("bgm_middleboss", 50);
SetVolumeBGM("bgm_boss", 55);
SetVolumeBGM("bgm_gameover", 60);
SetVolumeBGM("bgm_gameclear", 40);
SetVolumeSE("se_system_normal_decision", 70);
SetVolumeSE("se_system_ng", 50);
SetVolumeSE("se_system_cancel", 60);
SetVolumeSE("se_enemy_damage", 30);
SetVolumeSE("se_enemy_barrier_damage", 40);
SetVolumeSE("se_enemy_barrier_open", 50);
SetVolumeSE("se_enemy_spirit", 50);
SetVolumeSE("se_enemy_shout", 65);
SetVolumeSE("se_enemy_tackle", 65);
SetVolumeSE("se_enemy_bossbullet", 30);
SetVolumeSE("se_weapon_dagger_swing", 50);
SetVolumeSE("se_weapon_sword_swing", 50);
SetVolumeSE("se_weapon_greatsword_swing", 70);
//再生位置の調整
SetSoundSEPosition(10, "se_system_normal_decision");
//ループ位置の調整
SetLoopPosSoundMem(4798, GetBGMHandle("bgm_map"));
SetLoopPosSoundMem(56400, GetBGMHandle("bgm_weaponselection"));
SetLoopPosSoundMem(470, GetBGMHandle("bgm_normal"));
SetLoopPosSoundMem(45900, GetBGMHandle("bgm_middleboss"));
SetLoopPosSoundMem(22720, GetBGMHandle("bgm_boss"));
SetLoopPosSoundMem(5100, GetBGMHandle("bgm_smith"));
}
void SoundManager::DeleteSoundManager()
{
InitSoundMem();
delete manager;
manager = nullptr;
}
void SoundManager::SetBGM(const char* fileName)
{
//ローカル変数iteratorにfileNameキーの検索結果を代入
auto iterator = manager->bgm.find(string(fileName));
//設定されていない場合
if (iterator == manager->bgm.end())
{
//ファイルのパス
string filePath;
filePath = "resources/sounds/BGM/" + string(fileName) + ".wav";
//キーにBGMを読みこむ
manager->bgm[fileName] = LoadSoundMem(filePath.c_str());
}
}
void SoundManager::SetSE(const char* fileName)
{
//ローカル変数iteratorにfileNameキーの検索結果を代入
auto iterator = manager->se.find(string(fileName));
//設定されていない場合
if (iterator == manager->se.end())
{
//ファイルのパス
string filePath;
if (strstr(fileName, "se_system") != NULL)
{
filePath = "resources/sounds/SE/System/" + string(fileName) + ".wav";
}
else if (strstr(fileName, "se_enemy") != NULL)
{
filePath = "resources/sounds/SE/Enemy/" + string(fileName) + ".wav";
}
else if (strstr(fileName, "se_player") != NULL)
{
filePath = "resources/sounds/SE/Player/" + string(fileName) + ".wav";
}
else if (strstr(fileName, "se_weapon") != NULL)
{
filePath = "resources/sounds/SE/Weapon/" + string(fileName) + ".wav";
}
//キーにSEを読みこむ
manager->se[fileName] = LoadSoundMem(filePath.c_str());
}
}
void SoundManager::SetVolumeBGM(const char* fileName, const int volume)
{
ChangeVolumeSoundMem(255 * volume / 100, manager->bgm[fileName]);
}
void SoundManager::SetVolumeSE(const char* fileName, const int volume)
{
ChangeVolumeSoundMem(255 * volume / 100, manager->se[fileName]);
}
void SoundManager::SetVolumeBGMs(const int volume)
{
for (auto iterator = manager->bgm.begin(); iterator != manager->bgm.end(); ++iterator)
{
ChangeVolumeSoundMem(255 * volume / 100, manager->bgm[iterator->first]);
}
}
void SoundManager::SetVolumeSEs(const int volume)
{
for (auto iterator = manager->se.begin(); iterator != manager->se.end(); ++iterator)
{
ChangeVolumeSoundMem(255 * volume / 100, manager->se[iterator->first]);
}
}
void SoundManager::SetSoundBGMPosition(LONGLONG time, const char* fileName)
{
SetSoundCurrentTime(time, manager->bgm[fileName]);
}
void SoundManager::SetSoundBGMsPosition(LONGLONG time)
{
for (auto iterator = manager->bgm.begin(); iterator != manager->bgm.end(); ++iterator)
{
SetSoundCurrentTime(time, manager->bgm[iterator->first]);
}
}
void SoundManager::SetSoundSEPosition(LONGLONG time, const char* fileName)
{
SetSoundCurrentTime(time, manager->se[fileName]);
}
void SoundManager::SetSoundSEsPosition(LONGLONG time)
{
for (auto iterator = manager->se.begin(); iterator != manager->se.end(); ++iterator)
{
SetSoundCurrentTime(time, manager->se[iterator->first]);
}
}
void SoundManager::PlaySoundBGM(const char* fileName, bool isSingleUnit, int playType, int topPositionFlag)
{
//音を重ねないなら
if (isSingleUnit)
{
if (!CheckSoundMem(manager->bgm[fileName]))
{
//現在なっている音を止める
for (auto iterator = manager->bgm.begin(); iterator != manager->bgm.end(); ++iterator)
{
if (CheckSoundMem(manager->bgm[iterator->first]))
{
StopSoundMem(manager->bgm[iterator->first]);
SetSoundCurrentTime(0, manager->bgm[iterator->first]);
}
}
PlaySoundMem(manager->bgm[fileName], playType, topPositionFlag);
}
}
//音を重ねるなら
else
{
if (!CheckSoundMem(manager->bgm[fileName]))
{
PlaySoundMem(manager->bgm[fileName], playType, topPositionFlag);
}
}
}
void SoundManager::PlaySoundSE(const char* fileName, bool isSingleUnit, int playType, int topPositionFlag)
{
//音を重ねないなら
if (isSingleUnit)
{
if (!CheckSoundMem(manager->se[fileName]))
{
PlaySoundMem(manager->se[fileName], playType, topPositionFlag);
}
}
//音を重ねるなら
else
{
PlaySoundMem(manager->se[fileName], playType, topPositionFlag);
}
}
void SoundManager::StopSoundBGM(const char* fileName)
{
StopSoundMem(manager->bgm[fileName]);
}
void SoundManager::StopSoundBGMs()
{
for (auto iterator = manager->bgm.begin(); iterator != manager->bgm.end(); ++iterator)
{
StopSoundMem(manager->bgm[iterator->first]);
}
}
void SoundManager::StopSoundSE(const char* fileName)
{
StopSoundMem(manager->se[fileName]);
}
void SoundManager::StopSoundSEs()
{
for (auto iterator = manager->se.begin(); iterator != manager->se.end(); ++iterator)
{
StopSoundMem(manager->se[iterator->first]);
}
}