Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-05-18 09:21:20 +0000
committerStijn Buys <ingar@osirion.org>2008-05-18 09:21:20 +0000
commit4a2bad92171ff8a9a248599f47087cfe39e93653 (patch)
treeb8a4fe7f616b3e4f707d89a35fff5e8b5fdcfcc8 /src/audio/audio.cc
parenta185c11f2397c0296a4b62cc266b4fa00a63c1e2 (diff)
OpenAL support
Diffstat (limited to 'src/audio/audio.cc')
-rw-r--r--src/audio/audio.cc80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
new file mode 100644
index 0000000..063a079
--- /dev/null
+++ b/src/audio/audio.cc
@@ -0,0 +1,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 "AL/al.h"
+#include "AL/alc.h"
+
+#include "audio/audio.h"
+#include "audio/buffers.h"
+#include "audio/pcm.h"
+#include "sys/sys.h"
+
+namespace audio
+{
+
+ALCdevice *audio_device = 0;
+ALCcontext *audio_context = 0;
+
+ALuint source = 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();
+
+ //con_debug << " device ^B" << alcGetString(audio_device, ALC_DEFAULT_DEVICE_SPECIFIER) << std::endl;
+ load("ui/chat");
+
+ // default sound source
+ alGenSources(1, &source);
+}
+
+void load (const char *name)
+{
+ Buffers::load(std::string(name));
+}
+
+void shutdown()
+{
+ con_print << "^BShutting down audio...";
+
+ if (audio_context) {
+ alcMakeContextCurrent(0);
+ alcDestroyContext(audio_context);
+ audio_context = 0;
+ }
+
+ if (audio_device) {
+ alcCloseDevice(audio_device);
+ audio_device = 0;
+ }
+
+ alDeleteSources(1, &source);
+}
+
+void play(const char *name)
+{
+ Buffers::bind(source, std::string(name));
+ alSourcePlay(source);
+}
+
+}