-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSound.cpp
More file actions
118 lines (85 loc) · 1.99 KB
/
Sound.cpp
File metadata and controls
118 lines (85 loc) · 1.99 KB
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
//================================================//
#include "Sound.hpp"
//================================================//
Sound::Sound(void)
{
m_loaded = false;
}
//================================================//
Sound::Sound(unsigned type, Ogre::Vector3 pos)
{
m_loaded = false;
this->init(type, pos);
}
//================================================//
Sound::~Sound(void)
{
if(m_loaded){
m_sound->release();
}
}
//================================================//
void Sound::init(unsigned type, Ogre::Vector3 pos)
{
const char* file;
FMOD_VECTOR fPos, fVel;
m_mode = 0;
memset(&fPos, 0, sizeof(fPos));
memset(&fVel, 0, sizeof(fVel));
switch(type){
case TYPE_NULL:
default:
return;
case TYPE_FIRE1:
file = "D:/Sounds/magnum.mp3";
m_mode = FMOD_2D;
break;
case TYPE_RETRIEVE_MAGIC_CUBE:
file = "D:/Sounds/click.wav";
m_mode = FMOD_2D;
break;
case TYPE_MUSIC_MAIN_MENU:
file = "D:/Sounds/menu.mp3";
m_mode = FMOD_2D;
break;
}
FMOD_RESULT res = Base::getSingletonPtr()->m_soundSystem->createSound(file, m_mode, 0, &m_sound);
// 3D
if(m_mode & FMOD_3D){
fPos.x = pos.x;
fPos.y = pos.y;
fPos.z = pos.z;
m_channel->set3DAttributes(&fPos, &fVel);
}
if(res == FMOD_OK)
m_loaded = true;
#ifdef _DEBUG
else
printf("Failed to load sound %s\n", file);
#endif
}
//================================================//
void Sound::play(Ogre::Vector3 pos)
{
if(m_loaded)
Base::getSingletonPtr()->m_soundSystem->playSound(FMOD_CHANNEL_FREE, m_sound, false, &m_channel);
}
//================================================//
void Sound::updatePos(Ogre::Vector3 pos, Ogre::Vector3 vel)
{
if(m_mode & FMOD_3D){
FMOD_VECTOR fPos, fVel;
fPos.x = pos.x;
fPos.y = pos.y;
fPos.z = pos.z;
fVel.x = vel.x;
fVel.y = vel.y;
fVel.z = vel.z;
m_channel->set3DAttributes(&fPos, &fVel);
}
}
//================================================//
void Sound::update(double timeSinceLastFrame)
{
}
//================================================//