blob: 584f366920eb46bad84392add04bbcbc7dc5e9a3 (
plain)
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
|
/*
audio/sources.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include <string.h>
#include "audio/sources.h"
#include "sys/sys.h"
namespace audio
{
ALuint Sources::sources[MAXSOURCES];
bool Sources::source_available[MAXSOURCES];
void Sources::init()
{
int error;
clear();
alGenSources(MAXSOURCES, sources);
if ((error = alGetError()) != AL_NO_ERROR) {
con_warn << "Error " << std::hex << error << " initializing OpenAL sources!" << std::endl;
return;
}
// all sources are available for use
for (size_t i = MAXUISOURCES; i < MAXSOURCES; i++) {
source_available[i] = true;
}
// reserve ui sound sources
for (size_t i=0; i < MAXUISOURCES; i++) {
source_available[i] = false;
}
}
void Sources::shutdown()
{
alDeleteSources(MAXSOURCES, sources);
clear();
}
void Sources::clear()
{
memset(sources,0, sizeof(sources));
// all sources are available for use
for (size_t i=0; i < MAXSOURCES; i++) {
source_available[i] = false;
}
}
size_t Sources::get()
{
for (size_t i= MAXUISOURCES; i < MAXSOURCES; i++) {
if (source_available[i]) {
source_available[i] = false;
alSourcef(sources[i], AL_PITCH, 1.0);
alSourcef(sources[i], AL_GAIN, 0.0);
//con_debug << "reserved source " << i << std::endl;
return i;
}
}
return 0;
}
void Sources::remove(size_t index)
{
if ( (index < MAXUISOURCES ) || (MAXSOURCES <= index))
return;
source_available[index] = true;
alSourcef(sources[index], AL_GAIN, 0);
alSourceRewind(sources[index]);
//con_debug << "removed source " << index << std::endl;
}
}
|