dungeon_crawler

view prototype/src/audio/audio.cc @ 51:d57df51f6b50

- fixed audio panning (listener direction) - particles had no fog - sound sources were not destroyed properly
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 18 Sep 2012 09:40:56 +0300
parents c40efa9cf844
children
line source
1 #include <stdio.h>
2 #include "openal.h"
3 #include "audio.h"
5 static ALCdevice *dev;
6 static ALCcontext *ctx;
9 bool init_audio()
10 {
11 if(dev) {
12 return true;
13 }
15 if(!(dev = alcOpenDevice(0))) {
16 fprintf(stderr, "failed to open OpenAL device\n");
17 return false;
18 }
19 ctx = alcCreateContext(dev, 0);
20 alcMakeContextCurrent(ctx);
22 alGetError(); // clear error code
23 return true;
24 }
26 void destroy_audio()
27 {
28 alcMakeContextCurrent(0);
29 if(ctx) {
30 alcDestroyContext(ctx);
31 }
32 if(dev) {
33 alcCloseDevice(dev);
34 }
35 }
37 void set_audio_listener(const Matrix4x4 &xform)
38 {
39 float pos[3], orient[6];
41 pos[0] = xform[0][3];
42 pos[1] = xform[1][3];
43 pos[2] = xform[2][3];
45 orient[0] = xform[0][2];
46 orient[1] = xform[1][2];
47 orient[2] = -xform[2][2];
49 orient[3] = xform[0][1];
50 orient[4] = xform[1][1];
51 orient[5] = xform[2][1];
53 alListenerfv(AL_POSITION, pos);
54 alListenerfv(AL_ORIENTATION, orient);
55 }