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
|
#include "xe_sound.hpp"
#include <vector>
#include <stdexcept>
#include <iostream>
namespace xe {
Sound::Sound(const std::string& filename) {
buffer = alutCreateBufferFromFile(filename.c_str());
alGenSources(1, &source);
alSourcef(source, AL_GAIN, 1.f);
alSourcef(source, AL_PITCH, 1.f);
alSource3f(source, AL_POSITION, 0, 0, 0);
alSource3f(source, AL_VELOCITY, 0, 0, 0);
alSourcei(source, AL_LOOPING, AL_FALSE);
alSourcei(source, AL_BUFFER, buffer);
}
Sound::~Sound() {
alDeleteSources(1, &source);
alDeleteBuffers(1, &buffer);
}
void Sound::play() {
stop();
alSourcePlay(source);
};
void Sound::stop() {
alSourceStop(source);
};
void Sound::pause() {
alSourcePause(source);
};
void Sound::resume() {
alSourcePlay(source);
};
bool Sound::isPlaying() {
ALint playing;
alGetSourcei(source, AL_SOURCE_STATE, &playing);
return playing == AL_PLAYING;
};
void Sound::setPosition(glm::vec3 position) {
alSource3f(source, AL_POSITION, position.x, position.y, position.z);
};
void Sound::setLooping(bool looping) {
alSourcei(source, AL_LOOPING, looping ? 1 : 0);
};
void Sound::setVolume(float volume) {
alSourcef(source, AL_GAIN, volume);
}
}
|