-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsonido.cpp
More file actions
105 lines (83 loc) · 2.24 KB
/
sonido.cpp
File metadata and controls
105 lines (83 loc) · 2.24 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
#include "sonido.hpp"
using namespace std;
using namespace ed;
void initSonido(int argc, char **argv)
{
alutInit(&argc, argv);
}
void listener(vector3d posicion)
{
ALfloat listenerPos[3];
listenerPos[0] = posicion.getX();
listenerPos[1] = posicion.getY();
listenerPos[2] = posicion.getZ();
ALfloat listenerVel[] = {0.0,0.0,0.0};
ALfloat listenerOri[] = {0.0,0.0,1.0, 0.0,1.0,0.0};
alListenerfv(AL_POSITION, listenerPos);
alListenerfv(AL_VELOCITY, listenerVel);
alListenerfv(AL_ORIENTATION, listenerOri);
}
void Sonido::actualizarSonido(vector3d posicion)
{
ALfloat listenerPos[3];
listenerPos[0] = posicion.getX();
listenerPos[1] = posicion.getY();
listenerPos[2] = posicion.getZ();
ALfloat sourceDir[3];
sourceDir[0] = _PosicionSource.getX();
sourceDir[1] = _PosicionSource.getY();
sourceDir[2] = _PosicionSource.getZ();
ALfloat listenerVel[3];
listenerVel[0] = _VelocidadSource.getX();
listenerVel[1] = _VelocidadSource.getY();
listenerVel[2] = _VelocidadSource.getZ();
alSourcef(_source, AL_PITCH, 1.0f);
alSourcef(_source, AL_GAIN, 1.0f);
alListenerfv(AL_VELOCITY, listenerPos);
alListenerfv(AL_VELOCITY, listenerVel);
alListenerfv(AL_DIRECTION, sourceDir);
if(_loop)
alSourcei(_source, AL_LOOPING, AL_TRUE);
}
void Sonido::actualizarSonido()
{
ALfloat sourcePos[3];
sourcePos[0] = _PosicionSource.getX();
sourcePos[1] = _PosicionSource.getY();
sourcePos[2] = _PosicionSource.getZ();
ALfloat sourceVel[3];
sourceVel[0] = _VelocidadSource.getX();
sourceVel[1] = _VelocidadSource.getY();
sourceVel[2] = _VelocidadSource.getZ();
alSourcef(_source, AL_PITCH, 1.0f);
alSourcef(_source, AL_GAIN, 1.0f);
alListenerfv(AL_POSITION, sourcePos);
alListenerfv(AL_VELOCITY, sourceVel);
alSourcei(_source, AL_BUFFER, _buffer);
if(_loop)
alSourcei(_source, AL_LOOPING, AL_TRUE);
}
void Sonido::definirSonidoSinDoppler()
{
alSourcei(_source, AL_BUFFER, _buffer);
if(_loop)
alSourcei(_source, AL_LOOPING, AL_TRUE);
}
void Sonido::terminarSonido()
{
alutExit();
}
void Sonido::leerFichero()
{
_buffer = alutCreateBufferFromFile(_fichero.c_str());
alGenSources(1, &_source);
alSourcei(_source, AL_BUFFER, _buffer);
}
void Sonido::reproducirSonido()
{
alSourcePlay(_source);
}
void Sonido::pararSonido()
{
alSourceStop(_source);
}