/
SoundSystem.cpp
152 lines (118 loc) · 3.19 KB
/
SoundSystem.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
#include "Precompiled.h"
#include "SoundSystem.h"
#include "SceneNode.h"
SoundSystem::SoundSystem() {
}
SoundSystem::~SoundSystem() {
}
void SoundSystem::SetMasterVolume(float volume) {
pfSetMasterVolume(volume);
}
float SoundSystem::GetMasterVolume() {
return pfGetMasterVolume();
}
void SoundSystem::SetReverbPreset(ReverbPreset preset) {
pfSetListenerSetEAXPreset((Preset)preset);
}
int SoundSystem::GetSoundCount() {
return pfSystemGetSoundCount();
}
shared_ptr<ISound> SoundSystem::GetSound(int i) {
return gSoundList[i].lock();
}
shared_ptr<ISound> SoundSystem::LoadSound2D(const string & file) {
auto sound = make_shared<CSound>(file, false, false);
gSoundList.push_back(sound);
sound->mIs3D = false;
return sound;
}
shared_ptr<ISound> SoundSystem::LoadSound3D(const string & file) {
auto sound = make_shared<CSound>(file, true, false);
gSoundList.push_back(sound);
sound->mIs3D = true;
return sound;
}
shared_ptr<ISound> SoundSystem::LoadMusic(const string & file) {
auto sound = make_shared<CSound>(file, false, true);
gSoundList.push_back(sound);
sound->mIs3D = false;
return sound;
}
shared_ptr<ISound> SoundSystem::LoadMusic3D(const string & file) {
auto sound = make_shared<CSound>(file, true, true);
gSoundList.push_back(sound);
sound->mIs3D = false;
return sound;
}
CSound::CSound(const string & fileName, bool is3D, bool isMusic) : mIs3D(false) {
pfHandle = pfCreateSound(pfDataLoad(fileName.c_str(), isMusic), is3D);
}
CSound::~CSound() {
if(pfIsSound(pfHandle)) {
pfFreeSound(pfHandle);
}
}
void CSound::SetLoop(bool state) {
pfSetSoundLooping(pfHandle, state);
}
void CSound::Stop() {
pfStopSound(pfHandle);
}
bool CSound::Is3D() const {
return mIs3D;
}
Vector3 CSound::GetPosition() const {
Vector3 p;
pfGetSoundPosition(pfHandle, (float*)&p);
return p;
}
void CSound::Attach(const shared_ptr<ISceneNode>& node) {
shared_ptr<SceneNode> & sceneNode = std::dynamic_pointer_cast<SceneNode>(node);
if(sceneNode) {
sceneNode->AttachSound(shared_from_this());
}
}
void CSound::Play(int oneshot) {
PlayCallback.PlayEvent();
PlayCallback.Caller = shared_from_this();
pfPlaySound(pfHandle, oneshot);
}
float CSound::GetLength() {
return pfGetSoundLengthSeconds(pfHandle);
}
void CSound::Pause() {
pfPauseSound(pfHandle);
}
void CSound::SetVolume(float vol) {
pfSetSoundVolume(pfHandle, vol);
}
void CSound::SetPosition(Vector3 pos) {
pfSetSoundPosition(pfHandle, pos.x, pos.y, pos.z);
}
void CSound::SetReferenceDistance(float rd) {
pfSetReferenceDistance(pfHandle, rd);
}
void CSound::SetRolloffFactor(float rolloffFactor) {
pfSetRolloffFactor(pfHandle, rolloffFactor);
}
void CSound::SetRoomRolloffFactor(float rolloffDistance) {
pfSetRoomRolloffFactor(pfHandle, rolloffDistance);
}
void CSound::SetMaxDistance(float maxDistance) {
pfSetMaxDistance(pfHandle, maxDistance);
}
int CSound::IsPlaying() {
return pfIsSoundPlaying(pfHandle);
}
void CSound::SetPitch(float pitch) {
pfSetSoundPitch(pfHandle, pitch);
}
bool CSound::IsPaused() {
return pfIsSoundPaused(pfHandle);
}
float CSound::GetPlaybackPosition() {
return pfGetSoundPlaybackPosition(pfHandle);
}
void CSound::SetPlaybackPosition(float timeSeconds) {
pfSetSoundPlaybackPosition(pfHandle, timeSeconds);
}