--- /dev/null
+#include <stdio.h>
+#include "audio.h"
+
+#include "openal.h"
+
+static ALCdevice *dev;
+static ALCcontext *ctx;
+
+bool init_audio()
+{
+ if(!(dev = alcOpenDevice(0))) {
+ fprintf(stderr, "failed to open OpenAL device\n");
+ return false;
+ }
+
+ if(!(ctx = alcCreateContext(dev, 0))) {
+ fprintf(stderr, "failed to create context\n");
+ alcCloseDevice(dev);
+ return false;
+ }
+
+ alcMakeContextCurrent(ctx);
+
+ alGetError();
+ return true;
+}
+
+void destroy_audio()
+{
+ printf("shutting down audio system\n");
+ alcMakeContextCurrent(0);
+
+ if(ctx) {
+ alcDestroyContext(ctx);
+ ctx = 0;
+ }
+
+ if(dev) {
+ alcCloseDevice(dev);
+ dev = 0;
+ }
+}
+
+void set_audio_listener(const Mat4 &xform)
+{
+ float pos[3], orient[6];
+
+ pos[0] = xform[3][0];
+ pos[1] = xform[3][1];
+ pos[2] = xform[3][2];
+
+ orient[0] = xform[2][0];
+ orient[1] = xform[2][1];
+ orient[2] = -xform[2][2];
+
+ orient[3] = xform[1][0];
+ orient[4] = xform[1][1];
+ orient[5] = xform[1][2];
+
+ alListenerfv(AL_POSITION, pos);
+ alListenerfv(AL_ORIENTATION, orient);
+}