Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 308667b0d1e4d5dd26adcf65e6b1c13d38cae9d8 (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
/*
   audio/audio.cc
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#include "audio/audio.h"
#include "audio/buffers.h"
#include "audio/pcm.h"
#include "audio/sources.h"
#include "sys/sys.h"

namespace audio
{

ALCdevice 			*audio_device = 0;
ALCcontext			*audio_context = 0;

void init()
{
	con_print << "^BInitializing audio...";

	// open the default audio device
	audio_device = alcOpenDevice(0);

	if (!audio_device) {
		con_warn << "Could not initialize audio!";
		return;
	}

	// create the audio context
	audio_context = alcCreateContext(audio_device ,0);
	alcMakeContextCurrent(audio_context);

	// clear errors
	alGetError();
	
	Buffers::init();

	Sources::init();
	
	//con_debug << "  device  ^B" << alcGetString(audio_device, ALC_DEFAULT_DEVICE_SPECIFIER) << std::endl;
	load("com/chat");
	load("com/hail");
}

void load (const char *name)
{
	Buffers::load(std::string(name));
}

void shutdown()
{
	con_print << "^BShutting down audio...";

	Sources::shutdown();

	Buffers::shutdown();

	if (audio_context) {
		alcMakeContextCurrent(0);
		alcDestroyContext(audio_context);
		audio_context = 0;
	}

	if (audio_device) {
		alcCloseDevice(audio_device);
		audio_device = 0;
	}	
}

void play(const char *name)
{
	if (Sources::available(0)) {
		Buffers::bind(Sources::ui(), std::string(name));
		alSourcePlay(Sources::ui());
	}
}

}