-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound.cpp
51 lines (37 loc) · 1.24 KB
/
sound.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
#include "AL/al.h"
#include "AL/alut.h"
//FIXME: Add sound effects such as echo etc.
class Sound {
private:
ALuint source;
ALuint buffer;
public:
Sound(std::string path) {
//FIXME: Add streamable format and somehow get data from that..
buffer = alutCreateBufferFromFile((path + ".wav").c_str());
alGenSources(1, &source);
alSourcei(source, AL_BUFFER, buffer);
alSourcef(source, AL_REFERENCE_DISTANCE, 1.0f);
alSourcei(source, AL_LOOPING, AL_TRUE); // FIXME: Somewhere else. make this an option
}
void play() {
alSourcePlay(source);
}
void setPosition(glm::vec3 position) {
alSource3f(source, AL_POSITION, position.x, position.y, position.z);
}
void setVelocity(glm::vec3 velocity) {
alSource3f(source, AL_VELOCITY, velocity.x, velocity.y, velocity.z);
}
void removeDirection() {
alSource3f(source, AL_DIRECTION, 0.0f, 0.0f, 0.0f);
}
void setDirection(glm::vec3 direction, float innerAngle, float outerAngle) {
alSource3f(source, AL_DIRECTION, direction.x, direction.y, direction.z);
alSourcef(source, AL_CONE_INNER_ANGLE, innerAngle);
alSourcef(source, AL_CONE_OUTER_ANGLE, outerAngle);
}
void setPitch(float pitch) {
alSourcef(source, AL_PITCH, pitch);
}
};